I'm trying to make a spec test for the MHartl's example. As it follows bellow my difficult is for #Follows a user.
class User < ActiveRecord::Base
# Associations
has_many :active_relationships, class_name: "Relationship",
foreign_key: "follower_id",
dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower
# Follows a user.
def follow(other_user)
active_relationships.create(followed_id: other_user.id)
end
For my spec:
require 'rails_helper'
RSpec.describe User, :type => :model do
let(:user) { build(:user) }
describe 'Validations' do
it 'has a valid factory' do
expect(user).to be_valid
end
describe 'following utility methods' do
it "user starts to follow other user" do
user.follow(:other_user)
user.following?(:other_user).should be_valid
end
end
end
My failures :
Failures:
1) User following utility methods user starts to follow other user
Failure/Error: active_relationships.create(followed_id: other_user.id)
NoMethodError:
undefined method `id' for :other_user:Symbol
If you need more info about this post, please fell free to ask! and please tell me were can I learn more about this specs tests. thanks for your help :)
Aucun commentaire:
Enregistrer un commentaire