Sha256: fe67d7c321e47ccc1ad9d30afaf46848a5831a6fc96b0621e5f15f05155a68c5
Contents?: true
Size: 1.85 KB
Versions: 2
Compression:
Stored size: 1.85 KB
Contents
require 'helper' class ControllerResourceTest < ActiveSupport::TestCase setup do @params = HashWithIndifferentAccess.new(:controller => "companies") @controller_class = Class.new @controller = @controller_class.new @controller.stubs(:params).returns(@params) end test "should load resource into instance variable if params[:id] is specified" do Company.stubs(:find).with(1).returns(mock_company(:id => 1)) @params.merge!(:action => "next_step", :id => mock_company.id) resource = Stepper::ControllerResource.new(@controller) resource.load_resource assert_equal @controller.instance_variable_get(:@company), mock_company end test "should build resource and load into instance variable if params[:id] is not specified" do Company.stubs(:new).returns(mock_company) @params.merge!(:action => "some_action") resource = Stepper::ControllerResource.new(@controller) resource.load_resource assert_equal @controller.instance_variable_get(:@company), mock_company end test "should load resource into instance variable(:new)" do Company.stubs(:new).returns(mock_company) @params.merge!(:action => "create") resource = Stepper::ControllerResource.new(@controller) resource.load_resource assert_equal @controller.instance_variable_get(:@company), mock_company end test "should not load resource into instance variable if instance variable exists" do @controller.instance_variable_set(:@company, mock_company) @params.merge!(:action => "next_step", :id => 15) resource = Stepper::ControllerResource.new(@controller) resource.load_resource assert_equal @controller.instance_variable_get(:@company), mock_company 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_resource_test.rb |
stepper-0.1.0 | test/controllers/controller_resource_test.rb |