Sha256: fb19f949474172cbda76eba98e675f421f45776ac05789b067186f81d4cfb55e

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

# encoding: UTF-8
require 'cases/sqlserver_helper'

class UnicodeTestSqlserver < ActiveRecord::TestCase
  
  
  context 'Testing basic saves and unicode limits' do

    should 'save and reload simple nchar string' do
      assert nchar_data = SqlServerUnicode.create!(:nchar => 'A')
      assert_equal 'A', SqlServerUnicode.find(nchar_data.id).nchar
    end
    
    should 'save and reload simple nvarchar(max) string' do
      test_string = 'Ken Collins'
      assert nvarcharmax_data = SqlServerUnicode.create!(:nvarchar_max => test_string)
      assert_equal test_string, SqlServerUnicode.find(nvarcharmax_data.id).nvarchar_max
    end if sqlserver_2005? || sqlserver_2008?

    should 'enforce default nchar_10 limit of 10' do
      assert_raise(ActiveRecord::StatementInvalid) { SqlServerUnicode.create!(:nchar => '01234567891') }
    end

    should 'enforce default nvarchar_100 limit of 100' do
      assert_raise(ActiveRecord::StatementInvalid) { SqlServerUnicode.create!(:nvarchar_100 => '0123456789'*10+'1') }
    end

  end
  
  context 'Testing unicode data' do

    setup do
      @unicode_data = "\344\270\200\344\272\21434\344\272\224\345\205\255" # "一二34五六"
    end

    should 'insert and retrieve unicode data' do
      assert data = SqlServerUnicode.create!(:nvarchar => @unicode_data)
      if connection_mode_dblib?
        assert_equal "一二34五六", data.reload.nvarchar
      elsif connection_mode_odbc?
        assert_equal "一二34五六", data.reload.nvarchar, 'perhaps you are not using the utf8 odbc that does this legwork'
      elsif connection_mode_adonet?
        assert_equal "一二34五六", data.reload.nvarchar
      else
        raise 'need to add a case for this'
      end
      assert_equal Encoding.find('UTF-8'), data.nvarchar.encoding if ruby_19?
    end

  end
  
  
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-2.3.24 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.23 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.22 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.21 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.20 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.19 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.18 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.17 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.16 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.15 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.13 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.12 test/cases/unicode_test_sqlserver.rb