Permalink
Browse files

PostgreSQL, Fix handling of exclusive lower bound for int/date ranges.

[River MacLeod & Yves Senn]

Closes #14797.

This behavior is fixed on `master` by using `from.succ`. However, the
lower bownds exclusion is flawed and was deprecated. This fix is to make
it behave consistently until it's removed.
  • Loading branch information...
1 parent 98b56ed commit 099efc0c53edc02a252ef92ab1ba4b1ebdc5452f @anm anm committed with senny Apr 18, 2014
@@ -1,3 +1,7 @@
+* Fix excluding lower bounds of PostgreSQL date and int ranges.
+
+ *River MacLeod*, *Yves Senn*
+
* When using a custom `join_table` name on a `habtm`, rails was not saving it
on Reflections. This causes a problem when rails loads fixtures, because it
uses the reflections to set database with fixtures.
@@ -137,7 +137,7 @@ def type_cast(value)
case @subtype
when :date
from = ConnectionAdapters::Column.value_to_date(extracted[:from])
- from -= 1.day if extracted[:exclude_start]
+ from += 1.day if extracted[:exclude_start]
to = ConnectionAdapters::Column.value_to_date(extracted[:to])
when :decimal
from = BigDecimal.new(extracted[:from].to_s)
@@ -148,7 +148,7 @@ def type_cast(value)
to = ConnectionAdapters::Column.string_to_time(extracted[:to])
when :integer
from = to_integer(extracted[:from]) rescue value ? 1 : 0
- from -= 1 if extracted[:exclude_start]
+ from += 1 if extracted[:exclude_start]
to = to_integer(extracted[:to]) rescue value ? 1 : 0
else
return value
@@ -203,6 +203,19 @@ def test_update_int8range
assert_nil_round_trip(@first_range, :int8_range, 39999...39999)
end
+ def test_exclude_beginning_for_int_ranges
+ range = PostgresqlRange.create!(int4_range: "(1, 10]")
+ assert_equal 2..10, range.int4_range
+
+ range = PostgresqlRange.create!(int8_range: "(10, 100]")
+ assert_equal 11..100, range.int8_range
+ end
+
+ def test_exclude_beginning_for_date_ranges
+ range = PostgresqlRange.create!(date_range: "(''2012-01-02'', ''2012-01-04'']")
+ assert_equal Date.new(2012, 1, 3)..Date.new(2012, 1, 4), range.date_range
+ end
+
private
def assert_equal_round_trip(range, attribute, value)
round_trip(range, attribute, value)

0 comments on commit 099efc0

Please sign in to comment.