activity_notification 2.1.1 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -16
  3. data/CHANGELOG.md +53 -0
  4. data/Gemfile +2 -3
  5. data/README.md +1 -1
  6. data/activity_notification.gemspec +1 -1
  7. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +1 -1
  8. data/app/channels/activity_notification/notification_channel.rb +1 -1
  9. data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
  10. data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +1 -1
  11. data/app/controllers/activity_notification/notifications_controller.rb +0 -20
  12. data/app/controllers/activity_notification/subscriptions_api_controller.rb +1 -1
  13. data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +1 -1
  14. data/bin/bundle_update.sh +0 -1
  15. data/docs/Functions.md +2 -2
  16. data/docs/Setup.md +190 -63
  17. data/gemfiles/Gemfile.rails-5.0 +3 -1
  18. data/gemfiles/Gemfile.rails-5.1 +3 -1
  19. data/gemfiles/Gemfile.rails-5.2 +3 -1
  20. data/gemfiles/Gemfile.rails-6.0 +2 -3
  21. data/gemfiles/Gemfile.rails-6.1 +24 -0
  22. data/lib/activity_notification/apis/notification_api.rb +7 -0
  23. data/lib/activity_notification/common.rb +15 -4
  24. data/lib/activity_notification/controllers/common_controller.rb +2 -18
  25. data/lib/activity_notification/models/concerns/notifiable.rb +12 -12
  26. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +34 -34
  27. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +17 -17
  28. data/lib/activity_notification/models/concerns/target.rb +5 -9
  29. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +1 -1
  30. data/lib/activity_notification/optional_targets/action_cable_channel.rb +1 -1
  31. data/lib/activity_notification/orm/active_record.rb +1 -1
  32. data/lib/activity_notification/orm/active_record/notification.rb +3 -3
  33. data/lib/activity_notification/orm/dynamoid.rb +10 -3
  34. data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
  35. data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
  36. data/lib/activity_notification/orm/mongoid.rb +10 -3
  37. data/lib/activity_notification/orm/mongoid/notification.rb +8 -6
  38. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  39. data/lib/activity_notification/renderable.rb +2 -2
  40. data/lib/activity_notification/roles/acts_as_notifiable.rb +13 -16
  41. data/lib/activity_notification/version.rb +1 -1
  42. data/lib/generators/templates/migrations/migration.rb +1 -1
  43. data/spec/channels/notification_api_channel_spec.rb +42 -44
  44. data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
  45. data/spec/channels/notification_channel_spec.rb +41 -43
  46. data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
  47. data/spec/concerns/common_spec.rb +25 -3
  48. data/spec/concerns/models/notifiable_spec.rb +35 -35
  49. data/spec/concerns/models/target_spec.rb +10 -12
  50. data/spec/concerns/renderable_spec.rb +5 -5
  51. data/spec/config_spec.rb +26 -15
  52. data/spec/controllers/controller_spec_utility.rb +15 -51
  53. data/spec/generators/migration/migration_generator_spec.rb +2 -10
  54. data/spec/helpers/view_helpers_spec.rb +1 -1
  55. data/spec/models/subscription_spec.rb +8 -0
  56. data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
  57. data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
  58. data/spec/rails_app/app/controllers/users_controller.rb +5 -0
  59. data/spec/rails_app/app/javascript/App.vue +8 -72
  60. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +3 -4
  61. data/spec/rails_app/app/javascript/components/Top.vue +2 -3
  62. data/spec/rails_app/app/javascript/packs/spa.js +6 -3
  63. data/spec/rails_app/app/javascript/router/index.js +73 -0
  64. data/spec/rails_app/app/javascript/store/{auth.js → index.js} +0 -0
  65. data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
  66. data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
  67. data/spec/rails_app/app/models/user.rb +2 -1
  68. data/spec/rails_app/config/application.rb +6 -7
  69. data/spec/rails_app/config/dynamoid.rb +11 -3
  70. data/spec/rails_app/config/environments/production.rb +3 -0
  71. data/spec/rails_app/config/environments/test.rb +2 -11
  72. data/spec/rails_app/config/initializers/activity_notification.rb +3 -3
  73. data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
  74. data/spec/rails_app/config/routes.rb +5 -1
  75. data/spec/rails_app/db/seeds.rb +9 -2
  76. data/spec/roles/acts_as_notifiable_spec.rb +5 -5
  77. data/spec/spec_helper.rb +1 -5
  78. metadata +14 -12
  79. data/gemfiles/Gemfile.rails-4.2 +0 -23
  80. data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
@@ -1,50 +1,48 @@
1
- if Rails::VERSION::MAJOR >= 5
2
- require 'channels/notification_channel_shared_examples'
3
-
4
- # @See https://github.com/palkan/action-cable-testing
5
- describe ActivityNotification::NotificationChannel, type: :channel do
6
- let(:test_target) { create(:user) }
7
- let(:target_type) { "User" }
8
- let(:typed_target_param) { "user_id" }
9
- let(:extra_params) { {} }
10
-
11
- context "when target.notification_action_cable_with_devise? returns true" do
12
- before do
13
- @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
14
- User._notification_action_cable_with_devise = true
15
- end
16
-
17
- after do
18
- User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
19
- end
20
-
21
- it "rejects subscription even if target_type and target_id parameters are passed" do
22
- subscribe({ target_type: target_type, target_id: test_target.id })
23
- expect(subscription).to be_rejected
24
- expect {
25
- expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
26
- }.to raise_error(/Must be subscribed!/)
27
- end
1
+ require 'channels/notification_channel_shared_examples'
2
+
3
+ # @See https://github.com/palkan/action-cable-testing
4
+ describe ActivityNotification::NotificationChannel, type: :channel do
5
+ let(:test_target) { create(:user) }
6
+ let(:target_type) { "User" }
7
+ let(:typed_target_param) { "user_id" }
8
+ let(:extra_params) { {} }
9
+
10
+ context "when target.notification_action_cable_with_devise? returns true" do
11
+ before do
12
+ @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
13
+ User._notification_action_cable_with_devise = true
28
14
  end
29
15
 
30
- context "when target.notification_action_cable_with_devise? returns false" do
31
- before do
32
- @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
33
- User._notification_action_cable_with_devise = false
34
- end
35
-
36
- after do
37
- User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
38
- end
16
+ after do
17
+ User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
18
+ end
39
19
 
40
- it "successfully subscribes with target_type and target_id parameters" do
41
- subscribe({ target_type: target_type, target_id: test_target.id })
42
- expect(subscription).to be_confirmed
20
+ it "rejects subscription even if target_type and target_id parameters are passed" do
21
+ subscribe({ target_type: target_type, target_id: test_target.id })
22
+ expect(subscription).to be_rejected
23
+ expect {
43
24
  expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
44
- expect(subscription).to have_stream_from("activity_notification_channel_User##{test_target.id}")
45
- end
25
+ }.to raise_error(/Must be subscribed!/)
26
+ end
27
+ end
46
28
 
47
- it_behaves_like :notification_channel
29
+ context "when target.notification_action_cable_with_devise? returns false" do
30
+ before do
31
+ @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
32
+ User._notification_action_cable_with_devise = false
48
33
  end
34
+
35
+ after do
36
+ User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
37
+ end
38
+
39
+ it "successfully subscribes with target_type and target_id parameters" do
40
+ subscribe({ target_type: target_type, target_id: test_target.id })
41
+ expect(subscription).to be_confirmed
42
+ expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
43
+ expect(subscription).to have_stream_from("activity_notification_channel_User##{test_target.id}")
44
+ end
45
+
46
+ it_behaves_like :notification_channel
49
47
  end
50
- end
48
+ end
@@ -1,99 +1,97 @@
1
- if Rails::VERSION::MAJOR >= 5
2
- require 'channels/notification_channel_shared_examples'
1
+ require 'channels/notification_channel_shared_examples'
3
2
 
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
3
+ #TODO Make it more smart test method
4
+ module ActivityNotification
5
+ module Test
6
+ class NotificationWithDeviseChannel < ::ActivityNotification::NotificationWithDeviseChannel
7
+ @@custom_current_target = nil
8
+
9
+ def set_custom_current_target(custom_current_target)
10
+ @@custom_current_target = custom_current_target
11
+ end
12
+
13
+ def find_current_target(devise_type = nil)
14
+ super(devise_type)
15
+ rescue NoMethodError
16
+ devise_type = (devise_type || @target.notification_devise_resource.class.name).to_s
17
+ @@custom_current_target.is_a?(devise_type.to_model_class) ? @@custom_current_target : nil
20
18
  end
21
19
  end
22
20
  end
21
+ end
23
22
 
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
23
+ # @See https://github.com/palkan/action-cable-testing
24
+ describe ActivityNotification::Test::NotificationWithDeviseChannel, type: :channel do
25
+ let(:test_user) { create(:confirmed_user) }
26
+ let(:unauthenticated_user) { create(:confirmed_user) }
27
+ let(:test_target) { create(:admin, user: test_user) }
28
+ let(:target_type) { "Admin" }
29
+ let(:typed_target_param) { "admin_id" }
30
+ let(:extra_params) { { devise_type: :users } }
31
+ let(:valid_session) {}
39
32
 
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
33
+ #TODO Make it more smart test method
34
+ #include Devise::Test::IntegrationHelpers
35
+ def sign_in(current_target)
36
+ described_class.new(ActionCable::Channel::ConnectionStub.new, {}).set_custom_current_target(current_target)
37
+ end
44
38
 
45
- after do
46
- User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
47
- end
39
+ before do
40
+ @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
41
+ User._notification_action_cable_with_devise = true
42
+ end
48
43
 
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
44
+ after do
45
+ User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
46
+ end
47
+
48
+ context "signed in with devise as authenticated user" do
49
+ before do
50
+ sign_in test_user
55
51
  end
52
+
53
+ it_behaves_like :notification_channel
54
+ end
56
55
 
57
- context "signed in with devise as unauthenticated user" do
58
- let(:target_params) { { target_type: target_type, devise_type: :users } }
56
+ context "signed in with devise as unauthenticated user" do
57
+ let(:target_params) { { target_type: target_type, devise_type: :users } }
59
58
 
60
- before do
61
- sign_in unauthenticated_user
62
- end
59
+ before do
60
+ sign_in unauthenticated_user
61
+ end
63
62
 
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
63
+ it "rejects subscription" do
64
+ subscribe(target_params.merge({ typed_target_param => test_target }))
65
+ expect(subscription).to be_rejected
66
+ expect {
67
+ expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
68
+ }.to raise_error(/Must be subscribed!/)
71
69
  end
70
+ end
72
71
 
73
- context "unsigned in with devise" do
74
- let(:target_params) { { target_type: target_type, devise_type: :users } }
72
+ context "unsigned in with devise" do
73
+ let(:target_params) { { target_type: target_type, devise_type: :users } }
75
74
 
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
75
+ it "rejects subscription" do
76
+ subscribe(target_params.merge({ typed_target_param => test_target }))
77
+ expect(subscription).to be_rejected
78
+ expect {
79
+ expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
80
+ }.to raise_error(/Must be subscribed!/)
83
81
  end
82
+ end
84
83
 
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 } }
84
+ context "without target_id and (typed_target)_id parameters for devise integrated channel with devise_type option" do
85
+ let(:target_params) { { target_type: target_type, devise_type: :users } }
87
86
 
88
- before do
89
- sign_in test_target.user
90
- end
87
+ before do
88
+ sign_in test_target.user
89
+ end
91
90
 
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
91
+ it "successfully subscribes" do
92
+ subscribe(target_params)
93
+ expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
94
+ expect(subscription).to have_stream_from("activity_notification_channel_Admin##{test_target.id}")
97
95
  end
98
96
  end
99
97
  end
@@ -34,7 +34,7 @@ shared_examples_for :common do
34
34
  test_instance.extend(AdditionalMethods)
35
35
  expect(ActivityNotification.resolve_value(test_instance, :custom_method)).to eq(1)
36
36
  end
37
-
37
+
38
38
  it "returns specified symbol with controller and additional arguments" do
39
39
  module AdditionalMethods
40
40
  def custom_method(controller, key)
@@ -45,6 +45,17 @@ shared_examples_for :common do
45
45
  expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test1.key')).to eq(1)
46
46
  expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test2.key')).to eq(0)
47
47
  end
48
+
49
+ it "returns specified symbol with controller and additional arguments including hash as last argument" do
50
+ module AdditionalMethods
51
+ def custom_method(controller, key, options:)
52
+ controller == 'StubController' and key == 'test1.key' ? 1 : 0
53
+ end
54
+ end
55
+ test_instance.extend(AdditionalMethods)
56
+ expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test1.key', options: 1)).to eq(1)
57
+ expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test2.key', options: 1)).to eq(0)
58
+ end
48
59
  end
49
60
 
50
61
  context "with Proc" do
@@ -62,7 +73,7 @@ shared_examples_for :common do
62
73
  test_proc = ->(controller, model){ controller == 'StubController' and model == test_instance ? 1 : 0 }
63
74
  expect(ActivityNotification.resolve_value(test_instance, test_proc)).to eq(1)
64
75
  end
65
-
76
+
66
77
  it "returns specified lambda with controller, context(model) and additional arguments" do
67
78
  test_proc = ->(controller, model, key){ controller == 'StubController' and model == test_instance and key == 'test1.key' ? 1 : 0 }
68
79
  expect(ActivityNotification.resolve_value(test_instance, test_proc, 'test1.key')).to eq(1)
@@ -118,6 +129,17 @@ shared_examples_for :common do
118
129
  expect(test_instance.resolve_value(:custom_method, 'test1.key')).to eq(1)
119
130
  expect(test_instance.resolve_value(:custom_method, 'test2.key')).to eq(0)
120
131
  end
132
+
133
+ it "returns specified symbol with additional arguments including hash as last argument" do
134
+ module AdditionalMethods
135
+ def custom_method(key, options:)
136
+ key == 'test1.key' ? 1 : 0
137
+ end
138
+ end
139
+ test_instance.extend(AdditionalMethods)
140
+ expect(test_instance.resolve_value(:custom_method, 'test1.key', options: 1)).to eq(1)
141
+ expect(test_instance.resolve_value(:custom_method, 'test2.key', options: 1)).to eq(0)
142
+ end
121
143
  end
122
144
 
123
145
  context "with Proc" do
@@ -188,4 +210,4 @@ shared_examples_for :common do
188
210
  end
189
211
  end
190
212
 
191
- end
213
+ end
@@ -21,7 +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
+ expect(described_class._notifiable_action_cable_allowed).to eq({})
25
25
  expect(described_class._notifiable_path).to eq({})
26
26
  expect(described_class._printable_notifiable_name).to eq({})
27
27
  end
@@ -410,130 +410,130 @@ shared_examples_for :notifiable do
410
410
  end
411
411
  end
412
412
 
413
- describe "#notification_action_cable_allowed?" do
413
+ describe "#notifiable_action_cable_allowed?" do
414
414
  context "without any configuration" do
415
415
  it "returns ActivityNotification.config.action_cable_enabled" do
416
- expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key'))
416
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key'))
417
417
  .to eq(ActivityNotification.config.action_cable_enabled)
418
418
  end
419
419
 
420
420
  it "returns false as default" do
421
- expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to be_falsey
421
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to be_falsey
422
422
  end
423
423
  end
424
424
 
425
425
  context "configured with overridden method" do
426
426
  it "returns specified value" do
427
427
  module AdditionalMethods
428
- def notification_action_cable_allowed_for_users?(target, key)
428
+ def notifiable_action_cable_allowed_for_users?(target, key)
429
429
  true
430
430
  end
431
431
  end
432
432
  test_instance.extend(AdditionalMethods)
433
- expect(test_instance.notification_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
433
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
434
434
  end
435
435
  end
436
436
 
437
437
  context "configured with a field" do
438
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)
439
+ described_class._notifiable_action_cable_allowed[:users] = true
440
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
441
441
  end
442
442
 
443
443
  it "returns specified symbol without arguments" do
444
444
  module AdditionalMethods
445
- def custom_notification_action_cable_allowed?
445
+ def custom_notifiable_action_cable_allowed?
446
446
  true
447
447
  end
448
448
  end
449
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)
450
+ described_class._notifiable_action_cable_allowed[:users] = :custom_notifiable_action_cable_allowed?
451
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
452
452
  end
453
453
 
454
454
  it "returns specified symbol with target and key arguments" do
455
455
  module AdditionalMethods
456
- def custom_notification_action_cable_allowed?(target, key)
456
+ def custom_notifiable_action_cable_allowed?(target, key)
457
457
  true
458
458
  end
459
459
  end
460
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)
461
+ described_class._notifiable_action_cable_allowed[:users] = :custom_notifiable_action_cable_allowed?
462
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
463
463
  end
464
464
 
465
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)
466
+ described_class._notifiable_action_cable_allowed[:users] = ->(notifiable){ true }
467
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
468
468
  end
469
469
 
470
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)
471
+ described_class._notifiable_action_cable_allowed[:users] = ->(notifiable, target, key){ true }
472
+ expect(test_instance.notifiable_action_cable_allowed?(test_target, 'dummy_key')).to eq(true)
473
473
  end
474
474
  end
475
475
  end
476
476
 
477
- describe "#notification_action_cable_api_allowed?" do
477
+ describe "#notifiable_action_cable_api_allowed?" do
478
478
  context "without any configuration" do
479
479
  it "returns ActivityNotification.config.action_cable_api_enabled" do
480
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key'))
480
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key'))
481
481
  .to eq(ActivityNotification.config.action_cable_api_enabled)
482
482
  end
483
483
 
484
484
  it "returns false as default" do
485
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to be_falsey
485
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to be_falsey
486
486
  end
487
487
  end
488
488
 
489
489
  context "configured with overridden method" do
490
490
  it "returns specified value" do
491
491
  module AdditionalMethods
492
- def notification_action_cable_api_allowed_for_users?(target, key)
492
+ def notifiable_action_cable_api_allowed_for_users?(target, key)
493
493
  true
494
494
  end
495
495
  end
496
496
  test_instance.extend(AdditionalMethods)
497
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
497
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
498
498
  end
499
499
  end
500
500
 
501
501
  context "configured with a field" do
502
502
  it "returns specified value" do
503
- described_class._notification_action_cable_api_allowed[:users] = true
504
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
503
+ described_class._notifiable_action_cable_api_allowed[:users] = true
504
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
505
505
  end
506
506
 
507
507
  it "returns specified symbol without arguments" do
508
508
  module AdditionalMethods
509
- def custom_notification_action_cable_api_allowed?
509
+ def custom_notifiable_action_cable_api_allowed?
510
510
  true
511
511
  end
512
512
  end
513
513
  test_instance.extend(AdditionalMethods)
514
- described_class._notification_action_cable_api_allowed[:users] = :custom_notification_action_cable_api_allowed?
515
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
514
+ described_class._notifiable_action_cable_api_allowed[:users] = :custom_notifiable_action_cable_api_allowed?
515
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
516
516
  end
517
517
 
518
518
  it "returns specified symbol with target and key arguments" do
519
519
  module AdditionalMethods
520
- def custom_notification_action_cable_api_allowed?(target, key)
520
+ def custom_notifiable_action_cable_api_allowed?(target, key)
521
521
  true
522
522
  end
523
523
  end
524
524
  test_instance.extend(AdditionalMethods)
525
- described_class._notification_action_cable_api_allowed[:users] = :custom_notification_action_cable_api_allowed?
526
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
525
+ described_class._notifiable_action_cable_api_allowed[:users] = :custom_notifiable_action_cable_api_allowed?
526
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
527
527
  end
528
528
 
529
529
  it "returns specified lambda with single notifiable argument" do
530
- described_class._notification_action_cable_api_allowed[:users] = ->(notifiable){ true }
531
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
530
+ described_class._notifiable_action_cable_api_allowed[:users] = ->(notifiable){ true }
531
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
532
532
  end
533
533
 
534
534
  it "returns specified lambda with notifiable, target and key arguments" do
535
- described_class._notification_action_cable_api_allowed[:users] = ->(notifiable, target, key){ true }
536
- expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
535
+ described_class._notifiable_action_cable_api_allowed[:users] = ->(notifiable, target, key){ true }
536
+ expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
537
537
  end
538
538
  end
539
539
  end