Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6967 from frodsan/quite_as_duration

fix quoting for ActiveSupport::Duration instances
  • Loading branch information...
commit 6c9c50c30fe2e9a0e39216801f96b52a2df3097d 2 parents 3257355 + b5bb353
@rafaelfranca rafaelfranca authored
View
2  activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -31,7 +31,7 @@ def quote(value, column = nil)
# BigDecimals need to be put in a non-normalized form and quoted.
when nil then "NULL"
when BigDecimal then value.to_s('F')
- when Numeric then value.to_s
+ when Numeric, ActiveSupport::Duration then value.to_s
when Date, Time then "'#{quoted_date(value)}'"
when Symbol then "'#{quote_string(value.to_s)}'"
when Class then "'#{value.to_s}'"
View
6 activerecord/test/cases/column_test.rb
@@ -76,6 +76,12 @@ def test_type_cast_date
date_string = Time.now.utc.strftime("%F")
assert_equal date_string, column.type_cast(date_string).strftime("%F")
end
+
+ def test_type_cast_duration_to_integer
+ column = Column.new("field", nil, "integer")
+ assert_equal 1800, column.type_cast(30.minutes)
+ assert_equal 7200, column.type_cast(2.hours)
+ end
end
end
end
View
8 activerecord/test/cases/quoting_test.rb
@@ -216,6 +216,14 @@ def string_to_binary(value)
def test_string_with_crazy_column
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo))
end
+
+ def test_quote_duration
+ assert_equal "1800", @quoter.quote(30.minutes)
+ end
+
+ def test_quote_duration_int_column
+ assert_equal "7200", @quoter.quote(2.hours, FakeColumn.new(:integer))
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.