spec/unit/axiom/relation/operation/order/class_methods/new_spec.rb in axiom-0.1.0 vs spec/unit/axiom/relation/operation/order/class_methods/new_spec.rb in axiom-0.1.1
- old
+ new
@@ -3,32 +3,134 @@
require 'spec_helper'
describe Relation::Operation::Order, '.new' do
subject { object.new(relation, directions) }
- let(:header) { [ [ :id, Integer ], [ :name, String ] ] }
- let(:body) { [ [ 1, 'Dan Kubb' ], [ 2, 'Alex Kubb' ] ] }
- let(:relation) { Relation.new(header, body) }
- let(:object) { described_class }
+ let(:object) { described_class }
+ let(:relation) { Relation.new(header, body) }
+ let(:header) { [[:id, Integer], [:name, String]] }
+ let(:body) { [[1, 'Dan Kubb'], [2, 'Alex Kubb']] }
- context 'with all attributes specified in the directions' do
- let(:directions) { [ relation[:id], relation[:name] ] }
+ context 'attribute names' do
+ context 'full header' do
+ let(:directions) { [:id, :name] }
- it { should be_instance_of(object) }
+ it { should be_instance_of(object) }
- its(:operand) { should equal(relation) }
+ its(:operand) { should be(relation) }
- its(:directions) { should == [ relation[:id].asc, relation[:name].asc ] }
+ its(:directions) { should == [relation[:id].asc, relation[:name].asc] }
+ end
+
+ context 'partial header' do
+ let(:directions) { [:name] }
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:name].asc, relation[:id].asc] }
+ end
end
- context 'without no attributes specified in the directions' do
- let(:directions) { [] }
+ context 'attributes' do
+ context 'full header' do
+ let(:directions) { [relation[:id], relation[:name]] }
- specify { expect { subject }.to raise_error(InvalidDirectionsError, 'directions must include every attribute in the header') }
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:id].asc, relation[:name].asc] }
+ end
+
+ context 'partial header' do
+ let(:directions) { [relation[:name]] }
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:name].asc, relation[:id].asc] }
+ end
end
- context 'without all attributes specified in the directions' do
- let(:directions) { [ relation[:id] ] }
+ context 'array of directions' do
+ context 'full header' do
+ let(:directions) { [relation[:id].desc, relation[:name].desc] }
- specify { expect { subject }.to raise_error(InvalidDirectionsError, 'directions must include every attribute in the header') }
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:id].desc, relation[:name].desc] }
+ end
+
+ context 'partial header' do
+ let(:directions) { [relation[:name].desc] }
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:name].desc, relation[:id].asc] }
+ end
+ end
+
+ context 'header' do
+ context 'full header' do
+ let(:directions) { relation.header }
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:id].asc, relation[:name].asc] }
+ end
+
+ context 'partial header' do
+ let(:directions) { relation.header.project([:name]) }
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:name].asc, relation[:id].asc] }
+ end
+ end
+
+ context 'direction set' do
+ context 'full header' do
+ let(:directions) do
+ Relation::Operation::Order::DirectionSet.new([relation[:id].desc, relation[:name].desc])
+ end
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:id].desc, relation[:name].desc] }
+ end
+
+ context 'partial header' do
+ let(:directions) do
+ Relation::Operation::Order::DirectionSet.new([relation[:name].desc])
+ end
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:name].desc, relation[:id].asc] }
+ end
+ end
+
+ context 'no attributes' do
+ let(:directions) { [] }
+
+ it { should be_instance_of(object) }
+
+ its(:operand) { should be(relation) }
+
+ its(:directions) { should == [relation[:id].asc, relation[:name].asc] }
end
end