Skip to content

Instantly share code, notes, and snippets.

@armhold
Last active December 19, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armhold/5892370 to your computer and use it in GitHub Desktop.
Save armhold/5892370 to your computer and use it in GitHub Desktop.
demonstrates encoding bug in Rails4
#!/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