Skip to content

Instantly share code, notes, and snippets.

@iantropov
Last active December 27, 2015 21:49
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 iantropov/7394507 to your computer and use it in GitHub Desktop.
Save iantropov/7394507 to your computer and use it in GitHub Desktop.
Test case for Rails issue #7807
gemfile_path = "#{File.basename(__FILE__, '.rb')}.gemfile"
ENV['BUNDLE_GEMFILE'] = File.expand_path(gemfile_path)
unless File.exists?(gemfile_path)
File.write(gemfile_path, <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'sqlite3'
GEMFILE
system "bundle --gemfile=#{gemfile_path} --clean"
end
require 'bundler'
Bundler.setup(:default)
# Activate the gem you are reporting the issue against.
require 'active_record'
require 'minitest/autorun'
require 'logger'
# 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 :products do |t|
t.string :name
t.timestamps
end
end
class Product < ActiveRecord::Base
end
class BugTest < MiniTest::Unit::TestCase
def test_state
p = Product.new(name: 'Awesome Product')
begin
Product.transaction do
p.save
p.save
raise "exception"
end
rescue
end
assert_equal true, p.instance_eval { @new_record }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment