Created
June 12, 2014 13:25
-
-
Save JuanitoFatas/3fe51ddc0e989c718255 to your computer and use it in GitHub Desktop.
Rails 15258 issue gist
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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'sqlite3' | |
GEMFILE | |
system 'bundle' | |
end | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'active_record' | |
require 'sqlite3' | |
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 :posts do |t| | |
t.string :name | |
end | |
create_table :comments do |t| | |
t.string :content | |
t.belongs_to :post | |
end | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments, inverse_of: :post | |
validate :given_validation | |
after_save :update_comments | |
def given_validation | |
comments.select(:post_id) # This is the line that makes the test fail. | |
end | |
def update_comments | |
comments.update_all(content: "foo") | |
end | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post, inverse_of: :comments | |
end | |
class BugTest < Minitest::Test | |
def test_update_all_after_selection | |
post = Post.create! | |
comment = Comment.create! | |
post.comments << comment | |
post.update(name: "bar") | |
assert_equal 'foo', comment.reload.content | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment