Skip to content
Browse files

Bug fix: Don't use #delegate to declare delegations when intentionall…

…y delegating to nil

This accounts for a behavior change after Rails 2.3
  • Loading branch information...
1 parent 019f35a commit 724b48620c5cf21920717d66eea6e7cd4148b535 Lee Bankewitz committed Aug 10, 2009
View
10 lib/arel/engines/sql/primitives.rb
@@ -3,7 +3,7 @@ class SqlLiteral < String
def relation
nil
end
-
+
def to_sql(formatter = nil)
self
end
@@ -28,7 +28,13 @@ def to_sql(formatter = Sql::WhereCondition.new(relation))
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
View
15 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
View
2 spec/connections/mysql_connection.rb
@@ -7,7 +7,7 @@
ActiveRecord::Base.configurations = {
'unit' => {
:adapter => 'mysql',
- :username => 'rails',
+ :username => 'root',
:encoding => 'utf8',
:database => 'arel_unit',
}

0 comments on commit 724b486

Please sign in to comment.
Something went wrong with that request. Please try again.