Sha256: 66f9e52139e0376a1f6d01b110f69c42b0e475e91dd3f9528554c46a5cee7002

Contents?: true

Size: 1.64 KB

Versions: 20

Compression:

Stored size: 1.64 KB

Contents

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"
      @encoded_unicode_data = "\344\270\200\344\272\21434\344\272\224\345\205\255".force_encoding('UTF-8') if ruby_19?
    end

    should 'insert into nvarchar field' do
      assert data = SqlServerUnicode.create!(:nvarchar => @unicode_data)
      assert_equal @unicode_data, data.reload.nvarchar
    end
    
    should 're-encode data on DB reads' do
      assert data = SqlServerUnicode.create!(:nvarchar => @unicode_data)
      assert_equal @encoded_unicode_data, data.reload.nvarchar
    end if ruby_19?

  end
  
  
  
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
rails-sqlserver-2000-2005-adapter-2.2.18 test/cases/unicode_test_sqlserver.rb
rails-sqlserver-2000-2005-adapter-2.2.19 test/cases/unicode_test_sqlserver.rb
rails-sqlserver-2000-2005-adapter-2.2.21 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.11 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.10 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.9 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.8 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.7 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.6 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.5 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.4 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.3 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.2 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3.1 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.3 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.2.22 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.2.21 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.2.20 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.2.19 test/cases/unicode_test_sqlserver.rb
activerecord-sqlserver-adapter-2.2.18 test/cases/unicode_test_sqlserver.rb