Created
June 7, 2014 19:31
-
-
Save kuldeepaggarwal/60c68038134c924e9ca5 to your computer and use it in GitHub Desktop.
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.0.2' | |
require 'active_record' | |
require 'debugger' | |
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 do |t| | |
t.string :email | |
end | |
add_index :users, :email, name: "index_users_on_email", unique: true | |
end | |
class User < ActiveRecord::Base | |
before_validation { self.email = email.downcase } | |
VALID_EMAIL_REGEX = /\A[\w+\-.]+@mailinator\.com\z/i | |
validates :email, presence: true, uniqueness: true, format: { | |
with: VALID_EMAIL_REGEX, | |
message: "must be a Mailinator email address." | |
} | |
end | |
class BugTest < Minitest::Test | |
def test_uniqueness | |
user1 = User.create! email: '[email protected]' | |
user2 = User.create! email: '[email protected]' | |
assert_equal false, user2.update_attributes(id: user2.id, email: '[email protected]') | |
assert_raises(ActiveRecord::RecordInvalid) { user2.update_attributes!(id: user2.id, email: '[email protected]') } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment