mailboxer 0.11.0 → 0.12.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +4 -3
- data/Appraisals +6 -14
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/app/mailers/mailboxer/base_mailer.rb +14 -0
- data/app/mailers/{message_mailer.rb → mailboxer/message_mailer.rb} +9 -14
- data/app/mailers/mailboxer/notification_mailer.rb +17 -0
- data/app/models/mailboxer/conversation.rb +196 -0
- data/app/models/mailboxer/conversation/opt_out.rb +15 -0
- data/app/models/{mailbox.rb → mailboxer/mailbox.rb} +10 -10
- data/app/models/mailboxer/message.rb +49 -0
- data/app/models/{notification.rb → mailboxer/notification.rb} +44 -40
- data/app/models/{receipt.rb → mailboxer/receipt.rb} +12 -11
- data/app/views/{message_mailer → mailboxer/message_mailer}/new_message_email.html.erb +3 -3
- data/app/views/{message_mailer → mailboxer/message_mailer}/new_message_email.text.erb +2 -2
- data/app/views/{message_mailer → mailboxer/message_mailer}/reply_message_email.html.erb +3 -3
- data/app/views/{message_mailer → mailboxer/message_mailer}/reply_message_email.text.erb +2 -2
- data/app/views/{notification_mailer → mailboxer/notification_mailer}/new_notification_email.html.erb +0 -0
- data/app/views/{notification_mailer → mailboxer/notification_mailer}/new_notification_email.text.erb +0 -0
- data/db/migrate/20110511145103_create_mailboxer.rb +18 -14
- data/db/migrate/20131206080416_add_conversation_optout.rb +14 -0
- data/gemfiles/rails3.2.gemfile +2 -3
- data/gemfiles/rails4.0.gemfile +3 -4
- data/gemfiles/rails4.1.gemfile +7 -0
- data/lib/generators/mailboxer/install_generator.rb +1 -4
- data/lib/generators/mailboxer/namespacing_compatibility_generator.rb +22 -0
- data/lib/generators/mailboxer/templates/initializer.rb +8 -4
- data/lib/generators/mailboxer/templates/mailboxer_namespacing_compatibility.rb +24 -0
- data/lib/mailboxer.rb +7 -1
- data/lib/mailboxer/cleaner.rb +9 -0
- data/lib/mailboxer/engine.rb +1 -1
- data/lib/mailboxer/mail_dispatcher.rb +48 -0
- data/lib/mailboxer/models/messageable.rb +21 -20
- data/lib/mailboxer/version.rb +3 -0
- data/mailboxer.gemspec +16 -8
- data/spec/dummy/Gemfile +1 -1
- data/spec/dummy/app/models/duck.rb +2 -2
- data/spec/dummy/config/initializers/mailboxer.rb +4 -0
- data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +18 -14
- data/spec/dummy/db/migrate/20131206080416_add_conversation_optout.rb +14 -0
- data/spec/dummy/db/schema.rb +30 -21
- data/spec/integration/message_and_receipt_spec.rb +212 -212
- data/spec/mailboxer/mail_dispatcher_spec.rb +114 -0
- data/spec/mailers/message_mailer_spec.rb +4 -4
- data/spec/mailers/notification_mailer_spec.rb +2 -2
- data/spec/models/conversation_spec.rb +148 -47
- data/spec/models/mailbox_spec.rb +50 -50
- data/spec/models/mailboxer_models_messageable_spec.rb +52 -52
- data/spec/models/message_spec.rb +1 -1
- data/spec/models/notification_spec.rb +50 -18
- data/spec/models/receipt_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +68 -57
- data/app/mailers/notification_mailer.rb +0 -21
- data/app/models/conversation.rb +0 -166
- data/app/models/message.rb +0 -68
- data/db/migrate/20110719110700_add_notified_object.rb +0 -17
- data/db/migrate/20110912163911_add_notification_code.rb +0 -13
- data/db/migrate/20111204163911_add_attachments.rb +0 -9
- data/db/migrate/20120813110712_rename_receipts_read.rb +0 -9
- data/db/migrate/20130305144212_add_global_notification_support.rb +0 -9
- data/gemfiles/rails3.0.gemfile +0 -8
- data/gemfiles/rails3.1.gemfile +0 -8
- data/lib/mailboxer/concerns/configurable_mailer.rb +0 -13
- data/spec/dummy/db/migrate/20120305103201_add_notified_object.rb +0 -17
- data/spec/dummy/db/migrate/20120305103202_add_notification_code.rb +0 -13
- data/spec/dummy/db/migrate/20120305103203_add_attachments.rb +0 -5
- data/spec/dummy/db/migrate/20120813110712_rename_receipts_read.rb +0 -9
- data/spec/dummy/db/migrate/20130305144212_add_global_notification_support.rb +0 -11
- data/spec/mailboxer/concerns/configurable_mailer_spec.rb +0 -27
@@ -1,94 +1,94 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Mailboxer::Models::Messageable through User" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@entity1 = FactoryGirl.create(:user)
|
7
7
|
@entity2 = FactoryGirl.create(:user)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should have a mailbox" do
|
11
11
|
assert @entity1.mailbox
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should be able to send a message" do
|
15
15
|
assert @entity1.send_message(@entity2,"Body","Subject")
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should be able to reply to sender" do
|
19
19
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
20
20
|
assert @entity2.reply_to_sender(@receipt,"Reply body")
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "should be able to reply to all" do
|
24
24
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
25
|
-
assert @entity2.reply_to_all(@receipt,"Reply body")
|
25
|
+
assert @entity2.reply_to_all(@receipt,"Reply body")
|
26
26
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
it "should be able to unread an owned Receipt (mark as unread)" do
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
it "should be able to unread an owned Mailboxer::Receipt (mark as unread)" do
|
31
31
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
32
32
|
@receipt.is_read.should==true
|
33
33
|
@entity1.mark_as_unread(@receipt)
|
34
34
|
@receipt.is_read.should==false
|
35
35
|
end
|
36
|
-
|
37
|
-
it "should be able to read an owned Receipt (mark as read)" do
|
36
|
+
|
37
|
+
it "should be able to read an owned Mailboxer::Receipt (mark as read)" do
|
38
38
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
39
39
|
@receipt.is_read.should==true
|
40
40
|
@entity1.mark_as_unread(@receipt)
|
41
41
|
@entity1.mark_as_read(@receipt)
|
42
42
|
@receipt.is_read.should==true
|
43
43
|
end
|
44
|
-
|
45
|
-
it "should not be able to unread a not owned Receipt (mark as unread)" do
|
44
|
+
|
45
|
+
it "should not be able to unread a not owned Mailboxer::Receipt (mark as unread)" do
|
46
46
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
47
47
|
@receipt.is_read.should==true
|
48
48
|
@entity2.mark_as_unread(@receipt) #Should not change
|
49
49
|
@receipt.is_read.should==true
|
50
50
|
end
|
51
|
-
|
52
|
-
it "should not be able to read a not owned Receipt (mark as read)" do
|
51
|
+
|
52
|
+
it "should not be able to read a not owned Mailboxer::Receipt (mark as read)" do
|
53
53
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
54
54
|
@receipt.is_read.should==true
|
55
55
|
@entity1.mark_as_unread(@receipt) #From read to unread
|
56
56
|
@entity2.mark_as_read(@receipt) #Should not change
|
57
57
|
@receipt.is_read.should==false
|
58
58
|
end
|
59
|
-
|
60
|
-
it "should be able to trash an owned Receipt" do
|
59
|
+
|
60
|
+
it "should be able to trash an owned Mailboxer::Receipt" do
|
61
61
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
62
62
|
@receipt.trashed.should==false
|
63
63
|
@entity1.trash(@receipt)
|
64
64
|
@receipt.trashed.should==true
|
65
65
|
end
|
66
|
-
|
67
|
-
it "should be able to untrash an owned Receipt" do
|
66
|
+
|
67
|
+
it "should be able to untrash an owned Mailboxer::Receipt" do
|
68
68
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
69
69
|
@receipt.trashed.should==false
|
70
70
|
@entity1.trash(@receipt)
|
71
71
|
@entity1.untrash(@receipt)
|
72
72
|
@receipt.trashed.should==false
|
73
73
|
end
|
74
|
-
|
75
|
-
it "should not be able to trash a not owned Receipt" do
|
74
|
+
|
75
|
+
it "should not be able to trash a not owned Mailboxer::Receipt" do
|
76
76
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
77
77
|
@receipt.trashed.should==false
|
78
78
|
@entity2.trash(@receipt) #Should not change
|
79
79
|
@receipt.trashed.should==false
|
80
80
|
end
|
81
|
-
|
82
|
-
it "should not be able to untrash a not owned Receipt" do
|
81
|
+
|
82
|
+
it "should not be able to untrash a not owned Mailboxer::Receipt" do
|
83
83
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
84
84
|
@receipt.trashed.should==false
|
85
85
|
@entity1.trash(@receipt) #From read to unread
|
86
86
|
@entity2.untrash(@receipt) #Should not change
|
87
87
|
@receipt.trashed.should==true
|
88
88
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
|
90
|
+
|
91
|
+
|
92
92
|
it "should be able to unread an owned Message (mark as unread)" do
|
93
93
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
94
94
|
@message = @receipt.message
|
@@ -96,7 +96,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
96
96
|
@entity1.mark_as_unread(@message)
|
97
97
|
@message.receipt_for(@entity1).first.is_read.should==false
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it "should be able to read an owned Message (mark as read)" do
|
101
101
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
102
102
|
@message = @receipt.message
|
@@ -105,7 +105,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
105
105
|
@entity1.mark_as_read(@message)
|
106
106
|
@message.receipt_for(@entity1).first.is_read.should==true
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it "should not be able to unread a not owned Message (mark as unread)" do
|
110
110
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
111
111
|
@message = @receipt.message
|
@@ -113,7 +113,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
113
113
|
@entity2.mark_as_unread(@message) #Should not change
|
114
114
|
@message.receipt_for(@entity1).first.is_read.should==true
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
it "should not be able to read a not owned Message (mark as read)" do
|
118
118
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
119
119
|
@message = @receipt.message
|
@@ -122,7 +122,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
122
122
|
@entity2.mark_as_read(@message) #Should not change
|
123
123
|
@message.receipt_for(@entity1).first.is_read.should==false
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
it "should be able to trash an owned Message" do
|
127
127
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
128
128
|
@message = @receipt.message
|
@@ -130,7 +130,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
130
130
|
@entity1.trash(@message)
|
131
131
|
@message.receipt_for(@entity1).first.trashed.should==true
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
it "should be able to untrash an owned Message" do
|
135
135
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
136
136
|
@message = @receipt.message
|
@@ -139,7 +139,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
139
139
|
@entity1.untrash(@message)
|
140
140
|
@message.receipt_for(@entity1).first.trashed.should==false
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
it "should not be able to trash a not owned Message" do
|
144
144
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
145
145
|
@message = @receipt.message
|
@@ -147,7 +147,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
147
147
|
@entity2.trash(@message) #Should not change
|
148
148
|
@message.receipt_for(@entity1).first.trashed.should==false
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
it "should not be able to untrash a not owned Message" do
|
152
152
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
153
153
|
@message = @receipt.message
|
@@ -167,7 +167,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
167
167
|
@entity1.mark_as_unread(@notification)
|
168
168
|
@notification.receipt_for(@entity1).first.is_read.should==false
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
it "should be able to read an owned Notification (mark as read)" do
|
172
172
|
@receipt = @entity1.notify("Subject","Body")
|
173
173
|
@notification = @receipt.notification
|
@@ -175,7 +175,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
175
175
|
@entity1.mark_as_read(@notification)
|
176
176
|
@notification.receipt_for(@entity1).first.is_read.should==true
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
it "should not be able to unread a not owned Notification (mark as unread)" do
|
180
180
|
@receipt = @entity1.notify("Subject","Body")
|
181
181
|
@notification = @receipt.notification
|
@@ -184,7 +184,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
184
184
|
@entity2.mark_as_unread(@notification)
|
185
185
|
@notification.receipt_for(@entity1).first.is_read.should==true
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it "should not be able to read a not owned Notification (mark as read)" do
|
189
189
|
@receipt = @entity1.notify("Subject","Body")
|
190
190
|
@notification = @receipt.notification
|
@@ -192,7 +192,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
192
192
|
@entity2.mark_as_read(@notification)
|
193
193
|
@notification.receipt_for(@entity1).first.is_read.should==false
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
it "should be able to trash an owned Notification" do
|
197
197
|
@receipt = @entity1.notify("Subject","Body")
|
198
198
|
@notification = @receipt.notification
|
@@ -200,7 +200,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
200
200
|
@entity1.trash(@notification)
|
201
201
|
@notification.receipt_for(@entity1).first.trashed.should==true
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
it "should be able to untrash an owned Notification" do
|
205
205
|
@receipt = @entity1.notify("Subject","Body")
|
206
206
|
@notification = @receipt.notification
|
@@ -209,7 +209,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
209
209
|
@entity1.untrash(@notification)
|
210
210
|
@notification.receipt_for(@entity1).first.trashed.should==false
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
it "should not be able to trash a not owned Notification" do
|
214
214
|
@receipt = @entity1.notify("Subject","Body")
|
215
215
|
@notification = @receipt.notification
|
@@ -217,7 +217,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
217
217
|
@entity2.trash(@notification)
|
218
218
|
@notification.receipt_for(@entity1).first.trashed.should==false
|
219
219
|
end
|
220
|
-
|
220
|
+
|
221
221
|
it "should not be able to untrash a not owned Notification" do
|
222
222
|
@receipt = @entity1.notify("Subject","Body")
|
223
223
|
@notification = @receipt.notification
|
@@ -226,9 +226,9 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
226
226
|
@entity2.untrash(@notification)
|
227
227
|
@notification.receipt_for(@entity1).first.trashed.should==true
|
228
228
|
end
|
229
|
-
|
230
|
-
|
231
|
-
|
229
|
+
|
230
|
+
|
231
|
+
|
232
232
|
it "should be able to unread an owned Conversation (mark as unread)" do
|
233
233
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
234
234
|
@conversation = @receipt.conversation
|
@@ -236,7 +236,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
236
236
|
@entity1.mark_as_unread(@conversation)
|
237
237
|
@conversation.receipts_for(@entity1).first.is_read.should==false
|
238
238
|
end
|
239
|
-
|
239
|
+
|
240
240
|
it "should be able to read an owned Conversation (mark as read)" do
|
241
241
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
242
242
|
@conversation = @receipt.conversation
|
@@ -245,7 +245,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
245
245
|
@entity1.mark_as_read(@conversation)
|
246
246
|
@conversation.receipts_for(@entity1).first.is_read.should==true
|
247
247
|
end
|
248
|
-
|
248
|
+
|
249
249
|
it "should not be able to unread a not owned Conversation (mark as unread)" do
|
250
250
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
251
251
|
@conversation = @receipt.conversation
|
@@ -253,7 +253,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
253
253
|
@entity2.mark_as_unread(@conversation)
|
254
254
|
@conversation.receipts_for(@entity1).first.is_read.should==true
|
255
255
|
end
|
256
|
-
|
256
|
+
|
257
257
|
it "should not be able to read a not owned Conversation (mark as read)" do
|
258
258
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
259
259
|
@conversation = @receipt.conversation
|
@@ -262,7 +262,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
262
262
|
@entity2.mark_as_read(@conversation)
|
263
263
|
@conversation.receipts_for(@entity1).first.is_read.should==false
|
264
264
|
end
|
265
|
-
|
265
|
+
|
266
266
|
it "should be able to trash an owned Conversation" do
|
267
267
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
268
268
|
@conversation = @receipt.conversation
|
@@ -270,7 +270,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
270
270
|
@entity1.trash(@conversation)
|
271
271
|
@conversation.receipts_for(@entity1).first.trashed.should==true
|
272
272
|
end
|
273
|
-
|
273
|
+
|
274
274
|
it "should be able to untrash an owned Conversation" do
|
275
275
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
276
276
|
@conversation = @receipt.conversation
|
@@ -279,7 +279,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
279
279
|
@entity1.untrash(@conversation)
|
280
280
|
@conversation.receipts_for(@entity1).first.trashed.should==false
|
281
281
|
end
|
282
|
-
|
282
|
+
|
283
283
|
it "should not be able to trash a not owned Conversation" do
|
284
284
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
285
285
|
@conversation = @receipt.conversation
|
@@ -287,7 +287,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
287
287
|
@entity2.trash(@conversation)
|
288
288
|
@conversation.receipts_for(@entity1).first.trashed.should==false
|
289
289
|
end
|
290
|
-
|
290
|
+
|
291
291
|
it "should not be able to untrash a not owned Conversation" do
|
292
292
|
@receipt = @entity1.send_message(@entity2,"Body","Subject")
|
293
293
|
@conversation = @receipt.conversation
|
@@ -302,7 +302,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
302
302
|
@conversation = @receipt.conversation
|
303
303
|
@conversation.messages.first.attachment_identifier.should=='testfile.txt'
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
it "should be the same message time as passed" do
|
307
307
|
message_time = 5.days.ago
|
308
308
|
receipt = @entity1.send_message(@entity2, "Body", "Subject", nil, nil, message_time)
|
data/spec/models/message_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Mailboxer::Notification do
|
4
4
|
|
5
5
|
before do
|
6
6
|
@entity1 = FactoryGirl.create(:user)
|
@@ -8,6 +8,12 @@ describe Message do
|
|
8
8
|
@entity3 = FactoryGirl.create(:user)
|
9
9
|
end
|
10
10
|
|
11
|
+
it { should validate_presence_of :subject }
|
12
|
+
it { should validate_presence_of :body }
|
13
|
+
|
14
|
+
it { should ensure_length_of(:subject).is_at_most(Mailboxer.subject_max_length) }
|
15
|
+
it { should ensure_length_of(:body).is_at_most(Mailboxer.body_max_length) }
|
16
|
+
|
11
17
|
it "should notify one user" do
|
12
18
|
@entity1.notify("Subject", "Body")
|
13
19
|
|
@@ -41,9 +47,8 @@ describe Message do
|
|
41
47
|
end
|
42
48
|
|
43
49
|
it "should notify several users" do
|
44
|
-
recipients = Set.new [@entity1
|
45
|
-
Notification.notify_all(recipients,
|
46
|
-
|
50
|
+
recipients = Set.new [@entity1,@entity2,@entity3]
|
51
|
+
Mailboxer::Notification.notify_all(recipients,"Subject","Body")
|
47
52
|
#Check getting ALL receipts
|
48
53
|
@entity1.mailbox.receipts.size.should==1
|
49
54
|
receipt = @entity1.mailbox.receipts.first
|
@@ -78,7 +83,7 @@ describe Message do
|
|
78
83
|
end
|
79
84
|
|
80
85
|
it "should notify a single recipient" do
|
81
|
-
Notification.notify_all(@entity1,
|
86
|
+
Mailboxer::Notification.notify_all(@entity1,"Subject","Body")
|
82
87
|
|
83
88
|
#Check getting ALL receipts
|
84
89
|
@entity1.mailbox.receipts.size.should==1
|
@@ -93,10 +98,37 @@ describe Message do
|
|
93
98
|
notification.subject.should=="Subject"
|
94
99
|
notification.body.should=="Body"
|
95
100
|
end
|
96
|
-
|
101
|
+
|
102
|
+
describe "scopes" do
|
103
|
+
let(:scope_user) { FactoryGirl.create(:user) }
|
104
|
+
let!(:notification) { scope_user.notify("Body", "Subject").notification }
|
105
|
+
|
106
|
+
describe ".unread" do
|
107
|
+
it "finds unread notifications" do
|
108
|
+
unread_notification = scope_user.notify("Body", "Subject").notification
|
109
|
+
notification.mark_as_read(scope_user)
|
110
|
+
Mailboxer::Notification.unread.last.should == unread_notification
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe ".expired" do
|
115
|
+
it "finds expired notifications" do
|
116
|
+
notification.update_attributes(expires: 1.day.ago)
|
117
|
+
scope_user.mailbox.notifications.expired.count.should eq(1)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe ".unexpired" do
|
122
|
+
it "finds unexpired notifications" do
|
123
|
+
notification.update_attributes(expires: 1.day.from_now)
|
124
|
+
scope_user.mailbox.notifications.unexpired.count.should eq(1)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
97
129
|
describe "#expire" do
|
98
|
-
subject {
|
99
|
-
|
130
|
+
subject { described_class.new }
|
131
|
+
|
100
132
|
describe "when the notification is already expired" do
|
101
133
|
before do
|
102
134
|
subject.stub(:expired? => true)
|
@@ -124,11 +156,11 @@ describe Message do
|
|
124
156
|
subject.expire
|
125
157
|
end
|
126
158
|
end
|
127
|
-
|
159
|
+
|
128
160
|
end
|
129
|
-
|
161
|
+
|
130
162
|
describe "#expire!" do
|
131
|
-
subject {
|
163
|
+
subject { described_class.new }
|
132
164
|
|
133
165
|
describe "when the notification is already expired" do
|
134
166
|
before do
|
@@ -157,44 +189,44 @@ describe Message do
|
|
157
189
|
subject.expire!
|
158
190
|
end
|
159
191
|
end
|
160
|
-
|
192
|
+
|
161
193
|
end
|
162
194
|
|
163
195
|
describe "#expired?" do
|
164
|
-
subject {
|
196
|
+
subject { described_class.new }
|
165
197
|
context "when the expiration date is in the past" do
|
166
198
|
before { subject.stub(:expires => Time.now - 1.second) }
|
167
199
|
it 'should be expired' do
|
168
200
|
subject.expired?.should be_true
|
169
201
|
end
|
170
202
|
end
|
171
|
-
|
203
|
+
|
172
204
|
context "when the expiration date is now" do
|
173
205
|
before {
|
174
206
|
time = Time.now
|
175
207
|
Time.stub(:now => time)
|
176
208
|
subject.stub(:expires => time)
|
177
209
|
}
|
178
|
-
|
210
|
+
|
179
211
|
it 'should not be expired' do
|
180
212
|
subject.expired?.should be_false
|
181
213
|
end
|
182
214
|
end
|
183
|
-
|
215
|
+
|
184
216
|
context "when the expiration date is in the future" do
|
185
217
|
before { subject.stub(:expires => Time.now + 1.second) }
|
186
218
|
it 'should not be expired' do
|
187
219
|
subject.expired?.should be_false
|
188
220
|
end
|
189
221
|
end
|
190
|
-
|
222
|
+
|
191
223
|
context "when the expiration date is not set" do
|
192
224
|
before {subject.stub(:expires => nil)}
|
193
225
|
it 'should not be expired' do
|
194
226
|
subject.expired?.should be_false
|
195
227
|
end
|
196
228
|
end
|
197
|
-
|
229
|
+
|
198
230
|
end
|
199
231
|
|
200
232
|
end
|