@@ -382,12 +382,13 class Project < ActiveRecord::Base | |||
|
382 | 382 | |
|
383 | 383 | # Returns the mail adresses of users that should be always notified on project events |
|
384 | 384 | def recipients |
|
385 | members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user.mail} | |
|
385 | notified_users.collect {|user| user.mail} | |
|
386 | 386 | end |
|
387 | 387 | |
|
388 | 388 | # Returns the users that should be notified on project events |
|
389 | 389 | def notified_users |
|
390 | members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user} | |
|
390 | # TODO: User part should be extracted to User#notify_about? | |
|
391 | members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user} | |
|
391 | 392 | end |
|
392 | 393 | |
|
393 | 394 | # Returns an array of all custom fields enabled for project issues |
@@ -964,4 +964,54 class ProjectTest < ActiveSupport::TestCase | |||
|
964 | 964 | |
|
965 | 965 | end |
|
966 | 966 | end |
|
967 | ||
|
968 | context "#notified_users" do | |
|
969 | setup do | |
|
970 | @project = Project.generate! | |
|
971 | @role = Role.generate! | |
|
972 | ||
|
973 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
|
974 | Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) | |
|
975 | ||
|
976 | @all_events_user = User.generate!(:mail_notification => 'all') | |
|
977 | Member.generate!(:project => @project, :roles => [@role], :principal => @all_events_user) | |
|
978 | ||
|
979 | @no_events_user = User.generate!(:mail_notification => 'none') | |
|
980 | Member.generate!(:project => @project, :roles => [@role], :principal => @no_events_user) | |
|
981 | ||
|
982 | @only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | |
|
983 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_my_events_user) | |
|
984 | ||
|
985 | @only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | |
|
986 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_assigned_user) | |
|
987 | ||
|
988 | @only_owned_user = User.generate!(:mail_notification => 'only_owner') | |
|
989 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user) | |
|
990 | end | |
|
991 | ||
|
992 | should "include members with a mail notification" do | |
|
993 | assert @project.notified_users.include?(@user_with_membership_notification) | |
|
994 | end | |
|
995 | ||
|
996 | should "include users with the 'all' notification option" do | |
|
997 | assert @project.notified_users.include?(@all_events_user) | |
|
998 | end | |
|
999 | ||
|
1000 | should "not include users with the 'none' notification option" do | |
|
1001 | assert !@project.notified_users.include?(@no_events_user) | |
|
1002 | end | |
|
1003 | ||
|
1004 | should "not include users with the 'only_my_events' notification option" do | |
|
1005 | assert !@project.notified_users.include?(@only_my_events_user) | |
|
1006 | end | |
|
1007 | ||
|
1008 | should "not include users with the 'only_assigned' notification option" do | |
|
1009 | assert !@project.notified_users.include?(@only_assigned_user) | |
|
1010 | end | |
|
1011 | ||
|
1012 | should "not include users with the 'only_owner' notification option" do | |
|
1013 | assert !@project.notified_users.include?(@only_owned_user) | |
|
1014 | end | |
|
1015 | end | |
|
1016 | ||
|
967 | 1017 | end |
General Comments 0
You need to be logged in to leave comments.
Login now