diff options
Diffstat (limited to 'spec/active_relation/unit/predicates/equality_spec.rb')
-rw-r--r-- | spec/active_relation/unit/predicates/equality_spec.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/spec/active_relation/unit/predicates/equality_spec.rb b/spec/active_relation/unit/predicates/equality_spec.rb index 499b13383d..613236ad04 100644 --- a/spec/active_relation/unit/predicates/equality_spec.rb +++ b/spec/active_relation/unit/predicates/equality_spec.rb @@ -5,8 +5,8 @@ module ActiveRelation before do @relation1 = Table.new(:users) @relation2 = Table.new(:photos) - @attribute1 = @relation1[:name] - @attribute2 = @relation2[:name] + @attribute1 = @relation1[:id] + @attribute2 = @relation2[:user_id] end describe '==' do @@ -23,5 +23,27 @@ module ActiveRelation Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1) end end + + describe '#to_sql' do + describe 'when relating to a non-nil value' do + it "manufactures an equality predicate" do + Equality.new(@attribute1, @attribute2).to_sql.should be_like(" + `users`.`id` = `photos`.`user_id` + ") + end + end + + describe 'when relation to a nil value' do + before do + @nil = nil.bind(@relation1) + end + + it "manufactures an is null predicate" do + Equality.new(@attribute1, @nil).to_sql.should be_like(" + `users`.`id` IS NULL + ") + end + end + end end end
\ No newline at end of file |