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