Last active
January 11, 2016 15:52
-
-
Save claudiob/ae3452eaa3cf6307453a to your computer and use it in GitHub Desktop.
STI + enum fail in Rails 5.0.0.beta1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'rails', '>= 5.0.0.beta1', '< 5.1' | |
# gem 'rails' ## use this instead to test against the current Rails (4.2) | |
gem 'sqlite3' | |
end | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :activities, force: true do |t| | |
t.string :type | |
t.integer :status, default: 0, null: false | |
end | |
end | |
class Activity < ActiveRecord::Base | |
enum status: %i(pending failed successful) | |
end | |
class Snapshot < Activity | |
end | |
class Adjustment < Activity | |
end | |
class BugTest < Minitest::Test | |
def test_sti_enum | |
Adjustment.create! status: 'successful' | |
Snapshot.create! status: 'successful' | |
# The following passes both on Rails 4.2 and on Rails 5.0.0.beta1. | |
assert Snapshot.first.is_a?(Snapshot) | |
# The following fails only on Rails 5.0.0.beta1 (returns an Adjustment). | |
assert Snapshot.successful.first.is_a?(Snapshot) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When run against Rails 4.2, these are the SQL queries I see in the log file:
However, when run against Rails 5.0.0.beta1, these are the SQL queries I see in the log file: