Last active
August 29, 2015 13:55
-
-
Save sealocal/8745714 to your computer and use it in GitHub Desktop.
Test for Deleting a Record from a Model with Capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Use this line, replacing :id with and integer. | |
page.driver.submit :delete, "/posts/:id", {} | |
#You can also use fixtures | |
page.driver.submit :delete, "/posts/#{posts(:cr).id}", {} | |
featuren "Deleting a Post" do | |
scenario "As an author I should not be able to delete posts so that I can give the editor publishing control" do | |
#Given an author role | |
sign_in(:author) | |
#When I visit the posts index page | |
visit posts_path | |
#Then I should not see the "Destroy" link | |
page.wont_have_link "Destroy" | |
page.driver.submit :delete, "/posts/#{posts(:cr).id}", {} | |
#Then I will receive an error message | |
page.text.must_include "You are not authorized for that action!" | |
#When I visit the posts index page | |
visit posts_path | |
#Then the post will not be displayed | |
page.text.must_include posts(:cr).body | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment