Skip to content

Commit

Permalink
フォーム再表示時にグループに属するユーザーにチェックが入らないようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
kumojima committed Apr 11, 2024
1 parent 990b81c commit 5220a42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/watchers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def watchers_list(object)

def watchers_checkboxes(object, users, checked=nil)
users.map do |user|
c = checked.nil? ? object.watched_by?(user) : checked
c = checked.nil? ? object.watcher_user_ids.include?(user.id) : checked
tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
content_tag 'label', "#{tag} #{h(user)}".html_safe,
:id => "issue_watcher_user_ids_#{user.id}",
Expand Down
18 changes: 18 additions & 0 deletions test/functional/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4778,6 +4778,24 @@ def test_post_create_with_failure_should_preserve_watchers
assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]'
end

def test_post_create_with_failure_should_not_dereference_group_watchers
@request.session[:user_id] = 1
post(
:create,
:params => {
:project_id => 5,
:issue => {
:tracker_id => 1,
:watcher_user_ids => ['11']
}
}
)
assert_response :success

assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]', 0
assert_select 'input[name=?][value="11"][checked=checked]', 'issue[watcher_user_ids][]', 1
end

def test_post_create_should_ignore_non_safe_attributes
@request.session[:user_id] = 2
assert_nothing_raised do
Expand Down

0 comments on commit 5220a42

Please sign in to comment.