activity_notification 2.1.4 → 2.2.3
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 +4 -4
- data/.github/workflows/build.yml +120 -0
- data/CHANGELOG.md +38 -0
- data/README.md +2 -2
- data/activity_notification.gemspec +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +0 -20
- data/app/controllers/activity_notification/subscriptions_controller.rb +2 -2
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/index.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/show.html.erb +2 -2
- data/bin/bundle_update.sh +0 -1
- data/docs/Functions.md +17 -1
- data/gemfiles/{Gemfile.rails-4.2 → Gemfile.rails-6.1} +2 -4
- data/gemfiles/Gemfile.rails-7.0 +28 -0
- data/lib/activity_notification/apis/notification_api.rb +5 -1
- data/lib/activity_notification/apis/subscription_api.rb +5 -5
- data/lib/activity_notification/common.rb +11 -3
- data/lib/activity_notification/config.rb +63 -23
- data/lib/activity_notification/controllers/common_controller.rb +1 -17
- data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
- data/lib/activity_notification/models/concerns/subscriber.rb +6 -4
- data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +16 -16
- data/lib/activity_notification/models/concerns/target.rb +8 -12
- data/lib/activity_notification/orm/active_record/notification.rb +3 -3
- data/lib/activity_notification/orm/active_record.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
- data/lib/activity_notification/orm/mongoid/notification.rb +1 -1
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/renderable.rb +2 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +11 -15
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +15 -1
- data/lib/generators/templates/migrations/migration.rb +1 -1
- data/spec/channels/notification_api_channel_spec.rb +42 -44
- data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
- data/spec/channels/notification_channel_spec.rb +41 -43
- data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
- data/spec/concerns/apis/notification_api_spec.rb +26 -3
- data/spec/concerns/apis/subscription_api_spec.rb +144 -2
- data/spec/concerns/common_spec.rb +25 -3
- data/spec/concerns/models/subscriber_spec.rb +179 -6
- data/spec/concerns/models/target_spec.rb +10 -12
- data/spec/concerns/renderable_spec.rb +5 -5
- data/spec/controllers/controller_spec_utility.rb +15 -51
- data/spec/generators/migration/migration_generator_spec.rb +2 -10
- data/spec/helpers/view_helpers_spec.rb +1 -1
- data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
- data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
- data/spec/rails_app/config/application.rb +2 -6
- data/spec/rails_app/config/database.yml +1 -1
- data/spec/rails_app/config/environments/test.rb +2 -11
- data/spec/rails_app/config/initializers/activity_notification.rb +14 -0
- data/spec/rails_app/package.json +14 -14
- data/spec/spec_helper.rb +1 -5
- metadata +13 -14
- data/.travis.yml +0 -76
- data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
|
@@ -1,50 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
25
|
+
}.to raise_error(/Must be subscribed!/)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
46
28
|
|
|
47
|
-
|
|
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
|
-
|
|
2
|
-
require 'channels/notification_channel_shared_examples'
|
|
1
|
+
require 'channels/notification_channel_shared_examples'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
56
|
+
context "signed in with devise as unauthenticated user" do
|
|
57
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
before do
|
|
60
|
+
sign_in unauthenticated_user
|
|
61
|
+
end
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
72
|
+
context "unsigned in with devise" do
|
|
73
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
before do
|
|
88
|
+
sign_in test_target.user
|
|
89
|
+
end
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
@@ -136,9 +136,32 @@ shared_examples_for :notification_api do
|
|
|
136
136
|
Comment._optional_targets[:users] = @current_optional_target
|
|
137
137
|
end
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
notifications
|
|
141
|
-
|
|
139
|
+
context "with true as ActivityNotification.config.rescue_optional_target_errors" do
|
|
140
|
+
it "generates notifications even if some optional targets raise error" do
|
|
141
|
+
rescue_optional_target_errors = ActivityNotification.config.rescue_optional_target_errors
|
|
142
|
+
ActivityNotification.config.rescue_optional_target_errors = true
|
|
143
|
+
notifications = described_class.notify(:users, @comment_2)
|
|
144
|
+
expect(notifications.size).to eq(2)
|
|
145
|
+
ActivityNotification.config.rescue_optional_target_errors = rescue_optional_target_errors
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
context "with false as ActivityNotification.config.rescue_optional_target_errors" do
|
|
150
|
+
it "raises an capturable exception" do
|
|
151
|
+
rescue_optional_target_errors = ActivityNotification.config.rescue_optional_target_errors
|
|
152
|
+
ActivityNotification.config.rescue_optional_target_errors = false
|
|
153
|
+
expect { described_class.notify(:users, @comment_2) }.to raise_error(RuntimeError)
|
|
154
|
+
ActivityNotification.config.rescue_optional_target_errors = rescue_optional_target_errors
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "allows an exception to be captured to continue" do
|
|
159
|
+
begin
|
|
160
|
+
notifications = described_class.notify(:users, @comment_2)
|
|
161
|
+
expect(notifications.size).to eq(2)
|
|
162
|
+
rescue => e
|
|
163
|
+
next
|
|
164
|
+
end
|
|
142
165
|
end
|
|
143
166
|
end
|
|
144
167
|
end
|
|
@@ -45,6 +45,41 @@ shared_examples_for :subscription_api do
|
|
|
45
45
|
expect(test_instance.subscribed_to_email_at).to eq(Time.current)
|
|
46
46
|
Timecop.return
|
|
47
47
|
end
|
|
48
|
+
|
|
49
|
+
context "with true as ActivityNotification.config.subscribe_to_email_as_default" do
|
|
50
|
+
it "subscribe with current time" do
|
|
51
|
+
ActivityNotification.config.subscribe_to_email_as_default = true
|
|
52
|
+
|
|
53
|
+
expect(test_instance.subscribing?).to eq(false)
|
|
54
|
+
expect(test_instance.subscribing_to_email?).to eq(false)
|
|
55
|
+
Timecop.freeze(Time.at(Time.now.to_i))
|
|
56
|
+
test_instance.subscribe
|
|
57
|
+
expect(test_instance.subscribing?).to eq(true)
|
|
58
|
+
expect(test_instance.subscribing_to_email?).to eq(true)
|
|
59
|
+
expect(test_instance.subscribed_at).to eq(Time.current)
|
|
60
|
+
expect(test_instance.subscribed_to_email_at).to eq(Time.current)
|
|
61
|
+
Timecop.return
|
|
62
|
+
|
|
63
|
+
ActivityNotification.config.subscribe_to_email_as_default = nil
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "with false as ActivityNotification.config.subscribe_to_email_as_default" do
|
|
68
|
+
it "subscribe with current time" do
|
|
69
|
+
ActivityNotification.config.subscribe_to_email_as_default = false
|
|
70
|
+
|
|
71
|
+
expect(test_instance.subscribing?).to eq(false)
|
|
72
|
+
expect(test_instance.subscribing_to_email?).to eq(false)
|
|
73
|
+
Timecop.freeze(Time.at(Time.now.to_i))
|
|
74
|
+
test_instance.subscribe
|
|
75
|
+
expect(test_instance.subscribing?).to eq(true)
|
|
76
|
+
expect(test_instance.subscribing_to_email?).to eq(false)
|
|
77
|
+
expect(test_instance.subscribed_at).to eq(Time.current)
|
|
78
|
+
Timecop.return
|
|
79
|
+
|
|
80
|
+
ActivityNotification.config.subscribe_to_email_as_default = nil
|
|
81
|
+
end
|
|
82
|
+
end
|
|
48
83
|
end
|
|
49
84
|
|
|
50
85
|
context "with subscribed_at option" do
|
|
@@ -58,6 +93,39 @@ shared_examples_for :subscription_api do
|
|
|
58
93
|
expect(test_instance.subscribed_at.to_i).to eq(subscribed_at.to_i)
|
|
59
94
|
expect(test_instance.subscribed_to_email_at.to_i).to eq(subscribed_at.to_i)
|
|
60
95
|
end
|
|
96
|
+
|
|
97
|
+
context "with true as ActivityNotification.config.subscribe_to_email_as_default" do
|
|
98
|
+
it "subscribe with current time" do
|
|
99
|
+
ActivityNotification.config.subscribe_to_email_as_default = true
|
|
100
|
+
|
|
101
|
+
expect(test_instance.subscribing?).to eq(false)
|
|
102
|
+
expect(test_instance.subscribing_to_email?).to eq(false)
|
|
103
|
+
subscribed_at = Time.current - 1.months
|
|
104
|
+
test_instance.subscribe(subscribed_at: subscribed_at)
|
|
105
|
+
expect(test_instance.subscribing?).to eq(true)
|
|
106
|
+
expect(test_instance.subscribing_to_email?).to eq(true)
|
|
107
|
+
expect(test_instance.subscribed_at.to_i).to eq(subscribed_at.to_i)
|
|
108
|
+
expect(test_instance.subscribed_to_email_at.to_i).to eq(subscribed_at.to_i)
|
|
109
|
+
|
|
110
|
+
ActivityNotification.config.subscribe_to_email_as_default = nil
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "with false as ActivityNotification.config.subscribe_to_email_as_default" do
|
|
115
|
+
it "subscribe with current time" do
|
|
116
|
+
ActivityNotification.config.subscribe_to_email_as_default = false
|
|
117
|
+
|
|
118
|
+
expect(test_instance.subscribing?).to eq(false)
|
|
119
|
+
expect(test_instance.subscribing_to_email?).to eq(false)
|
|
120
|
+
subscribed_at = Time.current - 1.months
|
|
121
|
+
test_instance.subscribe(subscribed_at: subscribed_at)
|
|
122
|
+
expect(test_instance.subscribing?).to eq(true)
|
|
123
|
+
expect(test_instance.subscribing_to_email?).to eq(false)
|
|
124
|
+
expect(test_instance.subscribed_at.to_i).to eq(subscribed_at.to_i)
|
|
125
|
+
|
|
126
|
+
ActivityNotification.config.subscribe_to_email_as_default = nil
|
|
127
|
+
end
|
|
128
|
+
end
|
|
61
129
|
end
|
|
62
130
|
|
|
63
131
|
context "with false as with_email_subscription" do
|
|
@@ -79,6 +147,36 @@ shared_examples_for :subscription_api do
|
|
|
79
147
|
expect(test_instance.subscribing?).to eq(true)
|
|
80
148
|
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(true)
|
|
81
149
|
end
|
|
150
|
+
|
|
151
|
+
context "with true as ActivityNotification.config.subscribe_to_optional_targets_as_default" do
|
|
152
|
+
it "also subscribes to optional targets" do
|
|
153
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = true
|
|
154
|
+
|
|
155
|
+
test_instance.unsubscribe_to_optional_target(:console_output)
|
|
156
|
+
expect(test_instance.subscribing?).to eq(false)
|
|
157
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(false)
|
|
158
|
+
test_instance.subscribe
|
|
159
|
+
expect(test_instance.subscribing?).to eq(true)
|
|
160
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(true)
|
|
161
|
+
|
|
162
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = nil
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "with false as ActivityNotification.config.subscribe_to_optional_targets_as_default" do
|
|
167
|
+
it "does not subscribe to optional targets" do
|
|
168
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = false
|
|
169
|
+
|
|
170
|
+
test_instance.unsubscribe_to_optional_target(:console_output)
|
|
171
|
+
expect(test_instance.subscribing?).to eq(false)
|
|
172
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(false)
|
|
173
|
+
test_instance.subscribe
|
|
174
|
+
expect(test_instance.subscribing?).to eq(true)
|
|
175
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to eq(false)
|
|
176
|
+
|
|
177
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = nil
|
|
178
|
+
end
|
|
179
|
+
end
|
|
82
180
|
end
|
|
83
181
|
|
|
84
182
|
context "with false as with_optional_targets" do
|
|
@@ -210,7 +308,7 @@ shared_examples_for :subscription_api do
|
|
|
210
308
|
test_instance.update(optional_targets: {})
|
|
211
309
|
end
|
|
212
310
|
|
|
213
|
-
context "without configured optional target
|
|
311
|
+
context "without configured optional target subscription" do
|
|
214
312
|
context "without subscribe_as_default argument" do
|
|
215
313
|
context "with true as ActivityNotification.config.subscribe_as_default" do
|
|
216
314
|
it "returns true" do
|
|
@@ -219,6 +317,28 @@ shared_examples_for :subscription_api do
|
|
|
219
317
|
expect(test_instance.subscribing_to_optional_target?(:console_output)).to be_truthy
|
|
220
318
|
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
|
221
319
|
end
|
|
320
|
+
|
|
321
|
+
context "with true as ActivityNotification.config.subscribe_to_optional_targets_as_default" do
|
|
322
|
+
it "returns true" do
|
|
323
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
|
324
|
+
ActivityNotification.config.subscribe_as_default = true
|
|
325
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = true
|
|
326
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to be_truthy
|
|
327
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
|
328
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = nil
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
context "with false as ActivityNotification.config.subscribe_to_optional_targets_as_default" do
|
|
333
|
+
it "returns false" do
|
|
334
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
|
335
|
+
ActivityNotification.config.subscribe_as_default = true
|
|
336
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = false
|
|
337
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to be_falsey
|
|
338
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
|
339
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = nil
|
|
340
|
+
end
|
|
341
|
+
end
|
|
222
342
|
end
|
|
223
343
|
|
|
224
344
|
context "with false as ActivityNotification.config.subscribe_as_default" do
|
|
@@ -228,11 +348,33 @@ shared_examples_for :subscription_api do
|
|
|
228
348
|
expect(test_instance.subscribing_to_optional_target?(:console_output)).to be_falsey
|
|
229
349
|
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
|
230
350
|
end
|
|
351
|
+
|
|
352
|
+
context "with true as ActivityNotification.config.subscribe_to_optional_targets_as_default" do
|
|
353
|
+
it "returns false" do
|
|
354
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
|
355
|
+
ActivityNotification.config.subscribe_as_default = false
|
|
356
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = true
|
|
357
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to be_falsey
|
|
358
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
|
359
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = nil
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
context "with false as ActivityNotification.config.subscribe_to_optional_targets_as_default" do
|
|
364
|
+
it "returns false" do
|
|
365
|
+
subscribe_as_default = ActivityNotification.config.subscribe_as_default
|
|
366
|
+
ActivityNotification.config.subscribe_as_default = false
|
|
367
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = false
|
|
368
|
+
expect(test_instance.subscribing_to_optional_target?(:console_output)).to be_falsey
|
|
369
|
+
ActivityNotification.config.subscribe_as_default = subscribe_as_default
|
|
370
|
+
ActivityNotification.config.subscribe_to_optional_targets_as_default = nil
|
|
371
|
+
end
|
|
372
|
+
end
|
|
231
373
|
end
|
|
232
374
|
end
|
|
233
375
|
end
|
|
234
376
|
|
|
235
|
-
context "with configured
|
|
377
|
+
context "with configured subscription" do
|
|
236
378
|
context "subscribing to optional target" do
|
|
237
379
|
it "returns true" do
|
|
238
380
|
test_instance.subscribe_to_optional_target(:console_output)
|
|
@@ -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
|