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
|
@@ -10,7 +10,7 @@ shared_examples_for :target do
|
|
|
10
10
|
expect(test_instance.notifications.count).to eq(2)
|
|
11
11
|
expect(test_instance.notifications.earliest).to eq(notification_1)
|
|
12
12
|
expect(test_instance.notifications.latest).to eq(notification_2)
|
|
13
|
-
expect(test_instance.notifications).to
|
|
13
|
+
expect(test_instance.notifications.to_a).to eq(ActivityNotification::Notification.filtered_by_target(test_instance).to_a)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
@@ -24,10 +24,15 @@ shared_examples_for :target do
|
|
|
24
24
|
describe ".set_target_class_defaults" do
|
|
25
25
|
it "set parameter fields as default" do
|
|
26
26
|
described_class.set_target_class_defaults
|
|
27
|
-
expect(described_class._notification_email).to
|
|
28
|
-
expect(described_class._notification_email_allowed).to
|
|
29
|
-
expect(described_class.
|
|
30
|
-
expect(described_class.
|
|
27
|
+
expect(described_class._notification_email).to eq(nil)
|
|
28
|
+
expect(described_class._notification_email_allowed).to eq(ActivityNotification.config.email_enabled)
|
|
29
|
+
expect(described_class._batch_notification_email_allowed).to eq(ActivityNotification.config.email_enabled)
|
|
30
|
+
expect(described_class._notification_subscription_allowed).to eq(ActivityNotification.config.subscription_enabled)
|
|
31
|
+
expect(described_class._notification_action_cable_allowed).to eq(ActivityNotification.config.action_cable_enabled)
|
|
32
|
+
expect(described_class._notification_action_cable_with_devise).to eq(ActivityNotification.config.action_cable_with_devise)
|
|
33
|
+
expect(described_class._notification_devise_resource).to be_a_kind_of(Proc)
|
|
34
|
+
expect(described_class._notification_current_devise_target).to be_a_kind_of(Proc)
|
|
35
|
+
expect(described_class._printable_notification_target_name).to eq(:printable_name)
|
|
31
36
|
end
|
|
32
37
|
end
|
|
33
38
|
|
|
@@ -264,7 +269,8 @@ shared_examples_for :target do
|
|
|
264
269
|
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
265
270
|
end
|
|
266
271
|
|
|
267
|
-
it "returns specified symbol with
|
|
272
|
+
it "returns specified symbol with notifiable
|
|
273
|
+
and key arguments" do
|
|
268
274
|
module AdditionalMethods
|
|
269
275
|
def custom_notification_email_allowed?(notifiable, key)
|
|
270
276
|
true
|
|
@@ -391,6 +397,115 @@ shared_examples_for :target do
|
|
|
391
397
|
end
|
|
392
398
|
end
|
|
393
399
|
|
|
400
|
+
describe "#notification_action_cable_allowed?" do
|
|
401
|
+
context "without any configuration" do
|
|
402
|
+
it "returns ActivityNotification.config.action_cable_enabled without arguments" do
|
|
403
|
+
expect(test_instance.notification_action_cable_allowed?)
|
|
404
|
+
.to eq(ActivityNotification.config.action_cable_enabled)
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
it "returns ActivityNotification.config.action_cable_enabled with arguments" do
|
|
408
|
+
expect(test_instance.notification_action_cable_allowed?(test_notifiable, 'dummy_key'))
|
|
409
|
+
.to eq(ActivityNotification.config.action_cable_enabled)
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
it "returns false as default" do
|
|
413
|
+
expect(test_instance.notification_action_cable_allowed?).to be_falsey
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
context "configured with a field" do
|
|
418
|
+
it "returns specified value" do
|
|
419
|
+
described_class._notification_action_cable_allowed = true
|
|
420
|
+
expect(test_instance.notification_action_cable_allowed?).to eq(true)
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
it "returns specified symbol without argument" do
|
|
424
|
+
module AdditionalMethods
|
|
425
|
+
def custom_notification_action_cable_allowed?
|
|
426
|
+
true
|
|
427
|
+
end
|
|
428
|
+
end
|
|
429
|
+
test_instance.extend(AdditionalMethods)
|
|
430
|
+
described_class._notification_action_cable_allowed = :custom_notification_action_cable_allowed?
|
|
431
|
+
expect(test_instance.notification_action_cable_allowed?).to eq(true)
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
it "returns specified symbol with notifiable and key arguments" do
|
|
435
|
+
module AdditionalMethods
|
|
436
|
+
def custom_notification_action_cable_allowed?(notifiable, key)
|
|
437
|
+
true
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
test_instance.extend(AdditionalMethods)
|
|
441
|
+
described_class._notification_action_cable_allowed = :custom_notification_action_cable_allowed?
|
|
442
|
+
expect(test_instance.notification_action_cable_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
it "returns specified lambda with single target argument" do
|
|
446
|
+
described_class._notification_action_cable_allowed = ->(target){ true }
|
|
447
|
+
expect(test_instance.notification_action_cable_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
it "returns specified lambda with target, notifiable and key arguments" do
|
|
451
|
+
described_class._notification_action_cable_allowed = ->(target, notifiable, key){ true }
|
|
452
|
+
expect(test_instance.notification_action_cable_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
describe "#notification_action_cable_with_devise?" do
|
|
458
|
+
context "without any configuration" do
|
|
459
|
+
it "returns ActivityNotification.config.action_cable_with_devise without arguments" do
|
|
460
|
+
expect(test_instance.notification_action_cable_with_devise?)
|
|
461
|
+
.to eq(ActivityNotification.config.action_cable_with_devise)
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
it "returns false as default" do
|
|
465
|
+
expect(test_instance.notification_action_cable_with_devise?).to be_falsey
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
context "configured with a field" do
|
|
470
|
+
it "returns specified value" do
|
|
471
|
+
described_class._notification_action_cable_with_devise = true
|
|
472
|
+
expect(test_instance.notification_action_cable_with_devise?).to eq(true)
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
it "returns specified symbol without argument" do
|
|
476
|
+
module AdditionalMethods
|
|
477
|
+
def custom_notification_action_cable_with_devise?
|
|
478
|
+
true
|
|
479
|
+
end
|
|
480
|
+
end
|
|
481
|
+
test_instance.extend(AdditionalMethods)
|
|
482
|
+
described_class._notification_action_cable_with_devise = :custom_notification_action_cable_with_devise?
|
|
483
|
+
expect(test_instance.notification_action_cable_with_devise?).to eq(true)
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
it "returns specified lambda with single target argument" do
|
|
487
|
+
described_class._notification_action_cable_with_devise = ->(target){ true }
|
|
488
|
+
expect(test_instance.notification_action_cable_with_devise?).to eq(true)
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
describe "#notification_action_cable_channel_class_name" do
|
|
494
|
+
context "when custom_notification_action_cable_with_devise? returns true" do
|
|
495
|
+
it "returns ActivityNotification::NotificationWithDeviseChannel" do
|
|
496
|
+
described_class._notification_action_cable_with_devise = true
|
|
497
|
+
expect(test_instance.notification_action_cable_channel_class_name).to eq(ActivityNotification::NotificationWithDeviseChannel.name)
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
context "when custom_notification_action_cable_with_devise? returns false" do
|
|
502
|
+
it "returns ActivityNotification::NotificationChannel" do
|
|
503
|
+
described_class._notification_action_cable_with_devise = false
|
|
504
|
+
expect(test_instance.notification_action_cable_channel_class_name).to eq(ActivityNotification::NotificationChannel.name)
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
|
|
394
509
|
describe "#authenticated_with_devise?" do
|
|
395
510
|
context "without any configuration" do
|
|
396
511
|
context "when the current devise resource and called target are different class instance" do
|
|
@@ -612,18 +727,39 @@ shared_examples_for :target do
|
|
|
612
727
|
end
|
|
613
728
|
end
|
|
614
729
|
|
|
615
|
-
context 'with
|
|
730
|
+
context 'with later_than options' do
|
|
616
731
|
it "returns filtered notifications only" do
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
732
|
+
options = { later_than: (@notification1.created_at.in_time_zone + 0.001).iso8601(3) }
|
|
733
|
+
expect(test_instance.notification_index(options)[0]).to eq(@notification3)
|
|
734
|
+
expect(test_instance.notification_index(options).size).to eq(1)
|
|
735
|
+
end
|
|
736
|
+
end
|
|
622
737
|
|
|
738
|
+
context 'with earlier_than options' do
|
|
739
|
+
it "returns filtered notifications only" do
|
|
740
|
+
options = { earlier_than: @notification1.created_at.iso8601(3) }
|
|
741
|
+
expect(test_instance.notification_index(options)[0]).to eq(@notification2)
|
|
742
|
+
expect(test_instance.notification_index(options).size).to eq(1)
|
|
743
|
+
end
|
|
744
|
+
end
|
|
745
|
+
|
|
746
|
+
context 'with custom_filter options' do
|
|
747
|
+
it "returns filtered notifications only" do
|
|
623
748
|
options = { custom_filter: { key: @key } }
|
|
624
749
|
expect(test_instance.notification_index(options)[0]).to eq(@notification3)
|
|
625
750
|
expect(test_instance.notification_index(options).size).to eq(1)
|
|
626
751
|
end
|
|
752
|
+
|
|
753
|
+
it "returns filtered notifications only with filter depending on ORM" do
|
|
754
|
+
options =
|
|
755
|
+
case ActivityNotification.config.orm
|
|
756
|
+
when :active_record then { custom_filter: ["notifications.key = ?", @key] }
|
|
757
|
+
when :mongoid then { custom_filter: { key: {'$eq': @key} } }
|
|
758
|
+
when :dynamoid then { custom_filter: {'key.begins_with': @key} }
|
|
759
|
+
end
|
|
760
|
+
expect(test_instance.notification_index(options)[0]).to eq(@notification3)
|
|
761
|
+
expect(test_instance.notification_index(options).size).to eq(1)
|
|
762
|
+
end
|
|
627
763
|
end
|
|
628
764
|
end
|
|
629
765
|
|
|
@@ -778,10 +914,17 @@ shared_examples_for :target do
|
|
|
778
914
|
|
|
779
915
|
# Wrapper methods of Notification class methods
|
|
780
916
|
|
|
781
|
-
describe "#
|
|
917
|
+
describe "#receive_notification_of" do
|
|
782
918
|
it "is an alias of ActivityNotification::Notification.notify_to" do
|
|
783
919
|
expect(ActivityNotification::Notification).to receive(:notify_to)
|
|
784
|
-
test_instance.
|
|
920
|
+
test_instance.receive_notification_of create(:user)
|
|
921
|
+
end
|
|
922
|
+
end
|
|
923
|
+
|
|
924
|
+
describe "#receive_notification_later_of" do
|
|
925
|
+
it "is an alias of ActivityNotification::Notification.notify_later_to" do
|
|
926
|
+
expect(ActivityNotification::Notification).to receive(:notify_later_to)
|
|
927
|
+
test_instance.receive_notification_later_of create(:user)
|
|
785
928
|
end
|
|
786
929
|
end
|
|
787
930
|
|
|
@@ -793,7 +936,7 @@ shared_examples_for :target do
|
|
|
793
936
|
end
|
|
794
937
|
|
|
795
938
|
|
|
796
|
-
# Methods to be
|
|
939
|
+
# Methods to be overridden
|
|
797
940
|
|
|
798
941
|
describe "#notification_index_with_attributes" do
|
|
799
942
|
context "when the target has no notifications" do
|
|
@@ -880,6 +1023,22 @@ shared_examples_for :target do
|
|
|
880
1023
|
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
881
1024
|
end
|
|
882
1025
|
end
|
|
1026
|
+
|
|
1027
|
+
context 'with later_than options' do
|
|
1028
|
+
it "returns filtered notifications only" do
|
|
1029
|
+
options = { later_than: (@notification1.created_at.in_time_zone + 0.001).iso8601(3) }
|
|
1030
|
+
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification3)
|
|
1031
|
+
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1032
|
+
end
|
|
1033
|
+
end
|
|
1034
|
+
|
|
1035
|
+
context 'with earlier_than options' do
|
|
1036
|
+
it "returns filtered notifications only" do
|
|
1037
|
+
options = { earlier_than: @notification1.created_at.iso8601(3) }
|
|
1038
|
+
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification2)
|
|
1039
|
+
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1040
|
+
end
|
|
1041
|
+
end
|
|
883
1042
|
end
|
|
884
1043
|
|
|
885
1044
|
context "when the target has no unopened notifications" do
|
|
@@ -924,18 +1083,8 @@ shared_examples_for :target do
|
|
|
924
1083
|
end
|
|
925
1084
|
|
|
926
1085
|
if ActivityNotification.config.orm == :active_record
|
|
927
|
-
it "calls with_target, with_notifiable and
|
|
928
|
-
expect(
|
|
929
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifiable)
|
|
930
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifier)
|
|
931
|
-
test_instance.unopened_notification_index_with_attributes
|
|
932
|
-
end
|
|
933
|
-
|
|
934
|
-
it "does not call with_group" do
|
|
935
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:target)
|
|
936
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifiable)
|
|
937
|
-
expect(ActiveRecord::Base).not_to receive(:includes).with(:group)
|
|
938
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifier)
|
|
1086
|
+
it "calls with_target, with_notifiable, with_notifier and does not call with_group" do
|
|
1087
|
+
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_notifier)
|
|
939
1088
|
test_instance.unopened_notification_index_with_attributes
|
|
940
1089
|
end
|
|
941
1090
|
end
|
|
@@ -950,10 +1099,7 @@ shared_examples_for :target do
|
|
|
950
1099
|
|
|
951
1100
|
if ActivityNotification.config.orm == :active_record
|
|
952
1101
|
it "calls with_group" do
|
|
953
|
-
expect(
|
|
954
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifiable)
|
|
955
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:group)
|
|
956
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifier)
|
|
1102
|
+
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_group, :with_notifier)
|
|
957
1103
|
test_instance.unopened_notification_index_with_attributes
|
|
958
1104
|
end
|
|
959
1105
|
end
|
|
@@ -986,18 +1132,8 @@ shared_examples_for :target do
|
|
|
986
1132
|
end
|
|
987
1133
|
|
|
988
1134
|
if ActivityNotification.config.orm == :active_record
|
|
989
|
-
it "calls with_target, with_notifiable and
|
|
990
|
-
expect(
|
|
991
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifiable)
|
|
992
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifier)
|
|
993
|
-
test_instance.opened_notification_index_with_attributes
|
|
994
|
-
end
|
|
995
|
-
|
|
996
|
-
it "does not call with_group" do
|
|
997
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:target)
|
|
998
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifiable)
|
|
999
|
-
expect(ActiveRecord::Base).not_to receive(:includes).with(:group)
|
|
1000
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifier)
|
|
1135
|
+
it "calls with_target, with_notifiable, with_notifier and does not call with_group" do
|
|
1136
|
+
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_notifier)
|
|
1001
1137
|
test_instance.opened_notification_index_with_attributes
|
|
1002
1138
|
end
|
|
1003
1139
|
end
|
|
@@ -1012,10 +1148,7 @@ shared_examples_for :target do
|
|
|
1012
1148
|
|
|
1013
1149
|
if ActivityNotification.config.orm == :active_record
|
|
1014
1150
|
it "calls with_group" do
|
|
1015
|
-
expect(
|
|
1016
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifiable)
|
|
1017
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:group)
|
|
1018
|
-
expect(ActiveRecord::Base).to receive(:includes).with(:notifier)
|
|
1151
|
+
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_group, :with_notifier)
|
|
1019
1152
|
test_instance.opened_notification_index_with_attributes
|
|
1020
1153
|
end
|
|
1021
1154
|
end
|
|
@@ -4,17 +4,23 @@ shared_examples_for :renderable do
|
|
|
4
4
|
let(:test_instance) { create(test_class_name, target: test_target) }
|
|
5
5
|
let(:target_type_key) { 'user' }
|
|
6
6
|
|
|
7
|
-
let(:notifier_name)
|
|
8
|
-
let(:article_title)
|
|
9
|
-
let(:
|
|
10
|
-
let(:
|
|
11
|
-
let(:
|
|
12
|
-
let(:
|
|
13
|
-
let(:
|
|
14
|
-
let(:
|
|
15
|
-
let(:
|
|
16
|
-
let(:
|
|
17
|
-
let(:
|
|
7
|
+
let(:notifier_name) { 'foo' }
|
|
8
|
+
let(:article_title) { 'bar' }
|
|
9
|
+
let(:group_notification_count) { 4 }
|
|
10
|
+
let(:group_member_count) { 3 }
|
|
11
|
+
let(:simple_text_key) { 'article.create' }
|
|
12
|
+
let(:params_text_key) { 'article.update' }
|
|
13
|
+
let(:group_text_key) { 'comment.reply' }
|
|
14
|
+
let(:plural_text_key) { 'comment.post' }
|
|
15
|
+
let(:simple_text_original) { 'Article has been created' }
|
|
16
|
+
let(:params_text_original) { 'Article "%{article_title}" has been updated' }
|
|
17
|
+
let(:plural_text_original_one) { "<p>%{notifier_name} posted a comment on your article %{article_title}</p>" }
|
|
18
|
+
let(:plural_text_original_other) { "<p>%{notifier_name} posted %{count} comments on your article %{article_title}</p>" }
|
|
19
|
+
let(:group_text_original) { "<p>%{notifier_name} and %{group_member_count} other people replied %{group_notification_count} times to your comment</p>" }
|
|
20
|
+
let(:params_text_embedded) { 'Article "bar" has been updated' }
|
|
21
|
+
let(:group_text_embedded) { "<p>foo and 3 other people replied 4 times to your comment</p>" }
|
|
22
|
+
let(:plural_text_embedded_one) { "<p>foo posted a comment on your article bar</p>" }
|
|
23
|
+
let(:plural_text_embedded_other) { "<p>foo posted 4 comments on your article bar</p>" }
|
|
18
24
|
|
|
19
25
|
describe "i18n configuration" do
|
|
20
26
|
it "has key configured for simple text" do
|
|
@@ -26,17 +32,30 @@ shared_examples_for :renderable do
|
|
|
26
32
|
expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text"))
|
|
27
33
|
.to eq(params_text_original)
|
|
28
34
|
expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text",
|
|
29
|
-
|
|
35
|
+
article_title: article_title))
|
|
30
36
|
.to eq(params_text_embedded)
|
|
31
37
|
end
|
|
32
38
|
|
|
33
|
-
it "has key configured with embedded params including group_member_count" do
|
|
39
|
+
it "has key configured with embedded params including group_member_count and group_notification_count" do
|
|
34
40
|
expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text"))
|
|
35
41
|
.to eq(group_text_original)
|
|
36
42
|
expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text",
|
|
37
|
-
{notifier_name: notifier_name, group_member_count: group_member_count}))
|
|
43
|
+
**{ notifier_name: notifier_name, group_member_count: group_member_count, group_notification_count: group_notification_count }))
|
|
38
44
|
.to eq(group_text_embedded)
|
|
39
45
|
end
|
|
46
|
+
|
|
47
|
+
it "has key configured with plurals" do
|
|
48
|
+
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text")[:one])
|
|
49
|
+
.to eq(plural_text_original_one)
|
|
50
|
+
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text")[:other])
|
|
51
|
+
.to eq(plural_text_original_other)
|
|
52
|
+
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text",
|
|
53
|
+
**{ article_title: article_title, notifier_name: notifier_name, count: 1 }))
|
|
54
|
+
.to eq(plural_text_embedded_one)
|
|
55
|
+
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text",
|
|
56
|
+
**{ article_title: article_title, notifier_name: notifier_name, count: group_notification_count }))
|
|
57
|
+
.to eq(plural_text_embedded_other)
|
|
58
|
+
end
|
|
40
59
|
end
|
|
41
60
|
|
|
42
61
|
describe "as public instance methods" do
|
|
@@ -83,7 +102,7 @@ shared_examples_for :renderable do
|
|
|
83
102
|
context "when the text has embedded parameters" do
|
|
84
103
|
it "uses text with embedded parameters" do
|
|
85
104
|
test_instance.key = params_text_key
|
|
86
|
-
expect(test_instance.text({
|
|
105
|
+
expect(test_instance.text({article_title: article_title}))
|
|
87
106
|
.to eq(params_text_embedded)
|
|
88
107
|
end
|
|
89
108
|
|
|
@@ -107,4 +126,4 @@ shared_examples_for :renderable do
|
|
|
107
126
|
# #layout_path
|
|
108
127
|
|
|
109
128
|
end
|
|
110
|
-
end
|
|
129
|
+
end
|
data/spec/config_spec.rb
CHANGED
|
@@ -7,7 +7,7 @@ describe ActivityNotification::Config do
|
|
|
7
7
|
expect(ActivityNotification::Mailer).to receive(:send_notification_email).and_call_original
|
|
8
8
|
notification.send_notification_email send_later: false
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
it "is not configured with CustomNotificationMailer" do
|
|
12
12
|
expect(CustomNotificationMailer).not_to receive(:send_notification_email).and_call_original
|
|
13
13
|
notification.send_notification_email send_later: false
|
|
@@ -31,4 +31,55 @@ describe ActivityNotification::Config do
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
describe "config.store_with_associated_records" do
|
|
36
|
+
let(:target) { create(:confirmed_user) }
|
|
37
|
+
|
|
38
|
+
context "when it is configured as true" do
|
|
39
|
+
if ActivityNotification.config.orm == :active_record
|
|
40
|
+
it "raises ActivityNotification::ConfigError when you use active_record ORM" do
|
|
41
|
+
expect { ActivityNotification.config.store_with_associated_records = true }.to raise_error(ActivityNotification::ConfigError)
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
before do
|
|
45
|
+
@original = ActivityNotification.config.store_with_associated_records
|
|
46
|
+
ActivityNotification.config.store_with_associated_records = true
|
|
47
|
+
load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
|
|
48
|
+
@notification = create(:notification, target: target)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
after do
|
|
52
|
+
ActivityNotification.config.store_with_associated_records = @original
|
|
53
|
+
load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "stores notification with associated records" do
|
|
57
|
+
expect(@notification.target).to eq(target)
|
|
58
|
+
expect(@notification.stored_target["id"].to_s).to eq(target.id.to_s)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "when it is configured as false" do
|
|
64
|
+
before do
|
|
65
|
+
@original = ActivityNotification.config.store_with_associated_records
|
|
66
|
+
ActivityNotification.config.store_with_associated_records = false
|
|
67
|
+
load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
|
|
68
|
+
@notification = create(:notification, target: target)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
after do
|
|
72
|
+
ActivityNotification.config.store_with_associated_records = @original
|
|
73
|
+
load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "does not store notification with associated records" do
|
|
77
|
+
expect(@notification.target).to eq(target)
|
|
78
|
+
begin
|
|
79
|
+
expect(@notification.stored_target).to be_nil
|
|
80
|
+
rescue NoMethodError
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
34
85
|
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
module ActivityNotification
|
|
2
|
+
module ControllerSpec
|
|
3
|
+
module RequestUtility
|
|
4
|
+
def get_with_compatibility action, params, session
|
|
5
|
+
get action, params: params, session: session
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def post_with_compatibility action, params, session
|
|
9
|
+
post action, params: params, session: session
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def put_with_compatibility action, params, session
|
|
13
|
+
put action, params: params, session: session
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def delete_with_compatibility action, params, session
|
|
17
|
+
delete action, params: params, session: session
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def xhr_with_compatibility method, action, params, session
|
|
21
|
+
send method.to_s, action, xhr: true, params: params, session: session
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module ApiResponseUtility
|
|
26
|
+
def response_json
|
|
27
|
+
JSON.parse(response.body)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def assert_json_with_array_size(json_array, size)
|
|
31
|
+
expect(json_array.size).to eq(size)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def assert_json_with_object(json_object, object)
|
|
35
|
+
expect(json_object['id'].to_s).to eq(object.id.to_s)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def assert_json_with_object_array(json_array, expected_object_array)
|
|
39
|
+
assert_json_with_array_size(json_array, expected_object_array.size)
|
|
40
|
+
expected_object_array.each_with_index do |json_object, index|
|
|
41
|
+
assert_json_with_object(json_object, expected_object_array[index])
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def assert_error_response(code)
|
|
46
|
+
expect(response_json['gem']).to eq('activity_notification')
|
|
47
|
+
expect(response_json['error']['code']).to eq(code)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
module CommitteeUtility
|
|
52
|
+
extend ActiveSupport::Concern
|
|
53
|
+
included do
|
|
54
|
+
include Committee::Rails::Test::Methods
|
|
55
|
+
|
|
56
|
+
def api_path
|
|
57
|
+
"/#{root_path}/#{target_type}/#{test_target.id}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def schema_path
|
|
61
|
+
Rails.root.join('..', 'openapi.json')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def write_schema_file(schema_json)
|
|
65
|
+
File.open(schema_path, "w") { |file| file.write(schema_json) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def read_schema_file
|
|
69
|
+
JSON.parse(File.read(schema_path))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def committee_options
|
|
73
|
+
@committee_options ||= { schema: Committee::Drivers::load_from_file(schema_path), prefix: root_path, validate_success_only: true, parse_response_by_content_type: false }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def get_with_compatibility path, options = {}
|
|
77
|
+
get path, **options
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def post_with_compatibility path, options = {}
|
|
81
|
+
post path, **options
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def put_with_compatibility path, options = {}
|
|
85
|
+
put path, **options
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def delete_with_compatibility path, options = {}
|
|
89
|
+
delete path, **options
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def assert_all_schema_confirm(response, status)
|
|
93
|
+
expect(response).to have_http_status(status)
|
|
94
|
+
assert_request_schema_confirm
|
|
95
|
+
assert_response_schema_confirm
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|