spec/integration/veritas/algebra/rename/optimize_spec.rb in veritas-optimizer-0.0.4 vs spec/integration/veritas/algebra/rename/optimize_spec.rb in veritas-optimizer-0.0.5

- old
+ new

@@ -181,11 +181,11 @@ it_should_behave_like 'an optimize method' end context 'containing a restriction' do - let(:operand) { relation.restrict { |r| r[:id].eq(1) } } + let(:operand) { relation.restrict { |r| r.id.eq(1) } } it { should be_kind_of(Algebra::Restriction) } its(:operand) { should eql(described_class.new(relation, aliases)) } @@ -202,15 +202,15 @@ it_should_behave_like 'an optimize method' end context 'containing a restriction, containing a object that cancels out' do - let(:operand) { relation.rename(:id => :other_id).restrict { |r| r[:other_id].eq(1) } } - let(:aliases) { { :other_id => :id } } + let(:operand) { relation.rename(:id => :other_id).restrict { |r| r.other_id.eq(1) } } + let(:aliases) { { :other_id => :id } } it 'pushes the object before the restriction, and then cancel it out' do - should eql(relation.restrict { |r| r[:id].eq(1) }) + should eql(relation.restrict { |r| r.id.eq(1) }) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -265,15 +265,15 @@ it_should_behave_like 'an optimize method' end context 'containing a reverse operation' do - let(:limit) { relation.order.take(2) } - let(:operand) { limit.reverse } + let(:limit) { relation.sort_by { |r| [ r.id, r.name ] }.take(2) } + let(:operand) { limit.reverse } it 'pushes the object under the order, limit and reverse' do - should eql(relation.rename(aliases).order.take(2).reverse) + should eql(relation.rename(aliases).sort_by { |r| [ r.other_id, r.name ] }.take(2).reverse) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -285,16 +285,16 @@ it_should_behave_like 'an optimize method' end context 'containing a reverse operation, containing a object that cancels out' do - let(:limit) { relation.order.take(2) } - let(:operand) { limit.rename(:id => :other_id).reverse } - let(:aliases) { { :other_id => :id } } + let(:limit) { relation.sort_by { |r| [ r.id, r.name ] }.take(2) } + let(:operand) { limit.rename(:id => :other_id).reverse } + let(:aliases) { { :other_id => :id } } it 'pushes the object under the order, limit and reverse, and then cancel it out' do - should eql(relation.order.take(2).reverse) + should eql(relation.sort_by { |r| [ r.id, r.name ] }.take(2).reverse) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -306,14 +306,14 @@ it_should_behave_like 'an optimize method' end context 'containing an order operation' do - let(:operand) { relation.order } + let(:operand) { relation.sort_by { |r| [ r.id, r.name ] } } it 'pushes the object under the order' do - should eql(relation.rename(aliases).order) + should eql(relation.rename(aliases).sort_by { |r| [ r.other_id, r.name ] }) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -325,15 +325,15 @@ it_should_behave_like 'an optimize method' end context 'containing an order operation, containing a object that cancels out' do - let(:operand) { relation.rename(:id => :other_id).order } - let(:aliases) { { :other_id => :id } } + let(:operand) { relation.rename(:id => :other_id).sort_by { |r| [ r.other_id, r.name ] } } + let(:aliases) { { :other_id => :id } } it 'pushes the object under the order, and then cancel it out' do - should eql(relation.order) + should eql(relation.sort_by { |r| [ r.id, r.name ] }) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -345,15 +345,15 @@ it_should_behave_like 'an optimize method' end context 'containing a limit operation' do - let(:order) { relation.order } - let(:operand) { order.take(2) } + let(:order) { relation.sort_by { |r| [ r.id, r.name ] } } + let(:operand) { order.take(2) } it 'pushes the object under the limit and order' do - should eql(relation.rename(aliases).order.take(2)) + should eql(relation.rename(aliases).sort_by { |r| [ r.other_id, r.name ] }.take(2)) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -365,16 +365,16 @@ it_should_behave_like 'an optimize method' end context 'containing a limit operation, containing a object that cancels out' do - let(:order) { relation.order } - let(:operand) { order.rename(:id => :other_id).take(2) } - let(:aliases) { { :other_id => :id } } + let(:order) { relation.sort_by { |r| [ r.id, r.name ] } } + let(:operand) { order.rename(:id => :other_id).take(2) } + let(:aliases) { { :other_id => :id } } it 'pushes the object under the limit and order, and then cancel it out' do - should eql(relation.order.take(2)) + should eql(relation.sort_by { |r| [ r.id, r.name ] }.take(2)) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -386,15 +386,15 @@ it_should_behave_like 'an optimize method' end context 'containing an offset operation' do - let(:order) { relation.order } - let(:operand) { order.drop(1) } + let(:order) { relation.sort_by { |r| [ r.id, r.name ] } } + let(:operand) { order.drop(1) } it 'pushes the object under the offset and order' do - should eql(relation.rename(aliases).order.drop(1)) + should eql(relation.rename(aliases).sort_by { |r| [ r.other_id, r.name ] }.drop(1)) end it 'returns an equivalent relation to the unoptimized operation' do should == object end @@ -406,15 +406,15 @@ it_should_behave_like 'an optimize method' end context 'containing an offset operation, containing a object that cancels out' do - let(:order) { relation.order } - let(:operand) { order.rename(:id => :other_id).drop(1) } - let(:aliases) { { :other_id => :id } } + let(:order) { relation.sort_by { |r| [ r.id, r.name ] } } + let(:operand) { order.rename(:id => :other_id).drop(1) } + let(:aliases) { { :other_id => :id } } it 'pushes the object under the offset and order, and then cancel it out' do - should eql(relation.order.drop(1)) + should eql(relation.sort_by { |r| [ r.id, r.name ] }.drop(1)) end it 'returns an equivalent relation to the unoptimized operation' do should == object end