message_train 0.5.2 → 0.5.3
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/.ruby-gemset +1 -1
- data/.scss-lint.yml +7 -0
- data/.simplecov +1 -1
- data/.travis.yml +1 -1
- data/Gemfile +6 -2
- data/LICENSE.txt +2 -2
- data/README.rdoc +5 -5
- data/Rakefile +22 -21
- data/VERSION +1 -1
- data/app/assets/javascripts/message_train.js +1 -1
- data/app/assets/stylesheets/message_train.scss +29 -19
- data/app/controllers/concerns/message_train_support.rb +41 -37
- data/app/controllers/message_train/application_controller.rb +1 -0
- data/app/controllers/message_train/boxes_controller.rb +5 -4
- data/app/controllers/message_train/conversations_controller.rb +8 -7
- data/app/controllers/message_train/messages_controller.rb +25 -22
- data/app/controllers/message_train/participants_controller.rb +27 -23
- data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
- data/app/helpers/message_train/application_helper.rb +6 -8
- data/app/helpers/message_train/attachments_helper.rb +12 -4
- data/app/helpers/message_train/boxes_helper.rb +38 -11
- data/app/helpers/message_train/collectives_helper.rb +38 -12
- data/app/helpers/message_train/conversations_helper.rb +43 -35
- data/app/helpers/message_train/messages_helper.rb +32 -25
- data/app/mailers/message_train/application_mailer.rb +7 -4
- data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
- data/app/mailers/message_train/receipt_mailer.rb +14 -4
- data/app/models/message_train/attachment.rb +41 -25
- data/app/models/message_train/box.rb +159 -122
- data/app/models/message_train/conversation.rb +84 -41
- data/app/models/message_train/ignore.rb +8 -2
- data/app/models/message_train/message.rb +72 -42
- data/app/models/message_train/receipt.rb +30 -17
- data/app/models/message_train/unsubscribe.rb +1 -0
- data/app/views/application/404.html.haml +1 -1
- data/app/views/layouts/mailer.html.haml +2 -2
- data/app/views/layouts/mailer.text.haml +1 -1
- data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
- data/app/views/message_train/application/_widget.html.haml +1 -1
- data/app/views/message_train/application/results.json.jbuilder +1 -1
- data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/boxes/_list_item.html.haml +1 -1
- data/app/views/message_train/boxes/show.html.haml +1 -1
- data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/collectives/_list_item.html.haml +1 -1
- data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
- data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/show.html.haml +2 -2
- data/app/views/message_train/conversations/show.json.jbuilder +5 -1
- data/app/views/message_train/messages/_form.html.haml +1 -1
- data/app/views/message_train/messages/_message.html.haml +6 -6
- data/app/views/message_train/messages/_toggle.html.haml +1 -1
- data/app/views/message_train/messages/show.json.jbuilder +5 -1
- data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
- data/app/views/message_train/participants/index.json.jbuilder +1 -1
- data/app/views/message_train/participants/show.json.jbuilder +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
- data/app/views/message_train/unsubscribes/index.html.haml +1 -1
- data/config/environment.rb +1 -1
- data/config/initializers/date_time.rb +2 -2
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +37 -15
- data/lib/generators/message_train/install/install_generator.rb +26 -11
- data/lib/generators/message_train/install/templates/initializer.rb +0 -2
- data/lib/generators/message_train/utils.rb +11 -4
- data/lib/message_train/configuration.rb +4 -5
- data/lib/message_train/engine.rb +1 -7
- data/lib/message_train/localization.rb +14 -18
- data/lib/message_train/mixin.rb +211 -150
- data/lib/message_train/version.rb +1 -0
- data/lib/message_train.rb +7 -6
- data/message_train.gemspec +24 -11
- data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
- data/spec/controllers/message_train/concerns_spec.rb +17 -13
- data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
- data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
- data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
- data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
- data/spec/dummy/Rakefile +2 -1
- data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
- data/spec/dummy/app/controllers/application_controller.rb +7 -7
- data/spec/dummy/app/models/group.rb +1 -1
- data/spec/dummy/app/models/role.rb +11 -7
- data/spec/dummy/app/models/user.rb +6 -5
- data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
- data/spec/dummy/app/views/layouts/application.html.haml +1 -1
- data/spec/dummy/app/views/pages/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +23 -17
- data/spec/dummy/config/environments/development.rb +5 -4
- data/spec/dummy/config/environments/production.rb +10 -6
- data/spec/dummy/config/environments/test.rb +4 -3
- data/spec/dummy/config/initializers/assets.rb +2 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
- data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
- data/spec/dummy/config/initializers/devise.rb +63 -44
- data/spec/dummy/config/initializers/high_voltage.rb +1 -1
- data/spec/dummy/config/initializers/message_train.rb +5 -2
- data/spec/dummy/config/initializers/mime_types.rb +1 -1
- data/spec/dummy/config/initializers/paperclip.rb +5 -2
- data/spec/dummy/config/initializers/rolify.rb +3 -2
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/config/settings.yml +1 -1
- data/spec/dummy/db/schema.rb +98 -98
- data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
- data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
- data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
- data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
- data/spec/dummy/db/seeds/users.seeds.rb +47 -42
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/attachment.rb +6 -2
- data/spec/factories/group.rb +1 -4
- data/spec/factories/message.rb +29 -23
- data/spec/factories/user.rb +6 -4
- data/spec/features/boxes_spec.rb +76 -24
- data/spec/features/conversations_spec.rb +19 -7
- data/spec/features/messages_spec.rb +24 -5
- data/spec/features/unsubscribes_spec.rb +36 -9
- data/spec/helpers/message_train/application_helper_spec.rb +1 -1
- data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
- data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
- data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
- data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
- data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
- data/spec/message_train_spec.rb +3 -2
- data/spec/models/group_spec.rb +12 -9
- data/spec/models/message_train/attachment_spec.rb +33 -30
- data/spec/models/message_train/box_spec.rb +243 -60
- data/spec/models/message_train/conversation_spec.rb +16 -12
- data/spec/models/message_train/ignore_spec.rb +3 -1
- data/spec/models/message_train/message_spec.rb +22 -7
- data/spec/models/message_train/receipt_spec.rb +14 -4
- data/spec/models/role_spec.rb +10 -6
- data/spec/models/user_spec.rb +74 -22
- data/spec/rails_helper.rb +9 -4
- data/spec/spec_helper.rb +6 -54
- data/spec/support/controller_behaviors.rb +8 -5
- data/spec/support/controller_macros.rb +2 -2
- data/spec/support/factory_girl.rb +1 -1
- data/spec/support/feature_behaviors.rb +42 -13
- data/spec/support/loaded_site/attachments.rb +8 -0
- data/spec/support/loaded_site/conversations.rb +73 -0
- data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
- data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
- data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
- data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
- data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
- data/spec/support/shared_connection.rb +8 -6
- data/spec/support/utilities.rb +10 -10
- metadata +67 -10
- data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
- data/spec/support/attachments.rb +0 -4
- data/spec/support/conversations.rb +0 -23
@@ -9,11 +9,18 @@ module MessageTrain
|
|
9
9
|
let(:user_all_box) { first_user.box(:all) }
|
10
10
|
let(:user_drafts_box) { first_user.box(:drafts) }
|
11
11
|
let(:user_ignored_box) { first_user.box(:ignored) }
|
12
|
-
let(:owned_group_box)
|
13
|
-
|
12
|
+
let(:owned_group_box) do
|
13
|
+
first_user.collective_boxes[:groups].find do |x|
|
14
|
+
x.parent.slug == 'first-group'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
let(:membered_group_box) do
|
18
|
+
first_user.collective_boxes[:groups].find do |x|
|
19
|
+
x.parent.slug == 'membered-group'
|
20
|
+
end
|
21
|
+
end
|
14
22
|
|
15
23
|
describe 'Scopes and Methods' do
|
16
|
-
|
17
24
|
describe '#unread_count' do
|
18
25
|
subject { user_in_box.unread_count }
|
19
26
|
it { should be >= 2 }
|
@@ -85,7 +92,11 @@ module MessageTrain
|
|
85
92
|
describe '#new_message' do
|
86
93
|
context 'when conversation is set' do
|
87
94
|
let(:expected_recipients) { { 'users' => 'second-user' } }
|
88
|
-
subject
|
95
|
+
subject do
|
96
|
+
user_in_box.new_message(
|
97
|
+
message_train_conversation_id: unread_conversation.id
|
98
|
+
)
|
99
|
+
end
|
89
100
|
it { should be_a_new MessageTrain::Message }
|
90
101
|
its(:subject) { should eq 'Re: Unread Conversation' }
|
91
102
|
its(:recipients_to_save) { should eq expected_recipients }
|
@@ -100,28 +111,56 @@ module MessageTrain
|
|
100
111
|
|
101
112
|
describe '#send_message' do
|
102
113
|
describe 'to a singular recipient' do
|
103
|
-
let(:message)
|
114
|
+
let(:message) do
|
115
|
+
{
|
116
|
+
recipients_to_save: { 'users' => 'second-user' },
|
117
|
+
subject: 'Message to send',
|
118
|
+
body: '...'
|
119
|
+
}
|
120
|
+
end
|
104
121
|
subject { user_in_box.send_message(message) }
|
105
122
|
it { should be_a MessageTrain::Message }
|
106
123
|
end
|
107
124
|
describe 'to a collective recipient' do
|
108
125
|
describe 'when recipient does not accept from sender' do
|
109
126
|
context 'message status' do
|
110
|
-
let(:message)
|
127
|
+
let(:message) do
|
128
|
+
{
|
129
|
+
recipients_to_save: { 'groups' => 'membered-group' },
|
130
|
+
subject: 'Message to send',
|
131
|
+
body: '...'
|
132
|
+
}
|
133
|
+
end
|
111
134
|
subject { membered_group_box.send_message(message) }
|
112
135
|
it { should be false }
|
113
136
|
end
|
114
137
|
context 'box status' do
|
115
|
-
let(:message)
|
138
|
+
let(:message) do
|
139
|
+
{
|
140
|
+
recipients_to_save: { 'groups' => 'membered-group' },
|
141
|
+
subject: 'Message to send',
|
142
|
+
body: '...'
|
143
|
+
}
|
144
|
+
end
|
116
145
|
before do
|
117
146
|
membered_group_box.send_message(message)
|
118
147
|
end
|
119
|
-
subject
|
148
|
+
subject do
|
149
|
+
membered_group_box.errors.all.find do |x|
|
150
|
+
x[:css_id] == 'message_train_message'
|
151
|
+
end
|
152
|
+
end
|
120
153
|
its([:message]) { should eq 'Invalid sender for Group 2' }
|
121
154
|
end
|
122
155
|
end
|
123
156
|
describe 'when recipient accepts from sender' do
|
124
|
-
let(:message)
|
157
|
+
let(:message) do
|
158
|
+
{
|
159
|
+
recipients_to_save: { 'groups' => 'first-group' },
|
160
|
+
subject: 'Message to send',
|
161
|
+
body: '...'
|
162
|
+
}
|
163
|
+
end
|
125
164
|
subject { owned_group_box.send_message(message) }
|
126
165
|
it { should be_a MessageTrain::Message }
|
127
166
|
end
|
@@ -130,30 +169,75 @@ module MessageTrain
|
|
130
169
|
|
131
170
|
describe '#update_message' do
|
132
171
|
describe 'to a singular recipient' do
|
133
|
-
let(:message)
|
172
|
+
let(:message) do
|
173
|
+
{
|
174
|
+
recipients_to_save: { 'users' => 'second-user' },
|
175
|
+
subject: 'Message to send',
|
176
|
+
body: '...',
|
177
|
+
draft: false
|
178
|
+
}
|
179
|
+
end
|
134
180
|
subject { user_in_box.update_message(draft_message, message) }
|
135
181
|
it { should be_a MessageTrain::Message }
|
136
182
|
end
|
137
183
|
describe 'to a collective recipient' do
|
138
184
|
describe 'when recipient does not accept from sender' do
|
139
185
|
context 'message status' do
|
140
|
-
let(:message)
|
141
|
-
|
186
|
+
let(:message) do
|
187
|
+
{
|
188
|
+
recipients_to_save: { 'groups' => 'membered-group' },
|
189
|
+
subject: 'Message to send',
|
190
|
+
body: '...',
|
191
|
+
draft: false
|
192
|
+
}
|
193
|
+
end
|
194
|
+
subject do
|
195
|
+
membered_group_box.update_message(
|
196
|
+
owned_group_draft.messages.first,
|
197
|
+
message
|
198
|
+
)
|
199
|
+
end
|
142
200
|
it { should be false }
|
143
201
|
end
|
144
202
|
context 'box status' do
|
145
|
-
let(:message)
|
203
|
+
let(:message) do
|
204
|
+
{
|
205
|
+
recipients_to_save: { 'groups' => 'membered-group' },
|
206
|
+
subject: 'Message to send', body: '...', draft: false
|
207
|
+
}
|
208
|
+
end
|
146
209
|
let(:owned_group_draft_id) { owned_group_draft.messages.first.id }
|
147
210
|
before do
|
148
|
-
membered_group_box.update_message(
|
211
|
+
membered_group_box.update_message(
|
212
|
+
owned_group_draft.messages.first,
|
213
|
+
message
|
214
|
+
)
|
215
|
+
end
|
216
|
+
subject do
|
217
|
+
membered_group_box.errors.all.find do |x|
|
218
|
+
x[:css_id] == "message_train_message_#{owned_group_draft_id}"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
its([:message]) do
|
222
|
+
should eq "Access to Message #{owned_group_draft_id} denied"
|
149
223
|
end
|
150
|
-
subject { membered_group_box.errors.all.find { |x| x[:css_id] == "message_train_message_#{owned_group_draft_id}" } }
|
151
|
-
its([:message]) { should eq "Access to Message #{owned_group_draft_id} denied" }
|
152
224
|
end
|
153
225
|
end
|
154
226
|
describe 'when recipient accepts from sender' do
|
155
|
-
let(:message)
|
156
|
-
|
227
|
+
let(:message) do
|
228
|
+
{
|
229
|
+
recipients_to_save: { 'groups' => 'first-group' },
|
230
|
+
subject: 'Message to send',
|
231
|
+
body: '...',
|
232
|
+
draft: false
|
233
|
+
}
|
234
|
+
end
|
235
|
+
subject do
|
236
|
+
owned_group_box.update_message(
|
237
|
+
owned_group_draft.messages.first,
|
238
|
+
message
|
239
|
+
)
|
240
|
+
end
|
157
241
|
it { should be_a MessageTrain::Message }
|
158
242
|
end
|
159
243
|
end
|
@@ -162,7 +246,12 @@ module MessageTrain
|
|
162
246
|
describe '#ignore' do
|
163
247
|
context 'when not present' do
|
164
248
|
it 'raises an ActiveRecord::RecordNotFound error' do
|
165
|
-
expect
|
249
|
+
expect do
|
250
|
+
last_user.box.ignore(99_999_999)
|
251
|
+
end.to raise_error(
|
252
|
+
ActiveRecord::RecordNotFound,
|
253
|
+
/Couldn't find MessageTrain::Conversation with 'id'=99999999/
|
254
|
+
)
|
166
255
|
end
|
167
256
|
end
|
168
257
|
context 'when bad type' do
|
@@ -170,27 +259,33 @@ module MessageTrain
|
|
170
259
|
last_user.box.ignore(first_user)
|
171
260
|
end
|
172
261
|
subject { last_user.box.errors.all.first[:message] }
|
173
|
-
it { should match
|
262
|
+
it { should match(/Cannot ignore User/) }
|
174
263
|
end
|
175
264
|
context 'when not authorized' do
|
176
265
|
before do
|
177
266
|
last_user.box.ignore(read_conversation)
|
178
267
|
end
|
179
268
|
subject { last_user.box.errors.all.first[:message] }
|
180
|
-
it { should match
|
269
|
+
it { should match(/Access to Conversation ([0-9]+) denied/) }
|
181
270
|
end
|
182
271
|
context 'when authorized' do
|
183
272
|
before do
|
184
273
|
user_in_box.ignore(read_conversation)
|
185
274
|
end
|
186
|
-
subject { read_conversation.
|
187
|
-
it { should be true}
|
275
|
+
subject { read_conversation.participant_ignored?(first_user) }
|
276
|
+
it { should be true }
|
188
277
|
end
|
189
278
|
end
|
279
|
+
|
190
280
|
describe '#unignore' do
|
191
281
|
context 'when not present' do
|
192
282
|
it 'raises an ActiveRecord::RecordNotFound error' do
|
193
|
-
expect
|
283
|
+
expect do
|
284
|
+
last_user.box.unignore(99_999_999)
|
285
|
+
end.to raise_error(
|
286
|
+
ActiveRecord::RecordNotFound,
|
287
|
+
/Couldn't find MessageTrain::Conversation with 'id'=99999999/
|
288
|
+
)
|
194
289
|
end
|
195
290
|
end
|
196
291
|
context 'when bad type' do
|
@@ -198,23 +293,24 @@ module MessageTrain
|
|
198
293
|
last_user.box.unignore(first_user)
|
199
294
|
end
|
200
295
|
subject { last_user.box.errors.all.first[:message] }
|
201
|
-
it { should match
|
296
|
+
it { should match(/Cannot unignore User/) }
|
202
297
|
end
|
203
298
|
context 'when not authorized' do
|
204
299
|
before do
|
205
300
|
last_user.box.unignore(read_conversation)
|
206
301
|
end
|
207
302
|
subject { last_user.box.errors.all.first[:message] }
|
208
|
-
it { should match
|
303
|
+
it { should match(/Access to Conversation ([0-9]+) denied/) }
|
209
304
|
end
|
210
305
|
context 'when authorized' do
|
211
306
|
before do
|
212
307
|
user_in_box.unignore(ignored_conversation)
|
213
308
|
end
|
214
|
-
subject { ignored_conversation.
|
309
|
+
subject { ignored_conversation.participant_ignored?(first_user) }
|
215
310
|
it { should be false }
|
216
311
|
end
|
217
312
|
end
|
313
|
+
|
218
314
|
describe '#title' do
|
219
315
|
context 'with division set to :in' do
|
220
316
|
subject { user_in_box.title }
|
@@ -245,7 +341,14 @@ module MessageTrain
|
|
245
341
|
describe '#mark' do
|
246
342
|
context 'when not present' do
|
247
343
|
it 'raises an ActiveRecord::RecordNotFound error' do
|
248
|
-
expect
|
344
|
+
expect do
|
345
|
+
last_user.box.mark('read', conversations: ['99999999'])
|
346
|
+
end.to(
|
347
|
+
raise_error(
|
348
|
+
ActiveRecord::RecordNotFound,
|
349
|
+
/Couldn't find MessageTrain::Conversation/
|
350
|
+
)
|
351
|
+
)
|
249
352
|
end
|
250
353
|
end
|
251
354
|
context 'when bad type' do
|
@@ -253,7 +356,7 @@ module MessageTrain
|
|
253
356
|
last_user.box.mark('read', users: [first_user.id.to_s])
|
254
357
|
end
|
255
358
|
subject { last_user.box.errors.all.first[:message] }
|
256
|
-
it { should match
|
359
|
+
it { should match(/Cannot mark users/) }
|
257
360
|
end
|
258
361
|
context 'when bad object' do
|
259
362
|
describe 'given singular box' do
|
@@ -261,15 +364,25 @@ module MessageTrain
|
|
261
364
|
last_user.box.mark('read', conversations: Time.now)
|
262
365
|
end
|
263
366
|
subject { last_user.box.errors.all.first[:message] }
|
264
|
-
it { should match
|
367
|
+
it { should match(/Cannot mark with Time/) }
|
265
368
|
end
|
266
369
|
describe 'given collective box' do
|
267
|
-
# This test is mostly here to test the error handling for collective
|
370
|
+
# This test is mostly here to test the error handling for collective
|
371
|
+
# boxes, not so much the mark method
|
268
372
|
before do
|
269
|
-
first_group.box(:in, first_user)
|
373
|
+
first_group.box(:in, first_user)
|
374
|
+
.mark('read', conversations: Time.now)
|
270
375
|
end
|
271
376
|
subject { first_group.box(:in, first_user).errors.all }
|
272
|
-
it
|
377
|
+
it do
|
378
|
+
should eq [
|
379
|
+
{
|
380
|
+
css_id: 'box',
|
381
|
+
path: '/collectives/groups:first-group/box/in',
|
382
|
+
message: 'Cannot mark with Time'
|
383
|
+
}
|
384
|
+
]
|
385
|
+
end
|
273
386
|
end
|
274
387
|
end
|
275
388
|
context 'when not authorized' do
|
@@ -277,11 +390,14 @@ module MessageTrain
|
|
277
390
|
last_user.box.mark('unread', conversations: read_conversation)
|
278
391
|
end
|
279
392
|
subject { last_user.box.errors.all.first[:message] }
|
280
|
-
it { should match
|
393
|
+
it { should match(/Access to Conversation ([0-9]+) denied/) }
|
281
394
|
end
|
282
395
|
context 'when authorized' do
|
283
396
|
before do
|
284
|
-
user_in_box.mark(
|
397
|
+
user_in_box.mark(
|
398
|
+
'unread',
|
399
|
+
conversations: [read_conversation.id.to_s]
|
400
|
+
)
|
285
401
|
end
|
286
402
|
subject { read_conversation.includes_read_for?(first_user) }
|
287
403
|
it { should be false }
|
@@ -290,7 +406,12 @@ module MessageTrain
|
|
290
406
|
|
291
407
|
describe '#message' do
|
292
408
|
describe 'when there are errors' do
|
293
|
-
let(:message)
|
409
|
+
let(:message) do
|
410
|
+
{
|
411
|
+
recipients_to_save: { 'users' => 'second-user' },
|
412
|
+
subject: ''
|
413
|
+
}
|
414
|
+
end
|
294
415
|
before do
|
295
416
|
first_user.box.send_message(message)
|
296
417
|
end
|
@@ -298,22 +419,33 @@ module MessageTrain
|
|
298
419
|
it { should eq "Subject can't be blank" }
|
299
420
|
end
|
300
421
|
describe 'when there are results' do
|
301
|
-
let(:message)
|
422
|
+
let(:message) do
|
423
|
+
{
|
424
|
+
recipients_to_save: { 'users' => 'second-user' },
|
425
|
+
subject: 'Valid'
|
426
|
+
}
|
427
|
+
end
|
302
428
|
before do
|
303
429
|
first_user.box.send_message(message)
|
304
430
|
end
|
305
431
|
subject { first_user.box.message }
|
306
|
-
it { should eq
|
432
|
+
it { should eq 'Message sent.' }
|
307
433
|
end
|
308
434
|
describe 'when there is nothing to do' do
|
309
435
|
subject { first_user.box.message }
|
310
|
-
it { should eq 'Nothing to do'}
|
436
|
+
it { should eq 'Nothing to do' }
|
311
437
|
end
|
312
438
|
end
|
313
439
|
|
314
440
|
describe '#send_message' do
|
315
441
|
context 'when message is valid' do
|
316
|
-
let(:valid_attributes)
|
442
|
+
let(:valid_attributes) do
|
443
|
+
{
|
444
|
+
recipients_to_save: { 'users' => 'second-user, third-user' },
|
445
|
+
subject: 'Test Message',
|
446
|
+
body: 'This is the content.'
|
447
|
+
}
|
448
|
+
end
|
317
449
|
subject { user_in_box.send_message(valid_attributes) }
|
318
450
|
it { should be_a MessageTrain::Message }
|
319
451
|
its(:new_record?) { should be false }
|
@@ -323,10 +455,18 @@ module MessageTrain
|
|
323
455
|
its(:draft) { should be false }
|
324
456
|
end
|
325
457
|
context 'when message is invalid' do
|
326
|
-
let(:invalid_attributes)
|
458
|
+
let(:invalid_attributes) do
|
459
|
+
{
|
460
|
+
recipients_to_save: { 'users' => 'second-user, third-user' },
|
461
|
+
subject: nil,
|
462
|
+
body: 'This is the content.'
|
463
|
+
}
|
464
|
+
end
|
327
465
|
subject { user_in_box.send_message(invalid_attributes) }
|
328
466
|
it { should be_a_new MessageTrain::Message }
|
329
|
-
its('errors.full_messages.to_sentence')
|
467
|
+
its('errors.full_messages.to_sentence') do
|
468
|
+
should eq "Subject can't be blank"
|
469
|
+
end
|
330
470
|
its(:recipients) { should be_empty }
|
331
471
|
end
|
332
472
|
end
|
@@ -334,13 +474,17 @@ module MessageTrain
|
|
334
474
|
describe '#update_message' do
|
335
475
|
describe 'when message is valid' do
|
336
476
|
context 'and still a draft' do
|
337
|
-
let(:valid_attributes)
|
338
|
-
|
477
|
+
let(:valid_attributes) do
|
478
|
+
{
|
479
|
+
recipients_to_save: { 'users' => 'second-user, third-user' },
|
339
480
|
subject: 'Test Message',
|
340
481
|
body: 'This is the content.',
|
341
482
|
draft: true
|
342
|
-
|
343
|
-
|
483
|
+
}
|
484
|
+
end
|
485
|
+
subject do
|
486
|
+
user_in_box.update_message(draft_message, valid_attributes)
|
487
|
+
end
|
344
488
|
it { should be_a MessageTrain::Message }
|
345
489
|
its('errors.full_messages.to_sentence') { should eq '' }
|
346
490
|
its(:recipients) { should be_empty }
|
@@ -348,13 +492,17 @@ module MessageTrain
|
|
348
492
|
its(:draft) { should be true }
|
349
493
|
end
|
350
494
|
context 'and no longer a draft' do
|
351
|
-
let(:valid_attributes)
|
352
|
-
|
495
|
+
let(:valid_attributes) do
|
496
|
+
{
|
497
|
+
recipients_to_save: { 'users' => 'second-user, third-user' },
|
353
498
|
subject: 'Test Message',
|
354
499
|
body: 'This is the content.',
|
355
500
|
draft: false
|
356
|
-
|
357
|
-
|
501
|
+
}
|
502
|
+
end
|
503
|
+
subject do
|
504
|
+
user_in_box.update_message(draft_message, valid_attributes)
|
505
|
+
end
|
358
506
|
it { should be_a MessageTrain::Message }
|
359
507
|
its('errors.full_messages.to_sentence') { should eq '' }
|
360
508
|
its(:recipients) { should include second_user }
|
@@ -364,15 +512,21 @@ module MessageTrain
|
|
364
512
|
end
|
365
513
|
end
|
366
514
|
context 'when message is invalid' do
|
367
|
-
let(:invalid_attributes)
|
368
|
-
|
515
|
+
let(:invalid_attributes) do
|
516
|
+
{
|
517
|
+
recipients_to_save: { 'users' => 'second-user, third-user' },
|
369
518
|
subject: '',
|
370
519
|
body: 'This is the content.',
|
371
520
|
draft: false
|
372
|
-
|
373
|
-
|
521
|
+
}
|
522
|
+
end
|
523
|
+
subject do
|
524
|
+
user_in_box.update_message(draft_message, invalid_attributes)
|
525
|
+
end
|
374
526
|
it { should be_a MessageTrain::Message }
|
375
|
-
its('errors.full_messages.to_sentence')
|
527
|
+
its('errors.full_messages.to_sentence') do
|
528
|
+
should eq "Subject can't be blank"
|
529
|
+
end
|
376
530
|
its(:recipients) { should be_empty }
|
377
531
|
end
|
378
532
|
end
|
@@ -384,7 +538,15 @@ module MessageTrain
|
|
384
538
|
first_user.box.authorize(second_user)
|
385
539
|
end
|
386
540
|
subject { first_user.box.errors.all }
|
387
|
-
it
|
541
|
+
it do
|
542
|
+
should eq(
|
543
|
+
[
|
544
|
+
css_id: 'user',
|
545
|
+
path: nil,
|
546
|
+
message: 'Cannot authorize User'
|
547
|
+
]
|
548
|
+
)
|
549
|
+
end
|
388
550
|
end
|
389
551
|
describe 'when conversation' do
|
390
552
|
describe 'is authorized' do
|
@@ -411,20 +573,41 @@ module MessageTrain
|
|
411
573
|
# This is really here to test the error handling for this case.
|
412
574
|
describe 'when message' do
|
413
575
|
describe 'is authorized' do
|
414
|
-
subject
|
576
|
+
subject do
|
577
|
+
first_group.box(:in, first_user).authorize(group_message)
|
578
|
+
end
|
415
579
|
it { should be true }
|
416
580
|
end
|
417
581
|
describe 'is not authorized' do
|
418
582
|
describe 'result' do
|
419
|
-
subject
|
583
|
+
subject do
|
584
|
+
membered_group.box(:in, third_user).authorize(
|
585
|
+
membered_group_message
|
586
|
+
)
|
587
|
+
end
|
420
588
|
it { should be false }
|
421
589
|
end
|
422
590
|
describe 'box status' do
|
423
591
|
before do
|
424
|
-
membered_group.box(:in, third_user).authorize(
|
592
|
+
membered_group.box(:in, third_user).authorize(
|
593
|
+
membered_group_message
|
594
|
+
)
|
425
595
|
end
|
426
596
|
subject { membered_group.box(:in, third_user).errors.all }
|
427
|
-
it
|
597
|
+
it do
|
598
|
+
should(
|
599
|
+
eq [
|
600
|
+
{
|
601
|
+
css_id: 'message_train_message_'\
|
602
|
+
"#{membered_group_message.id}",
|
603
|
+
path: '/collectives/groups:membered-group/box/in/'\
|
604
|
+
"messages/#{membered_group_message.id}",
|
605
|
+
message: 'Access to Message '\
|
606
|
+
"#{membered_group_message.id} denied"
|
607
|
+
}
|
608
|
+
]
|
609
|
+
)
|
610
|
+
end
|
428
611
|
end
|
429
612
|
end
|
430
613
|
end
|
@@ -12,16 +12,15 @@ module MessageTrain
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'Scopes and Methods' do
|
15
|
-
|
16
15
|
describe '.ignored' do
|
17
16
|
let(:results) { MessageTrain::Conversation.ignored(first_user) }
|
18
|
-
subject { results.first.
|
17
|
+
subject { results.first.participant_ignored?(first_user) }
|
19
18
|
it { should be true }
|
20
19
|
end
|
21
20
|
|
22
21
|
describe '.unignored' do
|
23
22
|
let(:results) { MessageTrain::Conversation.unignored(first_user) }
|
24
|
-
subject { results.first.
|
23
|
+
subject { results.first.participant_ignored?(first_user) }
|
25
24
|
it { should be false }
|
26
25
|
end
|
27
26
|
|
@@ -41,7 +40,9 @@ module MessageTrain
|
|
41
40
|
end
|
42
41
|
|
43
42
|
describe '.with_messages_through' do
|
44
|
-
subject
|
43
|
+
subject do
|
44
|
+
MessageTrain::Conversation.with_messages_through(first_group)
|
45
|
+
end
|
45
46
|
it { should include group_conversation }
|
46
47
|
end
|
47
48
|
|
@@ -52,16 +53,16 @@ module MessageTrain
|
|
52
53
|
it { should_not include third_user }
|
53
54
|
end
|
54
55
|
|
55
|
-
describe '#
|
56
|
-
subject { ignored_conversation.
|
56
|
+
describe '#participant_ignore and #participant_ignored?' do
|
57
|
+
subject { ignored_conversation.participant_ignored?(first_user) }
|
57
58
|
it { should be true }
|
58
59
|
end
|
59
60
|
|
60
|
-
describe '#
|
61
|
+
describe '#participant_unignore' do
|
61
62
|
before do
|
62
|
-
ignored_conversation.
|
63
|
+
ignored_conversation.participant_unignore(first_user)
|
63
64
|
end
|
64
|
-
subject { ignored_conversation.
|
65
|
+
subject { ignored_conversation.participant_ignored?(first_user) }
|
65
66
|
it { should be false }
|
66
67
|
end
|
67
68
|
|
@@ -142,13 +143,17 @@ module MessageTrain
|
|
142
143
|
end
|
143
144
|
describe '.find_by_subject' do
|
144
145
|
# Testing super on method_missing
|
145
|
-
subject
|
146
|
+
subject do
|
147
|
+
MessageTrain::Conversation.find_by_subject('Unread Conversation')
|
148
|
+
end
|
146
149
|
it { should be_a(MessageTrain::Conversation) }
|
147
150
|
end
|
148
151
|
describe '#missing_method' do
|
149
152
|
# Testing super on method_missing
|
150
153
|
it 'raises a NoMethodError' do
|
151
|
-
expect {unread_conversation.missing_method}.to
|
154
|
+
expect { unread_conversation.missing_method }.to(
|
155
|
+
raise_error(NoMethodError)
|
156
|
+
)
|
152
157
|
end
|
153
158
|
end
|
154
159
|
describe '.with_ready_by' do
|
@@ -170,7 +175,6 @@ module MessageTrain
|
|
170
175
|
it { should_not include unread_conversation }
|
171
176
|
end
|
172
177
|
end
|
173
|
-
|
174
178
|
end
|
175
179
|
end
|
176
180
|
end
|
@@ -11,7 +11,9 @@ module MessageTrain
|
|
11
11
|
describe 'Scopes and Methods' do
|
12
12
|
include_context 'loaded site'
|
13
13
|
describe '.find_all_by_participant' do
|
14
|
-
subject
|
14
|
+
subject do
|
15
|
+
ignored_conversation.ignores.find_all_by_participant(first_user)
|
16
|
+
end
|
15
17
|
its(:first) { should be_a MessageTrain::Ignore }
|
16
18
|
end
|
17
19
|
describe '.conversations' do
|