I have a problem with the test of "User when email address is already taken", here is what it shows when I run the test
1) User when email address is already taken
Failure/Error: user_with_same_email = @user.dup
NoMethodError:
private method `initialize_dup' called for #<User:0x007f9710c7c528>
# ./spec/models/user_spec.rb:78:in `block (3 levels) in <top (required)>'
I don't realize what I am defining as private and I can't call.
Here is the test
describe "when email address is already taken" do
before do
user_with_same_email = @user.dup
user_with_same_email.email = @user.email.upcase
user_with_same_email.save
end
it { should_not be_valid }
end
and here the user model
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
has_many :microposts, dependent: :destroy
before_save { self.email.downcase! }
before_save :create_remember_token
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
validates :name, presence: true, length: { maximum: 50}
validates :password, length: { minimum: 6 }
validates :password_confirmation, presence: true
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
Thank you