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,8 +1,8 @@
|
|
|
1
1
|
FactoryBot.define do
|
|
2
2
|
factory :subscription, class: ActivityNotification::Subscription do
|
|
3
3
|
association :target, factory: :confirmed_user
|
|
4
|
-
key "default.default"
|
|
5
|
-
subscribed_at Time.current
|
|
6
|
-
subscribed_to_email_at Time.current
|
|
4
|
+
key { "default.default" }
|
|
5
|
+
subscribed_at { Time.current }
|
|
6
|
+
subscribed_to_email_at { Time.current }
|
|
7
7
|
end
|
|
8
8
|
end
|
data/spec/factories/users.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
FactoryBot.define do
|
|
2
2
|
factory :user do
|
|
3
|
-
email Array.new(10){[*"A".."Z", *"0".."9"].sample}.join + '@example.com'
|
|
4
|
-
password "password"
|
|
5
|
-
password_confirmation "password"
|
|
3
|
+
email { Array.new(10){[*"A".."Z", *"0".."9"].sample}.join + '@example.com' }
|
|
4
|
+
password { "password" }
|
|
5
|
+
password_confirmation { "password" }
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
factory :confirmed_user, parent: :user do
|
|
@@ -4,7 +4,17 @@ describe ActivityNotification::Generators::MigrationGenerator, type: :generator
|
|
|
4
4
|
|
|
5
5
|
# setup_default_destination
|
|
6
6
|
destination File.expand_path("../../../../tmp", __FILE__)
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
prepare_destination
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after do
|
|
13
|
+
if ActivityNotification.config.orm == :active_record
|
|
14
|
+
ActivityNotification::Notification.reset_column_information
|
|
15
|
+
ActivityNotification::Subscription.reset_column_information
|
|
16
|
+
end
|
|
17
|
+
end
|
|
8
18
|
|
|
9
19
|
it 'runs generating migration tasks' do
|
|
10
20
|
gen = generator
|
|
@@ -21,7 +31,15 @@ describe ActivityNotification::Generators::MigrationGenerator, type: :generator
|
|
|
21
31
|
describe 'CreateNotifications migration file' do
|
|
22
32
|
subject { file(Dir["tmp/db/migrate/*_create_activity_notification_tables.rb"].first.gsub!('tmp/', '')) }
|
|
23
33
|
it { is_expected.to exist }
|
|
24
|
-
it { is_expected.to contain(/class CreateActivityNotificationTables < ActiveRecord::Migration/) }
|
|
34
|
+
it { is_expected.to contain(/class CreateActivityNotificationTables < ActiveRecord::Migration\[\d\.\d\]/) }
|
|
35
|
+
|
|
36
|
+
if ActivityNotification.config.orm == :active_record
|
|
37
|
+
it 'can be executed to migrate scheme' do
|
|
38
|
+
require subject
|
|
39
|
+
CreateActivityNotificationTables.new.migrate(:down)
|
|
40
|
+
CreateActivityNotificationTables.new.migrate(:up)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
25
43
|
end
|
|
26
44
|
end
|
|
27
45
|
|
|
@@ -33,9 +51,16 @@ describe ActivityNotification::Generators::MigrationGenerator, type: :generator
|
|
|
33
51
|
describe 'CreateCustomNotifications migration file' do
|
|
34
52
|
subject { file(Dir["tmp/db/migrate/*_create_custom_notifications.rb"].first.gsub!('tmp/', '')) }
|
|
35
53
|
it { is_expected.to exist }
|
|
36
|
-
it { is_expected.to contain(/class CreateCustomNotifications < ActiveRecord::Migration/) }
|
|
54
|
+
it { is_expected.to contain(/class CreateCustomNotifications < ActiveRecord::Migration\[\d\.\d\]/) }
|
|
55
|
+
|
|
56
|
+
if ActivityNotification.config.orm == :active_record
|
|
57
|
+
it 'can be executed to migrate scheme' do
|
|
58
|
+
require subject
|
|
59
|
+
CreateActivityNotificationTables.new.migrate(:down)
|
|
60
|
+
CreateActivityNotificationTables.new.migrate(:up)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
37
63
|
end
|
|
38
64
|
end
|
|
39
|
-
|
|
40
65
|
end
|
|
41
66
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
describe ActivityNotification::ViewHelpers, type: :helper do
|
|
2
|
-
let(:view_context) { ActionView::Base.new }
|
|
2
|
+
let(:view_context) { ActionView::Base.new(ActionView::LookupContext.new(ActionController::Base.view_paths), [], nil) }
|
|
3
3
|
let(:notification) {
|
|
4
4
|
create(:notification, target: create(:confirmed_user))
|
|
5
5
|
}
|
|
@@ -42,16 +42,18 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
|
42
42
|
expect(render_notification notification, fallback: :default)
|
|
43
43
|
.to eq(
|
|
44
44
|
render partial: 'activity_notification/notifications/default/default',
|
|
45
|
-
locals: { notification: notification }
|
|
45
|
+
locals: { notification: notification, parameters: {} }
|
|
46
46
|
)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
it 'handles multiple notifications of records' do
|
|
50
|
+
rendered_template = render_notification notifications, fallback: :default
|
|
51
|
+
expect(rendered_template).to start_with(
|
|
52
|
+
render partial: 'activity_notification/notifications/default/default',
|
|
53
|
+
locals: { notification: notifications.to_a.first, parameters: {} })
|
|
54
|
+
expect(rendered_template).to end_with(
|
|
55
|
+
render partial: 'activity_notification/notifications/default/default',
|
|
56
|
+
locals: { notification: notifications.to_a.last , parameters: {} })
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
it 'handles multiple notifications of array' do
|
|
@@ -67,6 +69,21 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
|
67
69
|
expect(render_notification notification, fallback: :text)
|
|
68
70
|
.to eq(simple_text_original)
|
|
69
71
|
end
|
|
72
|
+
|
|
73
|
+
it "interpolates from parameters" do
|
|
74
|
+
notification.parameters = { "article_title" => "custom title" }
|
|
75
|
+
notification.key = 'article.destroy'
|
|
76
|
+
expect(render_notification notification, fallback: :text)
|
|
77
|
+
.to eq('The author removed an article "custom title"')
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "with i18n param set" do
|
|
82
|
+
it "uses i18n text from key" do
|
|
83
|
+
notification.key = simple_text_key
|
|
84
|
+
expect(render_notification notification, i18n: true)
|
|
85
|
+
.to eq(simple_text_original)
|
|
86
|
+
end
|
|
70
87
|
end
|
|
71
88
|
|
|
72
89
|
context "with custom view" do
|
|
@@ -96,23 +113,24 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
|
96
113
|
expect(self).to receive(:render).with({
|
|
97
114
|
layout: 'layouts/test',
|
|
98
115
|
partial: 'activity_notification/notifications/default/custom/test',
|
|
116
|
+
assigns: {},
|
|
99
117
|
locals: notification.prepare_locals({ layout: 'test' })
|
|
100
118
|
})
|
|
101
119
|
render_notification notification, layout: 'test'
|
|
102
120
|
end
|
|
103
121
|
|
|
104
122
|
context "with defined overriding_notification_template_key in notifiable model" do
|
|
105
|
-
it "renders
|
|
123
|
+
it "renders overridden custom notification view" do
|
|
106
124
|
notification.key = 'custom.test'
|
|
107
125
|
module AdditionalMethods
|
|
108
126
|
def overriding_notification_template_key(target, key)
|
|
109
|
-
'
|
|
127
|
+
'overridden.custom.test'
|
|
110
128
|
end
|
|
111
129
|
end
|
|
112
130
|
notification.notifiable.extend(AdditionalMethods)
|
|
113
|
-
# render activity_notification/notifications/users/
|
|
131
|
+
# render activity_notification/notifications/users/overridden/custom/test
|
|
114
132
|
expect(render_notification notification, target: :users)
|
|
115
|
-
.to eq("
|
|
133
|
+
.to eq("Overridden custom template root for user target: #{notification.id}")
|
|
116
134
|
end
|
|
117
135
|
end
|
|
118
136
|
end
|
|
@@ -153,16 +171,8 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
|
153
171
|
@target = target_user
|
|
154
172
|
end
|
|
155
173
|
|
|
156
|
-
#TODO make better test using content_for
|
|
157
174
|
it "renders custom notification view for specified target" do
|
|
158
|
-
|
|
159
|
-
# notification_2 = target_user.notifications.last
|
|
160
|
-
# notification_1.update(key: 'custom.test')
|
|
161
|
-
# notification_2.update(key: 'custom.test')
|
|
162
|
-
expect(render_notification_of target_user, partial: 'custom_index', fallback: :default)
|
|
163
|
-
.to eq("Custom index: ")
|
|
164
|
-
# .to eq("Custom index: Custom template root for user target: #{notification_1.id}"\
|
|
165
|
-
# "Custom template root for user target: #{notification_2.id}")
|
|
175
|
+
expect(render_notification_of target_user, partial: 'custom_index', fallback: :default).to eq("Custom index: ")
|
|
166
176
|
end
|
|
167
177
|
|
|
168
178
|
it "uses layout of layout parameter" do
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
describe ActivityNotification::NotifyAllJob, type: :job do
|
|
2
|
+
before do
|
|
3
|
+
ActiveJob::Base.queue_adapter = :test
|
|
4
|
+
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
|
5
|
+
@author_user = create(:confirmed_user)
|
|
6
|
+
@user = create(:confirmed_user)
|
|
7
|
+
@article = create(:article, user: @author_user)
|
|
8
|
+
@comment = create(:comment, article: @article, user: @user)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#perform_later" do
|
|
12
|
+
it "generates notifications" do
|
|
13
|
+
expect {
|
|
14
|
+
ActivityNotification::NotifyAllJob.perform_later([@author_user, @user], @comment)
|
|
15
|
+
}.to have_enqueued_job
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "generates notifications once" do
|
|
19
|
+
ActivityNotification::NotifyAllJob.perform_later([@author_user, @user], @comment)
|
|
20
|
+
expect(ActivityNotification::NotifyAllJob).to have_been_enqueued.exactly(:once)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
describe ActivityNotification::NotifyJob, type: :job do
|
|
2
|
+
before do
|
|
3
|
+
ActiveJob::Base.queue_adapter = :test
|
|
4
|
+
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
|
5
|
+
@author_user = create(:confirmed_user)
|
|
6
|
+
@user = create(:confirmed_user)
|
|
7
|
+
@article = create(:article, user: @author_user)
|
|
8
|
+
@comment = create(:comment, article: @article, user: @user)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#perform_later" do
|
|
12
|
+
it "generates notifications" do
|
|
13
|
+
expect {
|
|
14
|
+
ActivityNotification::NotifyJob.perform_later('users', @comment)
|
|
15
|
+
}.to have_enqueued_job
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "generates notifications once" do
|
|
19
|
+
ActivityNotification::NotifyJob.perform_later('users', @comment)
|
|
20
|
+
expect(ActivityNotification::NotifyJob).to have_been_enqueued.exactly(:once)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
describe ActivityNotification::NotifyToJob, type: :job do
|
|
2
|
+
before do
|
|
3
|
+
ActiveJob::Base.queue_adapter = :test
|
|
4
|
+
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
|
5
|
+
@author_user = create(:confirmed_user)
|
|
6
|
+
@user = create(:confirmed_user)
|
|
7
|
+
@article = create(:article, user: @author_user)
|
|
8
|
+
@comment = create(:comment, article: @article, user: @user)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#perform_later" do
|
|
12
|
+
it "generates notification" do
|
|
13
|
+
expect {
|
|
14
|
+
ActivityNotification::NotifyToJob.perform_later(@user, @comment)
|
|
15
|
+
}.to have_enqueued_job
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "generates notification once" do
|
|
19
|
+
ActivityNotification::NotifyToJob.perform_later(@user, @comment)
|
|
20
|
+
expect(ActivityNotification::NotifyToJob).to have_been_enqueued.exactly(:once)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/spec/mailers/mailer_spec.rb
CHANGED
|
@@ -84,7 +84,7 @@ describe ActivityNotification::Mailer do
|
|
|
84
84
|
notification.notifiable.extend(AdditionalMethods)
|
|
85
85
|
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
|
86
86
|
expect(ActivityNotification::Mailer.deliveries.last.subject)
|
|
87
|
-
.to eq("New comment
|
|
87
|
+
.to eq("New comment on your article")
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
@@ -102,6 +102,47 @@ describe ActivityNotification::Mailer do
|
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
+
context "with defined overriding_notification_email_from in notifiable model" do
|
|
106
|
+
it "sends with updated from" do
|
|
107
|
+
module AdditionalMethods
|
|
108
|
+
def overriding_notification_email_from(target, key)
|
|
109
|
+
'test05@example.com'
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
notification.notifiable.extend(AdditionalMethods)
|
|
113
|
+
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
|
114
|
+
expect(ActivityNotification::Mailer.deliveries.last.from.first)
|
|
115
|
+
.to eq('test05@example.com')
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context "with defined overriding_notification_email_reply_to in notifiable model" do
|
|
120
|
+
it "sends with updated reply_to" do
|
|
121
|
+
module AdditionalMethods
|
|
122
|
+
def overriding_notification_email_reply_to(target, key)
|
|
123
|
+
'test06@example.com'
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
notification.notifiable.extend(AdditionalMethods)
|
|
127
|
+
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
|
128
|
+
expect(ActivityNotification::Mailer.deliveries.last.reply_to.first)
|
|
129
|
+
.to eq('test06@example.com')
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context "with defined overriding_notification_email_message_id in notifiable model" do
|
|
134
|
+
it "sends with specific message id" do
|
|
135
|
+
module AdditionalMethods
|
|
136
|
+
def overriding_notification_email_message_id(target, key)
|
|
137
|
+
"https://www.example.com/test@example.com/"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
notification.notifiable.extend(AdditionalMethods)
|
|
141
|
+
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
|
142
|
+
expect(ActivityNotification::Mailer.deliveries.last.message_id)
|
|
143
|
+
.to eq("https://www.example.com/test@example.com/")
|
|
144
|
+
end
|
|
145
|
+
end
|
|
105
146
|
context "when fallback option is :none and the template is missing" do
|
|
106
147
|
it "raise ActionView::MissingTemplate" do
|
|
107
148
|
expect { ActivityNotification::Mailer.send_notification_email(notification, fallback: :none).deliver_now }
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# To run as single test for debugging
|
|
2
|
+
# require Rails.root.join('../../spec/concerns/models/notifiable_spec.rb').to_s
|
|
3
|
+
# require Rails.root.join('../../spec/concerns/common_spec.rb').to_s
|
|
4
|
+
|
|
1
5
|
describe Dummy::DummyNotifiable, type: :model do
|
|
2
6
|
|
|
3
7
|
it_behaves_like :notifiable
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# To run as single test for debugging
|
|
2
|
+
# require Rails.root.join('../../spec/concerns/models/notifier_spec.rb').to_s
|
|
3
|
+
# require Rails.root.join('../../spec/concerns/common_spec.rb').to_s
|
|
4
|
+
|
|
1
5
|
describe Dummy::DummyNotifier, type: :model do
|
|
2
6
|
|
|
3
7
|
it_behaves_like :notifier
|