Skip to content

Commit 027f5f4

Browse files
committed
[rails#52698] Add TimeZoneConverter#== method, so objects will be properly...
compared by their type, scale, limit & precision.
1 parent a59ddc7 commit 027f5f4

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

activerecord/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Add `TimeZoneConverter#==`` method, so objects will be properly compared by
2+
their type, scale, limit & precision.
3+
4+
Address #52699.
5+
6+
*Ruy Rocha*
7+
18
* Support use of alternative database interfaces via the `database_cli` ActiveRecord configuration option.
29

310
```ruby

activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def cast(value)
3232
end
3333
end
3434

35+
def ==(other)
36+
precision == other.precision &&
37+
scale == other.scale &&
38+
limit == other.limit &&
39+
type == other.type
40+
end
41+
3542
private
3643
def convert_time_to_time_zone(value)
3744
return if value.nil?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require "cases/helper"
4+
require "active_support/core_ext/enumerable"
5+
6+
module ActiveRecord
7+
module AttributeMethods
8+
module TimeZoneConversion
9+
class TimeZoneConverterTest < ActiveRecord::TestCase
10+
def test_with_date_time_type
11+
subtype = ActiveRecord::Type::DateTime.new
12+
value = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(subtype)
13+
value_from_cache = Marshal.load(Marshal.dump(value))
14+
15+
assert_equal value, value_from_cache
16+
end
17+
end
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)