Created
May 19, 2015 11:51
-
-
Save jacek213/93f8c2091e4ce8ef70f6 to your computer and use it in GitHub Desktop.
Test the acceptance validation for Rails 4.2.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '4.2.1' | |
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.boolean :terms1, limit: 1, default: false, null: false | |
t.boolean :terms2, limit: 1, default: false, null: false | |
end | |
end | |
class User < ActiveRecord::Base | |
validates :terms1, :acceptance => {:accept => true} | |
validates :terms2, :acceptance => {:accept => true} | |
end | |
class BugTest < Minitest::Test | |
def test_acceptance_validation | |
# ActiveRecord::StatementInvalid: SQLite3::ConstraintException: NOT NULL constraint failed: users.terms1: INSERT INTO "users" ("terms1", "terms2") VALUES (?, ?) | |
User.create!(terms1: '', terms2: '') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment