Skip to content

Instantly share code, notes, and snippets.

@sealocal
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sealocal/8745714 to your computer and use it in GitHub Desktop.
Save sealocal/8745714 to your computer and use it in GitHub Desktop.
Test for Deleting a Record from a Model with Capybara
#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