class PostgresqlEnumTest
Public Instance Methods
setup()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 13 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
test_assigning_enum_to_nil()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 86 def test_assigning_enum_to_nil model = PostgresqlEnum.new(current_mood: nil) assert_nil model.current_mood assert model.save assert_nil model.reload.current_mood end
test_column()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 31 def test_column column = PostgresqlEnum.columns_hash["current_mood"] assert_equal :enum, column.type assert_equal "mood", column.sql_type assert_not column.array? type = PostgresqlEnum.type_for_attribute("current_mood") assert_not type.binary? end
test_enum_defaults()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 41 def test_enum_defaults @connection.add_column "postgresql_enums", "good_mood", :mood, default: "happy" PostgresqlEnum.reset_column_information assert_equal "happy", PostgresqlEnum.column_defaults["good_mood"] assert_equal "happy", PostgresqlEnum.new.good_mood ensure PostgresqlEnum.reset_column_information end
test_enum_mapping()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 51 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
test_enum_type_cast()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 79 def test_enum_type_cast enum = PostgresqlEnum.new enum.current_mood = :happy assert_equal "happy", enum.current_mood end
test_invalid_enum_update()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 62 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
test_no_oid_warning()
click to toggle source
# File activerecord/test/cases/adapters/postgresql/enum_test.rb, line 72 def test_no_oid_warning @connection.execute "INSERT INTO postgresql_enums VALUES (1, 'sad');" stderr_output = capture(:stderr) { PostgresqlEnum.first } assert stderr_output.blank? end