FIX: `Group.search` should look up `Group#full_name` too.

https://meta.discourse.org/t/mentioning-group-by-full-name-doesnt-work/63437/3
This commit is contained in:
Guo Xiang Tan 2017-06-29 16:36:51 +09:00
parent 7b35c55a1e
commit 5e156fbe85
2 changed files with 17 additions and 1 deletions

View File

@ -282,7 +282,9 @@ class Group < ActiveRecord::Base
end
def self.search_group(name)
Group.where(visible: true).where("name ILIKE :term_like", term_like: "#{name}%")
Group.where(visible: true).where(
"name ILIKE :term_like OR full_name ILIKE :term_like", term_like: "#{name}%"
)
end
def self.lookup_group(name)

View File

@ -487,4 +487,18 @@ describe Group do
end
end
end
describe '.search_group' do
let(:group) { Fabricate(:group, name: 'tEsT', full_name: 'eSTt') }
it 'should return the right groups' do
group
expect(Group.search_group('te')).to eq([group])
expect(Group.search_group('TE')).to eq([group])
expect(Group.search_group('es')).to eq([group])
expect(Group.search_group('ES')).to eq([group])
expect(Group.search_group('test2')).to eq([])
end
end
end