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