Answer the question
In order to leave comments, you need to log in
How to understand controller testing in Rails?
Hello, I will be grateful if you explain what this controller test does.
I do the lesson. Before that, everything is clear and understandable, but in testing I just started to disassemble it and I don’t understand a little what is happening here.
test "Invalid category submission results in failture" do
get new_category_path
assert_template 'categories/new'
assert_difference 'Category.count', 1 do
post_via_redirect categories_path, category: {name: " "}
end
assert_template 'categories/new'
assert_select "h2.panel-title"
assert_select "div.panel-body"
end
Answer the question
In order to leave comments, you need to log in
Everything happens like this:
Go to the page at the address new_category_path
Make sure that this page was rendered using the template at the addressapp/categories/new.html.erb
assert_difference 'Category.count', 1 do
post_via_redirect categories_path, category: {name: " "}
end
categories_path
, a new category is actually created. assert_select "h2.panel-title"
assert_select "div.panel-body"
h2.panel-title
and in the DOM of the page div.panel-body
(here, most likely, a check that the form was made using one well-known css framework).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question