activity_notification 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +33 -0
  3. data/.rubocop.yml +1157 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG.md +25 -0
  6. data/Gemfile.lock +15 -17
  7. data/README.md +154 -27
  8. data/activity_notification.gemspec +1 -1
  9. data/app/controllers/activity_notification/notifications_controller.rb +30 -104
  10. data/app/controllers/activity_notification/notifications_with_devise_controller.rb +1 -33
  11. data/app/controllers/activity_notification/subscriptions_controller.rb +184 -0
  12. data/app/controllers/activity_notification/subscriptions_with_devise_controller.rb +6 -0
  13. data/app/mailers/activity_notification/mailer.rb +3 -3
  14. data/app/views/activity_notification/notifications/default/_index.html.erb +3 -0
  15. data/app/views/activity_notification/notifications/default/index.html.erb +8 -10
  16. data/app/views/activity_notification/notifications/default/show.html.erb +24 -2
  17. data/app/views/activity_notification/subscriptions/default/_form.html.erb +52 -0
  18. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +89 -0
  19. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +73 -0
  20. data/app/views/activity_notification/subscriptions/default/_subscriptions.html.erb +13 -0
  21. data/app/views/activity_notification/subscriptions/default/create.js.erb +5 -0
  22. data/app/views/activity_notification/subscriptions/default/destroy.js.erb +5 -0
  23. data/app/views/activity_notification/subscriptions/default/index.html.erb +197 -0
  24. data/app/views/activity_notification/subscriptions/default/show.html.erb +177 -0
  25. data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +8 -0
  26. data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +6 -0
  27. data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +8 -0
  28. data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +6 -0
  29. data/gemfiles/Gemfile.rails-4.2.lock +18 -20
  30. data/gemfiles/Gemfile.rails-5.0.lock +18 -20
  31. data/lib/activity_notification.rb +7 -3
  32. data/lib/activity_notification/apis/notification_api.rb +95 -61
  33. data/lib/activity_notification/apis/subscription_api.rb +51 -0
  34. data/lib/activity_notification/common.rb +1 -1
  35. data/lib/activity_notification/config.rb +65 -17
  36. data/lib/activity_notification/controllers/common_controller.rb +118 -0
  37. data/lib/activity_notification/controllers/devise_authentication_controller.rb +41 -0
  38. data/lib/activity_notification/helpers/view_helpers.rb +131 -3
  39. data/lib/activity_notification/mailers/helpers.rb +6 -8
  40. data/lib/activity_notification/models/concerns/notifiable.rb +45 -27
  41. data/lib/activity_notification/models/concerns/subscriber.rb +149 -0
  42. data/lib/activity_notification/models/concerns/target.rb +100 -66
  43. data/lib/activity_notification/models/notification.rb +7 -5
  44. data/lib/activity_notification/models/subscription.rb +93 -0
  45. data/lib/activity_notification/rails/routes.rb +148 -33
  46. data/lib/activity_notification/renderable.rb +3 -4
  47. data/lib/activity_notification/roles/acts_as_notifiable.rb +14 -1
  48. data/lib/activity_notification/roles/acts_as_target.rb +11 -8
  49. data/lib/activity_notification/version.rb +1 -1
  50. data/lib/generators/activity_notification/controllers_generator.rb +2 -2
  51. data/lib/generators/activity_notification/install_generator.rb +0 -1
  52. data/lib/generators/activity_notification/migration/migration_generator.rb +8 -2
  53. data/lib/generators/activity_notification/models_generator.rb +53 -0
  54. data/lib/generators/activity_notification/views_generator.rb +7 -7
  55. data/lib/generators/templates/activity_notification.rb +17 -3
  56. data/lib/generators/templates/controllers/notifications_controller.rb +18 -17
  57. data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +18 -17
  58. data/lib/generators/templates/controllers/subscriptions_controller.rb +79 -0
  59. data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +87 -0
  60. data/lib/generators/templates/migrations/migration.rb +57 -0
  61. data/lib/generators/templates/models/README +10 -0
  62. data/lib/generators/templates/{notification → models}/notification.rb +1 -3
  63. data/lib/generators/templates/models/subscription.rb +4 -0
  64. data/spec/concerns/apis/notification_api_spec.rb +48 -11
  65. data/spec/concerns/apis/subscription_api_spec.rb +167 -0
  66. data/spec/concerns/models/notifiable_spec.rb +60 -0
  67. data/spec/concerns/models/subscriber_spec.rb +525 -0
  68. data/spec/concerns/models/target_spec.rb +271 -42
  69. data/spec/controllers/common_controller_spec.rb +25 -0
  70. data/spec/controllers/dummy_common_controller.rb +5 -0
  71. data/spec/controllers/notifications_controller_shared_examples.rb +2 -6
  72. data/spec/controllers/subscriptions_controller_shared_examples.rb +735 -0
  73. data/spec/controllers/subscriptions_controller_spec.rb +12 -0
  74. data/spec/controllers/subscriptions_with_devise_controller_spec.rb +91 -0
  75. data/spec/factories/dummy/dummy_subscriber.rb +4 -0
  76. data/spec/factories/subscriptions.rb +8 -0
  77. data/spec/generators/controllers_generator_spec.rb +25 -2
  78. data/spec/generators/migration/migration_generator_spec.rb +3 -3
  79. data/spec/generators/models_generator_spec.rb +96 -0
  80. data/spec/generators/views_generator_spec.rb +84 -0
  81. data/spec/helpers/view_helpers_spec.rb +143 -0
  82. data/spec/mailers/mailer_spec.rb +5 -4
  83. data/spec/models/dummy/dummy_subscriber_spec.rb +5 -0
  84. data/spec/models/notification_spec.rb +7 -7
  85. data/spec/models/subscription_spec.rb +158 -0
  86. data/spec/rails_app/app/controllers/users/notifications_controller.rb +67 -0
  87. data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +75 -0
  88. data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +79 -0
  89. data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +87 -0
  90. data/spec/rails_app/app/models/admin.rb +1 -0
  91. data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +4 -0
  92. data/spec/rails_app/app/models/user.rb +2 -1
  93. data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +1 -0
  94. data/spec/rails_app/app/views/articles/index.html.erb +6 -0
  95. data/spec/rails_app/config/initializers/activity_notification.rb +17 -3
  96. data/spec/rails_app/config/routes.rb +2 -2
  97. data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +33 -0
  98. data/spec/rails_app/db/schema.rb +18 -0
  99. data/spec/roles/acts_as_notifiable_spec.rb +1 -1
  100. data/spec/roles/acts_as_target_spec.rb +1 -1
  101. metadata +70 -11
  102. data/lib/generators/activity_notification/notification/notification_generator.rb +0 -20
  103. data/lib/generators/templates/active_record/migration.rb +0 -18
  104. data/spec/generators/notification/notification_generator_spec.rb +0 -41
  105. data/spec/rails_app/db/migrate/20160715050420_create_notifications.rb +0 -18
@@ -10,7 +10,7 @@ shared_examples_for :target do
10
10
  expect(test_instance.notifications.count).to eq(2)
11
11
  expect(test_instance.notifications.earliest).to eq(notification_1)
12
12
  expect(test_instance.notifications.latest).to eq(notification_2)
13
- expect(test_instance.notifications).to eq (ActivityNotification::Notification.filtered_by_target(test_instance))
13
+ expect(test_instance.notifications).to eq(ActivityNotification::Notification.filtered_by_target(test_instance))
14
14
  end
15
15
  end
16
16
 
@@ -43,34 +43,103 @@ shared_examples_for :target do
43
43
  notification_5 = create(:notification, target: target_2)
44
44
  notification_6 = create(:notification, target: test_notifiable)
45
45
 
46
- expect(described_class.notification_index_map.size).to eq(2)
47
- expect(described_class.notification_index_map[target_1].size).to eq(3)
46
+ index_map = described_class.notification_index_map
47
+ expect(index_map.size).to eq(2)
48
+ expect(index_map[target_1].size).to eq(3)
48
49
  expect(described_class.notification_index_map[target_2].size).to eq(2)
49
50
  end
50
- end
51
51
 
52
- describe ".unopened_notification_index_map" do
53
- it "returns unopened notifications of this target type group by target" do
54
- ActivityNotification::Notification.delete_all
55
- target_1 = create(test_class_name)
56
- target_2 = create(test_class_name)
57
- target_3 = create(test_class_name)
58
- notification_1 = create(:notification, target: target_1)
59
- notification_2 = create(:notification, target: target_1)
60
- notification_3 = create(:notification, target: target_1)
61
- notification_3.open!
62
- notification_4 = create(:notification, target: target_2)
63
- notification_5 = create(:notification, target: target_2)
64
- notification_5.open!
65
- notification_6 = create(:notification, target: target_3)
66
- notification_6.open!
67
- notification_7 = create(:notification, target: test_notifiable)
52
+ context "with :filtered_by_status" do
53
+ context "as :opened" do
54
+ it "returns opened notifications of this target type group by target" do
55
+ ActivityNotification::Notification.delete_all
56
+ target_1 = create(test_class_name)
57
+ target_2 = create(test_class_name)
58
+ target_3 = create(test_class_name)
59
+ notification_1 = create(:notification, target: target_1)
60
+ notification_2 = create(:notification, target: target_1)
61
+ notification_2.open!
62
+ notification_3 = create(:notification, target: target_1)
63
+ notification_3.open!
64
+ notification_4 = create(:notification, target: target_2)
65
+ notification_5 = create(:notification, target: target_2)
66
+ notification_5.open!
67
+ notification_6 = create(:notification, target: target_3)
68
+ notification_7 = create(:notification, target: test_notifiable)
69
+
70
+ index_map = described_class.notification_index_map(filtered_by_status: :opened)
71
+ expect(index_map.size).to eq(2)
72
+ expect(index_map[target_1].size).to eq(2)
73
+ expect(index_map[target_2].size).to eq(1)
74
+ expect(index_map.has_key?(target_3)).to be_falsey
75
+ end
76
+ end
68
77
 
69
- index_map = described_class.unopened_notification_index_map
70
- expect(index_map.size).to eq(2)
71
- expect(index_map[target_1].size).to eq(2)
72
- expect(index_map[target_2].size).to eq(1)
73
- expect(index_map.has_key?(target_3)).to be_falsey
78
+ context "as :unopened" do
79
+ it "returns unopened notifications of this target type group by target" do
80
+ ActivityNotification::Notification.delete_all
81
+ target_1 = create(test_class_name)
82
+ target_2 = create(test_class_name)
83
+ target_3 = create(test_class_name)
84
+ notification_1 = create(:notification, target: target_1)
85
+ notification_2 = create(:notification, target: target_1)
86
+ notification_3 = create(:notification, target: target_1)
87
+ notification_3.open!
88
+ notification_4 = create(:notification, target: target_2)
89
+ notification_5 = create(:notification, target: target_2)
90
+ notification_5.open!
91
+ notification_6 = create(:notification, target: target_3)
92
+ notification_6.open!
93
+ notification_7 = create(:notification, target: test_notifiable)
94
+
95
+ index_map = described_class.notification_index_map(filtered_by_status: :unopened)
96
+ expect(index_map.size).to eq(2)
97
+ expect(index_map[target_1].size).to eq(2)
98
+ expect(index_map[target_2].size).to eq(1)
99
+ expect(index_map.has_key?(target_3)).to be_falsey
100
+ end
101
+ end
102
+ end
103
+
104
+ context "with :as_latest_group_member" do
105
+ before do
106
+ ActivityNotification::Notification.delete_all
107
+ @target_1 = create(test_class_name)
108
+ @target_2 = create(test_class_name)
109
+ @target_3 = create(test_class_name)
110
+ notification_1 = create(:notification, target: @target_1)
111
+ @notification_2 = create(:notification, target: @target_1)
112
+ notification_3 = create(:notification, target: @target_1, group_owner: @notification_2)
113
+ @notification_4 = create(:notification, target: @target_1, group_owner: @notification_2)
114
+ notification_5 = create(:notification, target: @target_2)
115
+ notification_6 = create(:notification, target: @target_2)
116
+ notification_6.open!
117
+ notification_7 = create(:notification, target: @target_3)
118
+ notification_7.open!
119
+ notification_8 = create(:notification, target: test_notifiable)
120
+ end
121
+
122
+ context "as default" do
123
+ it "returns earliest group members" do
124
+ index_map = described_class.notification_index_map(filtered_by_status: :unopened)
125
+ expect(index_map.size).to eq(2)
126
+ expect(index_map[@target_1].size).to eq(2)
127
+ expect(index_map[@target_1].first).to eq(@notification_2)
128
+ expect(index_map[@target_2].size).to eq(1)
129
+ expect(index_map.has_key?(@target_3)).to be_falsey
130
+ end
131
+ end
132
+
133
+ context "as true" do
134
+ it "returns latest group members" do
135
+ index_map = described_class.notification_index_map(filtered_by_status: :unopened, as_latest_group_member: true)
136
+ expect(index_map.size).to eq(2)
137
+ expect(index_map[@target_1].size).to eq(2)
138
+ expect(index_map[@target_1].first).to eq(@notification_4)
139
+ expect(index_map[@target_2].size).to eq(1)
140
+ expect(index_map.has_key?(@target_3)).to be_falsey
141
+ end
142
+ end
74
143
  end
75
144
  end
76
145
 
@@ -99,6 +168,29 @@ shared_examples_for :target do
99
168
  expect(sent_email_map.has_key?(target_3)).to be_falsey
100
169
  end
101
170
  end
171
+
172
+ describe "subscription_enabled?" do
173
+ context "with true as _notification_subscription_allowed" do
174
+ it "returns true" do
175
+ described_class._notification_subscription_allowed = true
176
+ expect(described_class.subscription_enabled?).to eq(true)
177
+ end
178
+ end
179
+
180
+ context "with false as _notification_subscription_allowed" do
181
+ it "returns false" do
182
+ described_class._notification_subscription_allowed = false
183
+ expect(described_class.subscription_enabled?).to eq(false)
184
+ end
185
+ end
186
+
187
+ context "with lambda configuration as _notification_subscription_allowed" do
188
+ it "returns true (even if configured lambda function returns false)" do
189
+ described_class._notification_subscription_allowed = ->(target, key){ false }
190
+ expect(described_class.subscription_enabled?).to eq(true)
191
+ end
192
+ end
193
+ end
102
194
  end
103
195
 
104
196
  describe "as public instance methods" do
@@ -195,6 +287,110 @@ shared_examples_for :target do
195
287
  end
196
288
  end
197
289
 
290
+ describe "#batch_notification_email_allowed?" do
291
+ context "without any configuration" do
292
+ it "returns ActivityNotification.config.email_enabled" do
293
+ expect(test_instance.batch_notification_email_allowed?('dummy_key'))
294
+ .to eq(ActivityNotification.config.email_enabled)
295
+ end
296
+
297
+ it "returns false as default" do
298
+ expect(test_instance.batch_notification_email_allowed?('dummy_key')).to be_falsey
299
+ end
300
+ end
301
+
302
+ context "configured with a field" do
303
+ it "returns specified value" do
304
+ described_class._batch_notification_email_allowed = true
305
+ expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
306
+ end
307
+
308
+ it "returns specified symbol without argument" do
309
+ module AdditionalMethods
310
+ def custom_batch_notification_email_allowed?
311
+ true
312
+ end
313
+ end
314
+ test_instance.extend(AdditionalMethods)
315
+ described_class._batch_notification_email_allowed = :custom_batch_notification_email_allowed?
316
+ expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
317
+ end
318
+
319
+ it "returns specified symbol with target and key arguments" do
320
+ module AdditionalMethods
321
+ def custom_batch_notification_email_allowed?(key)
322
+ true
323
+ end
324
+ end
325
+ test_instance.extend(AdditionalMethods)
326
+ described_class._batch_notification_email_allowed = :custom_batch_notification_email_allowed?
327
+ expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
328
+ end
329
+
330
+ it "returns specified lambda with single target argument" do
331
+ described_class._batch_notification_email_allowed = ->(target){ true }
332
+ expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
333
+ end
334
+
335
+ it "returns specified lambda with target and key arguments" do
336
+ described_class._batch_notification_email_allowed = ->(target, key){ true }
337
+ expect(test_instance.batch_notification_email_allowed?('dummy_key')).to eq(true)
338
+ end
339
+ end
340
+ end
341
+
342
+ describe "#subscription_allowed?" do
343
+ context "without any configuration" do
344
+ it "returns ActivityNotification.config.subscription_enabled" do
345
+ expect(test_instance.subscription_allowed?('dummy_key'))
346
+ .to eq(ActivityNotification.config.subscription_enabled)
347
+ end
348
+
349
+ it "returns false as default" do
350
+ expect(test_instance.subscription_allowed?('dummy_key')).to be_falsey
351
+ end
352
+ end
353
+
354
+ context "configured with a field" do
355
+ it "returns specified value" do
356
+ described_class._notification_subscription_allowed = true
357
+ expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
358
+ end
359
+
360
+ it "returns specified symbol without argument" do
361
+ module AdditionalMethods
362
+ def custom_subscription_allowed?
363
+ true
364
+ end
365
+ end
366
+ test_instance.extend(AdditionalMethods)
367
+ described_class._notification_subscription_allowed = :custom_subscription_allowed?
368
+ expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
369
+ end
370
+
371
+ it "returns specified symbol with key argument" do
372
+ module AdditionalMethods
373
+ def custom_subscription_allowed?(key)
374
+ true
375
+ end
376
+ end
377
+ test_instance.extend(AdditionalMethods)
378
+ described_class._notification_subscription_allowed = :custom_subscription_allowed?
379
+ expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
380
+ end
381
+
382
+ it "returns specified lambda with single target argument" do
383
+ described_class._notification_subscription_allowed = ->(target){ true }
384
+ expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
385
+ end
386
+
387
+ it "returns specified lambda with target and key arguments" do
388
+ described_class._notification_subscription_allowed = ->(target, key){ true }
389
+ expect(test_instance.subscription_allowed?('dummy_key')).to eq(true)
390
+ end
391
+ end
392
+ end
393
+
198
394
  describe "#authenticated_with_devise?" do
199
395
  context "without any configuration" do
200
396
  context "when the current devise resource and called target are defferent class instance" do
@@ -431,8 +627,8 @@ shared_examples_for :target do
431
627
 
432
628
  context "when the target has no unopened notifications" do
433
629
  before do
434
- create(:notification, target: test_instance, opened_at: DateTime.now)
435
- create(:notification, target: test_instance, opened_at: DateTime.now)
630
+ create(:notification, target: test_instance, opened_at: Time.current)
631
+ create(:notification, target: test_instance, opened_at: Time.current)
436
632
  end
437
633
 
438
634
  it "calls unopened_notification_index" do
@@ -485,7 +681,7 @@ shared_examples_for :target do
485
681
  end
486
682
 
487
683
  it "returns unopened notification index (unopened only)" do
488
- notification_3 = create(:notification, target: test_instance, opened_at: DateTime.now)
684
+ notification_3 = create(:notification, target: test_instance, opened_at: Time.current)
489
685
  expect(test_instance.unopened_notification_index.size).to eq(2)
490
686
  expect(test_instance.unopened_notification_index.last).to eq(@notification_1)
491
687
  expect(test_instance.unopened_notification_index.first).to eq(@notification_2)
@@ -503,8 +699,8 @@ shared_examples_for :target do
503
699
 
504
700
  context "when the target has no unopened notifications" do
505
701
  before do
506
- create(:notification, target: test_instance, group_owner: nil, opened_at: DateTime.now)
507
- create(:notification, target: test_instance, group_owner: nil, opened_at: DateTime.now)
702
+ create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
703
+ create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
508
704
  end
509
705
 
510
706
  it "returns empty records" do
@@ -522,8 +718,8 @@ shared_examples_for :target do
522
718
 
523
719
  context "when the target has opened notifications" do
524
720
  before do
525
- @notification_1 = create(:notification, target: test_instance, opened_at: DateTime.now)
526
- @notification_2 = create(:notification, target: test_instance, opened_at: DateTime.now)
721
+ @notification_1 = create(:notification, target: test_instance, opened_at: Time.current)
722
+ @notification_2 = create(:notification, target: test_instance, opened_at: Time.current)
527
723
  end
528
724
 
529
725
  context "without limit" do
@@ -542,7 +738,7 @@ shared_examples_for :target do
542
738
  end
543
739
 
544
740
  it "returns opened notification index (owner only)" do
545
- group_member = create(:notification, target: test_instance, group_owner: @notification_1, opened_at: DateTime.now)
741
+ group_member = create(:notification, target: test_instance, group_owner: @notification_1, opened_at: Time.current)
546
742
  expect(test_instance.opened_notification_index.size).to eq(2)
547
743
  expect(test_instance.opened_notification_index.last).to eq(@notification_1)
548
744
  expect(test_instance.opened_notification_index.first).to eq(@notification_2)
@@ -686,8 +882,8 @@ shared_examples_for :target do
686
882
 
687
883
  context "when the target has no unopened notifications" do
688
884
  before do
689
- create(:notification, target: test_instance, opened_at: DateTime.now)
690
- create(:notification, target: test_instance, opened_at: DateTime.now)
885
+ create(:notification, target: test_instance, opened_at: Time.current)
886
+ create(:notification, target: test_instance, opened_at: Time.current)
691
887
  end
692
888
 
693
889
  it "calls unopened_notification_index_with_attributes" do
@@ -760,8 +956,8 @@ shared_examples_for :target do
760
956
 
761
957
  context "when the target has no unopened notifications" do
762
958
  before do
763
- create(:notification, target: test_instance, opened_at: DateTime.now)
764
- create(:notification, target: test_instance, opened_at: DateTime.now)
959
+ create(:notification, target: test_instance, opened_at: Time.current)
960
+ create(:notification, target: test_instance, opened_at: Time.current)
765
961
  end
766
962
 
767
963
  it "returns empty records" do
@@ -779,8 +975,8 @@ shared_examples_for :target do
779
975
  context "when the target has opened notifications with no group members" do
780
976
  context "with no group members" do
781
977
  before do
782
- create(:notification, target: test_instance, opened_at: DateTime.now)
783
- create(:notification, target: test_instance, opened_at: DateTime.now)
978
+ create(:notification, target: test_instance, opened_at: Time.current)
979
+ create(:notification, target: test_instance, opened_at: Time.current)
784
980
  end
785
981
 
786
982
  it "calls with_target, with_notifiable and with_notifier" do
@@ -801,9 +997,9 @@ shared_examples_for :target do
801
997
 
802
998
  context "with group members" do
803
999
  before do
804
- group_owner = create(:notification, target: test_instance, group_owner: nil, opened_at: DateTime.now)
805
- create(:notification, target: test_instance, group_owner: nil, opened_at: DateTime.now)
806
- group_member = create(:notification, target: test_instance, group_owner: group_owner, opened_at: DateTime.now)
1000
+ group_owner = create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
1001
+ create(:notification, target: test_instance, group_owner: nil, opened_at: Time.current)
1002
+ group_member = create(:notification, target: test_instance, group_owner: group_owner, opened_at: Time.current)
807
1003
  end
808
1004
 
809
1005
  it "calls with_group" do
@@ -884,6 +1080,39 @@ shared_examples_for :target do
884
1080
  end
885
1081
  end
886
1082
 
1083
+ describe "#subscribes_to_notification?" do
1084
+ context "when the subscription is not enabled for the target" do
1085
+ it "returns true" do
1086
+ described_class._notification_subscription_allowed = false
1087
+ expect(test_instance.subscribes_to_notification?('test_key')).to be_truthy
1088
+ end
1089
+ end
1090
+
1091
+ context "when the subscription is enabled for the target" do
1092
+ it "calls Subscriber#_subscribes_to_notification?" do
1093
+ described_class._notification_subscription_allowed = true
1094
+ expect(test_instance).to receive(:_subscribes_to_notification?)
1095
+ test_instance.subscribes_to_notification?('test_key')
1096
+ end
1097
+ end
1098
+ end
1099
+
1100
+ describe "#subscribes_to_notification_email?" do
1101
+ context "when the subscription is not enabled for the target" do
1102
+ it "returns true" do
1103
+ described_class._notification_subscription_allowed = false
1104
+ expect(test_instance.subscribes_to_notification_email?('test_key')).to be_truthy
1105
+ end
1106
+ end
1107
+
1108
+ context "when the subscription is enabled for the target" do
1109
+ it "calls Subscriber#_subscribes_to_notification_email?" do
1110
+ described_class._notification_subscription_allowed = true
1111
+ expect(test_instance).to receive(:_subscribes_to_notification_email?)
1112
+ test_instance.subscribes_to_notification_email?('test_key')
1113
+ end
1114
+ end
1115
+ end
887
1116
  end
888
1117
 
889
1118
  end
@@ -0,0 +1,25 @@
1
+ require 'controllers/dummy_common_controller'
2
+
3
+ describe ActivityNotification::DummyCommonController, type: :controller do
4
+
5
+ describe "#set_index_options" do
6
+ it "raises NotImplementedError" do
7
+ expect { controller.send(:set_index_options) }
8
+ .to raise_error(NotImplementedError, /You have to implement .+#set_index_options/)
9
+ end
10
+ end
11
+
12
+ describe "#load_index" do
13
+ it "raises NotImplementedError" do
14
+ expect { controller.send(:load_index) }
15
+ .to raise_error(NotImplementedError, /You have to implement .+#load_index/)
16
+ end
17
+ end
18
+
19
+ describe "#controller_path" do
20
+ it "raises NotImplementedError" do
21
+ expect { controller.send(:controller_path) }
22
+ .to raise_error(NotImplementedError, /You have to implement .+#controller_path/)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module ActivityNotification
2
+ class DummyCommonController < ActivityNotification.config.parent_controller.constantize
3
+ include CommonController
4
+ end
5
+ end
@@ -240,12 +240,8 @@ shared_examples_for :notification_controller do
240
240
  expect(response.status).to eq(302)
241
241
  end
242
242
 
243
- it "assigns notification index as @notifications" do
244
- expect(assigns(:notifications)).to eq([@notification])
245
- end
246
-
247
243
  it "opens all notifications of the target" do
248
- expect(assigns(:notifications).first.opened?).to be_truthy
244
+ expect(@notification.reload.opened?).to be_truthy
249
245
  end
250
246
 
251
247
  it "redirects to :index" do
@@ -266,7 +262,7 @@ shared_examples_for :notification_controller do
266
262
  end
267
263
 
268
264
  it "opens all notifications of the target" do
269
- expect(assigns(:notifications).first.opened?).to be_truthy
265
+ expect(@notification.reload.opened?).to be_truthy
270
266
  end
271
267
 
272
268
  it "redirects to root_path as request.referer" do