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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +33 -0
- data/.rubocop.yml +1157 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +15 -17
- data/README.md +154 -27
- data/activity_notification.gemspec +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +30 -104
- data/app/controllers/activity_notification/notifications_with_devise_controller.rb +1 -33
- data/app/controllers/activity_notification/subscriptions_controller.rb +184 -0
- data/app/controllers/activity_notification/subscriptions_with_devise_controller.rb +6 -0
- data/app/mailers/activity_notification/mailer.rb +3 -3
- data/app/views/activity_notification/notifications/default/_index.html.erb +3 -0
- data/app/views/activity_notification/notifications/default/index.html.erb +8 -10
- data/app/views/activity_notification/notifications/default/show.html.erb +24 -2
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +52 -0
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +89 -0
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +73 -0
- data/app/views/activity_notification/subscriptions/default/_subscriptions.html.erb +13 -0
- data/app/views/activity_notification/subscriptions/default/create.js.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/destroy.js.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/index.html.erb +197 -0
- data/app/views/activity_notification/subscriptions/default/show.html.erb +177 -0
- data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +8 -0
- data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +6 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +8 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +6 -0
- data/gemfiles/Gemfile.rails-4.2.lock +18 -20
- data/gemfiles/Gemfile.rails-5.0.lock +18 -20
- data/lib/activity_notification.rb +7 -3
- data/lib/activity_notification/apis/notification_api.rb +95 -61
- data/lib/activity_notification/apis/subscription_api.rb +51 -0
- data/lib/activity_notification/common.rb +1 -1
- data/lib/activity_notification/config.rb +65 -17
- data/lib/activity_notification/controllers/common_controller.rb +118 -0
- data/lib/activity_notification/controllers/devise_authentication_controller.rb +41 -0
- data/lib/activity_notification/helpers/view_helpers.rb +131 -3
- data/lib/activity_notification/mailers/helpers.rb +6 -8
- data/lib/activity_notification/models/concerns/notifiable.rb +45 -27
- data/lib/activity_notification/models/concerns/subscriber.rb +149 -0
- data/lib/activity_notification/models/concerns/target.rb +100 -66
- data/lib/activity_notification/models/notification.rb +7 -5
- data/lib/activity_notification/models/subscription.rb +93 -0
- data/lib/activity_notification/rails/routes.rb +148 -33
- data/lib/activity_notification/renderable.rb +3 -4
- data/lib/activity_notification/roles/acts_as_notifiable.rb +14 -1
- data/lib/activity_notification/roles/acts_as_target.rb +11 -8
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/controllers_generator.rb +2 -2
- data/lib/generators/activity_notification/install_generator.rb +0 -1
- data/lib/generators/activity_notification/migration/migration_generator.rb +8 -2
- data/lib/generators/activity_notification/models_generator.rb +53 -0
- data/lib/generators/activity_notification/views_generator.rb +7 -7
- data/lib/generators/templates/activity_notification.rb +17 -3
- data/lib/generators/templates/controllers/notifications_controller.rb +18 -17
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +18 -17
- data/lib/generators/templates/controllers/subscriptions_controller.rb +79 -0
- data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +87 -0
- data/lib/generators/templates/migrations/migration.rb +57 -0
- data/lib/generators/templates/models/README +10 -0
- data/lib/generators/templates/{notification → models}/notification.rb +1 -3
- data/lib/generators/templates/models/subscription.rb +4 -0
- data/spec/concerns/apis/notification_api_spec.rb +48 -11
- data/spec/concerns/apis/subscription_api_spec.rb +167 -0
- data/spec/concerns/models/notifiable_spec.rb +60 -0
- data/spec/concerns/models/subscriber_spec.rb +525 -0
- data/spec/concerns/models/target_spec.rb +271 -42
- data/spec/controllers/common_controller_spec.rb +25 -0
- data/spec/controllers/dummy_common_controller.rb +5 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +2 -6
- data/spec/controllers/subscriptions_controller_shared_examples.rb +735 -0
- data/spec/controllers/subscriptions_controller_spec.rb +12 -0
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +91 -0
- data/spec/factories/dummy/dummy_subscriber.rb +4 -0
- data/spec/factories/subscriptions.rb +8 -0
- data/spec/generators/controllers_generator_spec.rb +25 -2
- data/spec/generators/migration/migration_generator_spec.rb +3 -3
- data/spec/generators/models_generator_spec.rb +96 -0
- data/spec/generators/views_generator_spec.rb +84 -0
- data/spec/helpers/view_helpers_spec.rb +143 -0
- data/spec/mailers/mailer_spec.rb +5 -4
- data/spec/models/dummy/dummy_subscriber_spec.rb +5 -0
- data/spec/models/notification_spec.rb +7 -7
- data/spec/models/subscription_spec.rb +158 -0
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +67 -0
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +75 -0
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +79 -0
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +87 -0
- data/spec/rails_app/app/models/admin.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +4 -0
- data/spec/rails_app/app/models/user.rb +2 -1
- data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +1 -0
- data/spec/rails_app/app/views/articles/index.html.erb +6 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +17 -3
- data/spec/rails_app/config/routes.rb +2 -2
- data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +33 -0
- data/spec/rails_app/db/schema.rb +18 -0
- data/spec/roles/acts_as_notifiable_spec.rb +1 -1
- data/spec/roles/acts_as_target_spec.rb +1 -1
- metadata +70 -11
- data/lib/generators/activity_notification/notification/notification_generator.rb +0 -20
- data/lib/generators/templates/active_record/migration.rb +0 -18
- data/spec/generators/notification/notification_generator_spec.rb +0 -41
- data/spec/rails_app/db/migrate/20160715050420_create_notifications.rb +0 -18
@@ -0,0 +1,57 @@
|
|
1
|
+
# Migration responsible for creating a table with notifications
|
2
|
+
class <%= @migration_name %> < ActiveRecord::Migration
|
3
|
+
# Create tables
|
4
|
+
def change
|
5
|
+
<% if @migration_tables.include?('notifications') %>create_table :notifications do |t|
|
6
|
+
t.belongs_to :target, polymorphic: true, index: true, null: false
|
7
|
+
t.belongs_to :notifiable, polymorphic: true, index: true, null: false
|
8
|
+
t.string :key, null: false
|
9
|
+
t.belongs_to :group, polymorphic: true, index: true
|
10
|
+
t.integer :group_owner_id, index: true
|
11
|
+
t.belongs_to :notifier, polymorphic: true, index: true
|
12
|
+
t.text :parameters
|
13
|
+
t.datetime :opened_at
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end<% else %># create_table :notifications do |t|
|
17
|
+
# t.belongs_to :target, polymorphic: true, index: true, null: false
|
18
|
+
# t.belongs_to :notifiable, polymorphic: true, index: true, null: false
|
19
|
+
# t.string :key, null: false
|
20
|
+
# t.belongs_to :group, polymorphic: true, index: true
|
21
|
+
# t.integer :group_owner_id, index: true
|
22
|
+
# t.belongs_to :notifier, polymorphic: true, index: true
|
23
|
+
# t.text :parameters
|
24
|
+
# t.datetime :opened_at
|
25
|
+
#
|
26
|
+
# t.timestamps
|
27
|
+
# end<% end %>
|
28
|
+
|
29
|
+
<% if @migration_tables.include?('subscriptions') %>create_table :subscriptions do |t|
|
30
|
+
t.belongs_to :target, polymorphic: true, index: true, null: false
|
31
|
+
t.string :key, index: true, null: false
|
32
|
+
t.boolean :subscribing, null: false, default: true
|
33
|
+
t.boolean :subscribing_to_email, null: false, default: true
|
34
|
+
t.datetime :subscribed_at
|
35
|
+
t.datetime :unsubscribed_at
|
36
|
+
t.datetime :subscribed_to_email_at
|
37
|
+
t.datetime :unsubscribed_to_email_at
|
38
|
+
t.text :parameters
|
39
|
+
|
40
|
+
t.timestamps
|
41
|
+
end
|
42
|
+
add_index :subscriptions, [:target_type, :target_id, :key], unique: true<% else %># create_table :subscriptions do |t|
|
43
|
+
# t.belongs_to :target, polymorphic: true, index: true, null: false
|
44
|
+
# t.string :key, index: true, null: false
|
45
|
+
# t.boolean :subscribing, null: false, default: true
|
46
|
+
# t.boolean :subscribing_to_email, null: false, default: true
|
47
|
+
# t.datetime :subscribed_at
|
48
|
+
# t.datetime :unsubscribed_at
|
49
|
+
# t.datetime :subscribed_to_email_at
|
50
|
+
# t.datetime :unsubscribed_to_email_at
|
51
|
+
# t.text :parameters
|
52
|
+
#
|
53
|
+
# t.timestamps
|
54
|
+
# end
|
55
|
+
# add_index :subscriptions, [:target_type, :target_id, :key], unique: true<% end %>
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
Ensure you have configured model name in your initializer activity_notification.rb.
|
6
|
+
For example:
|
7
|
+
|
8
|
+
#TODO
|
9
|
+
|
10
|
+
===============================================================================
|
@@ -118,7 +118,7 @@ shared_examples_for :notification_api do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
describe ".notify_to" do
|
121
|
-
it "returns
|
121
|
+
it "returns created notification" do
|
122
122
|
notification = described_class.notify_to(@user_1, @comment_2)
|
123
123
|
validate_expected_notification(notification, @user_1, @comment_2)
|
124
124
|
end
|
@@ -299,6 +299,29 @@ shared_examples_for :notification_api do
|
|
299
299
|
member_notification = described_class.notify_to(@user_1, @comment_2, key: 'key2', group: @article)
|
300
300
|
expect(member_notification.group_owner).to eq(nil)
|
301
301
|
end
|
302
|
+
|
303
|
+
context "with group_expiry_delay option" do
|
304
|
+
context "within the group expiry period" do
|
305
|
+
it "belongs to single group" do
|
306
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article, group_expiry_delay: 1.day)
|
307
|
+
member_notification_1 = described_class.notify_to(@user_1, @comment_2, group: @article, group_expiry_delay: 1.day)
|
308
|
+
member_notification_2 = described_class.notify_to(@user_1, @comment_2, group: @article, group_expiry_delay: 1.day)
|
309
|
+
expect(member_notification_1.group_owner).to eq(owner_notification)
|
310
|
+
expect(member_notification_2.group_owner).to eq(owner_notification)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context "out of the group expiry period" do
|
315
|
+
it "does not belong to single group" do
|
316
|
+
owner_notification = described_class.notify_to(@user_1, @comment_1, group: @article, group_expiry_delay: 1.second)
|
317
|
+
member_notification_1 = described_class.notify_to(@user_1, @comment_2, group: @article, group_expiry_delay: 1.second)
|
318
|
+
sleep(1)
|
319
|
+
member_notification_2 = described_class.notify_to(@user_1, @comment_2, group: @article, group_expiry_delay: 1.second)
|
320
|
+
expect(member_notification_1.group_owner).to eq(owner_notification)
|
321
|
+
expect(member_notification_2.group_owner).to be_nil
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
302
325
|
end
|
303
326
|
end
|
304
327
|
|
@@ -328,16 +351,16 @@ shared_examples_for :notification_api do
|
|
328
351
|
|
329
352
|
it "opens all notification with current time" do
|
330
353
|
expect(@user_1.notifications.first.opened_at).to be_nil
|
331
|
-
Timecop.freeze(
|
354
|
+
Timecop.freeze(Time.current)
|
332
355
|
described_class.open_all_of(@user_1)
|
333
|
-
expect(@user_1.notifications.first.opened_at.to_i).to eq(
|
356
|
+
expect(@user_1.notifications.first.opened_at.to_i).to eq(Time.current.to_i)
|
334
357
|
Timecop.return
|
335
358
|
end
|
336
359
|
|
337
360
|
context "with opened_at option" do
|
338
361
|
it "opens all notification with specified time" do
|
339
362
|
expect(@user_1.notifications.first.opened_at).to be_nil
|
340
|
-
opened_at =
|
363
|
+
opened_at = Time.current - 1.months
|
341
364
|
described_class.open_all_of(@user_1, opened_at: opened_at)
|
342
365
|
expect(@user_1.notifications.first.opened_at.to_i).to eq(opened_at.to_i)
|
343
366
|
end
|
@@ -507,21 +530,21 @@ shared_examples_for :notification_api do
|
|
507
530
|
context "as default" do
|
508
531
|
it "open notification with current time" do
|
509
532
|
expect(test_instance.opened_at.blank?).to be_truthy
|
510
|
-
Timecop.freeze(
|
533
|
+
Timecop.freeze(Time.current)
|
511
534
|
test_instance.open!
|
512
535
|
expect(test_instance.opened_at.blank?).to be_falsey
|
513
|
-
expect(test_instance.opened_at).to eq(
|
536
|
+
expect(test_instance.opened_at).to eq(Time.current)
|
514
537
|
Timecop.return
|
515
538
|
end
|
516
539
|
|
517
540
|
it "open group member notifications with current time" do
|
518
541
|
group_member = create(test_class_name, group_owner: test_instance)
|
519
542
|
expect(group_member.opened_at.blank?).to be_truthy
|
520
|
-
Timecop.freeze(
|
543
|
+
Timecop.freeze(Time.current)
|
521
544
|
test_instance.open!
|
522
545
|
group_member = group_member.reload
|
523
546
|
expect(group_member.opened_at.blank?).to be_falsey
|
524
|
-
expect(group_member.opened_at.to_i).to eq(
|
547
|
+
expect(group_member.opened_at.to_i).to eq(Time.current.to_i)
|
525
548
|
Timecop.return
|
526
549
|
end
|
527
550
|
end
|
@@ -529,7 +552,7 @@ shared_examples_for :notification_api do
|
|
529
552
|
context "with opened_at option" do
|
530
553
|
it "open notification with specified time" do
|
531
554
|
expect(test_instance.opened_at.blank?).to be_truthy
|
532
|
-
opened_at =
|
555
|
+
opened_at = Time.current - 1.months
|
533
556
|
test_instance.open!(opened_at: opened_at)
|
534
557
|
expect(test_instance.opened_at.blank?).to be_falsey
|
535
558
|
expect(test_instance.opened_at).to eq(opened_at)
|
@@ -538,7 +561,7 @@ shared_examples_for :notification_api do
|
|
538
561
|
it "open group member notifications with specified time" do
|
539
562
|
group_member = create(test_class_name, group_owner: test_instance)
|
540
563
|
expect(group_member.opened_at.blank?).to be_truthy
|
541
|
-
opened_at =
|
564
|
+
opened_at = Time.current - 1.months
|
542
565
|
test_instance.open!(opened_at: opened_at)
|
543
566
|
group_member = group_member.reload
|
544
567
|
expect(group_member.opened_at.blank?).to be_falsey
|
@@ -550,7 +573,7 @@ shared_examples_for :notification_api do
|
|
550
573
|
it "does not open group member notifications" do
|
551
574
|
group_member = create(test_class_name, group_owner: test_instance)
|
552
575
|
expect(group_member.opened_at.blank?).to be_truthy
|
553
|
-
opened_at =
|
576
|
+
opened_at = Time.current - 1.months
|
554
577
|
test_instance.open!(with_members: false)
|
555
578
|
group_member = group_member.reload
|
556
579
|
expect(group_member.opened_at.blank?).to be_truthy
|
@@ -1087,6 +1110,20 @@ shared_examples_for :notification_api do
|
|
1087
1110
|
.to eq(test_instance.notifiable.notifiable_path(test_instance.target_type, test_instance.key))
|
1088
1111
|
end
|
1089
1112
|
end
|
1113
|
+
|
1114
|
+
describe "#subscribed?" do
|
1115
|
+
it "returns target.subscribes_to_notification?" do
|
1116
|
+
expect(test_instance.subscribed?)
|
1117
|
+
.to eq(test_instance.target.subscribes_to_notification?(test_instance.key))
|
1118
|
+
end
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
describe "#email_subscribed?" do
|
1122
|
+
it "returns target.subscribes_to_notification_email?" do
|
1123
|
+
expect(test_instance.subscribed?)
|
1124
|
+
.to eq(test_instance.target.subscribes_to_notification_email?(test_instance.key))
|
1125
|
+
end
|
1126
|
+
end
|
1090
1127
|
end
|
1091
1128
|
|
1092
1129
|
describe "as protected instance methods" do
|
@@ -0,0 +1,167 @@
|
|
1
|
+
shared_examples_for :subscription_api do
|
2
|
+
include ActiveJob::TestHelper
|
3
|
+
let(:test_class_name) { described_class.to_s.underscore.split('/').last.to_sym }
|
4
|
+
let(:test_instance) { create(test_class_name) }
|
5
|
+
|
6
|
+
describe "as public instance methods" do
|
7
|
+
describe "#subscribe" do
|
8
|
+
before do
|
9
|
+
test_instance.unsubscribe
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns if successfully updated subscription instance" do
|
13
|
+
expect(test_instance.subscribe).to be_truthy
|
14
|
+
end
|
15
|
+
|
16
|
+
context "as default" do
|
17
|
+
it "subscribe with current time" do
|
18
|
+
expect(test_instance.subscribing).to eq(false)
|
19
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
20
|
+
Timecop.freeze(Time.current)
|
21
|
+
test_instance.subscribe
|
22
|
+
expect(test_instance.subscribing).to eq(true)
|
23
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
24
|
+
expect(test_instance.subscribed_at).to eq(Time.current)
|
25
|
+
expect(test_instance.subscribed_to_email_at).to eq(Time.current)
|
26
|
+
Timecop.return
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with subscribed_at option" do
|
31
|
+
it "subscribe with specified time" do
|
32
|
+
expect(test_instance.subscribing).to eq(false)
|
33
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
34
|
+
subscribed_at = Time.current - 1.months
|
35
|
+
test_instance.subscribe(subscribed_at: subscribed_at)
|
36
|
+
expect(test_instance.subscribing).to eq(true)
|
37
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
38
|
+
expect(test_instance.subscribed_at).to eq(subscribed_at)
|
39
|
+
expect(test_instance.subscribed_to_email_at).to eq(subscribed_at)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with false as with_email_subscription" do
|
44
|
+
it "does not subscribe to email" do
|
45
|
+
expect(test_instance.subscribing).to eq(false)
|
46
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
47
|
+
test_instance.subscribe(with_email_subscription: false)
|
48
|
+
expect(test_instance.subscribing).to eq(true)
|
49
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#unsubscribe" do
|
55
|
+
it "returns if successfully updated subscription instance" do
|
56
|
+
expect(test_instance.subscribe).to be_truthy
|
57
|
+
end
|
58
|
+
|
59
|
+
context "as default" do
|
60
|
+
it "unsubscribe with current time" do
|
61
|
+
expect(test_instance.subscribing).to eq(true)
|
62
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
63
|
+
Timecop.freeze(Time.current)
|
64
|
+
test_instance.unsubscribe
|
65
|
+
expect(test_instance.subscribing).to eq(false)
|
66
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
67
|
+
expect(test_instance.unsubscribed_at).to eq(Time.current)
|
68
|
+
expect(test_instance.unsubscribed_to_email_at).to eq(Time.current)
|
69
|
+
Timecop.return
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with unsubscribed_at option" do
|
74
|
+
it "unsubscribe with specified time" do
|
75
|
+
expect(test_instance.subscribing).to eq(true)
|
76
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
77
|
+
unsubscribed_at = Time.current - 1.months
|
78
|
+
test_instance.unsubscribe(unsubscribed_at: unsubscribed_at)
|
79
|
+
expect(test_instance.subscribing).to eq(false)
|
80
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
81
|
+
expect(test_instance.unsubscribed_at).to eq(unsubscribed_at)
|
82
|
+
expect(test_instance.unsubscribed_to_email_at).to eq(unsubscribed_at)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#subscribe_to_email" do
|
88
|
+
before do
|
89
|
+
test_instance.unsubscribe_to_email
|
90
|
+
end
|
91
|
+
|
92
|
+
context "for subscribing instance" do
|
93
|
+
it "returns true as successfully updated subscription instance" do
|
94
|
+
expect(test_instance.subscribing).to eq(true)
|
95
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
96
|
+
expect(test_instance.subscribe_to_email).to be_truthy
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "for not subscribing instance" do
|
101
|
+
it "returns false as successfully updated subscription instance" do
|
102
|
+
test_instance.unsubscribe
|
103
|
+
expect(test_instance.subscribing).to eq(false)
|
104
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
105
|
+
expect(test_instance.subscribe_to_email).to be_falsey
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "as default" do
|
110
|
+
it "subscribe_to_email with current time" do
|
111
|
+
expect(test_instance.subscribing).to eq(true)
|
112
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
113
|
+
Timecop.freeze(Time.current)
|
114
|
+
test_instance.subscribe_to_email
|
115
|
+
expect(test_instance.subscribing).to eq(true)
|
116
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
117
|
+
expect(test_instance.subscribed_to_email_at).to eq(Time.current)
|
118
|
+
Timecop.return
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with subscribed_to_email_at option" do
|
123
|
+
it "subscribe with specified time" do
|
124
|
+
expect(test_instance.subscribing).to eq(true)
|
125
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
126
|
+
subscribed_to_email_at = Time.current - 1.months
|
127
|
+
test_instance.subscribe_to_email(subscribed_to_email_at: subscribed_to_email_at)
|
128
|
+
expect(test_instance.subscribing).to eq(true)
|
129
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
130
|
+
expect(test_instance.subscribed_to_email_at).to eq(subscribed_to_email_at)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#unsubscribe_to_email" do
|
136
|
+
it "returns if successfully updated subscription instance" do
|
137
|
+
expect(test_instance.unsubscribe_to_email).to be_truthy
|
138
|
+
end
|
139
|
+
|
140
|
+
context "as default" do
|
141
|
+
it "unsubscribe_to_email with current time" do
|
142
|
+
expect(test_instance.subscribing).to eq(true)
|
143
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
144
|
+
Timecop.freeze(Time.current)
|
145
|
+
test_instance.unsubscribe_to_email
|
146
|
+
expect(test_instance.subscribing).to eq(true)
|
147
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
148
|
+
expect(test_instance.unsubscribed_to_email_at).to eq(Time.current)
|
149
|
+
Timecop.return
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "with unsubscribed_to_email_at option" do
|
154
|
+
it "unsubscribe with specified time" do
|
155
|
+
expect(test_instance.subscribing).to eq(true)
|
156
|
+
expect(test_instance.subscribing_to_email).to eq(true)
|
157
|
+
unsubscribed_to_email_at = Time.current - 1.months
|
158
|
+
test_instance.unsubscribe_to_email(unsubscribed_to_email_at: unsubscribed_to_email_at)
|
159
|
+
expect(test_instance.subscribing).to eq(true)
|
160
|
+
expect(test_instance.subscribing_to_email).to eq(false)
|
161
|
+
expect(test_instance.unsubscribed_to_email_at).to eq(unsubscribed_to_email_at)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
@@ -17,6 +17,7 @@ shared_examples_for :notifiable do
|
|
17
17
|
described_class.set_notifiable_class_defaults
|
18
18
|
expect(described_class._notification_targets).to eq({})
|
19
19
|
expect(described_class._notification_group).to eq({})
|
20
|
+
expect(described_class._notification_group_expiry_delay).to eq({})
|
20
21
|
expect(described_class._notifier).to eq({})
|
21
22
|
expect(described_class._notification_parameters).to eq({})
|
22
23
|
expect(described_class._notification_email_allowed).to eq({})
|
@@ -155,6 +156,65 @@ shared_examples_for :notifiable do
|
|
155
156
|
end
|
156
157
|
end
|
157
158
|
|
159
|
+
describe "#notification_group_expiry_delay" do
|
160
|
+
context "without any configuration" do
|
161
|
+
it "returns nil" do
|
162
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to be_nil
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "configured with overriden method" do
|
167
|
+
it "returns specified value" do
|
168
|
+
module AdditionalMethods
|
169
|
+
def notification_group_expiry_delay_for_users(key)
|
170
|
+
User.all.first
|
171
|
+
end
|
172
|
+
end
|
173
|
+
test_instance.extend(AdditionalMethods)
|
174
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to eq(User.all.first)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "configured with a field" do
|
179
|
+
it "returns specified value" do
|
180
|
+
described_class._notification_group_expiry_delay[:users] = User.all.first
|
181
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to eq(User.all.first)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "returns specified symbol without argumentss" do
|
185
|
+
module AdditionalMethods
|
186
|
+
def custom_notification_group_expiry_delay
|
187
|
+
User.all.first
|
188
|
+
end
|
189
|
+
end
|
190
|
+
test_instance.extend(AdditionalMethods)
|
191
|
+
described_class._notification_group_expiry_delay[:users] = :custom_notification_group_expiry_delay
|
192
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to eq(User.all.first)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "returns specified symbol with key argument" do
|
196
|
+
module AdditionalMethods
|
197
|
+
def custom_notification_group_expiry_delay(key)
|
198
|
+
User.all.first
|
199
|
+
end
|
200
|
+
end
|
201
|
+
test_instance.extend(AdditionalMethods)
|
202
|
+
described_class._notification_group_expiry_delay[:users] = :custom_notification_group_expiry_delay
|
203
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to eq(User.all.first)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "returns specified lambda with single notifiable argument" do
|
207
|
+
described_class._notification_group_expiry_delay[:users] = ->(notifiable){ User.all.first }
|
208
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to eq(User.all.first)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "returns specified lambda with notifiable and key arguments" do
|
212
|
+
described_class._notification_group_expiry_delay[:users] = ->(notifiable, key){ User.all.first }
|
213
|
+
expect(test_instance.notification_group_expiry_delay(User, 'dummy_key')).to eq(User.all.first)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
158
218
|
describe "#notification_parameters" do
|
159
219
|
context "without any configuration" do
|
160
220
|
it "returns blank hash" do
|