Skip to content

Commit

Permalink
Fix TimeZoneConverter#== method, so objects will be properly...
Browse files Browse the repository at this point in the history
compared by their type, scale, limit & precision.
  • Loading branch information
ruyrocha committed Aug 27, 2024
1 parent 82d8e0a commit 6b855f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
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
Expand Up @@ -8,13 +8,6 @@ class Timestamp < DateTime # :nodoc:
def type
real_type_unless_aliased(:timestamp)
end

def ==(other)
precision == other.precision &&
scale == other.scale &&
limit == other.limit &&
type == other.type
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,6 @@ def test_disable_extension_without_schema
@connection.execute("DROP EXTENSION IF EXISTS hstore")
end

def test_time_zone_converter_equals_to_timestamp
subtype = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp.new
value = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(subtype)

value_from_cache = Marshal.load(Marshal.dump(value))

assert_equal value, value_from_cache
end

private
def with_postgresql_apdater_decode_dates
PostgreSQLAdapter.decode_dates = true
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_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 6b855f3

Please sign in to comment.