Skip to content

Instantly share code, notes, and snippets.

@ccallebs
Created July 22, 2015 04:18
Show Gist options
  • Save ccallebs/ea0802dbbcedb09984ea to your computer and use it in GitHub Desktop.
Save ccallebs/ea0802dbbcedb09984ea to your computer and use it in GitHub Desktop.
Rails Issue #20867
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 :books, force: true do |t|
t.integer :chapters_count
t.timestamps
end
create_table :chapters, force: true do |t|
t.integer :book_id
end
end
class Book < ActiveRecord::Base
has_many :chapters
end
class Chapter < ActiveRecord::Base
belongs_to :book, counter_cache: true, touch: true
end
class BugTest < Minitest::Test
def test_updated_at_changes
book = Book.create!
book.chapters << Chapter.create!
book.chapters << Chapter.create!
updated_at = book.updated_at
chapter = book.chapters.last
chapter.book_id = nil
chapter.save
refreshed_updated_at = book.updated_at
assert updated_at != refreshed_updated_at
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment