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,167 +0,0 @@
1
- describe "Notification resilience in background jobs" do
2
- include ActiveJob::TestHelper
3
-
4
- let(:user) { create(:user) }
5
- let(:article) { create(:article, user: user) }
6
- let(:comment) { create(:comment, article: article, user: create(:user)) }
7
-
8
- before do
9
- ActivityNotification::Mailer.deliveries.clear
10
- clear_enqueued_jobs
11
- clear_performed_jobs
12
- @original_email_enabled = ActivityNotification.config.email_enabled
13
- ActivityNotification.config.email_enabled = true
14
- end
15
-
16
- after do
17
- ActivityNotification.config.email_enabled = @original_email_enabled
18
- end
19
-
20
- describe "Job resilience" do
21
- it "handles missing notifications gracefully in background jobs" do
22
- # Create a notification and destroy it to simulate race condition
23
- notification = ActivityNotification::Notification.create!(
24
- target: user,
25
- notifiable: comment,
26
- key: 'comment.create'
27
- )
28
-
29
- notification_id = notification.id
30
- notification.destroy
31
-
32
- # Expect warning to be logged
33
- expect(Rails.logger).to receive(:warn).with(/ActivityNotification: Notification.*not found for email delivery/)
34
-
35
- # Execute job - should not raise error
36
- expect {
37
- perform_enqueued_jobs do
38
- # Simulate job trying to send email for destroyed notification
39
- begin
40
- destroyed_notification = ActivityNotification::Notification.find(notification_id)
41
- destroyed_notification.send_notification_email
42
- rescue => e
43
- # Handle any ORM-specific "record not found" exception
44
- if ActivityNotification::NotificationResilience.record_not_found_exception?(e)
45
- Rails.logger.warn("ActivityNotification: Notification with id #{notification_id} not found for email delivery (#{ActivityNotification.config.orm}/#{e.class.name}), likely destroyed before job execution")
46
- else
47
- raise e
48
- end
49
- end
50
- end
51
- }.not_to raise_error
52
-
53
- expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
54
- end
55
- end
56
-
57
- describe "Mailer job resilience" do
58
- context "when notification is destroyed before mailer job executes" do
59
- it "handles the scenario gracefully" do
60
- # Create a notification
61
- notification = ActivityNotification::Notification.create!(
62
- target: user,
63
- notifiable: comment,
64
- key: 'comment.create'
65
- )
66
-
67
- notification_id = notification.id
68
-
69
- # Expect warning to be logged when notification is not found
70
- expect(Rails.logger).to receive(:warn).with(/ActivityNotification: Notification.*not found for email delivery/)
71
-
72
- # Destroy the notification
73
- notification.destroy
74
-
75
- # Try to send email using the mailer directly - this should use our resilient implementation
76
- expect {
77
- perform_enqueued_jobs do
78
- # Create a mock notification that will raise RecordNotFound when accessed
79
- mock_notification = double("notification")
80
- allow(mock_notification).to receive(:id).and_return(notification_id)
81
- allow(mock_notification).to receive(:target).and_raise(ActiveRecord::RecordNotFound)
82
-
83
- ActivityNotification::Mailer.send_notification_email(mock_notification).deliver_now
84
- end
85
- }.not_to raise_error
86
-
87
- # No email should be sent
88
- expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
89
- end
90
- end
91
-
92
- context "when notification exists during mailer job execution" do
93
- it "sends email normally" do
94
- # Enable email for this test
95
- allow_any_instance_of(User).to receive(:notification_email_allowed?).and_return(true)
96
- allow_any_instance_of(Comment).to receive(:notification_email_allowed?).and_return(true)
97
- allow_any_instance_of(ActivityNotification::Notification).to receive(:email_subscribed?).and_return(true)
98
-
99
- # Create a notification
100
- notification = ActivityNotification::Notification.create!(
101
- target: user,
102
- notifiable: comment,
103
- key: 'comment.create'
104
- )
105
-
106
- # Don't expect any warnings
107
- expect(Rails.logger).not_to receive(:warn)
108
-
109
- # Send email - this should work normally
110
- expect {
111
- perform_enqueued_jobs do
112
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
113
- end
114
- }.not_to raise_error
115
-
116
- # Email should be sent
117
- expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
118
- end
119
- end
120
- end
121
-
122
- describe "Multiple job resilience" do
123
- it "continues processing other jobs even when some notifications are missing" do
124
- # Enable email for this test
125
- allow_any_instance_of(User).to receive(:notification_email_allowed?).and_return(true)
126
- allow_any_instance_of(Comment).to receive(:notification_email_allowed?).and_return(true)
127
- allow_any_instance_of(ActivityNotification::Notification).to receive(:email_subscribed?).and_return(true)
128
-
129
- # Create two notifications
130
- notification1 = ActivityNotification::Notification.create!(
131
- target: user,
132
- notifiable: comment,
133
- key: 'comment.create'
134
- )
135
-
136
- notification2 = ActivityNotification::Notification.create!(
137
- target: user,
138
- notifiable: create(:comment, article: article, user: create(:user)),
139
- key: 'comment.create'
140
- )
141
-
142
- # Destroy the first notification
143
- notification1_id = notification1.id
144
- notification1.destroy
145
-
146
- # Expect one warning for the destroyed notification
147
- expect(Rails.logger).to receive(:warn).with(/ActivityNotification: Notification.*not found for email delivery/).once
148
-
149
- # Process both jobs
150
- expect {
151
- perform_enqueued_jobs do
152
- # First job - should handle missing notification gracefully
153
- mock_notification1 = double("notification")
154
- allow(mock_notification1).to receive(:id).and_return(notification1_id)
155
- allow(mock_notification1).to receive(:target).and_raise(ActiveRecord::RecordNotFound)
156
- ActivityNotification::Mailer.send_notification_email(mock_notification1).deliver_now
157
-
158
- # Second job - should work normally
159
- ActivityNotification::Mailer.send_notification_email(notification2).deliver_now
160
- end
161
- }.not_to raise_error
162
-
163
- # Only one email should be sent (for notification2)
164
- expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
165
- end
166
- end
167
- end
@@ -1,23 +0,0 @@
1
- describe ActivityNotification::NotifyAllJob, type: :job do
2
- before do
3
- ActiveJob::Base.queue_adapter = :test
4
- ActiveJob::Base.queue_adapter.enqueued_jobs.clear
5
- @author_user = create(:confirmed_user)
6
- @user = create(:confirmed_user)
7
- @article = create(:article, user: @author_user)
8
- @comment = create(:comment, article: @article, user: @user)
9
- end
10
-
11
- describe "#perform_later" do
12
- it "generates notifications" do
13
- expect {
14
- ActivityNotification::NotifyAllJob.perform_later([@author_user, @user], @comment)
15
- }.to have_enqueued_job
16
- end
17
-
18
- it "generates notifications once" do
19
- ActivityNotification::NotifyAllJob.perform_later([@author_user, @user], @comment)
20
- expect(ActivityNotification::NotifyAllJob).to have_been_enqueued.exactly(:once)
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- describe ActivityNotification::NotifyJob, type: :job do
2
- before do
3
- ActiveJob::Base.queue_adapter = :test
4
- ActiveJob::Base.queue_adapter.enqueued_jobs.clear
5
- @author_user = create(:confirmed_user)
6
- @user = create(:confirmed_user)
7
- @article = create(:article, user: @author_user)
8
- @comment = create(:comment, article: @article, user: @user)
9
- end
10
-
11
- describe "#perform_later" do
12
- it "generates notifications" do
13
- expect {
14
- ActivityNotification::NotifyJob.perform_later('users', @comment)
15
- }.to have_enqueued_job
16
- end
17
-
18
- it "generates notifications once" do
19
- ActivityNotification::NotifyJob.perform_later('users', @comment)
20
- expect(ActivityNotification::NotifyJob).to have_been_enqueued.exactly(:once)
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- describe ActivityNotification::NotifyToJob, type: :job do
2
- before do
3
- ActiveJob::Base.queue_adapter = :test
4
- ActiveJob::Base.queue_adapter.enqueued_jobs.clear
5
- @author_user = create(:confirmed_user)
6
- @user = create(:confirmed_user)
7
- @article = create(:article, user: @author_user)
8
- @comment = create(:comment, article: @article, user: @user)
9
- end
10
-
11
- describe "#perform_later" do
12
- it "generates notification" do
13
- expect {
14
- ActivityNotification::NotifyToJob.perform_later(@user, @comment)
15
- }.to have_enqueued_job
16
- end
17
-
18
- it "generates notification once" do
19
- ActivityNotification::NotifyToJob.perform_later(@user, @comment)
20
- expect(ActivityNotification::NotifyToJob).to have_been_enqueued.exactly(:once)
21
- end
22
- end
23
- end
@@ -1,214 +0,0 @@
1
- describe ActivityNotification::Mailer do
2
- include ActiveJob::TestHelper
3
- let(:notification) { create(:notification) }
4
- let(:test_target) { notification.target }
5
- let(:notifications) { [create(:notification, target: test_target), create(:notification, target: test_target)] }
6
- let(:batch_key) { 'test_batch_key' }
7
-
8
- before do
9
- ActivityNotification::Mailer.deliveries.clear
10
- expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
11
- end
12
-
13
- describe ".send_notification_email" do
14
- context "with deliver_now" do
15
- context "as default" do
16
- before do
17
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
18
- end
19
-
20
- it "sends notification email now" do
21
- expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
22
- end
23
-
24
- it "sends to target email" do
25
- expect(ActivityNotification::Mailer.deliveries.last.to[0]).to eq(notification.target.email)
26
- end
27
-
28
- it "sends from configured email in initializer" do
29
- expect(ActivityNotification::Mailer.deliveries.last.from[0])
30
- .to eq("please-change-me-at-config-initializers-activity_notification@example.com")
31
- end
32
-
33
- it "sends with default notification subject" do
34
- expect(ActivityNotification::Mailer.deliveries.last.subject)
35
- .to eq("Notification of article")
36
- end
37
- end
38
-
39
- context "with default from parameter in mailer" do
40
- it "sends from configured email as default parameter" do
41
- class CustomMailer < ActivityNotification::Mailer
42
- default from: "test01@example.com"
43
- end
44
- CustomMailer.send_notification_email(notification).deliver_now
45
- expect(CustomMailer.deliveries.last.from[0])
46
- .to eq("test01@example.com")
47
- end
48
- end
49
-
50
- context "with email value as ActivityNotification.config.mailer_sender" do
51
- it "sends from configured email as ActivityNotification.config.mailer_sender" do
52
- ActivityNotification.config.mailer_sender = "test02@example.com"
53
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
54
- expect(ActivityNotification::Mailer.deliveries.last.from[0])
55
- .to eq("test02@example.com")
56
- end
57
- end
58
-
59
- context "with email proc as ActivityNotification.config.mailer_sender" do
60
- it "sends from configured email as ActivityNotification.config.mailer_sender" do
61
- ActivityNotification.config.mailer_sender =
62
- ->(key){ key == notification.key ? "test03@example.com" : "test04@example.com" }
63
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
64
- expect(ActivityNotification::Mailer.deliveries.last.from[0])
65
- .to eq("test03@example.com")
66
- end
67
-
68
- it "sends from configured email as ActivityNotification.config.mailer_sender" do
69
- ActivityNotification.config.mailer_sender =
70
- ->(key){ key == 'hogehoge' ? "test03@example.com" : "test04@example.com" }
71
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
72
- expect(ActivityNotification::Mailer.deliveries.last.from[0])
73
- .to eq("test04@example.com")
74
- end
75
- end
76
-
77
- context "with defined overriding_notification_email_key in notifiable model" do
78
- it "sends with configured notification subject in locale file as updated key" do
79
- module AdditionalMethods
80
- def overriding_notification_email_key(target, key)
81
- 'comment.reply'
82
- end
83
- end
84
- notification.notifiable.extend(AdditionalMethods)
85
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
86
- expect(ActivityNotification::Mailer.deliveries.last.subject)
87
- .to eq("New comment on your article")
88
- end
89
- end
90
-
91
- context "with defined overriding_notification_email_subject in notifiable model" do
92
- it "sends with updated subject" do
93
- module AdditionalMethods
94
- def overriding_notification_email_subject(target, key)
95
- 'Hi, You have got comment'
96
- end
97
- end
98
- notification.notifiable.extend(AdditionalMethods)
99
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
100
- expect(ActivityNotification::Mailer.deliveries.last.subject)
101
- .to eq("Hi, You have got comment")
102
- end
103
- end
104
-
105
- context "with defined overriding_notification_email_from in notifiable model" do
106
- it "sends with updated from" do
107
- module AdditionalMethods
108
- def overriding_notification_email_from(target, key)
109
- 'test05@example.com'
110
- end
111
- end
112
- notification.notifiable.extend(AdditionalMethods)
113
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
114
- expect(ActivityNotification::Mailer.deliveries.last.from.first)
115
- .to eq('test05@example.com')
116
- end
117
- end
118
-
119
- context "with defined overriding_notification_email_reply_to in notifiable model" do
120
- it "sends with updated reply_to" do
121
- module AdditionalMethods
122
- def overriding_notification_email_reply_to(target, key)
123
- 'test06@example.com'
124
- end
125
- end
126
- notification.notifiable.extend(AdditionalMethods)
127
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
128
- expect(ActivityNotification::Mailer.deliveries.last.reply_to.first)
129
- .to eq('test06@example.com')
130
- end
131
- end
132
-
133
- context "with defined overriding_notification_email_message_id in notifiable model" do
134
- it "sends with specific message id" do
135
- module AdditionalMethods
136
- def overriding_notification_email_message_id(target, key)
137
- "https://www.example.com/test@example.com/"
138
- end
139
- end
140
- notification.notifiable.extend(AdditionalMethods)
141
- ActivityNotification::Mailer.send_notification_email(notification).deliver_now
142
- expect(ActivityNotification::Mailer.deliveries.last.message_id)
143
- .to eq("https://www.example.com/test@example.com/")
144
- end
145
- end
146
- context "when fallback option is :none and the template is missing" do
147
- it "raise ActionView::MissingTemplate" do
148
- expect { ActivityNotification::Mailer.send_notification_email(notification, fallback: :none).deliver_now }
149
- .to raise_error(ActionView::MissingTemplate)
150
- end
151
- end
152
- end
153
-
154
- context "with deliver_later" do
155
- it "sends notification email later" do
156
- expect {
157
- perform_enqueued_jobs do
158
- ActivityNotification::Mailer.send_notification_email(notification).deliver_later
159
- end
160
- }.to change { ActivityNotification::Mailer.deliveries.size }.by(1)
161
- expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
162
- end
163
-
164
- it "sends notification email with active job queue" do
165
- expect {
166
- ActivityNotification::Mailer.send_notification_email(notification).deliver_later
167
- }.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
168
- end
169
- end
170
- end
171
-
172
- describe ".send_batch_notification_email" do
173
- context "with deliver_now" do
174
- context "as default" do
175
- before do
176
- ActivityNotification::Mailer.send_batch_notification_email(test_target, notifications, batch_key).deliver_now
177
- end
178
-
179
- it "sends batch notification email now" do
180
- expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
181
- end
182
-
183
- it "sends to target email" do
184
- expect(ActivityNotification::Mailer.deliveries.last.to[0]).to eq(test_target.email)
185
- end
186
-
187
- end
188
-
189
- context "when fallback option is :none and the template is missing" do
190
- it "raise ActionView::MissingTemplate" do
191
- expect { ActivityNotification::Mailer.send_batch_notification_email(test_target, notifications, batch_key, fallback: :none).deliver_now }
192
- .to raise_error(ActionView::MissingTemplate)
193
- end
194
- end
195
- end
196
-
197
- context "with deliver_later" do
198
- it "sends notification email later" do
199
- expect {
200
- perform_enqueued_jobs do
201
- ActivityNotification::Mailer.send_batch_notification_email(test_target, notifications, batch_key).deliver_later
202
- end
203
- }.to change { ActivityNotification::Mailer.deliveries.size }.by(1)
204
- expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
205
- end
206
-
207
- it "sends notification email with active job queue" do
208
- expect {
209
- ActivityNotification::Mailer.send_batch_notification_email(test_target, notifications, batch_key).deliver_later
210
- }.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
211
- end
212
- end
213
- end
214
- end