Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Last active January 3, 2016 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsutphin/bc4dd4d531035259487d to your computer and use it in GitHub Desktop.
Save rsutphin/bc4dd4d531035259487d to your computer and use it in GitHub Desktop.
Demo of PostgreSQL ENUM-related regression from 3.2.16 to 4.0 (https://github.com/rails/rails/issues/7814)

Demonstration of PostgreSQL ENUM regression on Rails 4

Prereqs:

  • Rails 3.2.16 and Rails 4.0.2 installed, including each kind of app's default dependencies. (E.g., sdoc for Rails 4, etc.)
  • PostgreSQL configured so that dropdb and createdb work without authentication

To run:

  • Clone this gist

  • Edit database.yml so that the username and password are ones that will work on your database.

  • Run:

    $ RAILS_VERSION=3.2.16 ./pg_enum_and_fixtures_repo.sh

  • Observe that the test passes

  • Run:

    $ RAILS_VERSION=4.0.2 ./pg_enum_and_fixtures_repo.sh

  • Observe that the test fails

#!/bin/bash
rm -rf app
rails _${RAILS_VERSION}_ new app -G -S -J --skip-bundle -d postgresql
cp database.yml app/config/database.yml
cd app
mkdir -p db/migrate
echo "class TestSchema < ActiveRecord::Migration
def up
execute %q{CREATE TYPE primary_color AS ENUM ('red', 'green', 'blue')}
execute %q{CREATE TABLE items (id SERIAL PRIMARY KEY, color PRIMARY_COLOR)}
end
def down
end
end
" > db/migrate/0_test_schema.rb
echo "class Item < ActiveRecord::Base;
end" > app/models/item.rb
echo "blue_thing:
color: 'blue'" > test/fixtures/items.yml
mkdir -p test/unit
echo "require 'test_helper'
class ItemTest < ActiveSupport::TestCase
fixtures :items
test 'blue thing is blue' do
assert_equal 'blue', items(:blue_thing).color
end
end" > test/unit/item_test.rb
l=$((`wc -l < config/application.rb` - 2))
sed "${l}i\\
config.active_record.schema_format = :sql
" config/application.rb > config/application.rb.new
mv config/application.rb.new config/application.rb
dropdb app_development --if-exists
dropdb app_test --if-exists
createdb app_development
createdb app_test
rake db:migrate
rake test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment