Skip to content

Commit ee66185

Browse files
authored
Merge pull request rails#53347 from rails/revert-53337-opt-attr-dup
Revert "ActiveModel::Attribute: elide dup for immutable types"
2 parents 3d2ac8a + 2d969ba commit ee66185

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

activemodel/lib/active_model/attribute.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ def with_type(type)
9696
end
9797
end
9898

99-
def deep_dup # :nodoc:
100-
if @type.mutable?
101-
dup
102-
else
103-
self # If the underlying type is immutable we can get away with not duping
104-
end
105-
end
106-
10799
def type_cast(*)
108100
raise NotImplementedError
109101
end

activemodel/lib/active_model/attribute/user_provided_default.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ def with_type(type)
2626
self.class.new(name, user_provided_value, type, original_attribute)
2727
end
2828

29-
# Can't elide dup when a default is provided.
30-
# See Attribute#deep_dup
31-
alias_method :deep_dup, :dup
32-
3329
def marshal_dump
3430
result = [
3531
name,

activemodel/lib/active_model/type/string.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ def to_immutable_string
2929
)
3030
end
3131

32-
def mutable? # :nodoc:
33-
true
34-
end
35-
3632
private
3733
def cast_value(value)
3834
case value

activerecord/test/cases/base_test.rb

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,14 +1117,16 @@ def test_default_char_types
11171117
end
11181118

11191119
def test_default_in_local_time
1120-
with_timezone_config default: :local do
1121-
default = Default.new
1120+
with_env_tz do
1121+
with_timezone_config default: :local do
1122+
default = Default.new
11221123

1123-
assert_equal Date.new(2004, 1, 1), default.fixed_date
1124-
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
1124+
assert_equal Date.new(2004, 1, 1), default.fixed_date
1125+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
11251126

1126-
if current_adapter?(:PostgreSQLAdapter)
1127-
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
1127+
if current_adapter?(:PostgreSQLAdapter)
1128+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
1129+
end
11281130
end
11291131
end
11301132
end
@@ -1157,6 +1159,29 @@ def test_default_in_utc_with_time_zone
11571159
end
11581160
end
11591161

1162+
def test_switching_default_time_zone
1163+
with_env_tz do
1164+
2.times do
1165+
with_timezone_config default: :local do
1166+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
1167+
end
1168+
with_timezone_config default: :utc do
1169+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
1170+
end
1171+
end
1172+
end
1173+
end
1174+
1175+
def test_mutating_time_objects
1176+
with_env_tz do
1177+
with_timezone_config default: :local do
1178+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
1179+
assert_equal Time.utc(2004, 1, 1, 5, 0, 0, 0), Default.new.fixed_time.utc
1180+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
1181+
end
1182+
end
1183+
end
1184+
11601185
unless in_memory_db?
11611186
def test_connection_in_local_time
11621187
with_timezone_config default: :utc do

0 commit comments

Comments
 (0)