Skip to content

Instantly share code, notes, and snippets.

@Edouard-chin
Last active March 19, 2016 01:55
Show Gist options
  • Save Edouard-chin/b0233d159d6132662309 to your computer and use it in GitHub Desktop.
Save Edouard-chin/b0233d159d6132662309 to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
end
require 'active_record'
require 'active_support'
require 'active_support/core_ext/object/blank'
require 'minitest/autorun'
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :authors, force: true do |t|
t.string :name
t.integer :age
end
end
class Author < ActiveRecord::Base
attribute :does_not_exist, ActiveRecord::Type::String.new
end
class BugTest < ActiveSupport::TestCase
def test_raises_an_exception_when_partial_write_is_disabled
ActiveRecord::Base.partial_writes = false
assert_raises_with_message(ActiveRecord::StatementInvalid, /table authors has no column named does_not_exist/) do
Author.create!(name: 'john', age: 18)
end
end
def test_doesnt_raise_when_partial_write_is_enabled
assert_nothing_raised do
Author.create!(name: 'john', age: 18)
end
end
private
def assert_raises_with_message(exception_class, message, &block)
err = assert_raises(exception_class) { block.call }
assert_match message, err.message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment