From 83d6cc4815debe2086073387ecbf38c0f47cfec5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Apr 2017 10:46:07 -0700 Subject: Move around AR::Dirty and fix _attribute method We already have a _read_attribute method that can get the value we need from the model. Lets define that method in AM::Dirty and use the existing one from AR::Dirty rather than introducing a new method. --- activerecord/test/cases/dirty_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'activerecord/test/cases/dirty_test.rb') diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 15d7a32e21..721861975a 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -671,6 +671,28 @@ class DirtyTest < ActiveRecord::TestCase assert binary.changed? end + test "changes is correct for subclass" do + foo = Class.new(Pirate) do + def catchphrase + super.upcase + end + end + + pirate = foo.create!(catchphrase: "arrrr") + + new_catchphrase = "arrrr matey!" + + pirate.catchphrase = new_catchphrase + assert pirate.catchphrase_changed? + + expected_changes = { + "catchphrase" => ["arrrr", new_catchphrase] + } + + assert_equal new_catchphrase.upcase, pirate.catchphrase + assert_equal expected_changes, pirate.changes + end + test "changes is correct if override attribute reader" do pirate = Pirate.create!(catchphrase: "arrrr") def pirate.catchphrase -- cgit v1.2.3