Last active
December 19, 2015 03:48
-
-
Save armhold/5892370 to your computer and use it in GitHub Desktop.
demonstrates encoding bug in Rails4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '4.0.0' # NB: works fine with 3.2.13 | |
gem 'mysql2' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
# works fine w/ sqlite3 | |
#ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'YOUR_MYSQL_DB', username: 'YOUR_MYSQL_USER', password: 'YOUR_MYSQL_PASSWORD', encoding: 'utf8') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :posts do |t| | |
t.text "description" | |
end | |
end | |
class Post < ActiveRecord::Base | |
end | |
class BugTest < MiniTest::Unit::TestCase | |
# OK | |
def test_yen | |
post = Post.create!(description: "\u{A5}") | |
end | |
# fails | |
def test_emoji | |
post = Post.create!(description: "\u{1f525}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment