Sha256: 1b543e0b0c3bf92b12b73fe8aa75786296dbd0d9e5a4a5c009a9e5427bb8dc3d
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 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 => "new", :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 => "new") 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
stepper-0.0.4 | test/controllers/controller_resource_test.rb |
stepper-0.0.3 | test/controllers/controller_resource_test.rb |
stepper-0.0.1 | test/controllers/controller_resource_test.rb |