aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2008-05-27 21:56:38 -0400
committerBryan Helmkamp <bryan@brynary.com>2008-05-27 21:56:38 -0400
commitaeb09afd73cf188c6aee22bf4dd0f1beb937ac22 (patch)
tree051780a6e22ca2e0d61e9361abc8037ae8e492c3 /spec
parent191b2b7b7e6e2cf4fc5a24321bc9b1e593f96551 (diff)
downloadrails-aeb09afd73cf188c6aee22bf4dd0f1beb937ac22.tar.gz
rails-aeb09afd73cf188c6aee22bf4dd0f1beb937ac22.tar.bz2
rails-aeb09afd73cf188c6aee22bf4dd0f1beb937ac22.zip
AND/OR support for predicates
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/unit/predicates/binary_spec.rb27
-rw-r--r--spec/arel/unit/predicates/predicates_spec.rb33
2 files changed, 60 insertions, 0 deletions
diff --git a/spec/arel/unit/predicates/binary_spec.rb b/spec/arel/unit/predicates/binary_spec.rb
index 5dee4833d4..56fcf2d8ad 100644
--- a/spec/arel/unit/predicates/binary_spec.rb
+++ b/spec/arel/unit/predicates/binary_spec.rb
@@ -13,6 +13,33 @@ module Arel
end
end
+ describe "with compound predicates" do
+ before do
+ @operand1 = ConcreteBinary.new(@attribute1, 1)
+ @operand2 = ConcreteBinary.new(@attribute2, "name")
+ end
+
+ describe Or do
+ describe "#to_sql" do
+ it "manufactures sql with an OR operation" do
+ Or.new(@operand1, @operand2).to_sql.should be_like("
+ (`users`.`id` <=> 1 OR `users`.`name` <=> 'name')
+ ")
+ end
+ end
+ end
+
+ describe And do
+ describe "#to_sql" do
+ it "manufactures sql with an AND operation" do
+ And.new(@operand1, @operand2).to_sql.should be_like("
+ (`users`.`id` <=> 1 AND `users`.`name` <=> 'name')
+ ")
+ end
+ end
+ end
+ end
+
describe '#to_sql' do
describe 'when relating two attributes' do
it 'manufactures sql with a binary operation' do
diff --git a/spec/arel/unit/predicates/predicates_spec.rb b/spec/arel/unit/predicates/predicates_spec.rb
new file mode 100644
index 0000000000..d11637cabe
--- /dev/null
+++ b/spec/arel/unit/predicates/predicates_spec.rb
@@ -0,0 +1,33 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Predicate do
+ before do
+ @relation = Table.new(:users)
+ @attribute1 = @relation[:id]
+ @attribute2 = @relation[:name]
+ @operand1 = Equality.new(@attribute1, 1)
+ @operand2 = Equality.new(@attribute2, "name")
+ end
+
+ describe "when being combined with another predicate with AND logic" do
+ describe "#to_sql" do
+ it "manufactures sql with an AND operation" do
+ @operand1.and(@operand2).to_sql.should be_like("
+ (`users`.`id` = 1 AND `users`.`name` = 'name')
+ ")
+ end
+ end
+ end
+
+ describe "when being combined with another predicate with OR logic" do
+ describe "#to_sql" do
+ it "manufactures sql with an OR operation" do
+ @operand1.or(@operand2).to_sql.should be_like("
+ (`users`.`id` = 1 OR `users`.`name` = 'name')
+ ")
+ end
+ end
+ end
+ end
+end \ No newline at end of file