message_train 0.6.17 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +16 -13
  3. data/.rubocop_todo.yml +12 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +1 -1
  6. data/Gemfile +28 -30
  7. data/README.md +284 -0
  8. data/Rakefile +6 -7
  9. data/VERSION +1 -1
  10. data/app/assets/javascripts/ckeditor/{config.js.coffee → config.js} +7 -6
  11. data/app/assets/stylesheets/message_train.scss +0 -8
  12. data/app/controllers/concerns/message_train_authorization.rb +37 -0
  13. data/app/controllers/concerns/message_train_support.rb +41 -69
  14. data/app/controllers/message_train/application_controller.rb +1 -0
  15. data/app/controllers/message_train/boxes_controller.rb +5 -4
  16. data/app/controllers/message_train/conversations_controller.rb +7 -5
  17. data/app/controllers/message_train/messages_controller.rb +43 -27
  18. data/app/controllers/message_train/participants_controller.rb +14 -25
  19. data/app/controllers/message_train/unsubscribes_controller.rb +96 -61
  20. data/app/helpers/message_train/application_helper.rb +13 -7
  21. data/app/helpers/message_train/attachments_helper.rb +4 -12
  22. data/app/helpers/message_train/boxes_helper.rb +4 -14
  23. data/app/helpers/message_train/collectives_helper.rb +23 -29
  24. data/app/helpers/message_train/conversations_helper.rb +52 -30
  25. data/app/helpers/message_train/messages_helper.rb +33 -20
  26. data/app/mailers/message_train/receipt_mailer.rb +22 -12
  27. data/app/models/message_train/attachment.rb +2 -2
  28. data/app/models/message_train/box.rb +182 -228
  29. data/app/models/message_train/conversation.rb +100 -103
  30. data/app/models/message_train/ignore.rb +83 -4
  31. data/app/models/message_train/message.rb +66 -117
  32. data/app/models/message_train/receipt.rb +73 -49
  33. data/app/views/message_train/boxes/show.html.haml +11 -7
  34. data/config/locales/en.yml +1 -0
  35. data/config/routes.rb +6 -12
  36. data/lib/message_train.rb +3 -1
  37. data/lib/message_train/class_methods.rb +51 -0
  38. data/lib/message_train/configuration.rb +28 -3
  39. data/lib/message_train/instance_methods.rb +209 -0
  40. data/lib/message_train/mixin.rb +25 -320
  41. data/message_train.gemspec +83 -83
  42. data/spec/controllers/message_train/boxes_controller_spec.rb +37 -19
  43. data/spec/controllers/message_train/concerns_spec.rb +21 -3
  44. data/spec/controllers/message_train/conversations_controller_spec.rb +41 -18
  45. data/spec/controllers/message_train/messages_controller_spec.rb +112 -31
  46. data/spec/controllers/message_train/participants_controller_spec.rb +33 -7
  47. data/spec/controllers/message_train/unsubscribes_controller_spec.rb +10 -8
  48. data/spec/dummy/app/assets/stylesheets/{application.css.scss → application.scss} +2 -1
  49. data/spec/dummy/app/assets/stylesheets/bootstrap-everything.scss +54 -0
  50. data/spec/dummy/app/models/group.rb +1 -1
  51. data/spec/dummy/app/views/layouts/application.html.haml +9 -8
  52. data/spec/dummy/bin/setup +8 -8
  53. data/spec/dummy/config/application.rb +0 -3
  54. data/spec/dummy/config/environments/test.rb +4 -2
  55. data/spec/dummy/db/schema.rb +94 -103
  56. data/spec/dummy/db/test.sqlite3 +0 -0
  57. data/spec/factories/attachment.rb +3 -1
  58. data/spec/factories/message.rb +2 -3
  59. data/spec/features/boxes_spec.rb +0 -3
  60. data/spec/helpers/message_train/application_helper_spec.rb +3 -2
  61. data/spec/helpers/message_train/attachment_helper_spec.rb +4 -0
  62. data/spec/helpers/message_train/boxes_helper_spec.rb +1 -0
  63. data/spec/helpers/message_train/collectives_helper_spec.rb +1 -0
  64. data/spec/helpers/message_train/conversations_helper_spec.rb +3 -2
  65. data/spec/helpers/message_train/messages_helper_spec.rb +2 -1
  66. data/spec/models/group_spec.rb +6 -4
  67. data/spec/models/message_train/box_spec.rb +0 -88
  68. data/spec/models/message_train/ignore_spec.rb +65 -0
  69. data/spec/models/message_train/message_spec.rb +6 -5
  70. data/spec/models/message_train/receipt_spec.rb +6 -8
  71. data/spec/models/role_spec.rb +2 -2
  72. data/spec/models/user_spec.rb +29 -101
  73. data/spec/rails_helper.rb +16 -30
  74. data/spec/support/feature_behaviors.rb +2 -1
  75. data/spec/support/shared_connection.rb +5 -0
  76. data/spec/support/utilities.rb +7 -8
  77. metadata +145 -120
  78. data/README.rdoc +0 -175
  79. data/spec/dummy/app/models/.keep +0 -0
  80. data/spec/dummy/log/.keep +0 -0
Binary file
@@ -3,7 +3,9 @@ FactoryGirl.define do
3
3
  message { MessageTrain::Message.order('RANDOM()').first }
4
4
  attachment do
5
5
  File.open(
6
- Dir['spec/dummy/app/assets/files/message_train/attachments/*'].sample
6
+ Dir[
7
+ Rails.root.join 'app/assets/files/message_train/attachments/*'
8
+ ].sample
7
9
  )
8
10
  end
9
11
  end
@@ -26,10 +26,9 @@ FactoryGirl.define do
26
26
  generate_ignore? { [*1..100].sample >= 80 }
27
27
  end
28
28
 
29
- # the after(:create) yields two values; the user instance itself and the
29
+ # the after(:create) yields two values; the message instance itself and the
30
30
  # evaluator, which stores all values from the factory, including transient
31
- # attributes; `create_list`'s second argument is the number of records
32
- # to create and we make sure the user is associated properly to the post
31
+ # attributes
33
32
  after(:create) do |message, evaluator|
34
33
  if evaluator.generate_attachment?
35
34
  FactoryGirl.create(:attachment, message: message)
@@ -70,9 +70,6 @@ RSpec.feature 'Boxes' do
70
70
  before do
71
71
  visit '/box/in'
72
72
  click_link 'Last'
73
- find(
74
- "#message_train_conversation_#{unread_conversation.id}"
75
- ).hover
76
73
  within "#message_train_conversation_#{unread_conversation.id}" do
77
74
  accept_confirm do
78
75
  find('.trash-toggle').click
@@ -3,10 +3,11 @@ require 'rails_helper'
3
3
  describe MessageTrain::ApplicationHelper do
4
4
  include_context 'loaded site'
5
5
  include ControllerMacros
6
- helper MessageTrain::BoxesHelper
7
- helper MessageTrain::CollectivesHelper
8
6
 
9
7
  before do
8
+ view.extend MessageTrain::BoxesHelper
9
+ view.extend MessageTrain::CollectivesHelper
10
+ view.extend BootstrapLeatherHelper
10
11
  login_user first_user
11
12
  end
12
13
 
@@ -3,6 +3,10 @@ require 'rails_helper'
3
3
  describe MessageTrain::AttachmentsHelper do
4
4
  include_context 'loaded site'
5
5
 
6
+ before do
7
+ view.extend BootstrapLeatherHelper
8
+ end
9
+
6
10
  describe '#attachment_icon' do
7
11
  context 'when attachment is an image' do
8
12
  subject { helper.attachment_icon(image_attachment) }
@@ -5,6 +5,7 @@ describe MessageTrain::BoxesHelper do
5
5
  include ControllerMacros
6
6
 
7
7
  before do
8
+ view.extend BootstrapLeatherHelper
8
9
  login_user first_user
9
10
  end
10
11
 
@@ -5,6 +5,7 @@ describe MessageTrain::CollectivesHelper do
5
5
  include ControllerMacros
6
6
 
7
7
  before do
8
+ view.extend BootstrapLeatherHelper
8
9
  login_user first_user
9
10
  end
10
11
 
@@ -3,9 +3,10 @@ require 'rails_helper'
3
3
  describe MessageTrain::ConversationsHelper do
4
4
  include_context 'loaded site'
5
5
  include ControllerMacros
6
- helper MessageTrain::BoxesHelper
7
6
 
8
7
  before do
8
+ view.extend MessageTrain::BoxesHelper
9
+ view.extend BootstrapLeatherHelper
9
10
  login_user first_user
10
11
  assign(:box_user, first_user)
11
12
  end
@@ -17,7 +18,7 @@ describe MessageTrain::ConversationsHelper do
17
18
  end
18
19
  context 'when there is more than one sender' do
19
20
  subject { helper.conversation_senders(long_conversation) }
20
- it { should eq 'First User and Second User' }
21
+ it { should eq 'Second User and First User' }
21
22
  end
22
23
  end
23
24
 
@@ -3,9 +3,10 @@ require 'rails_helper'
3
3
  describe MessageTrain::MessagesHelper do
4
4
  include_context 'loaded site'
5
5
  include ControllerMacros
6
- helper MessageTrain::BoxesHelper
7
6
 
8
7
  before do
8
+ view.extend MessageTrain::BoxesHelper
9
+ view.extend BootstrapLeatherHelper
9
10
  login_user first_user
10
11
  assign(:box_user, first_user)
11
12
  end
@@ -11,8 +11,8 @@ RSpec.describe Group do
11
11
  end
12
12
 
13
13
  describe 'Scopes and Methods from Message Train' do
14
- describe '#slug_part' do
15
- subject { membered_group.slug_part }
14
+ describe '#message_train_slug' do
15
+ subject { membered_group.message_train_slug }
16
16
  it { should eq 'membered-group' }
17
17
  end
18
18
 
@@ -68,8 +68,10 @@ RSpec.describe Group do
68
68
 
69
69
  describe '#conversations' do
70
70
  subject { membered_group.conversations(:in, first_user) }
71
- its(:first) { should be_a MessageTrain::Conversation }
72
- its(:count) { should eq 4 }
71
+ it { should include membered_group_read_conversation }
72
+ it { should include membered_group_conversation }
73
+ it { should_not include membered_group_deleted_conversation }
74
+ it { should_not include membered_group_draft }
73
75
  end
74
76
 
75
77
  describe '#boxes_for_participant' do
@@ -89,26 +89,6 @@ module MessageTrain
89
89
  it { should eq unread_message }
90
90
  end
91
91
 
92
- describe '#new_message' do
93
- context 'when conversation is set' do
94
- let(:expected_recipients) { { 'users' => 'second-user' } }
95
- subject do
96
- user_in_box.new_message(
97
- message_train_conversation_id: unread_conversation.id
98
- )
99
- end
100
- it { should be_a_new MessageTrain::Message }
101
- its(:subject) { should eq 'Re: Unread Conversation' }
102
- its(:recipients_to_save) { should eq expected_recipients }
103
- end
104
- context 'when conversation is not set' do
105
- subject { user_in_box.new_message }
106
- it { should be_a_new MessageTrain::Message }
107
- its(:subject) { should eq nil }
108
- its(:recipients_to_save) { should be_empty }
109
- end
110
- end
111
-
112
92
  describe '#send_message' do
113
93
  describe 'to a singular recipient' do
114
94
  let(:message) do
@@ -243,74 +223,6 @@ module MessageTrain
243
223
  end
244
224
  end
245
225
 
246
- describe '#ignore' do
247
- context 'when not present' do
248
- it 'raises an ActiveRecord::RecordNotFound error' do
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
- )
255
- end
256
- end
257
- context 'when bad type' do
258
- before do
259
- last_user.box.ignore(first_user)
260
- end
261
- subject { last_user.box.errors.all.first[:message] }
262
- it { should match(/Cannot ignore User/) }
263
- end
264
- context 'when not authorized' do
265
- before do
266
- last_user.box.ignore(read_conversation)
267
- end
268
- subject { last_user.box.errors.all.first[:message] }
269
- it { should match(/Access to Conversation ([0-9]+) denied/) }
270
- end
271
- context 'when authorized' do
272
- before do
273
- user_in_box.ignore(read_conversation)
274
- end
275
- subject { read_conversation.participant_ignored?(first_user) }
276
- it { should be true }
277
- end
278
- end
279
-
280
- describe '#unignore' do
281
- context 'when not present' do
282
- it 'raises an ActiveRecord::RecordNotFound error' do
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
- )
289
- end
290
- end
291
- context 'when bad type' do
292
- before do
293
- last_user.box.unignore(first_user)
294
- end
295
- subject { last_user.box.errors.all.first[:message] }
296
- it { should match(/Cannot unignore User/) }
297
- end
298
- context 'when not authorized' do
299
- before do
300
- last_user.box.unignore(read_conversation)
301
- end
302
- subject { last_user.box.errors.all.first[:message] }
303
- it { should match(/Access to Conversation ([0-9]+) denied/) }
304
- end
305
- context 'when authorized' do
306
- before do
307
- user_in_box.unignore(ignored_conversation)
308
- end
309
- subject { ignored_conversation.participant_ignored?(first_user) }
310
- it { should be false }
311
- end
312
- end
313
-
314
226
  describe '#title' do
315
227
  context 'with division set to :in' do
316
228
  subject { user_in_box.title }
@@ -2,6 +2,7 @@ require 'rails_helper'
2
2
 
3
3
  module MessageTrain
4
4
  RSpec.describe Ignore do
5
+ let(:user_in_box) { first_user.box(:in) }
5
6
  describe 'Model' do
6
7
  it { should belong_to :conversation }
7
8
  it { should belong_to :participant }
@@ -20,6 +21,70 @@ module MessageTrain
20
21
  subject { MessageTrain::Ignore.conversations }
21
22
  it { should include ignored_conversation }
22
23
  end
24
+ describe '.ignore' do
25
+ context 'when not present' do
26
+ it 'raises an ActiveRecord::RecordNotFound error' do
27
+ expect { MessageTrain::Ignore.ignore(99_999_999, last_user.box) }
28
+ .to raise_error(
29
+ ActiveRecord::RecordNotFound,
30
+ /Couldn't find MessageTrain::Conversation with 'id'=99999999/
31
+ )
32
+ end
33
+ end
34
+ context 'when bad type' do
35
+ before do
36
+ MessageTrain::Ignore.ignore(first_user, last_user.box)
37
+ end
38
+ subject { last_user.box.errors.all.first[:message] }
39
+ it { should match(/Cannot ignore User/) }
40
+ end
41
+ context 'when not authorized' do
42
+ before do
43
+ MessageTrain::Ignore.ignore(read_conversation, last_user.box)
44
+ end
45
+ subject { last_user.box.errors.all.first[:message] }
46
+ it { should match(/Access to Conversation ([0-9]+) denied/) }
47
+ end
48
+ context 'when authorized' do
49
+ before do
50
+ MessageTrain::Ignore.ignore(read_conversation, user_in_box)
51
+ end
52
+ subject { read_conversation.participant_ignored?(first_user) }
53
+ it { should be true }
54
+ end
55
+ end
56
+ describe '.unignore' do
57
+ context 'when not present' do
58
+ it 'raises an ActiveRecord::RecordNotFound error' do
59
+ expect { MessageTrain::Ignore.unignore(99_999_999, last_user.box) }
60
+ .to raise_error(
61
+ ActiveRecord::RecordNotFound,
62
+ /Couldn't find MessageTrain::Conversation with 'id'=99999999/
63
+ )
64
+ end
65
+ end
66
+ context 'when bad type' do
67
+ before do
68
+ MessageTrain::Ignore.unignore(first_user, last_user.box)
69
+ end
70
+ subject { last_user.box.errors.all.first[:message] }
71
+ it { should match(/Cannot unignore User/) }
72
+ end
73
+ context 'when not authorized' do
74
+ before do
75
+ MessageTrain::Ignore.unignore(read_conversation, last_user.box)
76
+ end
77
+ subject { last_user.box.errors.all.first[:message] }
78
+ it { should match(/Access to Conversation ([0-9]+) denied/) }
79
+ end
80
+ context 'when authorized' do
81
+ before do
82
+ MessageTrain::Ignore.unignore(ignored_conversation, user_in_box)
83
+ end
84
+ subject { ignored_conversation.participant_ignored?(first_user) }
85
+ it { should be false }
86
+ end
87
+ end
23
88
  end
24
89
  end
25
90
  end
@@ -3,6 +3,7 @@ require 'rails_helper'
3
3
  module MessageTrain
4
4
  RSpec.describe Message do
5
5
  include_context 'loaded site'
6
+ let(:user_in_box) { first_user.box(:in) }
6
7
  describe 'Model' do
7
8
  # Relationships
8
9
  it { should belong_to :conversation }
@@ -31,7 +32,7 @@ module MessageTrain
31
32
  end
32
33
  context 'generates error when recipient_to_save does not exist' do
33
34
  let(:message) do
34
- first_user.box(:in).send_message(
35
+ user_in_box.send_message(
35
36
  subject: 'Message with missing recipient',
36
37
  recipients_to_save: { 'users' => 'missing-user' },
37
38
  body: 'Foo.'
@@ -48,7 +49,7 @@ module MessageTrain
48
49
  it { should_not include draft_conversation }
49
50
  end
50
51
  context '.drafts' do
51
- subject { MessageTrain::Message.drafts.first.conversation }
52
+ subject { MessageTrain::Message.drafts.last.conversation }
52
53
  it { should eq draft_conversation }
53
54
  end
54
55
  context '.by' do
@@ -57,7 +58,7 @@ module MessageTrain
57
58
  it { should include draft_message }
58
59
  end
59
60
  context '.drafts_by' do
60
- subject { MessageTrain::Message.drafts_by(first_user).first }
61
+ subject { MessageTrain::Message.drafts_by(first_user).last }
61
62
  it { should eq draft_message }
62
63
  end
63
64
  context '.find_by_subject' do
@@ -72,11 +73,11 @@ module MessageTrain
72
73
  end
73
74
  end
74
75
  context '.with_receipts_by' do
75
- subject { MessageTrain::Message.with_receipts_by(first_user).last }
76
+ subject { MessageTrain::Message.with_receipts_by(first_user).first }
76
77
  it { should eq sent_message }
77
78
  end
78
79
  context '.with_receipts_to' do
79
- subject { MessageTrain::Message.with_receipts_to(first_user).last }
80
+ subject { MessageTrain::Message.with_receipts_to(first_user).first }
80
81
  it { should eq unread_message }
81
82
  end
82
83
  context '.with_trashed_to and #is_trashed_to?' do
@@ -43,10 +43,9 @@ module MessageTrain
43
43
  end
44
44
  describe '.trashed_to' do
45
45
  subject do
46
- MessageTrain::Receipt.trashed_to(first_user)
47
- .first.message.conversation
46
+ MessageTrain::Receipt.trashed_to(first_user).conversations
48
47
  end
49
- its(:subject) { should eq 'Membered Group Trashed Conversation' }
48
+ it { should include membered_group_trashed_conversation }
50
49
  end
51
50
  describe '.untrashed_to' do
52
51
  subject do
@@ -56,16 +55,15 @@ module MessageTrain
56
55
  end
57
56
  describe '.read_to' do
58
57
  subject do
59
- MessageTrain::Receipt.read_to(first_user).first.message.conversation
58
+ MessageTrain::Receipt.read_to(first_user).conversations
60
59
  end
61
- its(:subject) { should eq 'Membered Group Read Conversation' }
60
+ it { should include membered_group_read_conversation }
62
61
  end
63
62
  describe '.deleted_to' do
64
63
  subject do
65
- MessageTrain::Receipt.deleted_to(first_user)
66
- .first.message.conversation
64
+ MessageTrain::Receipt.deleted_to(first_user).conversations
67
65
  end
68
- its(:subject) { should eq 'Membered Group Deleted Conversation' }
66
+ it { should include membered_group_deleted_conversation }
69
67
  end
70
68
  describe '.undeleted_to' do
71
69
  subject { MessageTrain::Receipt.undeleted_to(first_user).first }
@@ -9,8 +9,8 @@ RSpec.describe Role do
9
9
  describe 'Scopes and Methods from Message Train' do
10
10
  include_context 'loaded site'
11
11
 
12
- describe '#slug_part' do
13
- subject { superadmin_role.slug_part }
12
+ describe '#message_train_slug' do
13
+ subject { superadmin_role.message_train_slug }
14
14
  it { should eq 'superadmin' }
15
15
  end
16
16
 
@@ -14,25 +14,11 @@ RSpec.describe User do
14
14
 
15
15
  describe 'Scopes and Methods' do
16
16
  describe '#box' do
17
- describe 'with valid number of arguments' do
18
- subject { first_user.box }
19
- it { should be_a MessageTrain::Box }
20
- its(:division) { should be :in }
21
- its(:parent) { should be first_user }
22
- its(:participant) { should be first_user }
23
- end
24
- describe 'with invalid number of arguments' do
25
- it 'should raise' do
26
- expect do
27
- first_user.box(:in, first_user, 'extra argument')
28
- end.to(
29
- raise_error(
30
- RuntimeError,
31
- 'Wrong number of arguments for User (expected 0..2, got 3)'
32
- )
33
- )
34
- end
35
- end
17
+ subject { first_user.box }
18
+ it { should be_a MessageTrain::Box }
19
+ its(:division) { should be :in }
20
+ its(:parent) { should be first_user }
21
+ its(:participant) { should be first_user }
36
22
  end
37
23
 
38
24
  describe '#collective_boxes' do
@@ -50,18 +36,6 @@ RSpec.describe User do
50
36
  it { should include membered_group }
51
37
  it { should include first_group }
52
38
  end
53
- describe 'with 3 arguments' do
54
- it 'should raise' do
55
- expect do
56
- first_user.collective_boxes(:in, first_user, 'extra argument')
57
- end.to(
58
- raise_error(
59
- RuntimeError,
60
- 'Wrong number of arguments for User (expected 0..2, got 3)'
61
- )
62
- )
63
- end
64
- end
65
39
  end
66
40
 
67
41
  describe '#all_boxes' do
@@ -79,18 +53,6 @@ RSpec.describe User do
79
53
  its(:count) { should be 6 }
80
54
  end
81
55
  end
82
- describe 'with 2 arguments' do
83
- it 'should raise' do
84
- expect do
85
- first_user.all_boxes(first_user, 'extra argument')
86
- end.to(
87
- raise_error(
88
- RuntimeError,
89
- 'Wrong number of arguments for User (expected 0..1, got 2)'
90
- )
91
- )
92
- end
93
- end
94
56
  end
95
57
 
96
58
  describe '#conversations' do
@@ -120,18 +82,6 @@ RSpec.describe User do
120
82
  end
121
83
  it { should be true }
122
84
  end
123
- describe 'with 23 arguments' do
124
- it 'should raise' do
125
- expect do
126
- first_user.conversations(:in, first_user, 'extra argument')
127
- end.to(
128
- raise_error(
129
- RuntimeError,
130
- 'Wrong number of arguments for User (expected 0..2, got 3)'
131
- )
132
- )
133
- end
134
- end
135
85
  context 'with impossible division' do
136
86
  subject { first_user.conversations(:impossible).nil? }
137
87
  it { should be true }
@@ -139,42 +89,30 @@ RSpec.describe User do
139
89
  end
140
90
 
141
91
  describe '#all_conversations' do
92
+ let(:required_conversations) do
93
+ [
94
+ sent_conversation,
95
+ unread_conversation,
96
+ read_conversation,
97
+ ignored_conversation,
98
+ trashed_conversation,
99
+ deleted_conversation
100
+ ]
101
+ end
142
102
  describe 'with no arguments' do
143
103
  context 'returns all conversations with any receipt' do
144
104
  subject { first_user.all_conversations }
145
- it { should include sent_conversation }
146
- it { should include unread_conversation }
147
- it { should include read_conversation }
148
- it { should include ignored_conversation }
149
- it { should include trashed_conversation }
150
- it { should include deleted_conversation }
105
+ it { should include(*required_conversations) }
151
106
  it { should_not include someone_elses_conversation }
152
107
  end
153
108
  end
154
109
  describe 'with 1 argument' do
155
110
  context 'returns all conversations with any receipt' do
156
111
  subject { first_user.all_conversations(first_user) }
157
- it { should include sent_conversation }
158
- it { should include unread_conversation }
159
- it { should include read_conversation }
160
- it { should include ignored_conversation }
161
- it { should include trashed_conversation }
162
- it { should include deleted_conversation }
112
+ it { should include(*required_conversations) }
163
113
  it { should_not include someone_elses_conversation }
164
114
  end
165
115
  end
166
- describe 'with 2 arguments' do
167
- it 'should raise' do
168
- expect do
169
- first_user.all_conversations(first_user, 'extra argument')
170
- end.to(
171
- raise_error(
172
- RuntimeError,
173
- 'Wrong number of arguments for User (expected 0..1, got 2)'
174
- )
175
- )
176
- end
177
- end
178
116
  context 'when empty' do
179
117
  subject { silent_user.all_conversations }
180
118
  it { should eq [] }
@@ -182,40 +120,30 @@ RSpec.describe User do
182
120
  end
183
121
 
184
122
  describe '#all_messages' do
123
+ let(:required_messages) do
124
+ [
125
+ sent_message,
126
+ unread_message,
127
+ read_message,
128
+ ignored_message,
129
+ trashed_message,
130
+ deleted_message
131
+ ]
132
+ end
185
133
  describe 'with no arguments' do
186
134
  context 'returns all messages with any receipt' do
187
135
  subject { first_user.all_messages }
188
- it { should include sent_message }
189
- it { should include unread_message }
190
- it { should include read_message }
191
- it { should include ignored_message }
192
- it { should include trashed_message }
193
- it { should include deleted_message }
136
+ it { should include(*required_messages) }
194
137
  it { should_not include someone_elses_message }
195
138
  end
196
139
  end
197
140
  describe 'with 1 argument' do
198
141
  context 'returns all messages with any receipt' do
199
142
  subject { first_user.all_messages(first_user) }
200
- it { should include sent_message }
201
- it { should include unread_message }
202
- it { should include read_message }
203
- it { should include ignored_message }
204
- it { should include trashed_message }
205
- it { should include deleted_message }
143
+ it { should include(*required_messages) }
206
144
  it { should_not include someone_elses_message }
207
145
  end
208
146
  end
209
- describe 'with 2 arguments' do
210
- it 'should raise' do
211
- expect { first_user.all_messages(first_user, 'extra argument') }.to(
212
- raise_error(
213
- RuntimeError,
214
- 'Wrong number of arguments for User (expected 0..1, got 2)'
215
- )
216
- )
217
- end
218
- end
219
147
  context 'when empty' do
220
148
  subject { silent_user.all_messages }
221
149
  it { should eq [] }