You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to 6.1.3 the test should be all green but I am getting this error.
Failures:
User#products association destroys the associated products on self destruct
Failure/Error: @user.destroy
NoMethodError:
undefined method `name' for nil:NilClass
./spec/models/user_spec.rb:47:in`block (3 levels) in <top (required)>'
Finished in 0.66239 seconds
46 examples, 1 failure
Failed examples:
rspec ./spec/models/user_spec.rb:44 # User#products association destroys the associated products on self destruct
This is my user_spec.rb
require 'spec_helper'
describe User do
before { @user = FactoryGirl.build(:user) }
subject { @user }
it { should respond_to(:email) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:auth_token) }
it { should be_valid }
it { should validate_presence_of(:email) }
it { should validate_uniqueness_of(:email) }
it { should validate_confirmation_of(:password) }
it { should allow_value('[email protected]').for(:email) }
it { should validate_uniqueness_of(:auth_token)}
it { should have_many(:products) }
describe "#generate_authentication_token!" do
it "generates a unique token" do
Devise.stub(:friendly_token).and_return("auniquetoken123")
@user.generate_authentication_token!
expect(@user.auth_token).to eql "auniquetoken123"
end
it "generates another token when one already has been taken" do
existing_user = FactoryGirl.create(:user, auth_token: "auniquetoken123")
@user.generate_authentication_token!
expect(@user.auth_token).not_to eql existing_user.auth_token
end
end
describe "#products association" do
before do
@user.save
3.times { FactoryGirl.create :product, user: @user }
end
it "destroys the associated products on self destruct" do
products = @user.products
@user.destroy
products.each do |product|
expect(Product.find(product)).to raise_error ActiveRecord::RecordNotFound
end
end
end
end
The text was updated successfully, but these errors were encountered:
According to 6.1.3 the test should be all green but I am getting this error.
This is my user_spec.rb
The text was updated successfully, but these errors were encountered: