activity_notification 0.0.8
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +56 -0
- data/.rspec +3 -0
- data/.travis.yml +28 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +174 -0
- data/MIT-LICENSE +20 -0
- data/README.md +437 -0
- data/Rakefile +19 -0
- data/activity_notification.gemspec +33 -0
- data/app/controllers/activity_notification/notifications_controller.rb +119 -0
- data/app/controllers/activity_notification/notifications_with_devise_controller.rb +29 -0
- data/app/mailers/activity_notification/mailer.rb +13 -0
- data/app/views/activity_notification/mailer/default/default.html.erb +7 -0
- data/app/views/activity_notification/notifications/default/_default.html.erb +36 -0
- data/app/views/activity_notification/notifications/default/_index.html.erb +9 -0
- data/app/views/activity_notification/notifications/default/destroy.js.erb +2 -0
- data/app/views/activity_notification/notifications/default/index.html.erb +17 -0
- data/app/views/activity_notification/notifications/default/open.js.erb +2 -0
- data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -0
- data/app/views/activity_notification/notifications/default/show.html.erb +2 -0
- data/config/locales/en.yml +8 -0
- data/lib/activity_notification.rb +52 -0
- data/lib/activity_notification/apis/notification_api.rb +147 -0
- data/lib/activity_notification/common.rb +86 -0
- data/lib/activity_notification/config.rb +23 -0
- data/lib/activity_notification/controllers/store_controller.rb +30 -0
- data/lib/activity_notification/helpers/polymorphic_helpers.rb +32 -0
- data/lib/activity_notification/helpers/view_helpers.rb +108 -0
- data/lib/activity_notification/mailers/helpers.rb +97 -0
- data/lib/activity_notification/models/notifiable.rb +136 -0
- data/lib/activity_notification/models/notification.rb +50 -0
- data/lib/activity_notification/models/notifier.rb +11 -0
- data/lib/activity_notification/models/target.rb +104 -0
- data/lib/activity_notification/rails.rb +6 -0
- data/lib/activity_notification/rails/routes.rb +105 -0
- data/lib/activity_notification/renderable.rb +142 -0
- data/lib/activity_notification/roles/acts_as_notifiable.rb +37 -0
- data/lib/activity_notification/roles/acts_as_target.rb +30 -0
- data/lib/activity_notification/version.rb +3 -0
- data/lib/generators/activity_notification/controllers_generator.rb +44 -0
- data/lib/generators/activity_notification/install_generator.rb +45 -0
- data/lib/generators/activity_notification/migration/migration_generator.rb +17 -0
- data/lib/generators/activity_notification/notification/notification_generator.rb +17 -0
- data/lib/generators/activity_notification/views_generator.rb +44 -0
- data/lib/generators/templates/README +53 -0
- data/lib/generators/templates/active_record/migration.rb +18 -0
- data/lib/generators/templates/activity_notification.rb +18 -0
- data/lib/generators/templates/controllers/README +13 -0
- data/lib/generators/templates/controllers/notifications_controller.rb +66 -0
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +74 -0
- data/lib/generators/templates/notification/notification.rb +3 -0
- data/lib/tasks/activity_notification_tasks.rake +4 -0
- data/spec/concerns/notification_api_spec.rb +531 -0
- data/spec/factories/articles.rb +5 -0
- data/spec/factories/comments.rb +6 -0
- data/spec/factories/notifications.rb +7 -0
- data/spec/factories/users.rb +5 -0
- data/spec/models/notification_spec.rb +259 -0
- data/spec/rails_app/Rakefile +6 -0
- data/spec/rails_app/app/controllers/application_controller.rb +5 -0
- data/spec/rails_app/app/controllers/concerns/.keep +0 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.keep +0 -0
- data/spec/rails_app/app/models/.keep +0 -0
- data/spec/rails_app/app/models/article.rb +12 -0
- data/spec/rails_app/app/models/comment.rb +18 -0
- data/spec/rails_app/app/models/concerns/.keep +0 -0
- data/spec/rails_app/app/models/user.rb +8 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_app/bin/bundle +3 -0
- data/spec/rails_app/bin/rails +4 -0
- data/spec/rails_app/bin/rake +4 -0
- data/spec/rails_app/bin/setup +29 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +20 -0
- data/spec/rails_app/config/boot.rb +5 -0
- data/spec/rails_app/config/database.yml +25 -0
- data/spec/rails_app/config/environment.rb +12 -0
- data/spec/rails_app/config/environments/development.rb +44 -0
- data/spec/rails_app/config/environments/production.rb +79 -0
- data/spec/rails_app/config/environments/test.rb +45 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +18 -0
- data/spec/rails_app/config/initializers/assets.rb +11 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails_app/config/initializers/devise.rb +274 -0
- data/spec/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails_app/config/initializers/inflections.rb +16 -0
- data/spec/rails_app/config/initializers/mime_types.rb +4 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/routes.rb +5 -0
- data/spec/rails_app/config/secrets.yml +22 -0
- data/spec/rails_app/db/migrate/20160715050420_create_notifications.rb +18 -0
- data/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb +36 -0
- data/spec/rails_app/db/schema.rb +73 -0
- data/spec/rails_app/public/404.html +67 -0
- data/spec/rails_app/public/422.html +67 -0
- data/spec/rails_app/public/500.html +66 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +34 -0
- metadata +309 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
shared_examples_for :notification_api do
|
|
2
|
+
include ActiveJob::TestHelper
|
|
3
|
+
let(:test_class_name) { described_class.to_s.underscore.split('/').last.to_sym }
|
|
4
|
+
let(:test_instance) { create(test_class_name, target: create(:user, confirmed_at: DateTime.now)) }
|
|
5
|
+
before do
|
|
6
|
+
ActiveJob::Base.queue_adapter = :test
|
|
7
|
+
ActivityNotification::Mailer.deliveries.clear
|
|
8
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "as public class methods" do
|
|
12
|
+
before do
|
|
13
|
+
described_class.delete_all
|
|
14
|
+
@author_user = create(:user, confirmed_at: DateTime.now)
|
|
15
|
+
@user_1 = create(:user, confirmed_at: DateTime.now)
|
|
16
|
+
@user_2 = create(:user, confirmed_at: DateTime.now)
|
|
17
|
+
@article = create(:article, user: @author_user)
|
|
18
|
+
@comment_1 = create(:comment, article: @article, user: @user_1)
|
|
19
|
+
@comment_2 = create(:comment, article: @article, user: @user_2)
|
|
20
|
+
expect(@author_user.notifications.count).to eq(0)
|
|
21
|
+
expect(@user_1.notifications.count).to eq(0)
|
|
22
|
+
expect(@user_2.notifications.count).to eq(0)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "notify" do
|
|
26
|
+
it "creates notification records" do
|
|
27
|
+
described_class.notify(User, @comment_2)
|
|
28
|
+
expect(@author_user.notifications.unopened_only.count).to eq(1)
|
|
29
|
+
expect(@user_1.notifications.unopened_only.count).to eq(1)
|
|
30
|
+
expect(@user_2.notifications.unopened_only.count).to eq(0)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "as default" do
|
|
34
|
+
it "sends notification email later" do
|
|
35
|
+
expect {
|
|
36
|
+
perform_enqueued_jobs do
|
|
37
|
+
described_class.notify(User, @comment_2)
|
|
38
|
+
end
|
|
39
|
+
}.to change { ActivityNotification::Mailer.deliveries.size }.by(2)
|
|
40
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(2)
|
|
41
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@user_1.email)
|
|
42
|
+
expect(ActivityNotification::Mailer.deliveries.last.to[0]).to eq(@author_user.email)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "sends notification email with active job queue" do
|
|
46
|
+
expect {
|
|
47
|
+
described_class.notify(User, @comment_2)
|
|
48
|
+
}.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(2)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "with send_later false" do
|
|
53
|
+
it "sends notification email now" do
|
|
54
|
+
described_class.notify(User, @comment_2, send_later: false)
|
|
55
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(2)
|
|
56
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@user_1.email)
|
|
57
|
+
expect(ActivityNotification::Mailer.deliveries.last.to[0]).to eq(@author_user.email)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe "notify_all" do
|
|
63
|
+
it "creates notification records" do
|
|
64
|
+
described_class.notify_all([@author_user, @user_1], @comment_2)
|
|
65
|
+
expect(@author_user.notifications.unopened_only.count).to eq(1)
|
|
66
|
+
expect(@user_1.notifications.unopened_only.count).to eq(1)
|
|
67
|
+
expect(@user_2.notifications.unopened_only.count).to eq(0)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "as default" do
|
|
71
|
+
it "sends notification email later" do
|
|
72
|
+
expect {
|
|
73
|
+
perform_enqueued_jobs do
|
|
74
|
+
described_class.notify_all([@author_user, @user_1], @comment_2)
|
|
75
|
+
end
|
|
76
|
+
}.to change { ActivityNotification::Mailer.deliveries.size }.by(2)
|
|
77
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(2)
|
|
78
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@user_1.email)
|
|
79
|
+
expect(ActivityNotification::Mailer.deliveries.last.to[0]).to eq(@author_user.email)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "sends notification email with active job queue" do
|
|
83
|
+
expect {
|
|
84
|
+
described_class.notify_all([@author_user, @user_1], @comment_2)
|
|
85
|
+
}.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(2)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context "with send_later false" do
|
|
90
|
+
it "sends notification email now" do
|
|
91
|
+
described_class.notify_all([@author_user, @user_1], @comment_2, send_later: false)
|
|
92
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(2)
|
|
93
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@user_1.email)
|
|
94
|
+
expect(ActivityNotification::Mailer.deliveries.last.to[0]).to eq(@author_user.email)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "notify_to" do
|
|
100
|
+
it "creates notification records" do
|
|
101
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
102
|
+
expect(@user_1.notifications.unopened_only.count).to eq(1)
|
|
103
|
+
expect(@user_2.notifications.unopened_only.count).to eq(0)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context "as default" do
|
|
107
|
+
it "sends notification email later" do
|
|
108
|
+
expect {
|
|
109
|
+
perform_enqueued_jobs do
|
|
110
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
111
|
+
end
|
|
112
|
+
}.to change { ActivityNotification::Mailer.deliveries.size }.by(1)
|
|
113
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
|
114
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@user_1.email)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "sends notification email with active job queue" do
|
|
118
|
+
expect {
|
|
119
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
120
|
+
}.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context "with send_later false" do
|
|
125
|
+
it "sends notification email now" do
|
|
126
|
+
described_class.notify_to(@user_1, @comment_2, send_later: false)
|
|
127
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
|
128
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@user_1.email)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context "with options" do
|
|
133
|
+
context "as default" do
|
|
134
|
+
let(:created_notification) {
|
|
135
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
136
|
+
@user_1.notifications.latest
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
it "has key of notifiable.default_notification_key" do
|
|
140
|
+
expect(created_notification.key)
|
|
141
|
+
.to eq(created_notification.notifiable.default_notification_key)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "has group of notifiable.notification_group" do
|
|
145
|
+
expect(created_notification.group)
|
|
146
|
+
.to eq(
|
|
147
|
+
created_notification.notifiable.notification_group(
|
|
148
|
+
@user_1.class,
|
|
149
|
+
created_notification.key
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "has notifier of notifiable.notifier" do
|
|
155
|
+
expect(created_notification.notifier)
|
|
156
|
+
.to eq(
|
|
157
|
+
created_notification.notifiable.notifier(
|
|
158
|
+
@user_1.class,
|
|
159
|
+
created_notification.key
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "has parameters of notifiable.notification_parameters" do
|
|
165
|
+
expect(created_notification.parameters)
|
|
166
|
+
.to eq(
|
|
167
|
+
created_notification.notifiable.notification_parameters(
|
|
168
|
+
@user_1.class,
|
|
169
|
+
created_notification.key
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
context "as specified default value" do
|
|
176
|
+
let(:created_notification) {
|
|
177
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
it "has key of [notifiable_class_name].default" do
|
|
181
|
+
expect(created_notification.key).to eq('comment.default')
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "has group of group in acts_as_notifiable" do
|
|
185
|
+
expect(created_notification.group).to eq(@article)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "has notifier of notifier in acts_as_notifiable" do
|
|
189
|
+
expect(created_notification.notifier).to eq(@user_2)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "has parameters of parameters in acts_as_notifiable" do
|
|
193
|
+
expect(created_notification.parameters).to eq({test_default_param: '1'})
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
context "as api options" do
|
|
198
|
+
let(:created_notification) {
|
|
199
|
+
described_class.notify_to(
|
|
200
|
+
@user_1, @comment_2,
|
|
201
|
+
key: 'custom_test_key',
|
|
202
|
+
group: @comment_2,
|
|
203
|
+
notifier: @author_user,
|
|
204
|
+
parameters: {custom_param_1: '1'},
|
|
205
|
+
custom_param_2: '2'
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
it "has key of key option" do
|
|
210
|
+
expect(created_notification.key).to eq('custom_test_key')
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "has group of group option" do
|
|
214
|
+
expect(created_notification.group).to eq(@comment_2)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "has notifier of notifier option" do
|
|
218
|
+
expect(created_notification.notifier).to eq(@author_user)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it "has parameters of parameters option" do
|
|
222
|
+
expect(created_notification.parameters[:custom_param_1]).to eq('1')
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "has parameters from custom options" do
|
|
226
|
+
expect(created_notification.parameters[:custom_param_2]).to eq('2')
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
context "with grouping" do
|
|
232
|
+
it "creates group by specified group and the target" do
|
|
233
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article)
|
|
234
|
+
member_notification = described_class.notify_to(@user_1, @comment_2, group: @article)
|
|
235
|
+
expect(member_notification.group_owner).to eq(owner_notification)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "belongs to single group" do
|
|
239
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article)
|
|
240
|
+
member_notification_1 = described_class.notify_to(@user_1, @comment_2, group: @article)
|
|
241
|
+
member_notification_2 = described_class.notify_to(@user_1, @comment_2, group: @article)
|
|
242
|
+
expect(member_notification_1.group_owner).to eq(owner_notification)
|
|
243
|
+
expect(member_notification_2.group_owner).to eq(owner_notification)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "does not create group with opened notifications" do
|
|
247
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article)
|
|
248
|
+
owner_notification.open!
|
|
249
|
+
member_notification = described_class.notify_to(@user_1, @comment_2, group: @article)
|
|
250
|
+
expect(member_notification.group_owner).to eq(nil)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it "does not create group with different target" do
|
|
254
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article)
|
|
255
|
+
member_notification = described_class.notify_to(@user_2, @comment_2, group: @article)
|
|
256
|
+
expect(member_notification.group_owner).to eq(nil)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "does not create group with different group" do
|
|
260
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article)
|
|
261
|
+
member_notification = described_class.notify_to(@user_1, @comment_2, group: @comment_2)
|
|
262
|
+
expect(member_notification.group_owner).to eq(nil)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it "does not create group with different notifiable type" do
|
|
266
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article)
|
|
267
|
+
member_notification = described_class.notify_to(@user_1, @article, group: @article)
|
|
268
|
+
expect(member_notification.group_owner).to eq(nil)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it "does not create group with different key" do
|
|
272
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, key: 'key1', group: @article)
|
|
273
|
+
member_notification = described_class.notify_to(@user_1, @comment_2, key: 'key2', group: @article)
|
|
274
|
+
expect(member_notification.group_owner).to eq(nil)
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
describe "open_all_of" do
|
|
280
|
+
before do
|
|
281
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
282
|
+
described_class.notify_to(@user_1, @comment_2)
|
|
283
|
+
expect(@user_1.notifications.unopened_only.count).to eq(2)
|
|
284
|
+
expect(@user_1.notifications.opened_only!.count).to eq(0)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it "opens all notifications of the target" do
|
|
288
|
+
described_class.open_all_of(@user_1)
|
|
289
|
+
expect(@user_1.notifications.unopened_only.count).to eq(0)
|
|
290
|
+
expect(@user_1.notifications.opened_only!.count).to eq(2)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "does not open any notifications of the other targets" do
|
|
294
|
+
described_class.open_all_of(@user_2)
|
|
295
|
+
expect(@user_1.notifications.unopened_only.count).to eq(2)
|
|
296
|
+
expect(@user_1.notifications.opened_only!.count).to eq(0)
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
describe "group_member_exists?" do
|
|
301
|
+
context "when specified notifications have any group members" do
|
|
302
|
+
let(:owner_notifications) do
|
|
303
|
+
target = create(:user)
|
|
304
|
+
group_owner = create(:notification, target: target, group_owner: nil)
|
|
305
|
+
create(:notification, target: target, group_owner: nil)
|
|
306
|
+
group_member = create(:notification, target: target, group_owner: group_owner)
|
|
307
|
+
target.notifications.group_owners_only
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
it "returns true" do
|
|
311
|
+
expect(described_class.group_member_exists?(owner_notifications))
|
|
312
|
+
.to be_truthy
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
context "when specified notifications have no group members" do
|
|
317
|
+
let(:owner_notifications) do
|
|
318
|
+
target = create(:user)
|
|
319
|
+
group_owner = create(:notification, target: target, group_owner: nil)
|
|
320
|
+
create(:notification, target: target, group_owner: nil)
|
|
321
|
+
target.notifications.group_owners_only
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
it "returns false" do
|
|
325
|
+
expect(described_class.group_member_exists?(owner_notifications))
|
|
326
|
+
.to be_falsey
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
describe "available_options" do
|
|
332
|
+
it "returns list of available_options" do
|
|
333
|
+
expect(described_class.available_options)
|
|
334
|
+
.to eq([:key, :group, :parameters, :notifier, :send_email, :send_later])
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
describe "as private class methods" do
|
|
340
|
+
describe "store_notification" do
|
|
341
|
+
it "is defined as private method" do
|
|
342
|
+
expect(described_class.respond_to?(:store_notification)).to be_falsey
|
|
343
|
+
expect(described_class.respond_to?(:store_notification, true)).to be_truthy
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
describe "as public instance methods" do
|
|
349
|
+
describe "send_notification_email" do
|
|
350
|
+
context "as default" do
|
|
351
|
+
it "sends notification email later" do
|
|
352
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
|
353
|
+
expect {
|
|
354
|
+
perform_enqueued_jobs do
|
|
355
|
+
test_instance.send_notification_email
|
|
356
|
+
end
|
|
357
|
+
}.to change { ActivityNotification::Mailer.deliveries.size }.by(1)
|
|
358
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
|
359
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(test_instance.target.email)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
it "sends notification email with active job queue" do
|
|
363
|
+
expect {
|
|
364
|
+
test_instance.send_notification_email
|
|
365
|
+
}.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
context "with send_later false" do
|
|
370
|
+
it "sends notification email now" do
|
|
371
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
|
372
|
+
test_instance.send_notification_email false
|
|
373
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
|
374
|
+
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(test_instance.target.email)
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
describe "open!" do
|
|
380
|
+
context "as default" do
|
|
381
|
+
it "open notification with current time" do
|
|
382
|
+
expect(test_instance.opened_at.blank?).to be_truthy
|
|
383
|
+
Timecop.freeze(DateTime.now)
|
|
384
|
+
test_instance.open!
|
|
385
|
+
expect(test_instance.opened_at.blank?).to be_falsey
|
|
386
|
+
expect(test_instance.opened_at).to eq(DateTime.now)
|
|
387
|
+
Timecop.return
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
context "with an argument" do
|
|
392
|
+
it "open notification with specified time" do
|
|
393
|
+
expect(test_instance.opened_at.blank?).to be_truthy
|
|
394
|
+
datetime = DateTime.now - 1.months
|
|
395
|
+
test_instance.open!(datetime)
|
|
396
|
+
expect(test_instance.opened_at.blank?).to be_falsey
|
|
397
|
+
expect(test_instance.opened_at).to eq(datetime)
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
describe "unopened?" do
|
|
403
|
+
context "when opened_at is blank" do
|
|
404
|
+
it "returns true" do
|
|
405
|
+
expect(test_instance.unopened?).to be_truthy
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
context "when opened_at is present" do
|
|
410
|
+
it "returns false" do
|
|
411
|
+
test_instance.open!
|
|
412
|
+
expect(test_instance.unopened?).to be_falsey
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
describe "opened?" do
|
|
418
|
+
context "when opened_at is blank" do
|
|
419
|
+
it "returns false" do
|
|
420
|
+
expect(test_instance.opened?).to be_falsey
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
context "when opened_at is present" do
|
|
425
|
+
it "returns true" do
|
|
426
|
+
test_instance.open!
|
|
427
|
+
expect(test_instance.opened?).to be_truthy
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
describe "group_owner?" do
|
|
433
|
+
context "when the notification is group owner" do
|
|
434
|
+
it "returns true" do
|
|
435
|
+
expect(test_instance.group_owner?).to be_truthy
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
context "when the notification belongs to group" do
|
|
440
|
+
it "returns false" do
|
|
441
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
442
|
+
expect(group_member.group_owner?).to be_falsey
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
describe "group_member?" do
|
|
448
|
+
context "when the notification is group owner" do
|
|
449
|
+
it "returns false" do
|
|
450
|
+
expect(test_instance.group_member?).to be_falsey
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
context "when the notification belongs to group" do
|
|
455
|
+
it "returns true" do
|
|
456
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
457
|
+
expect(group_member.group_member?).to be_truthy
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
describe "group_member_exists?" do
|
|
463
|
+
context "when the notification is group owner and has no group members" do
|
|
464
|
+
it "returns false" do
|
|
465
|
+
expect(test_instance.group_member_exists?).to be_falsey
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
context "when the notification is group owner and has group members" do
|
|
470
|
+
it "returns true" do
|
|
471
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
472
|
+
expect(test_instance.group_member_exists?).to be_truthy
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
context "when the notification belongs to group" do
|
|
477
|
+
it "returns true" do
|
|
478
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
479
|
+
expect(group_member.group_member_exists?).to be_truthy
|
|
480
|
+
end
|
|
481
|
+
end
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
describe "group_member_count" do
|
|
485
|
+
context "when the notification is group owner and has no group members" do
|
|
486
|
+
it "returns 0" do
|
|
487
|
+
expect(test_instance.group_member_count).to eq(0)
|
|
488
|
+
end
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
context "when the notification is group owner and has group members" do
|
|
492
|
+
it "returns member count" do
|
|
493
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
494
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
495
|
+
expect(test_instance.group_member_count).to eq(2)
|
|
496
|
+
end
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
context "when the notification belongs to group" do
|
|
500
|
+
it "returns member count" do
|
|
501
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
502
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
|
503
|
+
expect(group_member.group_member_count).to eq(2)
|
|
504
|
+
end
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
describe "notifiale_path" do
|
|
509
|
+
it "returns notifiable.notifiable_path" do
|
|
510
|
+
expect(test_instance.notifiale_path).to eq(test_instance.notifiable.notifiable_path(test_instance.target_type))
|
|
511
|
+
end
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
describe "with protected instance methods" do
|
|
516
|
+
describe "unopened_group_member_count" do
|
|
517
|
+
it "is defined as protected method" do
|
|
518
|
+
expect(test_instance.respond_to?(:unopened_group_member_count)).to be_falsey
|
|
519
|
+
expect(test_instance.respond_to?(:unopened_group_member_count, true)).to be_truthy
|
|
520
|
+
end
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
describe "opened_group_member_count" do
|
|
524
|
+
it "is defined as protected method" do
|
|
525
|
+
expect(test_instance.respond_to?(:opened_group_member_count)).to be_falsey
|
|
526
|
+
expect(test_instance.respond_to?(:opened_group_member_count, true)).to be_truthy
|
|
527
|
+
end
|
|
528
|
+
end
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
end
|