Last active
August 3, 2021 00:41
-
-
Save marcelolx/e8cf5bbaf51adcf5b2cbe76bd6a84f75 to your computer and use it in GitHub Desktop.
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 characters
| require "bundler/inline" | |
| gemfile(true) do | |
| source 'https://rubygems.org' | |
| # Activate the gem you are reporting the issue against. | |
| gem 'rails', github: "marcelolx/rails", branch: "issue-25718" | |
| gem 'sqlite3' | |
| end | |
| require 'active_record' | |
| require 'minitest/autorun' | |
| require 'logger' | |
| # Ensure backward compatibility with Minitest 4 | |
| Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
| # 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 :owners, force: true do |t| | |
| t.string :name | |
| end | |
| create_table :pets, force: true do |t| | |
| t.integer :owner_id | |
| t.string :name | |
| end | |
| end | |
| class Owner < ActiveRecord::Base | |
| validates_presence_of :name | |
| end | |
| class Pet < ActiveRecord::Base | |
| belongs_to :owner, touch: true | |
| end | |
| class Pet2 < ActiveRecord::Base | |
| self.table_name = "pets" | |
| belongs_to :owner, touch: true, validate: true | |
| end | |
| class BugTest < Minitest::Test | |
| def test_association_touch_when_belong_to_invalid | |
| pet = Pet.new(owner: Owner.new) | |
| pet.save | |
| assert_predicate pet.owner.errors.full_messages, :empty? | |
| end | |
| def test_association_touch_when_belong_to_invalid_with_validate_true | |
| pet = Pet2.new(owner: Owner.new) | |
| pet.save | |
| assert pet.errors.full_messages, ['Owner is invalid'] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment