Skip to content

Commit

Permalink
Fixed psql batch updates quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
pyromaniac committed Jan 29, 2013
1 parent 94e86a8 commit 3ff6d03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/activeuuid/patches.rb
Expand Up @@ -81,18 +81,14 @@ module PostgreSQLQuoting

included do
def quote_with_visiting(value, column = nil)
if column && column.type == :uuid
value = UUIDTools::UUID.serialize(value)
value = value.to_s if value.is_a? UUIDTools::UUID
end
value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid
value = value.to_s if value.is_a? UUIDTools::UUID
quote_without_visiting(value, column)
end

def type_cast_with_visiting(value, column = nil)
if column && column.type == :uuid
value = UUIDTools::UUID.serialize(value)
value = value.to_s if value.is_a? UUIDTools::UUID
end
value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid
value = value.to_s if value.is_a? UUIDTools::UUID
type_cast_without_visiting(value, column)
end

Expand Down
5 changes: 5 additions & 0 deletions spec/lib/activerecord_spec.rb
Expand Up @@ -111,6 +111,11 @@
specify { model.where("id = :id", id: article.id) }
end

context 'batch interpolation' do
before { model.update_all(["title = CASE WHEN id = :id THEN 'Passed' ELSE 'Nothing' END", id: article.id]) }
specify { article.reload.title.should == 'Passed' }
end

context '.find' do
specify { model.find(article).should == article }
specify { model.find(id).should == article }
Expand Down

0 comments on commit 3ff6d03

Please sign in to comment.