diff options
Diffstat (limited to 'spec/relations/join_relation_spec.rb')
-rw-r--r-- | spec/relations/join_relation_spec.rb | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/spec/relations/join_relation_spec.rb b/spec/relations/join_relation_spec.rb index 7309563cd5..c6fae90ff3 100644 --- a/spec/relations/join_relation_spec.rb +++ b/spec/relations/join_relation_spec.rb @@ -1,20 +1,45 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper') -describe JoinRelation, 'between two relations' do +describe 'between two relations' do before do @relation1 = TableRelation.new(:foo) @relation2 = TableRelation.new(:bar) - @predicate = Predicate.new + @predicate = EqualityPredicate.new(@relation1[:a], @relation2[:b]) end - describe JoinRelation, '==' do - it "obtains if the two relations and the predicate are identical" do + describe '==' do + it 'obtains if the two relations and the predicate are identical' do JoinRelation.new(@relation1, @relation2, @predicate).should == JoinRelation.new(@relation1, @relation2, @predicate) JoinRelation.new(@relation1, @relation2, @predicate).should_not == JoinRelation.new(@relation1, @relation1, @predicate) end - it "is commutative on the relations" do + it 'is commutative on the relations' do JoinRelation.new(@relation1, @relation2, @predicate).should == JoinRelation.new(@relation2, @relation1, @predicate) end end + + describe '#to_sql' do + before do + @relation1 = @relation1.select(@relation1[:c] == @relation2[:d]) + class ConcreteJoinRelation < JoinRelation + def join_name + :inner_join + end + end + end + + it 'manufactures sql joining the two tables on the predicate, merging the selects' do + ConcreteJoinRelation.new(@relation1, @relation2, @predicate).to_sql.to_s.should == SelectBuilder.new do + select :* + from :foo do + inner_join :bar do + equals 'foo.a', 'bar.b' + end + end + where do + equals 'foo.c', 'bar.d' + end + end.to_s + end + end end
\ No newline at end of file |