Created
December 12, 2014 21:04
-
-
Save andrzejkrzywda/a3306ac5779a87aff255 to your computer and use it in GitHub Desktop.
Integration test for a scaffolded Post(title, content) which goes through all the pages. No validations
This file contains 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
require 'test_helper' | |
class MainTest < ActionDispatch::IntegrationTest | |
def test_main | |
#index looks ok | |
get '/' | |
assert_tag(:a, child: "New Post") | |
assert_select("a[href=/posts/new]") | |
# new form | |
get "/posts/new" | |
assert_select("form[action=\"/posts\"]") | |
assert_select("form[method=post]") | |
assert_select("input[id=post_title]") | |
assert_select("textarea[id=post_content]") | |
# submit new post | |
post "posts", post: {title: "new title", content: "new content"} | |
follow_redirect! | |
# check the post page | |
assert_tag(:p, child: /new title/) | |
assert_tag(:p, child: /new content/) | |
assert_tag(:p, child: /Post was successfully created/) | |
assert_select("a[href=/posts]") | |
# check the index page | |
get "/posts" | |
assert_tag(:td, child: "new title") | |
assert_tag(:td, child: /new content/) | |
assert_no_tag(:p, child: /Post was successfully created/) | |
# go to edit page | |
assert_select("a[href=/posts/#{Post.last.id}/edit]") | |
get "posts/#{Post.last.id}/edit" | |
assert_select("form[action=\"/posts/#{Post.last.id}\"]") | |
assert_select("form[method=post]") | |
assert_select("input[value=new title]") | |
assert_tag(:textarea, child: /new content/) | |
# update | |
patch "posts/#{Post.last.id}", post: {title: "more title", content: "more content"} | |
follow_redirect! | |
# check the post page | |
assert_tag(:p, child: /more title/) | |
assert_tag(:p, child: /more content/) | |
assert_tag(:p, child: /Post was successfully updated/) | |
# check the index page | |
get "/posts" | |
assert_tag(:td, child: "more title") | |
assert_tag(:td, child: /more content/) | |
assert_no_tag(:p, child: /Post was successfully created/) | |
# delete | |
delete "/posts/#{Post.last.id}/" | |
follow_redirect! | |
assert_no_tag(:td, child: "more title") | |
assert_no_tag(:td, child: /more content/) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment