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,619 +0,0 @@
1
- require_relative 'controller_spec_utility'
2
-
3
- shared_examples_for :notifications_api_controller do
4
- include ActivityNotification::ControllerSpec::RequestUtility
5
- include ActivityNotification::ControllerSpec::ApiResponseUtility
6
-
7
- let(:target_params) { { target_type: target_type }.merge(extra_params || {}) }
8
-
9
- describe "GET #index" do
10
- context "with target_type and target_id parameters" do
11
- before do
12
- @notification = create(:notification, target: test_target)
13
- get_with_compatibility :index, target_params.merge({ target_id: test_target, typed_target_param => 'dummy' }), valid_session
14
- end
15
-
16
- it "returns 200 as http status code" do
17
- expect(response.status).to eq(200)
18
- end
19
-
20
- it "returns JSON response" do
21
- expect(response_json["count"]).to eq(1)
22
- assert_json_with_object_array(response_json["notifications"], [@notification])
23
- end
24
- end
25
-
26
- context "with target_type and (typed_target)_id parameters" do
27
- before do
28
- @notification = create(:notification, target: test_target)
29
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target }), valid_session
30
- end
31
-
32
- it "returns 200 as http status code" do
33
- expect(response.status).to eq(200)
34
- end
35
- end
36
-
37
- context "without target_type parameters" do
38
- before do
39
- @notification = create(:notification, target: test_target)
40
- get_with_compatibility :index, { typed_target_param => test_target }, valid_session
41
- end
42
-
43
- it "returns 400 as http status code" do
44
- expect(response.status).to eq(400)
45
- end
46
-
47
- it "returns error JSON response" do
48
- assert_error_response(400)
49
- end
50
- end
51
-
52
- context "with not found (typed_target)_id parameter" do
53
- before do
54
- @notification = create(:notification, target: test_target)
55
- get_with_compatibility :index, target_params.merge({ typed_target_param => 0 }), valid_session
56
- end
57
-
58
- it "returns 404 as http status code" do
59
- expect(response.status).to eq(404)
60
- end
61
-
62
- it "returns error JSON response" do
63
- assert_error_response(404)
64
- end
65
- end
66
-
67
- context "with filter parameter" do
68
- context "with unopened as filter" do
69
- before do
70
- @notification = create(:notification, target: test_target)
71
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, filter: 'unopened' }), valid_session
72
- end
73
-
74
- it "returns unopened notification index as JSON" do
75
- assert_json_with_object_array(response_json["notifications"], [@notification])
76
- end
77
- end
78
-
79
- context "with opened as filter" do
80
- before do
81
- @notification = create(:notification, target: test_target)
82
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, filter: 'opened' }), valid_session
83
- end
84
-
85
- it "returns unopened notification index as JSON" do
86
- assert_json_with_object_array(response_json["notifications"], [])
87
- end
88
- end
89
- end
90
-
91
- context "with limit parameter" do
92
- before do
93
- create(:notification, target: test_target)
94
- create(:notification, target: test_target)
95
- end
96
- context "with 2 as limit" do
97
- before do
98
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, limit: 2 }), valid_session
99
- end
100
-
101
- it "returns notification index of size 2 as JSON" do
102
- assert_json_with_array_size(response_json["notifications"], 2)
103
- end
104
- end
105
-
106
- context "with 1 as limit" do
107
- before do
108
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, limit: 1 }), valid_session
109
- end
110
-
111
- it "returns notification index of size 1 as JSON" do
112
- assert_json_with_array_size(response_json["notifications"], 1)
113
- end
114
- end
115
- end
116
-
117
- context "with reverse parameter" do
118
- before do
119
- @notifiable = create(:article)
120
- @group = create(:article)
121
- @key = 'test.key.1'
122
- notification = create(:notification, target: test_target, notifiable: @notifiable)
123
- create(:notification, target: test_target, notifiable: create(:comment), group: @group, created_at: notification.created_at + 10.second)
124
- create(:notification, target: test_target, notifiable: create(:article), key: @key, created_at: notification.created_at + 20.second).open!
125
- @notification1 = test_target.notification_index[0]
126
- @notification2 = test_target.notification_index[1]
127
- @notification3 = test_target.notification_index[2]
128
- end
129
-
130
- context "as default" do
131
- before do
132
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target }), valid_session
133
- end
134
-
135
- it "returns the latest order" do
136
- assert_json_with_object_array(response_json["notifications"], [@notification1, @notification2, @notification3])
137
- end
138
- end
139
-
140
- context "with true as reverse" do
141
- before do
142
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, reverse: true }), valid_session
143
- end
144
-
145
- it "returns the earliest order" do
146
- assert_json_with_object_array(response_json["notifications"], [@notification2, @notification1, @notification3])
147
- end
148
- end
149
- end
150
-
151
- context "with options filter parameters" do
152
- before do
153
- @notifiable = create(:article)
154
- @group = create(:article)
155
- @key = 'test.key.1'
156
- @notification2 = create(:notification, target: test_target, notifiable: @notifiable)
157
- @notification1 = create(:notification, target: test_target, notifiable: create(:comment), group: @group, created_at: @notification2.created_at + 10.second)
158
- @notification3 = create(:notification, target: test_target, notifiable: create(:article), key: @key, created_at: @notification2.created_at + 20.second)
159
- @notification3.open!
160
- end
161
-
162
- context 'with filtered_by_type parameter' do
163
- it "returns filtered notifications only" do
164
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, filtered_by_type: 'Article' }), valid_session
165
- assert_json_with_object_array(response_json["notifications"], [@notification2, @notification3])
166
- end
167
- end
168
-
169
- context 'with filtered_by_group_type and filtered_by_group_id parameters' do
170
- it "returns filtered notifications only" do
171
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, filtered_by_group_type: 'Article', filtered_by_group_id: @group.id.to_s }), valid_session
172
- assert_json_with_object_array(response_json["notifications"], [@notification1])
173
- end
174
- end
175
-
176
- context 'with filtered_by_key parameter' do
177
- it "returns filtered notifications only" do
178
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, filtered_by_key: @key }), valid_session
179
- assert_json_with_object_array(response_json["notifications"], [@notification3])
180
- end
181
- end
182
-
183
- context 'with later_than parameter' do
184
- it "returns filtered notifications only" do
185
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, later_than: (@notification1.created_at.in_time_zone + 0.001).iso8601(3) }), valid_session
186
- assert_json_with_object_array(response_json["notifications"], [@notification3])
187
- end
188
- end
189
-
190
- context 'with earlier_than parameter' do
191
- it "returns filtered notifications only" do
192
- get_with_compatibility :index, target_params.merge({ typed_target_param => test_target, earlier_than: @notification1.created_at.iso8601(3) }), valid_session
193
- assert_json_with_object_array(response_json["notifications"], [@notification2])
194
- end
195
- end
196
- end
197
- end
198
-
199
- describe "POST #open_all" do
200
- context "http POST request" do
201
- before do
202
- @notification = create(:notification, target: test_target)
203
- expect(@notification.opened?).to be_falsey
204
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target }), valid_session
205
- end
206
-
207
- it "returns 200 as http status code" do
208
- expect(response.status).to eq(200)
209
- end
210
-
211
- it "opens all notifications of the target" do
212
- expect(@notification.reload.opened?).to be_truthy
213
- end
214
-
215
- it "returns JSON response" do
216
- expect(response_json["count"]).to eq(1)
217
- assert_json_with_object_array(response_json["notifications"], [@notification])
218
- end
219
- end
220
-
221
- context "with filter request parameters" do
222
- before do
223
- @target_1, @notifiable_1, @group_1, @key_1 = create(:confirmed_user), create(:article), nil, "key.1"
224
- @target_2, @notifiable_2, @group_2, @key_2 = create(:confirmed_user), create(:comment), @notifiable_1, "key.2"
225
- @notification_1 = create(:notification, target: test_target, notifiable: @notifiable_1, group: @group_1, key: @key_1)
226
- @notification_2 = create(:notification, target: test_target, notifiable: @notifiable_2, group: @group_2, key: @key_2, created_at: @notification_1.created_at + 10.second)
227
- expect(@notification_1.opened?).to be_falsey
228
- expect(@notification_2.opened?).to be_falsey
229
- end
230
-
231
- context "with filtered_by_type request parameters" do
232
- it "opens filtered notifications only" do
233
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target, 'filtered_by_type' => @notifiable_2.to_class_name }), valid_session
234
- expect(@notification_1.reload.opened?).to be_falsey
235
- expect(@notification_2.reload.opened?).to be_truthy
236
- end
237
- end
238
-
239
- context 'with filtered_by_group_type and :filtered_by_group_id request parameters' do
240
- it "opens filtered notifications only" do
241
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target, 'filtered_by_group_type' => 'Article', 'filtered_by_group_id' => @group_2.id.to_s }), valid_session
242
- expect(@notification_1.reload.opened?).to be_falsey
243
- expect(@notification_2.reload.opened?).to be_truthy
244
- end
245
- end
246
-
247
- context 'with filtered_by_key request parameters' do
248
- it "opens filtered notifications only" do
249
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target, 'filtered_by_key' => 'key.2' }), valid_session
250
- expect(@notification_1.reload.opened?).to be_falsey
251
- expect(@notification_2.reload.opened?).to be_truthy
252
- end
253
- end
254
-
255
- context 'with later_than parameter' do
256
- it "opens filtered notifications only" do
257
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target, later_than: (@notification_1.created_at.in_time_zone + 0.001).iso8601(3) }), valid_session
258
- expect(@notification_1.reload.opened?).to be_falsey
259
- expect(@notification_2.reload.opened?).to be_truthy
260
- end
261
- end
262
-
263
- context 'with earlier_than parameter' do
264
- it "opens filtered notifications only" do
265
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target, earlier_than: @notification_2.created_at.iso8601(3) }), valid_session
266
- expect(@notification_1.reload.opened?).to be_truthy
267
- expect(@notification_2.reload.opened?).to be_falsey
268
- end
269
- end
270
-
271
- context "with no filter request parameters" do
272
- it "opens all notifications of the target" do
273
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target}), valid_session
274
- expect(@notification_1.reload.opened?).to be_truthy
275
- expect(@notification_2.reload.opened?).to be_truthy
276
- end
277
- end
278
-
279
- context 'with ids parameter' do
280
- it "opens only specified notifications" do
281
- post_with_compatibility :open_all, target_params.merge({ typed_target_param => test_target, ids: [@notification_1.id] }), valid_session
282
- expect(@notification_1.reload.opened?).to be_truthy
283
- expect(@notification_2.reload.opened?).to be_falsey
284
- end
285
-
286
- it "applies other filter options when ids are specified" do
287
- post_with_compatibility :open_all, target_params.merge({
288
- typed_target_param => test_target,
289
- ids: [@notification_1.id],
290
- filtered_by_key: 'non_existent_key'
291
- }), valid_session
292
- expect(@notification_1.reload.opened?).to be_falsey
293
- expect(@notification_2.reload.opened?).to be_falsey
294
- end
295
- end
296
- end
297
- end
298
-
299
- describe "POST #destroy_all" do
300
- context "http POST request" do
301
- before do
302
- @notification = create(:notification, target: test_target)
303
- expect(test_target.notifications.count).to eq(1)
304
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target }), valid_session
305
- end
306
-
307
- it "returns 200 as http status code" do
308
- expect(response.status).to eq(200)
309
- end
310
-
311
- it "destroys all notifications of the target" do
312
- expect(test_target.notifications.count).to eq(0)
313
- end
314
-
315
- it "returns JSON response" do
316
- expect(response_json["count"]).to eq(1)
317
- assert_json_with_object_array(response_json["notifications"], [@notification])
318
- end
319
- end
320
-
321
- context "with filter request parameters" do
322
- before do
323
- @target_1, @notifiable_1, @group_1, @key_1 = create(:confirmed_user), create(:article), nil, "key.1"
324
- @target_2, @notifiable_2, @group_2, @key_2 = create(:confirmed_user), create(:comment), @notifiable_1, "key.2"
325
- @notification_1 = create(:notification, target: test_target, notifiable: @notifiable_1, group: @group_1, key: @key_1)
326
- @notification_2 = create(:notification, target: test_target, notifiable: @notifiable_2, group: @group_2, key: @key_2, created_at: @notification_1.created_at + 10.second)
327
- expect(test_target.notifications.count).to eq(2)
328
- end
329
-
330
- context "with filtered_by_type request parameters" do
331
- it "destroys filtered notifications only" do
332
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target, 'filtered_by_type' => @notifiable_2.to_class_name }), valid_session
333
- expect(test_target.notifications.count).to eq(1)
334
- expect(test_target.notifications.first).to eq(@notification_1)
335
- end
336
- end
337
-
338
- context 'with filtered_by_group_type and :filtered_by_group_id request parameters' do
339
- it "destroys filtered notifications only" do
340
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target, 'filtered_by_group_type' => 'Article', 'filtered_by_group_id' => @group_2.id.to_s }), valid_session
341
- expect(test_target.notifications.count).to eq(1)
342
- expect(test_target.notifications.first).to eq(@notification_1)
343
- end
344
- end
345
-
346
- context 'with filtered_by_key request parameters' do
347
- it "destroys filtered notifications only" do
348
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target, 'filtered_by_key' => 'key.2' }), valid_session
349
- expect(test_target.notifications.count).to eq(1)
350
- expect(test_target.notifications.first).to eq(@notification_1)
351
- end
352
- end
353
-
354
- context 'with later_than request parameters' do
355
- it "destroys filtered notifications only" do
356
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target, 'later_than' => (@notification_1.created_at.in_time_zone + 5.second).iso8601(3) }), valid_session
357
- expect(test_target.notifications.count).to eq(1)
358
- expect(test_target.notifications.first).to eq(@notification_1)
359
- end
360
- end
361
-
362
- context 'with earlier_than request parameters' do
363
- it "destroys filtered notifications only" do
364
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target, 'earlier_than' => (@notification_2.created_at.in_time_zone - 5.second).iso8601(3) }), valid_session
365
- expect(test_target.notifications.count).to eq(1)
366
- expect(test_target.notifications.first).to eq(@notification_2)
367
- end
368
- end
369
-
370
- context "with ids request parameters" do
371
- it "destroys notifications with specified IDs only" do
372
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target, 'ids' => [@notification_2.id.to_s] }), valid_session
373
- expect(test_target.notifications.count).to eq(1)
374
- expect(test_target.notifications.first).to eq(@notification_1)
375
- end
376
- end
377
-
378
- context "with no filter request parameters" do
379
- it "destroys all notifications of the target" do
380
- post_with_compatibility :destroy_all, target_params.merge({ typed_target_param => test_target}), valid_session
381
- expect(test_target.notifications.count).to eq(0)
382
- end
383
- end
384
- end
385
- end
386
-
387
- describe "GET #show" do
388
- context "with id, target_type and (typed_target)_id parameters" do
389
- before do
390
- @notification = create(:notification, target: test_target)
391
- get_with_compatibility :show, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
392
- end
393
-
394
- it "returns 200 as http status code" do
395
- expect(response.status).to eq(200)
396
- end
397
-
398
- it "returns the requested notification as JSON" do
399
- assert_json_with_object(response_json, @notification)
400
- end
401
- end
402
-
403
- context "with wrong id and (typed_target)_id parameters" do
404
- before do
405
- @notification = create(:notification, target: create(:user))
406
- get_with_compatibility :show, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
407
- end
408
-
409
- it "returns 403 as http status code" do
410
- expect(response.status).to eq(403)
411
- end
412
-
413
- it "returns error JSON response" do
414
- assert_error_response(403)
415
- end
416
- end
417
-
418
- context "when associated notifiable record was not found" do
419
- before do
420
- @notification = create(:notification, target: test_target)
421
- @notification.notifiable.delete
422
- get_with_compatibility :show, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
423
- end
424
-
425
- it "returns 500 as http status code" do
426
- expect(response.status).to eq(500)
427
- end
428
-
429
- it "returns error JSON response" do
430
- assert_error_response(500)
431
- end
432
- end
433
- end
434
-
435
- describe "DELETE #destroy" do
436
- context "http DELETE request" do
437
- before do
438
- @notification = create(:notification, target: test_target)
439
- delete_with_compatibility :destroy, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
440
- end
441
-
442
- it "returns 204 as http status code" do
443
- expect(response.status).to eq(204)
444
- end
445
-
446
- it "deletes the notification" do
447
- expect(test_target.notifications.where(id: @notification.id).exists?).to be_falsey
448
- end
449
- end
450
- end
451
-
452
- describe "PUT #open" do
453
- context "without move parameter" do
454
- context "http PUT request" do
455
- before do
456
- @notification = create(:notification, target: test_target)
457
- expect(@notification.opened?).to be_falsey
458
- put_with_compatibility :open, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
459
- end
460
-
461
- it "returns 200 as http status code" do
462
- expect(response.status).to eq(200)
463
- end
464
-
465
- it "opens the notification" do
466
- expect(@notification.reload.opened?).to be_truthy
467
- end
468
-
469
- it "returns JSON response" do
470
- expect(response_json["count"]).to eq(1)
471
- assert_json_with_object(response_json["notification"], @notification)
472
- end
473
- end
474
- end
475
-
476
- context "with true as move parameter" do
477
- context "http PUT request" do
478
- before do
479
- @notification = create(:notification, target: test_target)
480
- expect(@notification.opened?).to be_falsey
481
- put_with_compatibility :open, target_params.merge({ id: @notification, typed_target_param => test_target, move: true }), valid_session
482
- end
483
-
484
- it "returns 302 as http status code" do
485
- expect(response.status).to eq(302)
486
- end
487
-
488
- it "opens the notification" do
489
- expect(@notification.reload.opened?).to be_truthy
490
- end
491
-
492
- it "redirects to notifiable_path" do
493
- expect(response).to redirect_to @notification.notifiable_path
494
- end
495
- end
496
- end
497
- end
498
-
499
- describe "GET #move" do
500
- context "without open parameter" do
501
- context "http GET request" do
502
- before do
503
- @notification = create(:notification, target: test_target)
504
- get_with_compatibility :move, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
505
- end
506
-
507
- it "returns 302 as http status code" do
508
- expect(response.status).to eq(302)
509
- end
510
-
511
- it "redirects to notifiable_path" do
512
- expect(response).to redirect_to @notification.notifiable_path
513
- end
514
- end
515
- end
516
-
517
- context "with true as open parameter" do
518
- context "http GET request" do
519
- before do
520
- @notification = create(:notification, target: test_target)
521
- expect(@notification.opened?).to be_falsey
522
- get_with_compatibility :move, target_params.merge({ id: @notification, typed_target_param => test_target, open: true }), valid_session
523
- end
524
-
525
- it "returns 302 as http status code" do
526
- expect(response.status).to eq(302)
527
- end
528
-
529
- it "opens the notification" do
530
- expect(@notification.reload.opened?).to be_truthy
531
- end
532
-
533
- it "redirects to notifiable_path" do
534
- expect(response).to redirect_to @notification.notifiable_path
535
- end
536
- end
537
- end
538
- end
539
- end
540
-
541
- shared_examples_for :notifications_api_request do
542
- include ActivityNotification::ControllerSpec::CommitteeUtility
543
-
544
- before do
545
- group = create(:article)
546
- notifier = create(:user)
547
- create(:notification, target: test_target)
548
- group_owner = create(:notification, target: test_target, group: group, notifier: notifier, parameters: { "test_default_param": "1" })
549
- @notification = create(:notification, target: test_target, group: group, group_owner: group_owner, notifier: notifier, parameters: { "test_default_param": "1" })
550
- group_owner.open!
551
- end
552
-
553
- describe "GET /apidocs" do
554
- it "returns API references as OpenAPI Specification JSON schema" do
555
- get "#{root_path}/apidocs"
556
- write_schema_file(response.body)
557
- expect(read_schema_file["openapi"]).to eq("3.0.0")
558
- end
559
- end
560
-
561
- describe "GET /{target_type}/{target_id}/notifications", type: :request do
562
- it "returns response as API references" do
563
- get_with_compatibility "#{api_path}/notifications", headers: @headers
564
- assert_all_schema_confirm(response, 200)
565
- end
566
- end
567
-
568
- describe "POST /{target_type}/{target_id}/notifications/open_all", type: :request do
569
- it "returns response as API references" do
570
- post_with_compatibility "#{api_path}/notifications/open_all", headers: @headers
571
- assert_all_schema_confirm(response, 200)
572
- end
573
- end
574
-
575
- describe "POST /{target_type}/{target_id}/notifications/destroy_all", type: :request do
576
- it "returns response as API references" do
577
- post_with_compatibility "#{api_path}/notifications/destroy_all", headers: @headers
578
- assert_all_schema_confirm(response, 200)
579
- end
580
- end
581
-
582
- describe "GET /{target_type}/{target_id}/notifications/{id}", type: :request do
583
- it "returns response as API references" do
584
- get_with_compatibility "#{api_path}/notifications/#{@notification.id}", headers: @headers
585
- assert_all_schema_confirm(response, 200)
586
- end
587
-
588
- it "returns error response as API references" do
589
- get_with_compatibility "#{api_path}/notifications/0", headers: @headers
590
- assert_all_schema_confirm(response, 404)
591
- end
592
- end
593
-
594
- describe "DELETE /{target_type}/{target_id}/notifications/{id}", type: :request do
595
- it "returns response as API references" do
596
- delete_with_compatibility "#{api_path}/notifications/#{@notification.id}", headers: @headers
597
- assert_all_schema_confirm(response, 204)
598
- end
599
- end
600
-
601
- describe "PUT /{target_type}/{target_id}/notifications/{id}/open", type: :request do
602
- it "returns response as API references" do
603
- put_with_compatibility "#{api_path}/notifications/#{@notification.id}/open", headers: @headers
604
- assert_all_schema_confirm(response, 200)
605
- end
606
-
607
- it "returns response as API references when request parameters have move=true" do
608
- put_with_compatibility "#{api_path}/notifications/#{@notification.id}/open?move=true", headers: @headers
609
- assert_all_schema_confirm(response, 302)
610
- end
611
- end
612
-
613
- describe "GET /{target_type}/{target_id}/notifications/{id}/move", type: :request do
614
- it "returns response as API references" do
615
- get_with_compatibility "#{api_path}/notifications/#{@notification.id}/move", headers: @headers
616
- assert_all_schema_confirm(response, 302)
617
- end
618
- end
619
- end
@@ -1,19 +0,0 @@
1
- require 'controllers/notifications_api_controller_shared_examples'
2
-
3
- describe ActivityNotification::NotificationsApiController, type: :controller do
4
- let(:test_target) { create(:user) }
5
- let(:target_type) { :users }
6
- let(:typed_target_param) { :user_id }
7
- let(:extra_params) { {} }
8
- let(:valid_session) {}
9
-
10
- it_behaves_like :notifications_api_controller
11
-
12
- describe "/api/v#{ActivityNotification::GEM_VERSION::MAJOR}", type: :request do
13
- let(:root_path) { "/api/v#{ActivityNotification::GEM_VERSION::MAJOR}" }
14
- let(:test_target) { create(:user) }
15
- let(:target_type) { :users }
16
-
17
- it_behaves_like :notifications_api_request
18
- end
19
- end