1 #!/usr/bin/env ruby |
1 # vim: set nosta noet ts=4 sw=4 ft=rspec: |
2 |
|
3 BEGIN { |
|
4 require 'pathname' |
|
5 basedir = Pathname.new( __FILE__ ).dirname.parent.parent |
|
6 libdir = basedir + "lib" |
|
7 $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir ) |
|
8 } |
|
9 |
2 |
10 require_relative '../spec_helpers' |
3 require_relative '../spec_helpers' |
11 require 'ezmlm' |
|
12 |
4 |
13 describe Ezmlm::List do |
5 describe Ezmlm::List do |
14 |
6 |
15 before( :each ) do |
7 before( :each ) do |
16 @listdir = make_listdir() |
8 @listdir = make_listdir() |
23 let( :list ) do |
15 let( :list ) do |
24 described_class.new( @listdir ) |
16 described_class.new( @listdir ) |
25 end |
17 end |
26 |
18 |
27 |
19 |
28 it "can return the list name" do |
20 it "returns the list name" do |
29 expect( list.name ).to eq( TEST_LIST_NAME ) |
21 expect( list.name ).to eq( TEST_LIST_NAME ) |
30 end |
22 end |
31 |
23 |
32 it "can return the list host" do |
24 it "returns the list host" do |
33 expect( list.host ).to eq( TEST_LIST_HOST ) |
25 expect( list.host ).to eq( TEST_LIST_HOST ) |
34 end |
26 end |
35 |
27 |
36 it "can return the list address" do |
28 it "returns the list address" do |
37 expect( list.address ).to eq( TEST_LIST_NAME + '@' + TEST_LIST_HOST ) |
29 expect( list.address ).to eq( TEST_LIST_NAME + '@' + TEST_LIST_HOST ) |
38 end |
30 end |
39 |
31 |
40 it "returns nil if the list owner isn't an email address" do |
32 it "returns nil if the list owner isn't an email address" do |
41 expect( list.owner ).to eq( nil ) |
33 expect( list.owner ).to eq( nil ) |
42 end |
34 end |
43 |
35 |
44 it "can return an email address owner" do |
36 it "returns an email address owner" do |
45 expect( list ).to receive( :read ).with( 'owner' ).and_return( TEST_OWNER ) |
37 expect( list ).to receive( :read ).with( 'owner' ).and_return( TEST_OWNER ) |
46 expect( list.owner ).to eq( TEST_OWNER ) |
38 expect( list.owner ).to eq( TEST_OWNER ) |
47 end |
39 end |
48 |
40 |
49 |
41 |
50 it "can add a new subscriber" do |
42 it "can add a new subscriber" do |
51 list.add_subscriber( *TEST_SUBSCRIBERS ) |
43 list.add_subscriber( *TEST_SUBSCRIBERS ) |
52 expect( list.is_subscriber?( TEST_SUBSCRIBERS.first ) ).to be_truthy |
44 expect( list.is_subscriber?( TEST_SUBSCRIBERS.first ) ).to be_truthy |
53 end |
45 end |
54 |
46 |
55 it "can return the list of subscibers" do |
47 it "returns the list of subscibers" do |
56 list.add_subscriber( *TEST_SUBSCRIBERS ) |
48 list.add_subscriber( *TEST_SUBSCRIBERS ) |
57 list.add_subscriber( 'notanemailaddress' ) |
49 list.add_subscriber( 'notanemailaddress' ) |
58 expect( list.subscribers.length ).to eq( 3 ) |
50 expect( list.subscribers.length ).to eq( 3 ) |
59 expect( list.subscribers ).to include( TEST_SUBSCRIBERS.first ) |
51 expect( list.subscribers ).to include( TEST_SUBSCRIBERS.first ) |
60 end |
52 end |
70 it "can add a new moderator" do |
62 it "can add a new moderator" do |
71 list.add_moderator( *TEST_MODERATORS ) |
63 list.add_moderator( *TEST_MODERATORS ) |
72 expect( list.is_moderator?( TEST_MODERATORS.first ) ).to be_truthy |
64 expect( list.is_moderator?( TEST_MODERATORS.first ) ).to be_truthy |
73 end |
65 end |
74 |
66 |
75 it "can return the list of moderators" do |
67 it "returns the list of moderators" do |
76 list.add_moderator( *TEST_MODERATORS ) |
68 list.add_moderator( *TEST_MODERATORS ) |
77 expect( list.moderators.length ).to eq( 1 ) |
69 expect( list.moderators.length ).to eq( 1 ) |
78 expect( list.moderators ).to include( TEST_MODERATORS.first ) |
70 expect( list.moderators ).to include( TEST_MODERATORS.first ) |
79 end |
71 end |
80 |
72 |
88 it "can add a blacklisted address" do |
80 it "can add a blacklisted address" do |
89 list.add_blacklisted( *TEST_MODERATORS ) |
81 list.add_blacklisted( *TEST_MODERATORS ) |
90 expect( list.is_blacklisted?( TEST_MODERATORS.first ) ).to be_truthy |
82 expect( list.is_blacklisted?( TEST_MODERATORS.first ) ).to be_truthy |
91 end |
83 end |
92 |
84 |
93 it "can return the list of blacklisted addresses" do |
85 it "returns the list of blacklisted addresses" do |
94 list.add_blacklisted( *TEST_MODERATORS ) |
86 list.add_blacklisted( *TEST_MODERATORS ) |
95 expect( list.blacklisted.length ).to eq( 1 ) |
87 expect( list.blacklisted.length ).to eq( 1 ) |
96 expect( list.blacklisted ).to include( TEST_MODERATORS.first ) |
88 expect( list.blacklisted ).to include( TEST_MODERATORS.first ) |
97 end |
89 end |
98 |
90 |
106 it "can add an allowed address" do |
98 it "can add an allowed address" do |
107 list.add_allowed( *TEST_MODERATORS ) |
99 list.add_allowed( *TEST_MODERATORS ) |
108 expect( list.is_allowed?( TEST_MODERATORS.first ) ).to be_truthy |
100 expect( list.is_allowed?( TEST_MODERATORS.first ) ).to be_truthy |
109 end |
101 end |
110 |
102 |
111 it "can return the list of allowed addresses" do |
103 it "returns the list of allowed addresses" do |
112 list.add_allowed( *TEST_MODERATORS ) |
104 list.add_allowed( *TEST_MODERATORS ) |
113 expect( list.allowed.length ).to eq( 1 ) |
105 expect( list.allowed.length ).to eq( 1 ) |
114 expect( list.allowed ).to include( TEST_MODERATORS.first ) |
106 expect( list.allowed ).to include( TEST_MODERATORS.first ) |
115 end |
107 end |
116 |
108 |
119 list.remove_allowed( TEST_MODERATORS.first ) |
111 list.remove_allowed( TEST_MODERATORS.first ) |
120 expect( list.allowed ).to be_empty |
112 expect( list.allowed ).to be_empty |
121 end |
113 end |
122 |
114 |
123 |
115 |
124 it 'can return the current threading state' do |
116 it 'returns the current threading state' do |
|
117 expect( list.threaded? ).to be_truthy |
|
118 end |
|
119 |
|
120 it 'can set the threading state' do |
|
121 list.threaded = false |
125 expect( list.threaded? ).to be_falsey |
122 expect( list.threaded? ).to be_falsey |
126 end |
123 end |
127 |
124 |
128 it 'can set the threading state' do |
125 |
129 list.threaded = true |
126 it 'returns the current public/private state' do |
130 expect( list.threaded? ).to be_truthy |
|
131 end |
|
132 |
|
133 |
|
134 it 'can return the current public/private state' do |
|
135 expect( list.public? ).to be_truthy |
127 expect( list.public? ).to be_truthy |
136 expect( list.private? ).to be_falsey |
128 expect( list.private? ).to be_falsey |
137 end |
129 end |
138 |
130 |
139 it 'can set the privacy state' do |
131 it 'can set the privacy state' do |
321 list.maximum_message_size = 1024 * 300 |
313 list.maximum_message_size = 1024 * 300 |
322 expect( list.maximum_message_size ).to eq( 307200 ) |
314 expect( list.maximum_message_size ).to eq( 307200 ) |
323 end |
315 end |
324 |
316 |
325 |
317 |
326 it 'can return the message count for a pristine list' do |
318 it 'can return the total message count for a pristine list' do |
|
319 expect( list ).to receive( :read ).with( 'archnum' ).and_return( nil ) |
327 expect( list.message_count ).to eq( 0 ) |
320 expect( list.message_count ).to eq( 0 ) |
328 end |
321 end |
|
322 |
|
323 it 'can return the total message count for a list with deliveries' do |
|
324 expect( list.message_count ).to eq( 150 ) |
|
325 end |
|
326 |
|
327 |
|
328 it 'can generate a message number to thread index' do |
|
329 idx = list.index |
|
330 expect( idx.size ).to be( 150 ) |
|
331 expect( idx[39][:thread] ).to eq( 'cadgeokhhaieijmndokb' ) |
|
332 end |
|
333 |
|
334 |
|
335 it 'fetches thread objects upon request' do |
|
336 expect( list.thread('cadgeokhhaieijmndokb') ).to be_a( Ezmlm::List::Thread ) |
|
337 end |
|
338 |
|
339 |
|
340 it 'fetches author objects upon request' do |
|
341 expect( list.author('ojjhjlapnejjlbcplabi') ).to be_a( Ezmlm::List::Author ) |
|
342 end |
|
343 |
|
344 |
|
345 context 'fetching messages' do |
|
346 it 'raises an error if archiving is disabled' do |
|
347 expect( list ).to receive( :archived? ).and_return( false ) |
|
348 expect { |
|
349 list.message( 1 ) |
|
350 }.to raise_error( RuntimeError, /archiving is not enabled/i ) |
|
351 end |
|
352 |
|
353 it 'raises an error if the message archive is empty' do |
|
354 expect( list ).to receive( :message_count ).and_return( 0 ) |
|
355 expect { |
|
356 list.message( 1 ) |
|
357 }.to raise_error( RuntimeError, /message archive is empty/i ) |
|
358 end |
|
359 |
|
360 it 'returns an archived message' do |
|
361 message = list.message( 1 ) |
|
362 expect( message.id ).to be( 1 ) |
|
363 expect( message.subject ).to match( /compress program/ ) |
|
364 end |
|
365 |
|
366 it 'can iterate across all messages' do |
|
367 message = nil |
|
368 list.each_message do |m| |
|
369 if m.id == 20 |
|
370 message = m |
|
371 break |
|
372 end |
|
373 end |
|
374 expect( message ).to_not be_nil |
|
375 expect( message.id ).to be( 20 ) |
|
376 end |
|
377 end |
329 end |
378 end |
330 |
379 |
331 |
|
332 |
|
333 # it "can fetch the body of an archived post by message id" |
|
334 # it "can fetch the header of an archived post by message id" |
|
335 |
|
336 # it "can return a hash of the subjects of all archived posts to message ids" |
|
337 # it "can return an Array of the subjects of all archived posts" |
|
338 |
|
339 # it "can return a hash of the threads of all archived posts to message ids" |
|
340 # it "can return an Array of the threads of all archived posts" |
|
341 |
|
342 # it "can return a hash of the authors of all archived posts to message ids" |
|
343 # it "can return an Array of the authors of all archived posts" |
|
344 |
|
345 |
|