message_train 0.1.7 → 0.2.0
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/.simplecov +8 -0
- data/.travis.yml +7 -2
- data/Gemfile +3 -0
- data/README.rdoc +37 -1
- data/Rakefile +5 -6
- data/VERSION +1 -1
- data/app/assets/javascripts/message_train.js +33 -0
- data/app/assets/stylesheets/message_train.scss +26 -0
- data/app/controllers/concerns/message_train_support.rb +127 -0
- data/app/controllers/message_train/application_controller.rb +1 -60
- data/app/controllers/message_train/boxes_controller.rb +0 -4
- data/app/controllers/message_train/messages_controller.rb +12 -6
- data/app/controllers/message_train/participants_controller.rb +1 -1
- data/app/controllers/message_train/unsubscribes_controller.rb +59 -0
- data/app/helpers/message_train/application_helper.rb +26 -0
- data/app/helpers/message_train/attachments_helper.rb +19 -0
- data/app/helpers/message_train/boxes_helper.rb +16 -11
- data/app/helpers/message_train/collectives_helper.rb +48 -0
- data/app/helpers/message_train/conversations_helper.rb +24 -16
- data/app/helpers/message_train/messages_helper.rb +14 -12
- data/app/mailers/message_train/application_mailer.rb +8 -0
- data/app/mailers/message_train/previews/receipt_mailer_preview.rb +10 -0
- data/app/mailers/message_train/receipt_mailer.rb +17 -0
- data/app/models/message_train/attachment.rb +28 -10
- data/app/models/message_train/box.rb +114 -83
- data/app/models/message_train/conversation.rb +48 -39
- data/app/models/message_train/ignore.rb +2 -6
- data/app/models/message_train/message.rb +40 -24
- data/app/models/message_train/receipt.rb +20 -10
- data/app/models/message_train/unsubscribe.rb +7 -0
- data/app/views/layouts/mailer.html.haml +6 -0
- data/app/views/message_train/application/_attachment_fields.html.haml +7 -0
- data/app/views/message_train/application/_attachment_link.html.haml +4 -0
- data/app/views/message_train/application/_widget.html.haml +6 -0
- data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -2
- data/app/views/message_train/boxes/_list_item.html.haml +2 -2
- data/app/views/message_train/boxes/_widget.html.haml +4 -1
- data/app/views/message_train/boxes/show.html.haml +12 -4
- data/app/views/message_train/collectives/_dropdown_list.html.haml +6 -0
- data/app/views/message_train/collectives/_list_item.html.haml +5 -0
- data/app/views/message_train/collectives/_widget.html.haml +7 -0
- data/app/views/message_train/conversations/_conversation.html.haml +22 -7
- data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_ignored_toggle.html.haml +3 -3
- data/app/views/message_train/conversations/_read_toggle.html.haml +3 -3
- data/app/views/message_train/conversations/_toggle.html.haml +4 -1
- data/app/views/message_train/conversations/_trashed_toggle.html.haml +3 -3
- data/app/views/message_train/conversations/show.html.haml +4 -3
- data/app/views/message_train/messages/_deleted_toggle.html.haml +1 -1
- data/app/views/message_train/messages/_form.html.haml +22 -7
- data/app/views/message_train/messages/_message.html.haml +14 -4
- data/app/views/message_train/messages/_read_toggle.html.haml +1 -1
- data/app/views/message_train/messages/_trashed_toggle.html.haml +1 -1
- data/app/views/message_train/messages/edit.html.haml +1 -1
- data/app/views/message_train/messages/new.html.haml +4 -1
- data/app/views/message_train/participants/_field.html.haml +1 -1
- data/app/views/message_train/participants/_prefilled_field.html.haml +4 -0
- data/app/views/message_train/receipt_mailer/notification_email.html.haml +13 -0
- data/app/views/message_train/unsubscribes/index.html.haml +10 -0
- data/config/environment.rb +1 -0
- data/config/locales/en.yml +49 -7
- data/config/routes.rb +10 -2
- data/db/migrate/20150901183458_add_received_through_to_message_train_receipts.rb +6 -0
- data/db/migrate/20151004184347_add_unique_index_to_receipts.rb +5 -0
- data/db/migrate/20151124000820_create_message_train_unsubscribes.rb +14 -0
- data/lib/generators/message_train/install/install_generator.rb +8 -2
- data/lib/generators/message_train/install/templates/initializer.rb +5 -1
- data/lib/message_train/configuration.rb +11 -1
- data/lib/message_train/engine.rb +1 -0
- data/lib/message_train/mixin.rb +206 -21
- data/message_train.gemspec +66 -13
- data/spec/controllers/message_train/boxes_controller_spec.rb +10 -3
- data/spec/controllers/message_train/concerns_spec.rb +40 -0
- data/spec/controllers/message_train/conversations_controller_spec.rb +3 -3
- data/spec/controllers/message_train/messages_controller_spec.rb +60 -27
- data/spec/controllers/message_train/participants_controller_spec.rb +41 -6
- data/spec/controllers/message_train/unsubscribes_controller_spec.rb +56 -0
- data/spec/dummy/app/assets/files/message_train/attachments/{1917-Boys_Race_Above-Wiki.jpg → image-sample.jpg} +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/models/group.rb +16 -1
- data/spec/dummy/app/models/role.rb +22 -0
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/app/views/layouts/_top_navigation.html.haml +4 -2
- data/spec/dummy/app/views/layouts/application.html.haml +2 -3
- data/spec/dummy/app/views/pages/index.html.haml +4 -0
- data/spec/dummy/config/application.rb +6 -0
- data/spec/dummy/config/environments/development.rb +1 -0
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/initializers/high_voltage.rb +3 -0
- data/spec/dummy/config/initializers/message_train.rb +6 -1
- data/spec/dummy/config/initializers/paperclip.rb +2 -2
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/config/settings.yml +9 -0
- data/spec/dummy/db/migrate/{20150724142846_create_message_train_conversations.night_train.rb → 20150901183629_create_message_train_conversations.message_train.rb} +0 -0
- data/spec/dummy/db/migrate/{20150724142847_create_message_train_messages.night_train.rb → 20150901183630_create_message_train_messages.message_train.rb} +0 -0
- data/spec/dummy/db/migrate/{20150724142848_create_message_train_attachments.night_train.rb → 20150901183631_create_message_train_attachments.message_train.rb} +0 -0
- data/spec/dummy/db/migrate/{20150724142849_create_message_train_receipts.night_train.rb → 20150901183632_create_message_train_receipts.message_train.rb} +0 -0
- data/spec/dummy/db/migrate/{20150724142850_create_message_train_ignores.night_train.rb → 20150901183633_create_message_train_ignores.message_train.rb} +0 -0
- data/spec/dummy/db/migrate/20150901183634_add_received_through_to_message_train_receipts.message_train.rb +7 -0
- data/spec/dummy/db/migrate/20151004184519_add_unique_index_to_receipts.message_train.rb +6 -0
- data/spec/dummy/db/migrate/20151124001417_create_message_train_unsubscribes.message_train.rb +15 -0
- data/spec/dummy/db/schema.rb +24 -7
- data/spec/dummy/db/seeds/conversations.seeds.rb +92 -3
- data/spec/dummy/db/seeds/groups.seeds.rb +27 -0
- data/spec/dummy/db/seeds/test/attachments.seeds.rb +4 -0
- data/spec/dummy/db/seeds/unsubscribes.seeds.rb +12 -0
- data/spec/dummy/db/seeds/users.seeds.rb +27 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/group.rb +4 -4
- data/spec/factories/message.rb +10 -3
- data/spec/features/boxes_spec.rb +160 -33
- data/spec/features/conversations_spec.rb +11 -4
- data/spec/features/messages_spec.rb +20 -6
- data/spec/features/unsubscribes_spec.rb +38 -0
- data/spec/helpers/message_train/application_helper_spec.rb +60 -0
- data/spec/helpers/message_train/attachment_helper_spec.rb +35 -0
- data/spec/helpers/message_train/boxes_helper_spec.rb +11 -5
- data/spec/helpers/message_train/collectives_helper_spec.rb +76 -0
- data/spec/helpers/message_train/conversations_helper_spec.rb +295 -0
- data/spec/helpers/message_train/messages_helper_spec.rb +217 -0
- data/spec/models/group_spec.rb +112 -2
- data/spec/models/message_train/attachment_spec.rb +44 -1
- data/spec/models/message_train/box_spec.rb +306 -51
- data/spec/models/message_train/conversation_spec.rb +84 -6
- data/spec/models/message_train/ignore_spec.rb +0 -4
- data/spec/models/message_train/message_spec.rb +49 -12
- data/spec/models/message_train/receipt_spec.rb +44 -8
- data/spec/models/message_train/unsubscribe_spec.rb +16 -0
- data/spec/models/role_spec.rb +125 -0
- data/spec/models/user_spec.rb +155 -26
- data/spec/rails_helper.rb +8 -1
- data/spec/support/attachments.rb +4 -0
- data/spec/support/controller_behaviors.rb +28 -0
- data/spec/support/conversations.rb +13 -0
- data/spec/support/groups.rb +3 -0
- data/spec/support/loaded_site.rb +3 -0
- data/spec/support/messages.rb +23 -0
- data/spec/support/roles.rb +4 -0
- data/spec/support/users.rb +6 -0
- data/spec/support/wysihtml5_helper.rb +8 -0
- metadata +99 -12
- data/spec/dummy/app/assets/files/message_train/attachments/Haie_rci.svg +0 -1714
- data/spec/dummy/public/capybara.html +0 -193
|
@@ -2,23 +2,61 @@ require 'rails_helper'
|
|
|
2
2
|
|
|
3
3
|
module MessageTrain
|
|
4
4
|
RSpec.describe Conversation do
|
|
5
|
+
include_context 'loaded site'
|
|
6
|
+
|
|
5
7
|
describe 'Model' do
|
|
6
8
|
it { should have_many :messages }
|
|
7
9
|
it { should have_many :ignores }
|
|
8
10
|
it { should have_many(:receipts).through(:messages) }
|
|
11
|
+
it { should have_many(:attachments).through(:messages) }
|
|
9
12
|
end
|
|
13
|
+
|
|
10
14
|
describe 'Scopes and Methods' do
|
|
11
|
-
|
|
15
|
+
|
|
16
|
+
describe '.ignored' do
|
|
17
|
+
let(:results) { MessageTrain::Conversation.ignored(first_user) }
|
|
18
|
+
subject { results.first.is_ignored?(first_user) }
|
|
19
|
+
it { should be true }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '.unignored' do
|
|
23
|
+
let(:results) { MessageTrain::Conversation.unignored(first_user) }
|
|
24
|
+
subject { results.first.is_ignored?(first_user) }
|
|
25
|
+
it { should be false }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '.with_drafts_by' do
|
|
29
|
+
subject { MessageTrain::Conversation.with_drafts_by(first_user) }
|
|
30
|
+
it { should include draft_conversation }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '.with_ready_for' do
|
|
34
|
+
subject { MessageTrain::Conversation.with_ready_for(first_user) }
|
|
35
|
+
it { should include unread_conversation }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '.with_messages_for' do
|
|
39
|
+
subject { MessageTrain::Conversation.with_messages_for(first_user) }
|
|
40
|
+
it { should include unread_conversation }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe '.with_messages_through' do
|
|
44
|
+
subject { MessageTrain::Conversation.with_messages_through(first_group) }
|
|
45
|
+
it { should include group_conversation }
|
|
46
|
+
end
|
|
47
|
+
|
|
12
48
|
describe '#default_recipients_for' do
|
|
13
49
|
subject { sent_conversation.default_recipients_for(first_user) }
|
|
14
50
|
it { should include second_user }
|
|
15
51
|
it { should_not include first_user }
|
|
16
52
|
it { should_not include third_user }
|
|
17
53
|
end
|
|
54
|
+
|
|
18
55
|
describe '#set_ignored and #is_ignored?' do
|
|
19
56
|
subject { ignored_conversation.is_ignored?(first_user) }
|
|
20
57
|
it { should be true }
|
|
21
58
|
end
|
|
59
|
+
|
|
22
60
|
describe '#set_unignored' do
|
|
23
61
|
before do
|
|
24
62
|
ignored_conversation.set_unignored(first_user)
|
|
@@ -26,6 +64,7 @@ module MessageTrain
|
|
|
26
64
|
subject { ignored_conversation.is_ignored?(first_user) }
|
|
27
65
|
it { should be false }
|
|
28
66
|
end
|
|
67
|
+
|
|
29
68
|
describe '#mark and #includes_read_for?' do
|
|
30
69
|
before do
|
|
31
70
|
unread_conversation.mark(:read, first_user)
|
|
@@ -33,15 +72,12 @@ module MessageTrain
|
|
|
33
72
|
subject { unread_conversation.includes_read_for?(first_user) }
|
|
34
73
|
it { should be true }
|
|
35
74
|
end
|
|
75
|
+
|
|
36
76
|
describe '#includes_drafts_by?' do
|
|
37
77
|
subject { draft_conversation.includes_drafts_by?(first_user) }
|
|
38
78
|
it { should be true }
|
|
39
79
|
end
|
|
40
|
-
|
|
41
|
-
subject { MessageTrain::Conversation.with_drafts_by(first_user) }
|
|
42
|
-
its(:first) { should be_a MessageTrain::Conversation }
|
|
43
|
-
its(:count) { should eq 1 }
|
|
44
|
-
end
|
|
80
|
+
|
|
45
81
|
describe 'Dynamic Methods' do
|
|
46
82
|
describe '.trashed_for' do
|
|
47
83
|
subject { MessageTrain::Conversation.with_trashed_for(first_user) }
|
|
@@ -72,6 +108,14 @@ module MessageTrain
|
|
|
72
108
|
subject { trashed_conversation.includes_trashed_to?(first_user) }
|
|
73
109
|
it { should be true }
|
|
74
110
|
end
|
|
111
|
+
describe '#includes_ready_by?' do
|
|
112
|
+
subject { sent_conversation.includes_ready_by?(first_user) }
|
|
113
|
+
it { should be true }
|
|
114
|
+
end
|
|
115
|
+
describe '#includes_ready_to?' do
|
|
116
|
+
subject { unread_conversation.includes_ready_to?(first_user) }
|
|
117
|
+
it { should be true }
|
|
118
|
+
end
|
|
75
119
|
describe '#includes_read_to?' do
|
|
76
120
|
subject { read_conversation.includes_read_to?(first_user) }
|
|
77
121
|
it { should be true }
|
|
@@ -92,7 +136,41 @@ module MessageTrain
|
|
|
92
136
|
subject { sent_conversation.includes_receipts_for?(first_user) }
|
|
93
137
|
it { should be true }
|
|
94
138
|
end
|
|
139
|
+
describe 'responds to :includes_ready_for?' do
|
|
140
|
+
subject { unread_conversation.respond_to? :includes_ready_for? }
|
|
141
|
+
it { should be true }
|
|
142
|
+
end
|
|
143
|
+
describe '.find_by_subject' do
|
|
144
|
+
# Testing super on method_missing
|
|
145
|
+
subject { MessageTrain::Conversation.find_by_subject('Unread Conversation') }
|
|
146
|
+
it { should be_a(MessageTrain::Conversation) }
|
|
147
|
+
end
|
|
148
|
+
describe '#missing_method' do
|
|
149
|
+
# Testing super on method_missing
|
|
150
|
+
it 'raises a NoMethodError' do
|
|
151
|
+
expect {unread_conversation.missing_method}.to raise_error(NoMethodError)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
describe '.with_ready_by' do
|
|
155
|
+
subject { MessageTrain::Conversation.with_ready_by(first_user) }
|
|
156
|
+
it { should include sent_conversation }
|
|
157
|
+
it { should_not include draft_conversation }
|
|
158
|
+
it { should_not include unread_conversation }
|
|
159
|
+
end
|
|
160
|
+
describe '.with_ready_to' do
|
|
161
|
+
subject { MessageTrain::Conversation.with_ready_to(first_user) }
|
|
162
|
+
it { should_not include sent_conversation }
|
|
163
|
+
it { should_not include draft_conversation }
|
|
164
|
+
it { should include unread_conversation }
|
|
165
|
+
end
|
|
166
|
+
describe '.with_messages_by' do
|
|
167
|
+
subject { MessageTrain::Conversation.with_messages_by(first_user) }
|
|
168
|
+
it { should include sent_conversation }
|
|
169
|
+
it { should include draft_conversation }
|
|
170
|
+
it { should_not include unread_conversation }
|
|
171
|
+
end
|
|
95
172
|
end
|
|
173
|
+
|
|
96
174
|
end
|
|
97
175
|
end
|
|
98
176
|
end
|
|
@@ -14,10 +14,6 @@ module MessageTrain
|
|
|
14
14
|
subject { ignored_conversation.ignores.find_all_by_participant(first_user) }
|
|
15
15
|
its(:first) { should be_a MessageTrain::Ignore }
|
|
16
16
|
end
|
|
17
|
-
describe '.conversation_ids' do
|
|
18
|
-
subject { MessageTrain::Ignore.conversation_ids }
|
|
19
|
-
it { should include ignored_conversation.id }
|
|
20
|
-
end
|
|
21
17
|
describe '.conversations' do
|
|
22
18
|
subject { MessageTrain::Ignore.conversations }
|
|
23
19
|
it { should include ignored_conversation }
|
|
@@ -23,34 +23,55 @@ module MessageTrain
|
|
|
23
23
|
its(:draft) { should be true }
|
|
24
24
|
end
|
|
25
25
|
context 'generates receipts when present' do
|
|
26
|
-
subject {
|
|
26
|
+
subject { sent_message }
|
|
27
27
|
its(:sender) { should eq first_user }
|
|
28
28
|
its(:receipts) { should have_exactly(2).items } # i.e. sender and recipient
|
|
29
29
|
its(:recipients) { should include second_user }
|
|
30
30
|
its(:draft) { should be false }
|
|
31
31
|
end
|
|
32
|
+
context 'generates error when recipient_to_save does not exist' do
|
|
33
|
+
let(:message) { first_user.box(:in).send_message(subject: 'Message with missing recipient', recipients_to_save: { 'users' => 'missing-user' }, body: 'Foo.') }
|
|
34
|
+
subject { message.errors.full_messages.to_sentence }
|
|
35
|
+
it { should eq 'Recipient missing-user not found' }
|
|
36
|
+
end
|
|
32
37
|
end
|
|
33
38
|
describe 'Scopes and Methods' do
|
|
39
|
+
context '.ready' do
|
|
40
|
+
subject { MessageTrain::Message.ready.conversations }
|
|
41
|
+
it { should include sent_conversation }
|
|
42
|
+
it { should_not include draft_conversation }
|
|
43
|
+
end
|
|
34
44
|
context '.drafts' do
|
|
35
45
|
subject { MessageTrain::Message.drafts.first.conversation }
|
|
36
46
|
it { should eq draft_conversation }
|
|
37
47
|
end
|
|
38
48
|
context '.by' do
|
|
39
49
|
subject { MessageTrain::Message.by(first_user) }
|
|
40
|
-
it { should include
|
|
41
|
-
it { should include
|
|
50
|
+
it { should include sent_message }
|
|
51
|
+
it { should include draft_message }
|
|
42
52
|
end
|
|
43
53
|
context '.drafts_by' do
|
|
44
|
-
subject { MessageTrain::Message.drafts_by(first_user).first
|
|
45
|
-
it { should eq
|
|
54
|
+
subject { MessageTrain::Message.drafts_by(first_user).first }
|
|
55
|
+
it { should eq draft_message }
|
|
56
|
+
end
|
|
57
|
+
context '.find_by_subject' do
|
|
58
|
+
# Testing super on method_missing
|
|
59
|
+
subject { MessageTrain::Message.find_by_subject('Sent Conversation') }
|
|
60
|
+
it { should eq sent_message }
|
|
61
|
+
end
|
|
62
|
+
describe '#missing_method' do
|
|
63
|
+
# Testing super on method_missing
|
|
64
|
+
it 'raises a NoMethodError' do
|
|
65
|
+
expect {unread_message.missing_method}.to raise_error(NoMethodError)
|
|
66
|
+
end
|
|
46
67
|
end
|
|
47
68
|
context '.with_receipts_by' do
|
|
48
|
-
subject { MessageTrain::Message.with_receipts_by(first_user).last
|
|
49
|
-
it { should eq
|
|
69
|
+
subject { MessageTrain::Message.with_receipts_by(first_user).last }
|
|
70
|
+
it { should eq sent_message }
|
|
50
71
|
end
|
|
51
72
|
context '.with_receipts_to' do
|
|
52
|
-
subject { MessageTrain::Message.with_receipts_to(first_user).last
|
|
53
|
-
it { should eq
|
|
73
|
+
subject { MessageTrain::Message.with_receipts_to(first_user).last }
|
|
74
|
+
it { should eq unread_message }
|
|
54
75
|
end
|
|
55
76
|
context '.with_trashed_to and #is_trashed_to?' do
|
|
56
77
|
subject { trashed_conversation.messages.with_trashed_to(first_user).first.is_trashed_to?(first_user) }
|
|
@@ -68,16 +89,32 @@ module MessageTrain
|
|
|
68
89
|
before do
|
|
69
90
|
read_conversation.messages.mark(:trash, first_user)
|
|
70
91
|
end
|
|
71
|
-
subject {
|
|
92
|
+
subject { read_message.is_trashed_to?(first_user) }
|
|
72
93
|
it { should be true }
|
|
73
94
|
end
|
|
74
95
|
context '#mark' do
|
|
75
96
|
before do
|
|
76
|
-
|
|
97
|
+
read_message.mark(:unread, first_user)
|
|
77
98
|
end
|
|
78
|
-
subject {
|
|
99
|
+
subject { read_message.is_read_to?(first_user) }
|
|
79
100
|
it { should be false }
|
|
80
101
|
end
|
|
102
|
+
context '#recipients' do
|
|
103
|
+
subject { unread_message.recipients.first }
|
|
104
|
+
it { should eq first_user }
|
|
105
|
+
end
|
|
106
|
+
context '.conversation_ids' do
|
|
107
|
+
subject { unread_conversation.messages.conversation_ids }
|
|
108
|
+
its(:first) { should eq unread_conversation.id }
|
|
109
|
+
end
|
|
110
|
+
context '.conversations' do
|
|
111
|
+
subject { unread_conversation.messages.conversations }
|
|
112
|
+
its(:first) { should eq unread_conversation }
|
|
113
|
+
end
|
|
114
|
+
describe 'responds to :is_message_by?' do
|
|
115
|
+
subject { unread_message.respond_to? :is_message_by? }
|
|
116
|
+
it { should be true }
|
|
117
|
+
end
|
|
81
118
|
end
|
|
82
119
|
end
|
|
83
120
|
end
|
|
@@ -2,16 +2,19 @@ require 'rails_helper'
|
|
|
2
2
|
|
|
3
3
|
module MessageTrain
|
|
4
4
|
RSpec.describe Receipt do
|
|
5
|
+
include_context 'loaded site'
|
|
6
|
+
|
|
5
7
|
describe 'Model' do
|
|
6
8
|
# Relationships
|
|
7
9
|
it { should belong_to :message }
|
|
8
10
|
it { should belong_to :recipient }
|
|
11
|
+
it { should belong_to :received_through }
|
|
9
12
|
# Validations
|
|
10
13
|
it { should validate_presence_of :message }
|
|
11
14
|
it { should validate_presence_of :recipient }
|
|
12
15
|
end
|
|
16
|
+
|
|
13
17
|
describe 'Scopes and Methods' do
|
|
14
|
-
include_context 'loaded site'
|
|
15
18
|
describe '.sender_receipt' do
|
|
16
19
|
subject { MessageTrain::Receipt.sender_receipt.first }
|
|
17
20
|
its(:sender) { should be true }
|
|
@@ -28,6 +31,11 @@ module MessageTrain
|
|
|
28
31
|
it { should include trashed_conversation }
|
|
29
32
|
it { should include read_conversation }
|
|
30
33
|
end
|
|
34
|
+
describe '.find_by_recipient' do
|
|
35
|
+
# Testing super on method_missing
|
|
36
|
+
subject { MessageTrain::Receipt.find_by_recipient_type('User') }
|
|
37
|
+
it { should be_a(MessageTrain::Receipt) }
|
|
38
|
+
end
|
|
31
39
|
describe '.receipts_to' do
|
|
32
40
|
subject { MessageTrain::Receipt.receipts_to(first_user) }
|
|
33
41
|
its(:first) { should be_a MessageTrain::Receipt }
|
|
@@ -35,7 +43,7 @@ module MessageTrain
|
|
|
35
43
|
end
|
|
36
44
|
describe '.trashed_to' do
|
|
37
45
|
subject { MessageTrain::Receipt.trashed_to(first_user).first.message.conversation }
|
|
38
|
-
its(:subject) { should eq 'Trashed Conversation' }
|
|
46
|
+
its(:subject) { should eq 'Membered Group Trashed Conversation' }
|
|
39
47
|
end
|
|
40
48
|
describe '.untrashed_to' do
|
|
41
49
|
subject { MessageTrain::Receipt.untrashed_to(first_user).first }
|
|
@@ -43,11 +51,11 @@ module MessageTrain
|
|
|
43
51
|
end
|
|
44
52
|
describe '.read_to' do
|
|
45
53
|
subject { MessageTrain::Receipt.read_to(first_user).first.message.conversation }
|
|
46
|
-
its(:subject) { should eq 'Read Conversation' }
|
|
54
|
+
its(:subject) { should eq 'Membered Group Read Conversation' }
|
|
47
55
|
end
|
|
48
56
|
describe '.deleted_to' do
|
|
49
57
|
subject { MessageTrain::Receipt.deleted_to(first_user).first.message.conversation }
|
|
50
|
-
its(:subject) { should eq 'Deleted Conversation' }
|
|
58
|
+
its(:subject) { should eq 'Membered Group Deleted Conversation' }
|
|
51
59
|
end
|
|
52
60
|
describe '.undeleted_to' do
|
|
53
61
|
subject { MessageTrain::Receipt.undeleted_to(first_user).first }
|
|
@@ -55,19 +63,47 @@ module MessageTrain
|
|
|
55
63
|
end
|
|
56
64
|
describe '.message_ids' do
|
|
57
65
|
subject { MessageTrain::Receipt.receipts_by(first_user).message_ids }
|
|
58
|
-
it { should include
|
|
66
|
+
it { should include sent_message.id }
|
|
59
67
|
end
|
|
60
68
|
describe '.messages' do
|
|
61
69
|
subject { MessageTrain::Receipt.receipts_by(first_user).messages }
|
|
62
|
-
it { should include
|
|
70
|
+
it { should include sent_message }
|
|
63
71
|
end
|
|
64
72
|
describe '#mark' do
|
|
65
73
|
before do
|
|
66
|
-
|
|
74
|
+
unread_message.receipts.for(first_user).first.mark(:read)
|
|
67
75
|
end
|
|
68
|
-
subject {
|
|
76
|
+
subject { unread_message.is_read_to?(first_user) }
|
|
69
77
|
it { should be true }
|
|
70
78
|
end
|
|
79
|
+
describe '.message_ids' do
|
|
80
|
+
subject { first_user.receipts.message_ids }
|
|
81
|
+
it { should include unread_message.id }
|
|
82
|
+
it { should include sent_message.id }
|
|
83
|
+
it { should include read_message.id }
|
|
84
|
+
it { should include draft_message.id }
|
|
85
|
+
end
|
|
86
|
+
describe '.messages' do
|
|
87
|
+
subject { first_user.receipts.messages }
|
|
88
|
+
it { should include unread_message }
|
|
89
|
+
it { should include sent_message }
|
|
90
|
+
it { should include read_message }
|
|
91
|
+
it { should include draft_message }
|
|
92
|
+
end
|
|
93
|
+
describe '.conversation_ids' do
|
|
94
|
+
subject { first_user.receipts.conversation_ids }
|
|
95
|
+
it { should include unread_conversation.id }
|
|
96
|
+
it { should include sent_conversation.id }
|
|
97
|
+
it { should include read_conversation.id }
|
|
98
|
+
it { should include draft_conversation.id }
|
|
99
|
+
end
|
|
100
|
+
describe '.conversations' do
|
|
101
|
+
subject { first_user.receipts.conversations }
|
|
102
|
+
it { should include unread_conversation }
|
|
103
|
+
it { should include sent_conversation }
|
|
104
|
+
it { should include read_conversation }
|
|
105
|
+
it { should include draft_conversation }
|
|
106
|
+
end
|
|
71
107
|
end
|
|
72
108
|
end
|
|
73
109
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
module MessageTrain
|
|
4
|
+
RSpec.describe Unsubscribe do
|
|
5
|
+
include_context 'loaded site'
|
|
6
|
+
|
|
7
|
+
describe 'Model' do
|
|
8
|
+
# Relationships
|
|
9
|
+
it { should belong_to :recipient }
|
|
10
|
+
it { should belong_to :from }
|
|
11
|
+
# Validations
|
|
12
|
+
it { should validate_presence_of :recipient }
|
|
13
|
+
it { should validate_presence_of :from }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Role do
|
|
4
|
+
describe 'Model' do
|
|
5
|
+
# MessageTrain Gem
|
|
6
|
+
it { should have_many(:receipts) }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe 'Scopes and Methods from Message Train' do
|
|
10
|
+
include_context 'loaded site'
|
|
11
|
+
|
|
12
|
+
describe '#slug_part' do
|
|
13
|
+
subject { superadmin_role.slug_part }
|
|
14
|
+
it { should eq 'superadmin' }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#path_part' do
|
|
18
|
+
subject { superadmin_role.path_part }
|
|
19
|
+
it { should eq 'roles:superadmin' }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#valid_senders' do
|
|
23
|
+
subject { superadmin_role.valid_senders }
|
|
24
|
+
it { should include superadmin_user }
|
|
25
|
+
it { should_not include admin_user }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#allows_sending_by?' do
|
|
29
|
+
context 'when user is a superadmin' do
|
|
30
|
+
subject { admin_role.allows_sending_by?(superadmin_user) }
|
|
31
|
+
it { should be true }
|
|
32
|
+
end
|
|
33
|
+
context 'when user is not an owner' do
|
|
34
|
+
subject { admin_role.allows_sending_by?(admin_user) }
|
|
35
|
+
it { should be false }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#valid_recipients' do
|
|
40
|
+
subject { admin_role.valid_recipients }
|
|
41
|
+
it { should_not include first_user }
|
|
42
|
+
it { should include admin_user }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '#allows_receiving_by?' do
|
|
46
|
+
context 'when user is a member' do
|
|
47
|
+
subject { admin_role.allows_receiving_by?(admin_user) }
|
|
48
|
+
it { should be true }
|
|
49
|
+
end
|
|
50
|
+
context 'when user is not a member' do
|
|
51
|
+
subject { admin_role.allows_receiving_by?(first_user) }
|
|
52
|
+
it { should be false }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#self_collection' do
|
|
57
|
+
subject { admin_role.self_collection }
|
|
58
|
+
it { should be_a ActiveRecord::Relation }
|
|
59
|
+
it { should eq [admin_role] }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#conversations' do
|
|
63
|
+
subject { admin_role.conversations(:in, admin_user) }
|
|
64
|
+
its(:first) { should be_a MessageTrain::Conversation }
|
|
65
|
+
its(:count) { should eq 1 }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe '#boxes_for_participant' do
|
|
69
|
+
context 'when participant is a valid sender' do
|
|
70
|
+
subject { admin_role.boxes_for_participant(superadmin_user).collect { |x| x.division } }
|
|
71
|
+
it { should_not include :in }
|
|
72
|
+
it { should include :sent }
|
|
73
|
+
it { should include :drafts }
|
|
74
|
+
it { should include :all }
|
|
75
|
+
it { should include :trash }
|
|
76
|
+
it { should_not include :ignored }
|
|
77
|
+
end
|
|
78
|
+
context 'when participant is a valid recipient' do
|
|
79
|
+
subject { admin_role.boxes_for_participant(admin_user).collect { |x| x.division } }
|
|
80
|
+
it { should include :in }
|
|
81
|
+
it { should_not include :sent }
|
|
82
|
+
it { should_not include :drafts }
|
|
83
|
+
it { should include :all }
|
|
84
|
+
it { should include :trash }
|
|
85
|
+
it { should include :ignored }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#all_conversations' do
|
|
90
|
+
context 'when participant is a valid sender' do
|
|
91
|
+
subject { admin_role.all_conversations(superadmin_user) }
|
|
92
|
+
its(:first) { should be_a MessageTrain::Conversation }
|
|
93
|
+
it { should_not include unread_conversation }
|
|
94
|
+
it { should include role_conversation }
|
|
95
|
+
it { should_not include role_draft } # Because received_through not set on sender receipts
|
|
96
|
+
end
|
|
97
|
+
context 'when participant is a valid recipient' do
|
|
98
|
+
subject { admin_role.all_conversations(admin_user) }
|
|
99
|
+
its(:first) { should be_a MessageTrain::Conversation }
|
|
100
|
+
it { should_not include unread_conversation }
|
|
101
|
+
it { should include role_conversation }
|
|
102
|
+
it { should_not include role_draft }
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#all_messages' do
|
|
107
|
+
context 'when participant is a valid sender' do
|
|
108
|
+
subject { admin_role.all_messages(superadmin_user) }
|
|
109
|
+
its(:first) { should be_a MessageTrain::Message }
|
|
110
|
+
it { should_not include unread_message }
|
|
111
|
+
it { should include role_message }
|
|
112
|
+
it { should_not include role_draft_message } # Because received_through not set on sender receipts
|
|
113
|
+
end
|
|
114
|
+
context 'when participant is a valid recipient' do
|
|
115
|
+
subject { admin_role.all_messages(admin_user) }
|
|
116
|
+
its(:first) { should be_a MessageTrain::Message }
|
|
117
|
+
it { should_not include unread_message }
|
|
118
|
+
it { should include role_message }
|
|
119
|
+
it { should_not include role_draft_message }
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|