「メールアドレスが既に使用されているユーザー」のテストに問題があります。テストを実行すると、次のように表示されます
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)>'
何をプライベートと定義しているのかわからず、呼び出すことができません。
これがテストです
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
そしてここにユーザーモデル
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
ありがとうございました