Skip to content

Instantly share code, notes, and snippets.

@wiegand
Created May 16, 2018 15:28
Show Gist options
  • Save wiegand/e456acaabd8b3fc2aa22d014c08a4005 to your computer and use it in GitHub Desktop.
Save wiegand/e456acaabd8b3fc2aa22d014c08a4005 to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
warn 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# gem 'activerecord', '5.1.5'
gem 'activerecord', '5.2.0'
gem 'pg', '~> 0.19'
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('postgres://user:password@host/test_db')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :people, force: true do |t|
end
end
class Person < ActiveRecord::Base
define_attribute_method :first_name
attr_reader :first_name
def first_name=(value)
first_name_will_change!
@first_name = value
end
end
class BugTest < Minitest::Test
def test_dirty_attrs
person = Person.new
assert_equal person.changed?, false
person.first_name = 'First Name'
assert_equal person.changed?, true
assert_equal person.changes, 'first_name' => [nil, 'First Name']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment