activity_notification 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +33 -0
- data/.rubocop.yml +1157 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +15 -17
- data/README.md +154 -27
- data/activity_notification.gemspec +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +30 -104
- data/app/controllers/activity_notification/notifications_with_devise_controller.rb +1 -33
- data/app/controllers/activity_notification/subscriptions_controller.rb +184 -0
- data/app/controllers/activity_notification/subscriptions_with_devise_controller.rb +6 -0
- data/app/mailers/activity_notification/mailer.rb +3 -3
- data/app/views/activity_notification/notifications/default/_index.html.erb +3 -0
- data/app/views/activity_notification/notifications/default/index.html.erb +8 -10
- data/app/views/activity_notification/notifications/default/show.html.erb +24 -2
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +52 -0
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +89 -0
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +73 -0
- data/app/views/activity_notification/subscriptions/default/_subscriptions.html.erb +13 -0
- data/app/views/activity_notification/subscriptions/default/create.js.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/destroy.js.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/index.html.erb +197 -0
- data/app/views/activity_notification/subscriptions/default/show.html.erb +177 -0
- data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +8 -0
- data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +6 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +8 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +6 -0
- data/gemfiles/Gemfile.rails-4.2.lock +18 -20
- data/gemfiles/Gemfile.rails-5.0.lock +18 -20
- data/lib/activity_notification.rb +7 -3
- data/lib/activity_notification/apis/notification_api.rb +95 -61
- data/lib/activity_notification/apis/subscription_api.rb +51 -0
- data/lib/activity_notification/common.rb +1 -1
- data/lib/activity_notification/config.rb +65 -17
- data/lib/activity_notification/controllers/common_controller.rb +118 -0
- data/lib/activity_notification/controllers/devise_authentication_controller.rb +41 -0
- data/lib/activity_notification/helpers/view_helpers.rb +131 -3
- data/lib/activity_notification/mailers/helpers.rb +6 -8
- data/lib/activity_notification/models/concerns/notifiable.rb +45 -27
- data/lib/activity_notification/models/concerns/subscriber.rb +149 -0
- data/lib/activity_notification/models/concerns/target.rb +100 -66
- data/lib/activity_notification/models/notification.rb +7 -5
- data/lib/activity_notification/models/subscription.rb +93 -0
- data/lib/activity_notification/rails/routes.rb +148 -33
- data/lib/activity_notification/renderable.rb +3 -4
- data/lib/activity_notification/roles/acts_as_notifiable.rb +14 -1
- data/lib/activity_notification/roles/acts_as_target.rb +11 -8
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/controllers_generator.rb +2 -2
- data/lib/generators/activity_notification/install_generator.rb +0 -1
- data/lib/generators/activity_notification/migration/migration_generator.rb +8 -2
- data/lib/generators/activity_notification/models_generator.rb +53 -0
- data/lib/generators/activity_notification/views_generator.rb +7 -7
- data/lib/generators/templates/activity_notification.rb +17 -3
- data/lib/generators/templates/controllers/notifications_controller.rb +18 -17
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +18 -17
- data/lib/generators/templates/controllers/subscriptions_controller.rb +79 -0
- data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +87 -0
- data/lib/generators/templates/migrations/migration.rb +57 -0
- data/lib/generators/templates/models/README +10 -0
- data/lib/generators/templates/{notification → models}/notification.rb +1 -3
- data/lib/generators/templates/models/subscription.rb +4 -0
- data/spec/concerns/apis/notification_api_spec.rb +48 -11
- data/spec/concerns/apis/subscription_api_spec.rb +167 -0
- data/spec/concerns/models/notifiable_spec.rb +60 -0
- data/spec/concerns/models/subscriber_spec.rb +525 -0
- data/spec/concerns/models/target_spec.rb +271 -42
- data/spec/controllers/common_controller_spec.rb +25 -0
- data/spec/controllers/dummy_common_controller.rb +5 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +2 -6
- data/spec/controllers/subscriptions_controller_shared_examples.rb +735 -0
- data/spec/controllers/subscriptions_controller_spec.rb +12 -0
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +91 -0
- data/spec/factories/dummy/dummy_subscriber.rb +4 -0
- data/spec/factories/subscriptions.rb +8 -0
- data/spec/generators/controllers_generator_spec.rb +25 -2
- data/spec/generators/migration/migration_generator_spec.rb +3 -3
- data/spec/generators/models_generator_spec.rb +96 -0
- data/spec/generators/views_generator_spec.rb +84 -0
- data/spec/helpers/view_helpers_spec.rb +143 -0
- data/spec/mailers/mailer_spec.rb +5 -4
- data/spec/models/dummy/dummy_subscriber_spec.rb +5 -0
- data/spec/models/notification_spec.rb +7 -7
- data/spec/models/subscription_spec.rb +158 -0
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +67 -0
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +75 -0
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +79 -0
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +87 -0
- data/spec/rails_app/app/models/admin.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +4 -0
- data/spec/rails_app/app/models/user.rb +2 -1
- data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +1 -0
- data/spec/rails_app/app/views/articles/index.html.erb +6 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +17 -3
- data/spec/rails_app/config/routes.rb +2 -2
- data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +33 -0
- data/spec/rails_app/db/schema.rb +18 -0
- data/spec/roles/acts_as_notifiable_spec.rb +1 -1
- data/spec/roles/acts_as_target_spec.rb +1 -1
- metadata +70 -11
- data/lib/generators/activity_notification/notification/notification_generator.rb +0 -20
- data/lib/generators/templates/active_record/migration.rb +0 -18
- data/spec/generators/notification/notification_generator_spec.rb +0 -41
- data/spec/rails_app/db/migrate/20160715050420_create_notifications.rb +0 -18
@@ -0,0 +1,525 @@
|
|
1
|
+
shared_examples_for :subscriber 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) }
|
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 "with association" do
|
12
|
+
it "has many subscriptions" do
|
13
|
+
subscription_1 = create(:subscription, target: test_instance, key: 'subscription_key_1')
|
14
|
+
subscription_2 = create(:subscription, target: test_instance, key: 'subscription_key_2')
|
15
|
+
expect(test_instance.subscriptions.count).to eq(2)
|
16
|
+
expect(test_instance.subscriptions.earliest_order.first).to eq(subscription_1)
|
17
|
+
expect(test_instance.subscriptions.latest_order.first).to eq(subscription_2)
|
18
|
+
expect(test_instance.subscriptions).to eq(ActivityNotification::Subscription.filtered_by_target(test_instance))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "as public class methods" do
|
23
|
+
describe ".available_as_subscriber?" do
|
24
|
+
it "returns true" do
|
25
|
+
expect(described_class.available_as_subscriber?).to be_truthy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "as public instance methods" do
|
31
|
+
before do
|
32
|
+
ActivityNotification::Subscription.delete_all
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#find_subscription" do
|
36
|
+
before do
|
37
|
+
expect(test_instance.subscriptions).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the cofigured subscription exists" do
|
41
|
+
it "returns subscription record" do
|
42
|
+
subscription = test_instance.create_subscription(key: 'test_key')
|
43
|
+
expect(test_instance.subscriptions.reload).not_to be_empty
|
44
|
+
expect(test_instance.find_subscription('test_key')).to eq(subscription)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when the cofigured subscription does not exist" do
|
49
|
+
it "returns nil" do
|
50
|
+
expect(test_instance.find_subscription('test_key')).to be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#find_or_create_subscription" do
|
56
|
+
before do
|
57
|
+
expect(test_instance.subscriptions).to be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when the cofigured subscription exists" do
|
61
|
+
it "returns subscription record" do
|
62
|
+
subscription = test_instance.create_subscription(key: 'test_key')
|
63
|
+
expect(test_instance.subscriptions.reload).not_to be_empty
|
64
|
+
expect(test_instance.find_or_create_subscription('test_key')).to eq(subscription)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the cofigured subscription does not exist" do
|
69
|
+
it "returns created subscription record" do
|
70
|
+
expect(test_instance.find_or_create_subscription('test_key').target).to eq(test_instance)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#create_subscription" do
|
76
|
+
before do
|
77
|
+
expect(test_instance.subscriptions).to be_empty
|
78
|
+
end
|
79
|
+
|
80
|
+
context "without params" do
|
81
|
+
it "does not create a new subscription since it is invalid" do
|
82
|
+
new_subscription = test_instance.create_subscription
|
83
|
+
expect(new_subscription).to be_nil
|
84
|
+
expect(test_instance.subscriptions.reload).to be_empty
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with only key params" do
|
89
|
+
it "creates a new subscription" do
|
90
|
+
params = { key: 'key_1' }
|
91
|
+
new_subscription = test_instance.create_subscription(params)
|
92
|
+
expect(new_subscription.subscribing).to be_truthy
|
93
|
+
expect(new_subscription.subscribing_to_email).to be_truthy
|
94
|
+
expect(test_instance.subscriptions.reload.size).to eq(1)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with false as subscribing params" do
|
99
|
+
it "creates a new subscription" do
|
100
|
+
params = { key: 'key_1', subscribing: false }
|
101
|
+
new_subscription = test_instance.create_subscription(params)
|
102
|
+
expect(new_subscription.subscribing).to be_falsey
|
103
|
+
expect(new_subscription.subscribing_to_email).to be_falsey
|
104
|
+
expect(test_instance.subscriptions.reload.size).to eq(1)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with false as subscribing_to_email params" do
|
109
|
+
it "creates a new subscription" do
|
110
|
+
params = { key: 'key_1', subscribing_to_email: false }
|
111
|
+
new_subscription = test_instance.create_subscription(params)
|
112
|
+
expect(new_subscription.subscribing).to be_truthy
|
113
|
+
expect(new_subscription.subscribing_to_email).to be_falsey
|
114
|
+
expect(test_instance.subscriptions.reload.size).to eq(1)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "with true as subscribing and false as subscribing_to_email params" do
|
119
|
+
it "creates a new subscription" do
|
120
|
+
params = { key: 'key_1', subscribing: true, subscribing_to_email: false }
|
121
|
+
new_subscription = test_instance.create_subscription(params)
|
122
|
+
expect(new_subscription.subscribing).to be_truthy
|
123
|
+
expect(new_subscription.subscribing_to_email).to be_falsey
|
124
|
+
expect(test_instance.subscriptions.reload.size).to eq(1)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with false as subscribing and true as subscribing_to_email params" do
|
129
|
+
it "does not create a new subscription since it is invalid" do
|
130
|
+
params = { key: 'key_1', subscribing: false, subscribing_to_email: true }
|
131
|
+
new_subscription = test_instance.create_subscription(params)
|
132
|
+
expect(new_subscription).to be_nil
|
133
|
+
expect(test_instance.subscriptions.reload).to be_empty
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#subscription_index" do
|
139
|
+
context "when the target has no subscriptions" do
|
140
|
+
it "returns empty records" do
|
141
|
+
expect(test_instance.subscription_index).to be_empty
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when the target has subscriptions" do
|
146
|
+
before do
|
147
|
+
@subscription2 = create(:subscription, target: test_instance, key: 'subscription_key_2')
|
148
|
+
@subscription1 = create(:subscription, target: test_instance, key: 'subscription_key_1')
|
149
|
+
end
|
150
|
+
|
151
|
+
context "without any options" do
|
152
|
+
it "returns the array of subscriptions" do
|
153
|
+
expect(test_instance.subscription_index[0]).to eq(@subscription1)
|
154
|
+
expect(test_instance.subscription_index[1]).to eq(@subscription2)
|
155
|
+
expect(test_instance.subscription_index.size).to eq(2)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "with limit" do
|
160
|
+
it "returns the same as subscriptions with limit" do
|
161
|
+
options = { limit: 1 }
|
162
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription1)
|
163
|
+
expect(test_instance.subscription_index(options).size).to eq(1)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with reverse" do
|
168
|
+
it "returns the earliest order" do
|
169
|
+
options = { reverse: true }
|
170
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
171
|
+
expect(test_instance.subscription_index(options)[1]).to eq(@subscription1)
|
172
|
+
expect(test_instance.subscription_index(options).size).to eq(2)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'with filtered_by_key options' do
|
177
|
+
it "returns filtered notifications only" do
|
178
|
+
options = { filtered_by_key: 'subscription_key_2' }
|
179
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
180
|
+
expect(test_instance.subscription_index(options).size).to eq(1)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'with custom_filter options' do
|
185
|
+
it "returns filtered notifications only" do
|
186
|
+
options = { custom_filter: ["key = ?", 'subscription_key_2'] }
|
187
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
188
|
+
expect(test_instance.subscription_index(options).size).to eq(1)
|
189
|
+
|
190
|
+
options = { custom_filter: { key: 'subscription_key_1' } }
|
191
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription1)
|
192
|
+
expect(test_instance.subscription_index(options).size).to eq(1)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
#TODO
|
197
|
+
# context 'with with_target options' do
|
198
|
+
# it "calls includes(:target)" do
|
199
|
+
# expect(ActiveRecord::Base).to receive(:includes).with(:target)
|
200
|
+
# test_instance.subscription_index(with_target: true)
|
201
|
+
# end
|
202
|
+
# end
|
203
|
+
|
204
|
+
context 'without with_target options' do
|
205
|
+
it "does not call includes(:target)" do
|
206
|
+
expect(ActiveRecord::Base).not_to receive(:includes).with(:target)
|
207
|
+
test_instance.subscription_index
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#notification_keys" do
|
214
|
+
context "when the target has no notifications" do
|
215
|
+
it "returns empty records" do
|
216
|
+
expect(test_instance.notification_keys).to be_empty
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "when the target has notifications" do
|
221
|
+
before do
|
222
|
+
create(:notification, target: test_instance, key: 'notification_key_2')
|
223
|
+
create(:notification, target: test_instance, key: 'notification_key_1')
|
224
|
+
create(:subscription, target: test_instance, key: 'notification_key_1')
|
225
|
+
end
|
226
|
+
|
227
|
+
context "without any options" do
|
228
|
+
it "returns the array of notification keys" do
|
229
|
+
expect(test_instance.notification_keys[0]).to eq('notification_key_1')
|
230
|
+
expect(test_instance.notification_keys[1]).to eq('notification_key_2')
|
231
|
+
expect(test_instance.notification_keys.size).to eq(2)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "with limit" do
|
236
|
+
it "returns the same as subscriptions with limit" do
|
237
|
+
options = { limit: 1 }
|
238
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_1')
|
239
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "with reverse" do
|
244
|
+
it "returns the earliest order" do
|
245
|
+
options = { reverse: true }
|
246
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
247
|
+
expect(test_instance.notification_keys(options)[1]).to eq('notification_key_1')
|
248
|
+
expect(test_instance.notification_keys(options).size).to eq(2)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'with filter' do
|
253
|
+
context 'as :configured' do
|
254
|
+
it "returns notification keys of configured subscriptions only" do
|
255
|
+
options = { filter: :configured }
|
256
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_1')
|
257
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
258
|
+
options = { filter: 'configured' }
|
259
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_1')
|
260
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context 'as :unconfigured' do
|
265
|
+
it "returns unconfigured notification keys only" do
|
266
|
+
options = { filter: :unconfigured }
|
267
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
268
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
269
|
+
options = { filter: 'unconfigured' }
|
270
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
271
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'with filtered_by_key options' do
|
277
|
+
it "returns filtered notifications only" do
|
278
|
+
options = { filtered_by_key: 'notification_key_2' }
|
279
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
280
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context 'with custom_filter options' do
|
285
|
+
it "returns filtered notifications only" do
|
286
|
+
options = { custom_filter: ["key = ?", 'notification_key_2'] }
|
287
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
288
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
289
|
+
|
290
|
+
options = { custom_filter: { key: 'notification_key_1' } }
|
291
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_1')
|
292
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
# Function test for subscriptions
|
299
|
+
|
300
|
+
describe "#notify_to" do
|
301
|
+
before do
|
302
|
+
@test_key = 'test_key'
|
303
|
+
Comment.acts_as_notifiable described_class.to_s.underscore.pluralize.to_sym, targets: [], email_allowed: true
|
304
|
+
@notifiable = create(:comment)
|
305
|
+
expect(@notifiable.notification_email_allowed?(test_instance, @test_key)).to be_truthy
|
306
|
+
end
|
307
|
+
|
308
|
+
context "subscribing to notification" do
|
309
|
+
before do
|
310
|
+
test_instance.create_subscription(key: @test_key)
|
311
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_truthy
|
312
|
+
end
|
313
|
+
|
314
|
+
it "returns created notification" do
|
315
|
+
notification = test_instance.notify_to(@notifiable, key: @test_key)
|
316
|
+
expect(notification).not_to be_nil
|
317
|
+
expect(notification.target).to eq(test_instance)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "creates notification records" do
|
321
|
+
test_instance.notify_to(@notifiable, key: @test_key)
|
322
|
+
expect(test_instance.notifications.unopened_only.count).to eq(1)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context "subscribing to notification email" do
|
327
|
+
before do
|
328
|
+
test_instance.create_subscription(key: @test_key)
|
329
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_truthy
|
330
|
+
end
|
331
|
+
|
332
|
+
context "as default" do
|
333
|
+
it "sends notification email later" do
|
334
|
+
expect {
|
335
|
+
perform_enqueued_jobs do
|
336
|
+
test_instance.notify_to(@notifiable, key: @test_key)
|
337
|
+
end
|
338
|
+
}.to change { ActivityNotification::Mailer.deliveries.size }.by(1)
|
339
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
340
|
+
end
|
341
|
+
|
342
|
+
it "sends notification email with active job queue" do
|
343
|
+
expect {
|
344
|
+
test_instance.notify_to(@notifiable, key: @test_key)
|
345
|
+
}.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context "with send_later false" do
|
350
|
+
it "sends notification email now" do
|
351
|
+
test_instance.notify_to(@notifiable, key: @test_key, send_later: false)
|
352
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
context "unsubscribed to notification" do
|
358
|
+
before do
|
359
|
+
test_instance.create_subscription(key: @test_key, subscribing: false)
|
360
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_falsey
|
361
|
+
end
|
362
|
+
|
363
|
+
it "returns nil" do
|
364
|
+
notification = test_instance.notify_to(@notifiable, key: @test_key)
|
365
|
+
expect(notification).to be_nil
|
366
|
+
end
|
367
|
+
|
368
|
+
it "does not create notification records" do
|
369
|
+
test_instance.notify_to(@notifiable, key: @test_key)
|
370
|
+
expect(test_instance.notifications.unopened_only.count).to eq(0)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
context "unsubscribed to notification email" do
|
375
|
+
before do
|
376
|
+
test_instance.create_subscription(key: @test_key, subscribing: true, subscribing_to_email: false)
|
377
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_falsey
|
378
|
+
end
|
379
|
+
|
380
|
+
context "as default" do
|
381
|
+
it "does not send notification email later" do
|
382
|
+
expect {
|
383
|
+
perform_enqueued_jobs do
|
384
|
+
test_instance.notify_to(@notifiable, key: @test_key)
|
385
|
+
end
|
386
|
+
}.to change { ActivityNotification::Mailer.deliveries.size }.by(0)
|
387
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
388
|
+
end
|
389
|
+
|
390
|
+
it "does not send notification email with active job queue" do
|
391
|
+
expect {
|
392
|
+
test_instance.notify_to(@notifiable, key: @test_key)
|
393
|
+
}.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(0)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context "with send_later false" do
|
398
|
+
it "does not send notification email now" do
|
399
|
+
test_instance.notify_to(@notifiable, key: @test_key, send_later: false)
|
400
|
+
expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
describe "#subscribes_to_notification?" do
|
407
|
+
before do
|
408
|
+
@test_key = 'test_key'
|
409
|
+
end
|
410
|
+
|
411
|
+
context "when the subscription is not enabled for the target" do
|
412
|
+
it "returns true" do
|
413
|
+
described_class._notification_subscription_allowed = false
|
414
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_truthy
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
context "when the subscription is enabled for the target" do
|
419
|
+
before do
|
420
|
+
described_class._notification_subscription_allowed = true
|
421
|
+
end
|
422
|
+
|
423
|
+
context "without configured subscpriotion" do
|
424
|
+
context "without subscribe_as_default argument" do
|
425
|
+
context "with true as ActivityNotification.config.subscribe_as_default" do
|
426
|
+
it "returns true" do
|
427
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
428
|
+
ActivityNotification.config.subscribe_as_default = true
|
429
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_truthy
|
430
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
context "with false as ActivityNotification.config.subscribe_as_default" do
|
435
|
+
it "returns false" do
|
436
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
437
|
+
ActivityNotification.config.subscribe_as_default = false
|
438
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_falsey
|
439
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context "with configured subscpriotion" do
|
446
|
+
context "subscribing to notification" do
|
447
|
+
it "returns true" do
|
448
|
+
subscription = test_instance.create_subscription(key: @test_key)
|
449
|
+
expect(subscription.subscribing).to be_truthy
|
450
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_truthy
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
context "unsubscribed to notification" do
|
455
|
+
it "returns false" do
|
456
|
+
subscription = test_instance.create_subscription(key: @test_key, subscribing: false)
|
457
|
+
expect(subscription.subscribing).to be_falsey
|
458
|
+
expect(test_instance.subscribes_to_notification?(@test_key)).to be_falsey
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
describe "#subscribes_to_notification_email?" do
|
466
|
+
before do
|
467
|
+
@test_key = 'test_key'
|
468
|
+
end
|
469
|
+
|
470
|
+
context "when the subscription is not enabled for the target" do
|
471
|
+
it "returns true" do
|
472
|
+
described_class._notification_subscription_allowed = false
|
473
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_truthy
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context "when the subscription is enabled for the target" do
|
478
|
+
before do
|
479
|
+
described_class._notification_subscription_allowed = true
|
480
|
+
end
|
481
|
+
|
482
|
+
context "without configured subscpriotion" do
|
483
|
+
context "without subscribe_as_default argument" do
|
484
|
+
context "with true as ActivityNotification.config.subscribe_as_default" do
|
485
|
+
it "returns true" do
|
486
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
487
|
+
ActivityNotification.config.subscribe_as_default = true
|
488
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_truthy
|
489
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
context "with false as ActivityNotification.config.subscribe_as_default" do
|
494
|
+
it "returns false" do
|
495
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
496
|
+
ActivityNotification.config.subscribe_as_default = false
|
497
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_falsey
|
498
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
context "with configured subscpriotion" do
|
505
|
+
context "subscribing to notification email" do
|
506
|
+
it "returns true" do
|
507
|
+
subscription = test_instance.create_subscription(key: @test_key)
|
508
|
+
expect(subscription.subscribing_to_email).to be_truthy
|
509
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_truthy
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
context "unsubscribed to notification" do
|
514
|
+
it "returns false" do
|
515
|
+
subscription = test_instance.create_subscription(key: @test_key, subscribing: true, subscribing_to_email: false)
|
516
|
+
expect(subscription.subscribing_to_email).to be_falsey
|
517
|
+
expect(test_instance.subscribes_to_notification_email?(@test_key)).to be_falsey
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
end
|
525
|
+
end
|