From 583721397cbbfd801e6374b50e5e685ac249c9b8 Mon Sep 17 00:00:00 2001 From: Nikolai Ageev Date: Thu, 19 Dec 2024 14:19:02 +0100 Subject: [PATCH] Update handling nil value for PgHash --- lib/mobility/backends/active_record/pg_hash.rb | 1 + spec/integration/active_record_compatibility_spec.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/mobility/backends/active_record/pg_hash.rb b/lib/mobility/backends/active_record/pg_hash.rb index 3fcb7c13..47b4698b 100644 --- a/lib/mobility/backends/active_record/pg_hash.rb +++ b/lib/mobility/backends/active_record/pg_hash.rb @@ -22,6 +22,7 @@ def read(locale, _options = nil) def write(locale, value, _options = nil) if value.nil? translations.delete(locale.to_s) + nil else translations[locale.to_s] = value end diff --git a/spec/integration/active_record_compatibility_spec.rb b/spec/integration/active_record_compatibility_spec.rb index 0f4e4b6a..cad2a702 100644 --- a/spec/integration/active_record_compatibility_spec.rb +++ b/spec/integration/active_record_compatibility_spec.rb @@ -48,6 +48,8 @@ post.send(backend_for(post, :title).association_name).first.value = "association changed value" post.save expect(Post.first.title).to eq("association changed value") + post.title = nil + expect(post.title).to eq(nil) end it "resets cache when model is reloaded" do