Skip to content

Commit

Permalink
User can delete her own posts, not other authors'
Browse files Browse the repository at this point in the history
Added steps to fabricate blog with current user as author

added step to say I am signed in as user that did not author the post.
  • Loading branch information
maxbeizer committed Nov 8, 2012
1 parent 2711527 commit 8606aa3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
27 changes: 11 additions & 16 deletions features/authors_can_delete_posts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,33 @@ Feature: Authors can delete posts

Scenario: I can delete a post I wrote
Given I am signed in as "[email protected]"
Given the following posts:
| title | body | author_id |
| Foo | Foo Bar | 1 |
Given I have created a blog post with title "foo" and body "bar"
When I go to the homepage
And I click "Delete this post"
Then I should see "Your post has been deleted"
And I should be on the homepage
And I should not see the title "Foo"
And I should not see the title "foo"
And I should not see "Foo Bar"


@wip
Scenario: I cannot delete posts if I am not signed in
Given I am not signed in
Given the following posts:
| title | body | author_id |
| Foo | Foo Bar | 1 |
Given the following post:
| title | foo |
| body | Foo Bar |
When I go to the homepage
Then I should not see "Delete this post"
And I should be on the homepage
And I should see the title "Foo"
And I should see the title "foo"
And I should see "Foo Bar"

@wip
Scenario: I cannot delete posts I didn't write
Given I am signed in as "[email protected]"
Given the following posts:
| title | body | author_id |
| Foo | Foo Bar | 2 |
Given the following post:
| title | foo |

This comment has been minimized.

Copy link
@elizabrock

elizabrock Nov 12, 2012

Member

For what it's worth- if you've recorded the current user (via @user in the step definitions), you can use fabricate magic to hook up the post for you:

Given I am signed in as "[email protected]"
And I have the following post:
| title | foo |
| body  | bar |

This comment has been minimized.

Copy link
@maxbeizer

maxbeizer Nov 14, 2012

Author

Interesting. In this case it is not applicable as this is for a post that the user didn't write. It would work for for lines 4-5. Should I change it there?

This comment has been minimized.

Copy link
@elizabrock

elizabrock Nov 14, 2012

Member

I must have commented on the wrong lines. It's your call if you want to replace it.

| body | Foo Bar |
Given I am signed in as a user that did not write the post
When I go to the homepage
Then I should not see "Delete this post"
And I should be on the homepage
And I should see the title "Foo"
And I should see the title "foo"
And I should see "Foo Bar"

6 changes: 6 additions & 0 deletions features/step_definitions/authentication_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
@user = nil
end

Given "I am signed in as a user that did not write the post" do
post = Post.last
@user = User.where("id != ?", post.author_id).first || Fabricate(:user)
sign_in_as @user
end

def sign_in_as user
steps %Q{
Given I am on the homepage
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/blog_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
Then /^I should be viewing that blog post$/ do
step %{I should be on that blog post's page}
end

Given /^I have created a blog post with title "(.*?)" and body "(.*?)"$/ do |title, body|
Fabricate(:post, author: @user, title: title, body: body)
end

0 comments on commit 8606aa3

Please sign in to comment.