Defect #36446 ยป 36446.patch
| app/controllers/watchers_controller.rb | ||
|---|---|---|
|
end
|
||
|
def users_for_new_watcher
|
||
|
scope = nil
|
||
|
if params[:q].blank? && @project.present?
|
||
|
scope = @project.principals.assignable_watchers
|
||
|
else
|
||
|
scope = Principal.assignable_watchers.limit(100)
|
||
|
end
|
||
|
scope = if params[:q].blank?
|
||
|
if @project.present?
|
||
|
@project.principals.assignable_watchers
|
||
|
elsif @projects.present? && @projects.size > 1
|
||
|
Principal.joins(:members).where(:members => { :project_id => @projects }).assignable_watchers.distinct
|
||
|
end
|
||
|
else
|
||
|
Principal.assignable_watchers.limit(100)
|
||
|
end
|
||
|
users = scope.sorted.like(params[:q]).to_a
|
||
|
if @watchables && @watchables.size == 1
|
||
|
watchable_object = @watchables.first
|
||
| app/views/watchers/_new.html.erb | ||
|---|---|---|
|
:controller => 'watchers',
|
||
|
:action => 'autocomplete_for_user',
|
||
|
:object_type => (watchables.present? ? watchables.first.class.name.underscore : nil),
|
||
|
:object_id => (watchables.present? && watchables.size == 1 ? watchables.first.id : nil),
|
||
|
:object_id => (watchables.present? ? watchables.map(&:id) : nil),
|
||
|
:project_id => @project
|
||
|
)
|
||
|
)}'
|
||
| test/functional/watchers_controller_test.rb | ||
|---|---|---|
|
assert_response 404
|
||
|
end
|
||
|
end
|
||
|
def test_ajax_url_should_pass_object_id_when_there_are_multiple_objects
|
||
|
@request.session[:user_id] = 2
|
||
|
get :new, :params => {
|
||
|
:object_id => [7, 9],
|
||
|
:object_type => 'issue'
|
||
|
}, :xhr => true
|
||
|
assert_response :success
|
||
|
assert_match(
|
||
|
%r{/watchers/autocomplete_for_user\?object_id%5B%5D=7&object_id%5B%5D=9&object_type=issue},
|
||
|
response.body
|
||
|
)
|
||
|
end
|
||
|
def test_autocomplete_for_user_with_multiple_projects
|
||
|
# 7 => eCookbook
|
||
|
# 9 => Private child of eCookbook
|
||
|
@request.session[:user_id] = 2
|
||
|
get :autocomplete_for_user, :params => {
|
||
|
:object_id => [7, 9],
|
||
|
:object_type => 'issue'
|
||
|
}, :xhr => true
|
||
|
assert_response :success
|
||
|
# All users from two projects eCookbook (7) and Private child of eCookbook (9)
|
||
|
assert_select 'input', :count => 5
|
||
|
assert_select 'input[name=?][value="1"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="2"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="3"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="8"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="10"]', 'watcher[user_ids][]'
|
||
|
end
|
||
|
end
|
||