Created
February 26, 2016 17:08
-
-
Save claudiob/e453503c47074bab1617 to your computer and use it in GitHub Desktop.
Revisions
-
claudiob created this gist
Feb 26, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ 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.beta3' # CHANGE TO '5.0.0.beta2' for tests to pass gem 'sqlite3' gem 'pry-nav' 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 :accounts, force: true do |t| end create_table :authorizations, force: true do |t| t.integer :authority_id, null: false t.string :authority_type, null: false end end class Account < ActiveRecord::Base end class Authorization < ActiveRecord::Base validates :authority_id, :authority_type, presence: true belongs_to :authority, polymorphic: true end class Partnership < Authorization validates_associated :authority end class BugTest < Minitest::Test def test_polymorphic_validates_associated ActiveRecord::Base.belongs_to_required_by_default = true account = Account.create! account = Account.create! authority = Authorization.create! authority: account partnership = Partnership.new authority: authority Authorization.belongs_to :partner, foreign_key: 'authority_id', class_name: 'Authorization' assert partnership.valid?, partnership.errors.full_messages.to_sentence # on Rails 5.0.0.beta2: # => No errors # on Rails 5.0.0.beta3 (and master@364e155): # => Failure: Authority is invalid end end