Skip to content

Instantly share code, notes, and snippets.

@cmrd-senya
Created December 3, 2015 15:25
Show Gist options
  • Save cmrd-senya/1db9e1829ec030349280 to your computer and use it in GitHub Desktop.
Save cmrd-senya/1db9e1829ec030349280 to your computer and use it in GitHub Desktop.
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.2.5'
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
create_table :people, force: true do |t|
t.string :email
end
end
module M
def email=(value)
puts "shot!"
super
end
end
class User < ActiveRecord::Base
include M
end
class Parent < ActiveRecord::Base
self.abstract_class = true
include M
end
class Person < Parent
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
def test_first_or_create2
user = Person.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