josevalim-inherited_resources 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +4 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +362 -0
  4. data/Rakefile +19 -0
  5. data/init.rb +1 -0
  6. data/lib/inherited_resources.rb +4 -0
  7. data/lib/inherited_resources/base.rb +272 -0
  8. data/lib/inherited_resources/base_helpers.rb +199 -0
  9. data/lib/inherited_resources/belongs_to.rb +227 -0
  10. data/lib/inherited_resources/belongs_to_helpers.rb +89 -0
  11. data/lib/inherited_resources/class_methods.rb +155 -0
  12. data/lib/inherited_resources/polymorphic_helpers.rb +19 -0
  13. data/lib/inherited_resources/respond_to.rb +324 -0
  14. data/lib/inherited_resources/singleton_helpers.rb +53 -0
  15. data/lib/inherited_resources/url_helpers.rb +147 -0
  16. data/test/aliases_test.rb +71 -0
  17. data/test/base_helpers_test.rb +130 -0
  18. data/test/base_test.rb +219 -0
  19. data/test/belongs_to_base_test.rb +268 -0
  20. data/test/belongs_to_test.rb +109 -0
  21. data/test/class_methods_test.rb +73 -0
  22. data/test/fixtures/en.yml +9 -0
  23. data/test/nested_belongs_to_test.rb +138 -0
  24. data/test/polymorphic_base_test.rb +282 -0
  25. data/test/respond_to_test.rb +282 -0
  26. data/test/singleton_base_test.rb +226 -0
  27. data/test/test_helper.rb +37 -0
  28. data/test/url_helpers_test.rb +284 -0
  29. data/test/views/cities/edit.html.erb +1 -0
  30. data/test/views/cities/index.html.erb +1 -0
  31. data/test/views/cities/new.html.erb +1 -0
  32. data/test/views/cities/show.html.erb +1 -0
  33. data/test/views/comments/edit.html.erb +1 -0
  34. data/test/views/comments/index.html.erb +1 -0
  35. data/test/views/comments/new.html.erb +1 -0
  36. data/test/views/comments/show.html.erb +1 -0
  37. data/test/views/employees/edit.html.erb +1 -0
  38. data/test/views/employees/index.html.erb +1 -0
  39. data/test/views/employees/new.html.erb +1 -0
  40. data/test/views/employees/show.html.erb +1 -0
  41. data/test/views/managers/edit.html.erb +1 -0
  42. data/test/views/managers/new.html.erb +1 -0
  43. data/test/views/managers/show.html.erb +1 -0
  44. data/test/views/pets/edit.html.erb +1 -0
  45. data/test/views/professors/edit.html.erb +1 -0
  46. data/test/views/professors/index.html.erb +1 -0
  47. data/test/views/professors/new.html.erb +1 -0
  48. data/test/views/professors/show.html.erb +1 -0
  49. data/test/views/projects/index.html.erb +1 -0
  50. data/test/views/projects/respond_to_with_resource.html.erb +1 -0
  51. data/test/views/students/edit.html.erb +1 -0
  52. data/test/views/students/new.html.erb +1 -0
  53. data/test/views/users/edit.html.erb +1 -0
  54. data/test/views/users/index.html.erb +1 -0
  55. data/test/views/users/new.html.erb +1 -0
  56. data/test/views/users/show.html.erb +1 -0
  57. metadata +108 -0
@@ -0,0 +1,226 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
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
+ class Store
7
+ end
8
+
9
+ class Manager
10
+ def self.human_name; 'Manager'; end
11
+ end
12
+
13
+ class ManagersController < InheritedResources::Base
14
+ belongs_to :store, :singleton => true
15
+ end
16
+
17
+ # Create a TestHelper module with some helpers
18
+ module ManagerTestHelper
19
+ def setup
20
+ @controller = ManagersController.new
21
+ @controller.request = @request = ActionController::TestRequest.new
22
+ @controller.response = @response = ActionController::TestResponse.new
23
+ end
24
+
25
+ protected
26
+ def mock_store(stubs={})
27
+ @mock_store ||= mock(stubs)
28
+ end
29
+
30
+ def mock_manager(stubs={})
31
+ @mock_manager ||= mock(stubs)
32
+ end
33
+ end
34
+
35
+ class ShowActionSingletonTest < Test::Unit::TestCase
36
+ include ManagerTestHelper
37
+
38
+ def test_expose_the_resquested_manager
39
+ Store.expects(:find).with('37').returns(mock_store)
40
+ mock_store.expects(:manager).returns(mock_manager)
41
+ get :show, :store_id => '37'
42
+ assert_equal mock_store, assigns(:store)
43
+ assert_equal mock_manager, assigns(:manager)
44
+ end
45
+
46
+ def test_controller_should_render_show
47
+ Store.stubs(:find).returns(mock_store(:manager => mock_manager))
48
+ get :show
49
+ assert_response :success
50
+ assert_equal 'Show HTML', @response.body.strip
51
+ end
52
+
53
+ def test_render_exposed_manager_as_xml_when_mime_type_is_xml
54
+ @request.accept = 'application/xml'
55
+ Store.expects(:find).with('37').returns(mock_store)
56
+ mock_store.expects(:manager).returns(mock_manager)
57
+ mock_manager.expects(:to_xml).returns("Generated XML")
58
+ get :show, :id => '42', :store_id => '37'
59
+ assert_response :success
60
+ assert_equal 'Generated XML', @response.body
61
+ end
62
+ end
63
+
64
+ class NewActionSingletonTest < Test::Unit::TestCase
65
+ include ManagerTestHelper
66
+
67
+ def test_expose_a_new_manager
68
+ Store.expects(:find).with('37').returns(mock_store)
69
+ mock_store.expects(:build_manager).returns(mock_manager)
70
+ get :new, :store_id => '37'
71
+ assert_equal mock_store, assigns(:store)
72
+ assert_equal mock_manager, assigns(:manager)
73
+ end
74
+
75
+ def test_controller_should_render_new
76
+ Store.stubs(:find).returns(mock_store)
77
+ mock_store.stubs(:build_manager).returns(mock_manager)
78
+ get :new
79
+ assert_response :success
80
+ assert_equal 'New HTML', @response.body.strip
81
+ end
82
+
83
+ def test_render_exposed_a_new_manager_as_xml_when_mime_type_is_xml
84
+ @request.accept = 'application/xml'
85
+ Store.expects(:find).with('37').returns(mock_store)
86
+ mock_store.expects(:build_manager).returns(mock_manager)
87
+ mock_manager.expects(:to_xml).returns("Generated XML")
88
+ get :new, :store_id => '37'
89
+ assert_equal 'Generated XML', @response.body
90
+ assert_response :success
91
+ end
92
+ end
93
+
94
+ class EditActionSingletonTest < Test::Unit::TestCase
95
+ include ManagerTestHelper
96
+
97
+ def test_expose_the_resquested_manager
98
+ Store.expects(:find).with('37').returns(mock_store)
99
+ mock_store.expects(:manager).returns(mock_manager)
100
+ get :edit, :store_id => '37'
101
+ assert_equal mock_store, assigns(:store)
102
+ assert_equal mock_manager, assigns(:manager)
103
+ assert_response :success
104
+ end
105
+
106
+ def test_controller_should_render_edit
107
+ Store.stubs(:find).returns(mock_store)
108
+ mock_store.stubs(:manager).returns(mock_manager)
109
+ get :edit
110
+ assert_response :success
111
+ assert_equal 'Edit HTML', @response.body.strip
112
+ end
113
+ end
114
+
115
+ class CreateActionSingletonTest < Test::Unit::TestCase
116
+ include ManagerTestHelper
117
+
118
+ def test_expose_a_newly_create_manager_when_saved_with_success
119
+ Store.expects(:find).with('37').returns(mock_store)
120
+ mock_store.expects(:build_manager).with({'these' => 'params'}).returns(mock_manager(:save => true))
121
+ post :create, :store_id => '37', :manager => {:these => 'params'}
122
+ assert_equal mock_store, assigns(:store)
123
+ assert_equal mock_manager, assigns(:manager)
124
+ end
125
+
126
+ def test_redirect_to_the_created_manager
127
+ Store.stubs(:find).returns(mock_store)
128
+ mock_store.stubs(:build_manager).returns(mock_manager(:save => true))
129
+ @controller.expects(:resource_url).returns('http://test.host/').times(2)
130
+ post :create
131
+ assert_redirected_to 'http://test.host/'
132
+ end
133
+
134
+ def test_show_flash_message_when_success
135
+ Store.stubs(:find).returns(mock_store)
136
+ mock_store.stubs(:build_manager).returns(mock_manager(:save => true))
137
+ post :create
138
+ assert_equal flash[:notice], 'Manager was successfully created.'
139
+ end
140
+
141
+ def test_render_new_template_when_manager_cannot_be_saved
142
+ Store.stubs(:find).returns(mock_store)
143
+ mock_store.stubs(:build_manager).returns(mock_manager(:save => false, :errors => []))
144
+ post :create
145
+ assert_response :success
146
+ assert_template 'new'
147
+ end
148
+
149
+ def test_dont_show_flash_message_when_manager_cannot_be_saved
150
+ Store.stubs(:find).returns(mock_store)
151
+ mock_store.stubs(:build_manager).returns(mock_manager(:save => false, :errors => []))
152
+ post :create
153
+ assert flash.empty?
154
+ end
155
+ end
156
+
157
+ class UpdateActionSingletonTest < Test::Unit::TestCase
158
+ include ManagerTestHelper
159
+
160
+ def test_update_the_requested_object
161
+ Store.expects(:find).with('37').returns(mock_store(:manager => mock_manager))
162
+ mock_manager.expects(:update_attributes).with({'these' => 'params'}).returns(true)
163
+ put :update, :store_id => '37', :manager => {:these => 'params'}
164
+ assert_equal mock_store, assigns(:store)
165
+ assert_equal mock_manager, assigns(:manager)
166
+ end
167
+
168
+ def test_redirect_to_the_created_manager
169
+ Store.expects(:find).returns(mock_store(:manager => mock_manager))
170
+ mock_manager.stubs(:update_attributes).returns(true)
171
+ @controller.expects(:resource_url).returns('http://test.host/')
172
+ put :update
173
+ assert_redirected_to 'http://test.host/'
174
+ end
175
+
176
+ def test_show_flash_message_when_success
177
+ Store.expects(:find).returns(mock_store(:manager => mock_manager))
178
+ mock_manager.stubs(:update_attributes).returns(true)
179
+ put :update
180
+ assert_equal flash[:notice], 'Manager was successfully updated.'
181
+ end
182
+
183
+ def test_render_edit_template_when_manager_cannot_be_saved
184
+ Store.expects(:find).returns(mock_store(:manager => mock_manager(:errors => [])))
185
+ mock_manager.stubs(:update_attributes).returns(false)
186
+ put :update
187
+ assert_response :success
188
+ assert_template 'edit'
189
+ end
190
+
191
+ def test_dont_show_flash_message_when_manager_cannot_be_saved
192
+ Store.expects(:find).returns(mock_store(:manager => mock_manager(:errors => [])))
193
+ mock_manager.stubs(:update_attributes).returns(false)
194
+ put :update
195
+ assert flash.empty?
196
+ end
197
+ end
198
+
199
+ class DestroyActionSingletonTest < Test::Unit::TestCase
200
+ include ManagerTestHelper
201
+
202
+ def test_the_resquested_manager_is_destroyed
203
+ Store.expects(:find).with('37').returns(mock_store)
204
+ mock_store.expects(:manager).returns(mock_manager)
205
+ mock_manager.expects(:destroy)
206
+ delete :destroy, :store_id => '37'
207
+ assert_equal mock_store, assigns(:store)
208
+ assert_equal mock_manager, assigns(:manager)
209
+ end
210
+
211
+ def test_show_flash_message
212
+ Store.stubs(:find).returns(mock_store)
213
+ mock_store.stubs(:manager).returns(mock_manager(:destroy => true))
214
+ delete :destroy
215
+ assert_equal flash[:notice], 'Manager was successfully destroyed.'
216
+ end
217
+
218
+ def test_redirects_to_store_show
219
+ Store.stubs(:find).returns(mock_store)
220
+ mock_store.stubs(:manager).returns(mock_manager(:destroy => true))
221
+ @controller.expects(:collection_url).returns('http://test.host/')
222
+ delete :destroy
223
+ assert_redirected_to 'http://test.host/'
224
+ end
225
+ end
226
+
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+
5
+ ENV["RAILS_ENV"] = "test"
6
+
7
+ require 'active_support'
8
+ require 'action_controller'
9
+ require 'action_controller/test_case'
10
+ require 'action_controller/test_process'
11
+
12
+ I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'en.yml')
13
+ I18n.reload!
14
+
15
+ # Load respond_to before defining ApplicationController
16
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/respond_to.rb'
17
+
18
+ # Define ApplicationController
19
+ class ApplicationController < ActionController::Base; end
20
+
21
+ # Load InheritedResources::Base after defining ApplicationController
22
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/base_helpers.rb'
23
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/belongs_to.rb'
24
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/belongs_to_helpers.rb'
25
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/class_methods.rb'
26
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/polymorphic_helpers.rb'
27
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/singleton_helpers.rb'
28
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/url_helpers.rb'
29
+ require File.dirname(__FILE__) + '/../lib/inherited_resources/base.rb'
30
+
31
+ # Define view_paths
32
+ ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
33
+
34
+ # Define default routes
35
+ ActionController::Routing::Routes.draw do |map|
36
+ map.connect ':controller/:action/:id'
37
+ end
@@ -0,0 +1,284 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class House; end
4
+ class HousesController < InheritedResources::Base
5
+ end
6
+
7
+ class Table; end
8
+ class TablesController < InheritedResources::Base
9
+ belongs_to :house
10
+ end
11
+
12
+ class RoomsController < InheritedResources::Base
13
+ belongs_to :house, :route_name => 'big_house'
14
+ end
15
+
16
+ class ChairsController < InheritedResources::Base
17
+ belongs_to :house do
18
+ belongs_to :table
19
+ end
20
+ end
21
+
22
+ class OwnersController < InheritedResources::Base
23
+ belongs_to :house, :singleton => true
24
+ end
25
+
26
+ class Bed; end
27
+ class BedsController < InheritedResources::Base
28
+ belongs_to :house, :building, :polymorphic => true
29
+ end
30
+
31
+ class Dish; end
32
+ class DishesController < InheritedResources::Base
33
+ belongs_to :house do
34
+ belongs_to :table, :kitchen, :polymorphic => true
35
+ end
36
+ end
37
+
38
+ class Center; end
39
+ class CentersController < InheritedResources::Base
40
+ acts_as_singleton!
41
+
42
+ belongs_to :house do
43
+ belongs_to :table, :kitchen, :polymorphic => true
44
+ end
45
+ end
46
+
47
+ # Create a TestHelper module with some helpers
48
+ class UrlHelpersTest < Test::Unit::TestCase
49
+
50
+ def test_url_helpers_on_simple_inherited_resource
51
+ controller = HousesController.new
52
+ controller.instance_variable_set('@house', :house)
53
+
54
+ [:url, :path].each do |path_or_url|
55
+ controller.expects("houses_#{path_or_url}").with().once
56
+ controller.send("collection_#{path_or_url}")
57
+
58
+ controller.expects("house_#{path_or_url}").with(:house).once
59
+ controller.send("resource_#{path_or_url}")
60
+
61
+ controller.expects("new_house_#{path_or_url}").with().once
62
+ controller.send("new_resource_#{path_or_url}")
63
+
64
+ controller.expects("edit_house_#{path_or_url}").with(:house).once
65
+ controller.send("edit_resource_#{path_or_url}")
66
+
67
+ # With arg
68
+ controller.expects("house_#{path_or_url}").with(:arg).once
69
+ controller.send("resource_#{path_or_url}", :arg)
70
+
71
+ controller.expects("house_#{path_or_url}").with(:arg).once
72
+ controller.send("resource_#{path_or_url}", :arg)
73
+ end
74
+ end
75
+
76
+ def test_url_helpers_on_belongs_to
77
+ controller = TablesController.new
78
+ controller.instance_variable_set('@house', :house)
79
+ controller.instance_variable_set('@table', :table)
80
+
81
+ [:url, :path].each do |path_or_url|
82
+ controller.expects("house_tables_#{path_or_url}").with(:house).once
83
+ controller.send("collection_#{path_or_url}")
84
+
85
+ controller.expects("house_table_#{path_or_url}").with(:house, :table).once
86
+ controller.send("resource_#{path_or_url}")
87
+
88
+ controller.expects("new_house_table_#{path_or_url}").with(:house).once
89
+ controller.send("new_resource_#{path_or_url}")
90
+
91
+ controller.expects("edit_house_table_#{path_or_url}").with(:house, :table).once
92
+ controller.send("edit_resource_#{path_or_url}")
93
+
94
+ # With arg
95
+ controller.expects("house_table_#{path_or_url}").with(:house, :arg).once
96
+ controller.send("resource_#{path_or_url}", :arg)
97
+
98
+ controller.expects("edit_house_table_#{path_or_url}").with(:house, :arg).once
99
+ controller.send("edit_resource_#{path_or_url}", :arg)
100
+ end
101
+ end
102
+
103
+ def test_url_helpers_on_not_default_belongs_to
104
+ controller = RoomsController.new
105
+ controller.instance_variable_set('@house', :house)
106
+ controller.instance_variable_set('@room', :room)
107
+
108
+ [:url, :path].each do |path_or_url|
109
+ controller.expects("big_house_rooms_#{path_or_url}").with(:house).once
110
+ controller.send("collection_#{path_or_url}")
111
+
112
+ controller.expects("big_house_room_#{path_or_url}").with(:house, :room).once
113
+ controller.send("resource_#{path_or_url}")
114
+
115
+ controller.expects("new_big_house_room_#{path_or_url}").with(:house).once
116
+ controller.send("new_resource_#{path_or_url}")
117
+
118
+ controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :room).once
119
+ controller.send("edit_resource_#{path_or_url}")
120
+
121
+ # With args
122
+ controller.expects("big_house_room_#{path_or_url}").with(:house, :arg).once
123
+ controller.send("resource_#{path_or_url}", :arg)
124
+
125
+ controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :arg).once
126
+ controller.send("edit_resource_#{path_or_url}", :arg)
127
+ end
128
+ end
129
+
130
+ def test_url_helpers_on_nested_belongs_to
131
+ controller = ChairsController.new
132
+ controller.instance_variable_set('@house', :house)
133
+ controller.instance_variable_set('@table', :table)
134
+ controller.instance_variable_set('@chair', :chair)
135
+
136
+ [:url, :path].each do |path_or_url|
137
+ controller.expects("house_table_chairs_#{path_or_url}").with(:house, :table).once
138
+ controller.send("collection_#{path_or_url}")
139
+
140
+ controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :chair).once
141
+ controller.send("resource_#{path_or_url}")
142
+
143
+ controller.expects("new_house_table_chair_#{path_or_url}").with(:house, :table).once
144
+ controller.send("new_resource_#{path_or_url}")
145
+
146
+ controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :chair).once
147
+ controller.send("edit_resource_#{path_or_url}")
148
+
149
+ # With args
150
+ controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg).once
151
+ controller.send("edit_resource_#{path_or_url}", :arg)
152
+
153
+ controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :arg).once
154
+ controller.send("resource_#{path_or_url}", :arg)
155
+ end
156
+ end
157
+
158
+ def test_url_helpers_on_singletons
159
+ controller = OwnersController.new
160
+ controller.instance_variable_set('@house', :house)
161
+ controller.instance_variable_set('@owner', :owner)
162
+
163
+ [:url, :path].each do |path_or_url|
164
+ controller.expects("house_#{path_or_url}").with(:house).once
165
+ controller.send("collection_#{path_or_url}")
166
+
167
+ controller.expects("house_owner_#{path_or_url}").with(:house).once
168
+ controller.send("resource_#{path_or_url}")
169
+
170
+ controller.expects("new_house_owner_#{path_or_url}").with(:house).once
171
+ controller.send("new_resource_#{path_or_url}")
172
+
173
+ controller.expects("edit_house_owner_#{path_or_url}").with(:house).once
174
+ controller.send("edit_resource_#{path_or_url}")
175
+
176
+ assert_raise(ArgumentError){ controller.send("resource_#{path_or_url}", :arg) }
177
+ end
178
+ end
179
+
180
+ def test_url_helpers_on_house_polymorphic_belongs_to
181
+ house = House.new
182
+ bed = Bed.new
183
+
184
+ new_bed = Bed.new
185
+ Bed.stubs(:new).returns(new_bed)
186
+ new_bed.stubs(:new_record?).returns(true)
187
+
188
+ controller = BedsController.new
189
+ controller.instance_variable_set('@parent_type', :house)
190
+ controller.instance_variable_set('@house', house)
191
+ controller.instance_variable_set('@bed', bed)
192
+
193
+ [:url, :path].each do |path_or_url|
194
+ controller.expects("house_beds_#{path_or_url}").with(house).once
195
+ controller.send("collection_#{path_or_url}")
196
+
197
+ controller.expects("house_bed_#{path_or_url}").with(house, bed).once
198
+ controller.send("resource_#{path_or_url}")
199
+
200
+ controller.expects("new_house_bed_#{path_or_url}").with(house).once
201
+ controller.send("new_resource_#{path_or_url}")
202
+
203
+ controller.expects("edit_house_bed_#{path_or_url}").with(house, bed).once
204
+ controller.send("edit_resource_#{path_or_url}")
205
+ end
206
+
207
+ # Testing if it accepts args...
208
+ controller.expects("polymorphic_url").with([house, :arg]).once
209
+ controller.send("resource_url", :arg)
210
+
211
+ controller.expects("edit_polymorphic_url").with([house, :arg]).once
212
+ controller.send("edit_resource_url", :arg)
213
+ end
214
+
215
+ def test_url_helpers_on_nested_polymorphic_belongs_to
216
+ house = House.new
217
+ table = Table.new
218
+ dish = Dish.new
219
+
220
+ new_dish = Dish.new
221
+ Dish.stubs(:new).returns(new_dish)
222
+ new_dish.stubs(:new_record?).returns(true)
223
+
224
+ controller = DishesController.new
225
+ controller.instance_variable_set('@parent_type', :table)
226
+ controller.instance_variable_set('@house', house)
227
+ controller.instance_variable_set('@table', table)
228
+ controller.instance_variable_set('@dish', dish)
229
+
230
+ [:url, :path].each do |path_or_url|
231
+ controller.expects("house_table_dishes_#{path_or_url}").with(house, table).once
232
+ controller.send("collection_#{path_or_url}")
233
+
234
+ controller.expects("house_table_dish_#{path_or_url}").with(house, table, dish).once
235
+ controller.send("resource_#{path_or_url}")
236
+
237
+ controller.expects("new_house_table_dish_#{path_or_url}").with(house, table).once
238
+ controller.send("new_resource_#{path_or_url}")
239
+
240
+ controller.expects("edit_house_table_dish_#{path_or_url}").with(house, table, dish).once
241
+ controller.send("edit_resource_#{path_or_url}")
242
+ end
243
+
244
+ # Testing if it accepts args...
245
+ controller.expects("polymorphic_url").with([house, table, :arg]).once
246
+ controller.send("resource_url", :arg)
247
+
248
+ controller.expects("edit_polymorphic_url").with([house, table, :arg]).once
249
+ controller.send("edit_resource_url", :arg)
250
+ end
251
+
252
+ def test_url_helpers_on_singleton_nested_polymorphic_belongs_to
253
+ # Thus must not be usefull in singleton controllers...
254
+ # Center.new
255
+ house = House.new
256
+ table = Table.new
257
+
258
+ controller = CentersController.new
259
+ controller.instance_variable_set('@parent_type', :table)
260
+ controller.instance_variable_set('@house', house)
261
+ controller.instance_variable_set('@table', table)
262
+
263
+ # This must not be useful in singleton controllers...
264
+ # controller.instance_variable_set('@center', :center)
265
+
266
+ [:url, :path].each do |path_or_url|
267
+ controller.expects("house_table_#{path_or_url}").with(house, table).once
268
+ controller.send("collection_#{path_or_url}")
269
+
270
+ controller.expects("house_table_center_#{path_or_url}").with(house, table).once
271
+ controller.send("resource_#{path_or_url}")
272
+
273
+ controller.expects("new_house_table_center_#{path_or_url}").with(house, table).once
274
+ controller.send("new_resource_#{path_or_url}")
275
+
276
+ controller.expects("edit_house_table_center_#{path_or_url}").with(house, table).once
277
+ controller.send("edit_resource_#{path_or_url}")
278
+
279
+ # With arg
280
+ assert_raise(ArgumentError){ controller.send("resource_#{path_or_url}", :arg) }
281
+ end
282
+ end
283
+
284
+ end