From 5c55aafd38f45ac019573f98438ffdbdc8c580f9 Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Mon, 9 Dec 2013 18:52:36 +0100 Subject: Add Enum type to postgresql adapter's oids to prevent unknown OID warnings. --- .../test/cases/adapters/postgresql/enum_test.rb | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/adapters/postgresql/enum_test.rb b/activerecord/test/cases/adapters/postgresql/enum_test.rb index bf8dbd6c3f..a9a2901436 100644 --- a/activerecord/test/cases/adapters/postgresql/enum_test.rb +++ b/activerecord/test/cases/adapters/postgresql/enum_test.rb @@ -23,6 +23,8 @@ class PostgresqlEnumTest < ActiveRecord::TestCase t.column :current_mood, :mood end end + # reload type map after creating the enum type + @connection.send(:reload_type_map) end def test_enum_mapping @@ -35,4 +37,30 @@ class PostgresqlEnumTest < ActiveRecord::TestCase assert_equal "happy", enum.reload.current_mood end + + def test_invalid_enum_update + @connection.execute "INSERT INTO postgresql_enums VALUES (1, 'sad');" + enum = PostgresqlEnum.first + enum.current_mood = "angry" + + assert_raise ActiveRecord::StatementInvalid do + enum.save + end + end + + def test_no_oid_warning + @connection.execute "INSERT INTO postgresql_enums VALUES (1, 'sad');" + stderr_output = capture(:stderr) { + enum = PostgresqlEnum.first + } + + assert stderr_output.blank? + end + + def test_enum_type_cast + enum = PostgresqlEnum.new + enum.current_mood = :happy + + assert_equal "happy", enum.current_mood + end end -- cgit v1.2.3