Skip to content

Commit

Permalink
[rails#52698] Add TimeZoneConverter#== method, so objects will be p…
Browse files Browse the repository at this point in the history
…roperly...

compared by their type, scale, limit & precision.
  • Loading branch information
ruyrocha committed Aug 27, 2024
1 parent 5a0b2fa commit 71e5dc3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Add `TimeZoneConverter#==` method, so objects will be properly compared by
their type, scale, limit & precision.

Address #52699.

*Ruy Rocha*

* Add support for SQLite3 full-text-search and other virtual tables.

Previously, adding sqlite3 virtual tables messed up `schema.rb`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def cast(value)
end
end

def ==(other)
precision == other.precision &&
scale == other.scale &&
limit == other.limit &&
type == other.type
end

private
def convert_time_to_time_zone(value)
return if value.nil?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "cases/helper"
require "active_support/core_ext/enumerable"

module ActiveRecord
module AttributeMethods
module TimeZoneConversion
class TimeZoneConverterTest < ActiveRecord::TestCase
def test_comparison_with_date_time_type
subtype = ActiveRecord::Type::DateTime.new
value = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(subtype)
value_from_cache = Marshal.load(Marshal.dump(value))

assert_equal value, value_from_cache
end
end
end
end
end

0 comments on commit 71e5dc3

Please sign in to comment.