curationexperts-mailboxer 0.10.3.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +10 -0
  5. data/.yardopts +2 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +273 -0
  9. data/Rakefile +7 -0
  10. data/app/mailers/message_mailer.rb +37 -0
  11. data/app/mailers/notification_mailer.rb +21 -0
  12. data/app/models/conversation.rb +143 -0
  13. data/app/models/mailbox.rb +121 -0
  14. data/app/models/message.rb +66 -0
  15. data/app/models/notification.rb +184 -0
  16. data/app/models/receipt.rb +151 -0
  17. data/app/uploaders/attachment_uploader.rb +3 -0
  18. data/app/views/message_mailer/new_message_email.html.erb +20 -0
  19. data/app/views/message_mailer/new_message_email.text.erb +10 -0
  20. data/app/views/message_mailer/reply_message_email.html.erb +20 -0
  21. data/app/views/message_mailer/reply_message_email.text.erb +10 -0
  22. data/app/views/notification_mailer/new_notification_email.html.erb +20 -0
  23. data/app/views/notification_mailer/new_notification_email.text.erb +10 -0
  24. data/config/locales/en.yml +7 -0
  25. data/db/migrate/20110511145103_create_mailboxer.rb +61 -0
  26. data/db/migrate/20110719110700_add_notified_object.rb +17 -0
  27. data/db/migrate/20110912163911_add_notification_code.rb +13 -0
  28. data/db/migrate/20111204163911_add_attachments.rb +9 -0
  29. data/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
  30. data/db/migrate/20130305144212_add_global_notification_support.rb +9 -0
  31. data/lib/generators/mailboxer/install_generator.rb +35 -0
  32. data/lib/generators/mailboxer/templates/initializer.rb +17 -0
  33. data/lib/generators/mailboxer/views_generator.rb +9 -0
  34. data/lib/mailboxer.rb +31 -0
  35. data/lib/mailboxer/concerns/configurable_mailer.rb +13 -0
  36. data/lib/mailboxer/engine.rb +18 -0
  37. data/lib/mailboxer/models/messageable.rb +208 -0
  38. data/mailboxer.gemspec +47 -0
  39. data/spec/dummy/.gitignore +5 -0
  40. data/spec/dummy/Gemfile +33 -0
  41. data/spec/dummy/Rakefile +7 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/controllers/home_controller.rb +4 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/mailers/.gitkeep +0 -0
  46. data/spec/dummy/app/models/.gitkeep +0 -0
  47. data/spec/dummy/app/models/cylon.rb +7 -0
  48. data/spec/dummy/app/models/duck.rb +11 -0
  49. data/spec/dummy/app/models/user.rb +6 -0
  50. data/spec/dummy/app/views/home/index.html.haml +7 -0
  51. data/spec/dummy/app/views/layouts/application.html.haml +11 -0
  52. data/spec/dummy/config.ru +4 -0
  53. data/spec/dummy/config/application.rb +42 -0
  54. data/spec/dummy/config/boot.rb +10 -0
  55. data/spec/dummy/config/database.yml +24 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +26 -0
  58. data/spec/dummy/config/environments/production.rb +49 -0
  59. data/spec/dummy/config/environments/test.rb +33 -0
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/spec/dummy/config/initializers/inflections.rb +10 -0
  62. data/spec/dummy/config/initializers/mailboxer.rb +17 -0
  63. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  64. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  65. data/spec/dummy/config/initializers/session_store.rb +8 -0
  66. data/spec/dummy/config/locales/en.yml +5 -0
  67. data/spec/dummy/config/routes.rb +58 -0
  68. data/spec/dummy/config/sunspot.yml +17 -0
  69. data/spec/dummy/db/migrate/20110228120600_create_users.rb +14 -0
  70. data/spec/dummy/db/migrate/20110306002940_create_ducks.rb +14 -0
  71. data/spec/dummy/db/migrate/20110306015107_create_cylons.rb +14 -0
  72. data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +61 -0
  73. data/spec/dummy/db/migrate/20120305103201_add_notified_object.rb +17 -0
  74. data/spec/dummy/db/migrate/20120305103202_add_notification_code.rb +13 -0
  75. data/spec/dummy/db/migrate/20120305103203_add_attachments.rb +5 -0
  76. data/spec/dummy/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
  77. data/spec/dummy/db/migrate/20130305144212_add_global_notification_support.rb +11 -0
  78. data/spec/dummy/db/schema.rb +74 -0
  79. data/spec/dummy/public/404.html +26 -0
  80. data/spec/dummy/public/422.html +26 -0
  81. data/spec/dummy/public/500.html +26 -0
  82. data/spec/dummy/public/favicon.ico +0 -0
  83. data/spec/dummy/public/index.html +239 -0
  84. data/spec/dummy/public/robots.txt +5 -0
  85. data/spec/dummy/public/uploads/testfile.txt +1 -0
  86. data/spec/dummy/script/rails +6 -0
  87. data/spec/factories/cylon.rb +10 -0
  88. data/spec/factories/duck.rb +10 -0
  89. data/spec/factories/user.rb +10 -0
  90. data/spec/integration/message_and_receipt_spec.rb +903 -0
  91. data/spec/integration/navigation_spec.rb +9 -0
  92. data/spec/mailboxer/concerns/configurable_mailer_spec.rb +27 -0
  93. data/spec/mailboxer_spec.rb +7 -0
  94. data/spec/mailers/message_mailer_spec.rb +110 -0
  95. data/spec/mailers/notification_mailer_spec.rb +61 -0
  96. data/spec/models/conversation_spec.rb +101 -0
  97. data/spec/models/mailbox_spec.rb +124 -0
  98. data/spec/models/mailboxer_models_messageable_spec.rb +315 -0
  99. data/spec/models/message_spec.rb +24 -0
  100. data/spec/models/notification_spec.rb +200 -0
  101. data/spec/models/receipt_spec.rb +44 -0
  102. data/spec/spec_helper.rb +36 -0
  103. data/spec/testfile.txt +1 -0
  104. metadata +263 -0
@@ -0,0 +1,315 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mailboxer::Models::Messageable through User" do
4
+
5
+ before do
6
+ @entity1 = FactoryGirl.create(:user)
7
+ @entity2 = FactoryGirl.create(:user)
8
+ end
9
+
10
+ it "should have a mailbox" do
11
+ assert @entity1.mailbox
12
+ end
13
+
14
+ it "should be able to send a message" do
15
+ assert @entity1.send_message(@entity2,"Body","Subject")
16
+ end
17
+
18
+ it "should be able to reply to sender" do
19
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
20
+ assert @entity2.reply_to_sender(@receipt,"Reply body")
21
+ end
22
+
23
+ it "should be able to reply to all" do
24
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
25
+ assert @entity2.reply_to_all(@receipt,"Reply body")
26
+ end
27
+
28
+
29
+
30
+ it "should be able to unread an owned Receipt (mark as unread)" do
31
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
32
+ @receipt.is_read.should==true
33
+ @entity1.mark_as_unread(@receipt)
34
+ @receipt.is_read.should==false
35
+ end
36
+
37
+ it "should be able to read an owned Receipt (mark as read)" do
38
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
39
+ @receipt.is_read.should==true
40
+ @entity1.mark_as_unread(@receipt)
41
+ @entity1.mark_as_read(@receipt)
42
+ @receipt.is_read.should==true
43
+ end
44
+
45
+ it "should not be able to unread a not owned Receipt (mark as unread)" do
46
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
47
+ @receipt.is_read.should==true
48
+ @entity2.mark_as_unread(@receipt) #Should not change
49
+ @receipt.is_read.should==true
50
+ end
51
+
52
+ it "should not be able to read a not owned Receipt (mark as read)" do
53
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
54
+ @receipt.is_read.should==true
55
+ @entity1.mark_as_unread(@receipt) #From read to unread
56
+ @entity2.mark_as_read(@receipt) #Should not change
57
+ @receipt.is_read.should==false
58
+ end
59
+
60
+ it "should be able to trash an owned Receipt" do
61
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
62
+ @receipt.trashed.should==false
63
+ @entity1.trash(@receipt)
64
+ @receipt.trashed.should==true
65
+ end
66
+
67
+ it "should be able to untrash an owned Receipt" do
68
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
69
+ @receipt.trashed.should==false
70
+ @entity1.trash(@receipt)
71
+ @entity1.untrash(@receipt)
72
+ @receipt.trashed.should==false
73
+ end
74
+
75
+ it "should not be able to trash a not owned Receipt" do
76
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
77
+ @receipt.trashed.should==false
78
+ @entity2.trash(@receipt) #Should not change
79
+ @receipt.trashed.should==false
80
+ end
81
+
82
+ it "should not be able to untrash a not owned Receipt" do
83
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
84
+ @receipt.trashed.should==false
85
+ @entity1.trash(@receipt) #From read to unread
86
+ @entity2.untrash(@receipt) #Should not change
87
+ @receipt.trashed.should==true
88
+ end
89
+
90
+
91
+
92
+ it "should be able to unread an owned Message (mark as unread)" do
93
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
94
+ @message = @receipt.message
95
+ @receipt.is_read.should==true
96
+ @entity1.mark_as_unread(@message)
97
+ @message.receipt_for(@entity1).first.is_read.should==false
98
+ end
99
+
100
+ it "should be able to read an owned Message (mark as read)" do
101
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
102
+ @message = @receipt.message
103
+ @receipt.is_read.should==true
104
+ @entity1.mark_as_unread(@message)
105
+ @entity1.mark_as_read(@message)
106
+ @message.receipt_for(@entity1).first.is_read.should==true
107
+ end
108
+
109
+ it "should not be able to unread a not owned Message (mark as unread)" do
110
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
111
+ @message = @receipt.message
112
+ @receipt.is_read.should==true
113
+ @entity2.mark_as_unread(@message) #Should not change
114
+ @message.receipt_for(@entity1).first.is_read.should==true
115
+ end
116
+
117
+ it "should not be able to read a not owned Message (mark as read)" do
118
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
119
+ @message = @receipt.message
120
+ @receipt.is_read.should==true
121
+ @entity1.mark_as_unread(@message) #From read to unread
122
+ @entity2.mark_as_read(@message) #Should not change
123
+ @message.receipt_for(@entity1).first.is_read.should==false
124
+ end
125
+
126
+ it "should be able to trash an owned Message" do
127
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
128
+ @message = @receipt.message
129
+ @receipt.trashed.should==false
130
+ @entity1.trash(@message)
131
+ @message.receipt_for(@entity1).first.trashed.should==true
132
+ end
133
+
134
+ it "should be able to untrash an owned Message" do
135
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
136
+ @message = @receipt.message
137
+ @receipt.trashed.should==false
138
+ @entity1.trash(@message)
139
+ @entity1.untrash(@message)
140
+ @message.receipt_for(@entity1).first.trashed.should==false
141
+ end
142
+
143
+ it "should not be able to trash a not owned Message" do
144
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
145
+ @message = @receipt.message
146
+ @receipt.trashed.should==false
147
+ @entity2.trash(@message) #Should not change
148
+ @message.receipt_for(@entity1).first.trashed.should==false
149
+ end
150
+
151
+ it "should not be able to untrash a not owned Message" do
152
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
153
+ @message = @receipt.message
154
+ @receipt.trashed.should==false
155
+ @entity1.trash(@message) #From read to unread
156
+ @entity2.untrash(@message) #Should not change
157
+ @message.receipt_for(@entity1).first.trashed.should==true
158
+ end
159
+
160
+
161
+
162
+ it "should be able to unread an owned Notification (mark as unread)" do
163
+ @receipt = @entity1.notify("Subject","Body")
164
+ @notification = @receipt.notification
165
+ @receipt.is_read.should==false
166
+ @entity1.mark_as_read(@notification)
167
+ @entity1.mark_as_unread(@notification)
168
+ @notification.receipt_for(@entity1).first.is_read.should==false
169
+ end
170
+
171
+ it "should be able to read an owned Notification (mark as read)" do
172
+ @receipt = @entity1.notify("Subject","Body")
173
+ @notification = @receipt.notification
174
+ @receipt.is_read.should==false
175
+ @entity1.mark_as_read(@notification)
176
+ @notification.receipt_for(@entity1).first.is_read.should==true
177
+ end
178
+
179
+ it "should not be able to unread a not owned Notification (mark as unread)" do
180
+ @receipt = @entity1.notify("Subject","Body")
181
+ @notification = @receipt.notification
182
+ @receipt.is_read.should==false
183
+ @entity1.mark_as_read(@notification)
184
+ @entity2.mark_as_unread(@notification)
185
+ @notification.receipt_for(@entity1).first.is_read.should==true
186
+ end
187
+
188
+ it "should not be able to read a not owned Notification (mark as read)" do
189
+ @receipt = @entity1.notify("Subject","Body")
190
+ @notification = @receipt.notification
191
+ @receipt.is_read.should==false
192
+ @entity2.mark_as_read(@notification)
193
+ @notification.receipt_for(@entity1).first.is_read.should==false
194
+ end
195
+
196
+ it "should be able to trash an owned Notification" do
197
+ @receipt = @entity1.notify("Subject","Body")
198
+ @notification = @receipt.notification
199
+ @receipt.trashed.should==false
200
+ @entity1.trash(@notification)
201
+ @notification.receipt_for(@entity1).first.trashed.should==true
202
+ end
203
+
204
+ it "should be able to untrash an owned Notification" do
205
+ @receipt = @entity1.notify("Subject","Body")
206
+ @notification = @receipt.notification
207
+ @receipt.trashed.should==false
208
+ @entity1.trash(@notification)
209
+ @entity1.untrash(@notification)
210
+ @notification.receipt_for(@entity1).first.trashed.should==false
211
+ end
212
+
213
+ it "should not be able to trash a not owned Notification" do
214
+ @receipt = @entity1.notify("Subject","Body")
215
+ @notification = @receipt.notification
216
+ @receipt.trashed.should==false
217
+ @entity2.trash(@notification)
218
+ @notification.receipt_for(@entity1).first.trashed.should==false
219
+ end
220
+
221
+ it "should not be able to untrash a not owned Notification" do
222
+ @receipt = @entity1.notify("Subject","Body")
223
+ @notification = @receipt.notification
224
+ @receipt.trashed.should==false
225
+ @entity1.trash(@notification)
226
+ @entity2.untrash(@notification)
227
+ @notification.receipt_for(@entity1).first.trashed.should==true
228
+ end
229
+
230
+
231
+
232
+ it "should be able to unread an owned Conversation (mark as unread)" do
233
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
234
+ @conversation = @receipt.conversation
235
+ @receipt.is_read.should==true
236
+ @entity1.mark_as_unread(@conversation)
237
+ @conversation.receipts_for(@entity1).first.is_read.should==false
238
+ end
239
+
240
+ it "should be able to read an owned Conversation (mark as read)" do
241
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
242
+ @conversation = @receipt.conversation
243
+ @receipt.is_read.should==true
244
+ @entity1.mark_as_unread(@conversation)
245
+ @entity1.mark_as_read(@conversation)
246
+ @conversation.receipts_for(@entity1).first.is_read.should==true
247
+ end
248
+
249
+ it "should not be able to unread a not owned Conversation (mark as unread)" do
250
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
251
+ @conversation = @receipt.conversation
252
+ @receipt.is_read.should==true
253
+ @entity2.mark_as_unread(@conversation)
254
+ @conversation.receipts_for(@entity1).first.is_read.should==true
255
+ end
256
+
257
+ it "should not be able to read a not owned Conversation (mark as read)" do
258
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
259
+ @conversation = @receipt.conversation
260
+ @receipt.is_read.should==true
261
+ @entity1.mark_as_unread(@conversation)
262
+ @entity2.mark_as_read(@conversation)
263
+ @conversation.receipts_for(@entity1).first.is_read.should==false
264
+ end
265
+
266
+ it "should be able to trash an owned Conversation" do
267
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
268
+ @conversation = @receipt.conversation
269
+ @receipt.trashed.should==false
270
+ @entity1.trash(@conversation)
271
+ @conversation.receipts_for(@entity1).first.trashed.should==true
272
+ end
273
+
274
+ it "should be able to untrash an owned Conversation" do
275
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
276
+ @conversation = @receipt.conversation
277
+ @receipt.trashed.should==false
278
+ @entity1.trash(@conversation)
279
+ @entity1.untrash(@conversation)
280
+ @conversation.receipts_for(@entity1).first.trashed.should==false
281
+ end
282
+
283
+ it "should not be able to trash a not owned Conversation" do
284
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
285
+ @conversation = @receipt.conversation
286
+ @receipt.trashed.should==false
287
+ @entity2.trash(@conversation)
288
+ @conversation.receipts_for(@entity1).first.trashed.should==false
289
+ end
290
+
291
+ it "should not be able to untrash a not owned Conversation" do
292
+ @receipt = @entity1.send_message(@entity2,"Body","Subject")
293
+ @conversation = @receipt.conversation
294
+ @receipt.trashed.should==false
295
+ @entity1.trash(@conversation)
296
+ @entity2.untrash(@conversation)
297
+ @conversation.receipts_for(@entity1).first.trashed.should==true
298
+ end
299
+
300
+ it "should be able to read attachment" do
301
+ @receipt = @entity1.send_message(@entity2, "Body", "Subject", nil, File.open('spec/testfile.txt'))
302
+ @conversation = @receipt.conversation
303
+ @conversation.messages.first.attachment_identifier.should=='testfile.txt'
304
+ end
305
+
306
+ it "should be the same message time as passed" do
307
+ message_time = 5.days.ago.to_time
308
+ receipt = @entity1.send_message(@entity2, "Body", "Subject", nil, nil, message_time)
309
+ receipt.message.created_at.should eql(message_time)
310
+ receipt.message.updated_at.should eql(message_time)
311
+ receipt.message.conversation.created_at.should eql(message_time)
312
+ receipt.message.conversation.updated_at.should eql(message_time)
313
+ end
314
+
315
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Message do
4
+
5
+ before do
6
+ @entity1 = FactoryGirl.create(:user)
7
+ @entity2 = FactoryGirl.create(:user)
8
+ @receipt1 = @entity1.send_message(@entity2,"Body","Subject")
9
+ @receipt2 = @entity2.reply_to_all(@receipt1,"Reply body 1")
10
+ @receipt3 = @entity1.reply_to_all(@receipt2,"Reply body 2")
11
+ @receipt4 = @entity2.reply_to_all(@receipt3,"Reply body 3")
12
+ @message1 = @receipt1.notification
13
+ @message4 = @receipt4.notification
14
+ @conversation = @message1.conversation
15
+ end
16
+
17
+ it "should have right recipients" do
18
+ @receipt1.notification.recipients.count.should==2
19
+ @receipt2.notification.recipients.count.should==2
20
+ @receipt3.notification.recipients.count.should==2
21
+ @receipt4.notification.recipients.count.should==2
22
+ end
23
+
24
+ end
@@ -0,0 +1,200 @@
1
+ require 'spec_helper'
2
+
3
+ describe Message do
4
+
5
+ before do
6
+ @entity1 = FactoryGirl.create(:user)
7
+ @entity2 = FactoryGirl.create(:user)
8
+ @entity3 = FactoryGirl.create(:user)
9
+ end
10
+
11
+ it "should notify one user" do
12
+ @entity1.notify("Subject", "Body")
13
+
14
+ #Check getting ALL receipts
15
+ @entity1.mailbox.receipts.size.should==1
16
+ receipt = @entity1.mailbox.receipts.first
17
+ notification = receipt.notification
18
+ notification.subject.should=="Subject"
19
+ notification.body.should=="Body"
20
+
21
+ #Check getting NOTIFICATION receipts only
22
+ @entity1.mailbox.notifications.size.should==1
23
+ notification = @entity1.mailbox.notifications.first
24
+ notification.subject.should=="Subject"
25
+ notification.body.should=="Body"
26
+ end
27
+
28
+ it "should be unread by default" do
29
+ @entity1.notify("Subject", "Body")
30
+ @entity1.mailbox.receipts.size.should==1
31
+ notification = @entity1.mailbox.receipts.first.notification
32
+ notification.should be_is_unread(@entity1)
33
+ end
34
+
35
+ it "should be able to marked as read" do
36
+ @entity1.notify("Subject", "Body")
37
+ @entity1.mailbox.receipts.size.should==1
38
+ notification = @entity1.mailbox.receipts.first.notification
39
+ notification.mark_as_read(@entity1)
40
+ notification.should be_is_read(@entity1)
41
+ end
42
+
43
+ it "should notify several users" do
44
+ recipients = Set.new [@entity1, @entity2, @entity3]
45
+ Notification.notify_all(recipients, "Subject", "Body")
46
+
47
+ #Check getting ALL receipts
48
+ @entity1.mailbox.receipts.size.should==1
49
+ receipt = @entity1.mailbox.receipts.first
50
+ notification = receipt.notification
51
+ notification.subject.should=="Subject"
52
+ notification.body.should=="Body"
53
+ @entity2.mailbox.receipts.size.should==1
54
+ receipt = @entity2.mailbox.receipts.first
55
+ notification = receipt.notification
56
+ notification.subject.should=="Subject"
57
+ notification.body.should=="Body"
58
+ @entity3.mailbox.receipts.size.should==1
59
+ receipt = @entity3.mailbox.receipts.first
60
+ notification = receipt.notification
61
+ notification.subject.should=="Subject"
62
+ notification.body.should=="Body"
63
+
64
+ #Check getting NOTIFICATION receipts only
65
+ @entity1.mailbox.notifications.size.should==1
66
+ notification = @entity1.mailbox.notifications.first
67
+ notification.subject.should=="Subject"
68
+ notification.body.should=="Body"
69
+ @entity2.mailbox.notifications.size.should==1
70
+ notification = @entity2.mailbox.notifications.first
71
+ notification.subject.should=="Subject"
72
+ notification.body.should=="Body"
73
+ @entity3.mailbox.notifications.size.should==1
74
+ notification = @entity3.mailbox.notifications.first
75
+ notification.subject.should=="Subject"
76
+ notification.body.should=="Body"
77
+
78
+ end
79
+
80
+ it "should notify a single recipient" do
81
+ Notification.notify_all(@entity1, "Subject", "Body")
82
+
83
+ #Check getting ALL receipts
84
+ @entity1.mailbox.receipts.size.should==1
85
+ receipt = @entity1.mailbox.receipts.first
86
+ notification = receipt.notification
87
+ notification.subject.should=="Subject"
88
+ notification.body.should=="Body"
89
+
90
+ #Check getting NOTIFICATION receipts only
91
+ @entity1.mailbox.notifications.size.should==1
92
+ notification = @entity1.mailbox.notifications.first
93
+ notification.subject.should=="Subject"
94
+ notification.body.should=="Body"
95
+ end
96
+
97
+ describe "#expire" do
98
+ subject { Notification.new }
99
+
100
+ describe "when the notification is already expired" do
101
+ before do
102
+ subject.stub(:expired? => true)
103
+ end
104
+ it 'should not update the expires attribute' do
105
+ subject.should_not_receive :expires=
106
+ subject.should_not_receive :save
107
+ subject.expire
108
+ end
109
+ end
110
+
111
+ describe "when the notification is not expired" do
112
+ let(:now) { Time.now }
113
+ let(:one_second_ago) { now - 1.second }
114
+ before do
115
+ Time.stub(:now => now)
116
+ subject.stub(:expired? => false)
117
+ end
118
+ it 'should update the expires attribute' do
119
+ subject.should_receive(:expires=).with(one_second_ago)
120
+ subject.expire
121
+ end
122
+ it 'should not save the record' do
123
+ subject.should_not_receive :save
124
+ subject.expire
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ describe "#expire!" do
131
+ subject { Notification.new }
132
+
133
+ describe "when the notification is already expired" do
134
+ before do
135
+ subject.stub(:expired? => true)
136
+ end
137
+ it 'should not call expire' do
138
+ subject.should_not_receive :expire
139
+ subject.should_not_receive :save
140
+ subject.expire!
141
+ end
142
+ end
143
+
144
+ describe "when the notification is not expired" do
145
+ let(:now) { Time.now }
146
+ let(:one_second_ago) { now - 1.second }
147
+ before do
148
+ Time.stub(:now => now)
149
+ subject.stub(:expired? => false)
150
+ end
151
+ it 'should call expire' do
152
+ subject.should_receive(:expire)
153
+ subject.expire!
154
+ end
155
+ it 'should save the record' do
156
+ subject.should_receive :save
157
+ subject.expire!
158
+ end
159
+ end
160
+
161
+ end
162
+
163
+ describe "#expired?" do
164
+ subject { Notification.new }
165
+ context "when the expiration date is in the past" do
166
+ before { subject.stub(:expires => Time.now - 1.second) }
167
+ it 'should be expired' do
168
+ subject.expired?.should be_true
169
+ end
170
+ end
171
+
172
+ context "when the expiration date is now" do
173
+ before {
174
+ time = Time.now
175
+ Time.stub(:now => time)
176
+ subject.stub(:expires => time)
177
+ }
178
+
179
+ it 'should not be expired' do
180
+ subject.expired?.should be_false
181
+ end
182
+ end
183
+
184
+ context "when the expiration date is in the future" do
185
+ before { subject.stub(:expires => Time.now + 1.second) }
186
+ it 'should not be expired' do
187
+ subject.expired?.should be_false
188
+ end
189
+ end
190
+
191
+ context "when the expiration date is not set" do
192
+ before {subject.stub(:expires => nil)}
193
+ it 'should not be expired' do
194
+ subject.expired?.should be_false
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ end