Skip to content

Commit

Permalink
Fix #96 (Array Quoting) by using correct arel accessor (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
crashtech authored Oct 14, 2024
1 parent 5b7055e commit 920f750
Show file tree
Hide file tree
Showing 4 changed files with 9 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 = o.value_for_database
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 = '3.4.0'
VERSION = '3.4.1'
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
5 changes: 5 additions & 0 deletions spec/tests/arel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 920f750

Please sign in to comment.