diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-10-16 21:24:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-16 21:24:44 -0400 |
commit | 4a8f4124bf019fe87989aeccc99d812fea25eb80 (patch) | |
tree | 121f4e9ca687203579c1943d64a5d7941cf38d54 /activesupport | |
parent | e986cb49c8a475c48819cee451c73dbd005904c4 (diff) | |
parent | 5e6fa51b01a5da7a09c6365923d5cb2c16a7e7a6 (diff) | |
download | rails-4a8f4124bf019fe87989aeccc99d812fea25eb80.tar.gz rails-4a8f4124bf019fe87989aeccc99d812fea25eb80.tar.bz2 rails-4a8f4124bf019fe87989aeccc99d812fea25eb80.zip |
Merge pull request #30901 from aditya-kapoor/fix-range-to-s
Fix `to_s(:db)` for range comprising of alphabets.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/conversions.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/range_ext_test.rb | 5 |
2 files changed, 12 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/conversions.rb b/activesupport/lib/active_support/core_ext/range/conversions.rb index 37868f5875..8832fbcb3c 100644 --- a/activesupport/lib/active_support/core_ext/range/conversions.rb +++ b/activesupport/lib/active_support/core_ext/range/conversions.rb @@ -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. diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index a96e3d62e8..0467123e55 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -16,6 +16,11 @@ class RangeTest < ActiveSupport::TestCase 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) |