1 |
Here's an activerecord test that not passing: |
validations_test.rb -- activerecord (ruby)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
('UTF8') do Topic :title, :maximum => 5 t = Topic("title" => "一二三四五", "content" => "whatever") assert t t = "一二34五六" assert !t assert t(:title) assert_equal "is too long (maximum is 5 characters)", t["title"] end end |
output
1 2 3 4 5 6 7 8 9 10 |
5) Failure: (ValidationsTest) [test/cases/validations_test:1004:in `test_validates_length_of_using_maximum_utf8' test/cases/validations_test.rb:1442:in `with_kcode' test/cases/validations_test.rb:1000:in `test_validates_length_of_using_maximum_utf8' ./test/cases/../../../activesupport/lib/active_support/testing/setup_and_teardown:57:in `run']: <false> is not true. The error happens on this statement: assert t.valid? |
ar_utf8.rb (ruby)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# this is a plain program that should duplicate the same error # but it doesn't -- everything works correctly. if RUBY_VERSION < '1.9' orig_kcode, $KCODE = $KCODE, kcode begin yield ensure $KCODE = orig_kcode end else yield end end @logger = Logger $stderr ActiveRecord = @logger ActiveRecord = false # GRANT ALL PRIVILEGES ON my_activerecord_test.* to 'rails'@'localhost'; pool = ActiveRecord( :adapter => RUBY_PLATFORM =~ /java/ ? 'jdbcmysql' : 'mysql', :username => 'rails', :encoding => 'utf8', :database => 'my_activerecord_test' ) ActiveRecord do drop_table :posts if pool(:posts) create_table :posts do |t| t :subject t :body end end validates_length_of :subject, :maximum => 5 end ('UTF8') do p1 = Post(:subject => "一二三四五", :body => 'this is the body') len1 = p1 len2 = p1 puts "length: , " puts p1 puts p1(:subject) p2 = Post(:first) p2 = "一二34五六" puts p2 puts p2(:subject) end |
output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ jruby ar_utf8 SQL (1.3ms) SET SQL_AUTO_IS_NULL=0 -- (:posts) SQL (2.5ms) DROP TABLE `posts` -> 0.0037s -> 0 rows -- (:posts) SQL (2.2ms) CREATE TABLE `posts` (`id` (11) DEFAULT NULL auto_increment PRIMARY KEY, `subject` (255), `body` text) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin -> 0.0072s -> 0 rows SQL (2.1ms) INSERT INTO `posts` (`subject`, `body`) VALUES('一二三四五', 'this is the body') length: 15, 5 true nil Post Load (1.6ms) SELECT * FROM `posts` LIMIT 1 false is too long (maximum is 5 characters) |

