-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not rely on the column type when quoting infinity
- Loading branch information
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
activerecord/test/cases/adapters/postgresql/infinity_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "cases/helper" | ||
|
||
class PostgresqlInfinityTest < ActiveRecord::TestCase | ||
class PostgresqlInfinity < ActiveRecord::Base | ||
end | ||
|
||
setup do | ||
@connection = ActiveRecord::Base.connection | ||
@connection.create_table(:postgresql_infinities) do |t| | ||
t.float :float | ||
t.datetime :datetime | ||
end | ||
end | ||
|
||
teardown do | ||
@connection.execute("DROP TABLE IF EXISTS postgresql_infinities") | ||
end | ||
|
||
test "type casting infinity on a float column" do | ||
record = PostgresqlInfinity.create!(float: Float::INFINITY) | ||
record.reload | ||
assert_equal Float::INFINITY, record.float | ||
end | ||
|
||
test "update_all with infinity on a float column" do | ||
record = PostgresqlInfinity.create! | ||
PostgresqlInfinity.update_all(float: Float::INFINITY) | ||
record.reload | ||
assert_equal Float::INFINITY, record.float | ||
end | ||
|
||
test "type casting infinity on a datetime column" do | ||
record = PostgresqlInfinity.create!(datetime: Float::INFINITY) | ||
record.reload | ||
assert_equal Float::INFINITY, record.datetime | ||
end | ||
|
||
test "update_all with infinity on a datetime column" do | ||
record = PostgresqlInfinity.create! | ||
PostgresqlInfinity.update_all(datetime: Float::INFINITY) | ||
record.reload | ||
assert_equal Float::INFINITY, record.datetime | ||
end | ||
end |