Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def native_string_database_type
end

def native_text_database_type
@@native_text_database_type || enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)'
@@native_text_database_type || (enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)')
end

def native_time_database_type
Expand Down
36 changes: 36 additions & 0 deletions test/cases/adapter_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,42 @@ class AdapterTestSqlserver < ActiveRecord::TestCase

end

context 'testing #native_string_database_type configuration' do

should 'use varchar type when set to varchar' do
with_native_string_database_type('varchar') do
assert_equal 'varchar', @connection.native_string_database_type
assert_equal 'nvarchar(max)', @connection.native_text_database_type
end
end

should 'use nvarchar type when set to nvarchar' do
with_native_string_database_type('nvarchar') do
assert_equal 'nvarchar', @connection.native_string_database_type
assert_equal 'nvarchar(max)', @connection.native_text_database_type
end
end

end

context 'testing #with_native_text_database_type configuration' do

should 'use varchar type when set to varchar' do
with_native_text_database_type('varchar(max)') do
assert_equal 'nvarchar', @connection.native_string_database_type
assert_equal 'varchar(max)', @connection.native_text_database_type
end
end

should 'use nvarchar type when set to nvarchar' do
with_native_text_database_type('nvarchar(max)') do
assert_equal 'nvarchar', @connection.native_string_database_type
assert_equal 'nvarchar(max)', @connection.native_text_database_type
end
end

end

context 'testing #lowercase_schema_reflection' do

setup do
Expand Down
16 changes: 16 additions & 0 deletions test/cases/sqlserver_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ def with_enable_default_unicode_types(setting)
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = old_string
end

def with_native_string_database_type(type)
old_string = ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = type
yield
ensure
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = old_string
end

def with_native_text_database_type(type)
old_text = ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = type
yield
ensure
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = old_text
end

def with_auto_connect(boolean)
existing = ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = boolean
Expand Down