From cfb22381451b8984c57f3be2bd39819a0e8ad858 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 11 Feb 2014 14:41:11 +0100 Subject: test case for custom PostgreSQL enum type. This test currently outputs the following warning: ``` unknown OID: current_mood(3567879) (SELECT "postgresql_enums".* FROM "postgresql_enums" ORDER BY "postgresql_enums"."id" ASC LIMIT 1) unknown OID: current_mood(3567879) (SELECT "postgresql_enums".* FROM "postgresql_enums" WHERE "postgresql_enums"."id" = $1 LIMIT 1) ``` We have an open PR to deal with this issue. It will dynamically register the OID for enum columns. This test case is merely to exhibit the current behavior of PostgreSQL enum columns. --- .../test/cases/adapters/postgresql/enum_test.rb | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 activerecord/test/cases/adapters/postgresql/enum_test.rb (limited to 'activerecord/test/cases/adapters') diff --git a/activerecord/test/cases/adapters/postgresql/enum_test.rb b/activerecord/test/cases/adapters/postgresql/enum_test.rb new file mode 100644 index 0000000000..bf8dbd6c3f --- /dev/null +++ b/activerecord/test/cases/adapters/postgresql/enum_test.rb @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +require "cases/helper" +require 'active_record/base' +require 'active_record/connection_adapters/postgresql_adapter' + +class PostgresqlEnumTest < ActiveRecord::TestCase + class PostgresqlEnum < ActiveRecord::Base + self.table_name = "postgresql_enums" + end + + def teardown + @connection.execute 'DROP TABLE IF EXISTS postgresql_enums' + @connection.execute 'DROP TYPE IF EXISTS mood' + end + + def setup + @connection = ActiveRecord::Base.connection + @connection.transaction do + @connection.execute <<-SQL + CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); + SQL + @connection.create_table('postgresql_enums') do |t| + t.column :current_mood, :mood + end + end + end + + def test_enum_mapping + @connection.execute "INSERT INTO postgresql_enums VALUES (1, 'sad');" + enum = PostgresqlEnum.first + assert_equal "sad", enum.current_mood + + enum.current_mood = "happy" + enum.save! + + assert_equal "happy", enum.reload.current_mood + end +end -- cgit v1.2.3