spec/lib/pose/search_spec.rb in pose-3.0.0 vs spec/lib/pose/search_spec.rb in pose-3.1.1
- old
+ new
@@ -2,17 +2,15 @@
module Pose
describe Search do
let(:subject) { Search.new [PosableOne, [PosableTwo]], 'query string' }
- let(:arel) { double() }
+ let(:arel) { double() }
let(:arel_2) { double() }
let(:arel_3) { double() }
-
describe :add_join do
-
it 'returns the new arel' do
arel.should_receive(:joins).with('foo').and_return(arel_2)
expect(subject.add_join arel, 'foo').to eql arel_2
end
@@ -37,13 +35,11 @@
subject.add_join arel, :association
end
end
end
-
describe :add_joins do
-
it 'adds all joins to the given arel' do
arel.should_receive(:joins).with('one').and_return(arel_2)
arel_2.should_receive(:joins).with('two').and_return(arel_3)
search = Search.new nil, nil, joins: ['one', 'two']
search.add_joins arel
@@ -55,13 +51,11 @@
search = Search.new nil, nil, joins: ['one', 'two']
expect(search.add_joins arel).to eql arel_3
end
end
-
describe :add_wheres do
-
it 'adds all joins to the given arel' do
arel.should_receive(:where).with(['one = ?', true]).and_return(arel_2)
arel_2.should_receive(:where).with(['two = ?', false]).and_return(arel_3)
search = Search.new nil, nil, where: [['one = ?', true], ['two = ?', false]]
search.add_wheres arel
@@ -73,23 +67,20 @@
search = Search.new nil, nil, where: [['one'], ['two']]
expect(search.add_wheres arel).to eql arel_3
end
end
-
describe :empty_result do
-
it 'returns a hash with classes and empty arrays for each class in the search query' do
search = Search.new [PosableOne, PosableTwo], ''
result = search.empty_result
expect(result['PosableOne']).to eq []
expect(result['PosableTwo']).to eq []
expect(result).to_not have_key 'User'
end
end
-
describe :limit_ids do
before :each do
@search = Search.new nil, nil, limit: 2
end
@@ -127,11 +118,10 @@
end
end
describe :load_classes do
-
context 'when the user wants ids' do
it 'does nothing' do
search = Search.new nil, nil, result_type: :ids
result = { PosableOne => [1, 2] }
search.load_classes @result
@@ -141,22 +131,21 @@
context 'when the user wants classes' do
it 'loads the classes' do
object_1 = create :posable_one
object_2 = create :posable_one
- result = { PosableOne => [1, 2] }
+ result = { PosableOne => [object_1.id, object_2.id] }
search = Search.new nil, nil
search.load_classes result
expect(result[PosableOne]).to eq [object_1, object_2]
end
end
end
describe :merge_search_result_word_matches do
context 'given a new class name' do
-
before :each do
@result = {}
end
it 'sets the given ids as the ids for this class name' do
@@ -164,11 +153,10 @@
expect(@result).to eq({ 'class1' => [1, 2] })
end
end
context 'given a class name with already existing ids from another word' do
-
before :each do
@result = { 'class1' => [1, 2] }
end
it 'only keeps the ids that are included in both sets' do
@@ -176,11 +164,10 @@
expect(@result).to eq({ 'class1' => [1] })
end
end
context 'with an existing empty result set from a previous query' do
-
before :each do
@result = { 'class1' => [] }
end
it 'returns an empty result set' do
@@ -188,11 +175,10 @@
@result.should eq({ 'class1' => [] })
end
end
context 'with a new empty result set' do
-
before :each do
@result = { 'class1' => [1, 2] }
end
it 'returns an empty result set' do
@@ -200,11 +186,10 @@
@result.should eq({ 'class1' => [] })
end
end
context 'with a completely different result set' do
-
before :each do
@result = { 'class1' => [1, 2] }
end
it 'returns an empty result set' do
@@ -214,11 +199,10 @@
end
end
describe :search do
-
it 'finds all matching instances of all classes' do
posable_one_1 = create :posable_one, text: 'foo bar'
posable_one_2 = create :posable_one, text: 'foo bar'
posable_one_3 = create :posable_one, text: 'foo'
posable_two_1 = create :posable_two, text: 'foo bar'
@@ -253,11 +237,10 @@
result = search.search
expect(result[PosableOne]).to have(1).items
end
describe 'result types' do
-
it 'loads classes by default' do
posable_one = create :posable_one, text: 'foo'
search = Search.new PosableOne, 'foo'
result = search.search
expect(result[PosableOne]).to eq [posable_one]
@@ -290,11 +273,10 @@
end
end
describe :search_word do
-
context 'search results' do
it 'returns the ids of the matching instances for this class' do
posable_one_1 = create :posable_one, text: 'foo'
posable_one_2 = create :posable_one, text: 'foo'
search = Search.new PosableOne, nil
@@ -321,12 +303,10 @@
expect(result['PosableTwo']).to include posable_two_1.id
end
end
end
-
describe :search_words do
-
context 'search results' do
it 'returns the ids of all instances that match all query words' do
posable_one = create :posable_one, text: 'foo bar'
search = Search.new PosableOne, 'foo bar'
result = search.search_words