diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-12 13:10:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-12 13:10:52 -0700 |
commit | 4b2e16ed248d294133b8c5212f5facac78625e42 (patch) | |
tree | fb6d050a97fccb99f3e0d9247d70b15b4fd9ff18 /activerecord | |
parent | 5b5ae01f294c2a305c62372be732cc59f97d3c06 (diff) | |
download | rails-4b2e16ed248d294133b8c5212f5facac78625e42.tar.gz rails-4b2e16ed248d294133b8c5212f5facac78625e42.tar.bz2 rails-4b2e16ed248d294133b8c5212f5facac78625e42.zip |
all columns respond to string_to_binary, so no need to check respond_to?
Diffstat (limited to 'activerecord')
3 files changed, 19 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index 1e0c5fe902..a3928b4504 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -14,8 +14,8 @@ module ActiveRecord value = value.to_s return "'#{quote_string(value)}'" unless column - if column.type == :binary && column.class.respond_to?(:string_to_binary) - "'#{quote_string(column.class.string_to_binary(value))}'" # ' (for ruby-mode) + if column.type == :binary + "'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode) elsif [:integer, :float].include?(column.type) (column.type == :integer ? value.to_i : value.to_f).to_s else diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 6480aeb171..60ccf9edf3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -114,6 +114,11 @@ module ActiveRecord type_cast(default) end + # Used to convert from Strings to BLOBs + def string_to_binary(value) + self.class.string_to_binary(value) + end + class << self # Used to convert from Strings to BLOBs def string_to_binary(value) @@ -268,6 +273,10 @@ module ActiveRecord # for generating a number of table creation or table changing SQL statements. class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc: + def string_to_binary(value) + value + end + def sql_type base.type_to_sql(type.to_sym, limit, precision, scale) rescue type end diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 4cc81d0735..2ef5b5a800 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -3,7 +3,12 @@ require "cases/helper" module ActiveRecord module ConnectionAdapters class QuotingTest < ActiveRecord::TestCase - class FakeColumn < Struct.new(:type) + class FakeColumn < ActiveRecord::ConnectionAdapters::Column + attr_accessor :type + + def initialize type + @type = type + end end def setup @@ -190,7 +195,7 @@ module ActiveRecord def test_quote_binary_with_string_to_binary col = Class.new(FakeColumn) { - def self.string_to_binary(value) + def string_to_binary(value) 'foo' end }.new(:binary) @@ -199,7 +204,7 @@ module ActiveRecord def test_quote_as_mb_chars_binary_column_with_string_to_binary col = Class.new(FakeColumn) { - def self.string_to_binary(value) + def string_to_binary(value) 'foo' end }.new(:binary) |