has_messages_huacnlee 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,465 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class MessageByDefaultTest < ActiveSupport::TestCase
4
- def setup
5
- @message = Message.new
6
- end
7
-
8
- def test_should_not_have_a_sender
9
- assert_nil @message.sender
10
- end
11
-
12
- def test_should_not_have_a_subject
13
- assert @message.subject.blank?
14
- end
15
-
16
- def test_should_not_have_a_body
17
- assert @message.body.blank?
18
- end
19
-
20
- def test_should_be_in_the_unsent_state
21
- assert_equal 'unsent', @message.state
22
- end
23
-
24
- def test_should_not_be_hidden
25
- assert_nil @message.hidden_at
26
- assert !@message.hidden?
27
- end
28
- end
29
-
30
- class MessageTest < ActiveSupport::TestCase
31
- def test_should_be_valid_with_a_set_of_valid_attributes
32
- message = new_message
33
- assert message.valid?
34
- end
35
-
36
- def test_should_require_a_sender_id
37
- message = new_message(:sender => nil)
38
- assert !message.valid?
39
- assert message.errors.invalid?(:sender_id)
40
- end
41
-
42
- def test_should_require_a_sender_type
43
- message = new_message(:sender => nil)
44
- assert !message.valid?
45
- assert message.errors.invalid?(:sender_type)
46
- end
47
-
48
- def test_should_require_a_state
49
- message = new_message(:state => nil)
50
- assert !message.valid?
51
- assert message.errors.invalid?(:state)
52
- end
53
-
54
- def test_should_not_require_a_subject
55
- message = new_message(:subject => nil)
56
- assert message.valid?
57
- end
58
-
59
- def test_should_not_require_a_body
60
- message = new_message(:body => nil)
61
- assert message.valid?
62
- end
63
-
64
- def test_should_protect_attributes_from_mass_assignment
65
- message = Message.new(
66
- :id => 1,
67
- :sender_id => 1,
68
- :sender_type => 'User',
69
- :subject => 'New features',
70
- :body => 'Find out more!',
71
- :to => [1, 2],
72
- :cc => [3, 4],
73
- :bcc => [5, 6],
74
- :state => 'sent',
75
- :hidden_at => Time.now
76
- )
77
-
78
- assert_nil message.id
79
- assert_nil message.sender_id
80
- assert message.sender_type.blank?
81
- assert_equal 'New features', message.subject
82
- assert_equal 'Find out more!', message.body
83
- assert_equal [1, 2], message.to
84
- assert_equal [3, 4], message.cc
85
- assert_equal [5, 6], message.bcc
86
- assert_equal 'unsent', message.state
87
- assert_nil message.hidden_at
88
- end
89
- end
90
-
91
- class MessageBeforeBeingCreatedTest < ActiveSupport::TestCase
92
- def setup
93
- @message = new_message
94
- end
95
-
96
- def test_should_not_have_any_recipients
97
- assert @message.recipients.empty?
98
- end
99
-
100
- def test_should_not_have_any_to_receivers
101
- assert @message.to.empty?
102
- end
103
-
104
- def test_should_allow_to_receivers_to_be_built
105
- user = create_user(:login => 'coward')
106
- @message.to(user)
107
- assert_equal [user], @message.to
108
- end
109
-
110
- def test_should_not_have_any_cc_receivers
111
- assert @message.cc.empty?
112
- end
113
-
114
- def test_should_allow_cc_receivers_to_be_built
115
- user = create_user(:login => 'coward')
116
- @message.cc(user)
117
- assert_equal [user], @message.cc
118
- end
119
-
120
- def test_should_not_have_any_bcc_receivers
121
- assert @message.bcc.empty?
122
- end
123
-
124
- def test_should_allow_bcc_receivers_to_be_built
125
- user = create_user(:login => 'coward')
126
- @message.bcc(user)
127
- assert_equal [user], @message.bcc
128
- end
129
- end
130
-
131
- class MesageAfterBeingCreatedTest < ActiveSupport::TestCase
132
- def setup
133
- @message = create_message
134
- end
135
-
136
- def test_should_record_when_it_was_created
137
- assert_not_nil @message.created_at
138
- end
139
-
140
- def test_should_record_when_it_was_updated
141
- assert_not_nil @message.updated_at
142
- end
143
-
144
- def test_should_not_have_any_recipients
145
- assert @message.recipients.empty?
146
- end
147
-
148
- def test_should_not_have_any_to_receivers
149
- assert @message.to.empty?
150
- end
151
-
152
- def test_should_allow_to_receivers_to_be_built
153
- user = create_user(:login => 'coward')
154
- @message.to(user)
155
- assert_equal [user], @message.to
156
- end
157
-
158
- def test_should_not_have_any_cc_receivers
159
- assert @message.cc.empty?
160
- end
161
-
162
- def test_should_allow_cc_receivers_to_be_built
163
- user = create_user(:login => 'coward')
164
- @message.cc(user)
165
- assert_equal [user], @message.cc
166
- end
167
-
168
- def test_should_not_have_any_bcc_receivers
169
- assert @message.bcc.empty?
170
- end
171
-
172
- def test_should_allow_bcc_receivers_to_be_built
173
- user = create_user(:login => 'coward')
174
- @message.bcc(user)
175
- assert_equal [user], @message.bcc
176
- end
177
- end
178
-
179
- class MessageWithoutRecipientsTest < ActiveSupport::TestCase
180
- def setup
181
- @message = create_message
182
- end
183
-
184
- def test_should_not_be_able_to_queue
185
- assert !@message.queue
186
- end
187
-
188
- def test_should_not_be_able_to_deliver
189
- assert !@message.deliver
190
- end
191
- end
192
-
193
- class MessageWithRecipientsTest < ActiveSupport::TestCase
194
- def setup
195
- @erich = create_user(:login => 'Erich')
196
- @richard = create_user(:login => 'Richard')
197
- @ralph = create_user(:login => 'Ralph')
198
- @message = create_message(
199
- :to => @erich,
200
- :cc => @richard,
201
- :bcc => @ralph
202
- )
203
- end
204
-
205
- def test_should_have_recipients
206
- assert_equal 3, @message.recipients.count
207
- end
208
-
209
- def test_should_have_to_receivers
210
- assert_equal [@erich], @message.to
211
- end
212
-
213
- def test_should_have_cc_receivers
214
- assert_equal [@richard], @message.cc
215
- end
216
-
217
- def test_should_have_bcc_receivers
218
- assert_equal [@ralph], @message.bcc
219
- end
220
-
221
- def test_should_be_able_to_queue
222
- assert @message.queue
223
- end
224
-
225
- def test_should_be_able_to_deliver
226
- assert @message.deliver
227
- end
228
- end
229
-
230
- class MessageQueuedTest < ActiveSupport::TestCase
231
- def setup
232
- @message = create_message(:to => create_user(:login => 'coward'))
233
- @message.queue
234
- end
235
-
236
- def test_should_be_in_the_queued_state
237
- assert_equal 'queued', @message.state
238
- end
239
-
240
- def test_should_not_be_able_to_queue
241
- assert !@message.queue
242
- end
243
-
244
- def test_should_be_able_to_deliver
245
- assert @message.deliver
246
- end
247
- end
248
-
249
- class MessageDeliveredTest < ActiveSupport::TestCase
250
- def setup
251
- @message = create_message(:to => create_user(:login => 'coward'))
252
- @message.deliver
253
- end
254
-
255
- def test_should_be_in_the_sent_state
256
- assert_equal 'sent', @message.state
257
- end
258
-
259
- def test_should_not_be_able_to_queue
260
- assert !@message.queue
261
- end
262
-
263
- def test_should_not_be_able_to_deliver
264
- assert !@message.deliver
265
- end
266
- end
267
-
268
- class MessageHiddenTest < ActiveSupport::TestCase
269
- def setup
270
- @message = create_message
271
- @message.hide
272
- end
273
-
274
- def test_should_record_when_it_was_hidden
275
- assert_not_nil @message.hidden_at
276
- end
277
-
278
- def test_should_be_hidden
279
- assert @message.hidden?
280
- end
281
-
282
- def test_should_not_be_visible
283
- assert !@message.visible?
284
- end
285
- end
286
-
287
- class MessageUnhiddenTest < ActiveSupport::TestCase
288
- def setup
289
- @message = create_message
290
- @message.hide
291
- @message.unhide
292
- end
293
-
294
- def test_should_not_have_the_recorded_value_when_it_was_hidden
295
- assert_nil @message.hidden_at
296
- end
297
-
298
- def test_should_not_be_hidden
299
- assert !@message.hidden?
300
- end
301
-
302
- def test_should_be_visible
303
- assert @message.visible?
304
- end
305
- end
306
-
307
- class MessageForwardedTest < ActiveSupport::TestCase
308
- def setup
309
- @admin = create_user(:login => 'admin')
310
- original_message = create_message(
311
- :subject => 'Hello',
312
- :body => 'How are you?',
313
- :sender => @admin,
314
- :to => create_user(:login => 'Erich'),
315
- :cc => create_user(:login => 'Richard'),
316
- :bcc => create_user(:login => 'Ralph')
317
- )
318
- @message = original_message.forward
319
- end
320
-
321
- def test_should_be_in_unsent_state
322
- assert_equal 'unsent', @message.state
323
- end
324
-
325
- def test_should_not_be_hidden
326
- assert !@message.hidden?
327
- end
328
-
329
- def test_should_have_original_subject
330
- assert_equal 'Hello', @message.subject
331
- end
332
-
333
- def test_should_have_original_body
334
- assert_equal 'How are you?', @message.body
335
- end
336
-
337
- def test_should_use_same_sender
338
- assert_equal @admin, @message.sender
339
- end
340
-
341
- def test_should_not_include_to_recipients
342
- assert @message.to.empty?
343
- end
344
-
345
- def test_should_not_include_cc_recipients
346
- assert @message.cc.empty?
347
- end
348
-
349
- def test_should_not_include_bcc_recipients
350
- assert @message.bcc.empty?
351
- end
352
- end
353
-
354
- class MessageRepliedTest < ActiveSupport::TestCase
355
- def setup
356
- @admin = create_user(:login => 'admin')
357
- @erich = create_user(:login => 'Erich')
358
- @richard = create_user(:login => 'Richard')
359
- @ralph = create_user(:login => 'Ralph')
360
-
361
- original_message = create_message(
362
- :subject => 'Hello',
363
- :body => 'How are you?',
364
- :sender => @admin,
365
- :to => @erich,
366
- :cc => @richard,
367
- :bcc => @ralph
368
- )
369
- @message = original_message.reply
370
- end
371
-
372
- def test_should_be_in_unsent_state
373
- assert_equal 'unsent', @message.state
374
- end
375
-
376
- def test_should_not_be_hidden
377
- assert !@message.hidden?
378
- end
379
-
380
- def test_should_have_original_subject
381
- assert_equal 'Hello', @message.subject
382
- end
383
-
384
- def test_should_have_original_body
385
- assert_equal 'How are you?', @message.body
386
- end
387
-
388
- def test_should_use_same_sender
389
- assert_equal @admin, @message.sender
390
- end
391
-
392
- def test_should_use_same_to_recipients
393
- assert_equal [@erich], @message.to
394
- end
395
-
396
- def test_should_not_include_cc_recipients
397
- assert @message.cc.empty?
398
- end
399
-
400
- def test_should_not_include_bcc_recipients
401
- assert @message.bcc.empty?
402
- end
403
- end
404
-
405
- class MessageRepliedToAllTest < ActiveSupport::TestCase
406
- def setup
407
- @admin = create_user(:login => 'admin')
408
- @erich = create_user(:login => 'Erich')
409
- @richard = create_user(:login => 'Richard')
410
- @ralph = create_user(:login => 'Ralph')
411
-
412
- original_message = create_message(
413
- :subject => 'Hello',
414
- :body => 'How are you?',
415
- :sender => @admin,
416
- :to => @erich,
417
- :cc => @richard,
418
- :bcc => @ralph
419
- )
420
- @message = original_message.reply_to_all
421
- end
422
-
423
- def test_should_be_in_unsent_state
424
- assert_equal 'unsent', @message.state
425
- end
426
-
427
- def test_should_not_be_hidden
428
- assert !@message.hidden?
429
- end
430
-
431
- def test_should_have_original_subject
432
- assert_equal 'Hello', @message.subject
433
- end
434
-
435
- def test_should_have_original_body
436
- assert_equal 'How are you?', @message.body
437
- end
438
-
439
- def test_should_use_same_sender
440
- assert_equal @admin, @message.sender
441
- end
442
-
443
- def test_should_use_same_to_recipients
444
- assert_equal [@erich], @message.to
445
- end
446
-
447
- def test_should_use_same_cc_recipients
448
- assert_equal [@richard], @message.cc
449
- end
450
-
451
- def test_should_use_same_bcc_recipients
452
- assert_equal [@ralph], @message.bcc
453
- end
454
- end
455
-
456
- class MessageAsAClassTest < ActiveSupport::TestCase
457
- def setup
458
- @hidden_message = create_message(:hidden_at => Time.now)
459
- @visible_message = create_message
460
- end
461
-
462
- def test_should_include_only_visible_messages_in_visible_scope
463
- assert_equal [@visible_message], Message.visible
464
- end
465
- end