From ef00501c36992221a1afa5f5bd4706ed91fbb7f1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 22 May 2011 10:30:26 +0000 Subject: [PATCH] Fixed: validation error on issue creation when trying to add an invalid user as a watcher (#5373). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5880 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/watcher_test.rb | 21 +++++++++++++++++++ .../lib/acts_as_watchable.rb | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index d9abb7f6d..b9ef579d3 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -47,7 +47,28 @@ class WatcherTest < ActiveSupport::TestCase assert Issue.watched_by(@user).include?(@issue) end + def test_watcher_users + watcher_users = Issue.find(2).watcher_users + assert_kind_of Array, watcher_users + assert_kind_of User, watcher_users.first + end + + def test_watcher_users_should_not_validate_user + User.update_all("firstname = ''", "id=1") + @user.reload + assert !@user.valid? + + issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2)) + issue.watcher_users << @user + issue.save! + assert issue.watched_by?(@user) + end + def test_watcher_user_ids + assert_equal [1, 3], Issue.find(2).watcher_user_ids.sort + end + + def test_watcher_user_ids= issue = Issue.new issue.watcher_user_ids = ['1', '3'] assert issue.watched_by?(User.find(1)) diff --git a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb index a22098eec..e9c0eb3e6 100644 --- a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb +++ b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -13,7 +13,7 @@ module Redmine class_eval do has_many :watchers, :as => :watchable, :dependent => :delete_all - has_many :watcher_users, :through => :watchers, :source => :user + has_many :watcher_users, :through => :watchers, :source => :user, :validate => false named_scope :watched_by, lambda { |user_id| { :include => :watchers, -- 2.39.5