Last active
September 18, 2017 08:01
-
-
Save claudiob/7ba25b10713673fbb537 to your computer and use it in GitHub Desktop.
STI with index broken on Rails 5
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', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
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 :resources, force: :cascade do |t| | |
t.string :type, null: false, default: 'Resource' | |
t.datetime :created_at, null: false | |
t.datetime :updated_at, null: false | |
end | |
end | |
class Resource < ActiveRecord::Base | |
end | |
class Channel < Resource | |
end | |
class BugTest < Minitest::Test | |
def test_sti_with_index_on_type_raises_error_on_rails5_but_not_on4 | |
# on Rails 4: | |
# => Everything Ok | |
# on Rails 5.0.0.beta1 (and master@9864bce): | |
# => ActiveRecord::SubclassNotFound: Invalid single-table inheritance type: Resource is not a subclass of Channel | |
Channel.new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For googles, the discussion is here: rails/rails#23285