diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-07-11 18:33:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-07-11 18:33:07 +0000 |
commit | 3d9f2741404d5ca4a17e5a4d8685321be57666a1 (patch) | |
tree | e072a9fc0f70deb643a62a1f1cbb755bc08e9d34 | |
parent | 7375dff6d6bcad2b4075f71d41df28b70dce6b2e (diff) | |
download | redmine-3d9f2741404d5ca4a17e5a4d8685321be57666a1.tar.gz redmine-3d9f2741404d5ca4a17e5a4d8685321be57666a1.zip |
Merged r11839 from trunk (#14020).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@11997 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/my_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 2 | ||||
-rw-r--r-- | app/models/mailer.rb | 2 | ||||
-rw-r--r-- | app/models/user_preference.rb | 3 | ||||
-rw-r--r-- | app/views/users/_mail_notifications.html.erb | 9 | ||||
-rw-r--r-- | test/functional/admin_controller_test.rb | 2 | ||||
-rw-r--r-- | test/functional/users_controller_test.rb | 12 | ||||
-rw-r--r-- | test/unit/mailer_test.rb | 6 |
8 files changed, 25 insertions, 12 deletions
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 84f5b20ca..92853067b 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -53,7 +53,6 @@ class MyController < ApplicationController if request.post? @user.safe_attributes = params[:user] @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') if @user.save @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 23a979ea2..cecdc2d33 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -92,7 +92,6 @@ class UsersController < ApplicationController if @user.save @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) @@ -137,7 +136,6 @@ class UsersController < ApplicationController was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) # TODO: Similar to My#account @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') if @user.save @user.pref.save diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 7166025c2..c12195a02 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -390,7 +390,7 @@ class Mailer < ActionMailer::Base # Removes the author from the recipients and cc # if he doesn't want to receive notifications about what he does - if @author && @author.logged? && @author.pref[:no_self_notified] + if @author && @author.logged? && @author.pref.no_self_notified headers[:to].delete(@author.mail) if headers[:to].is_a?(Array) headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array) end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 5b95386be..cbeaec687 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -56,4 +56,7 @@ class UserPreference < ActiveRecord::Base def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end + + def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end + def no_self_notified=(value); self[:no_self_notified]=value; end end diff --git a/app/views/users/_mail_notifications.html.erb b/app/views/users/_mail_notifications.html.erb index 179f6749a..a31f6304b 100644 --- a/app/views/users/_mail_notifications.html.erb +++ b/app/views/users/_mail_notifications.html.erb @@ -19,9 +19,10 @@ end %> <p><em class="info"><%= l(:text_user_mail_option) %></em></p> <% end %> + +<%= fields_for :pref, @user.pref do |pref_fields| %> <p> - <label> - <%= l(:label_user_mail_no_self_notified) %> - <%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %> - </label> + <%= pref_fields.check_box :no_self_notified %> + <label for="pref_no_self_notified"><%= l(:label_user_mail_no_self_notified) %></label> </p> +<% end %> diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index 48f3aad55..794775c0c 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -83,7 +83,7 @@ class AdminControllerTest < ActionController::TestCase def test_test_email user = User.find(1) - user.pref[:no_self_notified] = '1' + user.pref.no_self_notified = '1' user.pref.save! ActionMailer::Base.deliveries.clear diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 37e58d500..2fb0d87e9 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -325,6 +325,18 @@ class UsersControllerTest < ActionController::TestCase assert_equal [1, 2], u.notified_projects_ids.sort end + def test_update_status_should_not_update_attributes + user = User.find(2) + user.pref[:no_self_notified] = '1' + user.pref.save + + put :update, :id => 2, :user => {:status => 3} + assert_response 302 + user = User.find(2) + assert_equal 3, user.status + assert_equal '1', user.pref[:no_self_notified] + end + def test_destroy assert_difference 'User.count', -1 do delete :destroy, :id => 2 diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 223422002..f429a3908 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -215,14 +215,14 @@ class MailerTest < ActiveSupport::TestCase # Remove members except news author news.project.memberships.each {|m| m.destroy unless m.user == user} - user.pref[:no_self_notified] = false + user.pref.no_self_notified = false user.pref.save User.current = user Mailer.news_added(news.reload).deliver assert_equal 1, last_email.bcc.size # nobody to notify - user.pref[:no_self_notified] = true + user.pref.no_self_notified = true user.pref.save User.current = user ActionMailer::Base.deliveries.clear @@ -296,7 +296,7 @@ class MailerTest < ActiveSupport::TestCase issue = Issue.find(1) user = User.find(9) # minimal email notification options - user.pref[:no_self_notified] = '1' + user.pref.no_self_notified = '1' user.pref.save user.mail_notification = false user.save |