diff options
author | Lisa Ugray <lisa.ugray@shopify.com> | 2017-10-19 12:45:07 -0400 |
---|---|---|
committer | Lisa Ugray <lisa.ugray@shopify.com> | 2017-11-09 14:29:39 -0500 |
commit | c3675f50d2e59b7fc173d7b332860c4b1a24a726 (patch) | |
tree | 736119c8ea9b683ac465c07e6a640d7e14bbc1b0 /activemodel/test/cases/attributes_dirty_test.rb | |
parent | dac7c8844b4d9944eaa0fca98b45ee478cdb7201 (diff) | |
download | rails-c3675f50d2e59b7fc173d7b332860c4b1a24a726.tar.gz rails-c3675f50d2e59b7fc173d7b332860c4b1a24a726.tar.bz2 rails-c3675f50d2e59b7fc173d7b332860c4b1a24a726.zip |
Move Attribute and AttributeSet to ActiveModel
Use these to back the attributes API. Stop automatically including
ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.
Diffstat (limited to 'activemodel/test/cases/attributes_dirty_test.rb')
-rw-r--r-- | activemodel/test/cases/attributes_dirty_test.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/activemodel/test/cases/attributes_dirty_test.rb b/activemodel/test/cases/attributes_dirty_test.rb index 26b0e85db3..83a86371e0 100644 --- a/activemodel/test/cases/attributes_dirty_test.rb +++ b/activemodel/test/cases/attributes_dirty_test.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true require "cases/helper" -require "active_model/attributes" class AttributesDirtyTest < ActiveModel::TestCase class DirtyModel include ActiveModel::Model include ActiveModel::Attributes + include ActiveModel::Dirty attribute :name, :string attribute :color, :string attribute :size, :integer @@ -69,12 +69,10 @@ class AttributesDirtyTest < ActiveModel::TestCase end test "attribute mutation" do - @model.instance_variable_set("@name", "Yam".dup) + @model.name = "Yam" + @model.save assert !@model.name_changed? @model.name.replace("Hadad") - assert !@model.name_changed? - @model.name_will_change! - @model.name.replace("Baal") assert @model.name_changed? end @@ -190,4 +188,18 @@ class AttributesDirtyTest < ActiveModel::TestCase assert_equal "Dmitry", @model.name assert_equal "White", @model.color end + + test "changing the attribute reports a change only when the cast value changes" do + @model.size = "2.3" + @model.save + @model.size = "2.1" + + assert_equal false, @model.changed? + + @model.size = "5.1" + + assert_equal true, @model.changed? + assert_equal true, @model.size_changed? + assert_equal({ "size" => [2, 5] }, @model.changes) + end end |