Browse files

Fixes bad monkey patch of array visitor

Closes issue #63
  • Loading branch information...
1 parent a95f617 commit 86f238ba6e30ca5d9669ca4a325c05b0e65d45b8 @danmcclain danmcclain committed Feb 13, 2013
Showing with 7 additions and 14 deletions.
  1. +1 −1 lib/postgres_ext/arel/visitors/to_sql.rb
  2. +6 −13 spec/queries/sanity_spec.rb
View
2 lib/postgres_ext/arel/visitors/to_sql.rb
@@ -7,7 +7,7 @@ def visit_Array o
if last_column.respond_to?(:array) && last_column.array
quoted o
else
- o.map { |x| visit x }.join(', ')
+ o.empty? ? 'NULL' : o.map { |x| visit x }.join(', ')
end
end
end
View
19 spec/queries/sanity_spec.rb
@@ -1,23 +1,16 @@
require 'spec_helper'
describe 'Ensure that we don\'t stomp on Active Record\'s queries' do
- let!(:adapter) { ActiveRecord::Base.connection }
-
- before do
- adapter.create_table :sanity_tests, :force => true do |t|
- t.string :tags, :array => true
- t.integer :tag_ids, :array => true
- end
-
- class SanityTest < ActiveRecord::Base
- attr_accessible :tags, :tags_ids
- end
- end
describe '.where' do
it 'generates IN clauses for non array columns' do
- query = SanityTest.where(:id => [1,2,3]).to_sql
+ query = Person.where(:id => [1,2,3]).to_sql
query.should match /IN \(1, 2, 3\)/
end
+ it 'generates IN clauses for non array columns' do
+ query = Person.where(:id => []).to_sql
+
+ query.should match /IN \(NULL\)/
+ end
end
end

0 comments on commit 86f238b

Please sign in to comment.