diff options
-rw-r--r-- | lib/arel/engines/sql/primitives.rb | 10 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/predicates/equality_spec.rb | 15 | ||||
-rw-r--r-- | spec/connections/mysql_connection.rb | 2 |
3 files changed, 24 insertions, 3 deletions
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb index bb3bed78e6..16e1abdf59 100644 --- a/lib/arel/engines/sql/primitives.rb +++ b/lib/arel/engines/sql/primitives.rb @@ -3,7 +3,7 @@ module Arel def relation nil end - + def to_sql(formatter = nil) self end @@ -28,7 +28,13 @@ module Arel end class Value - delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value + def inclusion_predicate_sql + value.inclusion_predicate_sql + end + + def equality_predicate_sql + value.equality_predicate_sql + end def to_sql(formatter = Sql::WhereCondition.new(relation)) formatter.value value diff --git a/spec/arel/engines/sql/unit/predicates/equality_spec.rb b/spec/arel/engines/sql/unit/predicates/equality_spec.rb index 688a6a20be..e874d07bf3 100644 --- a/spec/arel/engines/sql/unit/predicates/equality_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/equality_spec.rb @@ -41,6 +41,21 @@ module Arel end end end + + describe "when relating to a nil Value" do + it "manufactures an IS NULL predicate" do + value = nil.bind(@relation1) + sql = Equality.new(@attribute1, value).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{`users`.`id` IS NULL}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{"users"."id" IS NULL}) + end + end + end end end end diff --git a/spec/connections/mysql_connection.rb b/spec/connections/mysql_connection.rb index 6e2950f7dc..bcba2b3843 100644 --- a/spec/connections/mysql_connection.rb +++ b/spec/connections/mysql_connection.rb @@ -7,7 +7,7 @@ ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.configurations = { 'unit' => { :adapter => 'mysql', - :username => 'rails', + :username => 'root', :encoding => 'utf8', :database => 'arel_unit', } |