Skip to content

Commit

Permalink
Fix #96 (Array Quoting) by using correct arel accessor (v2) (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
crashtech authored Oct 14, 2024
1 parent f40f085 commit ce80587
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/torque/postgresql/arel/visitors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = PostgreSQL::AR610 ? o.value_for_database : o.val
return super unless value.is_a?(::Enumerable)
quote_array(value, collector)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/torque/postgresql/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Torque
module PostgreSQL
VERSION = '2.4.4'
VERSION = '2.4.5'
end
end
3 changes: 2 additions & 1 deletion spec/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/tests/arel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
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([])
result = Torque::PostgreSQL::AR610 ? "'[]'" : "ARRAY[]"
expect(Author.where(condition).to_sql).to eq(<<~SQL.squish)
SELECT "authors".* FROM "authors" WHERE "authors"."profile" IS DISTINCT FROM #{result}
SQL
end

it 'works properly when column is an array' do
Expand Down

0 comments on commit ce80587

Please sign in to comment.