aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/dirty_test.rb
diff options
context:
space:
mode:
authorbogdanvlviv <bogdanvlviv@gmail.com>2017-04-04 20:23:51 +0300
committerbogdanvlviv <bogdanvlviv@gmail.com>2017-04-12 08:06:13 +0300
commitb5eb3215a68f94bb8cb20739366232c415744b83 (patch)
tree991c873315009384453986698e3a77b2931077d2 /activerecord/test/cases/dirty_test.rb
parent2b4583f2a2ef94bc8c046e36e2b62ec642bbfb41 (diff)
downloadrails-b5eb3215a68f94bb8cb20739366232c415744b83.tar.gz
rails-b5eb3215a68f94bb8cb20739366232c415744b83.tar.bz2
rails-b5eb3215a68f94bb8cb20739366232c415744b83.zip
Fix inconsistency with changed attributes when overriding AR attribute reader
Diffstat (limited to 'activerecord/test/cases/dirty_test.rb')
-rw-r--r--activerecord/test/cases/dirty_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index f9eccfbda1..15d7a32e21 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -671,6 +671,25 @@ class DirtyTest < ActiveRecord::TestCase
assert binary.changed?
end
+ test "changes is correct if override attribute reader" do
+ pirate = Pirate.create!(catchphrase: "arrrr")
+ def pirate.catchphrase
+ super.upcase
+ end
+
+ 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 "attribute_changed? doesn't compute in-place changes for unrelated attributes" do
test_type_class = Class.new(ActiveRecord::Type::Value) do
define_method(:changed_in_place?) do |*|