aboutsummaryrefslogtreecommitdiffstats
path: root/spec/algebra/unit/predicates
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-12 14:46:37 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-12 14:46:37 -0800
commite13420c86afb5c31e90cff800f121bd49255b939 (patch)
tree7089d188061b2a676143add52227e107a5cf9b45 /spec/algebra/unit/predicates
parent0b8b87fb947a746d4e58d11ea73ef20cfb23f576 (diff)
downloadrails-e13420c86afb5c31e90cff800f121bd49255b939.tar.gz
rails-e13420c86afb5c31e90cff800f121bd49255b939.tar.bz2
rails-e13420c86afb5c31e90cff800f121bd49255b939.zip
We're obviously writing specs for arel. No need for a sub directory.
Diffstat (limited to 'spec/algebra/unit/predicates')
-rw-r--r--spec/algebra/unit/predicates/binary_spec.rb35
-rw-r--r--spec/algebra/unit/predicates/equality_spec.rb29
-rw-r--r--spec/algebra/unit/predicates/in_spec.rb12
3 files changed, 76 insertions, 0 deletions
diff --git a/spec/algebra/unit/predicates/binary_spec.rb b/spec/algebra/unit/predicates/binary_spec.rb
new file mode 100644
index 0000000000..051aeeeb6e
--- /dev/null
+++ b/spec/algebra/unit/predicates/binary_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+module Arel
+ module Predicates
+ describe Binary do
+ before do
+ @relation = Arel::Table.new(:users)
+ @attribute1 = @relation[:id]
+ @attribute2 = @relation[:name]
+ class ConcreteBinary < Binary
+ end
+ end
+
+ 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
+
+ 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
+ end
+end
diff --git a/spec/algebra/unit/predicates/equality_spec.rb b/spec/algebra/unit/predicates/equality_spec.rb
new file mode 100644
index 0000000000..7d1d79ff35
--- /dev/null
+++ b/spec/algebra/unit/predicates/equality_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+module Arel
+ module Predicates
+ describe Equality do
+ before do
+ @relation1 = Arel::Table.new(:users)
+ @relation2 = Arel::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)
+ 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)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/algebra/unit/predicates/in_spec.rb b/spec/algebra/unit/predicates/in_spec.rb
new file mode 100644
index 0000000000..b9e15d63a4
--- /dev/null
+++ b/spec/algebra/unit/predicates/in_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+module Arel
+ module Predicates
+ describe In do
+ before do
+ @relation = Table.new(:users)
+ @attribute = @relation[:id]
+ end
+ end
+ end
+end