Sha256: 89567e127e1216021dda79b4c0584dc6393aa63a3c7e8cc5eed8251f92f7d1f3

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

require "helper"

class CompaniesUpdateControllerTest < ActionController::TestCase
  tests CompaniesController

  setup do
    Company.expects(:find).with('1').returns(mock_company)
    mock_company.expects(:attributes=).with({'code' => '23'}).returns(true)
    mock_company.expects(:save).returns(true)
    mock_company.stubs(:id).returns(1)
  end

  test "should redirect to next step if commit 'Next step'" do
    mock_company.stubs(:stepper_current_step).returns("step2")
    put(:update, {:company => {:code => "23"}, :commit => "Next step", :id => 1})
    assert_response :redirect
    assert_redirected_to "http://test.host/companies/1/next_step"
  end

  test "should redirect to index if commit 'Finish later'" do
    mock_company.stubs(:previous_step!)
    put(:update, {:company => {:code => "23"}, :commit => "Finish later", :id => 1})
    assert_response :redirect
    assert_redirected_to "http://test.host/companies"
  end

  test "should redirect to previous step if commit 'Previous step'" do
    mock_company.expects(:previous_step!).returns(mock_company).at_least(2)
    mock_company.stubs(:current_step).returns("step2")
    put(:update, {:company => {:code => "23"}, :commit => "Previous step", :id => 1})
    assert_response :redirect
    assert_redirected_to "http://test.host/companies/1/next_step"
  end

  test "should redirect to show if commit 'Finish form'" do
    put(:update, {:company => {:code => "23"}, :commit => "Finish form", :id => 1})
    assert_response :redirect
    assert_redirected_to "http://test.host/companies/1"
  end

  protected
  def mock_company(stubs={})
    @mock_company ||= mock(stubs)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stepper-0.2.0 test/controllers/controller_update_test.rb
stepper-0.1.0 test/controllers/controller_update_test.rb