From 920f750bed0fa04aae5a134fe90dab6bb293b36c Mon Sep 17 00:00:00 2001 From: Carlos Silva Date: Mon, 14 Oct 2024 12:54:11 -0300 Subject: [PATCH] Fix #96 (Array Quoting) by using correct arel accessor (#97) --- lib/torque/postgresql/arel/visitors.rb | 2 +- lib/torque/postgresql/version.rb | 2 +- spec/schema.rb | 3 ++- spec/tests/arel_spec.rb | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/torque/postgresql/arel/visitors.rb b/lib/torque/postgresql/arel/visitors.rb index fdf4e10..de25add 100644 --- a/lib/torque/postgresql/arel/visitors.rb +++ b/lib/torque/postgresql/arel/visitors.rb @@ -25,7 +25,7 @@ def visit_Arel_Nodes_Quoted(o, collector) # Allow quoted arrays to get here def visit_Arel_Nodes_Casted(o, collector) - value = o.respond_to?(:val) ? o.val : o.value + value = o.value_for_database return super unless value.is_a?(::Enumerable) quote_array(value, collector) end diff --git a/lib/torque/postgresql/version.rb b/lib/torque/postgresql/version.rb index 59602cd..f3948f1 100644 --- a/lib/torque/postgresql/version.rb +++ b/lib/torque/postgresql/version.rb @@ -2,6 +2,6 @@ module Torque module PostgreSQL - VERSION = '3.4.0' + VERSION = '3.4.1' end end diff --git a/spec/schema.rb b/spec/schema.rb index 2b89ef6..6576882 100644 --- a/spec/schema.rb +++ b/spec/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -version = 3 +version = 4 return if ActiveRecord::Migrator.current_version == version ActiveRecord::Schema.define(version: version) do @@ -59,6 +59,7 @@ t.string "url" t.enum "type", enum_type: :types t.enum "conflicts", enum_type: :conflicts, array: true + t.jsonb "metadata" t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/spec/tests/arel_spec.rb b/spec/tests/arel_spec.rb index 4821721..35a39b4 100644 --- a/spec/tests/arel_spec.rb +++ b/spec/tests/arel_spec.rb @@ -62,6 +62,11 @@ it 'does not break jsonb' do expect { connection.add_column(:authors, :profile, :jsonb, default: []) }.not_to raise_error expect(Author.columns_hash['profile'].default).to eq('[]') + + condition = Author.arel_table['profile'].is_distinct_from([]) + expect(Author.where(condition).to_sql).to eq(<<~SQL.squish) + SELECT "authors".* FROM "authors" WHERE "authors"."profile" IS DISTINCT FROM '[]' + SQL end it 'works properly when column is an array' do