Skip to content

Instantly share code, notes, and snippets.

@haggen
Created February 8, 2014 21:33
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 haggen/8890680 to your computer and use it in GitHub Desktop.
Save haggen/8890680 to your computer and use it in GitHub Desktop.
Rails' ActiveModel#create returns truthy value even when the model is invalid
gem 'activerecord', '4.1.0.beta1'
require 'active_record'
require 'minitest/autorun'
require 'logger'
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 :posts do |t|
t.string :title
end
end
# *** Actual bug related snippet
class Post < ActiveRecord::Base
validates_presence_of :title
end
class BugTest < Minitest::Test
def test_save_return_value
assert_equal false, !!Post.new.save
end
def test_create_return_value
assert_equal false, !!Post.create
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment