activity_notification 1.4.4 → 2.2.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 +5 -5
- 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/.github/workflows/build.yml +116 -0
- data/.gitignore +15 -3
- data/CHANGELOG.md +200 -1
- data/Gemfile +17 -2
- data/Procfile +2 -0
- data/README.md +168 -1033
- data/Rakefile +19 -10
- data/activity_notification.gemspec +14 -9
- 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 +37 -0
- data/app/channels/activity_notification/notification_with_devise_channel.rb +51 -0
- 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 +60 -54
- 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 +83 -73
- data/app/jobs/activity_notification/notify_all_job.rb +25 -0
- data/app/jobs/activity_notification/notify_job.rb +26 -0
- data/app/jobs/activity_notification/notify_to_job.rb +25 -0
- data/app/views/activity_notification/notifications/default/_default.html.erb +23 -23
- data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +19 -19
- data/app/views/activity_notification/notifications/default/_index.html.erb +3 -3
- data/app/views/activity_notification/notifications/default/index.html.erb +60 -7
- data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/show.html.erb +2 -2
- data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
- data/app/views/activity_notification/optional_targets/default/base/_default.text.erb +1 -1
- data/app/views/activity_notification/optional_targets/default/slack/_default.text.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +5 -33
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +8 -8
- data/app/views/activity_notification/subscriptions/default/index.html.erb +13 -9
- data/app/views/activity_notification/subscriptions/default/show.html.erb +3 -3
- data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/subscribe_to_optional_target.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_optional_target.js.erb +1 -1
- data/bin/_dynamodblocal +4 -0
- data/bin/bundle_update.sh +7 -0
- data/bin/deploy_on_heroku.sh +16 -0
- data/bin/install_dynamodblocal.sh +5 -0
- data/bin/start_dynamodblocal.sh +47 -0
- data/bin/stop_dynamodblocal.sh +34 -0
- data/docs/CODE_OF_CONDUCT.md +76 -0
- data/docs/CONTRIBUTING.md +36 -0
- data/docs/Functions.md +1146 -0
- data/docs/Setup.md +817 -0
- data/docs/Testing.md +148 -0
- data/gemfiles/Gemfile.rails-5.0 +8 -1
- data/gemfiles/Gemfile.rails-5.1 +7 -1
- data/gemfiles/Gemfile.rails-5.2 +24 -0
- data/gemfiles/Gemfile.rails-6.0 +23 -0
- data/gemfiles/Gemfile.rails-6.1 +22 -0
- data/gemfiles/Gemfile.rails-7.0 +25 -0
- data/lib/activity_notification/apis/notification_api.rb +356 -159
- data/lib/activity_notification/apis/subscription_api.rb +98 -59
- data/lib/activity_notification/apis/swagger.rb +6 -0
- data/lib/activity_notification/common.rb +18 -7
- data/lib/activity_notification/config.rb +176 -30
- data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
- data/lib/activity_notification/controllers/common_controller.rb +47 -27
- 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 +22 -5
- data/lib/activity_notification/gem_version.rb +14 -0
- data/lib/activity_notification/helpers/errors.rb +6 -0
- data/lib/activity_notification/helpers/view_helpers.rb +118 -28
- data/lib/activity_notification/mailers/helpers.rb +19 -12
- data/lib/activity_notification/models/concerns/notifiable.rb +142 -55
- data/lib/activity_notification/models/concerns/subscriber.rb +28 -13
- 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 +131 -32
- data/lib/activity_notification/models/notification.rb +1 -0
- data/lib/activity_notification/models/subscription.rb +1 -0
- data/lib/activity_notification/models.rb +23 -1
- 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 +9 -15
- data/lib/activity_notification/orm/active_record/notification.rb +23 -34
- data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
- data/lib/activity_notification/orm/active_record.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/extension.rb +262 -0
- data/lib/activity_notification/orm/dynamoid/notification.rb +224 -0
- data/lib/activity_notification/orm/dynamoid/subscription.rb +82 -0
- data/lib/activity_notification/orm/dynamoid.rb +530 -0
- data/lib/activity_notification/orm/mongoid/notification.rb +29 -28
- data/lib/activity_notification/orm/mongoid/subscription.rb +3 -3
- data/lib/activity_notification/orm/mongoid.rb +33 -1
- data/lib/activity_notification/rails/routes.rb +273 -60
- data/lib/activity_notification/renderable.rb +22 -7
- data/lib/activity_notification/roles/acts_as_notifiable.rb +64 -1
- data/lib/activity_notification/roles/acts_as_target.rb +99 -9
- data/lib/activity_notification/version.rb +1 -1
- data/lib/activity_notification.rb +14 -0
- data/lib/generators/activity_notification/controllers_generator.rb +2 -1
- data/lib/generators/templates/activity_notification.rb +61 -7
- data/lib/generators/templates/controllers/README +2 -2
- 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/migrations/migration.rb +5 -5
- 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/lib/tasks/activity_notification_tasks.rake +14 -4
- data/package.json +8 -0
- data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_api_channel_spec.rb +49 -0
- data/spec/channels/notification_api_with_devise_channel_spec.rb +76 -0
- data/spec/channels/notification_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_channel_spec.rb +48 -0
- data/spec/channels/notification_with_devise_channel_spec.rb +97 -0
- data/spec/concerns/apis/notification_api_spec.rb +177 -12
- data/spec/concerns/apis/subscription_api_spec.rb +146 -4
- data/spec/concerns/common_spec.rb +25 -3
- data/spec/concerns/models/notifiable_spec.rb +161 -11
- data/spec/concerns/models/subscriber_spec.rb +253 -79
- data/spec/concerns/models/target_spec.rb +180 -47
- data/spec/concerns/renderable_spec.rb +35 -16
- data/spec/config_spec.rb +52 -1
- data/spec/controllers/controller_spec_utility.rb +100 -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 +55 -76
- data/spec/controllers/notifications_controller_spec.rb +1 -2
- data/spec/controllers/notifications_with_devise_controller_spec.rb +14 -8
- 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 +99 -121
- data/spec/controllers/subscriptions_controller_spec.rb +1 -2
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +14 -8
- data/spec/factories/notifications.rb +1 -1
- data/spec/factories/subscriptions.rb +3 -3
- data/spec/factories/users.rb +3 -3
- data/spec/generators/migration/migration_generator_spec.rb +29 -4
- data/spec/helpers/view_helpers_spec.rb +31 -21
- data/spec/jobs/notify_all_job_spec.rb +23 -0
- data/spec/jobs/notify_job_spec.rb +23 -0
- data/spec/jobs/notify_to_job_spec.rb +23 -0
- data/spec/mailers/mailer_spec.rb +42 -1
- 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 +181 -45
- data/spec/models/subscription_spec.rb +77 -27
- data/spec/optional_targets/action_cable_api_channel_spec.rb +34 -0
- data/spec/optional_targets/action_cable_channel_spec.rb +41 -0
- data/spec/optional_targets/amazon_sns_spec.rb +0 -2
- data/spec/optional_targets/slack_spec.rb +0 -2
- data/spec/orm/dynamoid_spec.rb +115 -0
- data/spec/rails_app/Rakefile +9 -0
- data/spec/rails_app/app/assets/config/manifest.js +3 -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/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 -1
- data/spec/rails_app/app/controllers/comments_controller.rb +3 -1
- 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 +15 -10
- data/spec/rails_app/app/models/article.rb +25 -20
- data/spec/rails_app/app/models/comment.rb +27 -62
- data/spec/rails_app/app/models/dummy/dummy_base.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_group.rb +9 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +27 -0
- data/spec/rails_app/app/models/dummy/dummy_notifier.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_target.rb +1 -0
- data/spec/rails_app/app/models/user.rb +44 -18
- data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
- data/spec/rails_app/app/views/activity_notification/notifications/users/overridden/custom/_test.html.erb +1 -0
- data/spec/rails_app/app/views/activity_notification/optional_targets/admins/amazon_sns/comment/_default.text.erb +1 -1
- data/spec/rails_app/app/views/articles/index.html.erb +68 -20
- data/spec/rails_app/app/views/articles/show.html.erb +1 -1
- data/spec/rails_app/app/views/layouts/_header.html.erb +9 -3
- 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 +26 -6
- data/spec/rails_app/config/cable.yml +8 -0
- data/spec/rails_app/config/database.yml +1 -1
- data/spec/rails_app/config/dynamoid.rb +13 -0
- data/spec/rails_app/config/environment.rb +5 -1
- data/spec/rails_app/config/environments/development.rb +5 -0
- data/spec/rails_app/config/environments/production.rb +7 -1
- data/spec/rails_app/config/environments/test.rb +7 -11
- data/spec/rails_app/config/initializers/activity_notification.rb +63 -9
- 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 +10 -4
- data/spec/rails_app/config/routes.rb +42 -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/{20160715050433_create_test_tables.rb → 20160716000000_create_test_tables.rb} +1 -1
- data/spec/rails_app/db/migrate/{20160715050420_create_activity_notification_tables.rb → 20181209000000_create_activity_notification_tables.rb} +3 -3
- data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
- data/spec/rails_app/db/schema.rb +46 -43
- data/spec/rails_app/db/seeds.rb +28 -4
- data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
- data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +14 -4
- 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 +80 -20
- data/spec/roles/acts_as_notifier_spec.rb +0 -2
- data/spec/roles/acts_as_target_spec.rb +1 -5
- data/spec/spec_helper.rb +13 -11
- data/spec/version_spec.rb +31 -0
- metadata +306 -53
- data/.travis.yml +0 -85
- data/Gemfile.lock +0 -234
- data/gemfiles/Gemfile.rails-4.2 +0 -17
- data/gemfiles/Gemfile.rails-4.2.lock +0 -225
- data/gemfiles/Gemfile.rails-5.0.lock +0 -234
- data/gemfiles/Gemfile.rails-5.1.lock +0 -234
- data/spec/rails_app/app/views/activity_notification/notifications/users/overriden/custom/_test.html.erb +0 -1
- /data/spec/rails_app/app/{models → assets/images}/.keep +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'controllers/subscriptions_api_controller_shared_examples'
|
|
2
|
+
|
|
3
|
+
describe ActivityNotification::SubscriptionsApiController, type: :controller do
|
|
4
|
+
let(:test_target) { create(:user) }
|
|
5
|
+
let(:target_type) { :users }
|
|
6
|
+
let(:typed_target_param) { :user_id }
|
|
7
|
+
let(:extra_params) { {} }
|
|
8
|
+
let(:valid_session) {}
|
|
9
|
+
|
|
10
|
+
it_behaves_like :subscriptions_api_controller
|
|
11
|
+
|
|
12
|
+
describe "/api/v#{ActivityNotification::GEM_VERSION::MAJOR}", type: :request do
|
|
13
|
+
let(:root_path) { "/api/v#{ActivityNotification::GEM_VERSION::MAJOR}" }
|
|
14
|
+
let(:test_target) { create(:user) }
|
|
15
|
+
let(:target_type) { :users }
|
|
16
|
+
|
|
17
|
+
it_behaves_like :subscriptions_api_request
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'controllers/subscriptions_api_controller_shared_examples'
|
|
2
|
+
|
|
3
|
+
context "ActivityNotification::NotificationsApiWithDeviseController" do
|
|
4
|
+
context "test admins API with associated users authentication" do
|
|
5
|
+
|
|
6
|
+
describe "/api/v#{ActivityNotification::GEM_VERSION::MAJOR}", type: :request do
|
|
7
|
+
include ActivityNotification::ControllerSpec::CommitteeUtility
|
|
8
|
+
|
|
9
|
+
let(:root_path) { "/api/v#{ActivityNotification::GEM_VERSION::MAJOR}" }
|
|
10
|
+
let(:test_user) { create(:confirmed_user) }
|
|
11
|
+
let(:unauthenticated_user) { create(:confirmed_user) }
|
|
12
|
+
let(:test_target) { create(:admin, user: test_user) }
|
|
13
|
+
let(:target_type) { :admins }
|
|
14
|
+
|
|
15
|
+
def sign_in_with_devise_token_auth(auth_user, status)
|
|
16
|
+
post_with_compatibility "#{root_path}/auth/sign_in", params: { email: auth_user.email, password: "password" }
|
|
17
|
+
expect(response).to have_http_status(status)
|
|
18
|
+
@headers = response.header.slice("access-token", "client", "uid")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "signed in with devise as authenticated user" do
|
|
22
|
+
before do
|
|
23
|
+
sign_in_with_devise_token_auth(test_user, 200)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it_behaves_like :subscriptions_api_request
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "signed in with devise as unauthenticated user" do
|
|
30
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
31
|
+
|
|
32
|
+
describe "GET #index" do
|
|
33
|
+
before do
|
|
34
|
+
sign_in_with_devise_token_auth(unauthenticated_user, 200)
|
|
35
|
+
get_with_compatibility "#{api_path}/subscriptions", headers: @headers
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "returns 403 as http status code" do
|
|
39
|
+
expect(response.status).to eq(403)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "unsigned in with devise" do
|
|
45
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
46
|
+
|
|
47
|
+
describe "GET #index" do
|
|
48
|
+
before do
|
|
49
|
+
get_with_compatibility "#{api_path}/subscriptions", headers: @headers
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "returns 401 as http status code" do
|
|
53
|
+
expect(response.status).to eq(401)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'controller_spec_utility'
|
|
2
|
+
|
|
3
|
+
shared_examples_for :subscriptions_controller do
|
|
4
|
+
include ActivityNotification::ControllerSpec::RequestUtility
|
|
5
|
+
|
|
2
6
|
let(:target_params) { { target_type: target_type }.merge(extra_params || {}) }
|
|
3
7
|
|
|
4
8
|
describe "GET #index" do
|
|
@@ -81,30 +85,6 @@ shared_examples_for :subscription_controller do
|
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
|
|
84
|
-
context "with json as format parameter" do
|
|
85
|
-
before do
|
|
86
|
-
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
87
|
-
@notification = create(:notification, target: test_target, key: 'test_notification_key')
|
|
88
|
-
get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, format: :json }), valid_session
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "returns 200 as http status code" do
|
|
92
|
-
expect(response.status).to eq(200)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it "returns json format" do
|
|
96
|
-
if ActivityNotification.config.orm == :active_record
|
|
97
|
-
expect(JSON.parse(response.body)["subscriptions"].first)
|
|
98
|
-
.to include("target_id" => test_target.id, "target_type" => test_target.to_class_name)
|
|
99
|
-
else
|
|
100
|
-
expect(JSON.parse(response.body)["subscriptions"].first)
|
|
101
|
-
.to include("target_id" => test_target.id.to_s, "target_type" => test_target.to_class_name)
|
|
102
|
-
end
|
|
103
|
-
expect(JSON.parse(response.body)["unconfigured_notification_keys"].first)
|
|
104
|
-
.to eq('test_notification_key')
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
88
|
context "with filter parameter" do
|
|
109
89
|
context "with configured as filter" do
|
|
110
90
|
before do
|
|
@@ -225,14 +205,14 @@ shared_examples_for :subscription_controller do
|
|
|
225
205
|
end
|
|
226
206
|
end
|
|
227
207
|
|
|
228
|
-
describe "
|
|
208
|
+
describe "PUT #create" do
|
|
229
209
|
before do
|
|
230
|
-
expect(test_target.subscriptions.size).to
|
|
210
|
+
expect(test_target.subscriptions.size).to eq(0)
|
|
231
211
|
end
|
|
232
212
|
|
|
233
|
-
context "http direct
|
|
213
|
+
context "http direct PUT request without optional targets" do
|
|
234
214
|
before do
|
|
235
|
-
|
|
215
|
+
put_with_compatibility :create, target_params.merge({
|
|
236
216
|
typed_target_param => test_target,
|
|
237
217
|
"subscription" => { "key" => "new_subscription_key",
|
|
238
218
|
"subscribing"=> "true",
|
|
@@ -255,9 +235,9 @@ shared_examples_for :subscription_controller do
|
|
|
255
235
|
end
|
|
256
236
|
end
|
|
257
237
|
|
|
258
|
-
context "http direct
|
|
238
|
+
context "http direct PUT request with optional targets" do
|
|
259
239
|
before do
|
|
260
|
-
|
|
240
|
+
put_with_compatibility :create, target_params.merge({
|
|
261
241
|
typed_target_param => test_target,
|
|
262
242
|
"subscription" => { "key" => "new_subscription_key",
|
|
263
243
|
"subscribing"=> "true",
|
|
@@ -273,9 +253,10 @@ shared_examples_for :subscription_controller do
|
|
|
273
253
|
|
|
274
254
|
it "creates new subscription of the target" do
|
|
275
255
|
expect(test_target.subscriptions.reload.size).to eq(1)
|
|
276
|
-
|
|
277
|
-
expect(
|
|
278
|
-
expect(
|
|
256
|
+
created_subscription = test_target.subscriptions.reload.first
|
|
257
|
+
expect(created_subscription.key).to eq("new_subscription_key")
|
|
258
|
+
expect(created_subscription.subscribing_to_optional_target?("base1")).to be_truthy
|
|
259
|
+
expect(created_subscription.subscribing_to_optional_target?("base2")).to be_falsey
|
|
279
260
|
end
|
|
280
261
|
|
|
281
262
|
it "redirects to :index" do
|
|
@@ -283,10 +264,10 @@ shared_examples_for :subscription_controller do
|
|
|
283
264
|
end
|
|
284
265
|
end
|
|
285
266
|
|
|
286
|
-
context "http
|
|
267
|
+
context "http PUT request from root_path" do
|
|
287
268
|
before do
|
|
288
269
|
request.env["HTTP_REFERER"] = root_path
|
|
289
|
-
|
|
270
|
+
put_with_compatibility :create, target_params.merge({
|
|
290
271
|
typed_target_param => test_target,
|
|
291
272
|
"subscription" => { "key" => "new_subscription_key",
|
|
292
273
|
"subscribing"=> "true",
|
|
@@ -309,10 +290,10 @@ shared_examples_for :subscription_controller do
|
|
|
309
290
|
end
|
|
310
291
|
end
|
|
311
292
|
|
|
312
|
-
context "Ajax
|
|
293
|
+
context "Ajax PUT request" do
|
|
313
294
|
before do
|
|
314
295
|
request.env["HTTP_REFERER"] = root_path
|
|
315
|
-
xhr_with_compatibility :
|
|
296
|
+
xhr_with_compatibility :put, :create, target_params.merge({
|
|
316
297
|
typed_target_param => test_target,
|
|
317
298
|
"subscription" => { "key" => "new_subscription_key",
|
|
318
299
|
"subscribing"=> "true",
|
|
@@ -340,6 +321,38 @@ shared_examples_for :subscription_controller do
|
|
|
340
321
|
end
|
|
341
322
|
end
|
|
342
323
|
|
|
324
|
+
describe "GET #find" do
|
|
325
|
+
context "with key, target_type and (typed_target)_id parameters" do
|
|
326
|
+
before do
|
|
327
|
+
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
328
|
+
get_with_compatibility :find, target_params.merge({ key: 'test_subscription_key', typed_target_param => test_target }), valid_session
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
it "returns 302 as http status code" do
|
|
332
|
+
expect(response.status).to eq(302)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
it "assigns the requested subscription as @subscription" do
|
|
336
|
+
expect(assigns(:subscription)).to eq(@subscription)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
it "redirects to :show" do
|
|
340
|
+
expect(response).to redirect_to action: :show, id: @subscription
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
context "with wrong id and (typed_target)_id parameters" do
|
|
345
|
+
before do
|
|
346
|
+
@subscription = create(:subscription, target: create(:user))
|
|
347
|
+
get_with_compatibility :find, target_params.merge({ key: 'test_subscription_key', typed_target_param => test_target }), valid_session
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
it "returns 404 as http status code" do
|
|
351
|
+
expect(response.status).to eq(404)
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
343
356
|
describe "GET #show" do
|
|
344
357
|
context "with id, target_type and (typed_target)_id parameters" do
|
|
345
358
|
before do
|
|
@@ -355,7 +368,7 @@ shared_examples_for :subscription_controller do
|
|
|
355
368
|
expect(assigns(:subscription)).to eq(@subscription)
|
|
356
369
|
end
|
|
357
370
|
|
|
358
|
-
it "renders the :
|
|
371
|
+
it "renders the :show template" do
|
|
359
372
|
expect(response).to render_template :show
|
|
360
373
|
end
|
|
361
374
|
end
|
|
@@ -384,7 +397,7 @@ shared_examples_for :subscription_controller do
|
|
|
384
397
|
end
|
|
385
398
|
|
|
386
399
|
it "deletes the subscription" do
|
|
387
|
-
expect(
|
|
400
|
+
expect(test_target.subscriptions.where(id: @subscription.id).exists?).to be_falsey
|
|
388
401
|
end
|
|
389
402
|
|
|
390
403
|
it "redirects to :index" do
|
|
@@ -436,13 +449,13 @@ shared_examples_for :subscription_controller do
|
|
|
436
449
|
end
|
|
437
450
|
end
|
|
438
451
|
|
|
439
|
-
describe "
|
|
440
|
-
context "http direct
|
|
452
|
+
describe "PUT #subscribe" do
|
|
453
|
+
context "http direct PUT request" do
|
|
441
454
|
before do
|
|
442
455
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
443
456
|
@subscription.unsubscribe
|
|
444
457
|
expect(@subscription.subscribing?).to be_falsey
|
|
445
|
-
|
|
458
|
+
put_with_compatibility :subscribe, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
446
459
|
end
|
|
447
460
|
|
|
448
461
|
it "returns 302 as http status code" do
|
|
@@ -458,13 +471,13 @@ shared_examples_for :subscription_controller do
|
|
|
458
471
|
end
|
|
459
472
|
end
|
|
460
473
|
|
|
461
|
-
context "http
|
|
474
|
+
context "http PUT request from root_path" do
|
|
462
475
|
before do
|
|
463
476
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
464
477
|
@subscription.unsubscribe
|
|
465
478
|
expect(@subscription.subscribing?).to be_falsey
|
|
466
479
|
request.env["HTTP_REFERER"] = root_path
|
|
467
|
-
|
|
480
|
+
put_with_compatibility :subscribe, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
468
481
|
end
|
|
469
482
|
|
|
470
483
|
it "returns 302 as http status code" do
|
|
@@ -480,13 +493,13 @@ shared_examples_for :subscription_controller do
|
|
|
480
493
|
end
|
|
481
494
|
end
|
|
482
495
|
|
|
483
|
-
context "Ajax
|
|
496
|
+
context "Ajax PUT request" do
|
|
484
497
|
before do
|
|
485
498
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
486
499
|
@subscription.unsubscribe
|
|
487
500
|
expect(@subscription.subscribing?).to be_falsey
|
|
488
501
|
request.env["HTTP_REFERER"] = root_path
|
|
489
|
-
xhr_with_compatibility :
|
|
502
|
+
xhr_with_compatibility :put, :subscribe, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
490
503
|
end
|
|
491
504
|
|
|
492
505
|
it "returns 200 as http status code" do
|
|
@@ -507,12 +520,12 @@ shared_examples_for :subscription_controller do
|
|
|
507
520
|
end
|
|
508
521
|
end
|
|
509
522
|
|
|
510
|
-
describe "
|
|
511
|
-
context "http direct
|
|
523
|
+
describe "PUT #unsubscribe" do
|
|
524
|
+
context "http direct PUT request" do
|
|
512
525
|
before do
|
|
513
526
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
514
527
|
expect(@subscription.subscribing?).to be_truthy
|
|
515
|
-
|
|
528
|
+
put_with_compatibility :unsubscribe, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
516
529
|
end
|
|
517
530
|
|
|
518
531
|
it "returns 302 as http status code" do
|
|
@@ -528,12 +541,12 @@ shared_examples_for :subscription_controller do
|
|
|
528
541
|
end
|
|
529
542
|
end
|
|
530
543
|
|
|
531
|
-
context "http
|
|
544
|
+
context "http PUT request from root_path" do
|
|
532
545
|
before do
|
|
533
546
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
534
547
|
expect(@subscription.subscribing?).to be_truthy
|
|
535
548
|
request.env["HTTP_REFERER"] = root_path
|
|
536
|
-
|
|
549
|
+
put_with_compatibility :unsubscribe, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
537
550
|
end
|
|
538
551
|
|
|
539
552
|
it "returns 302 as http status code" do
|
|
@@ -549,12 +562,12 @@ shared_examples_for :subscription_controller do
|
|
|
549
562
|
end
|
|
550
563
|
end
|
|
551
564
|
|
|
552
|
-
context "Ajax
|
|
565
|
+
context "Ajax PUT request" do
|
|
553
566
|
before do
|
|
554
567
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
555
568
|
expect(@subscription.subscribing?).to be_truthy
|
|
556
569
|
request.env["HTTP_REFERER"] = root_path
|
|
557
|
-
xhr_with_compatibility :
|
|
570
|
+
xhr_with_compatibility :put, :unsubscribe, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
558
571
|
end
|
|
559
572
|
|
|
560
573
|
it "returns 200 as http status code" do
|
|
@@ -575,13 +588,13 @@ shared_examples_for :subscription_controller do
|
|
|
575
588
|
end
|
|
576
589
|
end
|
|
577
590
|
|
|
578
|
-
describe "
|
|
579
|
-
context "http direct
|
|
591
|
+
describe "PUT #subscribe_to_email" do
|
|
592
|
+
context "http direct PUT request" do
|
|
580
593
|
before do
|
|
581
594
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
582
595
|
@subscription.unsubscribe_to_email
|
|
583
596
|
expect(@subscription.subscribing_to_email?).to be_falsey
|
|
584
|
-
|
|
597
|
+
put_with_compatibility :subscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
585
598
|
end
|
|
586
599
|
|
|
587
600
|
it "returns 302 as http status code" do
|
|
@@ -597,13 +610,13 @@ shared_examples_for :subscription_controller do
|
|
|
597
610
|
end
|
|
598
611
|
end
|
|
599
612
|
|
|
600
|
-
context "http
|
|
613
|
+
context "http PUT request from root_path" do
|
|
601
614
|
before do
|
|
602
615
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
603
616
|
@subscription.unsubscribe_to_email
|
|
604
617
|
expect(@subscription.subscribing_to_email?).to be_falsey
|
|
605
618
|
request.env["HTTP_REFERER"] = root_path
|
|
606
|
-
|
|
619
|
+
put_with_compatibility :subscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
607
620
|
end
|
|
608
621
|
|
|
609
622
|
it "returns 302 as http status code" do
|
|
@@ -619,13 +632,13 @@ shared_examples_for :subscription_controller do
|
|
|
619
632
|
end
|
|
620
633
|
end
|
|
621
634
|
|
|
622
|
-
context "Ajax
|
|
635
|
+
context "Ajax PUT request" do
|
|
623
636
|
before do
|
|
624
637
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
625
638
|
@subscription.unsubscribe_to_email
|
|
626
639
|
expect(@subscription.subscribing_to_email?).to be_falsey
|
|
627
640
|
request.env["HTTP_REFERER"] = root_path
|
|
628
|
-
xhr_with_compatibility :
|
|
641
|
+
xhr_with_compatibility :put, :subscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
629
642
|
end
|
|
630
643
|
|
|
631
644
|
it "returns 200 as http status code" do
|
|
@@ -651,7 +664,7 @@ shared_examples_for :subscription_controller do
|
|
|
651
664
|
@subscription.unsubscribe
|
|
652
665
|
expect(@subscription.subscribing?).to be_falsey
|
|
653
666
|
expect(@subscription.subscribing_to_email?).to be_falsey
|
|
654
|
-
|
|
667
|
+
put_with_compatibility :subscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
655
668
|
end
|
|
656
669
|
|
|
657
670
|
it "returns 302 as http status code" do
|
|
@@ -668,12 +681,12 @@ shared_examples_for :subscription_controller do
|
|
|
668
681
|
end
|
|
669
682
|
end
|
|
670
683
|
|
|
671
|
-
describe "
|
|
672
|
-
context "http direct
|
|
684
|
+
describe "PUT #unsubscribe_to_email" do
|
|
685
|
+
context "http direct PUT request" do
|
|
673
686
|
before do
|
|
674
687
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
675
688
|
expect(@subscription.subscribing_to_email?).to be_truthy
|
|
676
|
-
|
|
689
|
+
put_with_compatibility :unsubscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
677
690
|
end
|
|
678
691
|
|
|
679
692
|
it "returns 302 as http status code" do
|
|
@@ -689,12 +702,12 @@ shared_examples_for :subscription_controller do
|
|
|
689
702
|
end
|
|
690
703
|
end
|
|
691
704
|
|
|
692
|
-
context "http
|
|
705
|
+
context "http PUT request from root_path" do
|
|
693
706
|
before do
|
|
694
707
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
695
708
|
expect(@subscription.subscribing_to_email?).to be_truthy
|
|
696
709
|
request.env["HTTP_REFERER"] = root_path
|
|
697
|
-
|
|
710
|
+
put_with_compatibility :unsubscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
698
711
|
end
|
|
699
712
|
|
|
700
713
|
it "returns 302 as http status code" do
|
|
@@ -710,12 +723,12 @@ shared_examples_for :subscription_controller do
|
|
|
710
723
|
end
|
|
711
724
|
end
|
|
712
725
|
|
|
713
|
-
context "Ajax
|
|
726
|
+
context "Ajax PUT request" do
|
|
714
727
|
before do
|
|
715
728
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
716
729
|
expect(@subscription.subscribing_to_email?).to be_truthy
|
|
717
730
|
request.env["HTTP_REFERER"] = root_path
|
|
718
|
-
xhr_with_compatibility :
|
|
731
|
+
xhr_with_compatibility :put, :unsubscribe_to_email, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
719
732
|
end
|
|
720
733
|
|
|
721
734
|
it "returns 200 as http status code" do
|
|
@@ -736,13 +749,13 @@ shared_examples_for :subscription_controller do
|
|
|
736
749
|
end
|
|
737
750
|
end
|
|
738
751
|
|
|
739
|
-
describe "
|
|
752
|
+
describe "PUT #subscribe_to_optional_target" do
|
|
740
753
|
context "without optional_target_name param" do
|
|
741
754
|
before do
|
|
742
755
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
743
756
|
@subscription.unsubscribe_to_optional_target(:base)
|
|
744
757
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_falsey
|
|
745
|
-
|
|
758
|
+
put_with_compatibility :subscribe_to_optional_target, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
746
759
|
end
|
|
747
760
|
|
|
748
761
|
it "returns 400 as http status code" do
|
|
@@ -754,12 +767,12 @@ shared_examples_for :subscription_controller do
|
|
|
754
767
|
end
|
|
755
768
|
end
|
|
756
769
|
|
|
757
|
-
context "http direct
|
|
770
|
+
context "http direct PUT request" do
|
|
758
771
|
before do
|
|
759
772
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
760
773
|
@subscription.unsubscribe_to_optional_target(:base)
|
|
761
774
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_falsey
|
|
762
|
-
|
|
775
|
+
put_with_compatibility :subscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
763
776
|
end
|
|
764
777
|
|
|
765
778
|
it "returns 302 as http status code" do
|
|
@@ -775,13 +788,13 @@ shared_examples_for :subscription_controller do
|
|
|
775
788
|
end
|
|
776
789
|
end
|
|
777
790
|
|
|
778
|
-
context "http
|
|
791
|
+
context "http PUT request from root_path" do
|
|
779
792
|
before do
|
|
780
793
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
781
794
|
@subscription.unsubscribe_to_optional_target(:base)
|
|
782
795
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_falsey
|
|
783
796
|
request.env["HTTP_REFERER"] = root_path
|
|
784
|
-
|
|
797
|
+
put_with_compatibility :subscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
785
798
|
end
|
|
786
799
|
|
|
787
800
|
it "returns 302 as http status code" do
|
|
@@ -797,13 +810,13 @@ shared_examples_for :subscription_controller do
|
|
|
797
810
|
end
|
|
798
811
|
end
|
|
799
812
|
|
|
800
|
-
context "Ajax
|
|
813
|
+
context "Ajax PUT request" do
|
|
801
814
|
before do
|
|
802
815
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
803
816
|
@subscription.unsubscribe_to_optional_target(:base)
|
|
804
817
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_falsey
|
|
805
818
|
request.env["HTTP_REFERER"] = root_path
|
|
806
|
-
xhr_with_compatibility :
|
|
819
|
+
xhr_with_compatibility :put, :subscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
807
820
|
end
|
|
808
821
|
|
|
809
822
|
it "returns 200 as http status code" do
|
|
@@ -830,7 +843,7 @@ shared_examples_for :subscription_controller do
|
|
|
830
843
|
@subscription.unsubscribe
|
|
831
844
|
expect(@subscription.subscribing?).to be_falsey
|
|
832
845
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_falsey
|
|
833
|
-
|
|
846
|
+
put_with_compatibility :subscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
834
847
|
end
|
|
835
848
|
|
|
836
849
|
it "returns 302 as http status code" do
|
|
@@ -847,12 +860,12 @@ shared_examples_for :subscription_controller do
|
|
|
847
860
|
end
|
|
848
861
|
end
|
|
849
862
|
|
|
850
|
-
describe "
|
|
863
|
+
describe "PUT #unsubscribe_to_email" do
|
|
851
864
|
context "without optional_target_name param" do
|
|
852
865
|
before do
|
|
853
866
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
854
867
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_truthy
|
|
855
|
-
|
|
868
|
+
put_with_compatibility :unsubscribe_to_optional_target, target_params.merge({ id: @subscription, typed_target_param => test_target }), valid_session
|
|
856
869
|
end
|
|
857
870
|
|
|
858
871
|
it "returns 400 as http status code" do
|
|
@@ -864,11 +877,11 @@ shared_examples_for :subscription_controller do
|
|
|
864
877
|
end
|
|
865
878
|
end
|
|
866
879
|
|
|
867
|
-
context "http direct
|
|
880
|
+
context "http direct PUT request" do
|
|
868
881
|
before do
|
|
869
882
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
870
883
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_truthy
|
|
871
|
-
|
|
884
|
+
put_with_compatibility :unsubscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
872
885
|
end
|
|
873
886
|
|
|
874
887
|
it "returns 302 as http status code" do
|
|
@@ -884,12 +897,12 @@ shared_examples_for :subscription_controller do
|
|
|
884
897
|
end
|
|
885
898
|
end
|
|
886
899
|
|
|
887
|
-
context "http
|
|
900
|
+
context "http PUT request from root_path" do
|
|
888
901
|
before do
|
|
889
902
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
890
903
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_truthy
|
|
891
904
|
request.env["HTTP_REFERER"] = root_path
|
|
892
|
-
|
|
905
|
+
put_with_compatibility :unsubscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
893
906
|
end
|
|
894
907
|
|
|
895
908
|
it "returns 302 as http status code" do
|
|
@@ -905,12 +918,12 @@ shared_examples_for :subscription_controller do
|
|
|
905
918
|
end
|
|
906
919
|
end
|
|
907
920
|
|
|
908
|
-
context "Ajax
|
|
921
|
+
context "Ajax PUT request" do
|
|
909
922
|
before do
|
|
910
923
|
@subscription = create(:subscription, target: test_target, key: 'test_subscription_key')
|
|
911
924
|
expect(@subscription.subscribing_to_optional_target?(:base)).to be_truthy
|
|
912
925
|
request.env["HTTP_REFERER"] = root_path
|
|
913
|
-
xhr_with_compatibility :
|
|
926
|
+
xhr_with_compatibility :put, :unsubscribe_to_optional_target, target_params.merge({ id: @subscription, optional_target_name: 'base', typed_target_param => test_target }), valid_session
|
|
914
927
|
end
|
|
915
928
|
|
|
916
929
|
it "returns 200 as http status code" do
|
|
@@ -930,39 +943,4 @@ shared_examples_for :subscription_controller do
|
|
|
930
943
|
end
|
|
931
944
|
end
|
|
932
945
|
end
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
private
|
|
936
|
-
|
|
937
|
-
def get_with_compatibility action, params, session
|
|
938
|
-
if Rails::VERSION::MAJOR <= 4
|
|
939
|
-
get action, params, session
|
|
940
|
-
else
|
|
941
|
-
get action, params: params, session: session
|
|
942
|
-
end
|
|
943
|
-
end
|
|
944
|
-
|
|
945
|
-
def post_with_compatibility action, params, session
|
|
946
|
-
if Rails::VERSION::MAJOR <= 4
|
|
947
|
-
post action, params, session
|
|
948
|
-
else
|
|
949
|
-
post action, params: params, session: session
|
|
950
|
-
end
|
|
951
|
-
end
|
|
952
|
-
|
|
953
|
-
def delete_with_compatibility action, params, session
|
|
954
|
-
if Rails::VERSION::MAJOR <= 4
|
|
955
|
-
delete action, params, session
|
|
956
|
-
else
|
|
957
|
-
delete action, params: params, session: session
|
|
958
|
-
end
|
|
959
|
-
end
|
|
960
|
-
|
|
961
|
-
def xhr_with_compatibility method, action, params, session
|
|
962
|
-
if Rails::VERSION::MAJOR <= 4
|
|
963
|
-
xhr method, action, params, session
|
|
964
|
-
else
|
|
965
|
-
send method.to_s, action, xhr: true, params: params, session: session
|
|
966
|
-
end
|
|
967
|
-
end
|
|
968
946
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
require 'controllers/subscriptions_controller_shared_examples'
|
|
2
2
|
|
|
3
3
|
describe ActivityNotification::SubscriptionsWithDeviseController, type: :controller do
|
|
4
|
+
include ActivityNotification::ControllerSpec::RequestUtility
|
|
5
|
+
|
|
4
6
|
let(:test_user) { create(:confirmed_user) }
|
|
5
7
|
let(:unauthenticated_user) { create(:confirmed_user) }
|
|
6
8
|
let(:test_target) { create(:admin, user: test_user) }
|
|
@@ -14,7 +16,7 @@ describe ActivityNotification::SubscriptionsWithDeviseController, type: :control
|
|
|
14
16
|
sign_in test_user
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
it_behaves_like :
|
|
19
|
+
it_behaves_like :subscriptions_controller
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
context "signed in with devise as unauthenticated user" do
|
|
@@ -78,14 +80,18 @@ describe ActivityNotification::SubscriptionsWithDeviseController, type: :control
|
|
|
78
80
|
end
|
|
79
81
|
end
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
context "without target_id and (typed_target)_id parameters for devise integrated controller with devise_type option" do
|
|
84
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
85
|
+
|
|
86
|
+
describe "GET #index" do
|
|
87
|
+
before do
|
|
88
|
+
sign_in test_target.user
|
|
89
|
+
get_with_compatibility :index, target_params, valid_session
|
|
90
|
+
end
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
get action, params, session
|
|
86
|
-
else
|
|
87
|
-
get action, params: params, session: session
|
|
92
|
+
it "returns 200 as http status code" do
|
|
93
|
+
expect(response.status).to eq(200)
|
|
88
94
|
end
|
|
89
95
|
end
|
|
90
|
-
|
|
96
|
+
end
|
|
91
97
|
end
|