Jcrawshaw/Bloccit — pull request #3 by linojon (2014-11-20 04:52:21+00:00)
Title: fix profiles_spec so it demonstrates the authenticated user error and fixes it

hi, i found the problem with your rspec.

On line 32 of profiles_spec.rb, you have ```login_as(authenticated_user, :scope => :user)```, this creates a new user record (eg id 3), which is different than the one created in line 10 ```@user = authenticated_user``` which was used to create the post and comment.

When you go to @user's profile page (user id 1), and it renders comments using views/comments/_comment.html.erb, it asks if it can show the Delete link by calling ```if policy(comment).destroy?```, Tracing that policy, it checks if the current user is the owner of the comment, but current_user is 3 , the owner user 1, so the ```link_to "Delete", [ comment.post, comment], method: :delete``` is never called/rendered.

So, the spec doesnt fail.

When we fix line 32 to say ```login_as(@user, :scope => :user)``` then user 1 is logged in, user 1 owns the comment, the partial tries to render the Delete button and gets the error we thought would happen.

At that point, you need to fix the spec (not the app) by giving the comment a post id, e.g. line 12 ```@comment = Comment.new(user: @user, post: @post, body: "A Comment")```

Whew!