activity_notification 0.0.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +74 -58
- data/README.md +53 -26
- data/activity_notification.gemspec +2 -0
- data/app/controllers/activity_notification/notifications_controller.rb +4 -4
- data/app/mailers/activity_notification/mailer.rb +9 -3
- data/app/views/activity_notification/mailer/default/default.html.erb +9 -4
- data/app/views/activity_notification/mailer/default/default.text.erb +10 -0
- data/app/views/activity_notification/notifications/default/_default.html.erb +173 -34
- data/app/views/activity_notification/notifications/default/_index.html.erb +119 -11
- data/app/views/activity_notification/notifications/default/destroy.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/index.html.erb +25 -14
- data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/show.html.erb +1 -1
- data/gemfiles/Gemfile.rails-4.2 +0 -2
- data/gemfiles/Gemfile.rails-4.2.lock +3 -3
- data/gemfiles/Gemfile.rails-5.0 +1 -3
- data/lib/activity_notification.rb +10 -9
- data/lib/activity_notification/apis/notification_api.rb +108 -14
- data/lib/activity_notification/common.rb +11 -2
- data/lib/activity_notification/config.rb +13 -13
- data/lib/activity_notification/helpers/view_helpers.rb +26 -4
- data/lib/activity_notification/mailers/helpers.rb +8 -4
- data/lib/activity_notification/models.rb +4 -0
- data/lib/activity_notification/models/concerns/group.rb +32 -0
- data/lib/activity_notification/models/concerns/notifiable.rb +60 -32
- data/lib/activity_notification/models/concerns/notifier.rb +17 -1
- data/lib/activity_notification/models/concerns/target.rb +114 -55
- data/lib/activity_notification/models/notification.rb +26 -25
- data/lib/activity_notification/rails.rb +1 -0
- data/lib/activity_notification/renderable.rb +8 -3
- data/lib/activity_notification/roles/acts_as_common.rb +28 -0
- data/lib/activity_notification/roles/acts_as_group.rb +38 -0
- data/lib/activity_notification/roles/acts_as_notifiable.rb +56 -22
- data/lib/activity_notification/roles/acts_as_notifier.rb +25 -2
- data/lib/activity_notification/roles/acts_as_target.rb +27 -9
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +1 -1
- data/spec/concerns/apis/notification_api_spec.rb +361 -2
- data/spec/concerns/common_spec.rb +36 -0
- data/spec/concerns/models/group_spec.rb +61 -0
- data/spec/concerns/models/notifiable_spec.rb +37 -0
- data/spec/concerns/models/notifier_spec.rb +48 -0
- data/spec/concerns/models/target_spec.rb +81 -31
- data/spec/factories/dummy/dummy_group.rb +4 -0
- data/spec/helpers/view_helpers_spec.rb +13 -0
- data/spec/mailers/mailer_spec.rb +8 -1
- data/spec/models/dummy/dummy_group_spec.rb +6 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_app/app/assets/stylesheets/reset.css +85 -0
- data/spec/rails_app/app/assets/stylesheets/style.css +244 -0
- data/spec/rails_app/app/controllers/articles_controller.rb +1 -1
- data/spec/rails_app/app/models/admin.rb +2 -1
- data/spec/rails_app/app/models/article.rb +9 -2
- data/spec/rails_app/app/models/comment.rb +8 -2
- data/spec/rails_app/app/models/dummy/dummy_group.rb +4 -0
- data/spec/rails_app/app/models/user.rb +8 -3
- data/spec/rails_app/app/views/articles/_form.html.erb +14 -10
- data/spec/rails_app/app/views/articles/edit.html.erb +8 -6
- data/spec/rails_app/app/views/articles/index.html.erb +59 -67
- data/spec/rails_app/app/views/articles/new.html.erb +7 -5
- data/spec/rails_app/app/views/articles/show.html.erb +47 -36
- data/spec/rails_app/app/views/layouts/_header.html.erb +36 -9
- data/spec/rails_app/app/views/layouts/application.html.erb +8 -6
- data/spec/rails_app/config/environments/development.rb +9 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +1 -1
- data/spec/rails_app/db/schema.rb +14 -20
- data/spec/rails_app/db/seeds.rb +5 -5
- data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +13 -0
- data/spec/roles/acts_as_group_spec.rb +32 -0
- data/spec/roles/acts_as_notifiable_spec.rb +1 -1
- data/spec/roles/acts_as_notifier_spec.rb +15 -0
- data/spec/roles/acts_as_target_spec.rb +1 -1
- metadata +52 -2
@@ -11,6 +11,7 @@ module ActivityNotification
|
|
11
11
|
# * Email address to send notification email.
|
12
12
|
# This is a necessary option when you enables email notification.
|
13
13
|
# @example Simply use :email field
|
14
|
+
# # app/models/user.rb
|
14
15
|
# class User < ActiveRecord::Base
|
15
16
|
# validates :email, presence: true
|
16
17
|
# acts_as_target email: :email
|
@@ -23,10 +24,12 @@ module ActivityNotification
|
|
23
24
|
# To use notification email, email_allowed option must return true (not nil) in both of notifiable and target model.
|
24
25
|
# This can be also configured default option in initializer.
|
25
26
|
# @example Always enable email notification for this target
|
27
|
+
# # app/models/user.rb
|
26
28
|
# class User < ActiveRecord::Base
|
27
29
|
# acts_as_target email: :email, email_allowed: true
|
28
30
|
# end
|
29
31
|
# @example Use confirmed_at of devise field to decide whether activity_notification sends notification email to this user
|
32
|
+
# # app/models/user.rb
|
30
33
|
# class User < ActiveRecord::Base
|
31
34
|
# acts_as_target email: :email, email_allowed: :confirmed_at
|
32
35
|
# end
|
@@ -65,26 +68,41 @@ module ActivityNotification
|
|
65
68
|
# devise_resource: :user
|
66
69
|
# end
|
67
70
|
#
|
68
|
-
#
|
71
|
+
# * :printable_name or :printable_notification_target_name
|
72
|
+
# * Printable notification target name.
|
73
|
+
# This parameter is a optional since `ActivityNotification::Common.printable_name` is used as default value.
|
74
|
+
# :printable_name is the same option as :printable_notification_target_name
|
75
|
+
# @example Define printable name with user name of name field
|
76
|
+
# # app/models/user.rb
|
77
|
+
# class User < ActiveRecord::Base
|
78
|
+
# acts_as_target printable_name: :name
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# @example Define printable name with associated user name
|
82
|
+
# # app/models/admin.rb
|
83
|
+
# class Admin < ActiveRecord::Base
|
84
|
+
# acts_as_target printable_notification_target_name: ->(admin) { "admin (#{admin.user.name})" }
|
85
|
+
# end
|
86
|
+
#
|
69
87
|
# @param [Hash] options Options for notifiable model configuration
|
70
|
-
# @option options [Symbol, Proc,
|
71
|
-
# @option options [Symbol, Proc,
|
88
|
+
# @option options [Symbol, Proc, String] :email (nil) Email address to send notification email
|
89
|
+
# @option options [Symbol, Proc, Boolean] :email_allowed (ActivityNotification.config.email_enabled) Whether activity_notification sends notification email to this target
|
72
90
|
# @option options [Symbol, Proc, Object] :devise_resource (nil) Integrated resource with devise authentication
|
91
|
+
# @option options [Symbol, Proc, String] :printable_name (ActivityNotification::Common.printable_name) Printable notification target name
|
73
92
|
# @return [Hash] Configured parameters as target model
|
74
93
|
def acts_as_target(options = {})
|
75
94
|
include Target
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}.to_h.delete_if { |k, v| k.nil? }
|
95
|
+
|
96
|
+
options[:printable_notification_target_name] ||= options.delete(:printable_name)
|
97
|
+
set_acts_as_parameters([:email, :email_allowed, :devise_resource], options, "notification_")
|
98
|
+
.merge set_acts_as_parameters([:printable_notification_target_name], options)
|
81
99
|
end
|
82
100
|
alias_method :acts_as_notification_target, :acts_as_target
|
83
101
|
|
84
102
|
# Returns array of available target options in acts_as_target.
|
85
103
|
# @return [Array<Symbol>] Array of available target options
|
86
104
|
def available_target_options
|
87
|
-
[:email, :email_allowed, :devise_resource].freeze
|
105
|
+
[:email, :email_allowed, :devise_resource, :printable_notification_target_name, :printable_name].freeze
|
88
106
|
end
|
89
107
|
end
|
90
108
|
end
|
@@ -453,7 +453,7 @@ shared_examples_for :notification_api do
|
|
453
453
|
context "with send_later false" do
|
454
454
|
it "sends notification email now" do
|
455
455
|
expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
456
|
-
test_instance.send_notification_email false
|
456
|
+
test_instance.send_notification_email send_later: false
|
457
457
|
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
458
458
|
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(test_instance.target.email)
|
459
459
|
end
|
@@ -615,11 +615,97 @@ shared_examples_for :notification_api do
|
|
615
615
|
end
|
616
616
|
end
|
617
617
|
|
618
|
-
|
618
|
+
# Returns if group member notifier except group owner notifier exists.
|
619
|
+
# It always returns false if group owner notifier is blank.
|
620
|
+
# It counts only the member notifier of the same type with group owner notifier.
|
621
|
+
describe "#group_member_notifier_exists?" do
|
622
|
+
context "with notifier" do
|
623
|
+
before do
|
624
|
+
test_instance.update(notifier: create(:user))
|
625
|
+
end
|
626
|
+
|
627
|
+
context "when the notification is group owner and has no group members" do
|
628
|
+
it "returns false" do
|
629
|
+
expect(test_instance.group_member_notifier_exists?).to be_falsey
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
context "when the notification is group owner and has group members with the same notifier with the owner's" do
|
634
|
+
it "returns false" do
|
635
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
636
|
+
expect(test_instance.group_member_notifier_exists?).to be_falsey
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
context "when the notification is group owner and has group members with different notifier from the owner's" do
|
641
|
+
it "returns true" do
|
642
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
643
|
+
expect(test_instance.group_member_notifier_exists?).to be_truthy
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
context "when the notification belongs to group and has group members with the same notifier with the owner's" do
|
648
|
+
it "returns false" do
|
649
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
650
|
+
expect(group_member.group_member_notifier_exists?).to be_falsey
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
654
|
+
context "when the notification belongs to group and has group members with different notifier from the owner's" do
|
655
|
+
it "returns true" do
|
656
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
657
|
+
expect(group_member.group_member_notifier_exists?).to be_truthy
|
658
|
+
end
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
context "without notifier" do
|
663
|
+
before do
|
664
|
+
test_instance.update(notifier: nil)
|
665
|
+
end
|
666
|
+
|
667
|
+
context "when the notification is group owner and has no group members" do
|
668
|
+
it "returns false" do
|
669
|
+
expect(test_instance.group_member_notifier_exists?).to be_falsey
|
670
|
+
end
|
671
|
+
end
|
672
|
+
|
673
|
+
context "when the notification is group owner and has group members without notifier" do
|
674
|
+
it "returns false" do
|
675
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: nil)
|
676
|
+
expect(test_instance.group_member_notifier_exists?).to be_falsey
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
context "when the notification is group owner and has group members with notifier" do
|
681
|
+
it "returns false" do
|
682
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
683
|
+
expect(test_instance.group_member_notifier_exists?).to be_falsey
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
context "when the notification belongs to group and has group members without notifier" do
|
688
|
+
it "returns false" do
|
689
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: nil)
|
690
|
+
expect(group_member.group_member_notifier_exists?).to be_falsey
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
694
|
+
context "when the notification belongs to group and has group members with notifier" do
|
695
|
+
it "returns false" do
|
696
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
697
|
+
expect(group_member.group_member_notifier_exists?).to be_falsey
|
698
|
+
end
|
699
|
+
end
|
700
|
+
end
|
701
|
+
end
|
702
|
+
|
703
|
+
describe "#group_member_count (with #group_notification_count)" do
|
619
704
|
context "for unopened notification" do
|
620
705
|
context "when the notification is group owner and has no group members" do
|
621
706
|
it "returns 0" do
|
622
707
|
expect(test_instance.group_member_count).to eq(0)
|
708
|
+
expect(test_instance.group_notification_count).to eq(1)
|
623
709
|
end
|
624
710
|
end
|
625
711
|
|
@@ -628,6 +714,7 @@ shared_examples_for :notification_api do
|
|
628
714
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
629
715
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
630
716
|
expect(test_instance.group_member_count).to eq(2)
|
717
|
+
expect(test_instance.group_notification_count).to eq(3)
|
631
718
|
end
|
632
719
|
end
|
633
720
|
|
@@ -636,6 +723,7 @@ shared_examples_for :notification_api do
|
|
636
723
|
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
637
724
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
638
725
|
expect(group_member.group_member_count).to eq(2)
|
726
|
+
expect(group_member.group_notification_count).to eq(3)
|
639
727
|
end
|
640
728
|
end
|
641
729
|
end
|
@@ -645,6 +733,7 @@ shared_examples_for :notification_api do
|
|
645
733
|
it "returns 0" do
|
646
734
|
test_instance.open!
|
647
735
|
expect(test_instance.group_member_count).to eq(0)
|
736
|
+
expect(test_instance.group_notification_count).to eq(1)
|
648
737
|
end
|
649
738
|
end
|
650
739
|
|
@@ -655,6 +744,7 @@ shared_examples_for :notification_api do
|
|
655
744
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
656
745
|
test_instance.open!
|
657
746
|
expect(test_instance.group_member_count).to eq(2)
|
747
|
+
expect(test_instance.group_notification_count).to eq(3)
|
658
748
|
end
|
659
749
|
end
|
660
750
|
|
@@ -664,6 +754,7 @@ shared_examples_for :notification_api do
|
|
664
754
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
665
755
|
test_instance.open!
|
666
756
|
expect(group_member.group_member_count).to eq(2)
|
757
|
+
expect(group_member.group_notification_count).to eq(3)
|
667
758
|
end
|
668
759
|
end
|
669
760
|
end
|
@@ -675,6 +766,7 @@ shared_examples_for :notification_api do
|
|
675
766
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
676
767
|
test_instance.open!
|
677
768
|
expect(test_instance.group_member_count(0)).to eq(0)
|
769
|
+
expect(test_instance.group_notification_count(0)).to eq(1)
|
678
770
|
end
|
679
771
|
end
|
680
772
|
|
@@ -684,6 +776,259 @@ shared_examples_for :notification_api do
|
|
684
776
|
create(test_class_name, target: test_instance.target, group_owner: test_instance)
|
685
777
|
test_instance.open!
|
686
778
|
expect(group_member.group_member_count(0)).to eq(0)
|
779
|
+
expect(group_member.group_notification_count(0)).to eq(1)
|
780
|
+
end
|
781
|
+
end
|
782
|
+
end
|
783
|
+
end
|
784
|
+
end
|
785
|
+
|
786
|
+
# Returns count of group member notifiers of the notification not including group owner notifier.
|
787
|
+
# It always returns 0 if group owner notifier is blank.
|
788
|
+
# It counts only the member notifier of the same type with group owner notifier.
|
789
|
+
describe "#group_member_notifier_count (with #group_notifier_count)" do
|
790
|
+
context "for unopened notification" do
|
791
|
+
context "with notifier" do
|
792
|
+
before do
|
793
|
+
test_instance.update(notifier: create(:user))
|
794
|
+
end
|
795
|
+
|
796
|
+
context "when the notification is group owner and has no group members" do
|
797
|
+
it "returns 0" do
|
798
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
799
|
+
expect(test_instance.group_notifier_count).to eq(1)
|
800
|
+
end
|
801
|
+
end
|
802
|
+
|
803
|
+
context "when the notification is group owner and has group members with the same notifier with the owner's" do
|
804
|
+
it "returns 0" do
|
805
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
806
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
807
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
808
|
+
expect(test_instance.group_notifier_count).to eq(1)
|
809
|
+
end
|
810
|
+
end
|
811
|
+
|
812
|
+
context "when the notification is group owner and has group members with different notifier from the owner's" do
|
813
|
+
it "returns member notifier count" do
|
814
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
815
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
816
|
+
expect(test_instance.group_member_notifier_count).to eq(2)
|
817
|
+
expect(test_instance.group_notifier_count).to eq(3)
|
818
|
+
end
|
819
|
+
|
820
|
+
it "returns member notifier count with selecting distinct notifier" do
|
821
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
822
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: group_member.notifier)
|
823
|
+
expect(test_instance.group_member_notifier_count).to eq(1)
|
824
|
+
expect(test_instance.group_notifier_count).to eq(2)
|
825
|
+
end
|
826
|
+
end
|
827
|
+
|
828
|
+
context "when the notification belongs to group and has group members with the same notifier with the owner's" do
|
829
|
+
it "returns 0" do
|
830
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
831
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
832
|
+
expect(group_member.group_member_notifier_count).to eq(0)
|
833
|
+
expect(group_member.group_notifier_count).to eq(1)
|
834
|
+
end
|
835
|
+
end
|
836
|
+
|
837
|
+
context "when the notification belongs to group and has group members with different notifier from the owner's" do
|
838
|
+
it "returns member notifier count" do
|
839
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
840
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
841
|
+
expect(group_member.group_member_notifier_count).to eq(2)
|
842
|
+
expect(group_member.group_notifier_count).to eq(3)
|
843
|
+
end
|
844
|
+
|
845
|
+
it "returns member notifier count with selecting distinct notifier" do
|
846
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
847
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: group_member.notifier)
|
848
|
+
expect(group_member.group_member_notifier_count).to eq(1)
|
849
|
+
expect(group_member.group_notifier_count).to eq(2)
|
850
|
+
end
|
851
|
+
end
|
852
|
+
end
|
853
|
+
|
854
|
+
context "without notifier" do
|
855
|
+
before do
|
856
|
+
test_instance.update(notifier: nil)
|
857
|
+
end
|
858
|
+
|
859
|
+
context "when the notification is group owner and has no group members" do
|
860
|
+
it "returns 0" do
|
861
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
862
|
+
expect(test_instance.group_notifier_count).to eq(0)
|
863
|
+
end
|
864
|
+
end
|
865
|
+
|
866
|
+
context "when the notification is group owner and has group members with the same notifier with the owner's" do
|
867
|
+
it "returns 0" do
|
868
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
869
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
870
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
871
|
+
expect(test_instance.group_notifier_count).to eq(0)
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
context "when the notification is group owner and has group members with different notifier from the owner's" do
|
876
|
+
it "returns 0" do
|
877
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
878
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
879
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
880
|
+
expect(test_instance.group_notifier_count).to eq(0)
|
881
|
+
end
|
882
|
+
end
|
883
|
+
|
884
|
+
context "when the notification belongs to group and has group members with the same notifier with the owner's" do
|
885
|
+
it "returns 0" do
|
886
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
887
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
888
|
+
expect(group_member.group_member_notifier_count).to eq(0)
|
889
|
+
expect(group_member.group_notifier_count).to eq(0)
|
890
|
+
end
|
891
|
+
end
|
892
|
+
|
893
|
+
context "when the notification belongs to group and has group members with different notifier from the owner's" do
|
894
|
+
it "returns 0" do
|
895
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
896
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
897
|
+
expect(group_member.group_member_notifier_count).to eq(0)
|
898
|
+
expect(group_member.group_notifier_count).to eq(0)
|
899
|
+
end
|
900
|
+
end
|
901
|
+
end
|
902
|
+
end
|
903
|
+
|
904
|
+
context "for opened notification" do
|
905
|
+
context "as default" do
|
906
|
+
context "with notifier" do
|
907
|
+
before do
|
908
|
+
test_instance.update(notifier: create(:user))
|
909
|
+
end
|
910
|
+
|
911
|
+
context "when the notification is group owner and has group members with the same notifier with the owner's" do
|
912
|
+
it "returns 0" do
|
913
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
914
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
915
|
+
test_instance.open!
|
916
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
920
|
+
context "when the notification is group owner and has group members with different notifier from the owner's" do
|
921
|
+
it "returns member notifier count" do
|
922
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
923
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
924
|
+
test_instance.open!
|
925
|
+
expect(test_instance.group_member_notifier_count).to eq(2)
|
926
|
+
end
|
927
|
+
|
928
|
+
it "returns member notifier count with selecting distinct notifier" do
|
929
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
930
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: group_member.notifier)
|
931
|
+
test_instance.open!
|
932
|
+
expect(test_instance.group_member_notifier_count).to eq(1)
|
933
|
+
end
|
934
|
+
end
|
935
|
+
|
936
|
+
context "when the notification belongs to group and has group members with the same notifier with the owner's" do
|
937
|
+
it "returns 0" do
|
938
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
939
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
940
|
+
test_instance.open!
|
941
|
+
expect(group_member.group_member_notifier_count).to eq(0)
|
942
|
+
end
|
943
|
+
end
|
944
|
+
|
945
|
+
context "when the notification belongs to group and has group members with different notifier from the owner's" do
|
946
|
+
it "returns member notifier count" do
|
947
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
948
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
949
|
+
test_instance.open!
|
950
|
+
expect(group_member.group_member_notifier_count).to eq(2)
|
951
|
+
end
|
952
|
+
|
953
|
+
it "returns member notifier count with selecting distinct notifier" do
|
954
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
955
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: group_member.notifier)
|
956
|
+
test_instance.open!
|
957
|
+
expect(group_member.group_member_notifier_count).to eq(1)
|
958
|
+
end
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
context "without notifier" do
|
963
|
+
before do
|
964
|
+
test_instance.update(notifier: nil)
|
965
|
+
end
|
966
|
+
|
967
|
+
context "when the notification is group owner and has no group members" do
|
968
|
+
it "returns 0" do
|
969
|
+
test_instance.open!
|
970
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
971
|
+
end
|
972
|
+
end
|
973
|
+
|
974
|
+
context "when the notification is group owner and has group members with the same notifier with the owner's" do
|
975
|
+
it "returns 0" do
|
976
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
977
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
978
|
+
test_instance.open!
|
979
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
context "when the notification is group owner and has group members with different notifier from the owner's" do
|
984
|
+
it "returns 0" do
|
985
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
986
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
987
|
+
test_instance.open!
|
988
|
+
expect(test_instance.group_member_notifier_count).to eq(0)
|
989
|
+
end
|
990
|
+
end
|
991
|
+
|
992
|
+
context "when the notification belongs to group and has group members with the same notifier with the owner's" do
|
993
|
+
it "returns 0" do
|
994
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
995
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: test_instance.notifier)
|
996
|
+
test_instance.open!
|
997
|
+
expect(group_member.group_member_notifier_count).to eq(0)
|
998
|
+
end
|
999
|
+
end
|
1000
|
+
|
1001
|
+
context "when the notification belongs to group and has group members with different notifier from the owner's" do
|
1002
|
+
it "returns 0" do
|
1003
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
1004
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
1005
|
+
test_instance.open!
|
1006
|
+
expect(group_member.group_member_notifier_count).to eq(0)
|
1007
|
+
end
|
1008
|
+
end
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
context "with limit" do
|
1013
|
+
before do
|
1014
|
+
test_instance.update(notifier: create(:user))
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
context "when the notification is group owner and has group members with different notifier from the owner's" do
|
1018
|
+
it "returns member notifier count by limit" do
|
1019
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
1020
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
1021
|
+
test_instance.open!
|
1022
|
+
expect(test_instance.group_member_notifier_count(0)).to eq(0)
|
1023
|
+
end
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
context "when the notification belongs to group and has group members with different notifier from the owner's" do
|
1027
|
+
it "returns member count by limit" do
|
1028
|
+
group_member = create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
1029
|
+
create(test_class_name, target: test_instance.target, group_owner: test_instance, notifier: create(:user))
|
1030
|
+
test_instance.open!
|
1031
|
+
expect(group_member.group_member_notifier_count(0)).to eq(0)
|
687
1032
|
end
|
688
1033
|
end
|
689
1034
|
end
|
@@ -712,6 +1057,20 @@ shared_examples_for :notification_api do
|
|
712
1057
|
expect(test_instance.respond_to?(:opened_group_member_count, true)).to be_truthy
|
713
1058
|
end
|
714
1059
|
end
|
1060
|
+
|
1061
|
+
describe "#unopened_group_member_notifier_count" do
|
1062
|
+
it "is defined as protected method" do
|
1063
|
+
expect(test_instance.respond_to?(:unopened_group_member_notifier_count)).to be_falsey
|
1064
|
+
expect(test_instance.respond_to?(:unopened_group_member_notifier_count, true)).to be_truthy
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
describe "#opened_group_member_notifier_count" do
|
1069
|
+
it "is defined as protected method" do
|
1070
|
+
expect(test_instance.respond_to?(:opened_group_member_notifier_count)).to be_falsey
|
1071
|
+
expect(test_instance.respond_to?(:opened_group_member_notifier_count, true)).to be_truthy
|
1072
|
+
end
|
1073
|
+
end
|
715
1074
|
end
|
716
1075
|
|
717
1076
|
private
|