Skip to content

Commit

Permalink
creating the checkout form. testing the output of the form.
Browse files Browse the repository at this point in the history
  • Loading branch information
illuminerdi committed Feb 10, 2009
1 parent 81110ed commit c3e6978
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/order.rb
@@ -1,3 +1,9 @@
class Order < ActiveRecord::Base
has_many :line_items

PAYMENT_TYPES = [
["Check", "check"],
["Credit card", "cc"],
["Purchase order", "po"]
]
end
33 changes: 33 additions & 0 deletions app/views/store/checkout.html.erb
@@ -0,0 +1,33 @@
<div class="depot-form">

<%= error_messages_for 'order' %>
<% form_for :order, :url => {:action => :save_order} do |form| -%>
<fieldset>
<legend>Please Enter Your Details</legend>
<p>
<%= label :order, :name, "Name:" %>
<%= form.text_field :name, :size => 40 %>
</p>
<p>
<%= label :order, :address, "Address:" %>
<%= form.text_area :address, :rows => 3, :cols => 40 %>
</p>
<p>
<%= label :order, :email, "E-Mail:" %>
<%= form.text_field :email, :size => 40 %>
</p>

<p>
<%= label :order, :pay_type, "Pay with:" %>
<%=
form.select :pay_type,
Order::PAYMENT_TYPES,
:prompt => "Select a payment method"
%>
</p>
<%= submit_tag "Place Order", :class => "submit" %>
</fieldset>
<% end -%>

</div>
16 changes: 16 additions & 0 deletions test/functional/store_controller_test.rb
Expand Up @@ -66,4 +66,20 @@ class StoreControllerTest < ActionController::TestCase

#assert_match /<div id=\"notice\"/, @response.body
end

test "checkout does not allow empty cart" do
get :index
post :checkout
assert_redirected_to :controller => :store, :action => :index
end

test "checkout form has all required fields" do
post :add_to_cart, :id => products(:one)
post :checkout
assert_response :success
assert_tag :tag => 'input', :attributes => {:type => 'text', :name => 'order[name]'}
assert_tag :tag => 'textarea', :attributes => {:name => 'order[address]'}
assert_tag :tag => 'input', :attributes => {:type => 'text', :name => 'order[email]'}
assert_tag :tag => 'select', :attributes => {:name => 'order[pay_type]'}
end
end

0 comments on commit c3e6978

Please sign in to comment.