提交 4a8f4124 编写于 作者: S Sean Griffin 提交者: GitHub

Merge pull request #30901 from aditya-kapoor/fix-range-to-s

Fix `to_s(:db)` for range comprising of alphabets.
......@@ -2,7 +2,13 @@
module ActiveSupport::RangeWithFormat
RANGE_FORMATS = {
db: Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
db: -> (start, stop) do
case start
when String then "BETWEEN '#{start}' AND '#{stop}'"
else
"BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'"
end
end
}
# Convert range to a formatted string. See RANGE_FORMATS for predefined formats.
......
......@@ -16,6 +16,11 @@ def test_to_s_from_times
assert_equal "BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'", date_range.to_s(:db)
end
def test_to_s_with_alphabets
alphabet_range = ("a".."z")
assert_equal "BETWEEN 'a' AND 'z'", alphabet_range.to_s(:db)
end
def test_to_s_with_numeric
number_range = (1..100)
assert_equal "BETWEEN '1' AND '100'", number_range.to_s(:db)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册