activity_notification 0.0.8 → 0.0.9

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +11 -1
  3. data/README.md +63 -28
  4. data/activity_notification.gemspec +4 -2
  5. data/app/controllers/activity_notification/notifications_controller.rb +1 -1
  6. data/app/controllers/activity_notification/notifications_with_devise_controller.rb +10 -10
  7. data/app/views/activity_notification/notifications/default/_index.html.erb +9 -4
  8. data/lib/activity_notification.rb +7 -6
  9. data/lib/activity_notification/apis/notification_api.rb +14 -15
  10. data/lib/activity_notification/common.rb +15 -7
  11. data/lib/activity_notification/config.rb +2 -0
  12. data/lib/activity_notification/helpers/view_helpers.rb +5 -4
  13. data/lib/activity_notification/mailers/helpers.rb +9 -9
  14. data/lib/activity_notification/models.rb +16 -0
  15. data/lib/activity_notification/models/{notifiable.rb → concerns/notifiable.rb} +15 -10
  16. data/lib/activity_notification/models/{notifier.rb → concerns/notifier.rb} +6 -0
  17. data/lib/activity_notification/models/{target.rb → concerns/target.rb} +34 -17
  18. data/lib/activity_notification/renderable.rb +2 -1
  19. data/lib/activity_notification/roles/acts_as_notifiable.rb +38 -23
  20. data/lib/activity_notification/roles/acts_as_notifier.rb +11 -0
  21. data/lib/activity_notification/roles/acts_as_target.rb +9 -18
  22. data/lib/activity_notification/version.rb +1 -1
  23. data/lib/generators/activity_notification/{migration → active_record}/migration_generator.rb +5 -4
  24. data/lib/generators/activity_notification/controllers_generator.rb +1 -1
  25. data/lib/generators/activity_notification/install_generator.rb +3 -6
  26. data/lib/generators/activity_notification/{notification → models}/notification_generator.rb +5 -4
  27. data/lib/generators/activity_notification/views_generator.rb +20 -22
  28. data/lib/generators/templates/active_record/migration.rb +1 -1
  29. data/lib/generators/templates/activity_notification.rb +13 -3
  30. data/{config → lib/generators/templates}/locales/en.yml +0 -0
  31. data/lib/generators/templates/notification/notification.rb +4 -1
  32. data/spec/concerns/{notification_api_spec.rb → apis/notification_api_spec.rb} +169 -45
  33. data/spec/concerns/common_spec.rb +150 -0
  34. data/spec/concerns/models/notifiable_spec.rb +435 -0
  35. data/spec/concerns/models/notifier_spec.rb +23 -0
  36. data/spec/concerns/models/target_spec.rb +579 -0
  37. data/spec/concerns/renderable_spec.rb +110 -0
  38. data/spec/controllers/notifications_controller_shared_examples.rb +457 -0
  39. data/spec/controllers/notifications_controller_spec.rb +12 -0
  40. data/spec/controllers/notifications_with_devise_controller_spec.rb +81 -0
  41. data/spec/factories/admins.rb +5 -0
  42. data/spec/factories/articles.rb +1 -1
  43. data/spec/factories/comments.rb +1 -1
  44. data/spec/factories/dummy/dummy_notifiable.rb +4 -0
  45. data/spec/factories/dummy/dummy_notifier.rb +4 -0
  46. data/spec/factories/dummy/dummy_target.rb +4 -0
  47. data/spec/factories/notifications.rb +1 -1
  48. data/spec/factories/users.rb +7 -1
  49. data/spec/generators/active_record/migration_generator_spec.rb +41 -0
  50. data/spec/generators/controllers_generator_spec.rb +62 -0
  51. data/spec/generators/install_generator_spec.rb +43 -0
  52. data/spec/generators/models/notification_generator_spec.rb +41 -0
  53. data/spec/generators/views_generator_spec.rb +111 -0
  54. data/spec/helpers/polymorphic_helpers_spec.rb +89 -0
  55. data/spec/helpers/view_helpers_spec.rb +258 -0
  56. data/spec/mailers/mailer_spec.rb +98 -0
  57. data/spec/models/dummy/dummy_notifiable_spec.rb +6 -0
  58. data/spec/models/dummy/dummy_notifier_spec.rb +6 -0
  59. data/spec/models/dummy/dummy_target_spec.rb +6 -0
  60. data/spec/models/notification_spec.rb +5 -4
  61. data/spec/rails_app/app/assets/javascripts/application.js +2 -0
  62. data/spec/rails_app/app/controllers/articles_controller.rb +62 -0
  63. data/spec/rails_app/app/controllers/comments_controller.rb +34 -0
  64. data/spec/rails_app/app/models/admin.rb +8 -0
  65. data/spec/rails_app/app/models/article.rb +6 -6
  66. data/spec/rails_app/app/models/comment.rb +2 -2
  67. data/spec/rails_app/app/models/dummy/dummy_base.rb +2 -0
  68. data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +4 -0
  69. data/spec/rails_app/app/models/dummy/dummy_notifier.rb +4 -0
  70. data/spec/rails_app/app/models/dummy/dummy_target.rb +4 -0
  71. data/spec/rails_app/app/models/user.rb +5 -5
  72. data/spec/rails_app/app/views/activity_notification/notifications/default/custom/_path_test.html.erb +1 -0
  73. data/spec/rails_app/app/views/activity_notification/notifications/default/custom/_test.html.erb +1 -0
  74. data/spec/rails_app/app/views/activity_notification/notifications/users/_custom_index.html.erb +1 -0
  75. data/spec/rails_app/app/views/activity_notification/notifications/users/custom/_test.html.erb +1 -0
  76. data/spec/rails_app/app/views/articles/_form.html.erb +20 -0
  77. data/spec/rails_app/app/views/articles/edit.html.erb +6 -0
  78. data/spec/rails_app/app/views/articles/index.html.erb +67 -0
  79. data/spec/rails_app/app/views/articles/new.html.erb +5 -0
  80. data/spec/rails_app/app/views/articles/show.html.erb +38 -0
  81. data/spec/rails_app/app/views/layouts/_header.html.erb +8 -0
  82. data/spec/rails_app/app/views/layouts/application.html.erb +3 -4
  83. data/spec/rails_app/config/initializers/activity_notification.rb +13 -3
  84. data/spec/rails_app/config/initializers/devise.rb +274 -274
  85. data/spec/rails_app/config/locales/activity_notification.en.yml +20 -0
  86. data/spec/rails_app/config/locales/devise.en.yml +62 -0
  87. data/spec/rails_app/config/routes.rb +6 -2
  88. data/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb +6 -2
  89. data/spec/rails_app/db/schema.rb +8 -0
  90. data/spec/rails_app/db/seeds.rb +43 -0
  91. data/spec/roles/acts_as_notifiable_spec.rb +32 -0
  92. data/spec/roles/acts_as_notifier_spec.rb +17 -0
  93. data/spec/roles/acts_as_target_spec.rb +40 -0
  94. data/spec/spec_helper.rb +18 -14
  95. metadata +136 -12
@@ -0,0 +1,110 @@
1
+ shared_examples_for :renderable do
2
+ let(:test_class_name) { described_class.to_s.underscore.split('/').last.to_sym }
3
+ let(:test_target) { create(:user) }
4
+ let(:test_instance) { create(test_class_name, target: test_target) }
5
+ let(:target_type_key) { 'user' }
6
+
7
+ let(:notifier_name) { 'foo' }
8
+ let(:article_title) { 'bar' }
9
+ let(:group_member_count) { 3 }
10
+ let(:simple_text_key) { 'article.create' }
11
+ let(:params_text_key) { 'comment.post' }
12
+ let(:group_text_key) { 'comment.reply' }
13
+ let(:simple_text_original) { 'Article has been created' }
14
+ let(:params_text_original) { "<p>%{notifier_name} posted comments to your article %{article_title}</p>" }
15
+ let(:group_text_original) { "<p>%{notifier_name} and %{group_member_count} people replied for your comments</p>" }
16
+ let(:params_text_embedded) { "<p>foo posted comments to your article bar</p>" }
17
+ let(:group_text_embedded) { "<p>foo and 3 people replied for your comments</p>" }
18
+
19
+ describe "i18n configuration" do
20
+ it "has key configured for simple text" do
21
+ expect(I18n.t("notification.#{target_type_key}.#{simple_text_key}.text"))
22
+ .to eq(simple_text_original)
23
+ end
24
+
25
+ it "has key configured with embedded params" do
26
+ expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text"))
27
+ .to eq(params_text_original)
28
+ expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text",
29
+ {notifier_name: notifier_name, article_title: article_title}))
30
+ .to eq(params_text_embedded)
31
+ end
32
+
33
+ it "has key configured with embedded params including group_member_count" do
34
+ expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text"))
35
+ .to eq(group_text_original)
36
+ expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text",
37
+ {notifier_name: notifier_name, group_member_count: group_member_count}))
38
+ .to eq(group_text_embedded)
39
+ end
40
+ end
41
+
42
+ describe "as public instance methods" do
43
+ describe "#text" do
44
+ context "without params argument" do
45
+ context "with target type of test instance" do
46
+ it "uses text from key" do
47
+ test_instance.key = simple_text_key
48
+ expect(test_instance.text).to eq(simple_text_original)
49
+ end
50
+
51
+ it "uses text from key with notification namespace" do
52
+ test_instance.key = "notification.#{simple_text_key}"
53
+ expect(test_instance.text).to eq(simple_text_original)
54
+ end
55
+
56
+ context "when the text is missing for the target type" do
57
+ it "returns translation missing text" do
58
+ test_instance.target = create(:admin)
59
+ test_instance.key = "notification.#{simple_text_key}"
60
+ expect(test_instance.text)
61
+ .to eq("translation missing: en.notification.admin.#{simple_text_key}.text")
62
+ end
63
+ end
64
+
65
+ context "when the text has embedded parameters" do
66
+ it "raises MissingInterpolationArgument without embedded parameters" do
67
+ test_instance.key = params_text_key
68
+ expect { test_instance.text }
69
+ .to raise_error(I18n::MissingInterpolationArgument)
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ context "with params argument" do
76
+ context "with target type of target parameter" do
77
+ it "uses text from key" do
78
+ test_instance.target = create(:admin)
79
+ test_instance.key = simple_text_key
80
+ expect(test_instance.text({target: :user})).to eq(simple_text_original)
81
+ end
82
+
83
+ context "when the text has embedded parameters" do
84
+ it "uses text with embedded parameters" do
85
+ test_instance.key = params_text_key
86
+ expect(test_instance.text({notifier_name: notifier_name, article_title: article_title}))
87
+ .to eq(params_text_embedded)
88
+ end
89
+
90
+ it "uses text with automatically embedded group_member_count" do
91
+ # Create 3 group members
92
+ create(test_class_name, target: test_instance.target, group_owner: test_instance)
93
+ create(test_class_name, target: test_instance.target, group_owner: test_instance)
94
+ create(test_class_name, target: test_instance.target, group_owner: test_instance)
95
+ test_instance.key = group_text_key
96
+ expect(test_instance.text({notifier_name: notifier_name}))
97
+ .to eq(group_text_embedded)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # Test with view_helper for the following methods
105
+ # #render
106
+ # #partial_path
107
+ # #layout_path
108
+
109
+ end
110
+ end
@@ -0,0 +1,457 @@
1
+ shared_examples_for :notification_controller do
2
+ let(:target_params) { { target_type: target_type }.merge(extra_params || {}) }
3
+
4
+ describe "GET #index" do
5
+ context "with target_type and target_id parameters" do
6
+ before do
7
+ @notification = create(:notification, target: test_target)
8
+ get :index, target_params.merge({ target_id: test_target, typed_target_param => 'dummy' }), valid_session
9
+ end
10
+
11
+ it "returns 200 as http status code" do
12
+ expect(response.status).to eq(200)
13
+ end
14
+
15
+ it "assigns notification index as @notifications" do
16
+ expect(assigns(:notifications)).to eq([@notification])
17
+ end
18
+
19
+ it "renders the :index template" do
20
+ expect(response).to render_template :index
21
+ end
22
+ end
23
+
24
+ context "with target_type and (typed_target)_id parameters" do
25
+ before do
26
+ @notification = create(:notification, target: test_target)
27
+ get :index, target_params.merge({ typed_target_param => test_target }), valid_session
28
+ end
29
+
30
+ it "returns 200 as http status code" do
31
+ expect(response.status).to eq(200)
32
+ end
33
+
34
+ it "assigns notification index as @notifications" do
35
+ expect(assigns(:notifications)).to eq([@notification])
36
+ end
37
+
38
+ it "renders the :index template" do
39
+ expect(response).to render_template :index
40
+ end
41
+ end
42
+
43
+ context "without target_type parameters" do
44
+ before do
45
+ @notification = create(:notification, target: test_target)
46
+ get :index, { typed_target_param => test_target }, valid_session
47
+ end
48
+
49
+ it "returns 400 as http status code" do
50
+ expect(response.status).to eq(400)
51
+ end
52
+ end
53
+
54
+ context "with not found (typed_target)_id parameter" do
55
+ before do
56
+ @notification = create(:notification, target: test_target)
57
+ end
58
+
59
+ it "raises ActiveRecord::RecordNotFound" do
60
+ expect {
61
+ get :index, target_params.merge({ typed_target_param => 0 }), valid_session
62
+ }.to raise_error(ActiveRecord::RecordNotFound)
63
+ end
64
+ end
65
+
66
+ context "with json as format parameter" do
67
+ before do
68
+ @notification = create(:notification, target: test_target)
69
+ get :index, target_params.merge({ typed_target_param => test_target, format: :json }), valid_session
70
+ end
71
+
72
+ it "returns 200 as http status code" do
73
+ expect(response.status).to eq(200)
74
+ end
75
+
76
+ it "returns json format" do
77
+ expect(JSON.parse(response.body).first)
78
+ .to include("target_id" => test_target.id, "target_type" => test_target.to_class_name)
79
+ end
80
+ end
81
+
82
+ context "with filter parameter" do
83
+ context "with unopened as filter" do
84
+ before do
85
+ @notification = create(:notification, target: test_target)
86
+ get :index, target_params.merge({ typed_target_param => test_target, filter: 'unopened' }), valid_session
87
+ end
88
+
89
+ it "assigns unopened notification index as @notifications" do
90
+ expect(assigns(:notifications)).to eq([@notification])
91
+ end
92
+ end
93
+
94
+ context "with opened as filter" do
95
+ before do
96
+ @notification = create(:notification, target: test_target)
97
+ get :index, target_params.merge({ typed_target_param => test_target, filter: 'opened' }), valid_session
98
+ end
99
+
100
+ it "assigns unopened notification index as @notifications" do
101
+ expect(assigns(:notifications)).to eq([])
102
+ end
103
+ end
104
+ end
105
+
106
+ context "with limit parameter" do
107
+ before do
108
+ create(:notification, target: test_target)
109
+ create(:notification, target: test_target)
110
+ end
111
+ context "with 2 as limit" do
112
+ before do
113
+ get :index, target_params.merge({ typed_target_param => test_target, limit: 2 }), valid_session
114
+ end
115
+
116
+ it "assigns notification index of size 2 as @notifications" do
117
+ expect(assigns(:notifications).size).to eq(2)
118
+ end
119
+ end
120
+
121
+ context "with 1 as limit" do
122
+ before do
123
+ get :index, target_params.merge({ typed_target_param => test_target, limit: 1 }), valid_session
124
+ end
125
+
126
+ it "assigns notification index of size 1 as @notifications" do
127
+ expect(assigns(:notifications).size).to eq(1)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "with reload parameter" do
133
+ context "with false as reload" do
134
+ before do
135
+ @notification = create(:notification, target: test_target)
136
+ get :index, target_params.merge({ typed_target_param => test_target, reload: false }), valid_session
137
+ end
138
+
139
+ it "returns 200 as http status code" do
140
+ expect(response.status).to eq(200)
141
+ end
142
+
143
+ it "does not assign notification index as @notifications" do
144
+ expect(assigns(:notifications)).to be_nil
145
+ end
146
+
147
+ it "renders the :index template" do
148
+ expect(response).to render_template :index
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "POST #open_all" do
155
+ context "http direct POST request" do
156
+ before do
157
+ @notification = create(:notification, target: test_target)
158
+ expect(@notification.opened?).to be_falsey
159
+ post :open_all, target_params.merge({ typed_target_param => test_target }), valid_session
160
+ end
161
+
162
+ it "returns 302 as http status code" do
163
+ expect(response.status).to eq(302)
164
+ end
165
+
166
+ it "assigns notification index as @notifications" do
167
+ expect(assigns(:notifications)).to eq([@notification])
168
+ end
169
+
170
+ it "opens all notifications of the target" do
171
+ expect(assigns(:notifications).first.opened?).to be_truthy
172
+ end
173
+
174
+ it "redirects to :index" do
175
+ expect(response).to redirect_to action: :index
176
+ end
177
+ end
178
+
179
+ context "http POST request from root_path" do
180
+ before do
181
+ @notification = create(:notification, target: test_target)
182
+ expect(@notification.opened?).to be_falsey
183
+ request.env["HTTP_REFERER"] = root_path
184
+ post :open_all, target_params.merge({ typed_target_param => test_target }), valid_session
185
+ end
186
+
187
+ it "returns 302 as http status code" do
188
+ expect(response.status).to eq(302)
189
+ end
190
+
191
+ it "opens all notifications of the target" do
192
+ expect(assigns(:notifications).first.opened?).to be_truthy
193
+ end
194
+
195
+ it "redirects to root_path as request.referer" do
196
+ expect(response).to redirect_to root_path
197
+ end
198
+ end
199
+
200
+ context "Ajax POST request" do
201
+ before do
202
+ @notification = create(:notification, target: test_target)
203
+ expect(@notification.opened?).to be_falsey
204
+ xhr :post, :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 "assigns notification index as @notifications" do
212
+ expect(assigns(:notifications)).to eq([@notification])
213
+ end
214
+
215
+ it "opens all notifications of the target" do
216
+ expect(assigns(:notifications).first.opened?).to be_truthy
217
+ end
218
+
219
+ it "renders the :open_all template as format js" do
220
+ expect(response).to render_template :open_all, format: :js
221
+ end
222
+ end
223
+ end
224
+
225
+ describe "GET #show" do
226
+ context "with id, target_type and (typed_target)_id parameters" do
227
+ before do
228
+ @notification = create(:notification, target: test_target)
229
+ get :show, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
230
+ end
231
+
232
+ it "returns 200 as http status code" do
233
+ expect(response.status).to eq(200)
234
+ end
235
+
236
+ it "assigns the requested notification as @notification" do
237
+ expect(assigns(:notification)).to eq(@notification)
238
+ end
239
+
240
+ it "renders the :index template" do
241
+ expect(response).to render_template :show
242
+ end
243
+ end
244
+
245
+ context "with wrong id and (typed_target)_id parameters" do
246
+ before do
247
+ @notification = create(:notification, target: create(:user))
248
+ get :show, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
249
+ end
250
+
251
+ it "returns 403 as http status code" do
252
+ expect(response.status).to eq(403)
253
+ end
254
+ end
255
+ end
256
+
257
+ describe "DELETE #destroy" do
258
+ context "http direct DELETE request" do
259
+ before do
260
+ @notification = create(:notification, target: test_target)
261
+ delete :destroy, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
262
+ end
263
+
264
+ it "returns 302 as http status code" do
265
+ expect(response.status).to eq(302)
266
+ end
267
+
268
+ it "deletes the notification" do
269
+ expect(assigns(test_target.notifications.where(id: @notification.id).exists?)).to be_falsey
270
+ end
271
+
272
+ it "redirects to :index" do
273
+ expect(response).to redirect_to action: :index
274
+ end
275
+ end
276
+
277
+ context "http DELETE request from root_path" do
278
+ before do
279
+ @notification = create(:notification, target: test_target)
280
+ request.env["HTTP_REFERER"] = root_path
281
+ delete :destroy, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
282
+ end
283
+
284
+ it "returns 302 as http status code" do
285
+ expect(response.status).to eq(302)
286
+ end
287
+
288
+ it "deletes the notification" do
289
+ expect(assigns(test_target.notifications.where(id: @notification.id).exists?)).to be_falsey
290
+ end
291
+
292
+ it "redirects to root_path as request.referer" do
293
+ expect(response).to redirect_to root_path
294
+ end
295
+ end
296
+
297
+ context "Ajax DELETE request" do
298
+ before do
299
+ @notification = create(:notification, target: test_target)
300
+ xhr :delete, :destroy, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
301
+ end
302
+
303
+ it "returns 200 as http status code" do
304
+ expect(response.status).to eq(200)
305
+ end
306
+
307
+ it "assigns notification index as @notifications" do
308
+ expect(assigns(:notifications)).to eq([])
309
+ end
310
+
311
+ it "deletes the notification" do
312
+ expect(assigns(test_target.notifications.where(id: @notification.id).exists?)).to be_falsey
313
+ end
314
+
315
+ it "renders the :destroy template as format js" do
316
+ expect(response).to render_template :destroy, format: :js
317
+ end
318
+ end
319
+ end
320
+
321
+ describe "POST #open" do
322
+ context "without move parameter" do
323
+ context "http direct POST request" do
324
+ before do
325
+ @notification = create(:notification, target: test_target)
326
+ expect(@notification.opened?).to be_falsey
327
+ post :open, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
328
+ end
329
+
330
+ it "returns 302 as http status code" do
331
+ expect(response.status).to eq(302)
332
+ end
333
+
334
+ it "opens the notification" do
335
+ expect(@notification.reload.opened?).to be_truthy
336
+ end
337
+
338
+ it "redirects to :index" do
339
+ expect(response).to redirect_to action: :index
340
+ end
341
+ end
342
+
343
+ context "http POST request from root_path" do
344
+ before do
345
+ @notification = create(:notification, target: test_target)
346
+ expect(@notification.opened?).to be_falsey
347
+ request.env["HTTP_REFERER"] = root_path
348
+ post :open, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
349
+ end
350
+
351
+ it "returns 302 as http status code" do
352
+ expect(response.status).to eq(302)
353
+ end
354
+
355
+ it "opens the notification" do
356
+ expect(@notification.reload.opened?).to be_truthy
357
+ end
358
+
359
+ it "redirects to root_path as request.referer" do
360
+ expect(response).to redirect_to root_path
361
+ end
362
+ end
363
+
364
+ context "Ajax POST request" do
365
+ before do
366
+ @notification = create(:notification, target: test_target)
367
+ expect(@notification.opened?).to be_falsey
368
+ request.env["HTTP_REFERER"] = root_path
369
+ xhr :post, :open, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
370
+ end
371
+
372
+ it "returns 200 as http status code" do
373
+ expect(response.status).to eq(200)
374
+ end
375
+
376
+ it "assigns notification index as @notifications" do
377
+ expect(assigns(:notifications)).to eq([@notification])
378
+ end
379
+
380
+ it "opens the notification" do
381
+ expect(@notification.reload.opened?).to be_truthy
382
+ end
383
+
384
+ it "renders the :open template as format js" do
385
+ expect(response).to render_template :open, format: :js
386
+ end
387
+ end
388
+ end
389
+
390
+ context "with true as move parameter" do
391
+ context "http direct POST request" do
392
+ before do
393
+ @notification = create(:notification, target: test_target)
394
+ expect(@notification.opened?).to be_falsey
395
+ post :open, target_params.merge({ id: @notification, typed_target_param => test_target, move: true }), valid_session
396
+ end
397
+
398
+ it "returns 302 as http status code" do
399
+ expect(response.status).to eq(302)
400
+ end
401
+
402
+ it "assigns notification index as @notifications" do
403
+ expect(assigns(:notifications)).to eq([@notification])
404
+ end
405
+
406
+ it "opens the notification" do
407
+ expect(@notification.reload.opened?).to be_truthy
408
+ end
409
+
410
+ it "redirects to notifiable_path" do
411
+ expect(response).to redirect_to @notification.notifiable_path
412
+ end
413
+ end
414
+ end
415
+ end
416
+
417
+ describe "GET #move" do
418
+ context "without open parameter" do
419
+ context "http direct GET request" do
420
+ before do
421
+ @notification = create(:notification, target: test_target)
422
+ get :move, target_params.merge({ id: @notification, typed_target_param => test_target }), valid_session
423
+ end
424
+
425
+ it "returns 302 as http status code" do
426
+ expect(response.status).to eq(302)
427
+ end
428
+
429
+ it "redirects to notifiable_path" do
430
+ expect(response).to redirect_to @notification.notifiable_path
431
+ end
432
+ end
433
+ end
434
+
435
+ context "with true as open parameter" do
436
+ context "http direct GET request" do
437
+ before do
438
+ @notification = create(:notification, target: test_target)
439
+ expect(@notification.opened?).to be_falsey
440
+ get :move, target_params.merge({ id: @notification, typed_target_param => test_target, open: true }), valid_session
441
+ end
442
+
443
+ it "returns 302 as http status code" do
444
+ expect(response.status).to eq(302)
445
+ end
446
+
447
+ it "opens the notification" do
448
+ expect(@notification.reload.opened?).to be_truthy
449
+ end
450
+
451
+ it "redirects to notifiable_path" do
452
+ expect(response).to redirect_to @notification.notifiable_path
453
+ end
454
+ end
455
+ end
456
+ end
457
+ end