activity_notification 2.0.0 → 2.1.4
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/ISSUE_TEMPLATE/bug_report.md +22 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/.github/pull_request_template.md +13 -0
- data/.gitignore +10 -3
- data/.travis.yml +6 -5
- data/CHANGELOG.md +60 -0
- data/Gemfile +8 -3
- data/Procfile +1 -1
- data/README.md +153 -1510
- data/activity_notification.gemspec +4 -1
- data/app/channels/activity_notification/notification_api_channel.rb +12 -0
- data/app/channels/activity_notification/notification_api_with_devise_channel.rb +46 -0
- data/app/channels/activity_notification/notification_channel.rb +2 -2
- data/app/channels/activity_notification/notification_with_devise_channel.rb +2 -2
- data/app/controllers/activity_notification/apidocs_controller.rb +75 -0
- data/app/controllers/activity_notification/notifications_api_controller.rb +143 -0
- data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +7 -0
- data/app/controllers/activity_notification/notifications_controller.rb +79 -53
- data/app/controllers/activity_notification/subscriptions_api_controller.rb +197 -0
- data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +7 -0
- data/app/controllers/activity_notification/subscriptions_controller.rb +78 -69
- data/app/views/activity_notification/notifications/default/_default.html.erb +18 -18
- data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +14 -14
- data/app/views/activity_notification/notifications/default/index.html.erb +6 -6
- data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +3 -31
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +7 -7
- data/app/views/activity_notification/subscriptions/default/index.html.erb +11 -7
- data/bin/deploy_on_heroku.sh +3 -1
- data/docs/CODE_OF_CONDUCT.md +76 -0
- data/docs/CONTRIBUTING.md +36 -0
- data/docs/Functions.md +1130 -0
- data/docs/Setup.md +801 -0
- data/docs/Testing.md +148 -0
- data/gemfiles/Gemfile.rails-4.2 +5 -1
- data/gemfiles/Gemfile.rails-5.0 +6 -1
- data/gemfiles/Gemfile.rails-5.1 +6 -1
- data/gemfiles/Gemfile.rails-5.2 +6 -1
- data/gemfiles/{Gemfile.rails-6.0.rc → Gemfile.rails-6.0} +6 -5
- data/lib/activity_notification.rb +13 -0
- data/lib/activity_notification/apis/notification_api.rb +37 -93
- data/lib/activity_notification/apis/subscription_api.rb +20 -8
- data/lib/activity_notification/apis/swagger.rb +6 -0
- data/lib/activity_notification/common.rb +4 -1
- data/lib/activity_notification/config.rb +41 -21
- data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
- data/lib/activity_notification/controllers/common_controller.rb +45 -21
- data/lib/activity_notification/controllers/concerns/swagger/error_responses.rb +55 -0
- data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +273 -0
- data/lib/activity_notification/controllers/concerns/swagger/notifications_parameters.rb +92 -0
- data/lib/activity_notification/controllers/concerns/swagger/subscriptions_api.rb +405 -0
- data/lib/activity_notification/controllers/concerns/swagger/subscriptions_parameters.rb +50 -0
- data/lib/activity_notification/controllers/devise_authentication_controller.rb +7 -6
- data/lib/activity_notification/gem_version.rb +14 -0
- data/lib/activity_notification/helpers/errors.rb +2 -0
- data/lib/activity_notification/helpers/view_helpers.rb +4 -0
- data/lib/activity_notification/mailers/helpers.rb +17 -10
- data/lib/activity_notification/models/concerns/notifiable.rb +31 -15
- data/lib/activity_notification/models/concerns/subscriber.rb +12 -1
- data/lib/activity_notification/models/concerns/swagger/error_schema.rb +36 -0
- data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +209 -0
- data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +162 -0
- data/lib/activity_notification/models/concerns/target.rb +36 -10
- data/lib/activity_notification/models/notification.rb +1 -0
- data/lib/activity_notification/models/subscription.rb +1 -0
- data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +69 -0
- data/lib/activity_notification/optional_targets/action_cable_channel.rb +68 -0
- data/lib/activity_notification/optional_targets/base.rb +7 -13
- data/lib/activity_notification/orm/active_record/notification.rb +17 -1
- data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
- data/lib/activity_notification/orm/dynamoid.rb +38 -3
- data/lib/activity_notification/orm/dynamoid/extension.rb +79 -1
- data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
- data/lib/activity_notification/orm/dynamoid/subscription.rb +2 -2
- data/lib/activity_notification/orm/mongoid.rb +32 -3
- data/lib/activity_notification/orm/mongoid/notification.rb +24 -6
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/rails/routes.rb +132 -48
- data/lib/activity_notification/renderable.rb +13 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +39 -20
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/controllers_generator.rb +2 -1
- data/lib/generators/templates/activity_notification.rb +8 -0
- data/lib/generators/templates/controllers/notifications_api_controller.rb +31 -0
- data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +31 -0
- data/lib/generators/templates/controllers/notifications_controller.rb +1 -37
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +1 -45
- data/lib/generators/templates/controllers/subscriptions_api_controller.rb +61 -0
- data/lib/generators/templates/controllers/subscriptions_api_with_devise_controller.rb +61 -0
- data/lib/generators/templates/controllers/subscriptions_controller.rb +14 -37
- data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +14 -45
- data/lib/generators/templates/models/README +8 -4
- data/lib/generators/templates/models/notification.rb +1 -1
- data/lib/generators/templates/models/subscription.rb +1 -1
- data/package.json +8 -0
- data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_api_channel_spec.rb +51 -0
- data/spec/channels/notification_api_with_devise_channel_spec.rb +78 -0
- data/spec/concerns/apis/notification_api_spec.rb +38 -3
- data/spec/concerns/models/notifiable_spec.rb +82 -18
- data/spec/concerns/models/subscriber_spec.rb +13 -16
- data/spec/concerns/models/target_spec.rb +32 -0
- data/spec/concerns/renderable_spec.rb +2 -2
- data/spec/config_spec.rb +26 -15
- data/spec/controllers/controller_spec_utility.rb +136 -0
- data/spec/controllers/notifications_api_controller_shared_examples.rb +506 -0
- data/spec/controllers/notifications_api_controller_spec.rb +19 -0
- data/spec/controllers/notifications_api_with_devise_controller_spec.rb +60 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +54 -79
- data/spec/controllers/notifications_controller_spec.rb +1 -2
- data/spec/controllers/notifications_with_devise_controller_spec.rb +3 -12
- data/spec/controllers/subscriptions_api_controller_shared_examples.rb +750 -0
- data/spec/controllers/subscriptions_api_controller_spec.rb +19 -0
- data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +60 -0
- data/spec/controllers/subscriptions_controller_shared_examples.rb +94 -121
- data/spec/controllers/subscriptions_controller_spec.rb +1 -2
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +3 -12
- data/spec/helpers/view_helpers_spec.rb +4 -11
- data/spec/mailers/mailer_spec.rb +41 -0
- data/spec/models/notification_spec.rb +17 -0
- data/spec/models/subscription_spec.rb +8 -13
- data/spec/optional_targets/action_cable_api_channel_spec.rb +37 -0
- data/spec/optional_targets/action_cable_channel_spec.rb +44 -0
- data/spec/optional_targets/amazon_sns_spec.rb +0 -2
- data/spec/optional_targets/slack_spec.rb +0 -2
- data/spec/rails_app/Rakefile +9 -0
- data/spec/rails_app/app/assets/config/manifest.js +3 -0
- data/spec/rails_app/app/assets/images/.keep +0 -0
- data/spec/rails_app/app/controllers/admins_controller.rb +21 -0
- data/spec/rails_app/app/controllers/application_controller.rb +1 -1
- data/spec/rails_app/app/controllers/articles_controller.rb +6 -3
- data/spec/rails_app/app/controllers/spa_controller.rb +7 -0
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -65
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -73
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -77
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -85
- data/spec/rails_app/app/controllers/users_controller.rb +26 -0
- data/spec/rails_app/app/javascript/App.vue +40 -0
- data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +82 -0
- data/spec/rails_app/app/javascript/components/Top.vue +98 -0
- data/spec/rails_app/app/javascript/components/notifications/Index.vue +200 -0
- data/spec/rails_app/app/javascript/components/notifications/Notification.vue +133 -0
- data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +122 -0
- data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +279 -0
- data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +112 -0
- data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +141 -0
- data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +226 -0
- data/spec/rails_app/app/javascript/config/development.js +5 -0
- data/spec/rails_app/app/javascript/config/environment.js +7 -0
- data/spec/rails_app/app/javascript/config/production.js +5 -0
- data/spec/rails_app/app/javascript/config/test.js +5 -0
- data/spec/rails_app/app/javascript/packs/application.js +18 -0
- data/spec/rails_app/app/javascript/packs/spa.js +14 -0
- data/spec/rails_app/app/javascript/router/index.js +73 -0
- data/spec/rails_app/app/javascript/store/index.js +37 -0
- data/spec/rails_app/app/models/admin.rb +16 -15
- data/spec/rails_app/app/models/article.rb +26 -21
- data/spec/rails_app/app/models/comment.rb +24 -71
- data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
- data/spec/rails_app/app/models/user.rb +44 -20
- data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
- data/spec/rails_app/app/views/articles/index.html.erb +51 -7
- data/spec/rails_app/app/views/articles/show.html.erb +1 -1
- data/spec/rails_app/app/views/layouts/_header.html.erb +8 -10
- data/spec/rails_app/app/views/spa/index.html.erb +2 -0
- data/spec/rails_app/babel.config.js +72 -0
- data/spec/rails_app/bin/webpack +18 -0
- data/spec/rails_app/bin/webpack-dev-server +18 -0
- data/spec/rails_app/config/application.rb +18 -2
- data/spec/rails_app/config/dynamoid.rb +11 -3
- data/spec/rails_app/config/environment.rb +2 -1
- data/spec/rails_app/config/environments/development.rb +5 -0
- data/spec/rails_app/config/environments/production.rb +6 -0
- data/spec/rails_app/config/environments/test.rb +5 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +11 -3
- data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
- data/spec/rails_app/config/initializers/devise_token_auth.rb +55 -0
- data/spec/rails_app/config/initializers/mysql.rb +9 -0
- data/spec/rails_app/config/locales/activity_notification.en.yml +2 -2
- data/spec/rails_app/config/routes.rb +37 -1
- data/spec/rails_app/config/webpack/development.js +5 -0
- data/spec/rails_app/config/webpack/environment.js +7 -0
- data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
- data/spec/rails_app/config/webpack/production.js +5 -0
- data/spec/rails_app/config/webpack/test.js +5 -0
- data/spec/rails_app/config/webpacker.yml +97 -0
- data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
- data/spec/rails_app/db/schema.rb +4 -1
- data/spec/rails_app/db/seeds.rb +10 -2
- data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
- data/spec/rails_app/package.json +23 -0
- data/spec/rails_app/postcss.config.js +12 -0
- data/spec/roles/acts_as_group_spec.rb +0 -2
- data/spec/roles/acts_as_notifiable_spec.rb +6 -8
- data/spec/roles/acts_as_notifier_spec.rb +0 -2
- data/spec/roles/acts_as_target_spec.rb +0 -4
- data/spec/spec_helper.rb +7 -15
- data/spec/version_spec.rb +31 -0
- metadata +191 -13
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
===============================================================================
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
activity_notification uses internal models for notifications and subscriptions
|
|
4
|
+
- ActivityNotification::Notification
|
|
5
|
+
- ActivityNotification::Subscription
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
For example:
|
|
7
|
+
You can use your own models with same database table used by these internal models.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
Ensure you have configured table name in your initializer activity_notification.rb.
|
|
10
|
+
For example:
|
|
11
|
+
config.notification_table_name = "notifications"
|
|
12
|
+
config.subscription_table_name = "subscriptions"
|
|
9
13
|
|
|
10
14
|
===============================================================================
|
data/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @See https://github.com/palkan/action-cable-testing
|
|
2
|
+
shared_examples_for :notification_api_channel do
|
|
3
|
+
let(:target_params) { { target_type: target_type }.merge(extra_params || {}) }
|
|
4
|
+
|
|
5
|
+
before { stub_connection }
|
|
6
|
+
|
|
7
|
+
context "with target_type and target_id parameters" do
|
|
8
|
+
it "successfully subscribes" do
|
|
9
|
+
subscribe(target_params.merge({ target_id: test_target.id, typed_target_param => 'dummy' }).merge(@auth_headers))
|
|
10
|
+
expect(subscription).to be_confirmed
|
|
11
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "with target_type and (typed_target)_id parameters" do
|
|
16
|
+
it "successfully subscribes" do
|
|
17
|
+
subscribe(target_params.merge({ typed_target_param => test_target.id }).merge(@auth_headers))
|
|
18
|
+
expect(subscription).to be_confirmed
|
|
19
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "without any parameters" do
|
|
24
|
+
it "rejects subscription" do
|
|
25
|
+
subscribe(@auth_headers)
|
|
26
|
+
expect(subscription).to be_rejected
|
|
27
|
+
expect {
|
|
28
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
29
|
+
}.to raise_error(/Must be subscribed!/)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "without target_type parameter" do
|
|
34
|
+
it "rejects subscription" do
|
|
35
|
+
subscribe({ typed_target_param => test_target.id }.merge(@auth_headers))
|
|
36
|
+
expect(subscription).to be_rejected
|
|
37
|
+
expect {
|
|
38
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
39
|
+
}.to raise_error(/Must be subscribed!/)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "without target_id and (typed_target)_id parameters" do
|
|
44
|
+
it "rejects subscription" do
|
|
45
|
+
subscribe(target_params.merge(@auth_headers))
|
|
46
|
+
expect(subscription).to be_rejected
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "with not found (typed_target)_id parameter" do
|
|
51
|
+
it "rejects subscription" do
|
|
52
|
+
subscribe(target_params.merge({ typed_target_param => 0 }).merge(@auth_headers))
|
|
53
|
+
expect(subscription).to be_rejected
|
|
54
|
+
expect {
|
|
55
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
56
|
+
}.to raise_error(/Must be subscribed!/)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
if Rails::VERSION::MAJOR >= 5
|
|
2
|
+
require 'channels/notification_api_channel_shared_examples'
|
|
3
|
+
|
|
4
|
+
# @See https://github.com/palkan/action-cable-testing
|
|
5
|
+
describe ActivityNotification::NotificationApiChannel, 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_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
26
|
+
}.to raise_error(/Must be subscribed!/)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
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
|
+
@auth_headers = {}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
after do
|
|
38
|
+
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "successfully subscribes with target_type and target_id parameters" do
|
|
42
|
+
subscribe({ target_type: target_type, target_id: test_target.id })
|
|
43
|
+
expect(subscription).to be_confirmed
|
|
44
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
45
|
+
expect(subscription).to have_stream_from("activity_notification_api_channel_User##{test_target.id}")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it_behaves_like :notification_api_channel
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
if Rails::VERSION::MAJOR >= 5
|
|
2
|
+
require 'channels/notification_api_channel_shared_examples'
|
|
3
|
+
|
|
4
|
+
# @See https://github.com/palkan/action-cable-testing
|
|
5
|
+
describe ActivityNotification::NotificationApiWithDeviseChannel, type: :channel do
|
|
6
|
+
let(:test_user) { create(:confirmed_user) }
|
|
7
|
+
let(:unauthenticated_user) { create(:confirmed_user) }
|
|
8
|
+
let(:test_target) { create(:admin, user: test_user) }
|
|
9
|
+
let(:target_type) { "Admin" }
|
|
10
|
+
let(:typed_target_param) { "admin_id" }
|
|
11
|
+
let(:extra_params) { { devise_type: :users } }
|
|
12
|
+
let(:valid_session) {}
|
|
13
|
+
|
|
14
|
+
# @See https://github.com/lynndylanhurley/devise_token_auth
|
|
15
|
+
def sign_in(current_target)
|
|
16
|
+
@auth_headers = current_target.create_new_auth_token
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
before do
|
|
20
|
+
@user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
|
|
21
|
+
User._notification_action_cable_with_devise = true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
after do
|
|
25
|
+
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "signed in with devise as authenticated user" do
|
|
29
|
+
before do
|
|
30
|
+
sign_in test_user
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it_behaves_like :notification_api_channel
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "signed in with devise as unauthenticated user" do
|
|
37
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
38
|
+
|
|
39
|
+
before do
|
|
40
|
+
sign_in unauthenticated_user
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "rejects subscription" do
|
|
44
|
+
subscribe(target_params.merge({ typed_target_param => test_target }).merge(@auth_headers))
|
|
45
|
+
expect(subscription).to be_rejected
|
|
46
|
+
expect {
|
|
47
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
48
|
+
}.to raise_error(/Must be subscribed!/)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "unsigned in with devise" do
|
|
53
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
54
|
+
|
|
55
|
+
it "rejects subscription" do
|
|
56
|
+
subscribe(target_params.merge({ typed_target_param => test_target }))
|
|
57
|
+
expect(subscription).to be_rejected
|
|
58
|
+
expect {
|
|
59
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
60
|
+
}.to raise_error(/Must be subscribed!/)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "without target_id and (typed_target)_id parameters for devise integrated channel with devise_type option" do
|
|
65
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
66
|
+
|
|
67
|
+
before do
|
|
68
|
+
sign_in test_target.user
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "successfully subscribes" do
|
|
72
|
+
subscribe(target_params.merge(@auth_headers))
|
|
73
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
74
|
+
expect(subscription).to have_stream_from("activity_notification_api_channel_Admin##{test_target.id}")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -123,6 +123,24 @@ shared_examples_for :notification_api do
|
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
|
+
|
|
127
|
+
context "when some optional targets raise error" do
|
|
128
|
+
before do
|
|
129
|
+
require 'custom_optional_targets/raise_error'
|
|
130
|
+
@optional_target = CustomOptionalTarget::RaiseError.new
|
|
131
|
+
@current_optional_target = Comment._optional_targets[:users]
|
|
132
|
+
Comment.acts_as_notifiable :users, optional_targets: ->{ [@optional_target] }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
after do
|
|
136
|
+
Comment._optional_targets[:users] = @current_optional_target
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "generates notifications even if some optional targets raise error" do
|
|
140
|
+
notifications = described_class.notify(:users, @comment_2)
|
|
141
|
+
expect(notifications.size).to eq(2)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
126
144
|
end
|
|
127
145
|
|
|
128
146
|
describe ".notify_later" do
|
|
@@ -465,13 +483,14 @@ shared_examples_for :notification_api do
|
|
|
465
483
|
describe ".open_all_of" do
|
|
466
484
|
before do
|
|
467
485
|
described_class.notify_to(@user_1, @article, group: @article, key: 'key.1')
|
|
486
|
+
sleep(0.01)
|
|
468
487
|
described_class.notify_to(@user_1, @comment_2, group: @comment_2, key: 'key.2')
|
|
469
488
|
expect(@user_1.notifications.unopened_only.count).to eq(2)
|
|
470
489
|
expect(@user_1.notifications.opened_only!.count).to eq(0)
|
|
471
490
|
end
|
|
472
491
|
|
|
473
|
-
it "returns
|
|
474
|
-
expect(described_class.open_all_of(@user_1)).to eq(2)
|
|
492
|
+
it "returns array of opened notification records" do
|
|
493
|
+
expect(described_class.open_all_of(@user_1).size).to eq(2)
|
|
475
494
|
end
|
|
476
495
|
|
|
477
496
|
it "opens all notifications of the target" do
|
|
@@ -534,6 +553,22 @@ shared_examples_for :notification_api do
|
|
|
534
553
|
expect(@user_1.notifications.opened_only!.count).to eq(1)
|
|
535
554
|
end
|
|
536
555
|
end
|
|
556
|
+
|
|
557
|
+
context 'with later_than options' do
|
|
558
|
+
it "opens filtered notifications only" do
|
|
559
|
+
described_class.open_all_of(@user_1, { later_than: (@user_1.notifications.earliest.created_at.in_time_zone + 0.001).iso8601(3) })
|
|
560
|
+
expect(@user_1.notifications.unopened_only.count).to eq(1)
|
|
561
|
+
expect(@user_1.notifications.opened_only!.count).to eq(1)
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
context 'with earlier_than options' do
|
|
566
|
+
it "opens filtered notifications only" do
|
|
567
|
+
described_class.open_all_of(@user_1, { earlier_than: @user_1.notifications.latest.created_at.iso8601(3) })
|
|
568
|
+
expect(@user_1.notifications.unopened_only.count).to eq(1)
|
|
569
|
+
expect(@user_1.notifications.opened_only!.count).to eq(1)
|
|
570
|
+
end
|
|
571
|
+
end
|
|
537
572
|
end
|
|
538
573
|
|
|
539
574
|
describe ".group_member_exists?" do
|
|
@@ -605,7 +640,7 @@ shared_examples_for :notification_api do
|
|
|
605
640
|
describe ".available_options" do
|
|
606
641
|
it "returns list of available options in notify api" do
|
|
607
642
|
expect(described_class.available_options)
|
|
608
|
-
.to eq([:key, :group, :group_expiry_delay, :notifier, :parameters, :send_email, :send_later])
|
|
643
|
+
.to eq([:key, :group, :group_expiry_delay, :notifier, :parameters, :send_email, :send_later, :pass_full_options])
|
|
609
644
|
end
|
|
610
645
|
end
|
|
611
646
|
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.
|
|
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,66 +410,130 @@ shared_examples_for :notifiable do
|
|
|
410
410
|
end
|
|
411
411
|
end
|
|
412
412
|
|
|
413
|
-
describe "#
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
440
|
-
expect(test_instance.
|
|
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
|
|
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.
|
|
451
|
-
expect(test_instance.
|
|
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
|
|
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.
|
|
462
|
-
expect(test_instance.
|
|
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.
|
|
467
|
-
expect(test_instance.
|
|
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.
|
|
472
|
-
expect(test_instance.
|
|
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
|
+
end
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
describe "#notifiable_action_cable_api_allowed?" do
|
|
478
|
+
context "without any configuration" do
|
|
479
|
+
it "returns ActivityNotification.config.action_cable_api_enabled" do
|
|
480
|
+
expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key'))
|
|
481
|
+
.to eq(ActivityNotification.config.action_cable_api_enabled)
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
it "returns false as default" do
|
|
485
|
+
expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to be_falsey
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
context "configured with overridden method" do
|
|
490
|
+
it "returns specified value" do
|
|
491
|
+
module AdditionalMethods
|
|
492
|
+
def notifiable_action_cable_api_allowed_for_users?(target, key)
|
|
493
|
+
true
|
|
494
|
+
end
|
|
495
|
+
end
|
|
496
|
+
test_instance.extend(AdditionalMethods)
|
|
497
|
+
expect(test_instance.notifiable_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
context "configured with a field" do
|
|
502
|
+
it "returns specified value" do
|
|
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
|
+
end
|
|
506
|
+
|
|
507
|
+
it "returns specified symbol without arguments" do
|
|
508
|
+
module AdditionalMethods
|
|
509
|
+
def custom_notifiable_action_cable_api_allowed?
|
|
510
|
+
true
|
|
511
|
+
end
|
|
512
|
+
end
|
|
513
|
+
test_instance.extend(AdditionalMethods)
|
|
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
|
+
end
|
|
517
|
+
|
|
518
|
+
it "returns specified symbol with target and key arguments" do
|
|
519
|
+
module AdditionalMethods
|
|
520
|
+
def custom_notifiable_action_cable_api_allowed?(target, key)
|
|
521
|
+
true
|
|
522
|
+
end
|
|
523
|
+
end
|
|
524
|
+
test_instance.extend(AdditionalMethods)
|
|
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
|
+
end
|
|
528
|
+
|
|
529
|
+
it "returns specified lambda with single notifiable argument" do
|
|
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
|
+
end
|
|
533
|
+
|
|
534
|
+
it "returns specified lambda with notifiable, target and key arguments" do
|
|
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)
|
|
473
537
|
end
|
|
474
538
|
end
|
|
475
539
|
end
|