aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/attributes_dirty_test.rb
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-11-09 15:12:38 -0500
committerGitHub <noreply@github.com>2017-11-09 15:12:38 -0500
commit100c62ae15deb3d70c5e17d880fd57971bb8759a (patch)
tree736119c8ea9b683ac465c07e6a640d7e14bbc1b0 /activemodel/test/cases/attributes_dirty_test.rb
parentdac7c8844b4d9944eaa0fca98b45ee478cdb7201 (diff)
parentc3675f50d2e59b7fc173d7b332860c4b1a24a726 (diff)
downloadrails-100c62ae15deb3d70c5e17d880fd57971bb8759a.tar.gz
rails-100c62ae15deb3d70c5e17d880fd57971bb8759a.tar.bz2
rails-100c62ae15deb3d70c5e17d880fd57971bb8759a.zip
Merge pull request #30985 from lugray/attribute_set_in_am
Move Attribute and AttributeSet to ActiveModel
Diffstat (limited to 'activemodel/test/cases/attributes_dirty_test.rb')
-rw-r--r--activemodel/test/cases/attributes_dirty_test.rb22
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