# Returns an array of users that are proposed as watchers
# on the new issue form
def users_for_new_issue_watchers(issue)
- users = issue.watcher_users
+ users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}
if issue.project.users.count <= 20
users = (users + issue.project.users.sort).uniq
end
end
end
unless options[:watchers] == false
- self.watcher_user_ids = issue.watcher_user_ids.dup
+ self.watcher_user_ids =
+ issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}.map(&:id)
end
@copied_from = issue
@copy_options = options
assert_select 'input[type=hidden][name=?][value=?]', 'issue[watcher_user_ids][]', '', 1
end
+ def test_new_as_copy_should_not_propose_locked_watchers
+ @request.session[:user_id] = 2
+
+ issue = Issue.find(1)
+ user = User.generate!
+ user2 = User.generate!
+
+ Watcher.create!(:watchable => issue, :user => user)
+ Watcher.create!(:watchable => issue, :user => user2)
+
+ user2.status = User::STATUS_LOCKED
+ user2.save!
+ get :new, :params => {
+ :project_id => 1,
+ :copy_from => 1
+ }
+
+ assert_select 'input[type=checkbox][name=?][checked=checked]', 'issue[watcher_user_ids][]', 1
+ assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user.id.to_s
+ assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user2.id.to_s, 0
+ assert_select 'input[type=hidden][name=?][value=?]', 'issue[watcher_user_ids][]', '', 1
+ end
+
def test_new_as_copy_with_invalid_issue_should_respond_with_404
@request.session[:user_id] = 2
get :new, :params => {
assert_not_nil copied_closed.closed_on
end
+ def test_copy_should_not_copy_locked_watchers
+ user = User.find(2)
+ user2 = User.find(3)
+ issue = Issue.find(8)
+
+ Watcher.create!(:user => user, :watchable => issue)
+ Watcher.create!(:user => user2, :watchable => issue)
+
+ user2.status = User::STATUS_LOCKED
+ user2.save!
+
+ issue = Issue.new.copy_from(8)
+
+ assert issue.save
+ assert issue.watched_by?(user)
+ assert !issue.watched_by?(user2)
+ end
+
def test_should_not_call_after_project_change_on_creation
issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
:subject => 'Test', :author_id => 1)