has_messages 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,431 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class MessageByDefaultTest < Test::Unit::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 < Test::Unit::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_equal 1, Array(message.errors.on(:sender_id)).size
40
+ end
41
+
42
+ def test_should_require_a_sender_type
43
+ message = new_message(:sender => nil)
44
+ assert !message.valid?
45
+ assert_equal 1, Array(message.errors.on(:sender_type)).size
46
+ end
47
+
48
+ def test_should_require_a_state
49
+ message = new_message(:state => nil)
50
+ assert !message.valid?
51
+ assert_equal 1, Array(message.errors.on(:state)).size
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
+ end
64
+
65
+ class MessageBeforeBeingCreatedTest < Test::Unit::TestCase
66
+ def setup
67
+ @message = new_message
68
+ end
69
+
70
+ def test_should_not_have_any_recipients
71
+ assert @message.recipients.empty?
72
+ end
73
+
74
+ def test_should_not_have_any_to_receivers
75
+ assert @message.to.empty?
76
+ end
77
+
78
+ def test_should_allow_to_receivers_to_be_built
79
+ user = create_user(:login => 'coward')
80
+ @message.to(user)
81
+ assert_equal [user], @message.to
82
+ end
83
+
84
+ def test_should_not_have_any_cc_receivers
85
+ assert @message.cc.empty?
86
+ end
87
+
88
+ def test_should_allow_cc_receivers_to_be_built
89
+ user = create_user(:login => 'coward')
90
+ @message.cc(user)
91
+ assert_equal [user], @message.cc
92
+ end
93
+
94
+ def test_should_not_have_any_bcc_receivers
95
+ assert @message.bcc.empty?
96
+ end
97
+
98
+ def test_should_allow_bcc_receivers_to_be_built
99
+ user = create_user(:login => 'coward')
100
+ @message.bcc(user)
101
+ assert_equal [user], @message.bcc
102
+ end
103
+ end
104
+
105
+ class MesageAfterBeingCreatedTest < Test::Unit::TestCase
106
+ def setup
107
+ @message = create_message
108
+ end
109
+
110
+ def test_should_record_when_it_was_created
111
+ assert_not_nil @message.created_at
112
+ end
113
+
114
+ def test_should_record_when_it_was_updated
115
+ assert_not_nil @message.updated_at
116
+ end
117
+
118
+ def test_should_not_have_any_recipients
119
+ assert @message.recipients.empty?
120
+ end
121
+
122
+ def test_should_not_have_any_to_receivers
123
+ assert @message.to.empty?
124
+ end
125
+
126
+ def test_should_allow_to_receivers_to_be_built
127
+ user = create_user(:login => 'coward')
128
+ @message.to(user)
129
+ assert_equal [user], @message.to
130
+ end
131
+
132
+ def test_should_not_have_any_cc_receivers
133
+ assert @message.cc.empty?
134
+ end
135
+
136
+ def test_should_allow_cc_receivers_to_be_built
137
+ user = create_user(:login => 'coward')
138
+ @message.cc(user)
139
+ assert_equal [user], @message.cc
140
+ end
141
+
142
+ def test_should_not_have_any_bcc_receivers
143
+ assert @message.bcc.empty?
144
+ end
145
+
146
+ def test_should_allow_bcc_receivers_to_be_built
147
+ user = create_user(:login => 'coward')
148
+ @message.bcc(user)
149
+ assert_equal [user], @message.bcc
150
+ end
151
+ end
152
+
153
+ class MessageWithoutRecipientsTest < Test::Unit::TestCase
154
+ def setup
155
+ @message = create_message
156
+ end
157
+
158
+ def test_should_not_be_able_to_queue
159
+ assert !@message.queue!
160
+ end
161
+
162
+ def test_should_not_be_able_to_deliver
163
+ assert !@message.deliver!
164
+ end
165
+ end
166
+
167
+ class MessageWithRecipientsTest < Test::Unit::TestCase
168
+ def setup
169
+ @erich = create_user(:login => 'Erich')
170
+ @richard = create_user(:login => 'Richard')
171
+ @ralph = create_user(:login => 'Ralph')
172
+ @message = create_message(
173
+ :to => @erich,
174
+ :cc => @richard,
175
+ :bcc => @ralph
176
+ )
177
+ end
178
+
179
+ def test_should_have_recipients
180
+ assert_equal 3, @message.recipients.count
181
+ end
182
+
183
+ def test_should_have_to_receivers
184
+ assert_equal [@erich], @message.to
185
+ end
186
+
187
+ def test_should_have_cc_receivers
188
+ assert_equal [@richard], @message.cc
189
+ end
190
+
191
+ def test_should_have_bcc_receivers
192
+ assert_equal [@ralph], @message.bcc
193
+ end
194
+
195
+ def test_should_be_able_to_queue
196
+ assert @message.queue!
197
+ end
198
+
199
+ def test_should_be_able_to_deliver
200
+ assert @message.deliver!
201
+ end
202
+ end
203
+
204
+ class MessageQueuedTest < Test::Unit::TestCase
205
+ def setup
206
+ @message = create_message(:to => create_user(:login => 'coward'))
207
+ @message.queue!
208
+ end
209
+
210
+ def test_should_be_in_the_queued_state
211
+ assert_equal 'queued', @message.state
212
+ end
213
+
214
+ def test_should_not_be_able_to_queue
215
+ assert !@message.queue!
216
+ end
217
+
218
+ def test_should_be_able_to_deliver
219
+ assert @message.deliver!
220
+ end
221
+ end
222
+
223
+ class MessageDeliveredTest < Test::Unit::TestCase
224
+ def setup
225
+ @message = create_message(:to => create_user(:login => 'coward'))
226
+ @message.deliver!
227
+ end
228
+
229
+ def test_should_be_in_the_sent_state
230
+ assert_equal 'sent', @message.state
231
+ end
232
+
233
+ def test_should_not_be_able_to_queue
234
+ assert !@message.queue!
235
+ end
236
+
237
+ def test_should_not_be_able_to_deliver
238
+ assert !@message.deliver!
239
+ end
240
+ end
241
+
242
+ class MessageHiddenTest < Test::Unit::TestCase
243
+ def setup
244
+ @message = create_message
245
+ @message.hide!
246
+ end
247
+
248
+ def test_should_record_when_it_was_hidden
249
+ assert_not_nil @message.hidden_at
250
+ end
251
+
252
+ def test_should_be_hidden
253
+ assert @message.hidden?
254
+ end
255
+ end
256
+
257
+ class MessageUnhiddenTest < Test::Unit::TestCase
258
+ def setup
259
+ @message = create_message
260
+ @message.hide!
261
+ @message.unhide!
262
+ end
263
+
264
+ def test_should_not_have_the_recorded_value_when_it_was_hidden
265
+ assert_nil @message.hidden_at
266
+ end
267
+
268
+ def test_should_not_be_hidden
269
+ assert !@message.hidden?
270
+ end
271
+ end
272
+
273
+ class MessageForwardedTest < Test::Unit::TestCase
274
+ def setup
275
+ @admin = create_user(:login => 'admin')
276
+ original_message = create_message(
277
+ :subject => 'Hello',
278
+ :body => 'How are you?',
279
+ :sender => @admin,
280
+ :to => create_user(:login => 'Erich'),
281
+ :cc => create_user(:login => 'Richard'),
282
+ :bcc => create_user(:login => 'Ralph')
283
+ )
284
+ @message = original_message.forward
285
+ end
286
+
287
+ def test_should_be_in_unsent_state
288
+ assert_equal 'unsent', @message.state
289
+ end
290
+
291
+ def test_should_not_be_hidden
292
+ assert !@message.hidden?
293
+ end
294
+
295
+ def test_should_have_original_subject
296
+ assert_equal 'Hello', @message.subject
297
+ end
298
+
299
+ def test_should_have_original_body
300
+ assert_equal 'How are you?', @message.body
301
+ end
302
+
303
+ def test_should_use_same_sender
304
+ assert_equal @admin, @message.sender
305
+ end
306
+
307
+ def test_should_not_include_to_recipients
308
+ assert @message.to.empty?
309
+ end
310
+
311
+ def test_should_not_include_cc_recipients
312
+ assert @message.cc.empty?
313
+ end
314
+
315
+ def test_should_not_include_bcc_recipients
316
+ assert @message.bcc.empty?
317
+ end
318
+ end
319
+
320
+ class MessageRepliedTest < Test::Unit::TestCase
321
+ def setup
322
+ @admin = create_user(:login => 'admin')
323
+ @erich = create_user(:login => 'Erich')
324
+ @richard = create_user(:login => 'Richard')
325
+ @ralph = create_user(:login => 'Ralph')
326
+
327
+ original_message = create_message(
328
+ :subject => 'Hello',
329
+ :body => 'How are you?',
330
+ :sender => @admin,
331
+ :to => @erich,
332
+ :cc => @richard,
333
+ :bcc => @ralph
334
+ )
335
+ @message = original_message.reply
336
+ end
337
+
338
+ def test_should_be_in_unsent_state
339
+ assert_equal 'unsent', @message.state
340
+ end
341
+
342
+ def test_should_not_be_hidden
343
+ assert !@message.hidden?
344
+ end
345
+
346
+ def test_should_have_original_subject
347
+ assert_equal 'Hello', @message.subject
348
+ end
349
+
350
+ def test_should_have_original_body
351
+ assert_equal 'How are you?', @message.body
352
+ end
353
+
354
+ def test_should_use_same_sender
355
+ assert_equal @admin, @message.sender
356
+ end
357
+
358
+ def test_should_use_same_to_recipients
359
+ assert_equal [@erich], @message.to
360
+ end
361
+
362
+ def test_should_not_include_cc_recipients
363
+ assert @message.cc.empty?
364
+ end
365
+
366
+ def test_should_not_include_bcc_recipients
367
+ assert @message.bcc.empty?
368
+ end
369
+ end
370
+
371
+ class MessageRepliedToAllTest < Test::Unit::TestCase
372
+ def setup
373
+ @admin = create_user(:login => 'admin')
374
+ @erich = create_user(:login => 'Erich')
375
+ @richard = create_user(:login => 'Richard')
376
+ @ralph = create_user(:login => 'Ralph')
377
+
378
+ original_message = create_message(
379
+ :subject => 'Hello',
380
+ :body => 'How are you?',
381
+ :sender => @admin,
382
+ :to => @erich,
383
+ :cc => @richard,
384
+ :bcc => @ralph
385
+ )
386
+ @message = original_message.reply_to_all
387
+ end
388
+
389
+ def test_should_be_in_unsent_state
390
+ assert_equal 'unsent', @message.state
391
+ end
392
+
393
+ def test_should_not_be_hidden
394
+ assert !@message.hidden?
395
+ end
396
+
397
+ def test_should_have_original_subject
398
+ assert_equal 'Hello', @message.subject
399
+ end
400
+
401
+ def test_should_have_original_body
402
+ assert_equal 'How are you?', @message.body
403
+ end
404
+
405
+ def test_should_use_same_sender
406
+ assert_equal @admin, @message.sender
407
+ end
408
+
409
+ def test_should_use_same_to_recipients
410
+ assert_equal [@erich], @message.to
411
+ end
412
+
413
+ def test_should_use_same_cc_recipients
414
+ assert_equal [@richard], @message.cc
415
+ end
416
+
417
+ def test_should_use_same_bcc_recipients
418
+ assert_equal [@ralph], @message.bcc
419
+ end
420
+ end
421
+
422
+ class MessageAsAClassTest < Test::Unit::TestCase
423
+ def setup
424
+ @hidden_message = create_message(:hidden_at => Time.now)
425
+ @visible_message = create_message
426
+ end
427
+
428
+ def test_should_include_only_visible_messages_in_visible_scope
429
+ assert_equal [@visible_message], Message.visible
430
+ end
431
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_messages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Pfeifer
8
+ autorequire: has_messages
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-05 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: state_machine
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.0
23
+ version:
24
+ description:
25
+ email: aaron@pluginaweek.org
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - app/models
34
+ - app/models/message.rb
35
+ - app/models/message_recipient.rb
36
+ - db/migrate
37
+ - db/migrate/002_create_message_recipients.rb
38
+ - db/migrate/001_create_messages.rb
39
+ - lib/has_messages.rb
40
+ - test/factory.rb
41
+ - test/app_root
42
+ - test/app_root/db
43
+ - test/app_root/db/migrate
44
+ - test/app_root/db/migrate/001_create_users.rb
45
+ - test/app_root/db/migrate/002_migrate_has_messages_to_version_2.rb
46
+ - test/app_root/config
47
+ - test/app_root/config/environment.rb
48
+ - test/app_root/app
49
+ - test/app_root/app/models
50
+ - test/app_root/app/models/user.rb
51
+ - test/functional
52
+ - test/functional/has_messages_test.rb
53
+ - test/test_helper.rb
54
+ - test/unit
55
+ - test/unit/message_test.rb
56
+ - test/unit/message_recipient_test.rb
57
+ - CHANGELOG
58
+ - init.rb
59
+ - MIT-LICENSE
60
+ - Rakefile
61
+ - README
62
+ has_rdoc: true
63
+ homepage: http://www.pluginaweek.org
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.1.0
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Demonstrates a reference implementation for sending messages between users.
88
+ test_files:
89
+ - test/functional/has_messages_test.rb
90
+ - test/unit/message_test.rb
91
+ - test/unit/message_recipient_test.rb