require File.dirname(__FILE__) + '/../test_helper' class Muck::OrdersControllerTest < ActionController::TestCase tests Muck::OrdersController context "logged in without billing information" do setup do @user = Factory(:user) populate_cart(@user) activate_authlogic login_as @user end context "GET index" do setup do get :index end should_respond_with :success should_render_template :index end context "GET show" do setup do get :show, {:id => Factory(:order, :orderable => @user)} end should_respond_with :success should_render_template :show end context "GET new" do setup do get :new end should_respond_with :success should_render_template :new end context "POST create order with new billing information" do setup do post :create, :billing_information => billing_params, :amount => 100 end should_redirect_to("user_order_path(@user, assigns['order'])") { user_order_path(@user, assigns['order'], :new_order => true) } should "not have errors on the billing object" do assert assigns['billing_information'].errors.empty?, assigns['billing_information'].errors.full_messages.to_sentence end end context "POST create with bad verification value" do setup do post :create, :billing_information => billing_params(:verification_value => ''), :amount => 100 end should_respond_with :success should_render_template :new should "add a billing error to the flash" do ensure_flash_contains(I18n.t('muck.commerce.billing_information_update_error_friendly', :error => '')) end should "have errors on the billing object" do assert assigns['billing_information'].errors.on(:verification_value), assigns['billing_information'].errors.full_messages.to_sentence end end context "POST create with bad credit card" do setup do post :create, :billing_information => billing_params(:credit_card_number => ''), :amount => 100 end should_respond_with :success should_render_template :new should "add a billing error to the flash" do ensure_flash_contains(I18n.t('muck.commerce.payment_information_problem', :message => '')) end should "have errors on the billing object" do assert assigns['billing_information'].errors.on(:credit_card_number), assigns['billing_information'].errors.full_messages.to_sentence end end end # TODO shopping cart is decoupled for now. Add this test back in when shopping cart is implemented # context "user logged in with empty shopping cart" do # setup do # @user = Factory(:user) # login_as @user # post_create_billing # end # should_redirect_to("'cart_path'") { cart_path } # should_set_the_flash_to(/Your shopping cart is empty/i) # end # # context "not logged in with empty shopping cart" do # setup do # post_create_billing # end # should_redirect_to("'cart_path'") { cart_path } # should_set_the_flash_to(/Your shopping cart is empty/i) # end # TODO add these tests after adding ach support # create order with ach information # update billing during checkout with bad ach end