josevalim-inherited_resources 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/base_test.rb CHANGED
@@ -1,16 +1,13 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- # This test file is instead to test the how controller flow and actions.
4
- # This is done using mocks a la rspec.
5
- #
6
3
  class User
7
4
  def self.human_name; 'User'; end
8
5
  end
9
6
 
10
7
  class UsersController < InheritedResources::Base
8
+ respond_to :html, :xml
11
9
  end
12
10
 
13
- # Create a TestHelper module with some helpers
14
11
  module UserTestHelper
15
12
  def setup
16
13
  @controller = UsersController.new
@@ -24,7 +21,7 @@ module UserTestHelper
24
21
  end
25
22
  end
26
23
 
27
- class IndexActionBaseTest < TEST_CLASS
24
+ class IndexActionBaseTest < ActionController::TestCase
28
25
  include UserTestHelper
29
26
 
30
27
  def test_expose_all_users_as_instance_variable
@@ -50,7 +47,7 @@ class IndexActionBaseTest < TEST_CLASS
50
47
  end
51
48
  end
52
49
 
53
- class ShowActionBaseTest < TEST_CLASS
50
+ class ShowActionBaseTest < ActionController::TestCase
54
51
  include UserTestHelper
55
52
 
56
53
  def test_expose_the_resquested_user
@@ -76,7 +73,7 @@ class ShowActionBaseTest < TEST_CLASS
76
73
  end
77
74
  end
78
75
 
79
- class NewActionBaseTest < TEST_CLASS
76
+ class NewActionBaseTest < ActionController::TestCase
80
77
  include UserTestHelper
81
78
 
82
79
  def test_expose_a_new_user
@@ -102,7 +99,7 @@ class NewActionBaseTest < TEST_CLASS
102
99
  end
103
100
  end
104
101
 
105
- class EditActionBaseTest < TEST_CLASS
102
+ class EditActionBaseTest < ActionController::TestCase
106
103
  include UserTestHelper
107
104
 
108
105
  def test_expose_the_resquested_user
@@ -120,7 +117,7 @@ class EditActionBaseTest < TEST_CLASS
120
117
  end
121
118
  end
122
119
 
123
- class CreateActionBaseTest < TEST_CLASS
120
+ class CreateActionBaseTest < ActionController::TestCase
124
121
  include UserTestHelper
125
122
 
126
123
  def test_expose_a_newly_create_user_when_saved_with_success
@@ -156,7 +153,7 @@ class CreateActionBaseTest < TEST_CLASS
156
153
  end
157
154
  end
158
155
 
159
- class UpdateActionBaseTest < TEST_CLASS
156
+ class UpdateActionBaseTest < ActionController::TestCase
160
157
  include UserTestHelper
161
158
 
162
159
  def test_update_the_requested_object
@@ -193,7 +190,7 @@ class UpdateActionBaseTest < TEST_CLASS
193
190
  end
194
191
  end
195
192
 
196
- class DestroyActionBaseTest < TEST_CLASS
193
+ class DestroyActionBaseTest < ActionController::TestCase
197
194
  include UserTestHelper
198
195
 
199
196
  def test_the_resquested_user_is_destroyed
@@ -1,8 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- # This test file is instead to test the how controller flow and actions
4
- # using a belongs_to association. This is done using mocks a la rspec.
5
- #
6
3
  class Post
7
4
  end
8
5
 
@@ -14,17 +11,18 @@ class CommentsController < InheritedResources::Base
14
11
  belongs_to :post
15
12
  end
16
13
 
17
- class BelongsToTest < TEST_CLASS
14
+ class BelongsToTest < ActionController::TestCase
15
+ tests CommentsController
18
16
 
19
17
  def setup
20
- @controller = CommentsController.new
21
- @controller.request = @request = ActionController::TestRequest.new
22
- @controller.response = @response = ActionController::TestResponse.new
18
+ Post.expects(:find).with('37').returns(mock_post)
19
+ mock_post.expects(:comments).returns(Comment)
20
+
21
+ @controller.stubs(:resource_url).returns('/')
22
+ @controller.stubs(:collection_url).returns('/')
23
23
  end
24
24
 
25
25
  def test_expose_all_comments_as_instance_variable_on_index
26
- Post.expects(:find).with('37').returns(mock_post)
27
- mock_post.expects(:comments).returns(Comment)
28
26
  Comment.expects(:find).with(:all).returns([mock_comment])
29
27
  get :index, :post_id => '37'
30
28
  assert_equal mock_post, assigns(:post)
@@ -32,8 +30,6 @@ class BelongsToTest < TEST_CLASS
32
30
  end
33
31
 
34
32
  def test_expose_the_resquested_comment_on_show
35
- Post.expects(:find).with('37').returns(mock_post)
36
- mock_post.expects(:comments).returns(Comment)
37
33
  Comment.expects(:find).with('42').returns(mock_comment)
38
34
  get :show, :id => '42', :post_id => '37'
39
35
  assert_equal mock_post, assigns(:post)
@@ -41,8 +37,6 @@ class BelongsToTest < TEST_CLASS
41
37
  end
42
38
 
43
39
  def test_expose_a_new_comment_on_new
44
- Post.expects(:find).with('37').returns(mock_post)
45
- mock_post.expects(:comments).returns(Comment)
46
40
  Comment.expects(:build).returns(mock_comment)
47
41
  get :new, :post_id => '37'
48
42
  assert_equal mock_post, assigns(:post)
@@ -50,8 +44,6 @@ class BelongsToTest < TEST_CLASS
50
44
  end
51
45
 
52
46
  def test_expose_the_resquested_comment_on_edit
53
- Post.expects(:find).with('37').returns(mock_post)
54
- mock_post.expects(:comments).returns(Comment)
55
47
  Comment.expects(:find).with('42').returns(mock_comment)
56
48
  get :edit, :id => '42', :post_id => '37'
57
49
  assert_equal mock_post, assigns(:post)
@@ -59,8 +51,6 @@ class BelongsToTest < TEST_CLASS
59
51
  end
60
52
 
61
53
  def test_expose_a_newly_create_comment_on_create
62
- Post.expects(:find).with('37').returns(mock_post)
63
- mock_post.expects(:comments).returns(Comment)
64
54
  Comment.expects(:build).with({'these' => 'params'}).returns(mock_comment(:save => true))
65
55
  post :create, :post_id => '37', :comment => {:these => 'params'}
66
56
  assert_equal mock_post, assigns(:post)
@@ -68,8 +58,6 @@ class BelongsToTest < TEST_CLASS
68
58
  end
69
59
 
70
60
  def test_update_the_requested_object_on_update
71
- Post.expects(:find).with('37').returns(mock_post)
72
- mock_post.expects(:comments).returns(Comment)
73
61
  Comment.expects(:find).with('42').returns(mock_comment)
74
62
  mock_comment.expects(:update_attributes).with({'these' => 'params'}).returns(true)
75
63
  put :update, :id => '42', :post_id => '37', :comment => {:these => 'params'}
@@ -78,15 +66,15 @@ class BelongsToTest < TEST_CLASS
78
66
  end
79
67
 
80
68
  def test_the_resquested_comment_is_destroyed_on_destroy
81
- Post.expects(:find).with('37').returns(mock_post)
82
- mock_post.expects(:comments).returns(Comment)
83
69
  Comment.expects(:find).with('42').returns(mock_comment)
84
70
  mock_comment.expects(:destroy)
85
71
  delete :destroy, :id => '42', :post_id => '37'
86
72
  assert_equal mock_post, assigns(:post)
87
73
  assert_equal mock_comment, assigns(:comment)
88
74
  end
75
+
89
76
  protected
77
+
90
78
  def mock_post(stubs={})
91
79
  @mock_post ||= mock(stubs)
92
80
  end
@@ -93,62 +93,70 @@ class DefaultsClassMethodTest < ActiveSupport::TestCase
93
93
  end
94
94
 
95
95
 
96
- class BelongsToClassMethodTest < TEST_CLASS
96
+ class BelongsToClassMethodTest < ActionController::TestCase
97
+ tests ProfessorsController
98
+
97
99
  def setup
98
- @controller = ProfessorsController.new
99
- @controller.request = @request = ActionController::TestRequest.new
100
- @controller.response = @response = ActionController::TestResponse.new
100
+ GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
101
+
102
+ @controller.stubs(:resource_url).returns('/')
103
+ @controller.stubs(:collection_url).returns('/')
101
104
  end
102
105
 
103
106
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_index
104
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
105
107
  Professor.stubs(:find).returns([mock_professor])
106
108
  get :index, :school_title => 'nice'
107
109
  assert_equal mock_school, assigns(:great_school)
108
110
  end
109
111
 
110
112
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_show
111
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
112
113
  Professor.stubs(:find).returns(mock_professor)
113
114
  get :show, :school_title => 'nice'
114
115
  assert_equal mock_school, assigns(:great_school)
115
116
  end
116
117
 
117
118
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_new
118
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
119
119
  Professor.stubs(:build).returns(mock_professor)
120
120
  get :new, :school_title => 'nice'
121
121
  assert_equal mock_school, assigns(:great_school)
122
122
  end
123
123
 
124
124
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_edit
125
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
126
125
  Professor.stubs(:find).returns(mock_professor)
127
126
  get :edit, :school_title => 'nice'
128
127
  assert_equal mock_school, assigns(:great_school)
129
128
  end
130
129
 
131
130
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_create
132
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
133
131
  Professor.stubs(:build).returns(mock_professor(:save => true))
134
132
  post :create, :school_title => 'nice'
135
133
  assert_equal mock_school, assigns(:great_school)
136
134
  end
137
135
 
138
136
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_update
139
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
140
137
  Professor.stubs(:find).returns(mock_professor(:update_attributes => true))
141
138
  put :update, :school_title => 'nice'
142
139
  assert_equal mock_school, assigns(:great_school)
143
140
  end
144
141
 
145
142
  def test_expose_the_resquested_school_with_chosen_instance_variable_on_destroy
146
- GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
147
143
  Professor.stubs(:find).returns(mock_professor(:destroy => true))
148
144
  delete :destroy, :school_title => 'nice'
149
145
  assert_equal mock_school, assigns(:great_school)
150
146
  end
151
147
 
148
+ protected
149
+
150
+ def mock_school(stubs={})
151
+ @mock_school ||= mock(stubs)
152
+ end
153
+
154
+ def mock_professor(stubs={})
155
+ @mock_professor ||= mock(stubs)
156
+ end
157
+ end
158
+
159
+ class BelongsToErrorsTest < ActiveSupport::TestCase
152
160
  def test_belongs_to_raise_errors_with_invalid_arguments
153
161
  assert_raise ArgumentError do
154
162
  ProfessorsController.send(:belongs_to)
@@ -167,16 +175,7 @@ class BelongsToClassMethodTest < TEST_CLASS
167
175
  InheritedResources::UrlHelpers.expects(:create_resources_url_helpers!).returns(true).once
168
176
  ProfessorsController.send(:defaults, BELONGS_TO_OPTIONS)
169
177
  ensure
170
- # Reestore default settings
178
+ # Restore default settings
171
179
  ProfessorsController.send(:parents_symbols=, [:school])
172
180
  end
173
-
174
- protected
175
- def mock_school(stubs={})
176
- @mock_school ||= mock(stubs)
177
- end
178
-
179
- def mock_professor(stubs={})
180
- @mock_professor ||= mock(stubs)
181
- end
182
181
  end
@@ -8,11 +8,12 @@ class PaintersController < InheritedResources::Base
8
8
  defaults :instance_name => 'malarz', :collection_name => 'malarze', :resource_class => Malarz
9
9
  end
10
10
 
11
- class DefaultsTest < TEST_CLASS
11
+ class DefaultsTest < ActionController::TestCase
12
+ tests PaintersController
13
+
12
14
  def setup
13
- @controller = PaintersController.new
14
- @controller.request = @request = ActionController::TestRequest.new
15
- @controller.response = @response = ActionController::TestResponse.new
15
+ @controller.stubs(:resource_url).returns('/')
16
+ @controller.stubs(:collection_url).returns('/')
16
17
  end
17
18
 
18
19
  def test_expose_all_painters_as_instance_variable
@@ -14,22 +14,21 @@ class CitiesController < InheritedResources::Base
14
14
  belongs_to :country, :state
15
15
  end
16
16
 
17
- # Create a TestHelper module with some helpers
18
- class NestedBelongsToTest < TEST_CLASS
17
+ class NestedBelongsToTest < ActionController::TestCase
18
+ tests CitiesController
19
19
 
20
20
  def setup
21
- @controller = CitiesController.new
22
- @controller.request = @request = ActionController::TestRequest.new
23
- @controller.response = @response = ActionController::TestResponse.new
24
- end
25
-
26
- def test_assigns_country_and_state_and_city_on_create
27
21
  Country.expects(:find).with('13').returns(mock_country)
28
22
  mock_country.expects(:states).returns(State)
29
23
  State.expects(:find).with('37').returns(mock_state)
30
24
  mock_state.expects(:cities).returns(City)
31
- City.expects(:find).with(:all).returns([mock_city])
32
25
 
26
+ @controller.stubs(:resource_url).returns('/')
27
+ @controller.stubs(:collection_url).returns('/')
28
+ end
29
+
30
+ def test_assigns_country_and_state_and_city_on_create
31
+ City.expects(:find).with(:all).returns([mock_city])
33
32
  get :index, :state_id => '37', :country_id => '13'
34
33
 
35
34
  assert_equal mock_country, assigns(:country)
@@ -38,12 +37,7 @@ class NestedBelongsToTest < TEST_CLASS
38
37
  end
39
38
 
40
39
  def test_assigns_country_and_state_and_city_on_show
41
- Country.expects(:find).with('13').returns(mock_country)
42
- mock_country.expects(:states).returns(State)
43
- State.expects(:find).with('37').returns(mock_state)
44
- mock_state.expects(:cities).returns(City)
45
40
  City.expects(:find).with('42').returns(mock_city)
46
-
47
41
  get :show, :id => '42', :state_id => '37', :country_id => '13'
48
42
 
49
43
  assert_equal mock_country, assigns(:country)
@@ -52,12 +46,7 @@ class NestedBelongsToTest < TEST_CLASS
52
46
  end
53
47
 
54
48
  def test_assigns_country_and_state_and_city_on_new
55
- Country.expects(:find).with('13').returns(mock_country)
56
- mock_country.expects(:states).returns(State)
57
- State.expects(:find).with('37').returns(mock_state)
58
- mock_state.expects(:cities).returns(City)
59
49
  City.expects(:build).returns(mock_city)
60
-
61
50
  get :new, :state_id => '37', :country_id => '13'
62
51
 
63
52
  assert_equal mock_country, assigns(:country)
@@ -66,12 +55,7 @@ class NestedBelongsToTest < TEST_CLASS
66
55
  end
67
56
 
68
57
  def test_assigns_country_and_state_and_city_on_edit
69
- Country.expects(:find).with('13').returns(mock_country)
70
- mock_country.expects(:states).returns(State)
71
- State.expects(:find).with('37').returns(mock_state)
72
- mock_state.expects(:cities).returns(City)
73
58
  City.expects(:find).with('42').returns(mock_city)
74
-
75
59
  get :edit, :id => '42', :state_id => '37', :country_id => '13'
76
60
 
77
61
  assert_equal mock_country, assigns(:country)
@@ -80,12 +64,8 @@ class NestedBelongsToTest < TEST_CLASS
80
64
  end
81
65
 
82
66
  def test_assigns_country_and_state_and_city_on_create
83
- Country.expects(:find).with('13').returns(mock_country)
84
- mock_country.expects(:states).returns(State)
85
- State.expects(:find).with('37').returns(mock_state)
86
- mock_state.expects(:cities).returns(City)
87
- City.expects(:build).with({'these' => 'params'}).returns(mock_city(:save => true))
88
-
67
+ City.expects(:build).with({'these' => 'params'}).returns(mock_city)
68
+ mock_city.expects(:save).returns(true)
89
69
  post :create, :state_id => '37', :country_id => '13', :city => {:these => 'params'}
90
70
 
91
71
  assert_equal mock_country, assigns(:country)
@@ -94,13 +74,8 @@ class NestedBelongsToTest < TEST_CLASS
94
74
  end
95
75
 
96
76
  def test_assigns_country_and_state_and_city_on_update
97
- Country.expects(:find).with('13').returns(mock_country)
98
- mock_country.expects(:states).returns(State)
99
- State.expects(:find).with('37').returns(mock_state)
100
- mock_state.expects(:cities).returns(City)
101
77
  City.expects(:find).with('42').returns(mock_city)
102
- mock_city.expects(:update_attributes).with({'these' => 'params'}).returns(true)
103
-
78
+ mock_city.expects(:update_attributes).returns(true)
104
79
  put :update, :id => '42', :state_id => '37', :country_id => '13', :city => {:these => 'params'}
105
80
 
106
81
  assert_equal mock_country, assigns(:country)
@@ -109,13 +84,8 @@ class NestedBelongsToTest < TEST_CLASS
109
84
  end
110
85
 
111
86
  def test_assigns_country_and_state_and_city_on_destroy
112
- Country.expects(:find).with('13').returns(mock_country)
113
- mock_country.expects(:states).returns(State)
114
- State.expects(:find).with('37').returns(mock_state)
115
- mock_state.expects(:cities).returns(City)
116
87
  City.expects(:find).with('42').returns(mock_city)
117
88
  mock_city.expects(:destroy)
118
-
119
89
  delete :destroy, :id => '42', :state_id => '37', :country_id => '13'
120
90
 
121
91
  assert_equal mock_country, assigns(:country)
@@ -11,27 +11,14 @@ class ProductsController < InheritedResources::Base
11
11
  belongs_to :brand, :category, :polymorphic => true, :optional => true
12
12
  end
13
13
 
14
- # Create a TestHelper module with some helpers
15
- module ProductTestHelper
14
+ class OptionalTest < ActionController::TestCase
15
+ tests ProductsController
16
+
16
17
  def setup
17
- @controller = ProductsController.new
18
- @controller.request = @request = ActionController::TestRequest.new
19
- @controller.response = @response = ActionController::TestResponse.new
18
+ @controller.stubs(:resource_url).returns('/')
19
+ @controller.stubs(:collection_url).returns('/')
20
20
  end
21
21
 
22
- protected
23
- def mock_category(stubs={})
24
- @mock_category ||= mock(stubs)
25
- end
26
-
27
- def mock_product(stubs={})
28
- @mock_product ||= mock(stubs)
29
- end
30
- end
31
-
32
- class IndexActionOptionalTest < TEST_CLASS
33
- include ProductTestHelper
34
-
35
22
  def test_expose_all_products_as_instance_variable_with_category
36
23
  Category.expects(:find).with('37').returns(mock_category)
37
24
  mock_category.expects(:products).returns(Product)
@@ -47,10 +34,6 @@ class IndexActionOptionalTest < TEST_CLASS
47
34
  assert_equal nil, assigns(:category)
48
35
  assert_equal [mock_product], assigns(:products)
49
36
  end
50
- end
51
-
52
- class ShowActionOptionalTest < TEST_CLASS
53
- include ProductTestHelper
54
37
 
55
38
  def test_expose_the_resquested_product_with_category
56
39
  Category.expects(:find).with('37').returns(mock_category)
@@ -67,10 +50,6 @@ class ShowActionOptionalTest < TEST_CLASS
67
50
  assert_equal nil, assigns(:category)
68
51
  assert_equal mock_product, assigns(:product)
69
52
  end
70
- end
71
-
72
- class NewActionOptionalTest < TEST_CLASS
73
- include ProductTestHelper
74
53
 
75
54
  def test_expose_a_new_product_with_category
76
55
  Category.expects(:find).with('37').returns(mock_category)
@@ -87,12 +66,8 @@ class NewActionOptionalTest < TEST_CLASS
87
66
  assert_equal nil, assigns(:category)
88
67
  assert_equal mock_product, assigns(:product)
89
68
  end
90
- end
91
-
92
- class EditActionOptionalTest < TEST_CLASS
93
- include ProductTestHelper
94
69
 
95
- def test_expose_the_resquested_product_with_category
70
+ def test_expose_the_resquested_product_for_edition_with_category
96
71
  Category.expects(:find).with('37').returns(mock_category)
97
72
  mock_category.expects(:products).returns(Product)
98
73
  Product.expects(:find).with('42').returns(mock_product)
@@ -101,16 +76,12 @@ class EditActionOptionalTest < TEST_CLASS
101
76
  assert_equal mock_product, assigns(:product)
102
77
  end
103
78
 
104
- def test_expose_the_resquested_product_without_category
79
+ def test_expose_the_resquested_product_for_edition_without_category
105
80
  Product.expects(:find).with('42').returns(mock_product)
106
81
  get :edit, :id => '42'
107
82
  assert_equal nil, assigns(:category)
108
83
  assert_equal mock_product, assigns(:product)
109
84
  end
110
- end
111
-
112
- class CreateActionOptionalTest < TEST_CLASS
113
- include ProductTestHelper
114
85
 
115
86
  def test_expose_a_newly_create_product_with_category
116
87
  Category.expects(:find).with('37').returns(mock_category)
@@ -127,16 +98,13 @@ class CreateActionOptionalTest < TEST_CLASS
127
98
  assert_equal nil, assigns(:category)
128
99
  assert_equal mock_product, assigns(:product)
129
100
  end
130
- end
131
-
132
- class UpdateActionOptionalTest < TEST_CLASS
133
- include ProductTestHelper
134
101
 
135
102
  def test_update_the_requested_object_with_category
136
103
  Category.expects(:find).with('37').returns(mock_category)
137
104
  mock_category.expects(:products).returns(Product)
138
105
  Product.expects(:find).with('42').returns(mock_product)
139
106
  mock_product.expects(:update_attributes).with({'these' => 'params'}).returns(true)
107
+
140
108
  put :update, :id => '42', :category_id => '37', :product => {:these => 'params'}
141
109
  assert_equal mock_category, assigns(:category)
142
110
  assert_equal mock_product, assigns(:product)
@@ -145,20 +113,19 @@ class UpdateActionOptionalTest < TEST_CLASS
145
113
  def test_update_the_requested_object_without_category
146
114
  Product.expects(:find).with('42').returns(mock_product)
147
115
  mock_product.expects(:update_attributes).with({'these' => 'params'}).returns(true)
116
+
148
117
  put :update, :id => '42', :product => {:these => 'params'}
149
118
  assert_equal nil, assigns(:category)
150
119
  assert_equal mock_product, assigns(:product)
151
120
  end
152
- end
153
-
154
- class DestroyActionOptionalTest < TEST_CLASS
155
- include ProductTestHelper
156
121
 
157
122
  def test_the_resquested_product_is_destroyed_with_category
158
123
  Category.expects(:find).with('37').returns(mock_category)
159
124
  mock_category.expects(:products).returns(Product)
160
125
  Product.expects(:find).with('42').returns(mock_product)
161
126
  mock_product.expects(:destroy)
127
+ @controller.expects(:collection_url).returns('/')
128
+
162
129
  delete :destroy, :id => '42', :category_id => '37'
163
130
  assert_equal mock_category, assigns(:category)
164
131
  assert_equal mock_product, assigns(:product)
@@ -167,14 +134,12 @@ class DestroyActionOptionalTest < TEST_CLASS
167
134
  def test_the_resquested_product_is_destroyed_without_category
168
135
  Product.expects(:find).with('42').returns(mock_product)
169
136
  mock_product.expects(:destroy)
137
+ @controller.expects(:collection_url).returns('/')
138
+
170
139
  delete :destroy, :id => '42'
171
140
  assert_equal nil, assigns(:category)
172
141
  assert_equal mock_product, assigns(:product)
173
142
  end
174
- end
175
-
176
- class OptionalHelpersTest < TEST_CLASS
177
- include ProductTestHelper
178
143
 
179
144
  def test_polymorphic_helpers
180
145
  Product.expects(:find).with(:all).returns([mock_product])
@@ -187,4 +152,13 @@ class OptionalHelpersTest < TEST_CLASS
187
152
  assert_equal nil, assigns(:category)
188
153
  assert_equal nil, @controller.send(:parent)
189
154
  end
155
+
156
+ protected
157
+ def mock_category(stubs={})
158
+ @mock_category ||= mock(stubs)
159
+ end
160
+
161
+ def mock_product(stubs={})
162
+ @mock_product ||= mock(stubs)
163
+ end
190
164
  end