Skip to content

Commit

Permalink
Merge pull request #18 from kbrock/next_batch
Browse files Browse the repository at this point in the history
support int arrays
  • Loading branch information
danmcclain committed Oct 5, 2012
2 parents 2a8908f + dfb9e54 commit dad72e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,9 @@ def string_to_array(value)
end

def type_cast_array(array)
casted_array = []
array.each do |value|
if Array === value
casted_array.push type_cast_array(value)
else
casted_array.push type_cast value
end
array.map do |value|
Array === value ? type_cast_array(value) : type_cast(value)
end
casted_array
end

def type_cast_code_with_extended_types(var_name)
Expand Down
1 change: 1 addition & 0 deletions lib/postgres_ext/arel/visitors/to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def visit_IPAddr value
end

def change_string value
return value unless value.is_a?(String)
if value.match /"|,|\{/
value.gsub(/"/, "\"").gsub(/'/,'"')
else
Expand Down
7 changes: 7 additions & 0 deletions spec/arel/array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
before do
adapter.create_table :arel_arrays, :force => true do |t|
t.string :tags, :array => true
t.integer :tag_ids, :array => true
end

class ArelArray < ActiveRecord::Base
Expand All @@ -25,6 +26,12 @@ class ArelArray < ActiveRecord::Base
arel_table.where(arel_table[:tags].array_overlap(['tag','tag 2'])).to_sql.should match /&& '\{tag,tag 2\}'/
end

it 'converts Arel array_overlap statment' do
arel_table = ArelArray.arel_table

arel_table.where(arel_table[:tag_ids].array_overlap([1,2])).to_sql.should match /&& '\{1,2\}'/
end

it 'returns matched records' do
one = ArelArray.create!(:tags => ['one'])
two = ArelArray.create!(:tags => ['two'])
Expand Down

0 comments on commit dad72e1

Please sign in to comment.