aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/join_spec.rb
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2008-01-14 10:50:46 -0500
committerBryan Helmkamp <bryan@brynary.com>2008-01-14 10:50:46 -0500
commit553eb0ad490abc7f85d9836c3ba959ab771d3cf4 (patch)
treebaa9714465488d77980e8d252a82849b32844d3b /spec/active_relation/relations/join_spec.rb
parent17a5fd13bc4ba8405d95e90d12b87dcd7e5bea5b (diff)
downloadrails-553eb0ad490abc7f85d9836c3ba959ab771d3cf4.tar.gz
rails-553eb0ad490abc7f85d9836c3ba959ab771d3cf4.tar.bz2
rails-553eb0ad490abc7f85d9836c3ba959ab771d3cf4.zip
Remove ActiveRelation sub-modules and refactor specs
Diffstat (limited to 'spec/active_relation/relations/join_spec.rb')
-rw-r--r--spec/active_relation/relations/join_spec.rb64
1 files changed, 33 insertions, 31 deletions
diff --git a/spec/active_relation/relations/join_spec.rb b/spec/active_relation/relations/join_spec.rb
index 2a84a92b70..25c505e371 100644
--- a/spec/active_relation/relations/join_spec.rb
+++ b/spec/active_relation/relations/join_spec.rb
@@ -1,43 +1,45 @@
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
-describe ActiveRelation::Relations::Join do
- before do
- @relation1 = ActiveRelation::Relations::Table.new(:foo)
- @relation2 = ActiveRelation::Relations::Table.new(:bar)
- @predicate = ActiveRelation::Predicates::Equality.new(@relation1[:id], @relation2[:id])
- end
-
- describe '==' do
- it 'obtains if the two relations and the predicate are identical' do
- ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation2, @predicate)
- ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation2, @predicate).should_not == ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation1, @predicate)
+module ActiveRelation
+ describe Join do
+ before do
+ @relation1 = Table.new(:foo)
+ @relation2 = Table.new(:bar)
+ @predicate = Equality.new(@relation1[:id], @relation2[:id])
end
- it 'is commutative on the relations' do
- ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == ActiveRelation::Relations::Join.new("INNER JOIN", @relation2, @relation1, @predicate)
- end
- end
+ describe '==' do
+ it 'obtains if the two relations and the predicate are identical' do
+ Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation1, @relation2, @predicate)
+ Join.new("INNER JOIN", @relation1, @relation2, @predicate).should_not == Join.new("INNER JOIN", @relation1, @relation1, @predicate)
+ end
- describe '#qualify' do
- it 'distributes over the relations and predicates' do
- ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation2, @predicate).qualify. \
- should == ActiveRelation::Relations::Join.new("INNER JOIN", @relation1.qualify, @relation2.qualify, @predicate.qualify)
+ it 'is commutative on the relations' do
+ Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation2, @relation1, @predicate)
+ end
end
- end
- describe '#to_sql' do
- before do
- @relation1 = @relation1.select(@relation1[:id].equals(1))
+ describe '#qualify' do
+ it 'distributes over the relations and predicates' do
+ Join.new("INNER JOIN", @relation1, @relation2, @predicate).qualify. \
+ should == Join.new("INNER JOIN", @relation1.qualify, @relation2.qualify, @predicate.qualify)
+ end
end
+
+ describe '#to_sql' do
+ before do
+ @relation1 = @relation1.select(@relation1[:id].equals(1))
+ end
- it 'manufactures sql joining the two tables on the predicate, merging the selects' do
- ActiveRelation::Relations::Join.new("INNER JOIN", @relation1, @relation2, @predicate).to_sql.should be_like("""
- SELECT `foo`.`name`, `foo`.`id`, `bar`.`name`, `bar`.`foo_id`, `bar`.`id`
- FROM `foo`
- INNER JOIN `bar` ON `foo`.`id` = `bar`.`id`
- WHERE
- `foo`.`id` = 1
- """)
+ it 'manufactures sql joining the two tables on the predicate, merging the selects' do
+ Join.new("INNER JOIN", @relation1, @relation2, @predicate).to_sql.should be_like("""
+ SELECT `foo`.`name`, `foo`.`id`, `bar`.`name`, `bar`.`foo_id`, `bar`.`id`
+ FROM `foo`
+ INNER JOIN `bar` ON `foo`.`id` = `bar`.`id`
+ WHERE
+ `foo`.`id` = 1
+ """)
+ end
end
end
end \ No newline at end of file