Skip to content

Commit

Permalink
Merge in master
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Jan 26, 2017
2 parents 43be63f + d4f891f commit f594d0f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ODBCAdapter < AbstractAdapter
include ::ODBCAdapter::SchemaStatements

ADAPTER_NAME = 'ODBC'.freeze
BOOLEAN_TYPE = 'BOOLEAN'.freeze
ERR_DUPLICATE_KEY_VALUE = 23505

attr_reader :dbms
Expand Down
18 changes: 17 additions & 1 deletion lib/odbc_adapter/adapters/mysql_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Adapters
# Overrides specific to MySQL. Mostly taken from
# ActiveRecord::ConnectionAdapters::MySQLAdapter
class MySQLODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter
PRIMARY_KEY = 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
PRIMARY_KEY = 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'.freeze

def arel_visitor
Arel::Visitors::MySQL.new(self)
Expand Down Expand Up @@ -40,6 +40,22 @@ def quote_string(string)
string.gsub(/\\/, '\&\&').gsub(/'/, "''")
end

def quoted_true
'1'
end

def unquoted_true
1
end

def quoted_false
'0'
end

def unquoted_false
0
end

def disable_referential_integrity(&block) #:nodoc:
old = select_value("SELECT @@FOREIGN_KEY_CHECKS")

Expand Down
18 changes: 8 additions & 10 deletions lib/odbc_adapter/adapters/postgresql_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ module Adapters
# Overrides specific to PostgreSQL. Mostly taken from
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
class PostgreSQLODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter
PRIMARY_KEY = 'SERIAL PRIMARY KEY'
BOOLEAN_TYPE = 'bool'.freeze
PRIMARY_KEY = 'SERIAL PRIMARY KEY'.freeze

# Override to handle booleans appropriately
def native_database_types
@native_database_types ||= super.merge(boolean: { name: 'bool' })
end

def arel_visitor
Arel::Visitors::PostgreSQL.new(self)
Expand Down Expand Up @@ -62,7 +68,7 @@ def type_cast(value, column)

case value
when String
return super unless 'bytea' == column.sql_type
return super unless 'bytea' == column.native_type
{ value: value, format: 1 }
else
super
Expand All @@ -75,14 +81,6 @@ def quote_string(string)
string.gsub(/\\/, '\&\&').gsub(/'/, "''")
end

def quoted_true
"'t'"
end

def quoted_false
"'f'"
end

def disable_referential_integrity #:nodoc:
execute(tables.map { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(';'))
yield
Expand Down
4 changes: 0 additions & 4 deletions lib/odbc_adapter/quoting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def quote_column_name(name)
"#{quote_char.chr}#{name}#{quote_char.chr}"
end

def quoted_true
'1'
end

# Ideally, we'd return an ODBC date or timestamp literal escape
# sequence, but not all ODBC drivers support them.
def quoted_date(value)
Expand Down
22 changes: 22 additions & 0 deletions test/attributes_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'test_helper'

class AttributesTest < Minitest::Test
def test_booleans?
assert_equal true, Todo.first.published?
assert_equal false, Todo.last.published?
end

def test_integers
assert_kind_of Fixnum, User.first.letters
end

def test_strings
assert_kind_of String, User.first.first_name
assert_kind_of String, Todo.first.body
end

def test_attributes
assert_kind_of Hash, User.first.attributes
assert_kind_of Hash, Todo.first.attributes
end
end
4 changes: 4 additions & 0 deletions test/selection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ def test_find
def test_arel_conditions
assert_equal 2, User.lots_of_letters.count
end

def test_where_boolean
assert_equal 4, Todo.where(published: true).count
end
end
9 changes: 5 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
create_table :todos, force: true do |t|
t.integer :user_id
t.text :body
t.boolean :published, null: false, default: false
t.timestamps null: false
end
end
Expand All @@ -46,20 +47,20 @@ class Todo < ActiveRecord::Base
end

User.find(1).todos.create([
{ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' },
{ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', published: true },
{ body: 'Praesent ut dolor nec eros euismod hendrerit.' },
{ body: 'Curabitur lacinia metus eget interdum volutpat.' }
])

User.find(2).todos.create([
{ body: 'Nulla sollicitudin venenatis turpis vitae finibus.' },
{ body: 'Proin consectetur id lacus vel feugiat.' },
{ body: 'Nulla sollicitudin venenatis turpis vitae finibus.', published: true },
{ body: 'Proin consectetur id lacus vel feugiat.', published: true },
{ body: 'Pellentesque augue orci, aliquet nec ipsum ultrices, cursus blandit metus.' },
{ body: 'Nulla posuere nisl risus, eget scelerisque leo congue non.' },
{ body: 'Curabitur eget massa mollis, iaculis risus in, tristique metus.' }
])

User.find(4).todos.create([
{ body: 'In hac habitasse platea dictumst.' },
{ body: 'In hac habitasse platea dictumst.', published: true },
{ body: 'Integer molestie ornare velit, eu interdum felis euismod vitae.' }
])

0 comments on commit f594d0f

Please sign in to comment.