Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty string saving for ranges #48507

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def type_cast_for_schema(value)
end

def cast_value(value)
return if value == "empty"
return if ["empty", ""].include? value
return value unless value.is_a?(::String)

extracted = extract_bounds(value)
Expand Down
14 changes: 14 additions & 0 deletions activerecord/test/cases/adapters/postgresql/range_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,20 @@ def test_endless_range_values
assert_equal 0.5...Float::INFINITY, record.float_range
end

def test_empty_string_range_values
record = PostgresqlRange.create!(
int4_range: "",
int8_range: "",
float_range: ""
)

record = PostgresqlRange.find(record.id)

assert_nil record.int4_range
assert_nil record.int8_range
assert_nil record.float_range
end

private
def assert_equal_round_trip(range, attribute, value)
round_trip(range, attribute, value)
Expand Down