Skip to content

Commit

Permalink
Fixes #44
Browse files Browse the repository at this point in the history
Handles the default flow of Sanitization.quote_bound_value correctly
  • Loading branch information
danmcclain committed Dec 14, 2012
1 parent 9f14b45 commit e88c0be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/postgres_ext/active_record/sanitization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def sanitize_sql_hash_for_assignment(attrs)
end

def quote_bound_value(value, column = nil, c = connection)
if column.present?
if column.present? && column != c
record_column = self.columns.select {|col| col.name == column}.first
c.quote(value, record_column)
elsif value.respond_to?(:map) && !value.acts_like?(:string)
Expand Down
30 changes: 30 additions & 0 deletions spec/arel/arel_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

describe 'Don\'t stomp all over the default ActiveRecord queries' do
let!(:adapter) { ActiveRecord::Base.connection }

before do
adapter.create_table :cars, :force => true do |t|
t.string :make
t.string :model
t.timestamps
end

class Car < ActiveRecord::Base
attr_accessible :make, :model
end
end

after do
adapter.drop_table :cars
Object.send(:remove_const, :Car)
end

describe 'Where Queries' do
describe 'Set query' do
it '' do
Car.where('id in (?)', [1,2]).to_sql.should eq "SELECT \"cars\".* FROM \"cars\" WHERE (id in (1,2))"
end
end
end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each { |f| require f }

RSpec.configure do |config|
config.use_transactional_fixtures = false
config.treat_symbols_as_metadata_keys_with_true_values = true
config.mock_with :mocha
config.use_transactional_fixtures = true
config.backtrace_clean_patterns = [
#/\/lib\d*\/ruby\//,
#/bin\//,
Expand Down

0 comments on commit e88c0be

Please sign in to comment.