activity_notification 1.7.1 → 2.0.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 +5 -5
- data/.gitignore +3 -0
- data/.travis.yml +16 -2
- data/CHANGELOG.md +22 -2
- data/Gemfile +7 -0
- data/Procfile +2 -0
- data/README.md +366 -32
- data/Rakefile +19 -10
- data/activity_notification.gemspec +5 -3
- data/app/channels/activity_notification/notification_channel.rb +37 -0
- data/app/channels/activity_notification/notification_with_devise_channel.rb +51 -0
- data/app/controllers/activity_notification/notifications_controller.rb +1 -1
- data/app/controllers/activity_notification/subscriptions_controller.rb +1 -1
- data/app/jobs/activity_notification/notify_all_job.rb +16 -0
- data/app/jobs/activity_notification/notify_job.rb +17 -0
- data/app/jobs/activity_notification/notify_to_job.rb +16 -0
- data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +1 -1
- data/app/views/activity_notification/notifications/default/index.html.erb +55 -2
- data/bin/_dynamodblocal +4 -0
- data/{scripts → bin}/bundle_update.sh +1 -0
- data/bin/deploy_on_heroku.sh +14 -0
- data/bin/install_dynamodblocal.sh +5 -0
- data/bin/start_dynamodblocal.sh +47 -0
- data/bin/stop_dynamodblocal.sh +34 -0
- data/gemfiles/Gemfile.rails-4.2 +1 -0
- data/gemfiles/Gemfile.rails-5.0 +2 -0
- data/gemfiles/Gemfile.rails-5.1 +1 -0
- data/gemfiles/Gemfile.rails-5.2 +1 -0
- data/gemfiles/Gemfile.rails-6.0.rc +21 -0
- data/lib/activity_notification.rb +1 -0
- data/lib/activity_notification/apis/notification_api.rb +289 -136
- data/lib/activity_notification/apis/subscription_api.rb +80 -53
- data/lib/activity_notification/common.rb +3 -3
- data/lib/activity_notification/config.rb +89 -33
- data/lib/activity_notification/controllers/common_controller.rb +19 -7
- data/lib/activity_notification/helpers/errors.rb +4 -0
- data/lib/activity_notification/helpers/view_helpers.rb +1 -1
- data/lib/activity_notification/models/concerns/notifiable.rb +61 -53
- data/lib/activity_notification/models/concerns/subscriber.rb +7 -6
- data/lib/activity_notification/models/concerns/target.rb +73 -28
- data/lib/activity_notification/optional_targets/base.rb +2 -2
- data/lib/activity_notification/orm/active_record/notification.rb +4 -23
- data/lib/activity_notification/orm/dynamoid.rb +495 -0
- data/lib/activity_notification/orm/dynamoid/extension.rb +184 -0
- data/lib/activity_notification/orm/dynamoid/notification.rb +189 -0
- data/lib/activity_notification/orm/dynamoid/subscription.rb +82 -0
- data/lib/activity_notification/orm/mongoid.rb +4 -1
- data/lib/activity_notification/orm/mongoid/notification.rb +8 -25
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/roles/acts_as_notifiable.rb +33 -5
- data/lib/activity_notification/roles/acts_as_target.rb +62 -9
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +30 -7
- data/lib/tasks/activity_notification_tasks.rake +14 -4
- data/spec/channels/notification_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_channel_spec.rb +50 -0
- data/spec/channels/notification_with_devise_channel_spec.rb +99 -0
- data/spec/concerns/apis/notification_api_spec.rb +2 -2
- data/spec/concerns/apis/subscription_api_spec.rb +2 -2
- data/spec/concerns/models/notifiable_spec.rb +72 -7
- data/spec/concerns/models/subscriber_spec.rb +53 -49
- data/spec/concerns/models/target_spec.rb +135 -13
- data/spec/config_spec.rb +41 -1
- data/spec/controllers/notifications_controller_shared_examples.rb +7 -3
- data/spec/controllers/subscriptions_controller_shared_examples.rb +7 -3
- data/spec/helpers/view_helpers_spec.rb +12 -10
- data/spec/models/dummy/dummy_group_spec.rb +4 -0
- data/spec/models/dummy/dummy_notifiable_spec.rb +4 -0
- data/spec/models/dummy/dummy_notifier_spec.rb +4 -0
- data/spec/models/dummy/dummy_subscriber_spec.rb +3 -0
- data/spec/models/dummy/dummy_target_spec.rb +4 -0
- data/spec/models/notification_spec.rb +164 -45
- data/spec/models/subscription_spec.rb +69 -14
- data/spec/orm/dynamoid_spec.rb +115 -0
- data/spec/rails_app/app/assets/javascripts/application.js +2 -1
- data/spec/rails_app/app/assets/javascripts/cable.js +12 -0
- data/spec/rails_app/app/controllers/comments_controller.rb +3 -4
- data/spec/rails_app/app/models/admin.rb +6 -4
- data/spec/rails_app/app/models/article.rb +2 -2
- data/spec/rails_app/app/models/comment.rb +17 -5
- data/spec/rails_app/app/models/user.rb +5 -3
- data/spec/rails_app/app/views/activity_notification/notifications/users/overridden/custom/_test.html.erb +1 -0
- data/spec/rails_app/config/application.rb +6 -1
- data/spec/rails_app/config/cable.yml +8 -0
- data/spec/rails_app/config/dynamoid.rb +5 -0
- data/spec/rails_app/config/environment.rb +4 -1
- data/spec/rails_app/config/environments/production.rb +1 -1
- data/spec/rails_app/config/initializers/activity_notification.rb +30 -7
- data/spec/rails_app/config/locales/activity_notification.en.yml +2 -0
- data/spec/rails_app/db/seeds.rb +21 -5
- data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +12 -4
- data/spec/roles/acts_as_notifiable_spec.rb +2 -2
- data/spec/roles/acts_as_target_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -8
- metadata +67 -20
- data/spec/rails_app/app/models/.keep +0 -0
- data/spec/rails_app/app/views/activity_notification/notifications/users/overriden/custom/_test.html.erb +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
if Rails::VERSION::MAJOR >= 5
|
|
2
|
+
require 'channels/notification_channel_shared_examples'
|
|
3
|
+
|
|
4
|
+
#TODO Make it more smart test method
|
|
5
|
+
module ActivityNotification
|
|
6
|
+
module Test
|
|
7
|
+
class NotificationWithDeviseChannel < ::ActivityNotification::NotificationWithDeviseChannel
|
|
8
|
+
@@custom_current_target = nil
|
|
9
|
+
|
|
10
|
+
def set_custom_current_target(custom_current_target)
|
|
11
|
+
@@custom_current_target = custom_current_target
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def find_current_target(devise_type = nil)
|
|
15
|
+
super(devise_type)
|
|
16
|
+
rescue NoMethodError
|
|
17
|
+
devise_type = (devise_type || @target.notification_devise_resource.class.name).to_s
|
|
18
|
+
@@custom_current_target.is_a?(devise_type.to_model_class) ? @@custom_current_target : nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @See https://github.com/palkan/action-cable-testing
|
|
25
|
+
describe ActivityNotification::Test::NotificationWithDeviseChannel, type: :channel do
|
|
26
|
+
let(:test_user) { create(:confirmed_user) }
|
|
27
|
+
let(:unauthenticated_user) { create(:confirmed_user) }
|
|
28
|
+
let(:test_target) { create(:admin, user: test_user) }
|
|
29
|
+
let(:target_type) { "Admin" }
|
|
30
|
+
let(:typed_target_param) { "admin_id" }
|
|
31
|
+
let(:extra_params) { { devise_type: :users } }
|
|
32
|
+
let(:valid_session) {}
|
|
33
|
+
|
|
34
|
+
#TODO Make it more smart test method
|
|
35
|
+
#include Devise::Test::IntegrationHelpers
|
|
36
|
+
def sign_in(current_target)
|
|
37
|
+
described_class.new(ActionCable::Channel::ConnectionStub.new, {}).set_custom_current_target(current_target)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
before do
|
|
41
|
+
@user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
|
|
42
|
+
User._notification_action_cable_with_devise = true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
after do
|
|
46
|
+
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "signed in with devise as authenticated user" do
|
|
50
|
+
before do
|
|
51
|
+
sign_in test_user
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it_behaves_like :notification_channel
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context "signed in with devise as unauthenticated user" do
|
|
58
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
59
|
+
|
|
60
|
+
before do
|
|
61
|
+
sign_in unauthenticated_user
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "rejects subscription" do
|
|
65
|
+
subscribe(target_params.merge({ typed_target_param => test_target }))
|
|
66
|
+
expect(subscription).to be_rejected
|
|
67
|
+
expect {
|
|
68
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
69
|
+
}.to raise_error(/Must be subscribed!/)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context "unsigned in with devise" do
|
|
74
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
75
|
+
|
|
76
|
+
it "rejects subscription" do
|
|
77
|
+
subscribe(target_params.merge({ typed_target_param => test_target }))
|
|
78
|
+
expect(subscription).to be_rejected
|
|
79
|
+
expect {
|
|
80
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
81
|
+
}.to raise_error(/Must be subscribed!/)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "without target_id and (typed_target)_id parameters for devise integrated channel with devise_type option" do
|
|
86
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
87
|
+
|
|
88
|
+
before do
|
|
89
|
+
sign_in test_target.user
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "successfully subscribes" do
|
|
93
|
+
subscribe(target_params)
|
|
94
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
95
|
+
expect(subscription).to have_stream_from("activity_notification_channel_Admin##{test_target.id}")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -308,7 +308,7 @@ shared_examples_for :notification_api do
|
|
|
308
308
|
end
|
|
309
309
|
|
|
310
310
|
it "has parameters of notifiable.notification_parameters" do
|
|
311
|
-
expect(created_notification.parameters)
|
|
311
|
+
expect(created_notification.parameters.stringify_keys)
|
|
312
312
|
.to eq(
|
|
313
313
|
created_notification.notifiable.notification_parameters(
|
|
314
314
|
@user_1.class,
|
|
@@ -605,7 +605,7 @@ shared_examples_for :notification_api do
|
|
|
605
605
|
describe ".available_options" do
|
|
606
606
|
it "returns list of available options in notify api" do
|
|
607
607
|
expect(described_class.available_options)
|
|
608
|
-
.to eq([:key, :group, :
|
|
608
|
+
.to eq([:key, :group, :group_expiry_delay, :notifier, :parameters, :send_email, :send_later])
|
|
609
609
|
end
|
|
610
610
|
end
|
|
611
611
|
end
|
|
@@ -279,7 +279,7 @@ shared_examples_for :subscription_api do
|
|
|
279
279
|
test_instance.subscribe_to_optional_target(:console_output)
|
|
280
280
|
expect(test_instance.subscribing?).to eq(true)
|
|
281
281
|
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(true)
|
|
282
|
-
expect(test_instance.optional_targets[:subscribed_to_console_output_at]).to eq(Time.current)
|
|
282
|
+
expect(test_instance.optional_targets[:subscribed_to_console_output_at]).to eq(ActivityNotification::Subscription.convert_time_as_hash(Time.current))
|
|
283
283
|
Timecop.return
|
|
284
284
|
end
|
|
285
285
|
end
|
|
@@ -310,7 +310,7 @@ shared_examples_for :subscription_api do
|
|
|
310
310
|
test_instance.unsubscribe_to_optional_target(:console_output)
|
|
311
311
|
expect(test_instance.subscribing?).to eq(true)
|
|
312
312
|
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(false)
|
|
313
|
-
expect(test_instance.optional_targets[:unsubscribed_to_console_output_at]).to eq(Time.current)
|
|
313
|
+
expect(test_instance.optional_targets[:unsubscribed_to_console_output_at]).to eq(ActivityNotification::Subscription.convert_time_as_hash(Time.current))
|
|
314
314
|
Timecop.return
|
|
315
315
|
end
|
|
316
316
|
end
|
|
@@ -21,6 +21,7 @@ shared_examples_for :notifiable do
|
|
|
21
21
|
expect(described_class._notifier).to eq({})
|
|
22
22
|
expect(described_class._notification_parameters).to eq({})
|
|
23
23
|
expect(described_class._notification_email_allowed).to eq({})
|
|
24
|
+
expect(described_class._notification_action_cable_allowed).to eq({})
|
|
24
25
|
expect(described_class._notifiable_path).to eq({})
|
|
25
26
|
expect(described_class._printable_notifiable_name).to eq({})
|
|
26
27
|
end
|
|
@@ -47,7 +48,7 @@ shared_examples_for :notifiable do
|
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
|
|
50
|
-
context "configured with
|
|
51
|
+
context "configured with overridden method" do
|
|
51
52
|
it "returns specified value" do
|
|
52
53
|
module AdditionalMethods
|
|
53
54
|
def notification_users(key)
|
|
@@ -116,7 +117,7 @@ shared_examples_for :notifiable do
|
|
|
116
117
|
end
|
|
117
118
|
end
|
|
118
119
|
|
|
119
|
-
context "configured with
|
|
120
|
+
context "configured with overridden method" do
|
|
120
121
|
it "returns specified value" do
|
|
121
122
|
module AdditionalMethods
|
|
122
123
|
def notification_group_for_users(key)
|
|
@@ -175,7 +176,7 @@ shared_examples_for :notifiable do
|
|
|
175
176
|
end
|
|
176
177
|
end
|
|
177
178
|
|
|
178
|
-
context "configured with
|
|
179
|
+
context "configured with overridden method" do
|
|
179
180
|
it "returns specified value" do
|
|
180
181
|
module AdditionalMethods
|
|
181
182
|
def notification_group_expiry_delay_for_users(key)
|
|
@@ -234,7 +235,7 @@ shared_examples_for :notifiable do
|
|
|
234
235
|
end
|
|
235
236
|
end
|
|
236
237
|
|
|
237
|
-
context "configured with
|
|
238
|
+
context "configured with overridden method" do
|
|
238
239
|
it "returns specified value" do
|
|
239
240
|
module AdditionalMethods
|
|
240
241
|
def notification_parameters_for_users(key)
|
|
@@ -293,7 +294,7 @@ shared_examples_for :notifiable do
|
|
|
293
294
|
end
|
|
294
295
|
end
|
|
295
296
|
|
|
296
|
-
context "configured with
|
|
297
|
+
context "configured with overridden method" do
|
|
297
298
|
it "returns specified value" do
|
|
298
299
|
module AdditionalMethods
|
|
299
300
|
def notifier_for_users(key)
|
|
@@ -357,7 +358,7 @@ shared_examples_for :notifiable do
|
|
|
357
358
|
end
|
|
358
359
|
end
|
|
359
360
|
|
|
360
|
-
context "configured with
|
|
361
|
+
context "configured with overridden method" do
|
|
361
362
|
it "returns specified value" do
|
|
362
363
|
module AdditionalMethods
|
|
363
364
|
def notification_email_allowed_for_users?(target, key)
|
|
@@ -409,6 +410,70 @@ shared_examples_for :notifiable do
|
|
|
409
410
|
end
|
|
410
411
|
end
|
|
411
412
|
|
|
413
|
+
describe "#notification_action_cable_allowed?" do
|
|
414
|
+
context "without any configuration" do
|
|
415
|
+
it "returns ActivityNotification.config.action_cable_enabled" do
|
|
416
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key'))
|
|
417
|
+
.to eq(ActivityNotification.config.action_cable_enabled)
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
it "returns false as default" do
|
|
421
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to be_falsey
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
context "configured with overridden method" do
|
|
426
|
+
it "returns specified value" do
|
|
427
|
+
module AdditionalMethods
|
|
428
|
+
def notification_action_cable_allowed_for_users?(target, key)
|
|
429
|
+
true
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
test_instance.extend(AdditionalMethods)
|
|
433
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
context "configured with a field" do
|
|
438
|
+
it "returns specified value" do
|
|
439
|
+
described_class._notification_action_cable_allowed[:users] = true
|
|
440
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
it "returns specified symbol without arguments" do
|
|
444
|
+
module AdditionalMethods
|
|
445
|
+
def custom_notification_action_cable_allowed?
|
|
446
|
+
true
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
test_instance.extend(AdditionalMethods)
|
|
450
|
+
described_class._notification_action_cable_allowed[:users] = :custom_notification_action_cable_allowed?
|
|
451
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
it "returns specified symbol with target and key arguments" do
|
|
455
|
+
module AdditionalMethods
|
|
456
|
+
def custom_notification_action_cable_allowed?(target, key)
|
|
457
|
+
true
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
test_instance.extend(AdditionalMethods)
|
|
461
|
+
described_class._notification_action_cable_allowed[:users] = :custom_notification_action_cable_allowed?
|
|
462
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
it "returns specified lambda with single notifiable argument" do
|
|
466
|
+
described_class._notification_action_cable_allowed[:users] = ->(notifiable){ true }
|
|
467
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
it "returns specified lambda with notifiable, target and key arguments" do
|
|
471
|
+
described_class._notification_action_cable_allowed[:users] = ->(notifiable, target, key){ true }
|
|
472
|
+
expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
|
|
412
477
|
describe "#notifiable_path" do
|
|
413
478
|
context "without any configuration" do
|
|
414
479
|
it "raises NotImplementedError" do
|
|
@@ -424,7 +489,7 @@ shared_examples_for :notifiable do
|
|
|
424
489
|
end
|
|
425
490
|
end
|
|
426
491
|
|
|
427
|
-
context "configured with
|
|
492
|
+
context "configured with overridden method" do
|
|
428
493
|
it "returns specified value" do
|
|
429
494
|
module AdditionalMethods
|
|
430
495
|
def notifiable_path_for_users(key)
|
|
@@ -15,7 +15,7 @@ shared_examples_for :subscriber do
|
|
|
15
15
|
expect(test_instance.subscriptions.count).to eq(2)
|
|
16
16
|
expect(test_instance.subscriptions.earliest_order.first).to eq(subscription_1)
|
|
17
17
|
expect(test_instance.subscriptions.latest_order.first).to eq(subscription_2)
|
|
18
|
-
expect(test_instance.subscriptions.latest_order).to
|
|
18
|
+
expect(test_instance.subscriptions.latest_order.to_a).to eq(ActivityNotification::Subscription.filtered_by_target(test_instance).latest_order.to_a)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -30,13 +30,13 @@ shared_examples_for :subscriber do
|
|
|
30
30
|
describe "as public instance methods" do
|
|
31
31
|
describe "#find_subscription" do
|
|
32
32
|
before do
|
|
33
|
-
expect(test_instance.subscriptions).to be_empty
|
|
33
|
+
expect(test_instance.subscriptions.to_a).to be_empty
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
context "when the cofigured subscription exists" do
|
|
37
37
|
it "returns subscription record" do
|
|
38
38
|
subscription = test_instance.create_subscription(key: 'test_key')
|
|
39
|
-
expect(test_instance.subscriptions.reload).not_to be_empty
|
|
39
|
+
expect(test_instance.subscriptions.reload.to_a).not_to be_empty
|
|
40
40
|
expect(test_instance.find_subscription('test_key')).to eq(subscription)
|
|
41
41
|
end
|
|
42
42
|
end
|
|
@@ -50,13 +50,13 @@ shared_examples_for :subscriber do
|
|
|
50
50
|
|
|
51
51
|
describe "#find_or_create_subscription" do
|
|
52
52
|
before do
|
|
53
|
-
expect(test_instance.subscriptions).to be_empty
|
|
53
|
+
expect(test_instance.subscriptions.to_a).to be_empty
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
context "when the cofigured subscription exists" do
|
|
57
57
|
it "returns subscription record" do
|
|
58
58
|
subscription = test_instance.create_subscription(key: 'test_key')
|
|
59
|
-
expect(test_instance.subscriptions.reload).not_to be_empty
|
|
59
|
+
expect(test_instance.subscriptions.reload.to_a).not_to be_empty
|
|
60
60
|
expect(test_instance.find_or_create_subscription('test_key')).to eq(subscription)
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -70,14 +70,14 @@ shared_examples_for :subscriber do
|
|
|
70
70
|
|
|
71
71
|
describe "#create_subscription" do
|
|
72
72
|
before do
|
|
73
|
-
expect(test_instance.subscriptions).to be_empty
|
|
73
|
+
expect(test_instance.subscriptions.to_a).to be_empty
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
context "without params" do
|
|
77
77
|
it "does not create a new subscription since it is invalid" do
|
|
78
78
|
new_subscription = test_instance.create_subscription
|
|
79
79
|
expect(new_subscription).to be_nil
|
|
80
|
-
expect(test_instance.subscriptions.reload).to
|
|
80
|
+
expect(test_instance.subscriptions.reload.to_a).to be_empty
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -85,8 +85,8 @@ shared_examples_for :subscriber do
|
|
|
85
85
|
it "creates a new subscription" do
|
|
86
86
|
params = { key: 'key_1' }
|
|
87
87
|
new_subscription = test_instance.create_subscription(params)
|
|
88
|
-
expect(new_subscription.subscribing?).to
|
|
89
|
-
expect(new_subscription.subscribing_to_email?).to
|
|
88
|
+
expect(new_subscription.subscribing?).to be_truthy
|
|
89
|
+
expect(new_subscription.subscribing_to_email?).to be_truthy
|
|
90
90
|
expect(test_instance.subscriptions.reload.size).to eq(1)
|
|
91
91
|
end
|
|
92
92
|
end
|
|
@@ -95,8 +95,8 @@ shared_examples_for :subscriber do
|
|
|
95
95
|
it "creates a new subscription" do
|
|
96
96
|
params = { key: 'key_1', subscribing: false }
|
|
97
97
|
new_subscription = test_instance.create_subscription(params)
|
|
98
|
-
expect(new_subscription.subscribing?).to
|
|
99
|
-
expect(new_subscription.subscribing_to_email?).to
|
|
98
|
+
expect(new_subscription.subscribing?).to be_falsey
|
|
99
|
+
expect(new_subscription.subscribing_to_email?).to be_falsey
|
|
100
100
|
expect(test_instance.subscriptions.reload.size).to eq(1)
|
|
101
101
|
end
|
|
102
102
|
end
|
|
@@ -105,8 +105,8 @@ shared_examples_for :subscriber do
|
|
|
105
105
|
it "creates a new subscription" do
|
|
106
106
|
params = { key: 'key_1', subscribing_to_email: false }
|
|
107
107
|
new_subscription = test_instance.create_subscription(params)
|
|
108
|
-
expect(new_subscription.subscribing?).to
|
|
109
|
-
expect(new_subscription.subscribing_to_email?).to
|
|
108
|
+
expect(new_subscription.subscribing?).to be_truthy
|
|
109
|
+
expect(new_subscription.subscribing_to_email?).to be_falsey
|
|
110
110
|
expect(test_instance.subscriptions.reload.size).to eq(1)
|
|
111
111
|
end
|
|
112
112
|
end
|
|
@@ -115,8 +115,8 @@ shared_examples_for :subscriber do
|
|
|
115
115
|
it "creates a new subscription" do
|
|
116
116
|
params = { key: 'key_1', subscribing: true, subscribing_to_email: false }
|
|
117
117
|
new_subscription = test_instance.create_subscription(params)
|
|
118
|
-
expect(new_subscription.subscribing?).to
|
|
119
|
-
expect(new_subscription.subscribing_to_email?).to
|
|
118
|
+
expect(new_subscription.subscribing?).to be_truthy
|
|
119
|
+
expect(new_subscription.subscribing_to_email?).to be_falsey
|
|
120
120
|
expect(test_instance.subscriptions.reload.size).to eq(1)
|
|
121
121
|
end
|
|
122
122
|
end
|
|
@@ -126,7 +126,7 @@ shared_examples_for :subscriber do
|
|
|
126
126
|
params = { key: 'key_1', subscribing: false, subscribing_to_email: true }
|
|
127
127
|
new_subscription = test_instance.create_subscription(params)
|
|
128
128
|
expect(new_subscription).to be_nil
|
|
129
|
-
expect(test_instance.subscriptions.reload).to
|
|
129
|
+
expect(test_instance.subscriptions.reload.to_a).to be_empty
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
|
|
@@ -167,7 +167,7 @@ shared_examples_for :subscriber do
|
|
|
167
167
|
params = { key: 'key_1', subscribing: false, optional_targets: { subscribing_to_console_output: true } }
|
|
168
168
|
new_subscription = test_instance.create_subscription(params)
|
|
169
169
|
expect(new_subscription).to be_nil
|
|
170
|
-
expect(test_instance.subscriptions.reload).to
|
|
170
|
+
expect(test_instance.subscriptions.reload.to_a).to be_empty
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
end
|
|
@@ -187,8 +187,8 @@ shared_examples_for :subscriber do
|
|
|
187
187
|
|
|
188
188
|
context "without any options" do
|
|
189
189
|
it "returns the array of subscriptions" do
|
|
190
|
-
expect(test_instance.subscription_index[0]).to
|
|
191
|
-
expect(test_instance.subscription_index[1]).to
|
|
190
|
+
expect(test_instance.subscription_index[0]).to eq(@subscription1)
|
|
191
|
+
expect(test_instance.subscription_index[1]).to eq(@subscription2)
|
|
192
192
|
expect(test_instance.subscription_index.size).to eq(2)
|
|
193
193
|
end
|
|
194
194
|
end
|
|
@@ -196,7 +196,7 @@ shared_examples_for :subscriber do
|
|
|
196
196
|
context "with limit" do
|
|
197
197
|
it "returns the same as subscriptions with limit" do
|
|
198
198
|
options = { limit: 1 }
|
|
199
|
-
expect(test_instance.subscription_index(options)[0]).to
|
|
199
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription1)
|
|
200
200
|
expect(test_instance.subscription_index(options).size).to eq(1)
|
|
201
201
|
end
|
|
202
202
|
end
|
|
@@ -204,8 +204,8 @@ shared_examples_for :subscriber do
|
|
|
204
204
|
context "with reverse" do
|
|
205
205
|
it "returns the earliest order" do
|
|
206
206
|
options = { reverse: true }
|
|
207
|
-
expect(test_instance.subscription_index(options)[0]).to
|
|
208
|
-
expect(test_instance.subscription_index(options)[1]).to
|
|
207
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
|
208
|
+
expect(test_instance.subscription_index(options)[1]).to eq(@subscription1)
|
|
209
209
|
expect(test_instance.subscription_index(options).size).to eq(2)
|
|
210
210
|
end
|
|
211
211
|
end
|
|
@@ -213,37 +213,36 @@ shared_examples_for :subscriber do
|
|
|
213
213
|
context 'with filtered_by_key options' do
|
|
214
214
|
it "returns filtered notifications only" do
|
|
215
215
|
options = { filtered_by_key: 'subscription_key_2' }
|
|
216
|
-
expect(test_instance.subscription_index(options)[0]).to
|
|
216
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
|
217
217
|
expect(test_instance.subscription_index(options).size).to eq(1)
|
|
218
218
|
end
|
|
219
219
|
end
|
|
220
220
|
|
|
221
221
|
context 'with custom_filter options' do
|
|
222
|
-
it "returns filtered
|
|
223
|
-
if ActivityNotification.config.orm == :active_record
|
|
224
|
-
options = { custom_filter: ["subscriptions.key = ?", 'subscription_key_2'] }
|
|
225
|
-
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
|
226
|
-
expect(test_instance.subscription_index(options).size).to eq(1)
|
|
227
|
-
end
|
|
228
|
-
|
|
222
|
+
it "returns filtered subscriptions only" do
|
|
229
223
|
options = { custom_filter: { key: 'subscription_key_1' } }
|
|
230
|
-
expect(test_instance.subscription_index(options)[0]).to
|
|
224
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription1)
|
|
231
225
|
expect(test_instance.subscription_index(options).size).to eq(1)
|
|
232
226
|
end
|
|
233
|
-
end
|
|
234
227
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
228
|
+
it "returns filtered subscriptions only with filter depending on ORM" do
|
|
229
|
+
options =
|
|
230
|
+
case ActivityNotification.config.orm
|
|
231
|
+
when :active_record then { custom_filter: ["subscriptions.key = ?", 'subscription_key_2'] }
|
|
232
|
+
when :mongoid then { custom_filter: { key: {'$eq': 'subscription_key_2'} } }
|
|
233
|
+
when :dynamoid then { custom_filter: {'key.begins_with': 'subscription_key_2'} }
|
|
234
|
+
end
|
|
235
|
+
expect(test_instance.subscription_index(options)[0]).to eq(@subscription2)
|
|
236
|
+
expect(test_instance.subscription_index(options).size).to eq(1)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
242
239
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
240
|
+
if ActivityNotification.config.orm == :active_record
|
|
241
|
+
context 'with with_target options' do
|
|
242
|
+
it "calls with_target" do
|
|
243
|
+
expect(ActivityNotification::Subscription).to receive_message_chain(:with_target)
|
|
244
|
+
test_instance.subscription_index(with_target: true)
|
|
245
|
+
end
|
|
247
246
|
end
|
|
248
247
|
end
|
|
249
248
|
end
|
|
@@ -322,16 +321,21 @@ shared_examples_for :subscriber do
|
|
|
322
321
|
|
|
323
322
|
context 'with custom_filter options' do
|
|
324
323
|
it "returns filtered notifications only" do
|
|
325
|
-
if ActivityNotification.config.orm == :active_record
|
|
326
|
-
options = { custom_filter: ["notifications.key = ?", 'notification_key_2'] }
|
|
327
|
-
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
|
328
|
-
expect(test_instance.notification_keys(options).size).to eq(1)
|
|
329
|
-
end
|
|
330
|
-
|
|
331
324
|
options = { custom_filter: { key: 'notification_key_1' } }
|
|
332
325
|
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_1')
|
|
333
326
|
expect(test_instance.notification_keys(options).size).to eq(1)
|
|
334
327
|
end
|
|
328
|
+
|
|
329
|
+
it "returns filtered notifications only with filter depending on ORM" do
|
|
330
|
+
options =
|
|
331
|
+
case ActivityNotification.config.orm
|
|
332
|
+
when :active_record then { custom_filter: ["notifications.key = ?", 'notification_key_2'] }
|
|
333
|
+
when :mongoid then { custom_filter: { key: {'$eq': 'notification_key_2'} } }
|
|
334
|
+
when :dynamoid then { custom_filter: {'key.begins_with': 'notification_key_2'} }
|
|
335
|
+
end
|
|
336
|
+
expect(test_instance.notification_keys(options)[0]).to eq('notification_key_2')
|
|
337
|
+
expect(test_instance.notification_keys(options).size).to eq(1)
|
|
338
|
+
end
|
|
335
339
|
end
|
|
336
340
|
end
|
|
337
341
|
end
|