Defect #36446 ยป 36446.patch
app/controllers/watchers_controller.rb | ||
---|---|---|
133 | 133 |
end |
134 | 134 | |
135 | 135 |
def users_for_new_watcher |
136 |
scope = nil |
|
137 |
if params[:q].blank? && @project.present? |
|
138 |
scope = @project.principals.assignable_watchers |
|
139 |
else |
|
140 |
scope = Principal.assignable_watchers.limit(100) |
|
141 |
end |
|
136 |
scope = if params[:q].blank? |
|
137 |
if @project.present? |
|
138 |
@project.principals.assignable_watchers |
|
139 |
elsif @projects.present? && @projects.size > 1 |
|
140 |
Principal.joins(:members).where(:members => { :project_id => @projects }).assignable_watchers.distinct |
|
141 |
end |
|
142 |
else |
|
143 |
Principal.assignable_watchers.limit(100) |
|
144 |
end |
|
142 | 145 |
users = scope.sorted.like(params[:q]).to_a |
143 | 146 |
if @watchables && @watchables.size == 1 |
144 | 147 |
watchable_object = @watchables.first |
app/views/watchers/_new.html.erb | ||
---|---|---|
31 | 31 |
:controller => 'watchers', |
32 | 32 |
:action => 'autocomplete_for_user', |
33 | 33 |
:object_type => (watchables.present? ? watchables.first.class.name.underscore : nil), |
34 |
:object_id => (watchables.present? && watchables.size == 1 ? watchables.first.id : nil),
|
|
34 |
:object_id => (watchables.present? ? watchables.map(&:id) : nil),
|
|
35 | 35 |
:project_id => @project |
36 | 36 |
) |
37 | 37 |
)}' |
test/functional/watchers_controller_test.rb | ||
---|---|---|
543 | 543 |
assert_response 404 |
544 | 544 |
end |
545 | 545 |
end |
546 | ||
547 |
def test_ajax_url_should_pass_object_id_when_there_are_multiple_objects |
|
548 |
@request.session[:user_id] = 2 |
|
549 |
get :new, :params => { |
|
550 |
:object_id => [7, 9], |
|
551 |
:object_type => 'issue' |
|
552 |
}, :xhr => true |
|
553 |
assert_response :success |
|
554 | ||
555 |
assert_match( |
|
556 |
%r{/watchers/autocomplete_for_user\?object_id%5B%5D=7&object_id%5B%5D=9&object_type=issue}, |
|
557 |
response.body |
|
558 |
) |
|
559 |
end |
|
560 | ||
561 |
def test_autocomplete_for_user_with_multiple_projects |
|
562 |
# 7 => eCookbook |
|
563 |
# 9 => Private child of eCookbook |
|
564 |
@request.session[:user_id] = 2 |
|
565 |
get :autocomplete_for_user, :params => { |
|
566 |
:object_id => [7, 9], |
|
567 |
:object_type => 'issue' |
|
568 |
}, :xhr => true |
|
569 |
assert_response :success |
|
570 | ||
571 |
# All users from two projects eCookbook (7) and Private child of eCookbook (9) |
|
572 |
assert_select 'input', :count => 5 |
|
573 |
assert_select 'input[name=?][value="1"]', 'watcher[user_ids][]' |
|
574 |
assert_select 'input[name=?][value="2"]', 'watcher[user_ids][]' |
|
575 |
assert_select 'input[name=?][value="3"]', 'watcher[user_ids][]' |
|
576 |
assert_select 'input[name=?][value="8"]', 'watcher[user_ids][]' |
|
577 |
assert_select 'input[name=?][value="10"]', 'watcher[user_ids][]' |
|
578 |
end |
|
546 | 579 |
end |