Skip to content

Commit ce80587

Browse files
authored
Fix #96 (Array Quoting) by using correct arel accessor (v2) (#98)
1 parent f40f085 commit ce80587

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

lib/torque/postgresql/arel/visitors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def visit_Arel_Nodes_Quoted(o, collector)
2525

2626
# Allow quoted arrays to get here
2727
def visit_Arel_Nodes_Casted(o, collector)
28-
value = o.respond_to?(:val) ? o.val : o.value
28+
value = PostgreSQL::AR610 ? o.value_for_database : o.val
2929
return super unless value.is_a?(::Enumerable)
3030
quote_array(value, collector)
3131
end

lib/torque/postgresql/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Torque
44
module PostgreSQL
5-
VERSION = '2.4.4'
5+
VERSION = '2.4.5'
66
end
77
end

spec/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
version = 3
13+
version = 4
1414

1515
return if ActiveRecord::Migrator.current_version == version
1616
ActiveRecord::Schema.define(version: version) do
@@ -59,6 +59,7 @@
5959
t.string "url"
6060
t.enum "type", enum_type: :types
6161
t.enum "conflicts", enum_type: :conflicts, array: true
62+
t.jsonb "metadata"
6263
t.datetime "created_at", null: false
6364
t.datetime "updated_at", null: false
6465
end

spec/tests/arel_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
it 'does not break jsonb' do
6565
expect { connection.add_column(:authors, :profile, :jsonb, default: []) }.not_to raise_error
6666
expect(Author.columns_hash['profile'].default).to eq('[]')
67+
68+
condition = Author.arel_table['profile'].is_distinct_from([])
69+
result = Torque::PostgreSQL::AR610 ? "'[]'" : "ARRAY[]"
70+
expect(Author.where(condition).to_sql).to eq(<<~SQL.squish)
71+
SELECT "authors".* FROM "authors" WHERE "authors"."profile" IS DISTINCT FROM #{result}
72+
SQL
6773
end
6874

6975
it 'works properly when column is an array' do

0 commit comments

Comments
 (0)