aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/type
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-04-12 03:14:09 +0930
committerMatthew Draper <matthew@trebex.net>2017-04-12 03:14:09 +0930
commit8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4 (patch)
tree817c7966183f31e2e9d004e35489a09a8a5bed91 /activemodel/test/cases/type
parent24ac36be7150f97ac0a61cf7cbe7d212097ef1a6 (diff)
downloadrails-8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4.tar.gz
rails-8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4.tar.bz2
rails-8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4.zip
Don't freeze input strings
See 34321e4a433bb7eef48fd743286601403f8f7d82 for background on ImmutableString vs String. Our String type cannot delegate typecasting to ImmutableString, because the latter freezes its input: duplicating the value after that gives us an unfrozen result, but still mutates the originally passed object.
Diffstat (limited to 'activemodel/test/cases/type')
-rw-r--r--activemodel/test/cases/type/string_test.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/activemodel/test/cases/type/string_test.rb b/activemodel/test/cases/type/string_test.rb
index 222083817e..47d412e27e 100644
--- a/activemodel/test/cases/type/string_test.rb
+++ b/activemodel/test/cases/type/string_test.rb
@@ -12,16 +12,25 @@ module ActiveModel
end
test "cast strings are mutable" do
- s = "foo"
type = Type::String.new
+
+ s = "foo"
assert_equal false, type.cast(s).frozen?
+ assert_equal false, s.frozen?
+
+ f = "foo".freeze
+ assert_equal false, type.cast(f).frozen?
+ assert_equal true, f.frozen?
end
test "values are duped coming out" do
- s = "foo"
type = Type::String.new
+
+ s = "foo"
assert_not_same s, type.cast(s)
+ assert_equal s, type.cast(s)
assert_not_same s, type.deserialize(s)
+ assert_equal s, type.deserialize(s)
end
end
end