diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-09-30 23:32:05 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-09-30 23:32:05 -0400 |
commit | bcd8ffa2183a1ca98417fb39bbd83e8f69c984c8 (patch) | |
tree | 36eac8c0fdd0a6a126a10dd7ad829401793a9379 /spec/arel/algebra | |
parent | 52e8aff146c162986566d3e03852395729d7c24d (diff) | |
download | rails-bcd8ffa2183a1ca98417fb39bbd83e8f69c984c8.tar.gz rails-bcd8ffa2183a1ca98417fb39bbd83e8f69c984c8.tar.bz2 rails-bcd8ffa2183a1ca98417fb39bbd83e8f69c984c8.zip |
Create Predicates module to match directory structure
Diffstat (limited to 'spec/arel/algebra')
-rw-r--r-- | spec/arel/algebra/unit/predicates/binary_spec.rb | 42 | ||||
-rw-r--r-- | spec/arel/algebra/unit/predicates/equality_spec.rb | 36 | ||||
-rw-r--r-- | spec/arel/algebra/unit/predicates/in_spec.rb | 10 | ||||
-rw-r--r-- | spec/arel/algebra/unit/primitives/attribute_spec.rb | 14 | ||||
-rw-r--r-- | spec/arel/algebra/unit/relations/relation_spec.rb | 2 |
5 files changed, 55 insertions, 49 deletions
diff --git a/spec/arel/algebra/unit/predicates/binary_spec.rb b/spec/arel/algebra/unit/predicates/binary_spec.rb index 97ef098e0e..be4c1ac738 100644 --- a/spec/arel/algebra/unit/predicates/binary_spec.rb +++ b/spec/arel/algebra/unit/predicates/binary_spec.rb @@ -1,31 +1,33 @@ require 'spec_helper' module Arel - describe Binary do - before do - @relation = Table.new(:users) - @attribute1 = @relation[:id] - @attribute2 = @relation[:name] - class ConcreteBinary < Binary - end - end - - describe '#bind' do + module Predicates + describe Binary do before do - @another_relation = @relation.alias + @relation = Table.new(:users) + @attribute1 = @relation[:id] + @attribute2 = @relation[:name] + class ConcreteBinary < Binary + end end - describe 'when both operands are attributes' do - it "manufactures an expression with the attributes bound to the relation" do - ConcreteBinary.new(@attribute1, @attribute2).bind(@another_relation). \ - should == ConcreteBinary.new(@another_relation[@attribute1], @another_relation[@attribute2]) + describe '#bind' do + before do + @another_relation = @relation.alias + end + + describe 'when both operands are attributes' do + it "manufactures an expression with the attributes bound to the relation" do + ConcreteBinary.new(@attribute1, @attribute2).bind(@another_relation). \ + should == ConcreteBinary.new(@another_relation[@attribute1], @another_relation[@attribute2]) + end end - end - describe 'when an operand is a value' do - it "manufactures an expression with unmodified values" do - ConcreteBinary.new(@attribute1, "asdf").bind(@another_relation). \ - should == ConcreteBinary.new(@attribute1.find_correlate_in(@another_relation), "asdf".find_correlate_in(@another_relation)) + describe 'when an operand is a value' do + it "manufactures an expression with unmodified values" do + ConcreteBinary.new(@attribute1, "asdf").bind(@another_relation). \ + should == ConcreteBinary.new(@attribute1.find_correlate_in(@another_relation), "asdf".find_correlate_in(@another_relation)) + end end end end diff --git a/spec/arel/algebra/unit/predicates/equality_spec.rb b/spec/arel/algebra/unit/predicates/equality_spec.rb index 01917842f6..cfd04cd90c 100644 --- a/spec/arel/algebra/unit/predicates/equality_spec.rb +++ b/spec/arel/algebra/unit/predicates/equality_spec.rb @@ -1,26 +1,28 @@ require 'spec_helper' module Arel - describe Equality do - before do - @relation1 = Table.new(:users) - @relation2 = Table.new(:photos) - @attribute1 = @relation1[:id] - @attribute2 = @relation2[:user_id] - end - - describe '==' do - it "obtains if attribute1 and attribute2 are identical" do - check Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2) - Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1) + module Predicates + describe Equality do + before do + @relation1 = Table.new(:users) + @relation2 = Table.new(:photos) + @attribute1 = @relation1[:id] + @attribute2 = @relation2[:user_id] end - it "obtains if the concrete type of the predicates are identical" do - Equality.new(@attribute1, @attribute2).should_not == Binary.new(@attribute1, @attribute2) - end + describe '==' do + it "obtains if attribute1 and attribute2 are identical" do + check Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2) + Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1) + end + + it "obtains if the concrete type of the predicates are identical" do + Equality.new(@attribute1, @attribute2).should_not == Binary.new(@attribute1, @attribute2) + end - it "is commutative on the attributes" do - Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1) + it "is commutative on the attributes" do + Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1) + end end end end diff --git a/spec/arel/algebra/unit/predicates/in_spec.rb b/spec/arel/algebra/unit/predicates/in_spec.rb index 54a6d6c7da..b9e15d63a4 100644 --- a/spec/arel/algebra/unit/predicates/in_spec.rb +++ b/spec/arel/algebra/unit/predicates/in_spec.rb @@ -1,10 +1,12 @@ require 'spec_helper' module Arel - describe In do - before do - @relation = Table.new(:users) - @attribute = @relation[:id] + module Predicates + describe In do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end end end end diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index 93b661c6fc..f734cc9c38 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -87,43 +87,43 @@ module Arel describe '#eq' do it "manufactures an equality predicate" do - @attribute.eq('name').should == Equality.new(@attribute, 'name') + @attribute.eq('name').should == Predicates::Equality.new(@attribute, 'name') end end describe '#lt' do it "manufactures a less-than predicate" do - @attribute.lt(10).should == LessThan.new(@attribute, 10) + @attribute.lt(10).should == Predicates::LessThan.new(@attribute, 10) end end describe '#lteq' do it "manufactures a less-than or equal-to predicate" do - @attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10) + @attribute.lteq(10).should == Predicates::LessThanOrEqualTo.new(@attribute, 10) end end describe '#gt' do it "manufactures a greater-than predicate" do - @attribute.gt(10).should == GreaterThan.new(@attribute, 10) + @attribute.gt(10).should == Predicates::GreaterThan.new(@attribute, 10) end end describe '#gteq' do it "manufactures a greater-than or equal-to predicate" do - @attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10) + @attribute.gteq(10).should == Predicates::GreaterThanOrEqualTo.new(@attribute, 10) end end describe '#matches' do it "manufactures a match predicate" do - @attribute.matches(/.*/).should == Match.new(@attribute, /.*/) + @attribute.matches(/.*/).should == Predicates::Match.new(@attribute, /.*/) end end describe '#in' do it "manufactures an in predicate" do - @attribute.in(1..30).should == In.new(@attribute, (1..30)) + @attribute.in(1..30).should == Predicates::In.new(@attribute, (1..30)) end end end diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb index 2688ece4a5..35ce8bf1fb 100644 --- a/spec/arel/algebra/unit/relations/relation_spec.rb +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -80,7 +80,7 @@ module Arel describe '#where' do before do - @predicate = Equality.new(@attribute1, @attribute2) + @predicate = Predicates::Equality.new(@attribute1, @attribute2) end it "manufactures a where relation" do |