diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 20:47:02 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 20:47:02 -0700 |
commit | 89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8 (patch) | |
tree | 2e7fe3a9a814bc0ffacc48c50e0bc4d5de18bb0d /spec | |
parent | 9771b2f3a3fdb45517a132228a1129718acd2fac (diff) | |
download | rails-89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8.tar.gz rails-89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8.tar.bz2 rails-89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8.zip |
added attribute.eq(nil)
- produces attribute IS NULL
Diffstat (limited to 'spec')
-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 |