rails-alerter 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Appraisals +11 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +111 -0
- data/Rakefile +10 -0
- data/alerter.gemspec +60 -0
- data/app/builders/alerter/base_builder.rb +26 -0
- data/app/builders/alerter/message_builder.rb +16 -0
- data/app/builders/alerter/receipt_builder.rb +13 -0
- data/app/mailers/alerter/base_mailer.rb +15 -0
- data/app/mailers/alerter/message_mailer.rb +12 -0
- data/app/models/alerter/mailbox.rb +74 -0
- data/app/models/alerter/message.rb +171 -0
- data/app/models/alerter/notification_type.rb +20 -0
- data/app/models/alerter/preference.rb +19 -0
- data/app/models/alerter/receipt.rb +89 -0
- data/app/views/alerter/message_mailer/new_message_email.html.erb +20 -0
- data/app/views/alerter/message_mailer/new_message_email.text.erb +10 -0
- data/db/migrate/20150821000000_create_alerter.rb +65 -0
- data/lib/alerter/cleaner.rb +9 -0
- data/lib/alerter/engine.rb +31 -0
- data/lib/alerter/message_dispatcher.rb +62 -0
- data/lib/alerter/models/notifiable.rb +174 -0
- data/lib/alerter/version.rb +3 -0
- data/lib/generators/alerter/install_generator.rb +37 -0
- data/lib/generators/alerter/namespacing_compatibility_generator.rb +24 -0
- data/lib/generators/alerter/templates/initializer.rb +29 -0
- data/lib/generators/alerter/views_generator.rb +11 -0
- data/lib/rails-alerter.rb +71 -0
- data/spec/alerter/message_dispatcher_spec.rb +101 -0
- data/spec/alerter_spec.rb +8 -0
- data/spec/dummy/.gitignore +5 -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 +4 -0
- data/spec/dummy/app/models/duck.rb +3 -0
- data/spec/dummy/app/models/user.rb +3 -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 +47 -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 +29 -0
- data/spec/dummy/config/environments/production.rb +51 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/alerter.rb +26 -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/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/schema.rb +77 -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/general.rb +37 -0
- data/spec/integration/message_and_receipt_spec.rb +42 -0
- data/spec/integration/navigation_spec.rb +8 -0
- data/spec/mailers/message_mailer_spec.rb +44 -0
- data/spec/models/alerter_models_messageable_spec.rb +311 -0
- data/spec/models/mailbox_spec.rb +55 -0
- data/spec/models/message_spec.rb +51 -0
- data/spec/models/preference_spec.rb +35 -0
- data/spec/models/receipt_spec.rb +61 -0
- data/spec/spec_helper.rb +54 -0
- metadata +330 -0
@@ -0,0 +1 @@
|
|
1
|
+
this is a dummy file to test file uploads
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :user do
|
3
|
+
sequence(:name) { |n| "User #{ n }" }
|
4
|
+
sequence(:email) { |n| "user#{ n }@user.com" }
|
5
|
+
factory :user_with_email_pref do
|
6
|
+
after(:create) do |user|
|
7
|
+
create_list(:email_prefs, 1, notifiable: user)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
factory :cylon, class: User do
|
13
|
+
sequence(:name) { |n| "Cylon #{ n }" }
|
14
|
+
sequence(:email) { |n| "cylon#{ n }@cylon.com" }
|
15
|
+
end
|
16
|
+
|
17
|
+
factory :duck, class: User do
|
18
|
+
sequence(:name) { |n| "Duck #{ n }" }
|
19
|
+
sequence(:email) { |n| "duck#{ n }@duck.com" }
|
20
|
+
end
|
21
|
+
|
22
|
+
factory :email_prefs, class: Alerter::Preference do
|
23
|
+
alert_methods %w(email)
|
24
|
+
association :notification_type
|
25
|
+
end
|
26
|
+
|
27
|
+
factory :notification_type, class: Alerter::NotificationType do
|
28
|
+
name 'info'
|
29
|
+
initialize_with { Alerter::NotificationType.find_or_create_by(name: name)}
|
30
|
+
end
|
31
|
+
|
32
|
+
factory :message, class: Alerter::Message do
|
33
|
+
short_msg 'short message'
|
34
|
+
long_msg 'long message'
|
35
|
+
association :notification_type
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Messages And Alerter::Receipts", type: :integration do
|
4
|
+
|
5
|
+
describe "two equal entities" do
|
6
|
+
before do
|
7
|
+
@entity1 = FactoryGirl.create :user
|
8
|
+
@entity2 = FactoryGirl.create :user
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "message sending" do
|
12
|
+
|
13
|
+
before do
|
14
|
+
@receipts = Alerter::Message.message_all([@entity1,@entity2],"short", "long", "normal")
|
15
|
+
@message1 = @receipts.first.message
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create proper message" do
|
19
|
+
assert @message1.short_msg.eql?"short"
|
20
|
+
assert @message1.long_msg.eql?"long"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should create proper mails" do
|
24
|
+
#Receiver
|
25
|
+
mail = Alerter::Receipt.recipient(@entity1).where(message: @message1).first
|
26
|
+
assert mail
|
27
|
+
if mail
|
28
|
+
expect(mail.is_read).to be false
|
29
|
+
expect(mail.mailbox_type).to eq "inbox"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have the correct recipients" do
|
34
|
+
recipients = @message1.recipients
|
35
|
+
expect(recipients.count).to eq 2
|
36
|
+
expect(recipients.count(@entity1)).to eq 1
|
37
|
+
expect(recipients.count(@entity2)).to eq 1
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alerter::MessageMailer do
|
4
|
+
before do
|
5
|
+
@entity1 = FactoryGirl.create :user_with_email_pref
|
6
|
+
@entity2 = FactoryGirl.create :user_with_email_pref
|
7
|
+
@entity3 = FactoryGirl.create :user
|
8
|
+
@receipt1 = Alerter::Message.message_all([@entity1,@entity2,@entity3],"short", "long", "info")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should send emails when should_email? is true (2 out of 3)" do
|
12
|
+
expect(ActionMailer::Base.deliveries.size).to eq 2
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should send an email to user entity" do
|
16
|
+
temp = false
|
17
|
+
ActionMailer::Base.deliveries.each do |email|
|
18
|
+
if email.to.first.to_s.eql? @entity1.email
|
19
|
+
temp = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
expect(temp).to be true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should send an email to second user entity" do
|
26
|
+
temp = false
|
27
|
+
ActionMailer::Base.deliveries.each do |email|
|
28
|
+
if email.to.first.to_s.eql? @entity2.email
|
29
|
+
temp = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
expect(temp).to be true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "shouldn't send an email to last entity due to prefs" do
|
36
|
+
temp = false
|
37
|
+
ActionMailer::Base.deliveries.each do |email|
|
38
|
+
if email.to.first.to_s.eql? @entity3.email
|
39
|
+
temp = true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
expect(temp).to be false
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,311 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Alerter::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 return the inbox count' do
|
15
|
+
expect(@entity1.unread_inbox_count).to eq 0
|
16
|
+
@entity1.send_message("short", "long", "normal")
|
17
|
+
@entity1.send_message("short", "long", "normal")
|
18
|
+
expect(@entity1.unread_inbox_count).to eq 2
|
19
|
+
@entity1.receipts.first.mark_as_read
|
20
|
+
expect(@entity1.unread_inbox_count).to eq 1
|
21
|
+
@entity1.send_message("short", "long", "normal")
|
22
|
+
@entity1.send_message("short", "long", "normal")
|
23
|
+
expect(@entity1.unread_inbox_count).to eq 3
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to send a message" do
|
27
|
+
assert @entity1.send_message("short", "long", "normal")
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'receipts' do
|
31
|
+
context 'single message' do
|
32
|
+
it "should be able to unread an owned Alerter::Receipt (mark as unread)" do
|
33
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
34
|
+
expect(@receipt.is_unread?).to eq true
|
35
|
+
@entity1.mark_as_read(@receipt)
|
36
|
+
@entity1.mark_as_unread(@receipt)
|
37
|
+
expect(@receipt.is_unread?).to eq true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to read an owned Alerter::Receipt (mark as read)" do
|
41
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
42
|
+
expect(@receipt.is_unread?).to eq true
|
43
|
+
@entity1.mark_as_read(@receipt)
|
44
|
+
expect(@receipt.is_read?).to eq true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be able to undelete an owned Alerter::Receipt (mark as not deleted)" do
|
48
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
49
|
+
expect(@receipt.deleted?).to eq false
|
50
|
+
@entity1.mark_as_deleted(@receipt)
|
51
|
+
@entity1.mark_as_not_deleted(@receipt)
|
52
|
+
expect(@receipt.deleted?).to eq false
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be able to delete an owned Alerter::Receipt (mark as deleted)" do
|
56
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
57
|
+
expect(@receipt.deleted?).to eq false
|
58
|
+
@entity1.mark_as_deleted(@receipt)
|
59
|
+
expect(@receipt.deleted?).to eq true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not be able to unread a not owned Alerter::Receipt (mark as unread)" do
|
63
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
64
|
+
@entity1.mark_as_read(@receipt)
|
65
|
+
expect(@receipt.is_read?).to eq true
|
66
|
+
@entity2.mark_as_unread(@receipt) #Should not change
|
67
|
+
expect(@receipt.is_read?).to eq true
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not be able to read a not owned Alerter::Receipt (mark as read)" do
|
71
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
72
|
+
expect(@receipt.is_unread?).to eq true
|
73
|
+
@entity2.mark_as_read(@receipt) #Should not change
|
74
|
+
expect(@receipt.is_unread?).to eq true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not be able to delete a not owned Alerter::Receipt (mark as deleted)" do
|
78
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
79
|
+
expect(@receipt.deleted?).to eq false
|
80
|
+
@entity2.mark_as_deleted(@receipt) #Should not change
|
81
|
+
expect(@receipt.deleted?).to eq false
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should not be able to undelete a not owned Alerter::Receipt (mark as not deleted)" do
|
85
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
86
|
+
expect(@receipt.deleted?).to eq false
|
87
|
+
@entity2.mark_as_deleted(@receipt)
|
88
|
+
@entity2.mark_as_not_deleted(@receipt) #Should not change
|
89
|
+
expect(@receipt.deleted?).to eq false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'multiple' do
|
94
|
+
it "should be able to unread multiple owned Alerter::Receipts (mark as unread)" do
|
95
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
96
|
+
@entity1.send_message("short", "long", "normal"),
|
97
|
+
@entity2.send_message("short", "long", "normal")]
|
98
|
+
|
99
|
+
expect(@receipts.first.is_unread?).to eq true
|
100
|
+
expect(@receipts.second.is_unread?).to eq true
|
101
|
+
expect(@receipts.third.is_unread?).to eq true
|
102
|
+
@entity1.mark_as_read(@receipts)
|
103
|
+
@entity2.mark_as_read(@receipts)
|
104
|
+
expect(@receipts.first.is_read?).to eq true
|
105
|
+
expect(@receipts.second.is_read?).to eq true
|
106
|
+
expect(@receipts.third.is_read?).to eq true
|
107
|
+
@entity1.mark_as_unread(@receipts)
|
108
|
+
expect(@receipts.first.is_unread?).to eq true
|
109
|
+
expect(@receipts.second.is_unread?).to eq true
|
110
|
+
expect(@receipts.third.is_unread?).to eq false
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
it "should be able to read multiple owned Alerter::Receipts (mark as read)" do
|
115
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
116
|
+
@entity1.send_message("short", "long", "normal"),
|
117
|
+
@entity2.send_message("short", "long", "normal")]
|
118
|
+
|
119
|
+
expect(@receipts.first.is_unread?).to eq true
|
120
|
+
expect(@receipts.second.is_unread?).to eq true
|
121
|
+
expect(@receipts.third.is_unread?).to eq true
|
122
|
+
@entity1.mark_as_read(@receipts)
|
123
|
+
expect(@receipts.first.is_read?).to eq true
|
124
|
+
expect(@receipts.second.is_read?).to eq true
|
125
|
+
expect(@receipts.third.is_read?).to eq false
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
it "should be able to undelete multiple owned Alerter::Receipts (mark as not deleted)" do
|
130
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
131
|
+
@entity1.send_message("short", "long", "normal"),
|
132
|
+
@entity2.send_message("short", "long", "normal")]
|
133
|
+
|
134
|
+
expect(@receipts.first.deleted?).to eq false
|
135
|
+
expect(@receipts.second.deleted?).to eq false
|
136
|
+
expect(@receipts.third.deleted?).to eq false
|
137
|
+
@entity1.mark_as_deleted(@receipts)
|
138
|
+
@entity2.mark_as_deleted(@receipts)
|
139
|
+
expect(@receipts.first.deleted?).to eq true
|
140
|
+
expect(@receipts.second.deleted?).to eq true
|
141
|
+
expect(@receipts.third.deleted?).to eq true
|
142
|
+
@entity1.mark_as_not_deleted(@receipts)
|
143
|
+
expect(@receipts.first.deleted?).to eq false
|
144
|
+
expect(@receipts.second.deleted?).to eq false
|
145
|
+
expect(@receipts.third.deleted?).to eq true
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
it "should be able to delete multiple owned Alerter::Receipts (mark as deleted)" do
|
150
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
151
|
+
@entity1.send_message("short", "long", "normal"),
|
152
|
+
@entity2.send_message("short", "long", "normal")]
|
153
|
+
|
154
|
+
expect(@receipts.first.deleted?).to eq false
|
155
|
+
expect(@receipts.second.deleted?).to eq false
|
156
|
+
expect(@receipts.third.deleted?).to eq false
|
157
|
+
@entity1.mark_as_deleted(@receipts)
|
158
|
+
expect(@receipts.first.deleted?).to eq true
|
159
|
+
expect(@receipts.second.deleted?).to eq true
|
160
|
+
expect(@receipts.third.deleted?).to eq false
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'messages' do
|
166
|
+
context 'single' do
|
167
|
+
it "should be able to unread an owned Message (mark as unread)" do
|
168
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
169
|
+
@entity1.mark_as_read(@receipt)
|
170
|
+
@message = @receipt.message
|
171
|
+
expect(@receipt.is_read?).to eq true
|
172
|
+
@entity1.mark_as_unread(@message)
|
173
|
+
expect(@message.receipts_for(@entity1).first.is_read?).to eq false
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should be able to read an owned Message (mark as read)" do
|
177
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
178
|
+
@message = @receipt.message
|
179
|
+
expect(@receipt.is_unread?).to eq true
|
180
|
+
@entity1.mark_as_read(@message)
|
181
|
+
expect(@message.receipt_for(@entity1).first.is_read?).to eq true
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should be able to delete an owned Message (mark as deleted)" do
|
185
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
186
|
+
@message = @receipt.message
|
187
|
+
expect(@receipt.deleted?).to eq false
|
188
|
+
@entity1.mark_as_deleted(@message)
|
189
|
+
expect(@message.receipt_for(@entity1).first.deleted?).to eq true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should be able to undelete an owned Message (mark as not deleted)" do
|
193
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
194
|
+
@message = @receipt.message
|
195
|
+
expect(@receipt.deleted?).to eq false
|
196
|
+
@entity1.mark_as_deleted(@message)
|
197
|
+
expect(@message.receipt_for(@entity1).first.deleted?).to eq true
|
198
|
+
@entity1.mark_as_not_deleted(@message)
|
199
|
+
expect(@message.receipt_for(@entity1).first.deleted?).to eq false
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should not be able to unread a not owned Message (mark as unread)" do
|
203
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
204
|
+
@entity1.mark_as_read(@receipt)
|
205
|
+
@message = @receipt.message
|
206
|
+
expect(@receipt.is_read?).to eq true
|
207
|
+
@entity2.mark_as_unread(@message)
|
208
|
+
expect(@message.receipt_for(@entity1).first.is_read?).to eq true
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should not be able to read a not owned Message (mark as read)" do
|
212
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
213
|
+
@message = @receipt.message
|
214
|
+
expect(@receipt.is_unread?).to eq true
|
215
|
+
@entity2.mark_as_read(@message)
|
216
|
+
expect(@message.receipt_for(@entity1).first.is_read?).to eq false
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should not be able to delete a not owned Message (mark as deleted)" do
|
220
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
221
|
+
@message = @receipt.message
|
222
|
+
expect(@receipt.deleted?).to eq false
|
223
|
+
@entity2.mark_as_deleted(@message)
|
224
|
+
expect(@message.receipt_for(@entity1).first.deleted?).to eq false
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should not be able to undelete a not owned Message (mark as not deleted)" do
|
228
|
+
@receipt = @entity1.send_message("short", "long", "normal")
|
229
|
+
@message = @receipt.message
|
230
|
+
expect(@receipt.deleted?).to eq false
|
231
|
+
@entity1.mark_as_deleted(@message)
|
232
|
+
expect(@message.receipt_for(@entity1).first.deleted?).to eq true
|
233
|
+
@entity2.mark_as_not_deleted(@message)
|
234
|
+
expect(@message.receipt_for(@entity1).first.deleted?).to eq true
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'multiple' do
|
239
|
+
it "should be able to unread multiple owned Messages (mark as unread)" do
|
240
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
241
|
+
@entity1.send_message("short", "long", "normal"),
|
242
|
+
@entity2.send_message("short", "long", "normal")]
|
243
|
+
@messages = @receipts.map { |r| r.message}
|
244
|
+
|
245
|
+
expect(@receipts.first.is_unread?).to eq true
|
246
|
+
expect(@receipts.second.is_unread?).to eq true
|
247
|
+
expect(@receipts.third.is_unread?).to eq true
|
248
|
+
@entity1.mark_as_read(@messages)
|
249
|
+
@entity2.mark_as_read(@messages)
|
250
|
+
expect(@messages.first.receipt_for(@entity1).first.is_read?).to eq true
|
251
|
+
expect(@messages.second.receipt_for(@entity1).first.is_read?).to eq true
|
252
|
+
expect(@messages.third.receipt_for(@entity2).first.is_read?).to eq true
|
253
|
+
@entity1.mark_as_unread(@messages)
|
254
|
+
expect(@messages.first.receipt_for(@entity1).first.is_unread?).to eq true
|
255
|
+
expect(@messages.second.receipt_for(@entity1).first.is_unread?).to eq true
|
256
|
+
expect(@messages.third.receipt_for(@entity2).first.is_unread?).to eq false
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
it "should be able to read multiple owned Messages (mark as read)" do
|
261
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
262
|
+
@entity1.send_message("short", "long", "normal"),
|
263
|
+
@entity2.send_message("short", "long", "normal")]
|
264
|
+
@messages = @receipts.map { |r| r.message}
|
265
|
+
|
266
|
+
expect(@receipts.first.is_unread?).to eq true
|
267
|
+
expect(@receipts.second.is_unread?).to eq true
|
268
|
+
expect(@receipts.third.is_unread?).to eq true
|
269
|
+
@entity1.mark_as_read(@messages)
|
270
|
+
expect(@messages.first.receipt_for(@entity1).first.is_read?).to eq true
|
271
|
+
expect(@messages.second.receipt_for(@entity1).first.is_read?).to eq true
|
272
|
+
expect(@messages.third.receipt_for(@entity2).first.is_read?).to eq false
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should be able to undelete multiple owned Messages (mark as not deleted)" do
|
276
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
277
|
+
@entity1.send_message("short", "long", "normal"),
|
278
|
+
@entity2.send_message("short", "long", "normal")]
|
279
|
+
@messages = @receipts.map { |r| r.message}
|
280
|
+
|
281
|
+
expect(@receipts.first.deleted?).to eq false
|
282
|
+
expect(@receipts.second.deleted?).to eq false
|
283
|
+
expect(@receipts.third.deleted?).to eq false
|
284
|
+
@entity1.mark_as_deleted(@messages)
|
285
|
+
@entity2.mark_as_deleted(@messages)
|
286
|
+
expect(@messages.first.receipt_for(@entity1).first.deleted?).to eq true
|
287
|
+
expect(@messages.second.receipt_for(@entity1).first.deleted?).to eq true
|
288
|
+
expect(@messages.third.receipt_for(@entity2).first.deleted?).to eq true
|
289
|
+
@entity1.mark_as_not_deleted(@messages)
|
290
|
+
expect(@messages.first.receipt_for(@entity1).first.deleted?).to eq false
|
291
|
+
expect(@messages.second.receipt_for(@entity1).first.deleted?).to eq false
|
292
|
+
expect(@messages.third.receipt_for(@entity2).first.deleted?).to eq true
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should be able to delete multiple owned Messages (mark as deleted)" do
|
296
|
+
@receipts = [@entity1.send_message("short", "long", "normal"),
|
297
|
+
@entity1.send_message("short", "long", "normal"),
|
298
|
+
@entity2.send_message("short", "long", "normal")]
|
299
|
+
@messages = @receipts.map { |r| r.message}
|
300
|
+
|
301
|
+
expect(@receipts.first.deleted?).to eq false
|
302
|
+
expect(@receipts.second.deleted?).to eq false
|
303
|
+
expect(@receipts.third.deleted?).to eq false
|
304
|
+
@entity1.mark_as_deleted(@messages)
|
305
|
+
expect(@messages.first.receipt_for(@entity1).first.deleted?).to eq true
|
306
|
+
expect(@messages.second.receipt_for(@entity1).first.deleted?).to eq true
|
307
|
+
expect(@messages.third.receipt_for(@entity2).first.deleted?).to eq false
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|