From a6bc35c82cd58aac61608391f38fda4e034be0f7 Mon Sep 17 00:00:00 2001 From: Zach Ohlgren Date: Thu, 25 Apr 2013 17:20:33 -0700 Subject: Fix bug in ActiveRecord::Sanitization#sanitize_sql_hash_for_conditions Fixing CHANGLOG description Remove extra line. Remove blank lines. --- activerecord/CHANGELOG.md | 13 ++++++++++--- activerecord/lib/active_record/sanitization.rb | 2 +- activerecord/test/cases/sanitize_test.rb | 4 ++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 1304bcb7e4..a3c01bd03b 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Fixed a bug in ActiveRecord#sanitize_sql_hash_for_conditions in which + `self.class` is an argument to PredicateBuilder#build_from_hash + causing PredicateBuilder to call non-existant method + Class#reflect_on_association. + + *Zach Ohlgren* + * While removing index if column option is missing then raise IrreversibleMigration exception. Following code should raise `IrreversibleMigration`. But the code was @@ -80,9 +87,9 @@ * Abort a rake task when missing db/structure.sql like `db:schema:load` task. *kennyj* - + * rake:db:test:prepare falls back to original environment after execution. - + *Slava Markevich* -Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes. +Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes. \ No newline at end of file diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 3c5b871e99..0ed97b66d6 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -89,7 +89,7 @@ module ActiveRecord attrs = expand_hash_conditions_for_aggregates(attrs) table = Arel::Table.new(table_name, arel_engine).alias(default_table_name) - PredicateBuilder.build_from_hash(self.class, attrs, table).map { |b| + PredicateBuilder.build_from_hash(self, attrs, table).map { |b| connection.visitor.accept b }.join(' AND ') end diff --git a/activerecord/test/cases/sanitize_test.rb b/activerecord/test/cases/sanitize_test.rb index 817897ceac..09e02b29da 100644 --- a/activerecord/test/cases/sanitize_test.rb +++ b/activerecord/test/cases/sanitize_test.rb @@ -5,6 +5,10 @@ class SanitizeTest < ActiveRecord::TestCase def setup end + def test_sanitize_sql_hash_handles_associations + assert_equal "`adorable_animals`.`name` = 'Bambi'", Binary.send(:sanitize_sql_hash, {adorable_animals: {name: 'Bambi'}}) + end + def test_sanitize_sql_array_handles_string_interpolation quoted_bambi = ActiveRecord::Base.connection.quote_string("Bambi") assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=%s", "Bambi"]) -- cgit v1.2.3