rename to badge, better more consistent name

This commit is contained in:
Sam 2015-09-15 18:47:27 +10:00
parent a14d7f16c8
commit a7b34cd16b
2 changed files with 4 additions and 3 deletions

View File

@ -185,7 +185,7 @@ class Search
posts.where("posts.post_number = 1")
end
advanced_filter(/with_badge:(.*)/) do |posts,match|
advanced_filter(/badge:(.*)/) do |posts,match|
badge_id = Badge.where('name ilike ? OR id = ?', match, match.to_i).pluck(:id).first
if badge_id
posts.where('posts.user_id IN (SELECT ub.user_id FROM user_badges ub WHERE ub.badge_id = ?)', badge_id)

View File

@ -402,7 +402,7 @@ describe Search do
expect(Search.execute('group:"like a brick"').posts.length).to eq(0)
end
it 'supports with_badge' do
it 'supports badge' do
topic = Fabricate(:topic, created_at: 3.months.ago)
post = Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)
@ -410,7 +410,8 @@ describe Search do
badge = Badge.create!(name: "Like a Boss", badge_type_id: 1)
UserBadge.create!(user_id: post.user_id, badge_id: badge.id, granted_at: 1.minute.ago, granted_by_id: -1)
expect(Search.execute('with_badge:"like a boss"').posts.length).to eq(1)
expect(Search.execute('badge:"like a boss"').posts.length).to eq(1)
expect(Search.execute('badge:"test"').posts.length).to eq(0)
end
it 'can search numbers correctly, and match exact phrases' do