Skip to content

Commit

Permalink
orders_controller_test updated with some more tests when invalid orde…
Browse files Browse the repository at this point in the history
…r is placed
  • Loading branch information
Mark Holton authored and Mark Holton committed Feb 16, 2009
1 parent 10614fd commit 29b802f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Binary file modified db/test.sqlite3
Binary file not shown.
34 changes: 34 additions & 0 deletions test/functional/orders_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,38 @@ def setup

assert_redirected_to orders_path
end

test "should not create new order and show red boxes when order name does not exist" do
assert_no_difference('Order.count') do
post :create, :order => {
:name => '',
:address => '',
:email => '',
:pay_type => ''
}
end

assert_response :ok
assert_tag :tag => "div", :attributes => { :id => "errorExplanation" }
assert_tag :tag => "div", :attributes => { :class => "fieldWithErrors"}
assert_select "div[class*=fieldWithErrors]", :count => 8 #labels and input elements
assert_select "div[class*=errorExplanation]", :count => 1
# check explicitly that both the input is blank for Title and it is a fieldWithErrors
assert_select "div.fieldWithErrors" do
assert_select "input:last-of-type", ""
end
# check explicitly that both the input#product_price errs out and is blank
assert_equal 3, css_select("div.fieldWithErrors > input").size
assert_equal 1, css_select("div.fieldWithErrors > textarea").size
assert_select "div.fieldWithErrors > input#order_name", :text => ""
assert_select "div.fieldWithErrors > textarea#order_address", :text => ""
assert_select "div.fieldWithErrors > input#order_email", :text => ""
assert_select "div.fieldWithErrors > input#order_pay_type", :text => ""
assert_select "div#errorExplanation > ul > li", :text => "Name can't be blank"
assert_select "div#errorExplanation > ul > li", :text => "Pay type can't be blank"
assert_select "div#errorExplanation > ul > li", :text => "Pay type is not included in the list"
assert_select "div#errorExplanation > ul > li", :text => "Address can't be blank"
assert_select "div#errorExplanation > ul > li", :text => "Email can't be blank"
assert_select "div#errorExplanation > ul > li", :count => 5 #labels and input elements
end
end

0 comments on commit 29b802f

Please sign in to comment.