mailboxer-without-notification 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +11 -0
  4. data/.yardopts +2 -0
  5. data/Appraisals +19 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +298 -0
  9. data/Rakefile +11 -0
  10. data/app/mailers/message_mailer.rb +37 -0
  11. data/app/models/conversation.rb +179 -0
  12. data/app/models/mailbox.rb +122 -0
  13. data/app/models/message.rb +218 -0
  14. data/app/models/receipt.rb +176 -0
  15. data/app/uploaders/attachment_uploader.rb +3 -0
  16. data/app/views/message_mailer/new_message_email.html.erb +20 -0
  17. data/app/views/message_mailer/new_message_email.text.erb +10 -0
  18. data/app/views/message_mailer/reply_message_email.html.erb +20 -0
  19. data/app/views/message_mailer/reply_message_email.text.erb +10 -0
  20. data/config/locales/en.yml +7 -0
  21. data/config/locales/fr.yml +7 -0
  22. data/db/migrate/20110511145103_create_mailboxer.rb +61 -0
  23. data/db/migrate/20110719110700_add_notified_object.rb +17 -0
  24. data/db/migrate/20110912163911_add_notification_code.rb +13 -0
  25. data/db/migrate/20111204163911_add_attachments.rb +9 -0
  26. data/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
  27. data/db/migrate/20130305144212_add_global_notification_support.rb +9 -0
  28. data/db/migrate/20131003144212_change_table_notification.rb +10 -0
  29. data/db/migrate/20131003214212_change_relations.rb +6 -0
  30. data/gemfiles/rails3.0.gemfile +8 -0
  31. data/gemfiles/rails3.1.gemfile +8 -0
  32. data/gemfiles/rails3.2.gemfile +8 -0
  33. data/gemfiles/rails4.0.gemfile +8 -0
  34. data/lib/generators/mailboxer/install_generator.rb +35 -0
  35. data/lib/generators/mailboxer/templates/initializer.rb +17 -0
  36. data/lib/generators/mailboxer/views_generator.rb +9 -0
  37. data/lib/mailboxer.rb +37 -0
  38. data/lib/mailboxer/concerns/configurable_mailer.rb +13 -0
  39. data/lib/mailboxer/engine.rb +17 -0
  40. data/lib/mailboxer/models/messageable.rb +225 -0
  41. data/mailboxer.gemspec +49 -0
  42. data/spec/dummy/.gitignore +5 -0
  43. data/spec/dummy/Gemfile +33 -0
  44. data/spec/dummy/Rakefile +7 -0
  45. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  46. data/spec/dummy/app/controllers/home_controller.rb +4 -0
  47. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  48. data/spec/dummy/app/mailers/.gitkeep +0 -0
  49. data/spec/dummy/app/models/.gitkeep +0 -0
  50. data/spec/dummy/app/models/cylon.rb +7 -0
  51. data/spec/dummy/app/models/duck.rb +11 -0
  52. data/spec/dummy/app/models/user.rb +6 -0
  53. data/spec/dummy/app/views/home/index.html.haml +7 -0
  54. data/spec/dummy/app/views/layouts/application.html.haml +11 -0
  55. data/spec/dummy/config.ru +4 -0
  56. data/spec/dummy/config/application.rb +42 -0
  57. data/spec/dummy/config/boot.rb +10 -0
  58. data/spec/dummy/config/database.yml +24 -0
  59. data/spec/dummy/config/environment.rb +5 -0
  60. data/spec/dummy/config/environments/development.rb +26 -0
  61. data/spec/dummy/config/environments/production.rb +49 -0
  62. data/spec/dummy/config/environments/test.rb +33 -0
  63. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/spec/dummy/config/initializers/inflections.rb +10 -0
  65. data/spec/dummy/config/initializers/mailboxer.rb +17 -0
  66. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  67. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  68. data/spec/dummy/config/initializers/session_store.rb +8 -0
  69. data/spec/dummy/config/locales/en.yml +5 -0
  70. data/spec/dummy/config/routes.rb +58 -0
  71. data/spec/dummy/config/sunspot.yml +17 -0
  72. data/spec/dummy/db/migrate/20110228120600_create_users.rb +14 -0
  73. data/spec/dummy/db/migrate/20110306002940_create_ducks.rb +14 -0
  74. data/spec/dummy/db/migrate/20110306015107_create_cylons.rb +14 -0
  75. data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +61 -0
  76. data/spec/dummy/db/migrate/20120305103201_add_notified_object.rb +17 -0
  77. data/spec/dummy/db/migrate/20120305103202_add_notification_code.rb +13 -0
  78. data/spec/dummy/db/migrate/20120305103203_add_attachments.rb +5 -0
  79. data/spec/dummy/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
  80. data/spec/dummy/db/migrate/20130305144212_add_global_notification_support.rb +11 -0
  81. data/spec/dummy/db/migrate/20131003144212_change_table_notification.rb +10 -0
  82. data/spec/dummy/db/migrate/20131003214212_change_relations.rb +6 -0
  83. data/spec/dummy/db/schema.rb +74 -0
  84. data/spec/dummy/public/404.html +26 -0
  85. data/spec/dummy/public/422.html +26 -0
  86. data/spec/dummy/public/500.html +26 -0
  87. data/spec/dummy/public/favicon.ico +0 -0
  88. data/spec/dummy/public/index.html +239 -0
  89. data/spec/dummy/public/robots.txt +5 -0
  90. data/spec/dummy/public/uploads/testfile.txt +1 -0
  91. data/spec/dummy/script/rails +6 -0
  92. data/spec/factories/cylon.rb +10 -0
  93. data/spec/factories/duck.rb +10 -0
  94. data/spec/factories/user.rb +10 -0
  95. data/spec/integration/message_and_receipt_spec.rb +903 -0
  96. data/spec/integration/navigation_spec.rb +9 -0
  97. data/spec/mailboxer/concerns/configurable_mailer_spec.rb +27 -0
  98. data/spec/mailboxer_spec.rb +7 -0
  99. data/spec/mailers/message_mailer_spec.rb +109 -0
  100. data/spec/models/conversation_spec.rb +154 -0
  101. data/spec/models/mailbox_spec.rb +160 -0
  102. data/spec/models/mailboxer_models_messageable_spec.rb +324 -0
  103. data/spec/models/message_spec.rb +222 -0
  104. data/spec/models/receipt_spec.rb +56 -0
  105. data/spec/spec_helper.rb +36 -0
  106. data/spec/testfile.txt +1 -0
  107. metadata +301 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1 @@
1
+ this is a dummy file to test file uploads
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :cylon do
3
+ sequence :name do |n|
4
+ "Cylon #{ n }"
5
+ end
6
+ sequence :email do |n|
7
+ "cylon#{ n }@cylon.com"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :duck do
3
+ sequence :name do |n|
4
+ "Duck #{ n }"
5
+ end
6
+ sequence :email do |n|
7
+ "duck#{ n }@duck.com"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ sequence :name do |n|
4
+ "User #{ n }"
5
+ end
6
+ sequence :email do |n|
7
+ "user#{ n }@user.com"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,903 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Messages And Receipts" do
4
+
5
+ describe "two equal entities" do
6
+ before do
7
+ @entity1 = FactoryGirl.create(:user)
8
+ @entity2 = FactoryGirl.create(:user)
9
+ end
10
+
11
+ describe "message sending" do
12
+
13
+ before do
14
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
15
+ @message1 = @receipt1.message
16
+ end
17
+
18
+ it "should create proper message" do
19
+ @message1.sender.id.should == @entity1.id
20
+ @message1.sender.class.should == @entity1.class
21
+ assert @message1.body.eql?"Body"
22
+ assert @message1.subject.eql?"Subject"
23
+ end
24
+
25
+ it "should create proper mails" do
26
+ #Sender Mail
27
+ mail = Receipt.recipient(@entity1).message(@message1).first
28
+ assert mail
29
+ if mail
30
+ mail.is_read.should==true
31
+ mail.trashed.should==false
32
+ mail.mailbox_type.should=="sentbox"
33
+ end
34
+ #Receiver Mail
35
+ mail = Receipt.recipient(@entity2).message(@message1).first
36
+ assert mail
37
+ if mail
38
+ mail.is_read.should==false
39
+ mail.trashed.should==false
40
+ mail.mailbox_type.should=="inbox"
41
+ end
42
+ end
43
+
44
+ it "should have the correct recipients" do
45
+ recipients = @message1.recipients
46
+ recipients.count.should==2
47
+ recipients.count(@entity1).should==1
48
+ recipients.count(@entity2).should==1
49
+ end
50
+
51
+ end
52
+
53
+ describe "message replying to sender" do
54
+ before do
55
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
56
+ @receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
57
+ @message1 = @receipt1.message
58
+ @message2 = @receipt2.message
59
+ end
60
+
61
+ it "should create proper message" do
62
+ @message2.sender.id.should == @entity2.id
63
+ @message2.sender.class.should == @entity2.class
64
+ assert @message2.body.eql?"Reply body"
65
+ assert @message2.subject.eql?"RE: Subject"
66
+ end
67
+
68
+ it "should create proper mails" do
69
+ #Sender Mail
70
+ mail = Receipt.recipient(@entity2).message(@message2).first
71
+ assert mail
72
+ if mail
73
+ mail.is_read.should==true
74
+ mail.trashed.should==false
75
+ mail.mailbox_type.should=="sentbox"
76
+ end
77
+ #Receiver Mail
78
+ mail = Receipt.recipient(@entity1).message(@message2).first
79
+ assert mail
80
+ if mail
81
+ mail.is_read.should==false
82
+ mail.trashed.should==false
83
+ mail.mailbox_type.should=="inbox"
84
+ end
85
+ end
86
+
87
+ it "should have the correct recipients" do
88
+ recipients = @message2.recipients
89
+ recipients.count.should==2
90
+ recipients.count(@entity1).should==1
91
+ recipients.count(@entity2).should==1
92
+ end
93
+
94
+ it "should be associated to the same conversation" do
95
+ @message1.conversation.id.should==@message2.conversation.id
96
+ end
97
+ end
98
+
99
+ describe "message replying to all" do
100
+ before do
101
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
102
+ @receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
103
+ @message1 = @receipt1.message
104
+ @message2 = @receipt2.message
105
+ end
106
+
107
+ it "should create proper message" do
108
+ @message2.sender.id.should == @entity2.id
109
+ @message2.sender.class.should == @entity2.class
110
+ assert @message2.body.eql?"Reply body"
111
+ assert @message2.subject.eql?"RE: Subject"
112
+ end
113
+
114
+ it "should create proper mails" do
115
+ #Sender Mail
116
+ mail = Receipt.recipient(@entity2).message(@message2).first
117
+ assert mail
118
+ if mail
119
+ mail.is_read.should==true
120
+ mail.trashed.should==false
121
+ mail.mailbox_type.should=="sentbox"
122
+ end
123
+ #Receiver Mail
124
+ mail = Receipt.recipient(@entity1).message(@message2).first
125
+ assert mail
126
+ if mail
127
+ mail.is_read.should==false
128
+ mail.trashed.should==false
129
+ mail.mailbox_type.should=="inbox"
130
+ end
131
+ end
132
+
133
+ it "should have the correct recipients" do
134
+ recipients = @message2.recipients
135
+ recipients.count.should==2
136
+ recipients.count(@entity1).should==1
137
+ recipients.count(@entity2).should==1
138
+ end
139
+
140
+ it "should be associated to the same conversation" do
141
+ @message1.conversation.id.should==@message2.conversation.id
142
+ end
143
+ end
144
+ describe "message replying to conversation" do
145
+ before do
146
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
147
+ @receipt2 = @entity2.reply_to_conversation(@receipt1.conversation,"Reply body")
148
+ @message1 = @receipt1.message
149
+ @message2 = @receipt2.message
150
+ end
151
+
152
+ it "should create proper message" do
153
+ @message2.sender.id.should == @entity2.id
154
+ @message2.sender.class.should == @entity2.class
155
+ assert @message2.body.eql?"Reply body"
156
+ assert @message2.subject.eql?"RE: Subject"
157
+ end
158
+
159
+ it "should create proper mails" do
160
+ #Sender Mail
161
+ mail = Receipt.recipient(@entity2).message(@message2).first
162
+ assert mail
163
+ if mail
164
+ mail.is_read.should==true
165
+ mail.trashed.should==false
166
+ mail.mailbox_type.should=="sentbox"
167
+ end
168
+ #Receiver Mail
169
+ mail = Receipt.recipient(@entity1).message(@message2).first
170
+ assert mail
171
+ if mail
172
+ mail.is_read.should==false
173
+ mail.trashed.should==false
174
+ mail.mailbox_type.should=="inbox"
175
+ end
176
+ end
177
+
178
+ it "should have the correct recipients" do
179
+ recipients = @message2.recipients
180
+ recipients.count.should==2
181
+ recipients.count(@entity1).should==1
182
+ recipients.count(@entity2).should==1
183
+ end
184
+
185
+ it "should be associated to the same conversation" do
186
+ @message1.conversation.id.should==@message2.conversation.id
187
+ end
188
+ end
189
+ end
190
+
191
+ describe "two different entities" do
192
+ before do
193
+ @entity1 = FactoryGirl.create(:user)
194
+ @entity2 = FactoryGirl.create(:duck)
195
+ end
196
+
197
+ describe "message sending" do
198
+
199
+ before do
200
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
201
+ @message1 = @receipt1.message
202
+ end
203
+
204
+ it "should create proper message" do
205
+ @message1.sender.id.should == @entity1.id
206
+ @message1.sender.class.should == @entity1.class
207
+ assert @message1.body.eql?"Body"
208
+ assert @message1.subject.eql?"Subject"
209
+ end
210
+
211
+ it "should create proper mails" do
212
+ #Sender Mail
213
+ mail = Receipt.recipient(@entity1).message(@message1).first
214
+ assert mail
215
+ if mail
216
+ mail.is_read.should==true
217
+ mail.trashed.should==false
218
+ mail.mailbox_type.should=="sentbox"
219
+ end
220
+ #Receiver Mail
221
+ mail = Receipt.recipient(@entity2).message(@message1).first
222
+ assert mail
223
+ if mail
224
+ mail.is_read.should==false
225
+ mail.trashed.should==false
226
+ mail.mailbox_type.should=="inbox"
227
+ end
228
+ end
229
+
230
+ it "should have the correct recipients" do
231
+ recipients = @message1.recipients
232
+ recipients.count.should==2
233
+ recipients.count(@entity1).should==1
234
+ recipients.count(@entity2).should==1
235
+ end
236
+
237
+ end
238
+
239
+ describe "message replying to sender" do
240
+ before do
241
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
242
+ @receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
243
+ @message1 = @receipt1.message
244
+ @message2 = @receipt2.message
245
+ end
246
+
247
+ it "should create proper message" do
248
+ @message2.sender.id.should == @entity2.id
249
+ @message2.sender.class.should == @entity2.class
250
+ assert @message2.body.eql?"Reply body"
251
+ assert @message2.subject.eql?"RE: Subject"
252
+ end
253
+
254
+ it "should create proper mails" do
255
+ #Sender Mail
256
+ mail = Receipt.recipient(@entity2).message(@message2).first
257
+ assert mail
258
+ if mail
259
+ mail.is_read.should==true
260
+ mail.trashed.should==false
261
+ mail.mailbox_type.should=="sentbox"
262
+ end
263
+ #Receiver Mail
264
+ mail = Receipt.recipient(@entity1).message(@message2).first
265
+ assert mail
266
+ if mail
267
+ mail.is_read.should==false
268
+ mail.trashed.should==false
269
+ mail.mailbox_type.should=="inbox"
270
+ end
271
+ end
272
+
273
+ it "should have the correct recipients" do
274
+ recipients = @message2.recipients
275
+ recipients.count.should==2
276
+ recipients.count(@entity1).should==1
277
+ recipients.count(@entity2).should==1
278
+ end
279
+
280
+ it "should be associated to the same conversation" do
281
+ @message1.conversation.id.should==@message2.conversation.id
282
+ end
283
+ end
284
+
285
+ describe "message replying to all" do
286
+ before do
287
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
288
+ @receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
289
+ @message1 = @receipt1.message
290
+ @message2 = @receipt2.message
291
+ end
292
+
293
+ it "should create proper message" do
294
+ @message2.sender.id.should == @entity2.id
295
+ @message2.sender.class.should == @entity2.class
296
+ assert @message2.body.eql?"Reply body"
297
+ assert @message2.subject.eql?"RE: Subject"
298
+ end
299
+
300
+ it "should create proper mails" do
301
+ #Sender Mail
302
+ mail = Receipt.recipient(@entity2).message(@message2).first
303
+ assert mail
304
+ if mail
305
+ mail.is_read.should==true
306
+ mail.trashed.should==false
307
+ mail.mailbox_type.should=="sentbox"
308
+ end
309
+ #Receiver Mail
310
+ mail = Receipt.recipient(@entity1).message(@message2).first
311
+ assert mail
312
+ if mail
313
+ mail.is_read.should==false
314
+ mail.trashed.should==false
315
+ mail.mailbox_type.should=="inbox"
316
+ end
317
+ end
318
+
319
+ it "should have the correct recipients" do
320
+ recipients = @message2.recipients
321
+ recipients.count.should==2
322
+ recipients.count(@entity1).should==1
323
+ recipients.count(@entity2).should==1
324
+ end
325
+
326
+ it "should be associated to the same conversation" do
327
+ @message1.conversation.id.should==@message2.conversation.id
328
+ end
329
+ end
330
+ describe "message replying to conversation (TODO)" do
331
+ before do
332
+ #TODO
333
+ end
334
+
335
+ it "should create proper message" do
336
+ #TODO
337
+ end
338
+
339
+ it "should create proper mails" do
340
+ #TODO
341
+ end
342
+
343
+ it "should have the correct recipients" do
344
+ #TODO
345
+ end
346
+
347
+ it "should be associated to the same conversation" do
348
+ #TODO
349
+ end
350
+ end
351
+ end
352
+
353
+ describe "three equal entities" do
354
+ before do
355
+ @entity1 = FactoryGirl.create(:user)
356
+ @entity2 = FactoryGirl.create(:user)
357
+ @entity3 = FactoryGirl.create(:user)
358
+ @recipients = Array.new
359
+ @recipients << @entity2
360
+ @recipients << @entity3
361
+ end
362
+
363
+ describe "message sending" do
364
+
365
+ before do
366
+ @receipt1 = @entity1.send_message(@recipients,"Body","Subject")
367
+ @message1 = @receipt1.message
368
+ end
369
+
370
+ it "should create proper message" do
371
+ @message1.sender.id.should == @entity1.id
372
+ @message1.sender.class.should == @entity1.class
373
+ assert @message1.body.eql?"Body"
374
+ assert @message1.subject.eql?"Subject"
375
+ end
376
+
377
+ it "should create proper mails" do
378
+ #Sender Mail
379
+ mail = Receipt.recipient(@entity1).message(@message1).first
380
+ assert mail
381
+ if mail
382
+ mail.is_read.should==true
383
+ mail.trashed.should==false
384
+ mail.mailbox_type.should=="sentbox"
385
+ end
386
+ #Receiver Mails
387
+ @recipients.each do |receiver|
388
+ mail = Receipt.recipient(receiver).message(@message1).first
389
+ assert mail
390
+ if mail
391
+ mail.is_read.should==false
392
+ mail.trashed.should==false
393
+ mail.mailbox_type.should=="inbox"
394
+ end
395
+ end
396
+ end
397
+
398
+ it "should have the correct recipients" do
399
+ recipients = @message1.recipients
400
+ recipients.count.should==3
401
+ recipients.count(@entity1).should==1
402
+ recipients.count(@entity2).should==1
403
+ recipients.count(@entity3).should==1
404
+ end
405
+
406
+ end
407
+
408
+ describe "message replying to sender" do
409
+ before do
410
+ @receipt1 = @entity1.send_message(@recipients,"Body","Subject")
411
+ @receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
412
+ @message1 = @receipt1.message
413
+ @message2 = @receipt2.message
414
+ end
415
+
416
+ it "should create proper message" do
417
+ @message2.sender.id.should == @entity2.id
418
+ @message2.sender.class.should == @entity2.class
419
+ assert @message2.body.eql?"Reply body"
420
+ assert @message2.subject.eql?"RE: Subject"
421
+ end
422
+
423
+ it "should create proper mails" do
424
+ #Sender Mail
425
+ mail = Receipt.recipient(@entity2).message(@message2).first
426
+ assert mail
427
+ if mail
428
+ mail.is_read.should==true
429
+ mail.trashed.should==false
430
+ mail.mailbox_type.should=="sentbox"
431
+ end
432
+ #Receiver Mail
433
+ mail = Receipt.recipient(@entity1).message(@message2).first
434
+ assert mail
435
+ if mail
436
+ mail.is_read.should==false
437
+ mail.trashed.should==false
438
+ mail.mailbox_type.should=="inbox"
439
+ end
440
+
441
+ #No Receiver, No Mail
442
+ mail = Receipt.recipient(@entity3).message(@message2).first
443
+ assert mail.nil?
444
+
445
+ end
446
+
447
+ it "should have the correct recipients" do
448
+ recipients = @message2.recipients
449
+ recipients.count.should==2
450
+ recipients.count(@entity1).should==1
451
+ recipients.count(@entity2).should==1
452
+ recipients.count(@entity3).should==0
453
+ end
454
+
455
+ it "should be associated to the same conversation" do
456
+ @message1.conversation.id.should==@message2.conversation.id
457
+ end
458
+ end
459
+
460
+ describe "message replying to all" do
461
+ before do
462
+ @receipt1 = @entity1.send_message(@recipients,"Body","Subject")
463
+ @receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
464
+ @message1 = @receipt1.message
465
+ @message2 = @receipt2.message
466
+ @recipients2 = Array.new
467
+ @recipients2 << @entity1
468
+ @recipients2 << @entity3
469
+
470
+ end
471
+
472
+ it "should create proper message" do
473
+ @message2.sender.id.should == @entity2.id
474
+ @message2.sender.class.should == @entity2.class
475
+ assert @message2.body.eql?"Reply body"
476
+ assert @message2.subject.eql?"RE: Subject"
477
+ end
478
+
479
+ it "should create proper mails" do
480
+ #Sender Mail
481
+ mail = Receipt.recipient(@entity2).message(@message2).first
482
+ assert mail
483
+ if mail
484
+ mail.is_read.should==true
485
+ mail.trashed.should==false
486
+ mail.mailbox_type.should=="sentbox"
487
+ end
488
+ #Receiver Mails
489
+ @recipients2.each do |receiver|
490
+ mail = Receipt.recipient(receiver).message(@message2).first
491
+ assert mail
492
+ if mail
493
+ mail.is_read.should==false
494
+ mail.trashed.should==false
495
+ mail.mailbox_type.should=="inbox"
496
+ end
497
+ end
498
+ end
499
+
500
+ it "should have the correct recipients" do
501
+ recipients = @message2.recipients
502
+ recipients.count.should==3
503
+ recipients.count(@entity1).should==1
504
+ recipients.count(@entity2).should==1
505
+ recipients.count(@entity3).should==1
506
+ end
507
+
508
+ it "should be associated to the same conversation" do
509
+ @message1.conversation.id.should==@message2.conversation.id
510
+ end
511
+ end
512
+ describe "message replying to conversation (TODO)" do
513
+ before do
514
+ #TODO
515
+ end
516
+
517
+ it "should create proper message" do
518
+ #TODO
519
+ end
520
+
521
+ it "should create proper mails" do
522
+ #TODO
523
+ end
524
+
525
+ it "should have the correct recipients" do
526
+ #TODO
527
+ end
528
+
529
+ it "should be associated to the same conversation" do
530
+ #TODO
531
+ end
532
+ end
533
+ end
534
+
535
+ describe "three different entities" do
536
+ before do
537
+ @entity1 = FactoryGirl.create(:user)
538
+ @entity2 = FactoryGirl.create(:duck)
539
+ @entity3 = FactoryGirl.create(:cylon)
540
+ @recipients = Array.new
541
+ @recipients << @entity2
542
+ @recipients << @entity3
543
+ end
544
+
545
+ describe "message sending" do
546
+
547
+ before do
548
+ @receipt1 = @entity1.send_message(@recipients,"Body","Subject")
549
+ @message1 = @receipt1.message
550
+ end
551
+
552
+ it "should create proper message" do
553
+ @message1.sender.id.should == @entity1.id
554
+ @message1.sender.class.should == @entity1.class
555
+ assert @message1.body.eql?"Body"
556
+ assert @message1.subject.eql?"Subject"
557
+ end
558
+
559
+ it "should create proper mails" do
560
+ #Sender Mail
561
+ mail = Receipt.recipient(@entity1).message(@message1).first
562
+ assert mail
563
+ if mail
564
+ mail.is_read.should==true
565
+ mail.trashed.should==false
566
+ mail.mailbox_type.should=="sentbox"
567
+ end
568
+ #Receiver Mails
569
+ @recipients.each do |receiver|
570
+ mail = Receipt.recipient(receiver).message(@message1).first
571
+ assert mail
572
+ if mail
573
+ mail.is_read.should==false
574
+ mail.trashed.should==false
575
+ mail.mailbox_type.should=="inbox"
576
+ end
577
+ end
578
+ end
579
+
580
+ it "should have the correct recipients" do
581
+ recipients = @message1.recipients
582
+ recipients.count.should==3
583
+ recipients.count(@entity1).should==1
584
+ recipients.count(@entity2).should==1
585
+ recipients.count(@entity3).should==1
586
+ end
587
+
588
+ end
589
+
590
+ describe "message replying to sender" do
591
+ before do
592
+ @receipt1 = @entity1.send_message(@recipients,"Body","Subject")
593
+ @receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
594
+ @message1 = @receipt1.message
595
+ @message2 = @receipt2.message
596
+ end
597
+
598
+ it "should create proper message" do
599
+ @message2.sender.id.should == @entity2.id
600
+ @message2.sender.class.should == @entity2.class
601
+ assert @message2.body.eql?"Reply body"
602
+ assert @message2.subject.eql?"RE: Subject"
603
+ end
604
+
605
+ it "should create proper mails" do
606
+ #Sender Mail
607
+ mail = Receipt.recipient(@entity2).message(@message2).first
608
+ assert mail
609
+ if mail
610
+ mail.is_read.should==true
611
+ mail.trashed.should==false
612
+ mail.mailbox_type.should=="sentbox"
613
+ end
614
+ #Receiver Mail
615
+ mail = Receipt.recipient(@entity1).message(@message2).first
616
+ assert mail
617
+ if mail
618
+ mail.is_read.should==false
619
+ mail.trashed.should==false
620
+ mail.mailbox_type.should=="inbox"
621
+ end
622
+
623
+ #No Receiver, No Mail
624
+ mail = Receipt.recipient(@entity3).message(@message2).first
625
+ assert mail.nil?
626
+
627
+ end
628
+
629
+ it "should have the correct recipients" do
630
+ recipients = @message2.recipients
631
+ recipients.count.should==2
632
+ recipients.count(@entity1).should==1
633
+ recipients.count(@entity2).should==1
634
+ recipients.count(@entity3).should==0
635
+ end
636
+
637
+ it "should be associated to the same conversation" do
638
+ @message1.conversation.id.should==@message2.conversation.id
639
+ end
640
+ end
641
+
642
+ describe "message replying to all" do
643
+ before do
644
+ @receipt1 = @entity1.send_message(@recipients,"Body","Subject")
645
+ @receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
646
+ @message1 = @receipt1.message
647
+ @message2 = @receipt2.message
648
+ @recipients2 = Array.new
649
+ @recipients2 << @entity1
650
+ @recipients2 << @entity3
651
+
652
+ end
653
+
654
+ it "should create proper message" do
655
+ @message2.sender.id.should == @entity2.id
656
+ @message2.sender.class.should == @entity2.class
657
+ assert @message2.body.eql?"Reply body"
658
+ assert @message2.subject.eql?"RE: Subject"
659
+ end
660
+
661
+ it "should create proper mails" do
662
+ #Sender Mail
663
+ mail = Receipt.recipient(@entity2).message(@message2).first
664
+ assert mail
665
+ if mail
666
+ mail.is_read.should==true
667
+ mail.trashed.should==false
668
+ mail.mailbox_type.should=="sentbox"
669
+ end
670
+ #Receiver Mails
671
+ @recipients2.each do |receiver|
672
+ mail = Receipt.recipient(receiver).message(@message2).first
673
+ assert mail
674
+ if mail
675
+ mail.is_read.should==false
676
+ mail.trashed.should==false
677
+ mail.mailbox_type.should=="inbox"
678
+ end
679
+ end
680
+ end
681
+
682
+ it "should have the correct recipients" do
683
+ recipients = @message2.recipients
684
+ recipients.count.should==3
685
+ recipients.count(@entity1).should==1
686
+ recipients.count(@entity2).should==1
687
+ recipients.count(@entity3).should==1
688
+ end
689
+
690
+ it "should be associated to the same conversation" do
691
+ @message1.conversation.id.should==@message2.conversation.id
692
+ end
693
+ end
694
+
695
+ describe "message replying to conversation (TODO)" do
696
+ before do
697
+ #TODO
698
+ end
699
+
700
+ it "should create proper message" do
701
+ #TODO
702
+ end
703
+
704
+ it "should create proper mails" do
705
+ #TODO
706
+ end
707
+
708
+ it "should have the correct recipients" do
709
+ #TODO
710
+ end
711
+
712
+ it "should be associated to the same conversation" do
713
+ #TODO
714
+ end
715
+ end
716
+ end
717
+
718
+ describe "two STI entities" do
719
+ before do
720
+ @entity1 = FactoryGirl.create(:user)
721
+ @entity2 = FactoryGirl.create(:user)
722
+ end
723
+
724
+ describe "message sending" do
725
+
726
+ before do
727
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
728
+ @message1 = @receipt1.message
729
+ end
730
+
731
+ it "should create proper message" do
732
+ @message1.sender.id.should == @entity1.id
733
+ @message1.sender.class.should == @entity1.class
734
+ assert @message1.body.eql?"Body"
735
+ assert @message1.subject.eql?"Subject"
736
+ end
737
+
738
+ it "should create proper mails" do
739
+ #Sender Mail
740
+ mail = Receipt.recipient(@entity1).message(@message1).first
741
+ assert mail
742
+ if mail
743
+ mail.is_read.should==true
744
+ mail.trashed.should==false
745
+ mail.mailbox_type.should=="sentbox"
746
+ end
747
+ #Receiver Mail
748
+ mail = Receipt.recipient(@entity2).message(@message1).first
749
+ assert mail
750
+ if mail
751
+ mail.is_read.should==false
752
+ mail.trashed.should==false
753
+ mail.mailbox_type.should=="inbox"
754
+ end
755
+ end
756
+
757
+ it "should have the correct recipients" do
758
+ recipients = @message1.recipients
759
+ recipients.count.should==2
760
+ recipients.count(@entity1).should==1
761
+ recipients.count(@entity2).should==1
762
+ end
763
+
764
+ end
765
+
766
+ describe "message replying to sender" do
767
+ before do
768
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
769
+ @receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
770
+ @message1 = @receipt1.message
771
+ @message2 = @receipt2.message
772
+ end
773
+
774
+ it "should create proper message" do
775
+ @message2.sender.id.should == @entity2.id
776
+ @message2.sender.class.should == @entity2.class
777
+ assert @message2.body.eql?"Reply body"
778
+ assert @message2.subject.eql?"RE: Subject"
779
+ end
780
+
781
+ it "should create proper mails" do
782
+ #Sender Mail
783
+ mail = Receipt.recipient(@entity2).message(@message2).first
784
+ assert mail
785
+ if mail
786
+ mail.is_read.should==true
787
+ mail.trashed.should==false
788
+ mail.mailbox_type.should=="sentbox"
789
+ end
790
+ #Receiver Mail
791
+ mail = Receipt.recipient(@entity1).message(@message2).first
792
+ assert mail
793
+ if mail
794
+ mail.is_read.should==false
795
+ mail.trashed.should==false
796
+ mail.mailbox_type.should=="inbox"
797
+ end
798
+ end
799
+
800
+ it "should have the correct recipients" do
801
+ recipients = @message2.recipients
802
+ recipients.count.should==2
803
+ recipients.count(@entity1).should==1
804
+ recipients.count(@entity2).should==1
805
+ end
806
+
807
+ it "should be associated to the same conversation" do
808
+ @message1.conversation.id.should==@message2.conversation.id
809
+ end
810
+ end
811
+
812
+ describe "message replying to all" do
813
+ before do
814
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
815
+ @receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
816
+ @message1 = @receipt1.message
817
+ @message2 = @receipt2.message
818
+ end
819
+
820
+ it "should create proper message" do
821
+ @message2.sender.id.should == @entity2.id
822
+ @message2.sender.class.should == @entity2.class
823
+ assert @message2.body.eql?"Reply body"
824
+ assert @message2.subject.eql?"RE: Subject"
825
+ end
826
+
827
+ it "should create proper mails" do
828
+ #Sender Mail
829
+ mail = Receipt.recipient(@entity2).message(@message2).first
830
+ assert mail
831
+ if mail
832
+ mail.is_read.should==true
833
+ mail.trashed.should==false
834
+ mail.mailbox_type.should=="sentbox"
835
+ end
836
+ #Receiver Mail
837
+ mail = Receipt.recipient(@entity1).message(@message2).first
838
+ assert mail
839
+ if mail
840
+ mail.is_read.should==false
841
+ mail.trashed.should==false
842
+ mail.mailbox_type.should=="inbox"
843
+ end
844
+ end
845
+
846
+ it "should have the correct recipients" do
847
+ recipients = @message2.recipients
848
+ recipients.count.should==2
849
+ recipients.count(@entity1).should==1
850
+ recipients.count(@entity2).should==1
851
+ end
852
+
853
+ it "should be associated to the same conversation" do
854
+ @message1.conversation.id.should==@message2.conversation.id
855
+ end
856
+ end
857
+ describe "message replying to conversation" do
858
+ before do
859
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
860
+ @receipt2 = @entity2.reply_to_conversation(@receipt1.conversation,"Reply body")
861
+ @message1 = @receipt1.message
862
+ @message2 = @receipt2.message
863
+ end
864
+
865
+ it "should create proper message" do
866
+ @message2.sender.id.should == @entity2.id
867
+ @message2.sender.class.should == @entity2.class
868
+ assert @message2.body.eql?"Reply body"
869
+ assert @message2.subject.eql?"RE: Subject"
870
+ end
871
+
872
+ it "should create proper mails" do
873
+ #Sender Mail
874
+ mail = Receipt.recipient(@entity2).message(@message2).first
875
+ assert mail
876
+ if mail
877
+ mail.is_read.should==true
878
+ mail.trashed.should==false
879
+ mail.mailbox_type.should=="sentbox"
880
+ end
881
+ #Receiver Mail
882
+ mail = Receipt.recipient(@entity1).message(@message2).first
883
+ assert mail
884
+ if mail
885
+ mail.is_read.should==false
886
+ mail.trashed.should==false
887
+ mail.mailbox_type.should=="inbox"
888
+ end
889
+ end
890
+
891
+ it "should have the correct recipients" do
892
+ recipients = @message2.recipients
893
+ recipients.count.should==2
894
+ recipients.count(@entity1).should==1
895
+ recipients.count(@entity2).should==1
896
+ end
897
+
898
+ it "should be associated to the same conversation" do
899
+ @message1.conversation.id.should==@message2.conversation.id
900
+ end
901
+ end
902
+ end
903
+ end