class PostgresqlPointTest
Public Instance Methods
setup()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 21 def setup @connection = ActiveRecord::Base.connection @connection.create_table("postgresql_points") do |t| t.point :x t.point :y, default: [12.2, 13.3] t.point :z, default: "(14.4,15.5)" t.point :array_of_points, array: true t.point :legacy_x t.point :legacy_y, default: [12.2, 13.3] t.point :legacy_z, default: "(14.4,15.5)" end end
test_array_assignment()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 85 def test_array_assignment p = PostgresqlPoint.new(x: [1, 2]) assert_equal ActiveRecord::Point.new(1, 2), p.x end
test_array_of_points_round_trip()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 102 def test_array_of_points_round_trip expected_value = [ ActiveRecord::Point.new(1, 2), ActiveRecord::Point.new(2, 3), ActiveRecord::Point.new(3, 4), ] p = PostgresqlPoint.new(array_of_points: expected_value) assert_equal expected_value, p.array_of_points p.save! p.reload assert_equal expected_value, p.array_of_points end
test_column()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 38 def test_column column = PostgresqlPoint.columns_hash["x"] assert_equal :point, column.type assert_equal "point", column.sql_type assert_not column.array? type = PostgresqlPoint.type_for_attribute("x") assert_not type.binary? end
test_default()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 48 def test_default assert_equal ActiveRecord::Point.new(12.2, 13.3), PostgresqlPoint.column_defaults["y"] assert_equal ActiveRecord::Point.new(12.2, 13.3), PostgresqlPoint.new.y assert_equal ActiveRecord::Point.new(14.4, 15.5), PostgresqlPoint.column_defaults["z"] assert_equal ActiveRecord::Point.new(14.4, 15.5), PostgresqlPoint.new.z end
test_empty_string_assignment()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 97 def test_empty_string_assignment p = PostgresqlPoint.new(x: "") assert_nil p.x end
test_legacy_column()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 116 def test_legacy_column column = PostgresqlPoint.columns_hash["legacy_x"] assert_equal :point, column.type assert_equal "point", column.sql_type assert_not column.array? type = PostgresqlPoint.type_for_attribute("legacy_x") assert_not type.binary? end
test_legacy_default()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 126 def test_legacy_default assert_equal [12.2, 13.3], PostgresqlPoint.column_defaults["legacy_y"] assert_equal [12.2, 13.3], PostgresqlPoint.new.legacy_y assert_equal [14.4, 15.5], PostgresqlPoint.column_defaults["legacy_z"] assert_equal [14.4, 15.5], PostgresqlPoint.new.legacy_z end
test_legacy_mutation()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 152 def test_legacy_mutation p = PostgresqlPoint.create! legacy_x: [10, 20] p.legacy_x[1] = 25 p.save! p.reload assert_equal [10.0, 25.0], p.legacy_x assert_not p.changed? end
test_legacy_roundtrip()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 141 def test_legacy_roundtrip PostgresqlPoint.create! legacy_x: [10, 25.2] record = PostgresqlPoint.first assert_equal [10, 25.2], record.legacy_x record.legacy_x = [1.1, 2.2] record.save! assert record.reload assert_equal [1.1, 2.2], record.legacy_x end
test_legacy_schema_dumping()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 134 def test_legacy_schema_dumping output = dump_table_schema("postgresql_points") assert_match %r{t\.point\s+"legacy_x"$}, output assert_match %r{t\.point\s+"legacy_y",\s+default: \[12\.2, 13\.3\]$}, output assert_match %r{t\.point\s+"legacy_z",\s+default: \[14\.4, 15\.5\]$}, output end
test_mutation()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 74 def test_mutation p = PostgresqlPoint.create! x: ActiveRecord::Point.new(10, 20) p.x.y = 25 p.save! p.reload assert_equal ActiveRecord::Point.new(10.0, 25.0), p.x assert_not p.changed? end
test_roundtrip()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 63 def test_roundtrip PostgresqlPoint.create! x: [10, 25.2] record = PostgresqlPoint.first assert_equal ActiveRecord::Point.new(10, 25.2), record.x record.x = ActiveRecord::Point.new(1.1, 2.2) record.save! assert record.reload assert_equal ActiveRecord::Point.new(1.1, 2.2), record.x end
test_schema_dumping()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 56 def test_schema_dumping output = dump_table_schema("postgresql_points") assert_match %r{t\.point\s+"x"$}, output assert_match %r{t\.point\s+"y",\s+default: \[12\.2, 13\.3\]$}, output assert_match %r{t\.point\s+"z",\s+default: \[14\.4, 15\.5\]$}, output end
test_string_assignment()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/geometric_test.rb, line 91 def test_string_assignment p = PostgresqlPoint.new(x: "(1, 2)") assert_equal ActiveRecord::Point.new(1, 2), p.x end