Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 31334 Bytes
1 | require File.dirname(__FILE__) + '/../spec_helper' |
2 | |
3 | module ContentStateSpecHelper |
4 | def stop_the_clock |
5 | @this_instant = Time.now |
6 | Time.stub!(:now).and_return { @this_instant } |
7 | end |
8 | |
9 | def should_set_content_fields(expectations = {}) |
10 | expectations.each { |flag, val| @content.should_receive(:[]=).with(flag, val).and_return(val) } |
11 | end |
12 | |
13 | alias_method :should_set_content_field, :should_set_content_fields |
14 | |
15 | def should_change_state_to(statesym) |
16 | expected_state = case statesym |
17 | when :draft; ContentState::Draft |
18 | when :just_published; ContentState::JustPublished |
19 | when :published; ContentState::Published |
20 | when :draft; ContentState::Draft |
21 | when :publication_pending; ContentState::PublicationPending |
22 | when :withdrawn; ContentState::Withdrawn |
23 | when :just_withdrawn; ContentState::JustWithdrawn |
24 | when :unclassified; ContentState::Unclassified |
25 | when :new; ContentState::New |
26 | when :ham; ContentState::Ham |
27 | when :just_marked_as_ham; ContentState::JustMarkedAsHam |
28 | when :just_marked_as_spam; ContentState::JustMarkedAsSpam |
29 | when :spam; ContentState::Spam |
30 | when :presumed_ham; ContentState::PresumedHam |
31 | when :just_presumed_ham; ContentState::JustPresumedHam |
32 | when :presumed_spam; ContentState::PresumedSpam |
33 | else |
34 | raise "Don't recognize #{statesym.inspect} as a state" |
35 | end.instance |
36 | @content.should_receive(:state=).with(expected_state) |
37 | end |
38 | end |
39 | |
40 | context 'With ContentState::New.instance and mock content' do |
41 | include ContentStateSpecHelper |
42 | |
43 | setup do |
44 | @content = mock('content') |
45 | @state = ContentState::New.instance |
46 | end |
47 | |
48 | specify '#just_published? should be false' do |
49 | @state.should_not_be_just_published |
50 | end |
51 | |
52 | specify '#just_changed_published_status? should be false' do |
53 | @state.just_changed_published_status?.should_be false |
54 | end |
55 | |
56 | specify '#enter_hook should set :published false and :published_at nil' do |
57 | should_set_content_fields :published => false, :published_at => nil |
58 | |
59 | @state.enter_hook(@content) |
60 | end |
61 | |
62 | specify '#before_save should set content.state to Draft' do |
63 | should_change_state_to :draft |
64 | @state.before_save(@content) |
65 | end |
66 | |
67 | specify '#change_published_state => true should set published flag and change state to JustPublished' do |
68 | should_set_content_field :published => true |
69 | should_change_state_to :just_published |
70 | |
71 | @state.change_published_state(@content, true) |
72 | end |
73 | |
74 | specify '#change_published_state to false should set published flag' do |
75 | should_set_content_field :published => false |
76 | @state.change_published_state(@content, false) |
77 | end |
78 | |
79 | specify '#set_published_at to the_future should set published_at and change to PublicationPending' do |
80 | stop_the_clock |
81 | should_set_content_field :published_at => Time.now + 10 |
82 | should_change_state_to :publication_pending |
83 | |
84 | @state.set_published_at(@content, Time.now + 10) |
85 | end |
86 | |
87 | specify '#set_published_at now should set published_at and change to JustPublished' do |
88 | stop_the_clock |
89 | should_change_state_to :just_published |
90 | should_set_content_field :published_at => Time.now |
91 | |
92 | @state.set_published_at(@content, Time.now) |
93 | end |
94 | |
95 | specify '#set_published_at in the past should set published_at and change to JustPublished' do |
96 | stop_the_clock |
97 | should_change_state_to :just_published |
98 | should_set_content_field :published_at => Time.now - 10 |
99 | |
100 | @state.set_published_at(@content, Time.now - 10) |
101 | end |
102 | |
103 | specify '#send_notifications should not send notifications' do |
104 | @content.should_not_receive(:anything) |
105 | @state.send_notifications(@content) |
106 | end |
107 | |
108 | specify '#send_pings should not call back to @content.really_send_pings' do |
109 | @content.should_not_receive(:really_send_pings) |
110 | |
111 | @state.send_pings(@content) |
112 | end |
113 | end |
114 | |
115 | context 'With ContentState::Draft.instance and mock content' do |
116 | include ContentStateSpecHelper |
117 | |
118 | setup do |
119 | @content = mock('content') |
120 | @state = ContentState::Draft.instance |
121 | end |
122 | |
123 | specify '#just_published? should be false' do |
124 | @state.should_not_be_just_published |
125 | end |
126 | |
127 | specify '#just_changed_published_status? should be false' do |
128 | @state.just_changed_published_status?.should_be false |
129 | end |
130 | |
131 | specify '#enter_hook should set :published false and set published_at to nil' do |
132 | should_set_content_fields :published => false, :published_at => nil |
133 | |
134 | @state.enter_hook(@content) |
135 | end |
136 | |
137 | specify '#before_save should not do anything' do |
138 | @state.before_save(@content) |
139 | end |
140 | |
141 | specify '#change_published_state => true should set published flag and change state to JustPublished' do |
142 | should_set_content_field :published => true |
143 | should_change_state_to :just_published |
144 | |
145 | @state.change_published_state(@content, true) |
146 | end |
147 | |
148 | specify '#change_published_state to false should set published flag' do |
149 | should_set_content_field :published => false |
150 | @state.change_published_state(@content, false) |
151 | end |
152 | |
153 | specify '#set_published_at to the_future should set published_at and change to PublicationPending' do |
154 | stop_the_clock |
155 | should_set_content_field :published_at => Time.now + 10 |
156 | should_change_state_to :publication_pending |
157 | |
158 | @state.set_published_at(@content, Time.now + 10) |
159 | end |
160 | |
161 | specify '#set_published_at <=now should discard the time and set published_at to nil' do |
162 | stop_the_clock |
163 | @content.should_receive(:[]=).with(:published_at, Time.now).ordered |
164 | @content.should_receive(:[]=).with(:published_at, nil).ordered |
165 | |
166 | @state.set_published_at(@content, Time.now) |
167 | end |
168 | |
169 | specify '#send_notifications should not send notifications' do |
170 | @content.should_not_receive(:anything) |
171 | @state.send_notifications(@content) |
172 | end |
173 | |
174 | specify '#send_pings should not call back to @content.really_send_pings' do |
175 | @content.should_not_receive(:really_send_pings) |
176 | |
177 | @state.send_pings(@content) |
178 | end |
179 | end |
180 | |
181 | context 'With ContentState::Published.instance and mock content' do |
182 | include ContentStateSpecHelper |
183 | |
184 | setup do |
185 | @content = mock('content') |
186 | @state = ContentState::Published.instance |
187 | end |
188 | |
189 | specify '#just_published? should be false' do |
190 | @state.should_not_be_just_published |
191 | end |
192 | |
193 | specify '#just_changed_published_status? should be false' do |
194 | @state.just_changed_published_status?.should_be false |
195 | end |
196 | |
197 | specify '#enter_hook should set :published true and sets a nil published_at to Time.now' do |
198 | stop_the_clock |
199 | should_set_content_fields :published => true |
200 | @content.should_receive(:[]).with(:published_at).and_return nil |
201 | @content.should_receive(:[]=).with(:published_at, Time.now) |
202 | |
203 | @state.enter_hook(@content) |
204 | end |
205 | |
206 | specify '#before_save should just return true' do |
207 | @state.before_save(@content).should_be true |
208 | end |
209 | |
210 | specify '#change_published_state => true should not do anything' do |
211 | @state.change_published_state(@content, true) |
212 | end |
213 | |
214 | specify '#change_published_state to false should unset the published flag and change state to JustWithdrawn' do |
215 | should_set_content_fields :published => false, :published_at => nil |
216 | should_change_state_to :just_withdrawn |
217 | @state.change_published_state(@content, false) |
218 | end |
219 | |
220 | specify '#set_published_at to the_future should set published_at and change to PublicationPending' do |
221 | stop_the_clock |
222 | should_set_content_field :published_at => Time.now + 10 |
223 | should_change_state_to :publication_pending |
224 | |
225 | @state.set_published_at(@content, Time.now + 10) |
226 | end |
227 | |
228 | specify '#set_published_at now should set published_at' do |
229 | stop_the_clock |
230 | should_set_content_field :published_at => Time.now |
231 | |
232 | @state.set_published_at(@content, Time.now) |
233 | end |
234 | |
235 | specify '#set_published_at in the past should set published_at' do |
236 | stop_the_clock |
237 | should_set_content_field :published_at => Time.now - 10 |
238 | |
239 | @state.set_published_at(@content, Time.now - 10) |
240 | end |
241 | |
242 | specify '#send_notifications should not send notifications' do |
243 | @content.should_not_receive(:anything) |
244 | @state.send_notifications(@content) |
245 | end |
246 | |
247 | specify '#send_pings should not call back to @content.really_send_pings' do |
248 | @content.should_not_receive(:really_send_pings) |
249 | |
250 | @state.send_pings(@content) |
251 | end |
252 | end |
253 | |
254 | context 'With ContentState::JustPublished.instance and mock content' do |
255 | include ContentStateSpecHelper |
256 | |
257 | setup do |
258 | @content = mock('content') |
259 | @state = ContentState::JustPublished.instance |
260 | end |
261 | |
262 | specify '#just_published? should be true' do |
263 | @state.should_be_just_published |
264 | end |
265 | |
266 | specify '#just_changed_published_status? should be true' do |
267 | @state.just_changed_published_status?.should_be true |
268 | end |
269 | |
270 | specify '#enter_hook should set :published true and sets a nil published_at to Time.now' do |
271 | stop_the_clock |
272 | should_set_content_fields :published => true |
273 | @content.should_receive(:[]).with(:published_at).and_return nil |
274 | @content.should_receive(:[]=).with(:published_at, Time.now) |
275 | |
276 | @state.enter_hook(@content) |
277 | end |
278 | |
279 | specify '#before_save should just return true' do |
280 | @state.before_save(@content).should_be true |
281 | end |
282 | |
283 | specify '#change_published_state => true should not do anything' do |
284 | @state.change_published_state(@content, true) |
285 | end |
286 | |
287 | specify '#change_published_state to false should unset the published flag and change state to JustWithdrawn' do |
288 | should_set_content_fields :published => false, :published_at => nil |
289 | should_change_state_to :just_withdrawn |
290 | @state.change_published_state(@content, false) |
291 | end |
292 | |
293 | specify '#set_published_at to the_future should set published_at and change to PublicationPending' do |
294 | stop_the_clock |
295 | should_set_content_field :published_at => Time.now + 10 |
296 | should_change_state_to :publication_pending |
297 | |
298 | @state.set_published_at(@content, Time.now + 10) |
299 | end |
300 | |
301 | specify '#set_published_at now should set published_at' do |
302 | stop_the_clock |
303 | should_set_content_field :published_at => Time.now |
304 | |
305 | @state.set_published_at(@content, Time.now) |
306 | end |
307 | |
308 | specify '#set_published_at in the past should set published_at' do |
309 | stop_the_clock |
310 | should_set_content_field :published_at => Time.now - 10 |
311 | |
312 | @state.set_published_at(@content, Time.now - 10) |
313 | end |
314 | |
315 | specify '#send_notifications should really send notifications' do |
316 | @content.should_receive(:interested_users).and_return([:bob, :jim]) |
317 | @content.should_receive(:send_notification_to_user).with(:bob) |
318 | @content.should_receive(:send_notification_to_user).with(:jim) |
319 | |
320 | @state.send_notifications(@content) |
321 | end |
322 | |
323 | specify '#send_pings should call back to @content.really_send_pings' do |
324 | @content.should_receive(:really_send_pings) |
325 | |
326 | @state.send_pings(@content) |
327 | end |
328 | end |
329 | |
330 | context 'With ContentState::Withdrawn.instance and mock content' do |
331 | include ContentStateSpecHelper |
332 | |
333 | setup do |
334 | @content = mock('content') |
335 | @state = ContentState::Withdrawn.instance |
336 | end |
337 | |
338 | specify '#just_published? should be false' do |
339 | @state.should_not_be_just_published |
340 | end |
341 | |
342 | specify '#just_changed_published_status? should be false' do |
343 | @state.just_changed_published_status?.should_be false |
344 | end |
345 | |
346 | specify '#enter_hook should set :published false and set published_at to nil' do |
347 | should_set_content_field :published => false |
348 | |
349 | @state.enter_hook(@content) |
350 | end |
351 | |
352 | specify '#before_save should not do anything' do |
353 | @state.before_save(@content) |
354 | end |
355 | |
356 | specify '#change_published_state => true should set published flag and change state to JustPublished' do |
357 | should_set_content_field :published => true |
358 | should_change_state_to :published |
359 | |
360 | @state.change_published_state(@content, true) |
361 | end |
362 | |
363 | specify '#change_published_state to false should not do anything' do |
364 | @content.should_not_receive(:[]=) |
365 | @state.change_published_state(@content, false) |
366 | end |
367 | |
368 | specify '#set_published_at to the_future should set published_at, remove any trigger and change to PublicationPending' do |
369 | stop_the_clock |
370 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
371 | should_set_content_field :published_at => Time.now + 10 |
372 | should_change_state_to :publication_pending |
373 | |
374 | @state.set_published_at(@content, Time.now + 10) |
375 | end |
376 | |
377 | specify '#set_published_at <=now should change the publication time and remove any trigger' do |
378 | stop_the_clock |
379 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
380 | @content.should_receive(:[]=).with(:published_at, Time.now).ordered |
381 | |
382 | @state.set_published_at(@content, Time.now) |
383 | end |
384 | |
385 | specify '#send_notifications should not send notifications' do |
386 | @content.should_not_receive(:anything) |
387 | @state.send_notifications(@content) |
388 | end |
389 | |
390 | specify '#send_pings should not call back to @content.really_send_pings' do |
391 | @content.should_not_receive(:really_send_pings) |
392 | |
393 | @state.send_pings(@content) |
394 | end |
395 | end |
396 | |
397 | context 'With ContentState::JustWithdrawn.instance and mock content' do |
398 | include ContentStateSpecHelper |
399 | |
400 | setup do |
401 | @content = mock('content') |
402 | @state = ContentState::JustWithdrawn.instance |
403 | end |
404 | |
405 | specify '#just_published? should be false' do |
406 | @state.should_not_be_just_published |
407 | end |
408 | |
409 | specify '#just_changed_published_status? should be true' do |
410 | @state.just_changed_published_status?.should_be true |
411 | end |
412 | |
413 | specify '#enter_hook should set :published false' do |
414 | should_set_content_field :published => false |
415 | |
416 | @state.enter_hook(@content) |
417 | end |
418 | |
419 | specify '#before_save should not do anything' do |
420 | @content.should_not_receive(:[]=) |
421 | @state.before_save(@content) |
422 | end |
423 | |
424 | specify '#change_published_state => true should set published flag and change state to Published' do |
425 | should_set_content_field :published => true |
426 | should_change_state_to :published |
427 | |
428 | @state.change_published_state(@content, true) |
429 | end |
430 | |
431 | specify '#change_published_state to false should not do anything' do |
432 | @content.should_not_receive(:[]=) |
433 | @state.change_published_state(@content, false) |
434 | end |
435 | |
436 | specify '#set_published_at to the_future should set published_at, remove any trigger and change to PublicationPending' do |
437 | stop_the_clock |
438 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
439 | should_set_content_field :published_at => Time.now + 10 |
440 | should_change_state_to :publication_pending |
441 | |
442 | @state.set_published_at(@content, Time.now + 10) |
443 | end |
444 | |
445 | specify '#set_published_at <=now should change the publication time and remove any trigger' do |
446 | stop_the_clock |
447 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
448 | @content.should_receive(:[]=).with(:published_at, Time.now).ordered |
449 | |
450 | @state.set_published_at(@content, Time.now) |
451 | end |
452 | |
453 | specify '#send_notifications should not send notifications' do |
454 | @content.should_not_receive(:anything) |
455 | @state.send_notifications(@content) |
456 | end |
457 | |
458 | specify '#send_pings should not call back to @content.really_send_pings' do |
459 | @content.should_not_receive(:really_send_pings) |
460 | |
461 | @state.send_pings(@content) |
462 | end |
463 | end |
464 | |
465 | context 'With ContentState::PublicationPending.instance and mock content' do |
466 | include ContentStateSpecHelper |
467 | |
468 | setup do |
469 | @content = mock('content') |
470 | @state = ContentState::PublicationPending.instance |
471 | end |
472 | |
473 | specify '#just_published? should be false' do |
474 | @state.should_not_be_just_published |
475 | end |
476 | |
477 | specify '#just_changed_published_status? should be false' do |
478 | @state.just_changed_published_status?.should_be false |
479 | end |
480 | |
481 | specify '#enter_hook should set :published false for a new record' do |
482 | @content.should_receive(:new_record?).and_return true |
483 | should_set_content_field :published => false |
484 | |
485 | @state.enter_hook(@content) |
486 | end |
487 | |
488 | specify '#enter_hook should not touch an existing record' do |
489 | @content.should_receive(:new_record?).and_return false |
490 | @content.should_not_receive(:[]=) |
491 | |
492 | @state.enter_hook(@content) |
493 | end |
494 | |
495 | specify '#before_save should not do anything' do |
496 | @state.before_save(@content) |
497 | end |
498 | |
499 | # I don't quite understand why this works like this... just port the test for now. |
500 | specify '#change_published_state => true should set published flag and change to JustPublished if published_at is in the past' do |
501 | stop_the_clock |
502 | @content.should_receive(:published_at).and_return(Time.now - 10) |
503 | should_change_state_to :just_published |
504 | |
505 | should_set_content_field :published => true |
506 | |
507 | @state.change_published_state(@content, true) |
508 | end |
509 | |
510 | specify '#change_published_state => true should just set the published flag if published_at is in the future' do |
511 | stop_the_clock |
512 | @content.should_receive(:published_at).and_return(Time.now + 10) |
513 | |
514 | should_set_content_field :published => true |
515 | |
516 | @state.change_published_state(@content, true) |
517 | end |
518 | |
519 | |
520 | specify '#change_published_state to false should unset the flag' do |
521 | should_set_content_field :published => false |
522 | @state.change_published_state(@content, false) |
523 | end |
524 | |
525 | specify '#set_published_at to the_future should set published_at, remove any trigger and change to PublicationPending' do |
526 | stop_the_clock |
527 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
528 | should_set_content_field :published_at => Time.now + 10 |
529 | |
530 | @state.set_published_at(@content, Time.now + 10) |
531 | end |
532 | |
533 | specify '#set_published_at <=now should change the publication time and remove any trigger' do |
534 | stop_the_clock |
535 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
536 | should_set_content_field :published_at => Time.now - 10 |
537 | should_change_state_to :just_published |
538 | |
539 | @state.set_published_at(@content, Time.now - 10) |
540 | end |
541 | |
542 | specify '#set_published_at <= nil should nil the publication time and change state to Draft' do |
543 | Trigger.should_receive(:remove).with(@content, :trigger_method => 'publish!') |
544 | should_set_content_field :published_at => nil |
545 | should_change_state_to :draft |
546 | |
547 | @state.set_published_at(@content, nil) |
548 | end |
549 | |
550 | specify '#send_notifications should not send notifications' do |
551 | @content.should_not_receive(:anything) |
552 | @state.send_notifications(@content) |
553 | end |
554 | |
555 | specify '#send_pings should not call back to @content.really_send_pings' do |
556 | @content.should_not_receive(:really_send_pings) |
557 | |
558 | @state.send_pings(@content) |
559 | end |
560 | end |
561 | |
562 | context 'With ContentState::Unclassified.instance and mock content' do |
563 | include ContentStateSpecHelper |
564 | |
565 | setup do |
566 | @content = mock('content') |
567 | @state = ContentState::Unclassified.instance |
568 | end |
569 | |
570 | specify 'state should stringify as "Unclassified"' do |
571 | @state.to_s.should == 'Unclassified' |
572 | end |
573 | |
574 | specify '#just_published? should be false' do |
575 | @state.should_not_be_just_published |
576 | end |
577 | |
578 | specify '#published? should force content classification' do |
579 | should_force_classification(:published?) |
580 | end |
581 | |
582 | specify '#just_changed_published_status? should be false' do |
583 | @state.just_changed_published_status?.should_be false |
584 | end |
585 | |
586 | specify '#mark_as_spam should change to JustMarkedAsSpam' do |
587 | should_change_state_to :just_marked_as_spam |
588 | @state.mark_as_spam(@content) |
589 | end |
590 | |
591 | specify '#mark_as_ham should change state to JustMarkedAsHam' do |
592 | should_change_state_to :just_marked_as_ham |
593 | @state.mark_as_ham(@content) |
594 | end |
595 | |
596 | |
597 | specify '#is_spam? should force content classification' do |
598 | should_force_classification(:is_spam?) |
599 | end |
600 | |
601 | specify '#enter_hook should set :published and :status_confirmed to false' do |
602 | should_set_content_fields :published => false, :status_confirmed => false |
603 | |
604 | @state.enter_hook(@content) |
605 | end |
606 | |
607 | specify '#before_save should force classification' do |
608 | should_force_classification(:before_save) |
609 | end |
610 | |
611 | specify '#after_save should not do anything' do |
612 | @content.should_not_receive(:anything) |
613 | @state.after_save(@content).should_be true |
614 | end |
615 | |
616 | specify '#send_notifications should not do anything' do |
617 | @content.should_not_receive(:anything) |
618 | @state.send_notifications(@content) |
619 | end |
620 | |
621 | specify '#send_pings should not do anything' do |
622 | @content.should_not_receive(:anything) |
623 | @state.send_pings(@content) |
624 | end |
625 | |
626 | def should_force_classification(state_method, expected_result = :ham) |
627 | @content.should_receive(:classify).and_return(expected_result) |
628 | new_state = case expected_result |
629 | when :ham; ContentState::JustPresumedHam.instance |
630 | when :spam; ContentState::JustPresumedSpam.instance |
631 | else ContentState::JustPresumedSpam.instance |
632 | end |
633 | @content.should_receive(:state=).and_return(new_state) |
634 | @state.send(state_method, @content) |
635 | end |
636 | |
637 | |
638 | |
639 | end |
640 | |
641 | context 'With ContentState::JustPresumedHam.instance and mock content' do |
642 | include ContentStateSpecHelper |
643 | |
644 | setup do |
645 | @content = mock('content') |
646 | @state = ContentState::JustPresumedHam.instance |
647 | end |
648 | |
649 | specify '#just_published? should be true' do |
650 | @state.should_be_just_published |
651 | end |
652 | |
653 | specify '#published? should be true' do |
654 | @state.should_be_published(@content) |
655 | end |
656 | |
657 | specify '#just_changed_published_status? should be true' do |
658 | @state.just_changed_published_status?.should_be true |
659 | end |
660 | |
661 | specify '#enter_hook should set :published to true and :status_confirmed to false' do |
662 | should_set_content_fields :published => true, :status_confirmed => false |
663 | |
664 | @state.enter_hook(@content) |
665 | end |
666 | |
667 | specify '#after_save should not do anything' do |
668 | @content.should_not_receive(:anything) |
669 | @state.after_save(@content).should_be true |
670 | end |
671 | |
672 | specify '#before_save should not do anything' do |
673 | @content.should_not_receive(:anything) |
674 | @state.before_save(@content).should_be true |
675 | end |
676 | |
677 | specify '#mark_as_spam should change state to ContentState::JustMarkedAsSpam' do |
678 | should_change_state_to :just_marked_as_spam |
679 | @state.mark_as_spam(@content) |
680 | end |
681 | |
682 | specify '#mark_as_ham should change state to ContentState::Ham' do |
683 | should_change_state_to :ham |
684 | @state.mark_as_ham(@content) |
685 | end |
686 | |
687 | specify 'state should stringify as "Ham?"' do |
688 | @state.to_s.should == 'Ham?' |
689 | end |
690 | |
691 | specify '#send_notifications should send notifications to interested users' do |
692 | @content.should_receive(:interested_users).and_return([:tom, :dick, :harry]) |
693 | @content.should_receive(:send_notification_to_user).with(:tom) |
694 | @content.should_receive(:send_notification_to_user).with(:dick) |
695 | @content.should_receive(:send_notification_to_user).with(:harry) |
696 | |
697 | @state.send_notifications(@content) |
698 | end |
699 | |
700 | specify '#send_pings should really send pings' do |
701 | @content.should_receive(:really_send_pings) |
702 | @state.send_pings(@content) |
703 | end |
704 | end |
705 | |
706 | |
707 | context 'With ContentState::PresumedHam.instance and mock content' do |
708 | include ContentStateSpecHelper |
709 | |
710 | setup do |
711 | @content = mock('content') |
712 | @state = ContentState::PresumedHam.instance |
713 | end |
714 | |
715 | specify '#just_published? should be false' do |
716 | @state.should_not_be_just_published |
717 | end |
718 | |
719 | specify '#published? should be true' do |
720 | @state.should_be_published(@content) |
721 | end |
722 | |
723 | specify '#just_changed_published_status? should be false' do |
724 | @state.just_changed_published_status?.should_be false |
725 | end |
726 | |
727 | specify '#enter_hook should set :published to true and :status_confirmed to false' do |
728 | should_set_content_fields :published => true, :status_confirmed => false |
729 | |
730 | @state.enter_hook(@content) |
731 | end |
732 | |
733 | specify '#after_save should not do anything' do |
734 | @content.should_not_receive(:anything) |
735 | @state.after_save(@content).should_be true |
736 | end |
737 | |
738 | specify '#before_save should not do anything' do |
739 | @content.should_not_receive(:anything) |
740 | @state.before_save(@content).should_be true |
741 | end |
742 | |
743 | specify '#mark_as_spam should change state to ContentState::JustMarkedAsSpam' do |
744 | should_change_state_to :just_marked_as_spam |
745 | @state.mark_as_spam(@content) |
746 | end |
747 | |
748 | specify '#mark_as_ham should change state to ContentState::Ham' do |
749 | should_change_state_to :ham |
750 | @state.mark_as_ham(@content) |
751 | end |
752 | |
753 | specify 'state should stringify as "Ham?"' do |
754 | @state.to_s.should == 'Ham?' |
755 | end |
756 | |
757 | specify '#send_notifications should not send any notifications' do |
758 | @content.should_not_receive(:anything) |
759 | @state.send_notifications(@content) |
760 | end |
761 | |
762 | specify '#send_pings should not send pings' do |
763 | @content.should_not_receive(:really_send_pings) |
764 | @state.send_pings(@content) |
765 | end |
766 | end |
767 | |
768 | context 'With ContentState::Ham.instance and mock content' do |
769 | include ContentStateSpecHelper |
770 | |
771 | setup do |
772 | @content = mock('content') |
773 | @state = ContentState::Ham.instance |
774 | end |
775 | |
776 | specify '#just_published? should be false' do |
777 | @state.should_not_be_just_published |
778 | end |
779 | |
780 | specify '#published? should be true' do |
781 | @state.should_be_published(@content) |
782 | end |
783 | |
784 | specify '#just_changed_published_status? should be false' do |
785 | @state.just_changed_published_status?.should_be false |
786 | end |
787 | |
788 | specify '#enter_hook should set :published and :status_confirmed to true' do |
789 | should_set_content_fields :published => true, :status_confirmed => true |
790 | |
791 | @state.enter_hook(@content) |
792 | end |
793 | |
794 | specify '#after_save should not do anything' do |
795 | @content.should_not_receive(:anything) |
796 | @state.after_save(@content).should_be true |
797 | end |
798 | |
799 | specify '#before_save should not do anything' do |
800 | @content.should_receive(:report_as_ham) |
801 | @state.before_save(@content).should_be true |
802 | end |
803 | |
804 | specify '#mark_as_spam should change state to ContentState::JustMarkedAsSpam' do |
805 | should_change_state_to :just_marked_as_spam |
806 | @state.mark_as_spam(@content) |
807 | end |
808 | |
809 | specify '#mark_as_ham should not do anything' do |
810 | @content.should_not_receive(:anything) |
811 | @state.mark_as_ham(@content) |
812 | end |
813 | |
814 | specify 'state should stringify as "Ham"' do |
815 | @state.to_s.should == 'Ham' |
816 | end |
817 | |
818 | specify '#send_notifications should not send any notifications' do |
819 | @content.should_not_receive(:anything) |
820 | @state.send_notifications(@content) |
821 | end |
822 | |
823 | specify '#send_pings should not send pings' do |
824 | @content.should_not_receive(:really_send_pings) |
825 | @state.send_pings(@content) |
826 | end |
827 | end |
828 | |
829 | context 'With ContentState::PresumedSpam.instance and mock content' do |
830 | include ContentStateSpecHelper |
831 | |
832 | setup do |
833 | @content = mock('content') |
834 | @state = ContentState::PresumedSpam.instance |
835 | end |
836 | |
837 | specify '#just_published? should be false' do |
838 | @state.should_not_be_just_published |
839 | end |
840 | |
841 | specify '#published? should be false' do |
842 | @state.should_not_be_published(@content) |
843 | end |
844 | |
845 | specify '#just_changed_published_status? should be false' do |
846 | @state.just_changed_published_status?.should_be false |
847 | end |
848 | |
849 | specify '#enter_hook should set :published and :status_confirmed to false' do |
850 | should_set_content_fields :published => false, :status_confirmed => false |
851 | |
852 | @state.enter_hook(@content) |
853 | end |
854 | |
855 | specify '#after_save should not do anything' do |
856 | @content.should_not_receive(:anything) |
857 | @state.after_save(@content).should_be true |
858 | end |
859 | |
860 | specify '#before_save should not do anything' do |
861 | @content.should_not_receive(:anything) |
862 | @state.before_save(@content).should_be true |
863 | end |
864 | |
865 | specify '#mark_as_spam should change state to ContentState::Spam' do |
866 | should_change_state_to :spam |
867 | @state.mark_as_spam(@content) |
868 | end |
869 | |
870 | specify '#mark_as_ham should change state to ContentState::JustMarkedAsHam' do |
871 | should_change_state_to :just_marked_as_ham |
872 | @state.mark_as_ham(@content) |
873 | end |
874 | |
875 | specify 'state should stringify as "Spam?"' do |
876 | @state.to_s.should == 'Spam?' |
877 | end |
878 | |
879 | specify '#send_notifications should not send any notifications' do |
880 | @content.should_not_receive(:anything) |
881 | @state.send_notifications(@content) |
882 | end |
883 | |
884 | specify '#send_pings should not send pings' do |
885 | @content.should_not_receive(:really_send_pings) |
886 | @state.send_pings(@content) |
887 | end |
888 | end |
889 | |
890 | context 'With ContentState::JustMarkedAsSpam.instance and mock content' do |
891 | include ContentStateSpecHelper |
892 | |
893 | setup do |
894 | @content = mock('content') |
895 | @state = ContentState::JustMarkedAsSpam.instance |
896 | end |
897 | |
898 | specify '#just_published? should be false' do |
899 | @state.should_not_be_just_published |
900 | end |
901 | |
902 | specify '#published? should be false' do |
903 | @state.should_not_be_published(@content) |
904 | end |
905 | |
906 | specify '#just_changed_published_status? should be true' do |
907 | @state.just_changed_published_status?.should_be true |
908 | end |
909 | |
910 | specify '#enter_hook should set :published false and :status_confirmed to true' do |
911 | should_set_content_fields :published => false, :status_confirmed => true |
912 | |
913 | @state.enter_hook(@content) |
914 | end |
915 | |
916 | specify '#after_save should report the feedback as spam' do |
917 | @content.should_receive(:report_as_spam) |
918 | @state.after_save(@content).should_be true |
919 | end |
920 | |
921 | specify '#before_save should not do anything' do |
922 | @content.should_not_receive(:anything) |
923 | @state.before_save(@content).should_be true |
924 | end |
925 | |
926 | specify '#mark_as_spam should not do anything' do |
927 | @content.should_not_receive(:anything) |
928 | @state.mark_as_spam(@content) |
929 | end |
930 | |
931 | specify '#mark_as_ham should change state to ContentState::JustMarkedAsHam' do |
932 | should_change_state_to :just_marked_as_ham |
933 | @state.mark_as_ham(@content) |
934 | end |
935 | |
936 | specify 'state should stringify as "Spam"' do |
937 | @state.to_s.should == 'Spam' |
938 | end |
939 | |
940 | specify '#send_notifications should not send any notifications' do |
941 | @content.should_not_receive(:anything) |
942 | @state.send_notifications(@content) |
943 | end |
944 | |
945 | specify '#send_pings should not send pings' do |
946 | @content.should_not_receive(:really_send_pings) |
947 | @state.send_pings(@content) |
948 | end |
949 | end |
950 | |
951 | context 'With ContentState::Spam.instance and mock content' do |
952 | include ContentStateSpecHelper |
953 | |
954 | setup do |
955 | @content = mock('content') |
956 | @state = ContentState::Spam.instance |
957 | end |
958 | |
959 | specify '#just_published? should be false' do |
960 | @state.should_not_be_just_published |
961 | end |
962 | |
963 | specify '#published? should be false' do |
964 | @state.should_not_be_published(@content) |
965 | end |
966 | |
967 | specify '#just_changed_published_status? should be false' do |
968 | @state.just_changed_published_status?.should_be false |
969 | end |
970 | |
971 | specify '#enter_hook should set :published false and :status_confirmed to true' do |
972 | should_set_content_fields :published => false, :status_confirmed => true |
973 | |
974 | @state.enter_hook(@content) |
975 | end |
976 | |
977 | specify '#after_save should do nothing' do |
978 | @content.should_not_receive(:anything) |
979 | @state.after_save(@content).should_be true |
980 | end |
981 | |
982 | specify '#before_save should not do anything' do |
983 | @content.should_not_receive(:anything) |
984 | @state.before_save(@content).should_be true |
985 | end |
986 | |
987 | specify '#mark_as_spam should not do anything' do |
988 | @content.should_not_receive(:anything) |
989 | @state.mark_as_spam(@content) |
990 | end |
991 | |
992 | specify '#mark_as_ham should change state to ContentState::JustMarkedAsHam' do |
993 | should_change_state_to :just_marked_as_ham |
994 | @state.mark_as_ham(@content) |
995 | end |
996 | |
997 | specify 'state should stringify as "Spam"' do |
998 | @state.to_s.should == 'Spam' |
999 | end |
1000 | |
1001 | specify '#send_notifications should not send any notifications' do |
1002 | @content.should_not_receive(:anything) |
1003 | @state.send_notifications(@content) |
1004 | end |
1005 | |
1006 | specify '#send_pings should not send pings' do |
1007 | @content.should_not_receive(:really_send_pings) |
1008 | @state.send_pings(@content) |
1009 | end |
1010 | end |