Skip to content

Commit

Permalink
Merge pull request #6967 from frodsan/quite_as_duration
Browse files Browse the repository at this point in the history
fix quoting for ActiveSupport::Duration instances
  • Loading branch information
rafaelfranca committed Jul 5, 2012
2 parents 3257355 + b5bb353 commit 6c9c50c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Expand Up @@ -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}'"
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/column_test.rb
Expand Up @@ -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
8 changes: 8 additions & 0 deletions activerecord/test/cases/quoting_test.rb
Expand Up @@ -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

0 comments on commit 6c9c50c

Please sign in to comment.