Class: OptionalTest
- Inherits:
-
ActionController::TestCase
- Object
- ActionController::TestCase
- OptionalTest
- Defined in:
- lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_expose_a_new_product_with_category ⇒ Object
- #test_expose_a_new_product_without_category ⇒ Object
- #test_expose_a_newly_create_product_with_category ⇒ Object
- #test_expose_a_newly_create_product_without_category ⇒ Object
- #test_expose_all_products_as_instance_variable_with_category ⇒ Object
- #test_expose_all_products_as_instance_variable_without_category ⇒ Object
- #test_expose_the_resquested_product_for_edition_with_category ⇒ Object
- #test_expose_the_resquested_product_for_edition_without_category ⇒ Object
- #test_expose_the_resquested_product_with_category ⇒ Object
- #test_expose_the_resquested_product_without_category ⇒ Object
- #test_polymorphic_helpers ⇒ Object
- #test_the_resquested_product_is_destroyed_with_category ⇒ Object
- #test_the_resquested_product_is_destroyed_without_category ⇒ Object
- #test_update_the_requested_object_with_category ⇒ Object
- #test_update_the_requested_object_without_category ⇒ Object
Instance Method Details
#setup ⇒ Object
17 18 19 20 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 17 def setup @controller.stubs(:resource_url).returns('/') @controller.stubs(:collection_url).returns('/') end |
#test_expose_a_new_product_with_category ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 54 def test_expose_a_new_product_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:build).returns(mock_product) get :new, :category_id => '37' assert_equal mock_category, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_a_new_product_without_category ⇒ Object
63 64 65 66 67 68 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 63 def test_expose_a_new_product_without_category Product.expects(:new).returns(mock_product) get :new assert_equal nil, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_a_newly_create_product_with_category ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 86 def test_expose_a_newly_create_product_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:build).with({'these' => 'params'}).returns(mock_product(:save => true)) post :create, :category_id => '37', :product => {:these => 'params'} assert_equal mock_category, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_a_newly_create_product_without_category ⇒ Object
95 96 97 98 99 100 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 95 def test_expose_a_newly_create_product_without_category Product.expects(:new).with({'these' => 'params'}).returns(mock_product(:save => true)) post :create, :product => {:these => 'params'} assert_equal nil, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_all_products_as_instance_variable_with_category ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 22 def test_expose_all_products_as_instance_variable_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:find).with(:all).returns([mock_product]) get :index, :category_id => '37' assert_equal mock_category, assigns(:category) assert_equal [mock_product], assigns(:products) end |
#test_expose_all_products_as_instance_variable_without_category ⇒ Object
31 32 33 34 35 36 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 31 def test_expose_all_products_as_instance_variable_without_category Product.expects(:find).with(:all).returns([mock_product]) get :index assert_equal nil, assigns(:category) assert_equal [mock_product], assigns(:products) end |
#test_expose_the_resquested_product_for_edition_with_category ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 70 def test_expose_the_resquested_product_for_edition_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:find).with('42').returns(mock_product) get :edit, :id => '42', :category_id => '37' assert_equal mock_category, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_the_resquested_product_for_edition_without_category ⇒ Object
79 80 81 82 83 84 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 79 def test_expose_the_resquested_product_for_edition_without_category Product.expects(:find).with('42').returns(mock_product) get :edit, :id => '42' assert_equal nil, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_the_resquested_product_with_category ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 38 def test_expose_the_resquested_product_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:find).with('42').returns(mock_product) get :show, :id => '42', :category_id => '37' assert_equal mock_category, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_expose_the_resquested_product_without_category ⇒ Object
47 48 49 50 51 52 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 47 def test_expose_the_resquested_product_without_category Product.expects(:find).with('42').returns(mock_product) get :show, :id => '42' assert_equal nil, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_polymorphic_helpers ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 144 def test_polymorphic_helpers Product.expects(:find).with(:all).returns([mock_product]) get :index assert !@controller.send(:parent?) assert_equal nil, assigns(:parent_type) assert_equal nil, @controller.send(:parent_type) assert_equal nil, @controller.send(:parent_class) assert_equal nil, assigns(:category) assert_equal nil, @controller.send(:parent) end |
#test_the_resquested_product_is_destroyed_with_category ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 122 def test_the_resquested_product_is_destroyed_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:find).with('42').returns(mock_product) mock_product.expects(:destroy) @controller.expects(:collection_url).returns('/') delete :destroy, :id => '42', :category_id => '37' assert_equal mock_category, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_the_resquested_product_is_destroyed_without_category ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 134 def test_the_resquested_product_is_destroyed_without_category Product.expects(:find).with('42').returns(mock_product) mock_product.expects(:destroy) @controller.expects(:collection_url).returns('/') delete :destroy, :id => '42' assert_equal nil, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_update_the_requested_object_with_category ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 102 def test_update_the_requested_object_with_category Category.expects(:find).with('37').returns(mock_category) mock_category.expects(:products).returns(Product) Product.expects(:find).with('42').returns(mock_product) mock_product.expects(:update_attributes).with({'these' => 'params'}).returns(true) put :update, :id => '42', :category_id => '37', :product => {:these => 'params'} assert_equal mock_category, assigns(:category) assert_equal mock_product, assigns(:product) end |
#test_update_the_requested_object_without_category ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb', line 113 def test_update_the_requested_object_without_category Product.expects(:find).with('42').returns(mock_product) mock_product.expects(:update_attributes).with({'these' => 'params'}).returns(true) put :update, :id => '42', :product => {:these => 'params'} assert_equal nil, assigns(:category) assert_equal mock_product, assigns(:product) end |