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
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
# To run as single test for debugging
|
|
2
|
+
# require Rails.root.join('../../spec/concerns/apis/notification_api_spec.rb').to_s
|
|
3
|
+
# require Rails.root.join('../../spec/concerns/renderable_spec.rb').to_s
|
|
4
|
+
|
|
1
5
|
describe ActivityNotification::Notification, type: :model do
|
|
2
6
|
|
|
3
7
|
it_behaves_like :notification_api
|
|
4
8
|
it_behaves_like :renderable
|
|
5
9
|
|
|
6
10
|
describe "with association" do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
context "belongs to target" do
|
|
12
|
+
before do
|
|
13
|
+
@target = create(:confirmed_user)
|
|
14
|
+
@notification = create(:notification, target: @target)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "responds to target" do
|
|
18
|
+
expect(@notification.reload.target).to eq(@target)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "responds to target_id" do
|
|
22
|
+
expect(@notification.reload.target_id.to_s).to eq(@target.id.to_s)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "responds to target_type" do
|
|
26
|
+
expect(@notification.reload.target_type).to eq("User")
|
|
27
|
+
end
|
|
11
28
|
end
|
|
12
29
|
|
|
13
30
|
it "belongs to notifiable" do
|
|
@@ -39,21 +56,36 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
39
56
|
notification = create(:notification, notifier: notifier)
|
|
40
57
|
expect(notification.reload.notifier).to eq(notifier)
|
|
41
58
|
end
|
|
59
|
+
|
|
60
|
+
context "returns as_json including associated models" do
|
|
61
|
+
it "returns as_json with include option as Symbol" do
|
|
62
|
+
notification = create(:notification)
|
|
63
|
+
expect(notification.as_json(include: :target)["target"]["id"].to_s).to eq(notification.target.id.to_s)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "returns as_json with include option as Array" do
|
|
67
|
+
notification = create(:notification)
|
|
68
|
+
expect(notification.as_json(include: [:target])["target"]["id"].to_s).to eq(notification.target.id.to_s)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "returns as_json with include option as Hash" do
|
|
72
|
+
notification = create(:notification)
|
|
73
|
+
expect(notification.as_json(include: { target: { methods: [:printable_target_name] } })["target"]["id"].to_s).to eq(notification.target.id.to_s)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
42
76
|
end
|
|
43
77
|
|
|
44
78
|
describe "with serializable column" do
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(notification.reload.parameters).to eq(parameters)
|
|
50
|
-
end
|
|
79
|
+
it "has parameters for hash with symbol" do
|
|
80
|
+
parameters = {a: 1, b: 2, c: 3}
|
|
81
|
+
notification = create(:notification, parameters: parameters)
|
|
82
|
+
expect(notification.reload.parameters.symbolize_keys).to eq(parameters)
|
|
51
83
|
end
|
|
52
84
|
|
|
53
85
|
it "has parameters for hash with string" do
|
|
54
86
|
parameters = {'a' => 1, 'b' => 2, 'c' => 3}
|
|
55
87
|
notification = create(:notification, parameters: parameters)
|
|
56
|
-
expect(notification.reload.parameters).to eq(parameters)
|
|
88
|
+
expect(notification.reload.parameters.stringify_keys).to eq(parameters)
|
|
57
89
|
end
|
|
58
90
|
end
|
|
59
91
|
|
|
@@ -67,19 +99,19 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
67
99
|
it "is invalid with blank target" do
|
|
68
100
|
@notification.target = nil
|
|
69
101
|
expect(@notification).to be_invalid
|
|
70
|
-
expect(@notification.errors[:target]
|
|
102
|
+
expect(@notification.errors[:target]).not_to be_empty
|
|
71
103
|
end
|
|
72
104
|
|
|
73
105
|
it "is invalid with blank notifiable" do
|
|
74
106
|
@notification.notifiable = nil
|
|
75
107
|
expect(@notification).to be_invalid
|
|
76
|
-
expect(@notification.errors[:notifiable]
|
|
108
|
+
expect(@notification.errors[:notifiable]).not_to be_empty
|
|
77
109
|
end
|
|
78
110
|
|
|
79
111
|
it "is invalid with blank key" do
|
|
80
112
|
@notification.key = nil
|
|
81
113
|
expect(@notification).to be_invalid
|
|
82
|
-
expect(@notification.errors[:key]
|
|
114
|
+
expect(@notification.errors[:key]).not_to be_empty
|
|
83
115
|
end
|
|
84
116
|
end
|
|
85
117
|
|
|
@@ -99,34 +131,34 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
99
131
|
expect(notifications.unopened_only.first).to eq(@unopened_group_owner)
|
|
100
132
|
expect(notifications.opened_only!.first).to eq(@opened_group_owner)
|
|
101
133
|
end
|
|
102
|
-
|
|
134
|
+
|
|
103
135
|
it "works with group_members_only scope" do
|
|
104
136
|
notifications = ActivityNotification::Notification.group_members_only
|
|
105
137
|
expect(notifications.to_a.size).to eq(2)
|
|
106
138
|
expect(notifications.unopened_only.first).to eq(@unopened_group_member)
|
|
107
139
|
expect(notifications.opened_only!.first).to eq(@opened_group_member)
|
|
108
140
|
end
|
|
109
|
-
|
|
141
|
+
|
|
110
142
|
it "works with unopened_only scope" do
|
|
111
143
|
notifications = ActivityNotification::Notification.unopened_only
|
|
112
144
|
expect(notifications.to_a.size).to eq(2)
|
|
113
145
|
expect(notifications.group_owners_only.first).to eq(@unopened_group_owner)
|
|
114
146
|
expect(notifications.group_members_only.first).to eq(@unopened_group_member)
|
|
115
147
|
end
|
|
116
|
-
|
|
148
|
+
|
|
117
149
|
it "works with unopened_index scope" do
|
|
118
150
|
notifications = ActivityNotification::Notification.unopened_index
|
|
119
151
|
expect(notifications.to_a.size).to eq(1)
|
|
120
152
|
expect(notifications.first).to eq(@unopened_group_owner)
|
|
121
153
|
end
|
|
122
|
-
|
|
154
|
+
|
|
123
155
|
it "works with opened_only! scope" do
|
|
124
156
|
notifications = ActivityNotification::Notification.opened_only!
|
|
125
157
|
expect(notifications.to_a.size).to eq(2)
|
|
126
158
|
expect(notifications.group_owners_only.first).to eq(@opened_group_owner)
|
|
127
159
|
expect(notifications.group_members_only.first).to eq(@opened_group_member)
|
|
128
160
|
end
|
|
129
|
-
|
|
161
|
+
|
|
130
162
|
context "with opened_only scope" do
|
|
131
163
|
it "works" do
|
|
132
164
|
notifications = ActivityNotification::Notification.opened_only(4)
|
|
@@ -134,39 +166,39 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
134
166
|
expect(notifications.group_owners_only.first).to eq(@opened_group_owner)
|
|
135
167
|
expect(notifications.group_members_only.first).to eq(@opened_group_member)
|
|
136
168
|
end
|
|
137
|
-
|
|
169
|
+
|
|
138
170
|
it "works with limit" do
|
|
139
171
|
notifications = ActivityNotification::Notification.opened_only(1)
|
|
140
172
|
expect(notifications.to_a.size).to eq(1)
|
|
141
173
|
end
|
|
142
174
|
end
|
|
143
|
-
|
|
175
|
+
|
|
144
176
|
context "with opened_index scope" do
|
|
145
177
|
it "works" do
|
|
146
178
|
notifications = ActivityNotification::Notification.opened_index(4)
|
|
147
179
|
expect(notifications.to_a.size).to eq(1)
|
|
148
180
|
expect(notifications.first).to eq(@opened_group_owner)
|
|
149
181
|
end
|
|
150
|
-
|
|
182
|
+
|
|
151
183
|
it "works with limit" do
|
|
152
184
|
notifications = ActivityNotification::Notification.opened_index(0)
|
|
153
185
|
expect(notifications.to_a.size).to eq(0)
|
|
154
186
|
end
|
|
155
187
|
end
|
|
156
|
-
|
|
188
|
+
|
|
157
189
|
it "works with unopened_index_group_members_only scope" do
|
|
158
190
|
notifications = ActivityNotification::Notification.unopened_index_group_members_only
|
|
159
191
|
expect(notifications.to_a.size).to eq(1)
|
|
160
192
|
expect(notifications.first).to eq(@unopened_group_member)
|
|
161
193
|
end
|
|
162
|
-
|
|
194
|
+
|
|
163
195
|
context "with opened_index_group_members_only scope" do
|
|
164
196
|
it "works" do
|
|
165
197
|
notifications = ActivityNotification::Notification.opened_index_group_members_only(4)
|
|
166
198
|
expect(notifications.to_a.size).to eq(1)
|
|
167
199
|
expect(notifications.first).to eq(@opened_group_member)
|
|
168
200
|
end
|
|
169
|
-
|
|
201
|
+
|
|
170
202
|
it "works with limit" do
|
|
171
203
|
notifications = ActivityNotification::Notification.opened_index_group_members_only(0)
|
|
172
204
|
expect(notifications.to_a.size).to eq(0)
|
|
@@ -239,7 +271,7 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
239
271
|
expect(notifications.first).to eq(@notification_2)
|
|
240
272
|
end
|
|
241
273
|
end
|
|
242
|
-
|
|
274
|
+
|
|
243
275
|
context 'with filtered_by_group options' do
|
|
244
276
|
it "works with filtered_by_options scope" do
|
|
245
277
|
notifications = ActivityNotification::Notification.filtered_by_options({ filtered_by_group: @group_1 })
|
|
@@ -276,18 +308,24 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
276
308
|
|
|
277
309
|
context 'with custom_filter options' do
|
|
278
310
|
it "works with filtered_by_options scope" do
|
|
279
|
-
if ActivityNotification.config.orm == :active_record
|
|
280
|
-
notifications = ActivityNotification::Notification.filtered_by_options({ custom_filter: ["notifications.key = ?", @key_1] })
|
|
281
|
-
expect(notifications.to_a.size).to eq(1)
|
|
282
|
-
expect(notifications.first).to eq(@notification_1)
|
|
283
|
-
end
|
|
284
|
-
|
|
285
311
|
notifications = ActivityNotification::Notification.filtered_by_options({ custom_filter: { key: @key_2 } })
|
|
286
312
|
expect(notifications.to_a.size).to eq(1)
|
|
287
313
|
expect(notifications.first).to eq(@notification_2)
|
|
288
314
|
end
|
|
315
|
+
|
|
316
|
+
it "works with filtered_by_options scope with filter depending on ORM" do
|
|
317
|
+
options =
|
|
318
|
+
case ActivityNotification.config.orm
|
|
319
|
+
when :active_record then { custom_filter: ["notifications.key = ?", @key_1] }
|
|
320
|
+
when :mongoid then { custom_filter: { key: {'$eq': @key_1} } }
|
|
321
|
+
when :dynamoid then { custom_filter: {'key.begins_with': @key_1} }
|
|
322
|
+
end
|
|
323
|
+
notifications = ActivityNotification::Notification.filtered_by_options(options)
|
|
324
|
+
expect(notifications.to_a.size).to eq(1)
|
|
325
|
+
expect(notifications.first).to eq(@notification_1)
|
|
326
|
+
end
|
|
289
327
|
end
|
|
290
|
-
|
|
328
|
+
|
|
291
329
|
context 'with no options' do
|
|
292
330
|
it "works with filtered_by_options scope" do
|
|
293
331
|
notifications = ActivityNotification::Notification.filtered_by_options
|
|
@@ -300,37 +338,135 @@ describe ActivityNotification::Notification, type: :model do
|
|
|
300
338
|
context "to make order by created_at" do
|
|
301
339
|
before do
|
|
302
340
|
ActivityNotification::Notification.delete_all
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
341
|
+
@target = create(:confirmed_user)
|
|
342
|
+
unopened_group_owner = create(:notification, target: @target, group_owner: nil)
|
|
343
|
+
unopened_group_member = create(:notification, target: @target, group_owner: unopened_group_owner, created_at: unopened_group_owner.created_at + 10.second)
|
|
344
|
+
opened_group_owner = create(:notification, target: @target, group_owner: nil, opened_at: Time.current, created_at: unopened_group_owner.created_at + 20.second)
|
|
345
|
+
opened_group_member = create(:notification, target: @target, group_owner: opened_group_owner, opened_at: Time.current, created_at: unopened_group_owner.created_at + 30.second)
|
|
307
346
|
@earliest_notification = unopened_group_owner
|
|
308
347
|
@latest_notification = opened_group_member
|
|
309
348
|
end
|
|
310
349
|
|
|
311
|
-
|
|
312
|
-
|
|
350
|
+
unless ActivityNotification.config.orm == :dynamoid
|
|
351
|
+
context "using ORM other than dynamoid, you can directly call latest/earliest order method from class objects" do
|
|
352
|
+
|
|
353
|
+
it "works with latest_order scope" do
|
|
354
|
+
notifications = ActivityNotification::Notification.latest_order
|
|
355
|
+
expect(notifications.to_a.size).to eq(4)
|
|
356
|
+
expect(notifications.first).to eq(@latest_notification)
|
|
357
|
+
expect(notifications.last).to eq(@earliest_notification)
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
it "works with earliest_order scope" do
|
|
361
|
+
notifications = ActivityNotification::Notification.earliest_order
|
|
362
|
+
expect(notifications.to_a.size).to eq(4)
|
|
363
|
+
expect(notifications.first).to eq(@earliest_notification)
|
|
364
|
+
expect(notifications.last).to eq(@latest_notification)
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
it "returns the latest notification with latest scope" do
|
|
368
|
+
notification = ActivityNotification::Notification.latest
|
|
369
|
+
expect(notification).to eq(@latest_notification)
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
it "returns the earliest notification with earliest scope" do
|
|
373
|
+
notification = ActivityNotification::Notification.earliest
|
|
374
|
+
expect(notification).to eq(@earliest_notification)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
end
|
|
378
|
+
else
|
|
379
|
+
context "using dynamoid, you can call latest/earliest order method only with query using partition key of Global Secondary Index" do
|
|
380
|
+
|
|
381
|
+
it "works with latest_order scope" do
|
|
382
|
+
notifications = ActivityNotification::Notification.filtered_by_target(@target).latest_order
|
|
383
|
+
expect(notifications.to_a.size).to eq(4)
|
|
384
|
+
expect(notifications.first).to eq(@latest_notification)
|
|
385
|
+
expect(notifications.last).to eq(@earliest_notification)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
it "works with earliest_order scope" do
|
|
389
|
+
notifications = ActivityNotification::Notification.filtered_by_target(@target).earliest_order
|
|
390
|
+
expect(notifications.to_a.size).to eq(4)
|
|
391
|
+
expect(notifications.first).to eq(@earliest_notification)
|
|
392
|
+
expect(notifications.last).to eq(@latest_notification)
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it "returns the latest notification with latest scope" do
|
|
396
|
+
notification = ActivityNotification::Notification.filtered_by_target(@target).latest
|
|
397
|
+
expect(notification).to eq(@latest_notification)
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
it "returns the earliest notification with earliest scope" do
|
|
401
|
+
notification = ActivityNotification::Notification.filtered_by_target(@target).earliest
|
|
402
|
+
expect(notification).to eq(@earliest_notification)
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
it "works with latest_order! scope" do
|
|
409
|
+
notifications = ActivityNotification::Notification.latest_order!
|
|
313
410
|
expect(notifications.to_a.size).to eq(4)
|
|
314
411
|
expect(notifications.first).to eq(@latest_notification)
|
|
315
412
|
expect(notifications.last).to eq(@earliest_notification)
|
|
316
413
|
end
|
|
317
414
|
|
|
318
|
-
it "works with
|
|
319
|
-
notifications = ActivityNotification::Notification.
|
|
415
|
+
it "works with latest_order!(reverse=true) scope" do
|
|
416
|
+
notifications = ActivityNotification::Notification.latest_order!(true)
|
|
320
417
|
expect(notifications.to_a.size).to eq(4)
|
|
321
418
|
expect(notifications.first).to eq(@earliest_notification)
|
|
322
419
|
expect(notifications.last).to eq(@latest_notification)
|
|
323
420
|
end
|
|
324
421
|
|
|
325
|
-
it "
|
|
326
|
-
|
|
422
|
+
it "works with earliest_order! scope" do
|
|
423
|
+
notifications = ActivityNotification::Notification.earliest_order!
|
|
424
|
+
expect(notifications.to_a.size).to eq(4)
|
|
425
|
+
expect(notifications.first).to eq(@earliest_notification)
|
|
426
|
+
expect(notifications.last).to eq(@latest_notification)
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
it "returns the latest notification with latest! scope" do
|
|
430
|
+
notification = ActivityNotification::Notification.latest!
|
|
327
431
|
expect(notification).to eq(@latest_notification)
|
|
328
432
|
end
|
|
329
433
|
|
|
330
|
-
it "returns the earliest notification with earliest scope" do
|
|
331
|
-
notification = ActivityNotification::Notification.earliest
|
|
434
|
+
it "returns the earliest notification with earliest! scope" do
|
|
435
|
+
notification = ActivityNotification::Notification.earliest!
|
|
332
436
|
expect(notification).to eq(@earliest_notification)
|
|
333
437
|
end
|
|
334
438
|
end
|
|
439
|
+
|
|
440
|
+
context "to include with associated records" do
|
|
441
|
+
before do
|
|
442
|
+
ActivityNotification::Notification.delete_all
|
|
443
|
+
create(:notification)
|
|
444
|
+
@notifications = ActivityNotification::Notification.filtered_by_key("default.default")
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
it "works with_target" do
|
|
448
|
+
expect(@notifications.with_target.count).to eq(1)
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
it "works with_notifiable" do
|
|
452
|
+
expect(@notifications.with_notifiable.count).to eq(1)
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
it "works with_group" do
|
|
456
|
+
expect(@notifications.with_group.count).to eq(1)
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
it "works with_group_owner" do
|
|
460
|
+
expect(@notifications.with_group_owner.count).to eq(1)
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
it "works with_group_members" do
|
|
464
|
+
expect(@notifications.with_group_members.count).to eq(1)
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
it "works with_notifier" do
|
|
468
|
+
expect(@notifications.with_notifier.count).to eq(1)
|
|
469
|
+
end
|
|
470
|
+
end
|
|
335
471
|
end
|
|
336
472
|
end
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# To run as single test for debugging
|
|
2
|
+
# require Rails.root.join('../../spec/concerns/apis/subscription_api_spec.rb').to_s
|
|
3
|
+
|
|
1
4
|
describe ActivityNotification::Subscription, type: :model do
|
|
2
5
|
|
|
3
6
|
it_behaves_like :subscription_api
|
|
@@ -8,6 +11,14 @@ describe ActivityNotification::Subscription, type: :model do
|
|
|
8
11
|
subscription = create(:subscription, target: target)
|
|
9
12
|
expect(subscription.reload.target).to eq(target)
|
|
10
13
|
end
|
|
14
|
+
|
|
15
|
+
it "several targets can subscribe to the same key" do
|
|
16
|
+
target = create(:confirmed_user)
|
|
17
|
+
target2 = create(:confirmed_user)
|
|
18
|
+
subscription_1 = create(:subscription, target: target, key: 'key.1')
|
|
19
|
+
subscription_2 = create(:subscription, target: target2, key: 'key.1')
|
|
20
|
+
expect(subscription_2).to be_valid
|
|
21
|
+
end
|
|
11
22
|
end
|
|
12
23
|
|
|
13
24
|
describe "with validation" do
|
|
@@ -29,19 +40,6 @@ describe ActivityNotification::Subscription, type: :model do
|
|
|
29
40
|
expect(@subscription.errors[:key].size).to eq(1)
|
|
30
41
|
end
|
|
31
42
|
|
|
32
|
-
#TODO
|
|
33
|
-
# it "is invalid with non boolean value of subscribing" do
|
|
34
|
-
# @subscription.subscribing = 'hoge'
|
|
35
|
-
# expect(@subscription).to be_invalid
|
|
36
|
-
# expect(@subscription.errors[:subscribing].size).to eq(1)
|
|
37
|
-
# end
|
|
38
|
-
#
|
|
39
|
-
# it "is invalid with non boolean value of subscribing_to_email" do
|
|
40
|
-
# @subscription.subscribing_to_email = 'hoge'
|
|
41
|
-
# expect(@subscription).to be_invalid
|
|
42
|
-
# expect(@subscription.errors[:subscribing_to_email].size).to eq(1)
|
|
43
|
-
# end
|
|
44
|
-
|
|
45
43
|
it "is invalid with true as subscribing_to_email and false as subscribing" do
|
|
46
44
|
@subscription.subscribing = false
|
|
47
45
|
@subscription.subscribing_to_email = true
|
|
@@ -92,16 +90,22 @@ describe ActivityNotification::Subscription, type: :model do
|
|
|
92
90
|
|
|
93
91
|
context 'with custom_filter options' do
|
|
94
92
|
it "works with filtered_by_options scope" do
|
|
95
|
-
if ActivityNotification.config.orm == :active_record
|
|
96
|
-
subscriptions = ActivityNotification::Subscription.filtered_by_options({ custom_filter: ["subscriptions.key = ?", @key_1] })
|
|
97
|
-
expect(subscriptions.size).to eq(1)
|
|
98
|
-
expect(subscriptions.first).to eq(@subscription_1)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
93
|
subscriptions = ActivityNotification::Subscription.filtered_by_options({ custom_filter: { key: @key_2 } })
|
|
102
94
|
expect(subscriptions.size).to eq(1)
|
|
103
95
|
expect(subscriptions.first).to eq(@subscription_2)
|
|
104
96
|
end
|
|
97
|
+
|
|
98
|
+
it "works with filtered_by_options scope with filter depending on ORM" do
|
|
99
|
+
options =
|
|
100
|
+
case ActivityNotification.config.orm
|
|
101
|
+
when :active_record then { custom_filter: ["subscriptions.key = ?", @key_1] }
|
|
102
|
+
when :mongoid then { custom_filter: { key: {'$eq': @key_1} } }
|
|
103
|
+
when :dynamoid then { custom_filter: {'key.begins_with': @key_1} }
|
|
104
|
+
end
|
|
105
|
+
subscriptions = ActivityNotification::Subscription.filtered_by_options(options)
|
|
106
|
+
expect(subscriptions.size).to eq(1)
|
|
107
|
+
expect(subscriptions.first).to eq(@subscription_1)
|
|
108
|
+
end
|
|
105
109
|
end
|
|
106
110
|
|
|
107
111
|
context 'with no options' do
|
|
@@ -116,21 +120,67 @@ describe ActivityNotification::Subscription, type: :model do
|
|
|
116
120
|
context "to make order by created_at" do
|
|
117
121
|
before do
|
|
118
122
|
ActivityNotification::Subscription.delete_all
|
|
119
|
-
@
|
|
120
|
-
@
|
|
121
|
-
@
|
|
122
|
-
@
|
|
123
|
+
@target = create(:confirmed_user)
|
|
124
|
+
@subscription_1 = create(:subscription, target: @target, key: 'key.1')
|
|
125
|
+
@subscription_2 = create(:subscription, target: @target, key: 'key.2', created_at: @subscription_1.created_at + 10.second)
|
|
126
|
+
@subscription_3 = create(:subscription, target: @target, key: 'key.3', created_at: @subscription_1.created_at + 20.second)
|
|
127
|
+
@subscription_4 = create(:subscription, target: @target, key: 'key.4', created_at: @subscription_1.created_at + 30.second)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
unless ActivityNotification.config.orm == :dynamoid
|
|
131
|
+
context "using ORM other than dynamoid, you can directly call latest/earliest order method from class objects" do
|
|
132
|
+
|
|
133
|
+
it "works with latest_order scope" do
|
|
134
|
+
subscriptions = ActivityNotification::Subscription.latest_order
|
|
135
|
+
expect(subscriptions.size).to eq(4)
|
|
136
|
+
expect(subscriptions.first).to eq(@subscription_4)
|
|
137
|
+
expect(subscriptions.last).to eq(@subscription_1)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "works with earliest_order scope" do
|
|
141
|
+
subscriptions = ActivityNotification::Subscription.earliest_order
|
|
142
|
+
expect(subscriptions.size).to eq(4)
|
|
143
|
+
expect(subscriptions.first).to eq(@subscription_1)
|
|
144
|
+
expect(subscriptions.last).to eq(@subscription_4)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
else
|
|
149
|
+
context "using dynamoid, you can call latest/earliest order method only with query using partition key of Global Secondary Index" do
|
|
150
|
+
|
|
151
|
+
it "works with latest_order scope" do
|
|
152
|
+
subscriptions = ActivityNotification::Subscription.filtered_by_target(@target).latest_order
|
|
153
|
+
expect(subscriptions.size).to eq(4)
|
|
154
|
+
expect(subscriptions.first).to eq(@subscription_4)
|
|
155
|
+
expect(subscriptions.last).to eq(@subscription_1)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "works with earliest_order scope" do
|
|
159
|
+
subscriptions = ActivityNotification::Subscription.filtered_by_target(@target).earliest_order
|
|
160
|
+
expect(subscriptions.size).to eq(4)
|
|
161
|
+
expect(subscriptions.first).to eq(@subscription_1)
|
|
162
|
+
expect(subscriptions.last).to eq(@subscription_4)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
end
|
|
123
166
|
end
|
|
124
167
|
|
|
125
|
-
it "works with latest_order scope" do
|
|
126
|
-
subscriptions = ActivityNotification::Subscription.latest_order
|
|
168
|
+
it "works with latest_order! scope" do
|
|
169
|
+
subscriptions = ActivityNotification::Subscription.latest_order!
|
|
127
170
|
expect(subscriptions.size).to eq(4)
|
|
128
171
|
expect(subscriptions.first).to eq(@subscription_4)
|
|
129
172
|
expect(subscriptions.last).to eq(@subscription_1)
|
|
130
173
|
end
|
|
131
174
|
|
|
132
|
-
it "works with
|
|
133
|
-
subscriptions = ActivityNotification::Subscription.
|
|
175
|
+
it "works with latest_order!(reverse=true) scope" do
|
|
176
|
+
subscriptions = ActivityNotification::Subscription.latest_order!(true)
|
|
177
|
+
expect(subscriptions.size).to eq(4)
|
|
178
|
+
expect(subscriptions.first).to eq(@subscription_1)
|
|
179
|
+
expect(subscriptions.last).to eq(@subscription_4)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "works with earliest_order! scope" do
|
|
183
|
+
subscriptions = ActivityNotification::Subscription.earliest_order!
|
|
134
184
|
expect(subscriptions.size).to eq(4)
|
|
135
185
|
expect(subscriptions.first).to eq(@subscription_1)
|
|
136
186
|
expect(subscriptions.last).to eq(@subscription_4)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'activity_notification/optional_targets/action_cable_api_channel'
|
|
2
|
+
describe ActivityNotification::OptionalTarget::ActionCableApiChannel do
|
|
3
|
+
let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableApiChannel.new(skip_initializing_target: true) }
|
|
4
|
+
|
|
5
|
+
describe "as public instance methods" do
|
|
6
|
+
describe "#to_optional_target_name" do
|
|
7
|
+
it "is return demodulized symbol class name" do
|
|
8
|
+
expect(test_instance.to_optional_target_name).to eq(:action_cable_api_channel)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "#initialize_target" do
|
|
13
|
+
it "does not raise NotImplementedError" do
|
|
14
|
+
test_instance.initialize_target
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#notify" do
|
|
19
|
+
it "does not raise NotImplementedError" do
|
|
20
|
+
test_instance.notify(create(:notification))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "as protected instance methods" do
|
|
26
|
+
describe "#render_notification_message" do
|
|
27
|
+
context "as default" do
|
|
28
|
+
it "renders notification message as formatted JSON" do
|
|
29
|
+
expect(test_instance.send(:render_notification_message, create(:notification)).with_indifferent_access[:notification].has_key?(:id)).to be_truthy
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'activity_notification/optional_targets/action_cable_channel'
|
|
2
|
+
describe ActivityNotification::OptionalTarget::ActionCableChannel do
|
|
3
|
+
let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableChannel.new(skip_initializing_target: true) }
|
|
4
|
+
|
|
5
|
+
describe "as public instance methods" do
|
|
6
|
+
describe "#to_optional_target_name" do
|
|
7
|
+
it "is return demodulized symbol class name" do
|
|
8
|
+
expect(test_instance.to_optional_target_name).to eq(:action_cable_channel)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "#initialize_target" do
|
|
13
|
+
it "does not raise NotImplementedError" do
|
|
14
|
+
test_instance.initialize_target
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#notify" do
|
|
19
|
+
it "does not raise NotImplementedError" do
|
|
20
|
+
test_instance.notify(create(:notification))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "as protected instance methods" do
|
|
26
|
+
describe "#render_notification_message" do
|
|
27
|
+
context "as default" do
|
|
28
|
+
it "renders notification message with default template" do
|
|
29
|
+
expect(test_instance.send(:render_notification_message, create(:notification))).to be_include("<div class='notification_list")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "with unexisting template as fallback option" do
|
|
34
|
+
it "raise ActionView::MissingTemplate" do
|
|
35
|
+
expect { expect(test_instance.send(:render_notification_message, create(:notification), fallback: :hoge)) }
|
|
36
|
+
.to raise_error(ActionView::MissingTemplate)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -10,7 +10,6 @@ describe ActivityNotification::OptionalTarget::AmazonSNS do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
describe "#initialize_target" do
|
|
13
|
-
#TODO
|
|
14
13
|
it "does not raise NotImplementedError" do
|
|
15
14
|
begin
|
|
16
15
|
test_instance.initialize_target
|
|
@@ -21,7 +20,6 @@ describe ActivityNotification::OptionalTarget::AmazonSNS do
|
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
describe "#notify" do
|
|
24
|
-
#TODO
|
|
25
23
|
it "does not raise NotImplementedError but NoMethodError" do
|
|
26
24
|
expect { test_instance.notify(create(:notification)) }
|
|
27
25
|
.to raise_error(NoMethodError)
|
|
@@ -10,7 +10,6 @@ describe ActivityNotification::OptionalTarget::Slack do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
describe "#initialize_target" do
|
|
13
|
-
#TODO
|
|
14
13
|
it "does not raise NotImplementedError but URI::InvalidURIError" do
|
|
15
14
|
expect { test_instance.initialize_target }
|
|
16
15
|
.to raise_error(URI::InvalidURIError)
|
|
@@ -18,7 +17,6 @@ describe ActivityNotification::OptionalTarget::Slack do
|
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
describe "#notify" do
|
|
21
|
-
#TODO
|
|
22
20
|
it "does not raise NotImplementedError but NoMethodError" do
|
|
23
21
|
expect { test_instance.notify(create(:notification)) }
|
|
24
22
|
.to raise_error(NoMethodError)
|