activity_notification 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/app/jobs/activity_notification/cascading_notification_job.rb +123 -0
- data/docs/Functions.md +197 -1
- data/lib/activity_notification/apis/cascading_notification_api.rb +208 -0
- data/lib/activity_notification/apis/notification_api.rb +3 -0
- data/lib/activity_notification/config.rb +10 -0
- data/lib/activity_notification/mailers/helpers.rb +27 -1
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +8 -0
- metadata +5 -441
- data/.codeclimate.yml +0 -33
- data/.coveralls.yml +0 -1
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -22
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
- data/.github/pull_request_template.md +0 -13
- data/.github/workflows/build.yml +0 -100
- data/.gitignore +0 -74
- data/.rspec +0 -3
- data/.rubocop.yml +0 -1157
- data/.yardopts +0 -6
- data/CHANGELOG.md +0 -452
- data/Gemfile +0 -31
- data/Procfile +0 -2
- data/Rakefile +0 -28
- data/activity_notification.gemspec +0 -44
- data/ai-curated-specs/issues/172/design.md +0 -220
- data/ai-curated-specs/issues/172/tasks.md +0 -326
- data/ai-curated-specs/issues/188/design.md +0 -227
- data/ai-curated-specs/issues/188/requirements.md +0 -78
- data/ai-curated-specs/issues/188/tasks.md +0 -203
- data/ai-curated-specs/issues/188/upstream-contributions.md +0 -592
- data/ai-curated-specs/issues/50/design.md +0 -235
- data/ai-curated-specs/issues/50/requirements.md +0 -49
- data/ai-curated-specs/issues/50/tasks.md +0 -232
- data/bin/_dynamodblocal +0 -4
- data/bin/bundle_update.sh +0 -7
- data/bin/deploy_on_heroku.sh +0 -16
- data/bin/install_dynamodblocal.sh +0 -5
- data/bin/start_dynamodblocal.sh +0 -47
- data/bin/stop_dynamodblocal.sh +0 -34
- data/gemfiles/Gemfile.rails-5.0 +0 -25
- data/gemfiles/Gemfile.rails-5.1 +0 -25
- data/gemfiles/Gemfile.rails-5.2 +0 -24
- data/gemfiles/Gemfile.rails-6.0 +0 -23
- data/gemfiles/Gemfile.rails-6.1 +0 -22
- data/gemfiles/Gemfile.rails-7.0 +0 -25
- data/gemfiles/Gemfile.rails-7.1 +0 -23
- data/gemfiles/Gemfile.rails-7.2 +0 -23
- data/gemfiles/Gemfile.rails-8.0 +0 -24
- data/package.json +0 -8
- data/spec/channels/notification_api_channel_shared_examples.rb +0 -59
- data/spec/channels/notification_api_channel_spec.rb +0 -49
- data/spec/channels/notification_api_with_devise_channel_spec.rb +0 -76
- data/spec/channels/notification_channel_shared_examples.rb +0 -59
- data/spec/channels/notification_channel_spec.rb +0 -48
- data/spec/channels/notification_with_devise_channel_spec.rb +0 -97
- data/spec/concerns/apis/notification_api_spec.rb +0 -1627
- data/spec/concerns/apis/subscription_api_spec.rb +0 -474
- data/spec/concerns/common_spec.rb +0 -213
- data/spec/concerns/models/group_spec.rb +0 -61
- data/spec/concerns/models/notifiable_spec.rb +0 -782
- data/spec/concerns/models/notifier_spec.rb +0 -71
- data/spec/concerns/models/subscriber_spec.rb +0 -800
- data/spec/concerns/models/target_spec.rb +0 -1285
- data/spec/concerns/renderable_spec.rb +0 -129
- data/spec/config_spec.rb +0 -85
- data/spec/controllers/common_controller_spec.rb +0 -25
- data/spec/controllers/controller_spec_utility.rb +0 -100
- data/spec/controllers/dummy_common_controller.rb +0 -5
- data/spec/controllers/notifications_api_controller_shared_examples.rb +0 -619
- data/spec/controllers/notifications_api_controller_spec.rb +0 -19
- data/spec/controllers/notifications_api_with_devise_controller_spec.rb +0 -60
- data/spec/controllers/notifications_controller_shared_examples.rb +0 -743
- data/spec/controllers/notifications_controller_spec.rb +0 -11
- data/spec/controllers/notifications_with_devise_controller_spec.rb +0 -97
- data/spec/controllers/subscriptions_api_controller_shared_examples.rb +0 -750
- data/spec/controllers/subscriptions_api_controller_spec.rb +0 -19
- data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +0 -60
- data/spec/controllers/subscriptions_controller_shared_examples.rb +0 -946
- data/spec/controllers/subscriptions_controller_spec.rb +0 -11
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +0 -97
- data/spec/factories/admins.rb +0 -5
- data/spec/factories/articles.rb +0 -5
- data/spec/factories/comments.rb +0 -6
- data/spec/factories/dummy/dummy_group.rb +0 -4
- data/spec/factories/dummy/dummy_notifiable.rb +0 -4
- data/spec/factories/dummy/dummy_notifier.rb +0 -4
- data/spec/factories/dummy/dummy_subscriber.rb +0 -4
- data/spec/factories/dummy/dummy_target.rb +0 -4
- data/spec/factories/notifications.rb +0 -7
- data/spec/factories/subscriptions.rb +0 -8
- data/spec/factories/users.rb +0 -11
- data/spec/generators/controllers_generator_spec.rb +0 -85
- data/spec/generators/install_generator_spec.rb +0 -43
- data/spec/generators/migration/migration_generator_spec.rb +0 -80
- data/spec/generators/models_generator_spec.rb +0 -96
- data/spec/generators/views_generator_spec.rb +0 -195
- data/spec/helpers/polymorphic_helpers_spec.rb +0 -89
- data/spec/helpers/view_helpers_spec.rb +0 -547
- data/spec/jobs/notification_resilience_job_spec.rb +0 -167
- data/spec/jobs/notify_all_job_spec.rb +0 -23
- data/spec/jobs/notify_job_spec.rb +0 -23
- data/spec/jobs/notify_to_job_spec.rb +0 -23
- data/spec/mailers/mailer_spec.rb +0 -214
- data/spec/mailers/notification_resilience_spec.rb +0 -263
- data/spec/models/dummy/dummy_group_spec.rb +0 -10
- data/spec/models/dummy/dummy_notifiable_spec.rb +0 -10
- data/spec/models/dummy/dummy_notifier_spec.rb +0 -10
- data/spec/models/dummy/dummy_subscriber_spec.rb +0 -8
- data/spec/models/dummy/dummy_target_spec.rb +0 -10
- data/spec/models/notification_spec.rb +0 -472
- data/spec/models/subscription_spec.rb +0 -215
- data/spec/optional_targets/action_cable_api_channel_spec.rb +0 -34
- data/spec/optional_targets/action_cable_channel_spec.rb +0 -41
- data/spec/optional_targets/amazon_sns_spec.rb +0 -47
- data/spec/optional_targets/base_spec.rb +0 -45
- data/spec/optional_targets/slack_spec.rb +0 -44
- data/spec/orm/dynamoid_spec.rb +0 -115
- data/spec/rails_app/Rakefile +0 -15
- data/spec/rails_app/app/assets/config/manifest.js +0 -3
- data/spec/rails_app/app/assets/images/.keep +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +0 -3
- data/spec/rails_app/app/assets/javascripts/cable.js +0 -12
- data/spec/rails_app/app/assets/stylesheets/application.css +0 -15
- data/spec/rails_app/app/assets/stylesheets/reset.css +0 -85
- data/spec/rails_app/app/assets/stylesheets/style.css +0 -244
- data/spec/rails_app/app/controllers/admins_controller.rb +0 -21
- data/spec/rails_app/app/controllers/application_controller.rb +0 -5
- data/spec/rails_app/app/controllers/articles_controller.rb +0 -67
- data/spec/rails_app/app/controllers/comments_controller.rb +0 -36
- data/spec/rails_app/app/controllers/concerns/.keep +0 -0
- data/spec/rails_app/app/controllers/spa_controller.rb +0 -7
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -2
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -2
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -2
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -2
- data/spec/rails_app/app/controllers/users_controller.rb +0 -26
- data/spec/rails_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails_app/app/helpers/devise_helper.rb +0 -2
- data/spec/rails_app/app/javascript/App.vue +0 -40
- data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +0 -82
- data/spec/rails_app/app/javascript/components/Top.vue +0 -98
- data/spec/rails_app/app/javascript/components/notifications/Index.vue +0 -200
- data/spec/rails_app/app/javascript/components/notifications/Notification.vue +0 -133
- data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +0 -122
- data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +0 -279
- data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +0 -112
- data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +0 -141
- data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +0 -226
- data/spec/rails_app/app/javascript/config/development.js +0 -5
- data/spec/rails_app/app/javascript/config/environment.js +0 -7
- data/spec/rails_app/app/javascript/config/production.js +0 -5
- data/spec/rails_app/app/javascript/config/test.js +0 -5
- data/spec/rails_app/app/javascript/packs/application.js +0 -18
- data/spec/rails_app/app/javascript/packs/spa.js +0 -14
- data/spec/rails_app/app/javascript/router/index.js +0 -73
- data/spec/rails_app/app/javascript/store/index.js +0 -37
- data/spec/rails_app/app/mailers/.keep +0 -0
- data/spec/rails_app/app/mailers/custom_notification_mailer.rb +0 -5
- data/spec/rails_app/app/models/admin.rb +0 -35
- data/spec/rails_app/app/models/article.rb +0 -54
- data/spec/rails_app/app/models/comment.rb +0 -81
- data/spec/rails_app/app/models/dummy/dummy_base.rb +0 -11
- data/spec/rails_app/app/models/dummy/dummy_group.rb +0 -23
- data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +0 -15
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +0 -27
- data/spec/rails_app/app/models/dummy/dummy_notifier.rb +0 -15
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +0 -14
- data/spec/rails_app/app/models/dummy/dummy_target.rb +0 -16
- data/spec/rails_app/app/models/user.rb +0 -73
- data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +0 -1
- data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +0 -146
- data/spec/rails_app/app/views/activity_notification/notifications/default/custom/_path_test.html.erb +0 -1
- data/spec/rails_app/app/views/activity_notification/notifications/default/custom/_test.html.erb +0 -1
- data/spec/rails_app/app/views/activity_notification/notifications/users/_custom_index.html.erb +0 -1
- data/spec/rails_app/app/views/activity_notification/notifications/users/custom/_test.html.erb +0 -1
- data/spec/rails_app/app/views/activity_notification/notifications/users/overridden/custom/_test.html.erb +0 -1
- data/spec/rails_app/app/views/activity_notification/optional_targets/admins/amazon_sns/comment/_default.text.erb +0 -10
- data/spec/rails_app/app/views/articles/_form.html.erb +0 -24
- data/spec/rails_app/app/views/articles/edit.html.erb +0 -8
- data/spec/rails_app/app/views/articles/index.html.erb +0 -113
- data/spec/rails_app/app/views/articles/new.html.erb +0 -7
- data/spec/rails_app/app/views/articles/show.html.erb +0 -49
- data/spec/rails_app/app/views/layouts/_header.html.erb +0 -46
- data/spec/rails_app/app/views/layouts/application.html.erb +0 -15
- data/spec/rails_app/app/views/spa/index.html.erb +0 -2
- data/spec/rails_app/babel.config.js +0 -72
- data/spec/rails_app/bin/bundle +0 -3
- data/spec/rails_app/bin/rails +0 -4
- data/spec/rails_app/bin/rake +0 -4
- data/spec/rails_app/bin/setup +0 -29
- data/spec/rails_app/bin/webpack +0 -18
- data/spec/rails_app/bin/webpack-dev-server +0 -18
- data/spec/rails_app/config/application.rb +0 -54
- data/spec/rails_app/config/boot.rb +0 -5
- data/spec/rails_app/config/cable.yml +0 -8
- data/spec/rails_app/config/database.yml +0 -36
- data/spec/rails_app/config/dynamoid.rb +0 -13
- data/spec/rails_app/config/environment.rb +0 -26
- data/spec/rails_app/config/environments/development.rb +0 -60
- data/spec/rails_app/config/environments/production.rb +0 -85
- data/spec/rails_app/config/environments/test.rb +0 -53
- data/spec/rails_app/config/initializers/activity_notification.rb +0 -104
- data/spec/rails_app/config/initializers/assets.rb +0 -11
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails_app/config/initializers/cookies_serializer.rb +0 -3
- data/spec/rails_app/config/initializers/copy_it.aws.rb.template +0 -6
- data/spec/rails_app/config/initializers/devise.rb +0 -278
- data/spec/rails_app/config/initializers/devise_token_auth.rb +0 -55
- data/spec/rails_app/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/rails_app/config/initializers/inflections.rb +0 -16
- data/spec/rails_app/config/initializers/mime_types.rb +0 -4
- data/spec/rails_app/config/initializers/mysql.rb +0 -9
- data/spec/rails_app/config/initializers/session_store.rb +0 -3
- data/spec/rails_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/rails_app/config/initializers/zeitwerk.rb +0 -10
- data/spec/rails_app/config/locales/activity_notification.en.yml +0 -26
- data/spec/rails_app/config/locales/devise.en.yml +0 -62
- data/spec/rails_app/config/mongoid.yml +0 -13
- data/spec/rails_app/config/routes.rb +0 -50
- data/spec/rails_app/config/secrets.yml +0 -22
- data/spec/rails_app/config/webpack/development.js +0 -5
- data/spec/rails_app/config/webpack/environment.js +0 -7
- data/spec/rails_app/config/webpack/loaders/vue.js +0 -6
- data/spec/rails_app/config/webpack/production.js +0 -5
- data/spec/rails_app/config/webpack/test.js +0 -5
- data/spec/rails_app/config/webpacker.yml +0 -97
- data/spec/rails_app/config.ru +0 -4
- data/spec/rails_app/db/migrate/20160716000000_create_test_tables.rb +0 -42
- data/spec/rails_app/db/migrate/20181209000000_create_activity_notification_tables.rb +0 -33
- data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +0 -10
- data/spec/rails_app/db/schema.rb +0 -98
- data/spec/rails_app/db/seeds.rb +0 -95
- data/spec/rails_app/lib/custom_optional_targets/console_output.rb +0 -16
- data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +0 -14
- data/spec/rails_app/lib/custom_optional_targets/wrong_target.rb +0 -13
- data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +0 -29
- data/spec/rails_app/package.json +0 -23
- data/spec/rails_app/postcss.config.js +0 -12
- data/spec/rails_app/public/404.html +0 -67
- data/spec/rails_app/public/422.html +0 -67
- data/spec/rails_app/public/500.html +0 -66
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/roles/acts_as_group_spec.rb +0 -30
- data/spec/roles/acts_as_notifiable_spec.rb +0 -432
- data/spec/roles/acts_as_notifier_spec.rb +0 -30
- data/spec/roles/acts_as_target_spec.rb +0 -36
- data/spec/spec_helper.rb +0 -56
- data/spec/version_spec.rb +0 -31
|
@@ -1,1285 +0,0 @@
|
|
|
1
|
-
shared_examples_for :target do
|
|
2
|
-
let(:test_class_name) { described_class.to_s.underscore.split('/').last.to_sym }
|
|
3
|
-
let(:test_instance) { create(test_class_name) }
|
|
4
|
-
let(:test_notifiable) { create(:dummy_notifiable) }
|
|
5
|
-
|
|
6
|
-
describe "with association" do
|
|
7
|
-
it "has many notifications" do
|
|
8
|
-
notification_1 = create(:notification, target: test_instance)
|
|
9
|
-
notification_2 = create(:notification, target: test_instance, created_at: notification_1.created_at + 10.second)
|
|
10
|
-
expect(test_instance.notifications.count).to eq(2)
|
|
11
|
-
expect(test_instance.notifications.earliest).to eq(notification_1)
|
|
12
|
-
expect(test_instance.notifications.latest).to eq(notification_2)
|
|
13
|
-
expect(test_instance.notifications.to_a).to eq(ActivityNotification::Notification.filtered_by_target(test_instance).to_a)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "as public class methods" do
|
|
18
|
-
describe ".available_as_target?" do
|
|
19
|
-
it "returns true" do
|
|
20
|
-
expect(described_class.available_as_target?).to be_truthy
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe ".set_target_class_defaults" do
|
|
25
|
-
it "set parameter fields as default" do
|
|
26
|
-
described_class.set_target_class_defaults
|
|
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)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe ".notification_index_map" do
|
|
40
|
-
it "returns notifications of this target type group by target" do
|
|
41
|
-
ActivityNotification::Notification.delete_all
|
|
42
|
-
target_1 = create(test_class_name)
|
|
43
|
-
target_2 = create(test_class_name)
|
|
44
|
-
notification_1 = create(:notification, target: target_1)
|
|
45
|
-
notification_2 = create(:notification, target: target_1)
|
|
46
|
-
notification_3 = create(:notification, target: target_1)
|
|
47
|
-
notification_4 = create(:notification, target: target_2)
|
|
48
|
-
notification_5 = create(:notification, target: target_2)
|
|
49
|
-
notification_6 = create(:notification, target: test_notifiable)
|
|
50
|
-
|
|
51
|
-
index_map = described_class.notification_index_map
|
|
52
|
-
expect(index_map.size).to eq(2)
|
|
53
|
-
expect(index_map[target_1].size).to eq(3)
|
|
54
|
-
expect(described_class.notification_index_map[target_2].size).to eq(2)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context "with :filtered_by_status" do
|
|
58
|
-
context "as :opened" do
|
|
59
|
-
it "returns opened notifications of this target type group by target" do
|
|
60
|
-
ActivityNotification::Notification.delete_all
|
|
61
|
-
target_1 = create(test_class_name)
|
|
62
|
-
target_2 = create(test_class_name)
|
|
63
|
-
target_3 = create(test_class_name)
|
|
64
|
-
notification_1 = create(:notification, target: target_1)
|
|
65
|
-
notification_2 = create(:notification, target: target_1)
|
|
66
|
-
notification_2.open!
|
|
67
|
-
notification_3 = create(:notification, target: target_1)
|
|
68
|
-
notification_3.open!
|
|
69
|
-
notification_4 = create(:notification, target: target_2)
|
|
70
|
-
notification_5 = create(:notification, target: target_2)
|
|
71
|
-
notification_5.open!
|
|
72
|
-
notification_6 = create(:notification, target: target_3)
|
|
73
|
-
notification_7 = create(:notification, target: test_notifiable)
|
|
74
|
-
|
|
75
|
-
index_map = described_class.notification_index_map(filtered_by_status: :opened)
|
|
76
|
-
expect(index_map.size).to eq(2)
|
|
77
|
-
expect(index_map[target_1].size).to eq(2)
|
|
78
|
-
expect(index_map[target_2].size).to eq(1)
|
|
79
|
-
expect(index_map.has_key?(target_3)).to be_falsey
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "as :unopened" do
|
|
84
|
-
it "returns unopened notifications of this target type group by target" do
|
|
85
|
-
ActivityNotification::Notification.delete_all
|
|
86
|
-
target_1 = create(test_class_name)
|
|
87
|
-
target_2 = create(test_class_name)
|
|
88
|
-
target_3 = create(test_class_name)
|
|
89
|
-
notification_1 = create(:notification, target: target_1)
|
|
90
|
-
notification_2 = create(:notification, target: target_1)
|
|
91
|
-
notification_3 = create(:notification, target: target_1)
|
|
92
|
-
notification_3.open!
|
|
93
|
-
notification_4 = create(:notification, target: target_2)
|
|
94
|
-
notification_5 = create(:notification, target: target_2)
|
|
95
|
-
notification_5.open!
|
|
96
|
-
notification_6 = create(:notification, target: target_3)
|
|
97
|
-
notification_6.open!
|
|
98
|
-
notification_7 = create(:notification, target: test_notifiable)
|
|
99
|
-
|
|
100
|
-
index_map = described_class.notification_index_map(filtered_by_status: :unopened)
|
|
101
|
-
expect(index_map.size).to eq(2)
|
|
102
|
-
expect(index_map[target_1].size).to eq(2)
|
|
103
|
-
expect(index_map[target_2].size).to eq(1)
|
|
104
|
-
expect(index_map.has_key?(target_3)).to be_falsey
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context "with :as_latest_group_member" do
|
|
110
|
-
before do
|
|
111
|
-
ActivityNotification::Notification.delete_all
|
|
112
|
-
@target_1 = create(test_class_name)
|
|
113
|
-
@target_2 = create(test_class_name)
|
|
114
|
-
@target_3 = create(test_class_name)
|
|
115
|
-
notification_1 = create(:notification, target: @target_1)
|
|
116
|
-
@notification_2 = create(:notification, target: @target_1, created_at: notification_1.created_at + 10.second)
|
|
117
|
-
notification_3 = create(:notification, target: @target_1, group_owner: @notification_2, created_at: notification_1.created_at + 20.second)
|
|
118
|
-
@notification_4 = create(:notification, target: @target_1, group_owner: @notification_2, created_at: notification_1.created_at + 30.second)
|
|
119
|
-
notification_5 = create(:notification, target: @target_2, created_at: notification_1.created_at + 40.second)
|
|
120
|
-
notification_6 = create(:notification, target: @target_2, created_at: notification_1.created_at + 50.second)
|
|
121
|
-
notification_6.open!
|
|
122
|
-
notification_7 = create(:notification, target: @target_3, created_at: notification_1.created_at + 60.second)
|
|
123
|
-
notification_7.open!
|
|
124
|
-
notification_8 = create(:notification, target: test_notifiable, created_at: notification_1.created_at + 70.second)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
context "as default" do
|
|
128
|
-
it "returns earliest group members" do
|
|
129
|
-
index_map = described_class.notification_index_map(filtered_by_status: :unopened)
|
|
130
|
-
expect(index_map.size).to eq(2)
|
|
131
|
-
expect(index_map[@target_1].size).to eq(2)
|
|
132
|
-
expect(index_map[@target_1].first).to eq(@notification_2)
|
|
133
|
-
expect(index_map[@target_2].size).to eq(1)
|
|
134
|
-
expect(index_map.has_key?(@target_3)).to be_falsey
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
context "as true" do
|
|
139
|
-
it "returns latest group members" do
|
|
140
|
-
index_map = described_class.notification_index_map(filtered_by_status: :unopened, as_latest_group_member: true)
|
|
141
|
-
expect(index_map.size).to eq(2)
|
|
142
|
-
expect(index_map[@target_1].size).to eq(2)
|
|
143
|
-
expect(index_map[@target_1].first).to eq(@notification_4)
|
|
144
|
-
expect(index_map[@target_2].size).to eq(1)
|
|
145
|
-
expect(index_map.has_key?(@target_3)).to be_falsey
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe ".send_batch_unopened_notification_email" do
|
|
152
|
-
it "sends batch notification email to this type targets with unopened notifications" do
|
|
153
|
-
ActivityNotification::Notification.delete_all
|
|
154
|
-
target_1 = create(test_class_name)
|
|
155
|
-
target_2 = create(test_class_name)
|
|
156
|
-
target_3 = create(test_class_name)
|
|
157
|
-
notification_1 = create(:notification, target: target_1)
|
|
158
|
-
notification_2 = create(:notification, target: target_1)
|
|
159
|
-
notification_3 = create(:notification, target: target_1)
|
|
160
|
-
notification_3.open!
|
|
161
|
-
notification_4 = create(:notification, target: target_2)
|
|
162
|
-
notification_5 = create(:notification, target: target_2)
|
|
163
|
-
notification_5.open!
|
|
164
|
-
notification_6 = create(:notification, target: target_3)
|
|
165
|
-
notification_6.open!
|
|
166
|
-
notification_7 = create(:notification, target: test_notifiable)
|
|
167
|
-
|
|
168
|
-
expect(ActivityNotification::Notification).to receive(:send_batch_notification_email).at_least(:once)
|
|
169
|
-
sent_email_map = described_class.send_batch_unopened_notification_email
|
|
170
|
-
expect(sent_email_map.size).to eq(2)
|
|
171
|
-
expect(sent_email_map.has_key?(target_1)).to be_truthy
|
|
172
|
-
expect(sent_email_map.has_key?(target_2)).to be_truthy
|
|
173
|
-
expect(sent_email_map.has_key?(target_3)).to be_falsey
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
describe "subscription_enabled?" do
|
|
178
|
-
context "with true as _notification_subscription_allowed" do
|
|
179
|
-
it "returns true" do
|
|
180
|
-
described_class._notification_subscription_allowed = true
|
|
181
|
-
expect(described_class.subscription_enabled?).to eq(true)
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
context "with false as _notification_subscription_allowed" do
|
|
186
|
-
it "returns false" do
|
|
187
|
-
described_class._notification_subscription_allowed = false
|
|
188
|
-
expect(described_class.subscription_enabled?).to eq(false)
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
context "with lambda configuration as _notification_subscription_allowed" do
|
|
193
|
-
it "returns true (even if configured lambda function returns false)" do
|
|
194
|
-
described_class._notification_subscription_allowed = ->(target, key){ false }
|
|
195
|
-
expect(described_class.subscription_enabled?).to eq(true)
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
describe "as public instance methods" do
|
|
202
|
-
before do
|
|
203
|
-
ActivityNotification::Notification.delete_all
|
|
204
|
-
described_class.set_target_class_defaults
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
describe "#mailer_to" do
|
|
208
|
-
context "without any configuration" do
|
|
209
|
-
it "returns nil" do
|
|
210
|
-
expect(test_instance.mailer_to).to be_nil
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
context "configured with a field" do
|
|
215
|
-
it "returns specified value" do
|
|
216
|
-
described_class._notification_email = 'test@example.com'
|
|
217
|
-
expect(test_instance.mailer_to).to eq('test@example.com')
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
it "returns specified symbol of field" do
|
|
221
|
-
described_class._notification_email = :email
|
|
222
|
-
expect(test_instance.mailer_to).to eq(test_instance.email)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it "returns specified symbol of method" do
|
|
226
|
-
module AdditionalMethods
|
|
227
|
-
def custom_notification_email
|
|
228
|
-
'test@example.com'
|
|
229
|
-
end
|
|
230
|
-
end
|
|
231
|
-
test_instance.extend(AdditionalMethods)
|
|
232
|
-
described_class._notification_email = :custom_notification_email
|
|
233
|
-
expect(test_instance.mailer_to).to eq('test@example.com')
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
it "returns specified lambda with single target argument" do
|
|
237
|
-
described_class._notification_email = ->(target){ 'test@example.com' }
|
|
238
|
-
expect(test_instance.mailer_to).to eq('test@example.com')
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
describe "#notification_email_allowed?" do
|
|
244
|
-
context "without any configuration" do
|
|
245
|
-
it "returns ActivityNotification.config.email_enabled" do
|
|
246
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key'))
|
|
247
|
-
.to eq(ActivityNotification.config.email_enabled)
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
it "returns false as default" do
|
|
251
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to be_falsey
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
context "configured with a field" do
|
|
256
|
-
it "returns specified value" do
|
|
257
|
-
described_class._notification_email_allowed = true
|
|
258
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
it "returns specified symbol without argument" do
|
|
262
|
-
module AdditionalMethods
|
|
263
|
-
def custom_notification_email_allowed?
|
|
264
|
-
true
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
test_instance.extend(AdditionalMethods)
|
|
268
|
-
described_class._notification_email_allowed = :custom_notification_email_allowed?
|
|
269
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
it "returns specified symbol with notifiable
|
|
273
|
-
and key arguments" do
|
|
274
|
-
module AdditionalMethods
|
|
275
|
-
def custom_notification_email_allowed?(notifiable, key)
|
|
276
|
-
true
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
test_instance.extend(AdditionalMethods)
|
|
280
|
-
described_class._notification_email_allowed = :custom_notification_email_allowed?
|
|
281
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
it "returns specified lambda with single target argument" do
|
|
285
|
-
described_class._notification_email_allowed = ->(target){ true }
|
|
286
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
it "returns specified lambda with target, notifiable and key arguments" do
|
|
290
|
-
described_class._notification_email_allowed = ->(target, notifiable, key){ true }
|
|
291
|
-
expect(test_instance.notification_email_allowed?(test_notifiable, 'dummy_key')).to eq(true)
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
describe "#batch_notification_email_allowed?" do
|
|
297
|
-
context "without any configuration" do
|
|
298
|
-
it "returns ActivityNotification.config.email_enabled" do
|
|
299
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key'))
|
|
300
|
-
.to eq(ActivityNotification.config.email_enabled)
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
it "returns false as default" do
|
|
304
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key')).to be_falsey
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
context "configured with a field" do
|
|
309
|
-
it "returns specified value" do
|
|
310
|
-
described_class._batch_notification_email_allowed = true
|
|
311
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
it "returns specified symbol without argument" do
|
|
315
|
-
module AdditionalMethods
|
|
316
|
-
def custom_batch_notification_email_allowed?
|
|
317
|
-
true
|
|
318
|
-
end
|
|
319
|
-
end
|
|
320
|
-
test_instance.extend(AdditionalMethods)
|
|
321
|
-
described_class._batch_notification_email_allowed = :custom_batch_notification_email_allowed?
|
|
322
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
it "returns specified symbol with target and key arguments" do
|
|
326
|
-
module AdditionalMethods
|
|
327
|
-
def custom_batch_notification_email_allowed?(key)
|
|
328
|
-
true
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
test_instance.extend(AdditionalMethods)
|
|
332
|
-
described_class._batch_notification_email_allowed = :custom_batch_notification_email_allowed?
|
|
333
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
it "returns specified lambda with single target argument" do
|
|
337
|
-
described_class._batch_notification_email_allowed = ->(target){ true }
|
|
338
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
it "returns specified lambda with target and key arguments" do
|
|
342
|
-
described_class._batch_notification_email_allowed = ->(target, key){ true }
|
|
343
|
-
expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
describe "#subscription_allowed?" do
|
|
349
|
-
context "without any configuration" do
|
|
350
|
-
it "returns ActivityNotification.config.subscription_enabled" do
|
|
351
|
-
expect(test_instance.subscription_allowed?('dummy_key'))
|
|
352
|
-
.to eq(ActivityNotification.config.subscription_enabled)
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
it "returns false as default" do
|
|
356
|
-
expect(test_instance.subscription_allowed?('dummy_key')).to be_falsey
|
|
357
|
-
end
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
context "configured with a field" do
|
|
361
|
-
it "returns specified value" do
|
|
362
|
-
described_class._notification_subscription_allowed = true
|
|
363
|
-
expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
it "returns specified symbol without argument" do
|
|
367
|
-
module AdditionalMethods
|
|
368
|
-
def custom_subscription_allowed?
|
|
369
|
-
true
|
|
370
|
-
end
|
|
371
|
-
end
|
|
372
|
-
test_instance.extend(AdditionalMethods)
|
|
373
|
-
described_class._notification_subscription_allowed = :custom_subscription_allowed?
|
|
374
|
-
expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
it "returns specified symbol with key argument" do
|
|
378
|
-
module AdditionalMethods
|
|
379
|
-
def custom_subscription_allowed?(key)
|
|
380
|
-
true
|
|
381
|
-
end
|
|
382
|
-
end
|
|
383
|
-
test_instance.extend(AdditionalMethods)
|
|
384
|
-
described_class._notification_subscription_allowed = :custom_subscription_allowed?
|
|
385
|
-
expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
it "returns specified lambda with single target argument" do
|
|
389
|
-
described_class._notification_subscription_allowed = ->(target){ true }
|
|
390
|
-
expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
it "returns specified lambda with target and key arguments" do
|
|
394
|
-
described_class._notification_subscription_allowed = ->(target, key){ true }
|
|
395
|
-
expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
|
|
396
|
-
end
|
|
397
|
-
end
|
|
398
|
-
end
|
|
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
|
-
|
|
509
|
-
describe "#authenticated_with_devise?" do
|
|
510
|
-
context "without any configuration" do
|
|
511
|
-
context "when the current devise resource and called target are different class instance" do
|
|
512
|
-
it "raises TypeError" do
|
|
513
|
-
expect { test_instance.authenticated_with_devise?(test_notifiable) }
|
|
514
|
-
.to raise_error(TypeError, /Different type of .+ has been passed to .+ You have to override .+ /)
|
|
515
|
-
end
|
|
516
|
-
end
|
|
517
|
-
|
|
518
|
-
context "when the current devise resource equals called target" do
|
|
519
|
-
it "returns true" do
|
|
520
|
-
expect(test_instance.authenticated_with_devise?(test_instance)).to be_truthy
|
|
521
|
-
end
|
|
522
|
-
end
|
|
523
|
-
|
|
524
|
-
context "when the current devise resource does not equal called target" do
|
|
525
|
-
it "returns false" do
|
|
526
|
-
expect(test_instance.authenticated_with_devise?(create(test_class_name))).to be_falsey
|
|
527
|
-
end
|
|
528
|
-
end
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
context "configured with a field" do
|
|
532
|
-
context "when the current devise resource and called target are different class instance" do
|
|
533
|
-
it "raises TypeError" do
|
|
534
|
-
described_class._notification_devise_resource = test_notifiable
|
|
535
|
-
expect { test_instance.authenticated_with_devise?(test_instance) }
|
|
536
|
-
.to raise_error(TypeError, /Different type of .+ has been passed to .+ You have to override .+ /)
|
|
537
|
-
end
|
|
538
|
-
end
|
|
539
|
-
|
|
540
|
-
context "when the current devise resource equals called target" do
|
|
541
|
-
it "returns true" do
|
|
542
|
-
described_class._notification_devise_resource = test_notifiable
|
|
543
|
-
expect(test_instance.authenticated_with_devise?(test_notifiable)).to be_truthy
|
|
544
|
-
end
|
|
545
|
-
end
|
|
546
|
-
|
|
547
|
-
context "when the current devise resource does not equal called target" do
|
|
548
|
-
it "returns false" do
|
|
549
|
-
described_class._notification_devise_resource = test_instance
|
|
550
|
-
expect(test_instance.authenticated_with_devise?(create(test_class_name))).to be_falsey
|
|
551
|
-
end
|
|
552
|
-
end
|
|
553
|
-
end
|
|
554
|
-
end
|
|
555
|
-
|
|
556
|
-
describe "#printable_target_name" do
|
|
557
|
-
context "without any configuration" do
|
|
558
|
-
it "returns ActivityNotification::Common.printable_name" do
|
|
559
|
-
expect(test_instance.printable_target_name).to eq(test_instance.printable_name)
|
|
560
|
-
end
|
|
561
|
-
end
|
|
562
|
-
|
|
563
|
-
context "configured with a field" do
|
|
564
|
-
it "returns specified value" do
|
|
565
|
-
described_class._printable_notification_target_name = 'test_printable_name'
|
|
566
|
-
expect(test_instance.printable_target_name).to eq('test_printable_name')
|
|
567
|
-
end
|
|
568
|
-
|
|
569
|
-
it "returns specified symbol of field" do
|
|
570
|
-
described_class._printable_notification_target_name = :name
|
|
571
|
-
expect(test_instance.printable_target_name).to eq(test_instance.name)
|
|
572
|
-
end
|
|
573
|
-
|
|
574
|
-
it "returns specified symbol of method" do
|
|
575
|
-
module AdditionalMethods
|
|
576
|
-
def custom_printable_name
|
|
577
|
-
'test_printable_name'
|
|
578
|
-
end
|
|
579
|
-
end
|
|
580
|
-
test_instance.extend(AdditionalMethods)
|
|
581
|
-
described_class._printable_notification_target_name = :custom_printable_name
|
|
582
|
-
expect(test_instance.printable_target_name).to eq('test_printable_name')
|
|
583
|
-
end
|
|
584
|
-
|
|
585
|
-
it "returns specified lambda with single target argument" do
|
|
586
|
-
described_class._printable_notification_target_name = ->(target){ 'test_printable_name' }
|
|
587
|
-
expect(test_instance.printable_target_name).to eq('test_printable_name')
|
|
588
|
-
end
|
|
589
|
-
end
|
|
590
|
-
end
|
|
591
|
-
|
|
592
|
-
describe "#unopened_notification_count" do
|
|
593
|
-
it "returns count of unopened notification index" do
|
|
594
|
-
create(:notification, target: test_instance)
|
|
595
|
-
create(:notification, target: test_instance)
|
|
596
|
-
expect(test_instance.unopened_notification_count).to eq(2)
|
|
597
|
-
end
|
|
598
|
-
|
|
599
|
-
it "returns count of unopened notification index (owner only)" do
|
|
600
|
-
group_owner = create(:notification, target: test_instance, group_owner: nil)
|
|
601
|
-
create(:notification, target: test_instance, group_owner: nil)
|
|
602
|
-
group_member = create(:notification, target: test_instance, group_owner: group_owner)
|
|
603
|
-
expect(test_instance.unopened_notification_count).to eq(2)
|
|
604
|
-
end
|
|
605
|
-
end
|
|
606
|
-
|
|
607
|
-
describe "#has_unopened_notifications?" do
|
|
608
|
-
context "when the target has no unopened notifications" do
|
|
609
|
-
it "returns false" do
|
|
610
|
-
expect(test_instance.has_unopened_notifications?).to be_falsey
|
|
611
|
-
end
|
|
612
|
-
end
|
|
613
|
-
|
|
614
|
-
context "when the target has unopened notifications" do
|
|
615
|
-
it "returns true" do
|
|
616
|
-
create(:notification, target: test_instance)
|
|
617
|
-
expect(test_instance.has_unopened_notifications?).to be_truthy
|
|
618
|
-
end
|
|
619
|
-
end
|
|
620
|
-
end
|
|
621
|
-
|
|
622
|
-
describe "#notification_index" do
|
|
623
|
-
context "when the target has no notifications" do
|
|
624
|
-
it "returns empty records" do
|
|
625
|
-
expect(test_instance.notification_index).to be_empty
|
|
626
|
-
end
|
|
627
|
-
end
|
|
628
|
-
|
|
629
|
-
context "when the target has unopened notifications" do
|
|
630
|
-
before do
|
|
631
|
-
@notifiable = create(:article)
|
|
632
|
-
@group = create(:article)
|
|
633
|
-
@key = 'test.key.1'
|
|
634
|
-
@notification2 = create(:notification, target: test_instance, notifiable: @notifiable)
|
|
635
|
-
@notification1 = create(:notification, target: test_instance, notifiable: create(:comment), group: @group, created_at: @notification2.created_at + 10.second)
|
|
636
|
-
@member1 = create(:notification, target: test_instance, notifiable: create(:comment), group_owner: @notification1, created_at: @notification2.created_at + 20.second)
|
|
637
|
-
@notification3 = create(:notification, target: test_instance, notifiable: create(:article), key: @key, created_at: @notification2.created_at + 30.second)
|
|
638
|
-
@notification3.open!
|
|
639
|
-
end
|
|
640
|
-
|
|
641
|
-
it "calls unopened_notification_index" do
|
|
642
|
-
expect(test_instance).to receive(:unopened_notification_index).at_least(:once)
|
|
643
|
-
test_instance.notification_index
|
|
644
|
-
end
|
|
645
|
-
|
|
646
|
-
context "without any options" do
|
|
647
|
-
it "returns the combined array of unopened_notification_index and opened_notification_index" do
|
|
648
|
-
expect(test_instance.notification_index[0]).to eq(@notification1)
|
|
649
|
-
expect(test_instance.notification_index[1]).to eq(@notification2)
|
|
650
|
-
expect(test_instance.notification_index[2]).to eq(@notification3)
|
|
651
|
-
expect(test_instance.notification_index.size).to eq(3)
|
|
652
|
-
end
|
|
653
|
-
end
|
|
654
|
-
|
|
655
|
-
context "with limit" do
|
|
656
|
-
it "returns the same as unopened_notification_index with limit" do
|
|
657
|
-
options = { limit: 1 }
|
|
658
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification1)
|
|
659
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
660
|
-
end
|
|
661
|
-
end
|
|
662
|
-
|
|
663
|
-
context "with reverse" do
|
|
664
|
-
it "returns the earliest order" do
|
|
665
|
-
options = { reverse: true }
|
|
666
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification2)
|
|
667
|
-
expect(test_instance.notification_index(options)[1]).to eq(@notification1)
|
|
668
|
-
expect(test_instance.notification_index(options)[2]).to eq(@notification3)
|
|
669
|
-
expect(test_instance.notification_index(options).size).to eq(3)
|
|
670
|
-
end
|
|
671
|
-
end
|
|
672
|
-
|
|
673
|
-
context "with with_group_members" do
|
|
674
|
-
it "returns the index with group members" do
|
|
675
|
-
options = { with_group_members: true }
|
|
676
|
-
expect(test_instance.notification_index(options)[0]).to eq(@member1)
|
|
677
|
-
expect(test_instance.notification_index(options)[1]).to eq(@notification1)
|
|
678
|
-
expect(test_instance.notification_index(options)[2]).to eq(@notification2)
|
|
679
|
-
expect(test_instance.notification_index(options)[3]).to eq(@notification3)
|
|
680
|
-
expect(test_instance.notification_index(options).size).to eq(4)
|
|
681
|
-
end
|
|
682
|
-
end
|
|
683
|
-
|
|
684
|
-
context "with as_latest_group_member" do
|
|
685
|
-
it "returns the index as latest group member" do
|
|
686
|
-
options = { as_latest_group_member: true }
|
|
687
|
-
expect(test_instance.notification_index(options)[0]).to eq(@member1)
|
|
688
|
-
expect(test_instance.notification_index(options)[1]).to eq(@notification2)
|
|
689
|
-
expect(test_instance.notification_index(options)[2]).to eq(@notification3)
|
|
690
|
-
expect(test_instance.notification_index(options).size).to eq(3)
|
|
691
|
-
end
|
|
692
|
-
end
|
|
693
|
-
|
|
694
|
-
context 'with filtered_by_type options' do
|
|
695
|
-
it "returns filtered notifications only" do
|
|
696
|
-
options = { filtered_by_type: 'Article' }
|
|
697
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification2)
|
|
698
|
-
expect(test_instance.notification_index(options)[1]).to eq(@notification3)
|
|
699
|
-
expect(test_instance.notification_index(options).size).to eq(2)
|
|
700
|
-
options = { filtered_by_type: 'Comment' }
|
|
701
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification1)
|
|
702
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
703
|
-
end
|
|
704
|
-
end
|
|
705
|
-
|
|
706
|
-
context 'with filtered_by_group options' do
|
|
707
|
-
it "returns filtered notifications only" do
|
|
708
|
-
options = { filtered_by_group: @group }
|
|
709
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification1)
|
|
710
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
711
|
-
end
|
|
712
|
-
end
|
|
713
|
-
|
|
714
|
-
context 'with filtered_by_group_type and :filtered_by_group_id options' do
|
|
715
|
-
it "returns filtered notifications only" do
|
|
716
|
-
options = { filtered_by_group_type: 'Article', filtered_by_group_id: @group.id.to_s }
|
|
717
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification1)
|
|
718
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
719
|
-
end
|
|
720
|
-
end
|
|
721
|
-
|
|
722
|
-
context 'with filtered_by_key options' do
|
|
723
|
-
it "returns filtered notifications only" do
|
|
724
|
-
options = { filtered_by_key: @key }
|
|
725
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification3)
|
|
726
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
727
|
-
end
|
|
728
|
-
end
|
|
729
|
-
|
|
730
|
-
context 'with later_than options' do
|
|
731
|
-
it "returns filtered notifications only" do
|
|
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
|
|
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
|
|
748
|
-
options = { custom_filter: { key: @key } }
|
|
749
|
-
expect(test_instance.notification_index(options)[0]).to eq(@notification3)
|
|
750
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
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
|
|
763
|
-
end
|
|
764
|
-
end
|
|
765
|
-
|
|
766
|
-
context "when the target has no unopened notifications" do
|
|
767
|
-
before do
|
|
768
|
-
notification = create(:notification, target: test_instance, opened_at: Time.current)
|
|
769
|
-
create(:notification, target: test_instance, opened_at: Time.current, created_at: notification.created_at + 10.second)
|
|
770
|
-
end
|
|
771
|
-
|
|
772
|
-
it "calls unopened_notification_index" do
|
|
773
|
-
expect(test_instance).to receive(:opened_notification_index).at_least(:once)
|
|
774
|
-
test_instance.notification_index
|
|
775
|
-
end
|
|
776
|
-
|
|
777
|
-
context "without limit" do
|
|
778
|
-
it "returns the same as opened_notification_index" do
|
|
779
|
-
expect(test_instance.notification_index).to eq(test_instance.opened_notification_index)
|
|
780
|
-
expect(test_instance.notification_index.size).to eq(2)
|
|
781
|
-
end
|
|
782
|
-
end
|
|
783
|
-
|
|
784
|
-
context "with limit" do
|
|
785
|
-
it "returns the same as opened_notification_index with limit" do
|
|
786
|
-
options = { limit: 1 }
|
|
787
|
-
expect(test_instance.notification_index(options)).to eq(test_instance.opened_notification_index(options))
|
|
788
|
-
expect(test_instance.notification_index(options).size).to eq(1)
|
|
789
|
-
end
|
|
790
|
-
end
|
|
791
|
-
end
|
|
792
|
-
end
|
|
793
|
-
|
|
794
|
-
describe "#unopened_notification_index" do
|
|
795
|
-
context "when the target has no notifications" do
|
|
796
|
-
it "returns empty records" do
|
|
797
|
-
expect(test_instance.unopened_notification_index).to be_empty
|
|
798
|
-
end
|
|
799
|
-
end
|
|
800
|
-
|
|
801
|
-
context "when the target has unopened notifications" do
|
|
802
|
-
before do
|
|
803
|
-
@notification_1 = create(:notification, target: test_instance)
|
|
804
|
-
@notification_2 = create(:notification, target: test_instance, created_at: @notification_1.created_at + 10.second)
|
|
805
|
-
end
|
|
806
|
-
|
|
807
|
-
context "without limit" do
|
|
808
|
-
it "returns unopened notification index" do
|
|
809
|
-
expect(test_instance.unopened_notification_index.size).to eq(2)
|
|
810
|
-
expect(test_instance.unopened_notification_index.last).to eq(@notification_1)
|
|
811
|
-
expect(test_instance.unopened_notification_index.first).to eq(@notification_2)
|
|
812
|
-
end
|
|
813
|
-
|
|
814
|
-
it "returns unopened notification index (owner only)" do
|
|
815
|
-
group_member = create(:notification, target: test_instance, group_owner: @notification_1)
|
|
816
|
-
expect(test_instance.unopened_notification_index.size).to eq(2)
|
|
817
|
-
expect(test_instance.unopened_notification_index.last).to eq(@notification_1)
|
|
818
|
-
expect(test_instance.unopened_notification_index.first).to eq(@notification_2)
|
|
819
|
-
end
|
|
820
|
-
|
|
821
|
-
it "returns unopened notification index (unopened only)" do
|
|
822
|
-
notification_3 = create(:notification, target: test_instance, opened_at: Time.current)
|
|
823
|
-
expect(test_instance.unopened_notification_index.size).to eq(2)
|
|
824
|
-
expect(test_instance.unopened_notification_index.last).to eq(@notification_1)
|
|
825
|
-
expect(test_instance.unopened_notification_index.first).to eq(@notification_2)
|
|
826
|
-
end
|
|
827
|
-
end
|
|
828
|
-
|
|
829
|
-
context "with limit" do
|
|
830
|
-
it "returns unopened notification index with limit" do
|
|
831
|
-
options = { limit: 1 }
|
|
832
|
-
expect(test_instance.unopened_notification_index(options).size).to eq(1)
|
|
833
|
-
expect(test_instance.unopened_notification_index(options).first).to eq(@notification_2)
|
|
834
|
-
end
|
|
835
|
-
end
|
|
836
|
-
end
|
|
837
|
-
|
|
838
|
-
context "when the target has no unopened notifications" do
|
|
839
|
-
before do
|
|
840
|
-
create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
|
|
841
|
-
create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
|
|
842
|
-
end
|
|
843
|
-
|
|
844
|
-
it "returns empty records" do
|
|
845
|
-
expect(test_instance.unopened_notification_index).to be_empty
|
|
846
|
-
end
|
|
847
|
-
end
|
|
848
|
-
end
|
|
849
|
-
|
|
850
|
-
describe "#opened_notification_index" do
|
|
851
|
-
context "when the target has no notifications" do
|
|
852
|
-
it "returns empty records" do
|
|
853
|
-
expect(test_instance.opened_notification_index).to be_empty
|
|
854
|
-
end
|
|
855
|
-
end
|
|
856
|
-
|
|
857
|
-
context "when the target has opened notifications" do
|
|
858
|
-
before do
|
|
859
|
-
@notification_1 = create(:notification, target: test_instance, opened_at: Time.current)
|
|
860
|
-
@notification_2 = create(:notification, target: test_instance, opened_at: Time.current, created_at: @notification_1.created_at + 10.second)
|
|
861
|
-
end
|
|
862
|
-
|
|
863
|
-
context "without limit" do
|
|
864
|
-
it "uses ActivityNotification.config.opened_index_limit as limit" do
|
|
865
|
-
configured_opened_index_limit = ActivityNotification.config.opened_index_limit
|
|
866
|
-
ActivityNotification.config.opened_index_limit = 1
|
|
867
|
-
expect(test_instance.opened_notification_index.size).to eq(1)
|
|
868
|
-
expect(test_instance.opened_notification_index.first).to eq(@notification_2)
|
|
869
|
-
ActivityNotification.config.opened_index_limit = configured_opened_index_limit
|
|
870
|
-
end
|
|
871
|
-
|
|
872
|
-
it "returns opened notification index" do
|
|
873
|
-
expect(test_instance.opened_notification_index.size).to eq(2)
|
|
874
|
-
expect(test_instance.opened_notification_index.last).to eq(@notification_1)
|
|
875
|
-
expect(test_instance.opened_notification_index.first).to eq(@notification_2)
|
|
876
|
-
end
|
|
877
|
-
|
|
878
|
-
it "returns opened notification index (owner only)" do
|
|
879
|
-
group_member = create(:notification, target: test_instance, group_owner: @notification_1, opened_at: Time.current)
|
|
880
|
-
expect(test_instance.opened_notification_index.size).to eq(2)
|
|
881
|
-
expect(test_instance.opened_notification_index.last).to eq(@notification_1)
|
|
882
|
-
expect(test_instance.opened_notification_index.first).to eq(@notification_2)
|
|
883
|
-
end
|
|
884
|
-
|
|
885
|
-
it "returns opened notification index (opened only)" do
|
|
886
|
-
notification_3 = create(:notification, target: test_instance)
|
|
887
|
-
expect(test_instance.opened_notification_index.size).to eq(2)
|
|
888
|
-
expect(test_instance.opened_notification_index.last).to eq(@notification_1)
|
|
889
|
-
expect(test_instance.opened_notification_index.first).to eq(@notification_2)
|
|
890
|
-
end
|
|
891
|
-
end
|
|
892
|
-
|
|
893
|
-
context "with limit" do
|
|
894
|
-
it "returns opened notification index with limit" do
|
|
895
|
-
options = { limit: 1 }
|
|
896
|
-
expect(test_instance.opened_notification_index(options).size).to eq(1)
|
|
897
|
-
expect(test_instance.opened_notification_index(options).first).to eq(@notification_2)
|
|
898
|
-
end
|
|
899
|
-
end
|
|
900
|
-
end
|
|
901
|
-
|
|
902
|
-
context "when the target has no opened notifications" do
|
|
903
|
-
before do
|
|
904
|
-
create(:notification, target: test_instance, group_owner: nil)
|
|
905
|
-
create(:notification, target: test_instance, group_owner: nil)
|
|
906
|
-
end
|
|
907
|
-
|
|
908
|
-
it "returns empty records" do
|
|
909
|
-
expect(test_instance.opened_notification_index).to be_empty
|
|
910
|
-
end
|
|
911
|
-
end
|
|
912
|
-
end
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
# Wrapper methods of Notification class methods
|
|
916
|
-
|
|
917
|
-
describe "#receive_notification_of" do
|
|
918
|
-
it "is an alias of ActivityNotification::Notification.notify_to" do
|
|
919
|
-
expect(ActivityNotification::Notification).to receive(:notify_to)
|
|
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)
|
|
928
|
-
end
|
|
929
|
-
end
|
|
930
|
-
|
|
931
|
-
describe "#open_all_notifications" do
|
|
932
|
-
it "is an alias of ActivityNotification::Notification.open_all_of" do
|
|
933
|
-
expect(ActivityNotification::Notification).to receive(:open_all_of)
|
|
934
|
-
test_instance.open_all_notifications
|
|
935
|
-
end
|
|
936
|
-
end
|
|
937
|
-
|
|
938
|
-
describe "#destroy_all_notifications" do
|
|
939
|
-
it "is an alias of ActivityNotification::Notification.destroy_all_of" do
|
|
940
|
-
expect(ActivityNotification::Notification).to receive(:destroy_all_of)
|
|
941
|
-
test_instance.destroy_all_notifications
|
|
942
|
-
end
|
|
943
|
-
end
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
# Methods to be overridden
|
|
947
|
-
|
|
948
|
-
describe "#notification_index_with_attributes" do
|
|
949
|
-
context "when the target has no notifications" do
|
|
950
|
-
it "returns empty records" do
|
|
951
|
-
expect(test_instance.notification_index_with_attributes).to be_empty
|
|
952
|
-
end
|
|
953
|
-
end
|
|
954
|
-
|
|
955
|
-
context "when the target has unopened notifications" do
|
|
956
|
-
before do
|
|
957
|
-
@notifiable = create(:article)
|
|
958
|
-
@group = create(:article)
|
|
959
|
-
@key = 'test.key.1'
|
|
960
|
-
@notification2 = create(:notification, target: test_instance, notifiable: @notifiable)
|
|
961
|
-
@notification1 = create(:notification, target: test_instance, notifiable: create(:comment), group: @group, created_at: @notification2.created_at + 10.second)
|
|
962
|
-
@notification3 = create(:notification, target: test_instance, notifiable: create(:article), key: @key, created_at: @notification2.created_at + 20.second)
|
|
963
|
-
@notification3.open!
|
|
964
|
-
end
|
|
965
|
-
|
|
966
|
-
it "calls unopened_notification_index_with_attributes" do
|
|
967
|
-
expect(test_instance).to receive(:unopened_notification_index_with_attributes).at_least(:once)
|
|
968
|
-
test_instance.notification_index_with_attributes
|
|
969
|
-
end
|
|
970
|
-
|
|
971
|
-
context "without any options" do
|
|
972
|
-
it "returns the combined array of unopened_notification_index_with_attributes and opened_notification_index_with_attributes" do
|
|
973
|
-
expect(test_instance.notification_index_with_attributes[0]).to eq(@notification1)
|
|
974
|
-
expect(test_instance.notification_index_with_attributes[1]).to eq(@notification2)
|
|
975
|
-
expect(test_instance.notification_index_with_attributes[2]).to eq(@notification3)
|
|
976
|
-
expect(test_instance.notification_index_with_attributes.size).to eq(3)
|
|
977
|
-
end
|
|
978
|
-
end
|
|
979
|
-
|
|
980
|
-
context "with limit" do
|
|
981
|
-
it "returns the same as unopened_notification_index_with_attributes with limit" do
|
|
982
|
-
options = { limit: 1 }
|
|
983
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification1)
|
|
984
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
985
|
-
end
|
|
986
|
-
end
|
|
987
|
-
|
|
988
|
-
context "with reverse" do
|
|
989
|
-
it "returns the earliest order" do
|
|
990
|
-
options = { reverse: true }
|
|
991
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification2)
|
|
992
|
-
expect(test_instance.notification_index_with_attributes(options)[1]).to eq(@notification1)
|
|
993
|
-
expect(test_instance.notification_index_with_attributes(options)[2]).to eq(@notification3)
|
|
994
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(3)
|
|
995
|
-
end
|
|
996
|
-
end
|
|
997
|
-
|
|
998
|
-
context 'with filtered_by_type options' do
|
|
999
|
-
it "returns filtered notifications only" do
|
|
1000
|
-
options = { filtered_by_type: 'Article' }
|
|
1001
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification2)
|
|
1002
|
-
expect(test_instance.notification_index_with_attributes(options)[1]).to eq(@notification3)
|
|
1003
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(2)
|
|
1004
|
-
options = { filtered_by_type: 'Comment' }
|
|
1005
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification1)
|
|
1006
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1007
|
-
end
|
|
1008
|
-
end
|
|
1009
|
-
|
|
1010
|
-
context 'with filtered_by_group options' do
|
|
1011
|
-
it "returns filtered notifications only" do
|
|
1012
|
-
options = { filtered_by_group: @group }
|
|
1013
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification1)
|
|
1014
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1015
|
-
end
|
|
1016
|
-
end
|
|
1017
|
-
|
|
1018
|
-
context 'with filtered_by_group_type and :filtered_by_group_id options' do
|
|
1019
|
-
it "returns filtered notifications only" do
|
|
1020
|
-
options = { filtered_by_group_type: 'Article', filtered_by_group_id: @group.id.to_s }
|
|
1021
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification1)
|
|
1022
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1023
|
-
end
|
|
1024
|
-
end
|
|
1025
|
-
|
|
1026
|
-
context 'with filtered_by_key options' do
|
|
1027
|
-
it "returns filtered notifications only" do
|
|
1028
|
-
options = { filtered_by_key: @key }
|
|
1029
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification3)
|
|
1030
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1031
|
-
end
|
|
1032
|
-
end
|
|
1033
|
-
|
|
1034
|
-
context 'with later_than options' do
|
|
1035
|
-
it "returns filtered notifications only" do
|
|
1036
|
-
options = { later_than: (@notification1.created_at.in_time_zone + 0.001).iso8601(3) }
|
|
1037
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification3)
|
|
1038
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1039
|
-
end
|
|
1040
|
-
end
|
|
1041
|
-
|
|
1042
|
-
context 'with earlier_than options' do
|
|
1043
|
-
it "returns filtered notifications only" do
|
|
1044
|
-
options = { earlier_than: @notification1.created_at.iso8601(3) }
|
|
1045
|
-
expect(test_instance.notification_index_with_attributes(options)[0]).to eq(@notification2)
|
|
1046
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1047
|
-
end
|
|
1048
|
-
end
|
|
1049
|
-
end
|
|
1050
|
-
|
|
1051
|
-
context "when the target has no unopened notifications" do
|
|
1052
|
-
before do
|
|
1053
|
-
notification = create(:notification, target: test_instance, opened_at: Time.current)
|
|
1054
|
-
create(:notification, target: test_instance, opened_at: Time.current, created_at: notification.created_at + 10.second)
|
|
1055
|
-
end
|
|
1056
|
-
|
|
1057
|
-
it "calls unopened_notification_index_with_attributes" do
|
|
1058
|
-
expect(test_instance).to receive(:opened_notification_index_with_attributes)
|
|
1059
|
-
test_instance.notification_index_with_attributes
|
|
1060
|
-
end
|
|
1061
|
-
|
|
1062
|
-
context "without limit" do
|
|
1063
|
-
it "returns the same as opened_notification_index_with_attributes" do
|
|
1064
|
-
expect(test_instance.notification_index_with_attributes).to eq(test_instance.opened_notification_index_with_attributes)
|
|
1065
|
-
expect(test_instance.notification_index_with_attributes.size).to eq(2)
|
|
1066
|
-
end
|
|
1067
|
-
end
|
|
1068
|
-
|
|
1069
|
-
context "with limit" do
|
|
1070
|
-
it "returns the same as opened_notification_index_with_attributes with limit" do
|
|
1071
|
-
options = { limit: 1 }
|
|
1072
|
-
expect(test_instance.notification_index_with_attributes(options)).to eq(test_instance.opened_notification_index_with_attributes(options))
|
|
1073
|
-
expect(test_instance.notification_index_with_attributes(options).size).to eq(1)
|
|
1074
|
-
end
|
|
1075
|
-
end
|
|
1076
|
-
end
|
|
1077
|
-
end
|
|
1078
|
-
|
|
1079
|
-
describe "#unopened_notification_index_with_attributes" do
|
|
1080
|
-
it "calls _unopened_notification_index" do
|
|
1081
|
-
expect(test_instance).to receive(:_unopened_notification_index)
|
|
1082
|
-
test_instance.unopened_notification_index_with_attributes
|
|
1083
|
-
end
|
|
1084
|
-
|
|
1085
|
-
context "when the target has unopened notifications with no group members" do
|
|
1086
|
-
context "with no group members" do
|
|
1087
|
-
before do
|
|
1088
|
-
create(:notification, target: test_instance)
|
|
1089
|
-
create(:notification, target: test_instance)
|
|
1090
|
-
end
|
|
1091
|
-
|
|
1092
|
-
if ActivityNotification.config.orm == :active_record
|
|
1093
|
-
it "calls with_target, with_notifiable, with_notifier and does not call with_group" do
|
|
1094
|
-
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_notifier)
|
|
1095
|
-
test_instance.unopened_notification_index_with_attributes
|
|
1096
|
-
end
|
|
1097
|
-
end
|
|
1098
|
-
end
|
|
1099
|
-
|
|
1100
|
-
context "with group members" do
|
|
1101
|
-
before do
|
|
1102
|
-
group_owner = create(:notification, target: test_instance, group_owner: nil)
|
|
1103
|
-
create(:notification, target: test_instance, group_owner: nil)
|
|
1104
|
-
group_member = create(:notification, target: test_instance, group_owner: group_owner)
|
|
1105
|
-
end
|
|
1106
|
-
|
|
1107
|
-
if ActivityNotification.config.orm == :active_record
|
|
1108
|
-
it "calls with_group" do
|
|
1109
|
-
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_group, :with_notifier)
|
|
1110
|
-
test_instance.unopened_notification_index_with_attributes
|
|
1111
|
-
end
|
|
1112
|
-
end
|
|
1113
|
-
end
|
|
1114
|
-
end
|
|
1115
|
-
|
|
1116
|
-
context "when the target has no unopened notifications" do
|
|
1117
|
-
before do
|
|
1118
|
-
create(:notification, target: test_instance, opened_at: Time.current)
|
|
1119
|
-
create(:notification, target: test_instance, opened_at: Time.current)
|
|
1120
|
-
end
|
|
1121
|
-
|
|
1122
|
-
it "returns empty records" do
|
|
1123
|
-
expect(test_instance.unopened_notification_index_with_attributes).to be_empty
|
|
1124
|
-
end
|
|
1125
|
-
end
|
|
1126
|
-
end
|
|
1127
|
-
|
|
1128
|
-
describe "#opened_notification_index_with_attributes" do
|
|
1129
|
-
it "calls _opened_notification_index" do
|
|
1130
|
-
expect(test_instance).to receive(:_opened_notification_index)
|
|
1131
|
-
test_instance.opened_notification_index_with_attributes
|
|
1132
|
-
end
|
|
1133
|
-
|
|
1134
|
-
context "when the target has opened notifications with no group members" do
|
|
1135
|
-
context "with no group members" do
|
|
1136
|
-
before do
|
|
1137
|
-
create(:notification, target: test_instance, opened_at: Time.current)
|
|
1138
|
-
create(:notification, target: test_instance, opened_at: Time.current)
|
|
1139
|
-
end
|
|
1140
|
-
|
|
1141
|
-
if ActivityNotification.config.orm == :active_record
|
|
1142
|
-
it "calls with_target, with_notifiable, with_notifier and does not call with_group" do
|
|
1143
|
-
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_notifier)
|
|
1144
|
-
test_instance.opened_notification_index_with_attributes
|
|
1145
|
-
end
|
|
1146
|
-
end
|
|
1147
|
-
end
|
|
1148
|
-
|
|
1149
|
-
context "with group members" do
|
|
1150
|
-
before do
|
|
1151
|
-
group_owner = create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
|
|
1152
|
-
create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
|
|
1153
|
-
group_member = create(:notification, target: test_instance, group_owner: group_owner, opened_at: Time.current)
|
|
1154
|
-
end
|
|
1155
|
-
|
|
1156
|
-
if ActivityNotification.config.orm == :active_record
|
|
1157
|
-
it "calls with_group" do
|
|
1158
|
-
expect(ActivityNotification::Notification).to receive_message_chain(:with_target, :with_notifiable, :with_group, :with_notifier)
|
|
1159
|
-
test_instance.opened_notification_index_with_attributes
|
|
1160
|
-
end
|
|
1161
|
-
end
|
|
1162
|
-
end
|
|
1163
|
-
end
|
|
1164
|
-
|
|
1165
|
-
context "when the target has no opened notifications" do
|
|
1166
|
-
before do
|
|
1167
|
-
create(:notification, target: test_instance)
|
|
1168
|
-
create(:notification, target: test_instance)
|
|
1169
|
-
end
|
|
1170
|
-
|
|
1171
|
-
it "returns empty records" do
|
|
1172
|
-
expect(test_instance.opened_notification_index_with_attributes).to be_empty
|
|
1173
|
-
end
|
|
1174
|
-
end
|
|
1175
|
-
end
|
|
1176
|
-
|
|
1177
|
-
describe "#send_notification_email" do
|
|
1178
|
-
context "with right target of notification" do
|
|
1179
|
-
before do
|
|
1180
|
-
@notification = create(:notification, target: test_instance)
|
|
1181
|
-
end
|
|
1182
|
-
|
|
1183
|
-
it "calls notification.send_notification_email" do
|
|
1184
|
-
expect(@notification).to receive(:send_notification_email).at_least(:once)
|
|
1185
|
-
test_instance.send_notification_email(@notification)
|
|
1186
|
-
end
|
|
1187
|
-
end
|
|
1188
|
-
|
|
1189
|
-
context "with wrong target of notification" do
|
|
1190
|
-
before do
|
|
1191
|
-
@notification = create(:notification, target: create(:user))
|
|
1192
|
-
end
|
|
1193
|
-
|
|
1194
|
-
it "does not call notification.send_notification_email" do
|
|
1195
|
-
expect(@notification).not_to receive(:send_notification_email)
|
|
1196
|
-
test_instance.send_notification_email(@notification)
|
|
1197
|
-
end
|
|
1198
|
-
|
|
1199
|
-
it "returns nil" do
|
|
1200
|
-
expect(test_instance.send_notification_email(@notification)).to be_nil
|
|
1201
|
-
end
|
|
1202
|
-
end
|
|
1203
|
-
end
|
|
1204
|
-
|
|
1205
|
-
describe "#send_batch_notification_email" do
|
|
1206
|
-
context "with right target of notification" do
|
|
1207
|
-
before do
|
|
1208
|
-
@notifications = [create(:notification, target: test_instance), create(:notification, target: test_instance)]
|
|
1209
|
-
end
|
|
1210
|
-
|
|
1211
|
-
it "calls ActivityNotification::Notification.send_batch_notification_email" do
|
|
1212
|
-
expect(ActivityNotification::Notification).to receive(:send_batch_notification_email).at_least(:once)
|
|
1213
|
-
test_instance.send_batch_notification_email(@notifications)
|
|
1214
|
-
end
|
|
1215
|
-
end
|
|
1216
|
-
|
|
1217
|
-
context "with wrong target of notification" do
|
|
1218
|
-
before do
|
|
1219
|
-
notifications = [create(:notification, target: test_instance), create(:notification, target: create(:user))]
|
|
1220
|
-
end
|
|
1221
|
-
|
|
1222
|
-
it "does not call ActivityNotification::Notification.send_batch_notification_email" do
|
|
1223
|
-
expect(ActivityNotification::Notification).not_to receive(:send_batch_notification_email)
|
|
1224
|
-
test_instance.send_batch_notification_email(@notifications)
|
|
1225
|
-
end
|
|
1226
|
-
|
|
1227
|
-
it "returns nil" do
|
|
1228
|
-
expect(test_instance.send_batch_notification_email(@notifications)).to be_nil
|
|
1229
|
-
end
|
|
1230
|
-
end
|
|
1231
|
-
end
|
|
1232
|
-
|
|
1233
|
-
describe "#subscribes_to_notification?" do
|
|
1234
|
-
context "when the subscription is not enabled for the target" do
|
|
1235
|
-
it "returns true" do
|
|
1236
|
-
described_class._notification_subscription_allowed = false
|
|
1237
|
-
expect(test_instance.subscribes_to_notification?('test_key')).to be_truthy
|
|
1238
|
-
end
|
|
1239
|
-
end
|
|
1240
|
-
|
|
1241
|
-
context "when the subscription is enabled for the target" do
|
|
1242
|
-
it "calls Subscriber#_subscribes_to_notification?" do
|
|
1243
|
-
described_class._notification_subscription_allowed = true
|
|
1244
|
-
expect(test_instance).to receive(:_subscribes_to_notification?)
|
|
1245
|
-
test_instance.subscribes_to_notification?('test_key')
|
|
1246
|
-
end
|
|
1247
|
-
end
|
|
1248
|
-
end
|
|
1249
|
-
|
|
1250
|
-
describe "#subscribes_to_notification_email?" do
|
|
1251
|
-
context "when the subscription is not enabled for the target" do
|
|
1252
|
-
it "returns true" do
|
|
1253
|
-
described_class._notification_subscription_allowed = false
|
|
1254
|
-
expect(test_instance.subscribes_to_notification_email?('test_key')).to be_truthy
|
|
1255
|
-
end
|
|
1256
|
-
end
|
|
1257
|
-
|
|
1258
|
-
context "when the subscription is enabled for the target" do
|
|
1259
|
-
it "calls Subscriber#_subscribes_to_notification_email?" do
|
|
1260
|
-
described_class._notification_subscription_allowed = true
|
|
1261
|
-
expect(test_instance).to receive(:_subscribes_to_notification_email?)
|
|
1262
|
-
test_instance.subscribes_to_notification_email?('test_key')
|
|
1263
|
-
end
|
|
1264
|
-
end
|
|
1265
|
-
end
|
|
1266
|
-
|
|
1267
|
-
describe "#subscribes_to_optional_target?" do
|
|
1268
|
-
context "when the subscription is not enabled for the target" do
|
|
1269
|
-
it "returns true" do
|
|
1270
|
-
described_class._notification_subscription_allowed = false
|
|
1271
|
-
expect(test_instance.subscribes_to_optional_target?('test_key', :slack)).to be_truthy
|
|
1272
|
-
end
|
|
1273
|
-
end
|
|
1274
|
-
|
|
1275
|
-
context "when the subscription is enabled for the target" do
|
|
1276
|
-
it "calls Subscriber#_subscribes_to_optional_target?" do
|
|
1277
|
-
described_class._notification_subscription_allowed = true
|
|
1278
|
-
expect(test_instance).to receive(:_subscribes_to_optional_target?)
|
|
1279
|
-
test_instance.subscribes_to_optional_target?('test_key', :slack)
|
|
1280
|
-
end
|
|
1281
|
-
end
|
|
1282
|
-
end
|
|
1283
|
-
end
|
|
1284
|
-
|
|
1285
|
-
end
|