27 describe Ezmlm::List do |
27 describe Ezmlm::List do |
28 include Ezmlm::SpecHelpers |
28 include Ezmlm::SpecHelpers |
29 |
29 |
30 |
30 |
31 LISTDIR = Pathname.new( 'list' ) |
31 LISTDIR = Pathname.new( 'list' ) |
32 |
|
33 TEST_SUBSCRIBERS = %w[ |
32 TEST_SUBSCRIBERS = %w[ |
34 pete.chaffee@toadsmackers.com |
33 pete.chaffee@toadsmackers.com |
35 dolphinzombie@alahalohamorra.com |
34 dolphinzombie@alahalohamorra.com |
36 piratebanker@yahoo.com |
35 piratebanker@yahoo.com |
37 ] |
36 ] |
38 |
|
39 TEST_MODERATORS = %w[ |
37 TEST_MODERATORS = %w[ |
40 dolphinzombie@alahalohamorra.com |
38 dolphinzombie@alahalohamorra.com |
41 ] |
39 ] |
42 |
40 TEST_LIST_NAME = 'waffle-lovers' |
|
41 TEST_LIST_HOST = 'lists.syrup.info' |
43 TEST_OWNER = 'listowner@rumpus-the-whale.info' |
42 TEST_OWNER = 'listowner@rumpus-the-whale.info' |
44 |
|
45 TEST_CUSTOM_MODERATORS_DIR = '/foo/bar/clowns' |
43 TEST_CUSTOM_MODERATORS_DIR = '/foo/bar/clowns' |
46 |
44 TEST_CONFIG = <<-"EOF".gsub( /^\t+/, '' ) |
47 |
|
48 |
|
49 |
|
50 it "can create a new list" |
|
51 |
|
52 ### |
|
53 ### List manager functions |
|
54 ### |
|
55 describe "list manager functions" do |
|
56 |
|
57 before( :each ) do |
|
58 @listpath = LISTDIR.dup |
|
59 @list = Ezmlm::List.new( @listpath ) |
|
60 end |
|
61 |
|
62 |
|
63 it "can return a list of subscribers' email addresses" do |
|
64 subscribers_dir = LISTDIR + 'subscribers' |
|
65 |
|
66 expectation = Pathname.should_receive( :glob ).with( subscribers_dir + '*' ) |
|
67 |
|
68 TEST_SUBSCRIBERS.each do |email| |
|
69 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
70 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
71 |
|
72 expectation.and_yield( mock_subfile ) |
|
73 end |
|
74 |
|
75 subscribers = @list.subscribers |
|
76 |
|
77 subscribers.should have(TEST_SUBSCRIBERS.length).members |
|
78 subscribers.should include( *TEST_SUBSCRIBERS ) |
|
79 end |
|
80 |
|
81 |
|
82 ### Subscriber moderation |
|
83 |
|
84 it "knows that subscription moderation is enabled if the dir/modsub file exists" do |
|
85 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
86 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
87 modsub_path_obj.should_receive( :exist? ).and_return( true ) |
|
88 |
|
89 @list.should be_closed() |
|
90 end |
|
91 |
|
92 it "knows that subscription moderation is enabled if the dir/remote file exists" do |
|
93 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
94 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
95 modsub_path_obj.should_receive( :exist? ).and_return( false ) |
|
96 |
|
97 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
98 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
99 remote_path_obj.should_receive( :exist? ).and_return( true ) |
|
100 |
|
101 @list.should be_closed() |
|
102 end |
|
103 |
|
104 |
|
105 it "knows that subscription moderation is disabled if neither the dir/modsub nor " + |
|
106 "dir/remote files exist" do |
|
107 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
108 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
109 modsub_path_obj.should_receive( :exist? ).and_return( false ) |
|
110 |
|
111 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
112 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
113 remote_path_obj.should_receive( :exist? ).and_return( false ) |
|
114 |
|
115 @list.should_not be_closed() |
|
116 end |
|
117 |
|
118 |
|
119 it "returns an empty array of subscription moderators for an open list" do |
|
120 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
121 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
122 modsub_path_obj.should_receive( :exist? ).and_return( false ) |
|
123 |
|
124 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
125 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
126 remote_path_obj.should_receive( :exist? ).and_return( false ) |
|
127 |
|
128 @list.subscription_moderators.should be_empty() |
|
129 end |
|
130 |
|
131 it "can return a list of subscription moderators' email addresses" do |
|
132 # Test the moderation config files for existence |
|
133 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
134 @listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj ) |
|
135 modsub_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
136 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
137 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
138 remote_path_obj.should_receive( :exist? ).once.and_return( true ) |
|
139 |
|
140 # Try to read directory names from both config files |
|
141 modsub_path_obj.should_receive( :read ).with( 1 ).and_return( nil ) |
|
142 remote_path_obj.should_receive( :read ).with( 1 ).and_return( nil ) |
|
143 |
|
144 # Read subscribers from the default directory |
|
145 subscribers_dir = mock( "Mock moderator subscribers directory" ) |
|
146 @listpath.should_receive( :+ ).with( 'mod/subscribers' ).and_return( subscribers_dir ) |
|
147 subscribers_dir.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
148 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
149 |
|
150 TEST_MODERATORS.each do |email| |
|
151 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
152 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
153 |
|
154 expectation.and_yield( mock_subfile ) |
|
155 end |
|
156 |
|
157 mods = @list.subscription_moderators |
|
158 mods.should have(TEST_MODERATORS.length).members |
|
159 mods.should include( *TEST_MODERATORS ) |
|
160 end |
|
161 |
|
162 |
|
163 it "can return a list of subscription moderators' email addresses when the moderators " + |
|
164 "directory has been customized" do |
|
165 # Test the moderation config files for existence |
|
166 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
167 @listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj ) |
|
168 modsub_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
169 @listpath.should_receive( :+ ).with( 'remote' ) |
|
170 |
|
171 # Try to read directory names from both config files |
|
172 modsub_path_obj.should_receive( :read ).with( 1 ).and_return( '/' ) |
|
173 modsub_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR ) |
|
174 |
|
175 custom_mod_path = mock( "Mock path object for customized moderator dir" ) |
|
176 Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path ) |
|
177 |
|
178 # Read subscribers from the default file |
|
179 custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
180 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
181 |
|
182 TEST_MODERATORS.each do |email| |
|
183 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
184 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
185 |
|
186 expectation.and_yield( mock_subfile ) |
|
187 end |
|
188 |
|
189 mods = @list.subscription_moderators |
|
190 mods.should have(TEST_MODERATORS.length).members |
|
191 mods.should include( *TEST_MODERATORS ) |
|
192 end |
|
193 |
|
194 it "can get a list of modererators when remote subscription moderation is enabled" + |
|
195 " and the modsub configuration is empty" do |
|
196 # Test the moderation config files for existence |
|
197 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
198 @listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj ) |
|
199 modsub_path_obj.should_receive( :exist? ).twice.and_return( false ) |
|
200 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
201 @listpath.should_receive( :+ ).with( 'remote' ).twice.and_return( remote_path_obj ) |
|
202 remote_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
203 |
|
204 # Try to read directory names from both config files |
|
205 remote_path_obj.should_receive( :read ).with( 1 ).and_return( '/' ) |
|
206 remote_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR ) |
|
207 |
|
208 custom_mod_path = mock( "Mock path object for customized moderator dir" ) |
|
209 Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path ) |
|
210 |
|
211 # Read subscribers from the default file |
|
212 custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
213 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
214 |
|
215 TEST_MODERATORS.each do |email| |
|
216 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
217 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
218 |
|
219 expectation.and_yield( mock_subfile ) |
|
220 end |
|
221 |
|
222 mods = @list.subscription_moderators |
|
223 mods.should have(TEST_MODERATORS.length).members |
|
224 mods.should include( *TEST_MODERATORS ) |
|
225 end |
|
226 |
|
227 ### Message moderation |
|
228 |
|
229 it "knows that subscription moderation is enabled if the dir/modpost file exists" do |
|
230 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
231 @listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj ) |
|
232 modpost_path_obj.should_receive( :exist? ).and_return( true ) |
|
233 |
|
234 @list.should be_moderated() |
|
235 end |
|
236 |
|
237 it "knows that subscription moderation is disabled if the dir/modpost file doesn't exist" do |
|
238 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
239 @listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj ) |
|
240 modpost_path_obj.should_receive( :exist? ).and_return( false ) |
|
241 |
|
242 @list.should_not be_moderated() |
|
243 end |
|
244 |
|
245 |
|
246 it "returns an empty array of message moderators for an open list" do |
|
247 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
248 @listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj ) |
|
249 modpost_path_obj.should_receive( :exist? ).and_return( false ) |
|
250 |
|
251 @list.message_moderators.should be_empty() |
|
252 end |
|
253 |
|
254 |
|
255 it "can return a list of message moderators' email addresses" do |
|
256 # Test the moderation config file for existence |
|
257 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
258 @listpath.should_receive( :+ ).with( 'modpost' ).twice.and_return( modpost_path_obj ) |
|
259 modpost_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
260 |
|
261 # Try to read directory names from the config file |
|
262 modpost_path_obj.should_receive( :read ).with( 1 ).and_return( nil ) |
|
263 |
|
264 # Read subscribers from the default directory |
|
265 subscribers_dir = mock( "Mock moderator subscribers directory" ) |
|
266 @listpath.should_receive( :+ ).with( 'mod/subscribers' ).and_return( subscribers_dir ) |
|
267 subscribers_dir.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
268 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
269 |
|
270 TEST_MODERATORS.each do |email| |
|
271 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
272 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
273 |
|
274 expectation.and_yield( mock_subfile ) |
|
275 end |
|
276 |
|
277 mods = @list.message_moderators |
|
278 mods.should have(TEST_MODERATORS.length).members |
|
279 mods.should include( *TEST_MODERATORS ) |
|
280 end |
|
281 |
|
282 |
|
283 it "can return a list of message moderators' email addresses when the moderators " + |
|
284 "directory has been customized" do |
|
285 # Test the moderation config files for existence |
|
286 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
287 @listpath.should_receive( :+ ).with( 'modpost' ).twice.and_return( modpost_path_obj ) |
|
288 modpost_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
289 |
|
290 # Try to read directory names from both config files |
|
291 modpost_path_obj.should_receive( :read ).with( 1 ).and_return( '/' ) |
|
292 modpost_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR ) |
|
293 |
|
294 custom_mod_path = mock( "Mock path object for customized moderator dir" ) |
|
295 Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path ) |
|
296 |
|
297 # Read subscribers from the default file |
|
298 custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
299 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
300 |
|
301 TEST_MODERATORS.each do |email| |
|
302 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
303 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
304 |
|
305 expectation.and_yield( mock_subfile ) |
|
306 end |
|
307 |
|
308 mods = @list.message_moderators |
|
309 mods.should have(TEST_MODERATORS.length).members |
|
310 mods.should include( *TEST_MODERATORS ) |
|
311 end |
|
312 |
|
313 |
|
314 ### List owner |
|
315 |
|
316 TEST_CONFIG_WITHOUT_OWNER = <<-"EOF".gsub( /^\t+/, '' ) |
|
317 F:-aBCDeFGHijKlMnOpQrStUVWXYZ |
45 F:-aBCDeFGHijKlMnOpQrStUVWXYZ |
318 X: |
46 X: |
319 D:/var/qmail/alias/lists/waffle-lovers/ |
47 D:/var/qmail/alias/lists/waffle-lovers/ |
320 T:/var/qmail/alias/.qmail-waffle-lovers |
48 T:/var/qmail/alias/.qmail-waffle-lovers |
321 L:waffle-lovers |
49 L:#{TEST_LIST_NAME} |
322 H:lists.syrup.info |
50 H:#{TEST_LIST_HOST} |
323 C: |
|
324 0: |
|
325 3: |
|
326 4: |
|
327 5: |
|
328 6: |
|
329 7: |
|
330 8: |
|
331 9: |
|
332 EOF |
|
333 |
|
334 it "returns nil when the list doesn't have an owner in its config" do |
|
335 config_path_obj = mock( "Config path object" ) |
|
336 @listpath.should_receive( :+ ).with( 'config' ).and_return( config_path_obj ) |
|
337 config_path_obj.should_receive( :read ).and_return( TEST_CONFIG_WITHOUT_OWNER ) |
|
338 |
|
339 @list.owner.should == nil |
|
340 end |
|
341 |
|
342 |
|
343 TEST_CONFIG_WITH_OWNER = <<-"EOF".gsub( /^\t+/, '' ) |
|
344 F:-aBCDeFGHijKlMnOpQrStUVWXYZ |
|
345 X: |
|
346 D:/var/qmail/alias/lists/waffle-lovers/ |
|
347 T:/var/qmail/alias/.qmail-waffle-lovers |
|
348 L:waffle-lovers |
|
349 H:lists.syrup.info |
|
350 C: |
51 C: |
351 0: |
52 0: |
352 3: |
53 3: |
353 4: |
54 4: |
354 5:#{TEST_OWNER} |
55 5:#{TEST_OWNER} |
355 6: |
56 6: |
356 7: |
57 7: |
357 8: |
58 8: |
358 9: |
59 9: |
359 EOF |
60 EOF |
360 |
61 |
|
62 |
|
63 it "can create a new list" |
|
64 it "can add a new subscriber" |
|
65 it "can remove a current subscriber" |
|
66 it "can edit the list's text files" |
|
67 |
|
68 |
|
69 ### |
|
70 ### List manager functions |
|
71 ### |
|
72 describe "list manager functions" do |
|
73 |
|
74 before( :each ) do |
|
75 @listpath = LISTDIR.dup |
|
76 @list = Ezmlm::List.new( @listpath ) |
|
77 end |
|
78 |
|
79 |
|
80 it "can return the configured list name" do |
|
81 @list.stub!( :config ).and_return({ 'L' => :the_list_name }) |
|
82 @list.name.should == :the_list_name |
|
83 end |
|
84 |
|
85 |
|
86 it "can return the configured list host" do |
|
87 @list.stub!( :config ).and_return({ 'H' => :the_list_host }) |
|
88 @list.host.should == :the_list_host |
|
89 end |
|
90 |
|
91 |
|
92 it "can return the configured list address" do |
|
93 @list.stub!( :config ).and_return({ 'L' => TEST_LIST_NAME, 'H' => TEST_LIST_HOST }) |
|
94 @list.address.should == "%s@%s" % [ TEST_LIST_NAME, TEST_LIST_HOST ] |
|
95 end |
|
96 |
|
97 |
|
98 CONFIG_KEYS = %w[ F X D T L H C 0 3 4 5 6 7 8 9 ] |
|
99 |
|
100 it "can fetch the list config as a Hash" do |
|
101 config_path = mock( "Mock config path" ) |
|
102 @listpath.should_receive( :+ ).with( 'config' ).and_return( config_path ) |
|
103 config_path.should_receive( :exist? ).and_return( true ) |
|
104 config_path.should_receive( :read ).and_return( TEST_CONFIG ) |
|
105 |
|
106 @list.config.should be_an_instance_of( Hash ) |
|
107 @list.config.should have( CONFIG_KEYS.length ).members |
|
108 @list.config.keys.should include( *CONFIG_KEYS ) |
|
109 end |
|
110 |
|
111 |
|
112 it "raises an error if the list config file doesn't exist" do |
|
113 config_path = mock( "Mock config path" ) |
|
114 @listpath.should_receive( :+ ).with( 'config' ).and_return( config_path ) |
|
115 config_path.should_receive( :exist? ).and_return( false ) |
|
116 |
|
117 lambda { |
|
118 @list.config |
|
119 }.should raise_error( RuntimeError, /does not exist/ ) |
|
120 end |
|
121 |
|
122 |
|
123 it "can return a list of subscribers' email addresses" do |
|
124 subscribers_dir = LISTDIR + 'subscribers' |
|
125 |
|
126 expectation = Pathname.should_receive( :glob ).with( subscribers_dir + '*' ) |
|
127 |
|
128 TEST_SUBSCRIBERS.each do |email| |
|
129 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
130 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
131 |
|
132 expectation.and_yield( mock_subfile ) |
|
133 end |
|
134 |
|
135 subscribers = @list.subscribers |
|
136 |
|
137 subscribers.should have(TEST_SUBSCRIBERS.length).members |
|
138 subscribers.should include( *TEST_SUBSCRIBERS ) |
|
139 end |
|
140 |
|
141 |
|
142 ### Subscriber moderation |
|
143 |
|
144 it "knows that subscription moderation is enabled if the dir/modsub file exists" do |
|
145 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
146 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
147 modsub_path_obj.should_receive( :exist? ).and_return( true ) |
|
148 |
|
149 @list.should be_closed() |
|
150 end |
|
151 |
|
152 it "knows that subscription moderation is enabled if the dir/remote file exists" do |
|
153 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
154 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
155 modsub_path_obj.should_receive( :exist? ).and_return( false ) |
|
156 |
|
157 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
158 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
159 remote_path_obj.should_receive( :exist? ).and_return( true ) |
|
160 |
|
161 @list.should be_closed() |
|
162 end |
|
163 |
|
164 |
|
165 it "knows that subscription moderation is disabled if neither the dir/modsub nor " + |
|
166 "dir/remote files exist" do |
|
167 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
168 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
169 modsub_path_obj.should_receive( :exist? ).and_return( false ) |
|
170 |
|
171 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
172 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
173 remote_path_obj.should_receive( :exist? ).and_return( false ) |
|
174 |
|
175 @list.should_not be_closed() |
|
176 end |
|
177 |
|
178 |
|
179 it "returns an empty array of subscription moderators for an open list" do |
|
180 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
181 @listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj ) |
|
182 modsub_path_obj.should_receive( :exist? ).and_return( false ) |
|
183 |
|
184 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
185 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
186 remote_path_obj.should_receive( :exist? ).and_return( false ) |
|
187 |
|
188 @list.subscription_moderators.should be_empty() |
|
189 end |
|
190 |
|
191 it "can return a list of subscription moderators' email addresses" do |
|
192 # Test the moderation config files for existence |
|
193 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
194 @listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj ) |
|
195 modsub_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
196 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
197 @listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj ) |
|
198 remote_path_obj.should_receive( :exist? ).once.and_return( true ) |
|
199 |
|
200 # Try to read directory names from both config files |
|
201 modsub_path_obj.should_receive( :read ).with( 1 ).and_return( nil ) |
|
202 remote_path_obj.should_receive( :read ).with( 1 ).and_return( nil ) |
|
203 |
|
204 # Read subscribers from the default directory |
|
205 subscribers_dir = mock( "Mock moderator subscribers directory" ) |
|
206 @listpath.should_receive( :+ ).with( 'mod/subscribers' ).and_return( subscribers_dir ) |
|
207 subscribers_dir.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
208 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
209 |
|
210 TEST_MODERATORS.each do |email| |
|
211 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
212 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
213 |
|
214 expectation.and_yield( mock_subfile ) |
|
215 end |
|
216 |
|
217 mods = @list.subscription_moderators |
|
218 mods.should have(TEST_MODERATORS.length).members |
|
219 mods.should include( *TEST_MODERATORS ) |
|
220 end |
|
221 |
|
222 |
|
223 it "can return a list of subscription moderators' email addresses when the moderators " + |
|
224 "directory has been customized" do |
|
225 # Test the moderation config files for existence |
|
226 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
227 @listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj ) |
|
228 modsub_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
229 @listpath.should_receive( :+ ).with( 'remote' ) |
|
230 |
|
231 # Try to read directory names from both config files |
|
232 modsub_path_obj.should_receive( :read ).with( 1 ).and_return( '/' ) |
|
233 modsub_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR ) |
|
234 |
|
235 custom_mod_path = mock( "Mock path object for customized moderator dir" ) |
|
236 Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path ) |
|
237 |
|
238 # Read subscribers from the default file |
|
239 custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
240 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
241 |
|
242 TEST_MODERATORS.each do |email| |
|
243 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
244 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
245 |
|
246 expectation.and_yield( mock_subfile ) |
|
247 end |
|
248 |
|
249 mods = @list.subscription_moderators |
|
250 mods.should have(TEST_MODERATORS.length).members |
|
251 mods.should include( *TEST_MODERATORS ) |
|
252 end |
|
253 |
|
254 it "can get a list of modererators when remote subscription moderation is enabled" + |
|
255 " and the modsub configuration is empty" do |
|
256 # Test the moderation config files for existence |
|
257 modsub_path_obj = mock( "Mock 'modsub' path object" ) |
|
258 @listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj ) |
|
259 modsub_path_obj.should_receive( :exist? ).twice.and_return( false ) |
|
260 remote_path_obj = mock( "Mock 'remote' path object" ) |
|
261 @listpath.should_receive( :+ ).with( 'remote' ).twice.and_return( remote_path_obj ) |
|
262 remote_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
263 |
|
264 # Try to read directory names from both config files |
|
265 remote_path_obj.should_receive( :read ).with( 1 ).and_return( '/' ) |
|
266 remote_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR ) |
|
267 |
|
268 custom_mod_path = mock( "Mock path object for customized moderator dir" ) |
|
269 Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path ) |
|
270 |
|
271 # Read subscribers from the default file |
|
272 custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
273 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
274 |
|
275 TEST_MODERATORS.each do |email| |
|
276 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
277 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
278 |
|
279 expectation.and_yield( mock_subfile ) |
|
280 end |
|
281 |
|
282 mods = @list.subscription_moderators |
|
283 mods.should have(TEST_MODERATORS.length).members |
|
284 mods.should include( *TEST_MODERATORS ) |
|
285 end |
|
286 |
|
287 ### Message moderation |
|
288 |
|
289 it "knows that subscription moderation is enabled if the dir/modpost file exists" do |
|
290 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
291 @listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj ) |
|
292 modpost_path_obj.should_receive( :exist? ).and_return( true ) |
|
293 |
|
294 @list.should be_moderated() |
|
295 end |
|
296 |
|
297 it "knows that subscription moderation is disabled if the dir/modpost file doesn't exist" do |
|
298 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
299 @listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj ) |
|
300 modpost_path_obj.should_receive( :exist? ).and_return( false ) |
|
301 |
|
302 @list.should_not be_moderated() |
|
303 end |
|
304 |
|
305 |
|
306 it "returns an empty array of message moderators for an open list" do |
|
307 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
308 @listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj ) |
|
309 modpost_path_obj.should_receive( :exist? ).and_return( false ) |
|
310 |
|
311 @list.message_moderators.should be_empty() |
|
312 end |
|
313 |
|
314 |
|
315 it "can return a list of message moderators' email addresses" do |
|
316 # Test the moderation config file for existence |
|
317 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
318 @listpath.should_receive( :+ ).with( 'modpost' ).twice.and_return( modpost_path_obj ) |
|
319 modpost_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
320 |
|
321 # Try to read directory names from the config file |
|
322 modpost_path_obj.should_receive( :read ).with( 1 ).and_return( nil ) |
|
323 |
|
324 # Read subscribers from the default directory |
|
325 subscribers_dir = mock( "Mock moderator subscribers directory" ) |
|
326 @listpath.should_receive( :+ ).with( 'mod/subscribers' ).and_return( subscribers_dir ) |
|
327 subscribers_dir.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
328 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
329 |
|
330 TEST_MODERATORS.each do |email| |
|
331 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
332 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
333 |
|
334 expectation.and_yield( mock_subfile ) |
|
335 end |
|
336 |
|
337 mods = @list.message_moderators |
|
338 mods.should have(TEST_MODERATORS.length).members |
|
339 mods.should include( *TEST_MODERATORS ) |
|
340 end |
|
341 |
|
342 |
|
343 it "can return a list of message moderators' email addresses when the moderators " + |
|
344 "directory has been customized" do |
|
345 # Test the moderation config files for existence |
|
346 modpost_path_obj = mock( "Mock 'modpost' path object" ) |
|
347 @listpath.should_receive( :+ ).with( 'modpost' ).twice.and_return( modpost_path_obj ) |
|
348 modpost_path_obj.should_receive( :exist? ).twice.and_return( true ) |
|
349 |
|
350 # Try to read directory names from both config files |
|
351 modpost_path_obj.should_receive( :read ).with( 1 ).and_return( '/' ) |
|
352 modpost_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR ) |
|
353 |
|
354 custom_mod_path = mock( "Mock path object for customized moderator dir" ) |
|
355 Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path ) |
|
356 |
|
357 # Read subscribers from the default file |
|
358 custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir ) |
|
359 expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir ) |
|
360 |
|
361 TEST_MODERATORS.each do |email| |
|
362 mock_subfile = mock( "Mock subscribers file for '#{email}'" ) |
|
363 mock_subfile.should_receive( :read ).and_return( "T#{email}\0" ) |
|
364 |
|
365 expectation.and_yield( mock_subfile ) |
|
366 end |
|
367 |
|
368 mods = @list.message_moderators |
|
369 mods.should have(TEST_MODERATORS.length).members |
|
370 mods.should include( *TEST_MODERATORS ) |
|
371 end |
|
372 |
|
373 |
|
374 ### List owner |
|
375 |
|
376 it "returns nil when the list doesn't have an owner in its config" do |
|
377 @list.stub!( :config ).and_return({ '5' => nil }) |
|
378 @list.owner.should == nil |
|
379 end |
|
380 |
|
381 |
361 it "can return the email address of the list owner" do |
382 it "can return the email address of the list owner" do |
362 config_path_obj = mock( "Config path object" ) |
383 @list.stub!( :config ).and_return({ '5' => TEST_OWNER }) |
363 @listpath.should_receive( :+ ).with( 'config' ).and_return( config_path_obj ) |
|
364 config_path_obj.should_receive( :read ).and_return( TEST_CONFIG_WITH_OWNER ) |
|
365 |
|
366 @list.owner.should == TEST_OWNER |
384 @list.owner.should == TEST_OWNER |
367 end |
385 end |
368 |
386 |
369 end |
387 end |
|
388 |
370 |
389 |
371 ### |
390 ### |
372 ### Archive functions |
391 ### Archive functions |
373 ### |
392 ### |
374 describe "archive functions" do |
393 describe "archive functions" do |