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.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/app/jobs/activity_notification/cascading_notification_job.rb +123 -0
  4. data/docs/Functions.md +197 -1
  5. data/lib/activity_notification/apis/cascading_notification_api.rb +208 -0
  6. data/lib/activity_notification/apis/notification_api.rb +3 -0
  7. data/lib/activity_notification/config.rb +10 -0
  8. data/lib/activity_notification/mailers/helpers.rb +27 -1
  9. data/lib/activity_notification/version.rb +1 -1
  10. data/lib/generators/templates/activity_notification.rb +8 -0
  11. metadata +5 -441
  12. data/.codeclimate.yml +0 -33
  13. data/.coveralls.yml +0 -1
  14. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -22
  15. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  16. data/.github/pull_request_template.md +0 -13
  17. data/.github/workflows/build.yml +0 -100
  18. data/.gitignore +0 -74
  19. data/.rspec +0 -3
  20. data/.rubocop.yml +0 -1157
  21. data/.yardopts +0 -6
  22. data/CHANGELOG.md +0 -452
  23. data/Gemfile +0 -31
  24. data/Procfile +0 -2
  25. data/Rakefile +0 -28
  26. data/activity_notification.gemspec +0 -44
  27. data/ai-curated-specs/issues/172/design.md +0 -220
  28. data/ai-curated-specs/issues/172/tasks.md +0 -326
  29. data/ai-curated-specs/issues/188/design.md +0 -227
  30. data/ai-curated-specs/issues/188/requirements.md +0 -78
  31. data/ai-curated-specs/issues/188/tasks.md +0 -203
  32. data/ai-curated-specs/issues/188/upstream-contributions.md +0 -592
  33. data/ai-curated-specs/issues/50/design.md +0 -235
  34. data/ai-curated-specs/issues/50/requirements.md +0 -49
  35. data/ai-curated-specs/issues/50/tasks.md +0 -232
  36. data/bin/_dynamodblocal +0 -4
  37. data/bin/bundle_update.sh +0 -7
  38. data/bin/deploy_on_heroku.sh +0 -16
  39. data/bin/install_dynamodblocal.sh +0 -5
  40. data/bin/start_dynamodblocal.sh +0 -47
  41. data/bin/stop_dynamodblocal.sh +0 -34
  42. data/gemfiles/Gemfile.rails-5.0 +0 -25
  43. data/gemfiles/Gemfile.rails-5.1 +0 -25
  44. data/gemfiles/Gemfile.rails-5.2 +0 -24
  45. data/gemfiles/Gemfile.rails-6.0 +0 -23
  46. data/gemfiles/Gemfile.rails-6.1 +0 -22
  47. data/gemfiles/Gemfile.rails-7.0 +0 -25
  48. data/gemfiles/Gemfile.rails-7.1 +0 -23
  49. data/gemfiles/Gemfile.rails-7.2 +0 -23
  50. data/gemfiles/Gemfile.rails-8.0 +0 -24
  51. data/package.json +0 -8
  52. data/spec/channels/notification_api_channel_shared_examples.rb +0 -59
  53. data/spec/channels/notification_api_channel_spec.rb +0 -49
  54. data/spec/channels/notification_api_with_devise_channel_spec.rb +0 -76
  55. data/spec/channels/notification_channel_shared_examples.rb +0 -59
  56. data/spec/channels/notification_channel_spec.rb +0 -48
  57. data/spec/channels/notification_with_devise_channel_spec.rb +0 -97
  58. data/spec/concerns/apis/notification_api_spec.rb +0 -1627
  59. data/spec/concerns/apis/subscription_api_spec.rb +0 -474
  60. data/spec/concerns/common_spec.rb +0 -213
  61. data/spec/concerns/models/group_spec.rb +0 -61
  62. data/spec/concerns/models/notifiable_spec.rb +0 -782
  63. data/spec/concerns/models/notifier_spec.rb +0 -71
  64. data/spec/concerns/models/subscriber_spec.rb +0 -800
  65. data/spec/concerns/models/target_spec.rb +0 -1285
  66. data/spec/concerns/renderable_spec.rb +0 -129
  67. data/spec/config_spec.rb +0 -85
  68. data/spec/controllers/common_controller_spec.rb +0 -25
  69. data/spec/controllers/controller_spec_utility.rb +0 -100
  70. data/spec/controllers/dummy_common_controller.rb +0 -5
  71. data/spec/controllers/notifications_api_controller_shared_examples.rb +0 -619
  72. data/spec/controllers/notifications_api_controller_spec.rb +0 -19
  73. data/spec/controllers/notifications_api_with_devise_controller_spec.rb +0 -60
  74. data/spec/controllers/notifications_controller_shared_examples.rb +0 -743
  75. data/spec/controllers/notifications_controller_spec.rb +0 -11
  76. data/spec/controllers/notifications_with_devise_controller_spec.rb +0 -97
  77. data/spec/controllers/subscriptions_api_controller_shared_examples.rb +0 -750
  78. data/spec/controllers/subscriptions_api_controller_spec.rb +0 -19
  79. data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +0 -60
  80. data/spec/controllers/subscriptions_controller_shared_examples.rb +0 -946
  81. data/spec/controllers/subscriptions_controller_spec.rb +0 -11
  82. data/spec/controllers/subscriptions_with_devise_controller_spec.rb +0 -97
  83. data/spec/factories/admins.rb +0 -5
  84. data/spec/factories/articles.rb +0 -5
  85. data/spec/factories/comments.rb +0 -6
  86. data/spec/factories/dummy/dummy_group.rb +0 -4
  87. data/spec/factories/dummy/dummy_notifiable.rb +0 -4
  88. data/spec/factories/dummy/dummy_notifier.rb +0 -4
  89. data/spec/factories/dummy/dummy_subscriber.rb +0 -4
  90. data/spec/factories/dummy/dummy_target.rb +0 -4
  91. data/spec/factories/notifications.rb +0 -7
  92. data/spec/factories/subscriptions.rb +0 -8
  93. data/spec/factories/users.rb +0 -11
  94. data/spec/generators/controllers_generator_spec.rb +0 -85
  95. data/spec/generators/install_generator_spec.rb +0 -43
  96. data/spec/generators/migration/migration_generator_spec.rb +0 -80
  97. data/spec/generators/models_generator_spec.rb +0 -96
  98. data/spec/generators/views_generator_spec.rb +0 -195
  99. data/spec/helpers/polymorphic_helpers_spec.rb +0 -89
  100. data/spec/helpers/view_helpers_spec.rb +0 -547
  101. data/spec/jobs/notification_resilience_job_spec.rb +0 -167
  102. data/spec/jobs/notify_all_job_spec.rb +0 -23
  103. data/spec/jobs/notify_job_spec.rb +0 -23
  104. data/spec/jobs/notify_to_job_spec.rb +0 -23
  105. data/spec/mailers/mailer_spec.rb +0 -214
  106. data/spec/mailers/notification_resilience_spec.rb +0 -263
  107. data/spec/models/dummy/dummy_group_spec.rb +0 -10
  108. data/spec/models/dummy/dummy_notifiable_spec.rb +0 -10
  109. data/spec/models/dummy/dummy_notifier_spec.rb +0 -10
  110. data/spec/models/dummy/dummy_subscriber_spec.rb +0 -8
  111. data/spec/models/dummy/dummy_target_spec.rb +0 -10
  112. data/spec/models/notification_spec.rb +0 -472
  113. data/spec/models/subscription_spec.rb +0 -215
  114. data/spec/optional_targets/action_cable_api_channel_spec.rb +0 -34
  115. data/spec/optional_targets/action_cable_channel_spec.rb +0 -41
  116. data/spec/optional_targets/amazon_sns_spec.rb +0 -47
  117. data/spec/optional_targets/base_spec.rb +0 -45
  118. data/spec/optional_targets/slack_spec.rb +0 -44
  119. data/spec/orm/dynamoid_spec.rb +0 -115
  120. data/spec/rails_app/Rakefile +0 -15
  121. data/spec/rails_app/app/assets/config/manifest.js +0 -3
  122. data/spec/rails_app/app/assets/images/.keep +0 -0
  123. data/spec/rails_app/app/assets/javascripts/application.js +0 -3
  124. data/spec/rails_app/app/assets/javascripts/cable.js +0 -12
  125. data/spec/rails_app/app/assets/stylesheets/application.css +0 -15
  126. data/spec/rails_app/app/assets/stylesheets/reset.css +0 -85
  127. data/spec/rails_app/app/assets/stylesheets/style.css +0 -244
  128. data/spec/rails_app/app/controllers/admins_controller.rb +0 -21
  129. data/spec/rails_app/app/controllers/application_controller.rb +0 -5
  130. data/spec/rails_app/app/controllers/articles_controller.rb +0 -67
  131. data/spec/rails_app/app/controllers/comments_controller.rb +0 -36
  132. data/spec/rails_app/app/controllers/concerns/.keep +0 -0
  133. data/spec/rails_app/app/controllers/spa_controller.rb +0 -7
  134. data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -2
  135. data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -2
  136. data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -2
  137. data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -2
  138. data/spec/rails_app/app/controllers/users_controller.rb +0 -26
  139. data/spec/rails_app/app/helpers/application_helper.rb +0 -2
  140. data/spec/rails_app/app/helpers/devise_helper.rb +0 -2
  141. data/spec/rails_app/app/javascript/App.vue +0 -40
  142. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +0 -82
  143. data/spec/rails_app/app/javascript/components/Top.vue +0 -98
  144. data/spec/rails_app/app/javascript/components/notifications/Index.vue +0 -200
  145. data/spec/rails_app/app/javascript/components/notifications/Notification.vue +0 -133
  146. data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +0 -122
  147. data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +0 -279
  148. data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +0 -112
  149. data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +0 -141
  150. data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +0 -226
  151. data/spec/rails_app/app/javascript/config/development.js +0 -5
  152. data/spec/rails_app/app/javascript/config/environment.js +0 -7
  153. data/spec/rails_app/app/javascript/config/production.js +0 -5
  154. data/spec/rails_app/app/javascript/config/test.js +0 -5
  155. data/spec/rails_app/app/javascript/packs/application.js +0 -18
  156. data/spec/rails_app/app/javascript/packs/spa.js +0 -14
  157. data/spec/rails_app/app/javascript/router/index.js +0 -73
  158. data/spec/rails_app/app/javascript/store/index.js +0 -37
  159. data/spec/rails_app/app/mailers/.keep +0 -0
  160. data/spec/rails_app/app/mailers/custom_notification_mailer.rb +0 -5
  161. data/spec/rails_app/app/models/admin.rb +0 -35
  162. data/spec/rails_app/app/models/article.rb +0 -54
  163. data/spec/rails_app/app/models/comment.rb +0 -81
  164. data/spec/rails_app/app/models/dummy/dummy_base.rb +0 -11
  165. data/spec/rails_app/app/models/dummy/dummy_group.rb +0 -23
  166. data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +0 -15
  167. data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +0 -27
  168. data/spec/rails_app/app/models/dummy/dummy_notifier.rb +0 -15
  169. data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +0 -14
  170. data/spec/rails_app/app/models/dummy/dummy_target.rb +0 -16
  171. data/spec/rails_app/app/models/user.rb +0 -73
  172. data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +0 -1
  173. data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +0 -146
  174. data/spec/rails_app/app/views/activity_notification/notifications/default/custom/_path_test.html.erb +0 -1
  175. data/spec/rails_app/app/views/activity_notification/notifications/default/custom/_test.html.erb +0 -1
  176. data/spec/rails_app/app/views/activity_notification/notifications/users/_custom_index.html.erb +0 -1
  177. data/spec/rails_app/app/views/activity_notification/notifications/users/custom/_test.html.erb +0 -1
  178. data/spec/rails_app/app/views/activity_notification/notifications/users/overridden/custom/_test.html.erb +0 -1
  179. data/spec/rails_app/app/views/activity_notification/optional_targets/admins/amazon_sns/comment/_default.text.erb +0 -10
  180. data/spec/rails_app/app/views/articles/_form.html.erb +0 -24
  181. data/spec/rails_app/app/views/articles/edit.html.erb +0 -8
  182. data/spec/rails_app/app/views/articles/index.html.erb +0 -113
  183. data/spec/rails_app/app/views/articles/new.html.erb +0 -7
  184. data/spec/rails_app/app/views/articles/show.html.erb +0 -49
  185. data/spec/rails_app/app/views/layouts/_header.html.erb +0 -46
  186. data/spec/rails_app/app/views/layouts/application.html.erb +0 -15
  187. data/spec/rails_app/app/views/spa/index.html.erb +0 -2
  188. data/spec/rails_app/babel.config.js +0 -72
  189. data/spec/rails_app/bin/bundle +0 -3
  190. data/spec/rails_app/bin/rails +0 -4
  191. data/spec/rails_app/bin/rake +0 -4
  192. data/spec/rails_app/bin/setup +0 -29
  193. data/spec/rails_app/bin/webpack +0 -18
  194. data/spec/rails_app/bin/webpack-dev-server +0 -18
  195. data/spec/rails_app/config/application.rb +0 -54
  196. data/spec/rails_app/config/boot.rb +0 -5
  197. data/spec/rails_app/config/cable.yml +0 -8
  198. data/spec/rails_app/config/database.yml +0 -36
  199. data/spec/rails_app/config/dynamoid.rb +0 -13
  200. data/spec/rails_app/config/environment.rb +0 -26
  201. data/spec/rails_app/config/environments/development.rb +0 -60
  202. data/spec/rails_app/config/environments/production.rb +0 -85
  203. data/spec/rails_app/config/environments/test.rb +0 -53
  204. data/spec/rails_app/config/initializers/activity_notification.rb +0 -104
  205. data/spec/rails_app/config/initializers/assets.rb +0 -11
  206. data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  207. data/spec/rails_app/config/initializers/cookies_serializer.rb +0 -3
  208. data/spec/rails_app/config/initializers/copy_it.aws.rb.template +0 -6
  209. data/spec/rails_app/config/initializers/devise.rb +0 -278
  210. data/spec/rails_app/config/initializers/devise_token_auth.rb +0 -55
  211. data/spec/rails_app/config/initializers/filter_parameter_logging.rb +0 -4
  212. data/spec/rails_app/config/initializers/inflections.rb +0 -16
  213. data/spec/rails_app/config/initializers/mime_types.rb +0 -4
  214. data/spec/rails_app/config/initializers/mysql.rb +0 -9
  215. data/spec/rails_app/config/initializers/session_store.rb +0 -3
  216. data/spec/rails_app/config/initializers/wrap_parameters.rb +0 -14
  217. data/spec/rails_app/config/initializers/zeitwerk.rb +0 -10
  218. data/spec/rails_app/config/locales/activity_notification.en.yml +0 -26
  219. data/spec/rails_app/config/locales/devise.en.yml +0 -62
  220. data/spec/rails_app/config/mongoid.yml +0 -13
  221. data/spec/rails_app/config/routes.rb +0 -50
  222. data/spec/rails_app/config/secrets.yml +0 -22
  223. data/spec/rails_app/config/webpack/development.js +0 -5
  224. data/spec/rails_app/config/webpack/environment.js +0 -7
  225. data/spec/rails_app/config/webpack/loaders/vue.js +0 -6
  226. data/spec/rails_app/config/webpack/production.js +0 -5
  227. data/spec/rails_app/config/webpack/test.js +0 -5
  228. data/spec/rails_app/config/webpacker.yml +0 -97
  229. data/spec/rails_app/config.ru +0 -4
  230. data/spec/rails_app/db/migrate/20160716000000_create_test_tables.rb +0 -42
  231. data/spec/rails_app/db/migrate/20181209000000_create_activity_notification_tables.rb +0 -33
  232. data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +0 -10
  233. data/spec/rails_app/db/schema.rb +0 -98
  234. data/spec/rails_app/db/seeds.rb +0 -95
  235. data/spec/rails_app/lib/custom_optional_targets/console_output.rb +0 -16
  236. data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +0 -14
  237. data/spec/rails_app/lib/custom_optional_targets/wrong_target.rb +0 -13
  238. data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +0 -29
  239. data/spec/rails_app/package.json +0 -23
  240. data/spec/rails_app/postcss.config.js +0 -12
  241. data/spec/rails_app/public/404.html +0 -67
  242. data/spec/rails_app/public/422.html +0 -67
  243. data/spec/rails_app/public/500.html +0 -66
  244. data/spec/rails_app/public/favicon.ico +0 -0
  245. data/spec/roles/acts_as_group_spec.rb +0 -30
  246. data/spec/roles/acts_as_notifiable_spec.rb +0 -432
  247. data/spec/roles/acts_as_notifier_spec.rb +0 -30
  248. data/spec/roles/acts_as_target_spec.rb +0 -36
  249. data/spec/spec_helper.rb +0 -56
  250. data/spec/version_spec.rb +0 -31
@@ -1,66 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/500.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>We're sorry, but something went wrong.</h1>
62
- </div>
63
- <p>If you are the application owner check the logs for more information.</p>
64
- </div>
65
- </body>
66
- </html>
File without changes
@@ -1,30 +0,0 @@
1
- describe ActivityNotification::ActsAsGroup do
2
- let(:dummy_model_class) { Dummy::DummyBase }
3
-
4
- describe "as public class methods" do
5
- describe ".acts_as_group" do
6
- it "have not included Group before calling" do
7
- expect(dummy_model_class.respond_to?(:available_as_group?)).to be_falsey
8
- end
9
-
10
- it "includes Group" do
11
- dummy_model_class.acts_as_group
12
- expect(dummy_model_class.respond_to?(:available_as_group?)).to be_truthy
13
- expect(dummy_model_class.available_as_group?).to be_truthy
14
- end
15
-
16
- context "with no options" do
17
- it "returns hash of specified options" do
18
- expect(dummy_model_class.acts_as_group).to eq({})
19
- end
20
- end
21
- end
22
-
23
- describe ".available_group_options" do
24
- it "returns list of available options in acts_as_group" do
25
- expect(dummy_model_class.available_group_options)
26
- .to eq([:printable_notification_group_name, :printable_name])
27
- end
28
- end
29
- end
30
- end
@@ -1,432 +0,0 @@
1
- describe ActivityNotification::ActsAsNotifiable do
2
- include ActiveJob::TestHelper
3
- let(:dummy_model_class) { Dummy::DummyBase }
4
- let(:dummy_notifiable_class) { Dummy::DummyNotifiable }
5
- let(:user_target) { create(:confirmed_user) }
6
- let(:dummy_target) { create(:dummy_target) }
7
-
8
- describe "as public class methods" do
9
- describe ".acts_as_notifiable" do
10
- before do
11
- dummy_notifiable_class.set_notifiable_class_defaults
12
- dummy_notifiable_class.reset_callbacks :create
13
- dummy_notifiable_class.reset_callbacks :update
14
- dummy_notifiable_class.reset_callbacks :destroy
15
- dummy_notifiable_class.reset_callbacks :commit if dummy_notifiable_class.respond_to? :after_commit
16
- @notifiable = dummy_notifiable_class.create
17
- end
18
-
19
- it "have not included Notifiable before calling" do
20
- expect(dummy_model_class.respond_to?(:available_as_notifiable?)).to be_falsey
21
- end
22
-
23
- it "includes Notifiable" do
24
- dummy_model_class.acts_as_notifiable :users
25
- expect(dummy_model_class.respond_to?(:available_as_notifiable?)).to be_truthy
26
- expect(dummy_model_class.available_as_notifiable?).to be_truthy
27
- end
28
-
29
- context "with no options" do
30
- it "returns hash of specified options" do
31
- expect(dummy_model_class.acts_as_notifiable :users).to eq({})
32
- end
33
- end
34
-
35
- context "with :tracked option" do
36
- before do
37
- user_target.notifications.delete_all
38
- expect(user_target.notifications.count).to eq(0)
39
- end
40
-
41
- it "returns hash of :tracked option" do
42
- expect(dummy_notifiable_class.acts_as_notifiable :users, tracked: true)
43
- .to eq({ tracked: [:create, :update] })
44
- end
45
-
46
- context "without option" do
47
- it "does not generate notifications when notifiable is created and updated" do
48
- dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target]
49
- notifiable = dummy_notifiable_class.create
50
- notifiable.update(created_at: notifiable.updated_at)
51
- expect(user_target.notifications.filtered_by_instance(notifiable).count).to eq(0)
52
- end
53
- end
54
-
55
- context "true as :tracked" do
56
- before do
57
- dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target], tracked: true, notifiable_path: -> { "dummy_path" }
58
- @created_notifiable = dummy_notifiable_class.create
59
- end
60
-
61
- context "creation" do
62
- it "generates notifications when notifiable is created" do
63
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
64
- end
65
-
66
- it "generated notification has notification_key_for_tracked_creation as key" do
67
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).latest.key)
68
- .to eq(@created_notifiable.notification_key_for_tracked_creation)
69
- end
70
- end
71
-
72
- context "update" do
73
- before do
74
- user_target.notifications.delete_all
75
- expect(user_target.notifications.count).to eq(0)
76
- @notifiable.update(created_at: @notifiable.updated_at)
77
- end
78
-
79
- it "generates notifications when notifiable is updated" do
80
- expect(user_target.notifications.filtered_by_instance(@notifiable).count).to eq(1)
81
- end
82
-
83
- it "generated notification has notification_key_for_tracked_update as key" do
84
- expect(user_target.notifications.filtered_by_instance(@notifiable).first.key)
85
- .to eq(@notifiable.notification_key_for_tracked_update)
86
- end
87
- end
88
-
89
- context "when the target is also configured as notifiable" do
90
- before do
91
- ActivityNotification::Notification.filtered_by_type("Dummy::DummyNotifiableTarget").delete_all
92
- Dummy::DummyNotifiableTarget.delete_all
93
- @created_target = Dummy::DummyNotifiableTarget.create
94
- @created_notifiable = Dummy::DummyNotifiableTarget.create
95
- end
96
-
97
- it "generates notifications to specified targets" do
98
- expect(@created_target.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
99
- expect(@created_notifiable.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
100
- end
101
- end
102
- end
103
-
104
- context "with :only option (creation only)" do
105
- before do
106
- dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target], tracked: { only: [:create] }, notifiable_path: -> { "dummy_path" }
107
- @created_notifiable = dummy_notifiable_class.create
108
- end
109
-
110
- context "creation" do
111
- it "generates notifications when notifiable is created" do
112
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
113
- end
114
-
115
- it "generated notification has notification_key_for_tracked_creation as key" do
116
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).latest.key)
117
- .to eq(@created_notifiable.notification_key_for_tracked_creation)
118
- end
119
- end
120
-
121
- context "update" do
122
- before do
123
- user_target.notifications.delete_all
124
- expect(user_target.notifications.count).to eq(0)
125
- @notifiable.update(created_at: @notifiable.updated_at)
126
- end
127
-
128
- it "does not generate notifications when notifiable is updated" do
129
- expect(user_target.notifications.filtered_by_instance(@notifiable).count).to eq(0)
130
- end
131
- end
132
- end
133
-
134
- context "with :except option (except update)" do
135
- before do
136
- dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target], tracked: { except: [:update] }, notifiable_path: -> { "dummy_path" }
137
- @created_notifiable = dummy_notifiable_class.create
138
- end
139
-
140
- context "creation" do
141
- it "generates notifications when notifiable is created" do
142
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
143
- end
144
-
145
- it "generated notification has notification_key_for_tracked_creation as key" do
146
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).latest.key)
147
- .to eq(@created_notifiable.notification_key_for_tracked_creation)
148
- end
149
- end
150
-
151
- context "update" do
152
- before do
153
- user_target.notifications.delete_all
154
- expect(user_target.notifications.count).to eq(0)
155
- @notifiable.update(created_at: @notifiable.updated_at)
156
- end
157
-
158
- it "does not generate notifications when notifiable is updated" do
159
- expect(user_target.notifications.filtered_by_instance(@notifiable).count).to eq(0)
160
- end
161
- end
162
- end
163
-
164
- context "with :key option" do
165
- before do
166
- dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target], tracked: { key: "test.key" }, notifiable_path: -> { "dummy_path" }
167
- @created_notifiable = dummy_notifiable_class.create
168
- end
169
-
170
- context "creation" do
171
- it "generates notifications when notifiable is created" do
172
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
173
- end
174
-
175
- it "generated notification has specified key" do
176
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).latest.key)
177
- .to eq("test.key")
178
- end
179
- end
180
-
181
- context "update" do
182
- before do
183
- user_target.notifications.delete_all
184
- expect(user_target.notifications.count).to eq(0)
185
- @notifiable.update(created_at: @notifiable.updated_at)
186
- end
187
-
188
- it "generates notifications when notifiable is updated" do
189
- expect(user_target.notifications.filtered_by_instance(@notifiable).count).to eq(1)
190
- end
191
-
192
- it "generated notification has notification_key_for_tracked_update as key" do
193
- expect(user_target.notifications.filtered_by_instance(@notifiable).first.key)
194
- .to eq("test.key")
195
- end
196
- end
197
- end
198
-
199
- context "with :notify_later option" do
200
- before do
201
- ActiveJob::Base.queue_adapter = :test
202
- dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target], tracked: { notify_later: true }, notifiable_path: -> { "dummy_path" }
203
- @created_notifiable = dummy_notifiable_class.create
204
- end
205
-
206
- context "creation" do
207
- it "generates notifications later when notifiable is created" do
208
- expect {
209
- @created_notifiable = dummy_notifiable_class.create
210
- }.to have_enqueued_job(ActivityNotification::NotifyJob)
211
- end
212
-
213
- it "creates notification records later when notifiable is created" do
214
- perform_enqueued_jobs do
215
- @created_notifiable = dummy_notifiable_class.create
216
- end
217
- expect(user_target.notifications.filtered_by_instance(@created_notifiable).count).to eq(1)
218
- end
219
- end
220
-
221
- context "update" do
222
- before do
223
- user_target.notifications.delete_all
224
- expect(user_target.notifications.count).to eq(0)
225
- @notifiable.update(created_at: @notifiable.updated_at)
226
- end
227
-
228
- it "generates notifications later when notifiable is created" do
229
- expect {
230
- @notifiable.update(created_at: @notifiable.updated_at)
231
- }.to have_enqueued_job(ActivityNotification::NotifyJob)
232
- end
233
-
234
- it "creates notification records later when notifiable is created" do
235
- perform_enqueued_jobs do
236
- @notifiable.update(created_at: @notifiable.updated_at)
237
- end
238
- expect(user_target.notifications.filtered_by_instance(@notifiable).count).to eq(1)
239
- end
240
- end
241
- end
242
- end
243
-
244
- context "with :dependent_notifications option" do
245
- before do
246
- dummy_notifiable_class.delete_all
247
- @notifiable_1, @notifiable_2, @notifiable_3 = dummy_notifiable_class.create, dummy_notifiable_class.create, dummy_notifiable_class.create
248
- @group_owner = create(:notification, target: user_target, notifiable: @notifiable_1, group: @notifiable_1)
249
- @group_member = create(:notification, target: user_target, notifiable: @notifiable_2, group: @notifiable_1, group_owner: @group_owner)
250
- create(:notification, target: user_target, notifiable: @notifiable_3, group: @notifiable_1, group_owner: @group_owner, created_at: @group_member.created_at + 10.second)
251
- @other_target_group_owner = create(:notification, target: dummy_target, notifiable: @notifiable_1, group: @notifiable_1)
252
- @other_target_group_member = create(:notification, target: dummy_target, notifiable: @notifiable_2, group: @notifiable_1, group_owner: @other_target_group_owner)
253
- create(:notification, target: dummy_target, notifiable: @notifiable_3, group: @notifiable_1, group_owner: @other_target_group_owner)
254
- expect(@group_owner.group_member_count).to eq(2)
255
- expect(@other_target_group_owner.group_member_count).to eq(2)
256
- expect(user_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(1)
257
- expect(dummy_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(1)
258
- end
259
-
260
- it "returns hash of :dependent_notifications option" do
261
- expect(dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :restrict_with_exception)
262
- .to eq({ dependent_notifications: :restrict_with_exception })
263
- end
264
-
265
- context "without option" do
266
- it "does not deletes any notifications when notifiable is deleted" do
267
- dummy_notifiable_class.acts_as_notifiable :users
268
- expect(user_target.notifications.reload.size).to eq(3)
269
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
270
- expect(user_target.notifications.reload.size).to eq(3)
271
- end
272
- end
273
-
274
- context ":delete_all" do
275
- it "deletes all notifications when notifiable is deleted" do
276
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :delete_all
277
- expect(user_target.notifications.reload.size).to eq(3)
278
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
279
- expect(user_target.notifications.reload.size).to eq(2)
280
- expect(@group_member.reload.group_owner?).to be_falsey
281
- end
282
-
283
- it "does not delete notifications of other targets when notifiable is deleted" do
284
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :delete_all
285
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
286
- expect(user_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(0)
287
- expect(dummy_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(1)
288
- end
289
- end
290
-
291
- context ":destroy" do
292
- it "destroies all notifications when notifiable is deleted" do
293
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :destroy
294
- expect(user_target.notifications.reload.size).to eq(3)
295
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
296
- expect(user_target.notifications.reload.size).to eq(2)
297
- expect(@group_member.reload.group_owner?).to be_falsey
298
- end
299
-
300
- it "does not destroy notifications of other targets when notifiable is deleted" do
301
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :destroy
302
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
303
- expect(user_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(0)
304
- expect(dummy_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(1)
305
- end
306
- end
307
-
308
- context ":restrict_with_exception" do
309
- it "can not be deleted when it has generated notifications" do
310
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :restrict_with_exception
311
- expect(user_target.notifications.reload.size).to eq(3)
312
- if ActivityNotification.config.orm == :active_record
313
- expect { @notifiable_1.destroy }.to raise_error(ActiveRecord::DeleteRestrictionError)
314
- else
315
- expect { @notifiable_1.destroy }.to raise_error(ActivityNotification::DeleteRestrictionError)
316
- end
317
- end
318
- end
319
-
320
- context ":restrict_with_error" do
321
- it "can not be deleted when it has generated notifications" do
322
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :restrict_with_error
323
- expect(user_target.notifications.reload.size).to eq(3)
324
- @notifiable_1.destroy
325
- expect(@notifiable_1.destroyed?).to be_falsey
326
- end
327
- end
328
-
329
- context ":update_group_and_delete_all" do
330
- it "deletes all notifications and update notification group when notifiable is deleted" do
331
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :update_group_and_delete_all
332
- expect(user_target.notifications.reload.size).to eq(3)
333
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
334
- expect(user_target.notifications.reload.size).to eq(2)
335
- expect(@group_member.reload.group_owner?).to be_truthy
336
- end
337
-
338
- it "does not delete notifications of other targets when notifiable is deleted" do
339
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :update_group_and_delete_all
340
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
341
- expect(user_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(0)
342
- expect(dummy_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(1)
343
- end
344
-
345
- it "does not update notification group when notifiable is deleted" do
346
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :update_group_and_delete_all
347
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
348
- expect(@group_member.reload.group_owner?).to be_truthy
349
- expect(@other_target_group_member.reload.group_owner?).to be_falsey
350
- end
351
- end
352
-
353
- context ":update_group_and_destroy" do
354
- it "destroies all notifications and update notification group when notifiable is deleted" do
355
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :update_group_and_destroy
356
- expect(user_target.notifications.reload.size).to eq(3)
357
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
358
- expect(user_target.notifications.reload.size).to eq(2)
359
- expect(@group_member.reload.group_owner?).to be_truthy
360
- end
361
-
362
- it "does not destroy notifications of other targets when notifiable is deleted" do
363
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :update_group_and_destroy
364
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
365
- expect(user_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(0)
366
- expect(dummy_target.notifications.filtered_by_instance(@notifiable_1).count).to eq(1)
367
- end
368
-
369
- it "does not update notification group when notifiable is deleted" do
370
- dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :update_group_and_destroy
371
- expect { @notifiable_1.destroy }.to change(@notifiable_1, :destroyed?).from(false).to(true)
372
- expect(@group_member.reload.group_owner?).to be_truthy
373
- expect(@other_target_group_member.reload.group_owner?).to be_falsey
374
- end
375
- end
376
- end
377
-
378
- context "with :optional_targets option" do
379
- require 'custom_optional_targets/console_output'
380
- require 'custom_optional_targets/wrong_target'
381
-
382
- it "returns hash of :optional_targets option" do
383
- result_hash = dummy_notifiable_class.acts_as_notifiable :users, optional_targets: { CustomOptionalTarget::ConsoleOutput => {} }
384
- expect(result_hash).to be_a(Hash)
385
- expect(result_hash[:optional_targets]).to be_a(Array)
386
- expect(result_hash[:optional_targets].first).to be_a(CustomOptionalTarget::ConsoleOutput)
387
- end
388
-
389
- context "without option" do
390
- it "does not configure optional_targets and notifiable#optional_targets returns empty array" do
391
- dummy_notifiable_class.acts_as_notifiable :users
392
- expect(@notifiable.optional_targets(:users)).to eq([])
393
- end
394
- end
395
-
396
- context "with hash configuration" do
397
- it "configure optional_targets and notifiable#optional_targets returns optional_target array" do
398
- dummy_notifiable_class.acts_as_notifiable :users, optional_targets: { CustomOptionalTarget::ConsoleOutput => {} }
399
- expect(@notifiable.optional_targets(:users)).to be_a(Array)
400
- expect(@notifiable.optional_targets(:users).first).to be_a(CustomOptionalTarget::ConsoleOutput)
401
- end
402
- end
403
-
404
- context "with hash configuration but specified class does not extends ActivityNotification::OptionalTarget::Base" do
405
- it "raise TypeError" do
406
- expect { dummy_notifiable_class.acts_as_notifiable :users, optional_targets: { CustomOptionalTarget::WrongTarget => {} } }
407
- .to raise_error(TypeError, /.+ is not a kind of ActivityNotification::OptionalTarget::Base/)
408
- end
409
- end
410
-
411
- context "with lambda function configuration" do
412
- it "configure optional_targets and notifiable#optional_targets returns optional_target array" do
413
- module AdditionalMethods
414
- require 'custom_optional_targets/console_output'
415
- end
416
- dummy_notifiable_class.extend(AdditionalMethods)
417
- dummy_notifiable_class.acts_as_notifiable :users, optional_targets: ->(notifiable, key){ key == 'dummy_key' ? [CustomOptionalTarget::ConsoleOutput.new] : [] }
418
- expect(@notifiable.optional_targets(:users)).to eq([])
419
- expect(@notifiable.optional_targets(:users, 'dummy_key').first).to be_a(CustomOptionalTarget::ConsoleOutput)
420
- end
421
- end
422
- end
423
- end
424
-
425
- describe ".available_notifiable_options" do
426
- it "returns list of available options in acts_as_notifiable" do
427
- expect(dummy_model_class.available_notifiable_options)
428
- .to eq([:targets, :group, :group_expiry_delay, :notifier, :parameters, :email_allowed, :action_cable_allowed, :action_cable_api_allowed, :notifiable_path, :printable_notifiable_name, :printable_name, :dependent_notifications, :optional_targets])
429
- end
430
- end
431
- end
432
- end
@@ -1,30 +0,0 @@
1
- describe ActivityNotification::ActsAsNotifier do
2
- let(:dummy_model_class) { Dummy::DummyBase }
3
-
4
- describe "as public class methods" do
5
- describe ".acts_as_notifier" do
6
- it "have not included Notifier before calling" do
7
- expect(dummy_model_class.respond_to?(:available_as_notifier?)).to be_falsey
8
- end
9
-
10
- it "includes Notifier" do
11
- dummy_model_class.acts_as_notifier
12
- expect(dummy_model_class.respond_to?(:available_as_notifier?)).to be_truthy
13
- expect(dummy_model_class.available_as_notifier?).to be_truthy
14
- end
15
-
16
- context "with no options" do
17
- it "returns hash of specified options" do
18
- expect(dummy_model_class.acts_as_notifier).to eq({})
19
- end
20
- end
21
- end
22
-
23
- describe ".available_notifier_options" do
24
- it "returns list of available options in acts_as_group" do
25
- expect(dummy_model_class.available_notifier_options)
26
- .to eq([:printable_notifier_name, :printable_name])
27
- end
28
- end
29
- end
30
- end
@@ -1,36 +0,0 @@
1
- describe ActivityNotification::ActsAsTarget do
2
- let(:dummy_model_class) { Dummy::DummyBase }
3
-
4
- describe "as public class methods" do
5
- describe ".acts_as_target" do
6
- it "have not included Target before calling" do
7
- expect(dummy_model_class.respond_to?(:available_as_target?)).to be_falsey
8
- end
9
-
10
- it "includes Target" do
11
- dummy_model_class.acts_as_target
12
- expect(dummy_model_class.respond_to?(:available_as_target?)).to be_truthy
13
- expect(dummy_model_class.available_as_target?).to be_truthy
14
- end
15
-
16
- context "with no options" do
17
- it "returns hash of specified options" do
18
- expect(dummy_model_class.acts_as_target).to eq({})
19
- end
20
- end
21
- end
22
-
23
- describe ".acts_as_notification_target" do
24
- it "is an alias of acts_as_target" do
25
- expect(dummy_model_class.respond_to?(:acts_as_notification_target)).to be_truthy
26
- end
27
- end
28
-
29
- describe ".available_target_options" do
30
- it "returns list of available options in acts_as_target" do
31
- expect(dummy_model_class.available_target_options)
32
- .to eq([:email, :email_allowed, :batch_email_allowed, :subscription_allowed, :action_cable_enabled, :action_cable_with_devise, :devise_resource, :printable_notification_target_name, :printable_name])
33
- end
34
- end
35
- end
36
- end
data/spec/spec_helper.rb DELETED
@@ -1,56 +0,0 @@
1
- ENV["RAILS_ENV"] ||= "test"
2
- Warning[:deprecated] = true if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.2")
3
-
4
- require 'bundler/setup'
5
- Bundler.setup
6
-
7
- require 'simplecov'
8
- require 'coveralls'
9
- require 'rails'
10
- Coveralls.wear!
11
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [
12
- SimpleCov::Formatter::HTMLFormatter,
13
- Coveralls::SimpleCov::Formatter
14
- ]
15
- SimpleCov.start('rails') do
16
- add_filter '/spec/'
17
- add_filter '/lib/generators/templates/'
18
- add_filter '/lib/activity_notification/version'
19
- if ENV['AN_ORM'] == 'mongoid'
20
- add_filter '/lib/activity_notification/orm/active_record'
21
- add_filter '/lib/activity_notification/orm/dynamoid'
22
- elsif ENV['AN_ORM'] == 'dynamoid'
23
- add_filter '/lib/activity_notification/orm/active_record'
24
- add_filter '/lib/activity_notification/orm/mongoid'
25
- else
26
- add_filter '/lib/activity_notification/orm/mongoid'
27
- add_filter '/lib/activity_notification/orm/dynamoid'
28
- end
29
- end
30
-
31
- # Dummy application
32
- require 'rails_app/config/environment'
33
-
34
- require 'rspec/rails'
35
- require 'ammeter/init'
36
- require "action_cable/testing/rspec" if Rails::VERSION::MAJOR == 5
37
- require 'factory_bot_rails'
38
- require 'activity_notification'
39
-
40
- Dir[Rails.root.join("../../spec/support/**/*.rb")].each { |file| require file }
41
-
42
- def clean_database
43
- [ActivityNotification::Notification, ActivityNotification::Subscription, Comment, Article, Admin, User].each do |model_class|
44
- model_class.delete_all
45
- end
46
- end
47
-
48
- RSpec.configure do |config|
49
- config.expect_with :minitest, :rspec
50
- config.include FactoryBot::Syntax::Methods
51
- config.before(:each) do
52
- FactoryBot.reload
53
- clean_database
54
- end
55
- config.include Devise::Test::ControllerHelpers, type: :controller
56
- end