FIX: username autocomplete in assign modal wasn't working

This commit is contained in:
Régis Hanol 2017-10-03 12:49:45 +02:00
parent 5b96463c40
commit daf1dda700
2 changed files with 24 additions and 4 deletions

View File

@ -706,8 +706,10 @@ class UsersController < ApplicationController
Group.messageable(current_user)
end
to_render[:groups] = groups.where("name ILIKE :term_like", term_like: "#{term}%")
.map { |m| { name: m.name, full_name: m.full_name } }
if groups
to_render[:groups] = groups.where("name ILIKE :term_like", term_like: "#{term}%")
.map { |m| { name: m.name, full_name: m.full_name } }
end
end
render json: to_render

View File

@ -175,6 +175,16 @@ RSpec.describe UsersController do
sign_in(user)
end
it "doesn't search for groups" do
get "/u/search/users.json", params: {
include_mentionable_groups: 'false',
include_messageable_groups: 'false'
}
expect(response).to be_success
expect(JSON.parse(response.body)).not_to have_key(:groups)
end
it "searches for messageable groups" do
get "/u/search/users.json", params: {
include_mentionable_groups: 'false',
@ -198,13 +208,21 @@ RSpec.describe UsersController do
describe 'when not signed in' do
it 'should not include mentionable/messageable groups' do
get "/u/search/users.json", params: {
include_mentionable_groups: 'false',
include_messageable_groups: 'false'
}
expect(response).to be_success
expect(JSON.parse(response.body)).not_to have_key(:groups)
get "/u/search/users.json", params: {
include_mentionable_groups: 'false',
include_messageable_groups: 'true'
}
expect(response).to be_success
expect(JSON.parse(response.body)["groups"]).to eq(nil)
expect(JSON.parse(response.body)).not_to have_key(:groups)
get "/u/search/users.json", params: {
include_messageable_groups: 'false',
@ -212,7 +230,7 @@ RSpec.describe UsersController do
}
expect(response).to be_success
expect(JSON.parse(response.body)["groups"]).to eq(nil)
expect(JSON.parse(response.body)).not_to have_key(:groups)
end
end
end