Sha256: 5a837f71fcf529e4170b8cbbf1a7e1a70fcb21dd3a906c9d83a46f8b37d7e408

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

#---
# Excerpted from "Agile Web Development with Rails, 2nd Ed."
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.
#---
require File.dirname(__FILE__) + '/../test_helper'
require 'amrita2/testsupport'
require 'store_controller'

module StoreControllerMixinForTest
  def index_erb
    index
    render :template=>'store/index.html.erb', :layout=>'store.rhtml'
  end

  def checkout_erb
    checkout
    render :template=>'store/checkout.html.erb', :layout=>'store.rhtml'
  end
end

class StoreController
  include StoreControllerMixinForTest
end

class StoreControllerTest < Test::Unit::TestCase
  fixtures :products

  def setup
    @controller = StoreController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
    ActionView::Base.register_template_handler(:a2, Amrita2View::Base)
  end

  def test_index
    get :index_erb
    erb_result = @response.body
    #puts erb_result
    get :index
    amrita2_result = @response.body
    #puts amrita2_result
    assert_equal_as_xml(erb_result, amrita2_result)
  end

  def test_post_to_add_to_cart
    get :index
    ruby_id = products(:ruby_book).id
    assert_select "form[action=/store/add_to_cart/#{ruby_id}][method=post]"

    post :add_to_cart, :id=>ruby_id

    test_index
  end

  def test_checkout
    ruby_id = products(:ruby_book).id
    get :index
    post :add_to_cart, :id=>ruby_id

    get :checkout
    amrita2_result = @response.body
    #puts amrita2_result
    get :checkout_erb
    erb_result = @response.body
    assert_equal_as_xml(erb_result, amrita2_result)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amrita2-2.0.1 sample/depot/test/functional/store_controller_test.rb
amrita2-2.0.2 sample/depot/test/functional/store_controller_test.rb