mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
Fix Rubocop warnings. Fix merge conflict error. Fix merge conflict error.
This commit is contained in:
parent
8717744c56
commit
37f3b4dc05
7 changed files with 39 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
||||
|
||||
*Peter Fry*
|
||||
|
||||
* Resolve issue with insert_all unique_by option when used with expression index.
|
||||
|
||||
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
||||
|
|
|
@ -12,6 +12,7 @@ require "active_record/connection_adapters/postgresql/oid/enum"
|
|||
require "active_record/connection_adapters/postgresql/oid/hstore"
|
||||
require "active_record/connection_adapters/postgresql/oid/inet"
|
||||
require "active_record/connection_adapters/postgresql/oid/jsonb"
|
||||
require "active_record/connection_adapters/postgresql/oid/macaddr"
|
||||
require "active_record/connection_adapters/postgresql/oid/money"
|
||||
require "active_record/connection_adapters/postgresql/oid/oid"
|
||||
require "active_record/connection_adapters/postgresql/oid/point"
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
module PostgreSQL
|
||||
module OID # :nodoc:
|
||||
class Macaddr < Type::String # :nodoc:
|
||||
def type
|
||||
:macaddr
|
||||
end
|
||||
|
||||
private
|
||||
def cast_value(value)
|
||||
value.to_s.downcase
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -15,7 +15,7 @@ module ActiveRecord
|
|||
|
||||
private
|
||||
def cast_value(value)
|
||||
casted = value.to_s
|
||||
casted = value.to_s.downcase
|
||||
casted if casted.match?(ACCEPTABLE_UUID)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -535,7 +535,7 @@ module ActiveRecord
|
|||
m.register_type "uuid", OID::Uuid.new
|
||||
m.register_type "xml", OID::Xml.new
|
||||
m.register_type "tsvector", OID::SpecializedString.new(:tsvector)
|
||||
m.register_type "macaddr", OID::SpecializedString.new(:macaddr)
|
||||
m.register_type "macaddr", OID::Macaddr.new
|
||||
m.register_type "citext", OID::SpecializedString.new(:citext)
|
||||
m.register_type "ltree", OID::SpecializedString.new(:ltree)
|
||||
m.register_type "line", OID::SpecializedString.new(:line)
|
||||
|
|
|
@ -93,4 +93,10 @@ class PostgresqlNetworkTest < ActiveRecord::PostgreSQLTestCase
|
|||
assert_match %r{t\.cidr\s+"cidr_address",\s+default: "192\.168\.1\.0/24"}, output
|
||||
assert_match %r{t\.macaddr\s+"mac_address",\s+default: "ff:ff:ff:ff:ff:ff"}, output
|
||||
end
|
||||
|
||||
def test_mac_address_change_case_does_not_mark_dirty
|
||||
model = PostgresqlNetworkAddress.create(mac_address: "Ab:Cd:Ef:01:02:03")
|
||||
model.mac_address = model.mac_address.swapcase
|
||||
assert_not_predicate model, :changed?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -120,6 +120,12 @@ class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase
|
|||
assert_empty UUIDType.where(guid: "foobar")
|
||||
end
|
||||
|
||||
def test_uuid_change_case_does_not_mark_dirty
|
||||
model = UUIDType.create!(guid: "abcd-0123-4567-89ef-dead-beef-0101-1010")
|
||||
model.guid = model.guid.swapcase
|
||||
assert_not_predicate model, :changed?
|
||||
end
|
||||
|
||||
class DuckUUID
|
||||
def initialize(uuid)
|
||||
@uuid = uuid
|
||||
|
|
Loading…
Reference in a new issue