Skip to content

Commit

Permalink
Add rspec tests for advanced search by tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacjam committed May 30, 2017
1 parent 2927b45 commit 6d1fafa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/components/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,28 @@ def search
expect(Search.execute('green tags:eggs').posts.map(&:id)).to eq([post2.id])
expect(Search.execute('green tags:plants').posts.size).to eq(0)
end

context 'tags' do
let(:tag1) { Fabricate(:tag, name: 'lunch') }
let(:tag2) { Fabricate(:tag, name: 'eggs') }
let(:topic1) { Fabricate(:topic, tags: [tag2, Fabricate(:tag)]) }
let(:topic2) { Fabricate(:topic, tags: [tag1]) }
let(:topic3) { Fabricate(:topic, tags: [tag1, tag2]) }
let!(:post1) { Fabricate(:post, topic: topic1)}
let!(:post2) { Fabricate(:post, topic: topic2)}
let!(:post3) { Fabricate(:post, topic: topic3)}

it 'can find posts with any tag from multiple tags' do
Fabricate(:post)

expect(Search.execute('tags:eggs|lunch').posts.map(&:id).sort).to eq([post1.id, post2.id, post3.id].sort)
end

it 'can find posts which contains all provided tags' do
expect(Search.execute('tags:lunch,eggs').posts.map(&:id)).to eq([post3.id])
end
end

end

it 'can parse complex strings using ts_query helper' do
Expand Down

0 comments on commit 6d1fafa

Please sign in to comment.