Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

orders_controller_test updated with some more tests when invalid orde…

…r is placed
  • Loading branch information...
commit 29b802f27ac52948d590ddf0050636a5e414a17e 1 parent 10614fd
Mark Holton authored
View
BIN  db/test.sqlite3
Binary file not shown
View
34 test/functional/orders_controller_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.