aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/selection_spec.rb
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-12 18:57:22 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-12 18:57:22 -0800
commit45d2557ae097da1e5dd3dc532444233b4fed0b31 (patch)
tree5b114baa2fe0791435b750d2251f5453263f84e5 /spec/active_relation/relations/selection_spec.rb
parentc2cbe7bb27b6cd2e136ac06f4f36d6de0ec52459 (diff)
downloadrails-45d2557ae097da1e5dd3dc532444233b4fed0b31.tar.gz
rails-45d2557ae097da1e5dd3dc532444233b4fed0b31.tar.bz2
rails-45d2557ae097da1e5dd3dc532444233b4fed0b31.zip
missing files
Diffstat (limited to 'spec/active_relation/relations/selection_spec.rb')
-rw-r--r--spec/active_relation/relations/selection_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/active_relation/relations/selection_spec.rb b/spec/active_relation/relations/selection_spec.rb
new file mode 100644
index 0000000000..90dc3169b6
--- /dev/null
+++ b/spec/active_relation/relations/selection_spec.rb
@@ -0,0 +1,42 @@
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
+
+describe ActiveRelation::Relations::Selection do
+ before do
+ @relation1 = ActiveRelation::Relations::Table.new(:foo)
+ @relation2 = ActiveRelation::Relations::Table.new(:bar)
+ @predicate1 = ActiveRelation::Predicates::Equality.new(@relation1[:id], @relation2[:foo_id])
+ @predicate2 = ActiveRelation::Predicates::LessThan.new(@relation1[:age], 2)
+ end
+
+ describe '#initialize' do
+ it "manufactures nested selection relations if multiple predicates are provided" do
+ ActiveRelation::Relations::Selection.new(@relation1, @predicate1, @predicate2). \
+ should == ActiveRelation::Relations::Selection.new(ActiveRelation::Relations::Selection.new(@relation1, @predicate2), @predicate1)
+ end
+ end
+
+ describe '#qualify' do
+ it "distributes over the relation and predicates" do
+ ActiveRelation::Relations::Selection.new(@relation1, @predicate1).qualify. \
+ should == ActiveRelation::Relations::Selection.new(@relation1.qualify, @predicate1.qualify)
+ end
+ end
+
+ describe '#to_sql' do
+ it "manufactures sql with where clause conditions" do
+ ActiveRelation::Relations::Selection.new(@relation1, @predicate1).to_sql.should be_like("""
+ SELECT `foo`.`name`, `foo`.`id`
+ FROM `foo`
+ WHERE `foo`.`id` = `bar`.`foo_id`
+ """)
+ end
+
+ it "allows arbitrary sql" do
+ ActiveRelation::Relations::Selection.new(@relation1, "asdf").to_sql.should be_like("""
+ SELECT `foo`.`name`, `foo`.`id`
+ FROM `foo`
+ WHERE asdf
+ """)
+ end
+ end
+end \ No newline at end of file