Skip to content

Instantly share code, notes, and snippets.

@andrey-skat
Created February 18, 2015 16:33
Show Gist options
  • Save andrey-skat/84d3b2f0203391f45f3b to your computer and use it in GitHub Desktop.
Save andrey-skat/84d3b2f0203391f45f3b to your computer and use it in GitHub Desktop.
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.2.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :email
end
end
class User < ActiveRecord::Base
def email=(value)
super
end
end
class BugTest < Minitest::Test
def test_first_or_create
user = User.where(email: 'email@email.com').first_or_create!
assert_equal 'email@email.com', user.email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment