Class: PolymorphicFactoriesTest
- Inherits:
-
ActionController::TestCase
- Object
- ActionController::TestCase
- PolymorphicFactoriesTest
- Defined in:
- lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_expose_a_new_employee_on_new ⇒ Object
- #test_expose_a_newly_create_employee_on_create ⇒ Object
- #test_expose_all_employees_as_instance_variable_on_index ⇒ Object
- #test_expose_the_resquested_employee_on_edit ⇒ Object
- #test_expose_the_resquested_employee_on_show ⇒ Object
- #test_polymorphic_helpers ⇒ Object
- #test_the_resquested_employee_is_destroyed_on_destroy ⇒ Object
- #test_update_the_requested_object_on_update ⇒ Object
Instance Method Details
#setup ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 17 def setup Factory.expects(:find).with('37').returns(mock_factory) mock_factory.expects(:employees).returns(Employee) @controller.stubs(:resource_url).returns('/') @controller.stubs(:collection_url).returns('/') end |
#test_expose_a_new_employee_on_new ⇒ Object
39 40 41 42 43 44 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 39 def test_expose_a_new_employee_on_new Employee.expects(:build).returns(mock_employee) get :new, :factory_id => '37' assert_equal mock_factory, assigns(:factory) assert_equal mock_employee, assigns(:employee) end |
#test_expose_a_newly_create_employee_on_create ⇒ Object
54 55 56 57 58 59 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 54 def test_expose_a_newly_create_employee_on_create Employee.expects(:build).with({'these' => 'params'}).returns(mock_employee(:save => true)) post :create, :factory_id => '37', :employee => {:these => 'params'} assert_equal mock_factory, assigns(:factory) assert_equal mock_employee, assigns(:employee) end |
#test_expose_all_employees_as_instance_variable_on_index ⇒ Object
25 26 27 28 29 30 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 25 def test_expose_all_employees_as_instance_variable_on_index Employee.expects(:find).with(:all).returns([mock_employee]) get :index, :factory_id => '37' assert_equal mock_factory, assigns(:factory) assert_equal [mock_employee], assigns(:employees) end |
#test_expose_the_resquested_employee_on_edit ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 46 def test_expose_the_resquested_employee_on_edit Employee.expects(:find).with('42').returns(mock_employee) get :edit, :id => '42', :factory_id => '37' assert_equal mock_factory, assigns(:factory) assert_equal mock_employee, assigns(:employee) assert_response :success end |
#test_expose_the_resquested_employee_on_show ⇒ Object
32 33 34 35 36 37 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 32 def test_expose_the_resquested_employee_on_show Employee.expects(:find).with('42').returns(mock_employee) get :show, :id => '42', :factory_id => '37' assert_equal mock_factory, assigns(:factory) assert_equal mock_employee, assigns(:employee) end |
#test_polymorphic_helpers ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 77 def test_polymorphic_helpers mock_factory.stubs(:class).returns(Factory) Employee.expects(:find).with(:all).returns([mock_employee]) get :index, :factory_id => '37' assert @controller.send(:parent?) assert_equal :factory, assigns(:parent_type) assert_equal :factory, @controller.send(:parent_type) assert_equal Factory, @controller.send(:parent_class) assert_equal mock_factory, assigns(:factory) assert_equal mock_factory, @controller.send(:parent) end |
#test_the_resquested_employee_is_destroyed_on_destroy ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 69 def test_the_resquested_employee_is_destroyed_on_destroy Employee.expects(:find).with('42').returns(mock_employee) mock_employee.expects(:destroy) delete :destroy, :id => '42', :factory_id => '37' assert_equal mock_factory, assigns(:factory) assert_equal mock_employee, assigns(:employee) end |
#test_update_the_requested_object_on_update ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 61 def test_update_the_requested_object_on_update Employee.expects(:find).with('42').returns(mock_employee) mock_employee.expects(:update_attributes).with({'these' => 'params'}).returns(true) put :update, :id => '42', :factory_id => '37', :employee => {:these => 'params'} assert_equal mock_factory, assigns(:factory) assert_equal mock_employee, assigns(:employee) end |