inherited_resources 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/lib/inherited_resources/version.rb +1 -1
  3. metadata +13 -218
  4. data/.gitignore +0 -1
  5. data/CHANGELOG +0 -172
  6. data/Gemfile +0 -10
  7. data/Gemfile.lock +0 -71
  8. data/Rakefile +0 -24
  9. data/inherited_resources.gemspec +0 -25
  10. data/test/aliases_test.rb +0 -146
  11. data/test/association_chain_test.rb +0 -125
  12. data/test/base_test.rb +0 -334
  13. data/test/belongs_to_test.rb +0 -130
  14. data/test/belongs_to_with_shallow_test.rb +0 -93
  15. data/test/class_methods_test.rb +0 -185
  16. data/test/customized_base_test.rb +0 -168
  17. data/test/customized_belongs_to_test.rb +0 -76
  18. data/test/customized_redirect_to_test.rb +0 -32
  19. data/test/defaults_test.rb +0 -197
  20. data/test/locales/en.yml +0 -17
  21. data/test/multiple_nested_optional_belongs_to_test.rb +0 -369
  22. data/test/nested_belongs_to_test.rb +0 -108
  23. data/test/nested_belongs_to_with_shallow_test.rb +0 -123
  24. data/test/nested_model_with_shallow_test.rb +0 -147
  25. data/test/nested_singleton_test.rb +0 -167
  26. data/test/optional_belongs_to_test.rb +0 -164
  27. data/test/polymorphic_test.rb +0 -215
  28. data/test/redirect_to_test.rb +0 -51
  29. data/test/singleton_test.rb +0 -87
  30. data/test/strong_parameters_test.rb +0 -120
  31. data/test/test_helper.rb +0 -47
  32. data/test/url_helpers_test.rb +0 -988
  33. data/test/views/address/edit.html.erb +0 -1
  34. data/test/views/address/new.html.erb +0 -1
  35. data/test/views/address/show.html.erb +0 -1
  36. data/test/views/cars/edit.html.erb +0 -1
  37. data/test/views/cars/index.html.erb +0 -1
  38. data/test/views/cars/new.html.erb +0 -1
  39. data/test/views/cars/show.html.erb +0 -1
  40. data/test/views/cities/edit.html.erb +0 -1
  41. data/test/views/cities/index.html.erb +0 -1
  42. data/test/views/cities/new.html.erb +0 -1
  43. data/test/views/cities/show.html.erb +0 -1
  44. data/test/views/comments/edit.html.erb +0 -1
  45. data/test/views/comments/index.html.erb +0 -1
  46. data/test/views/comments/new.html.erb +0 -1
  47. data/test/views/comments/show.html.erb +0 -1
  48. data/test/views/educations/new.html.erb +0 -0
  49. data/test/views/employees/edit.html.erb +0 -1
  50. data/test/views/employees/index.html.erb +0 -1
  51. data/test/views/employees/new.html.erb +0 -1
  52. data/test/views/employees/show.html.erb +0 -1
  53. data/test/views/geolocation/show.html.erb +0 -1
  54. data/test/views/groups/edit.html.erb +0 -0
  55. data/test/views/managers/edit.html.erb +0 -1
  56. data/test/views/managers/new.html.erb +0 -1
  57. data/test/views/managers/show.html.erb +0 -1
  58. data/test/views/painters/edit.html.erb +0 -1
  59. data/test/views/painters/index.html.erb +0 -1
  60. data/test/views/painters/new.html.erb +0 -1
  61. data/test/views/painters/show.html.erb +0 -1
  62. data/test/views/pets/edit.html.erb +0 -1
  63. data/test/views/pets/index.html.erb +0 -1
  64. data/test/views/pets/new.html.erb +0 -1
  65. data/test/views/pets/show.html.erb +0 -1
  66. data/test/views/photos/index.html.erb +0 -1
  67. data/test/views/plates/edit.html.erb +0 -1
  68. data/test/views/plates/index.html.erb +0 -1
  69. data/test/views/plates/new.html.erb +0 -1
  70. data/test/views/plates/show.html.erb +0 -1
  71. data/test/views/products/edit.html.erb +0 -1
  72. data/test/views/products/index.html.erb +0 -1
  73. data/test/views/products/new.html.erb +0 -1
  74. data/test/views/products/show.html.erb +0 -1
  75. data/test/views/professors/edit.html.erb +0 -1
  76. data/test/views/professors/index.html.erb +0 -1
  77. data/test/views/professors/new.html.erb +0 -1
  78. data/test/views/professors/show.html.erb +0 -1
  79. data/test/views/projects/edit.html.erb +0 -1
  80. data/test/views/projects/index.html.erb +0 -1
  81. data/test/views/projects/index.json.erb +0 -1
  82. data/test/views/projects/new.html.erb +0 -1
  83. data/test/views/projects/respond_to_skip_default_template.html.erb +0 -1
  84. data/test/views/projects/respond_with_resource.html.erb +0 -1
  85. data/test/views/projects/show.html.erb +0 -1
  86. data/test/views/students/edit.html.erb +0 -1
  87. data/test/views/students/new.html.erb +0 -1
  88. data/test/views/tags/edit.html.erb +0 -1
  89. data/test/views/tags/index.html.erb +0 -1
  90. data/test/views/tags/new.html.erb +0 -1
  91. data/test/views/tags/show.html.erb +0 -1
  92. data/test/views/trees/edit.html.erb +0 -1
  93. data/test/views/trees/index.html.erb +0 -1
  94. data/test/views/trees/new.html.erb +0 -1
  95. data/test/views/trees/show.html.erb +0 -1
  96. data/test/views/university/professors/edit.html.erb +0 -1
  97. data/test/views/university/professors/index.html.erb +0 -1
  98. data/test/views/university/professors/new.html.erb +0 -1
  99. data/test/views/university/professors/show.html.erb +0 -1
  100. data/test/views/users/create.js.erb +0 -1
  101. data/test/views/users/destroy.js.erb +0 -1
  102. data/test/views/users/edit.html.erb +0 -1
  103. data/test/views/users/index.html.erb +0 -1
  104. data/test/views/users/new.html.erb +0 -1
  105. data/test/views/users/show.html.erb +0 -1
  106. data/test/views/users/update.js.erb +0 -1
  107. data/test/views/venue/show.html.erb +0 -1
  108. data/test/views/widgets/new.html.erb +0 -0
@@ -1,120 +0,0 @@
1
- require File.expand_path('test_helper', File.dirname(__FILE__))
2
-
3
- if ActionPack::VERSION::MAJOR == 3
4
- require 'strong_parameters'
5
- end
6
-
7
- class Widget
8
- extend ActiveModel::Naming
9
- end
10
-
11
- class WidgetsController < InheritedResources::Base
12
- end
13
-
14
- # test usage of `permitted_params`
15
- class StrongParametersTest < ActionController::TestCase
16
- def setup
17
- @controller = WidgetsController.new
18
- @controller.stubs(:widget_url).returns("/")
19
- @controller.stubs(:permitted_params).returns(:widget => {:permitted => 'param'})
20
- class << @controller
21
- private :permitted_params
22
- end
23
- end
24
-
25
- def test_permitted_params_from_new
26
- Widget.expects(:new).with(:permitted => 'param')
27
- get :new, :widget => { :permitted => 'param', :prohibited => 'param' }
28
- end
29
-
30
- def test_permitted_params_from_create
31
- Widget.expects(:new).with(:permitted => 'param').returns(mock(:save => true))
32
- post :create, :widget => { :permitted => 'param', :prohibited => 'param' }
33
- end
34
-
35
- def test_permitted_params_from_update
36
- mock_widget = mock
37
- mock_widget.stubs(:class).returns(Widget)
38
- mock_widget.expects(:update_attributes).with(:permitted => 'param')
39
- Widget.expects(:find).with('42').returns(mock_widget)
40
- put :update, :id => '42', :widget => {:permitted => 'param', :prohibited => 'param'}
41
- end
42
-
43
- # `permitted_params` has greater priority than `widget_params`
44
- def test_with_permitted_and_resource_methods
45
- @controller.stubs(:widget_params).returns(:permitted => 'another_param')
46
- class << @controller
47
- private :widget_params
48
- end
49
- Widget.expects(:new).with(:permitted => 'param')
50
- get :new, :widget => { :permitted => 'param', :prohibited => 'param' }
51
- end
52
- end
53
-
54
- # test usage of `widget_params`
55
- class StrongParametersWithoutPermittedParamsTest < ActionController::TestCase
56
- def setup
57
- @controller = WidgetsController.new
58
- @controller.stubs(:widget_url).returns("/")
59
- @controller.stubs(:widget_params).returns(:permitted => 'param')
60
- class << @controller
61
- private :widget_params
62
- end
63
- end
64
-
65
- def test_permitted_params_from_new
66
- Widget.expects(:new).with(:permitted => 'param')
67
- get :new, :widget => { :permitted => 'param', :prohibited => 'param' }
68
- end
69
-
70
- def test_permitted_params_from_create
71
- Widget.expects(:new).with(:permitted => 'param').returns(mock(:save => true))
72
- post :create, :widget => { :permitted => 'param', :prohibited => 'param' }
73
- end
74
-
75
- def test_permitted_params_from_update
76
- mock_widget = mock
77
- mock_widget.stubs(:class).returns(Widget)
78
- mock_widget.expects(:update_attributes).with(:permitted => 'param')
79
- Widget.expects(:find).with('42').returns(mock_widget)
80
- put :update, :id => '42', :widget => {:permitted => 'param', :prohibited => 'param'}
81
- end
82
- end
83
-
84
- # test usage of `widget_params` integrated with strong parameters (not using stubs)
85
- class StrongParametersIntegrationTest < ActionController::TestCase
86
- def setup
87
- @controller = WidgetsController.new
88
- @controller.stubs(:widget_url).returns("/")
89
-
90
- class << @controller
91
- define_method :widget_params do
92
- params.require(:widget).permit(:permitted)
93
- end
94
- private :widget_params
95
- end
96
- end
97
-
98
- def test_permitted_empty_params_from_new
99
- Widget.expects(:new).with({})
100
- get :new, {}
101
- end
102
-
103
- def test_permitted_params_from_new
104
- Widget.expects(:new).with('permitted' => 'param')
105
- get :new, :widget => { :permitted => 'param', :prohibited => 'param' }
106
- end
107
-
108
- def test_permitted_params_from_create
109
- Widget.expects(:new).with('permitted' => 'param').returns(mock(:save => true))
110
- post :create, :widget => { :permitted => 'param', :prohibited => 'param' }
111
- end
112
-
113
- def test_permitted_params_from_update
114
- mock_widget = mock
115
- mock_widget.stubs(:class).returns(Widget)
116
- mock_widget.expects(:update_attributes).with('permitted' => 'param')
117
- Widget.expects(:find).with('42').returns(mock_widget)
118
- put :update, :id => '42', :widget => {:permitted => 'param', :prohibited => 'param'}
119
- end
120
- end
data/test/test_helper.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- Bundler.setup
5
-
6
- require 'minitest'
7
- require 'mocha/mini_test'
8
- require 'minitest/rg'
9
- require 'minitest/autorun'
10
-
11
- ENV["RAILS_ENV"] = "test"
12
- RAILS_ROOT = "anywhere"
13
-
14
- require "active_support"
15
- require "active_model"
16
- require "action_controller"
17
-
18
- I18n.load_path << File.join(File.dirname(__FILE__), 'locales', 'en.yml')
19
- I18n.reload!
20
-
21
- class ApplicationController < ActionController::Base; end
22
-
23
- # Add IR to load path and load the main file
24
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
25
- require 'inherited_resources'
26
-
27
- ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
28
-
29
- InheritedResources::Routes = ActionDispatch::Routing::RouteSet.new
30
- InheritedResources::Routes.draw do
31
- get ':controller(/:action(/:id))'
32
- get ':controller(/:action)'
33
- resources 'posts'
34
- root :to => 'posts#index'
35
- end
36
-
37
- ActionController::Base.send :include, InheritedResources::Routes.url_helpers
38
-
39
- # Add app base to load path
40
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../app/controllers')
41
- require 'inherited_resources/base'
42
-
43
- class ActiveSupport::TestCase
44
- setup do
45
- @routes = InheritedResources::Routes
46
- end
47
- end
@@ -1,988 +0,0 @@
1
- require File.expand_path('test_helper', File.dirname(__FILE__))
2
-
3
- class Universe
4
- extend ActiveModel::Naming
5
- end
6
- class UniversesController < InheritedResources::Base
7
- defaults :singleton => true, :route_instance_name => 'universum'
8
- end
9
-
10
- class House
11
- extend ActiveModel::Naming
12
- end
13
- class HousesController < InheritedResources::Base
14
- end
15
-
16
- class News
17
- extend ActiveModel::Naming
18
- end
19
- class NewsController < InheritedResources::Base
20
- end
21
-
22
- class Backpack
23
- extend ActiveModel::Naming
24
- end
25
- module Admin; end
26
- class Admin::BackpacksController < InheritedResources::Base
27
- defaults :route_collection_name => 'tour_backpacks'
28
- end
29
-
30
- class Table
31
- extend ActiveModel::Naming
32
- end
33
- class TablesController < InheritedResources::Base
34
- belongs_to :house
35
- end
36
-
37
- class RoomsController < InheritedResources::Base
38
- belongs_to :house, :route_name => 'big_house'
39
- end
40
-
41
- class ChairsController < InheritedResources::Base
42
- belongs_to :house do
43
- belongs_to :table
44
- end
45
- end
46
-
47
- class OwnersController < InheritedResources::Base
48
- defaults :singleton => true
49
-
50
- belongs_to :house
51
- end
52
-
53
- class Fireplace
54
- extend ActiveModel::Naming
55
- end
56
- class Flame
57
- extend ActiveModel::Naming
58
- end
59
- class FlamesController < InheritedResources::Base
60
- belongs_to :house do
61
- belongs_to :fireplace, :singleton => true
62
- end
63
- end
64
-
65
- class Bed
66
- extend ActiveModel::Naming
67
- end
68
- class BedsController < InheritedResources::Base
69
- optional_belongs_to :house, :building
70
- end
71
-
72
- class Sheep
73
- extend ActiveModel::Naming
74
- end
75
- class SheepController < InheritedResources::Base
76
- belongs_to :news, :table, :polymorphic => true
77
- end
78
-
79
- class Fish
80
- extend ActiveModel::Naming
81
- end
82
- class FishController < InheritedResources::Base
83
- belongs_to :bed, :shallow => true
84
- end
85
-
86
- class Desk
87
- extend ActiveModel::Naming
88
- end
89
- module Admin
90
- class DesksController < InheritedResources::Base
91
- optional_belongs_to :house
92
- end
93
- end
94
-
95
- class Dish
96
- extend ActiveModel::Naming
97
- end
98
- class DishesController < InheritedResources::Base
99
- belongs_to :house do
100
- polymorphic_belongs_to :table, :kitchen
101
- end
102
- end
103
-
104
- class Dishwasher
105
- extend ActiveModel::Naming
106
- end
107
- class Fork
108
- extend ActiveModel::Naming
109
- end
110
- class Spot
111
- extend ActiveModel::Naming
112
- end
113
- class SpotsController < InheritedResources::Base
114
- belongs_to :house do
115
- belongs_to :dishwasher, :singleton => true do
116
- polymorphic_belongs_to :dish, :fork
117
- end
118
- end
119
- end
120
-
121
- class Center
122
- extend ActiveModel::Naming
123
- end
124
- class CentersController < InheritedResources::Base
125
- acts_as_singleton!
126
-
127
- belongs_to :house do
128
- belongs_to :table, :kitchen, :polymorphic => true
129
- end
130
- end
131
-
132
- class Mirror
133
- extend ActiveModel::Naming
134
- end
135
- class MirrorsController < InheritedResources::Base
136
- belongs_to :house, :shallow => true
137
- end
138
- class Admin::MirrorsController < InheritedResources::Base
139
- belongs_to :house, :shallow => true
140
- end
141
-
142
-
143
- class Display
144
- extend ActiveModel::Naming
145
- end
146
-
147
- class Window
148
- extend ActiveModel::Naming
149
- end
150
-
151
- class Button
152
- extend ActiveModel::Naming
153
- end
154
-
155
- class ButtonsController < InheritedResources::Base
156
- belongs_to :display, :window, :shallow => true
157
- custom_actions :resource => :delete, :collection => :search
158
- end
159
-
160
- class ImageButtonsController < ButtonsController
161
- end
162
-
163
-
164
- # Create a TestHelper module with some helpers
165
- class UrlHelpersTest < ActiveSupport::TestCase
166
- def mock_polymorphic(controller, route)
167
- controller.expects(route)
168
- end
169
-
170
- def test_url_helpers_on_simple_inherited_resource
171
- controller = HousesController.new
172
- controller.instance_variable_set('@house', :house)
173
-
174
- [:url, :path].each do |path_or_url|
175
- controller.expects("houses_#{path_or_url}").with({}).once
176
- controller.send("collection_#{path_or_url}")
177
-
178
- controller.expects("house_#{path_or_url}").with(:house, {}).once
179
- controller.send("resource_#{path_or_url}")
180
-
181
- controller.expects("new_house_#{path_or_url}").with({}).once
182
- controller.send("new_resource_#{path_or_url}")
183
-
184
- controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
185
- controller.send("edit_resource_#{path_or_url}")
186
-
187
- # With arg
188
- controller.expects("house_#{path_or_url}").with(:arg, {}).once
189
- controller.send("resource_#{path_or_url}", :arg)
190
-
191
- controller.expects("house_#{path_or_url}").with(:arg, {}).once
192
- controller.send("resource_#{path_or_url}", :arg)
193
-
194
- # With options
195
- controller.expects("house_#{path_or_url}").with(:arg, :page => 1).once
196
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
197
- end
198
- end
199
-
200
- def test_url_helpers_on_simple_inherited_resource_using_uncountable
201
- controller = NewsController.new
202
- controller.instance_variable_set('@news', :news)
203
-
204
- [:url, :path].each do |path_or_url|
205
- controller.expects("news_index_#{path_or_url}").with({}).once
206
- controller.send("collection_#{path_or_url}")
207
-
208
- controller.expects("news_#{path_or_url}").with(:news, {}).once
209
- controller.send("resource_#{path_or_url}")
210
-
211
- controller.expects("new_news_#{path_or_url}").with({}).once
212
- controller.send("new_resource_#{path_or_url}")
213
-
214
- controller.expects("edit_news_#{path_or_url}").with(:news, {}).once
215
- controller.send("edit_resource_#{path_or_url}")
216
-
217
- # With arg
218
- controller.expects("news_#{path_or_url}").with(:arg, {}).once
219
- controller.send("resource_#{path_or_url}", :arg)
220
-
221
- controller.expects("news_#{path_or_url}").with(:arg, {}).once
222
- controller.send("resource_#{path_or_url}", :arg)
223
-
224
- # With options
225
- controller.expects("news_#{path_or_url}").with(:arg, :page => 1).once
226
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
227
- end
228
- end
229
-
230
- def test_url_helpers_on_simple_inherited_namespaced_resource
231
- controller = Admin::BackpacksController.new
232
- controller.instance_variable_set('@backpack', :backpack)
233
-
234
- assert_equal 'admin', controller.class.resources_configuration[:self][:route_prefix]
235
-
236
- [:url, :path].each do |path_or_url|
237
- controller.expects("admin_tour_backpacks_#{path_or_url}").with({}).once
238
- controller.send("collection_#{path_or_url}")
239
-
240
- controller.expects("admin_backpack_#{path_or_url}").with(:backpack, {}).once
241
- controller.send("resource_#{path_or_url}")
242
-
243
- controller.expects("new_admin_backpack_#{path_or_url}").with({}).once
244
- controller.send("new_resource_#{path_or_url}")
245
-
246
- controller.expects("edit_admin_backpack_#{path_or_url}").with(:backpack, {}).once
247
- controller.send("edit_resource_#{path_or_url}")
248
-
249
- # With arg
250
- controller.expects("admin_backpack_#{path_or_url}").with(:arg, {}).once
251
- controller.send("resource_#{path_or_url}", :arg)
252
-
253
- controller.expects("admin_backpack_#{path_or_url}").with(:arg, {}).once
254
- controller.send("resource_#{path_or_url}", :arg)
255
-
256
- # With options
257
- controller.expects("admin_backpack_#{path_or_url}").with(:arg, :page => 1).once
258
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
259
- end
260
- end
261
-
262
- def test_url_helpers_on_simple_inherited_singleton_resource
263
- controller = UniversesController.new
264
- controller.instance_variable_set('@universe', :universe)
265
-
266
- [:url, :path].each do |path_or_url|
267
- controller.expects("root_#{path_or_url}").with({}).once
268
- controller.send("collection_#{path_or_url}")
269
-
270
- controller.expects("universum_#{path_or_url}").with({}).once
271
- controller.send("resource_#{path_or_url}")
272
-
273
- controller.expects("new_universum_#{path_or_url}").with({}).once
274
- controller.send("new_resource_#{path_or_url}")
275
-
276
- controller.expects("edit_universum_#{path_or_url}").with({}).once
277
- controller.send("edit_resource_#{path_or_url}")
278
-
279
- # With options
280
- # Also tests that argument sent are not used
281
- controller.expects("universum_#{path_or_url}").with(:page => 1).once
282
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
283
- end
284
- end
285
-
286
- def test_url_helpers_on_singleton_belongs_to
287
- controller = FlamesController.new
288
- controller.instance_variable_set('@house', :house)
289
- controller.instance_variable_set('@fireplace', :fireplace)
290
- controller.instance_variable_set('@flame', :flame)
291
-
292
- [:url, :path].each do |path_or_url|
293
- controller.expects("house_fireplace_flames_#{path_or_url}").with(:house, {}).once
294
- controller.send("collection_#{path_or_url}")
295
-
296
- controller.expects("house_fireplace_flame_#{path_or_url}").with(:house, :flame, {}).once
297
- controller.send("resource_#{path_or_url}")
298
-
299
- controller.expects("new_house_fireplace_flame_#{path_or_url}").with(:house, {}).once
300
- controller.send("new_resource_#{path_or_url}")
301
-
302
- controller.expects("edit_house_fireplace_flame_#{path_or_url}").with(:house, :flame, {}).once
303
- controller.send("edit_resource_#{path_or_url}")
304
-
305
- controller.expects("house_fireplace_#{path_or_url}").with(:house, {}).once
306
- controller.send("parent_#{path_or_url}")
307
-
308
- controller.expects("edit_house_fireplace_#{path_or_url}").with(:house, {}).once
309
- controller.send("edit_parent_#{path_or_url}")
310
-
311
- # With options
312
- # Also tests that argument sent are not used
313
- controller.expects("house_fireplace_flame_#{path_or_url}").with(:house, :arg, :page => 1).once
314
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
315
- end
316
- end
317
-
318
- def test_url_helpers_on_belongs_to
319
- controller = TablesController.new
320
- controller.instance_variable_set('@house', :house)
321
- controller.instance_variable_set('@table', :table)
322
-
323
- [:url, :path].each do |path_or_url|
324
- controller.expects("house_tables_#{path_or_url}").with(:house, {}).once
325
- controller.send("collection_#{path_or_url}")
326
-
327
- controller.expects("house_table_#{path_or_url}").with(:house, :table, {}).once
328
- controller.send("resource_#{path_or_url}")
329
-
330
- controller.expects("new_house_table_#{path_or_url}").with(:house, {}).once
331
- controller.send("new_resource_#{path_or_url}")
332
-
333
- controller.expects("edit_house_table_#{path_or_url}").with(:house, :table, {}).once
334
- controller.send("edit_resource_#{path_or_url}")
335
-
336
- controller.expects("house_#{path_or_url}").with(:house, {}).once
337
- controller.send("parent_#{path_or_url}")
338
-
339
- controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
340
- controller.send("edit_parent_#{path_or_url}")
341
-
342
- # With arg
343
- controller.expects("house_table_#{path_or_url}").with(:house, :arg, {}).once
344
- controller.send("resource_#{path_or_url}", :arg)
345
-
346
- controller.expects("edit_house_table_#{path_or_url}").with(:house, :arg, {}).once
347
- controller.send("edit_resource_#{path_or_url}", :arg)
348
-
349
- controller.expects("house_#{path_or_url}").with(:arg, {}).once
350
- controller.send("parent_#{path_or_url}", :arg)
351
-
352
- # With options
353
- controller.expects("house_table_#{path_or_url}").with(:house, :arg, :page => 1).once
354
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
355
- end
356
- end
357
-
358
- def test_url_helpers_on_not_default_belongs_to
359
- controller = RoomsController.new
360
- controller.instance_variable_set('@house', :house)
361
- controller.instance_variable_set('@room', :room)
362
-
363
- [:url, :path].each do |path_or_url|
364
- controller.expects("big_house_rooms_#{path_or_url}").with(:house, {}).once
365
- controller.send("collection_#{path_or_url}")
366
-
367
- controller.expects("big_house_room_#{path_or_url}").with(:house, :room, {}).once
368
- controller.send("resource_#{path_or_url}")
369
-
370
- controller.expects("new_big_house_room_#{path_or_url}").with(:house, {}).once
371
- controller.send("new_resource_#{path_or_url}")
372
-
373
- controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :room, {}).once
374
- controller.send("edit_resource_#{path_or_url}")
375
-
376
- controller.expects("big_house_#{path_or_url}").with(:house, {}).once
377
- controller.send("parent_#{path_or_url}")
378
-
379
- controller.expects("edit_big_house_#{path_or_url}").with(:house, {}).once
380
- controller.send("edit_parent_#{path_or_url}")
381
-
382
- # With args
383
- controller.expects("big_house_room_#{path_or_url}").with(:house, :arg, {}).once
384
- controller.send("resource_#{path_or_url}", :arg)
385
-
386
- controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :arg, {}).once
387
- controller.send("edit_resource_#{path_or_url}", :arg)
388
-
389
- controller.expects("big_house_#{path_or_url}").with(:arg, {}).once
390
- controller.send("parent_#{path_or_url}", :arg)
391
-
392
- # With options
393
- controller.expects("big_house_room_#{path_or_url}").with(:house, :arg, :page => 1).once
394
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
395
- end
396
- end
397
-
398
- def test_url_helpers_on_nested_belongs_to
399
- controller = ChairsController.new
400
- controller.instance_variable_set('@house', :house)
401
- controller.instance_variable_set('@table', :table)
402
- controller.instance_variable_set('@chair', :chair)
403
-
404
- [:url, :path].each do |path_or_url|
405
- controller.expects("house_table_chairs_#{path_or_url}").with(:house, :table, {}).once
406
- controller.send("collection_#{path_or_url}")
407
-
408
- controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :chair, {}).once
409
- controller.send("resource_#{path_or_url}")
410
-
411
- controller.expects("new_house_table_chair_#{path_or_url}").with(:house, :table, {}).once
412
- controller.send("new_resource_#{path_or_url}")
413
-
414
- controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :chair, {}).once
415
- controller.send("edit_resource_#{path_or_url}")
416
-
417
- controller.expects("house_table_#{path_or_url}").with(:house, :table, {}).once
418
- controller.send("parent_#{path_or_url}")
419
-
420
- controller.expects("edit_house_table_#{path_or_url}").with(:house, :table, {}).once
421
- controller.send("edit_parent_#{path_or_url}")
422
-
423
- # With args
424
- controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg, {}).once
425
- controller.send("edit_resource_#{path_or_url}", :arg)
426
-
427
- controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :arg, {}).once
428
- controller.send("resource_#{path_or_url}", :arg)
429
-
430
- controller.expects("house_table_#{path_or_url}").with(:house, :arg, {}).once
431
- controller.send("parent_#{path_or_url}", :arg)
432
-
433
- # With options
434
- controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg, :page => 1).once
435
- controller.send("edit_resource_#{path_or_url}", :arg, :page => 1)
436
- end
437
- end
438
-
439
- def test_url_helpers_on_singletons_with_belongs_to
440
- controller = OwnersController.new
441
- controller.instance_variable_set('@house', :house)
442
- controller.instance_variable_set('@owner', :owner)
443
-
444
- [:url, :path].each do |path_or_url|
445
- controller.expects("house_#{path_or_url}").with(:house, {}).once
446
- controller.send("collection_#{path_or_url}")
447
-
448
- controller.expects("house_owner_#{path_or_url}").with(:house, {}).once
449
- controller.send("resource_#{path_or_url}")
450
-
451
- controller.expects("new_house_owner_#{path_or_url}").with(:house, {}).once
452
- controller.send("new_resource_#{path_or_url}")
453
-
454
- controller.expects("edit_house_owner_#{path_or_url}").with(:house, {}).once
455
- controller.send("edit_resource_#{path_or_url}")
456
-
457
- controller.expects("house_#{path_or_url}").with(:house, {}).once
458
- controller.send("parent_#{path_or_url}")
459
-
460
- controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
461
- controller.send("edit_parent_#{path_or_url}")
462
-
463
- # With options
464
- # Also tests that argument sent are not used
465
- controller.expects("house_owner_#{path_or_url}").with(:house, :page => 1).once
466
- controller.send("resource_#{path_or_url}", :arg, :page => 1)
467
- end
468
- end
469
-
470
- def test_url_helpers_on_nested_polymorphic_belongs_to
471
- house = House.new
472
- table = Table.new
473
- dish = Dish.new
474
-
475
- new_dish = Dish.new
476
- Dish.stubs(:new).returns(new_dish)
477
- new_dish.stubs(:persisted?).returns(false)
478
-
479
- controller = DishesController.new
480
- controller.instance_variable_set('@parent_type', :table)
481
- controller.instance_variable_set('@house', house)
482
- controller.instance_variable_set('@table', table)
483
- controller.instance_variable_set('@dish', dish)
484
-
485
- [:url, :path].each do |path_or_url|
486
- mock_polymorphic(controller, "house_table_dishes_#{path_or_url}").with(house, table).once
487
- controller.send("collection_#{path_or_url}")
488
-
489
- mock_polymorphic(controller, "house_table_dish_#{path_or_url}").with(house, table, dish).once
490
- controller.send("resource_#{path_or_url}")
491
-
492
- mock_polymorphic(controller, "new_house_table_dish_#{path_or_url}").with(house, table).once
493
- controller.send("new_resource_#{path_or_url}")
494
-
495
- mock_polymorphic(controller, "edit_house_table_dish_#{path_or_url}").with(house, table, dish).once
496
- controller.send("edit_resource_#{path_or_url}")
497
-
498
- mock_polymorphic(controller, "house_table_#{path_or_url}").with(house, table).once
499
- controller.send("parent_#{path_or_url}")
500
-
501
- mock_polymorphic(controller, "edit_house_table_#{path_or_url}").with(house, table).once
502
- controller.send("edit_parent_#{path_or_url}")
503
- end
504
- end
505
-
506
- def test_url_helpers_on_singleton_and_polymorphic_belongs_to
507
- house = House.new
508
- dishwasher = Dishwasher.new
509
- fork = Fork.new
510
- spot = Spot.new
511
-
512
- new_spot = Spot.new
513
- Spot.stubs(:new).returns(new_spot)
514
- new_spot.stubs(:persisted?).returns(false)
515
-
516
- controller = SpotsController.new
517
- controller.instance_variable_set('@parent_type', :fork)
518
- controller.instance_variable_set('@house', house)
519
- controller.instance_variable_set('@dishwasher', dishwasher)
520
- controller.instance_variable_set('@fork', fork)
521
- controller.instance_variable_set('@spot', spot)
522
-
523
- [:url, :path].each do |path_or_url|
524
- mock_polymorphic(controller, "house_dishwasher_fork_spots_#{path_or_url}").with(house, fork).once
525
- controller.send("collection_#{path_or_url}")
526
-
527
- mock_polymorphic(controller, "house_dishwasher_fork_spot_#{path_or_url}").with(house, fork, spot).once
528
- controller.send("resource_#{path_or_url}")
529
-
530
- mock_polymorphic(controller, "new_house_dishwasher_fork_spot_#{path_or_url}").with(house, fork).once
531
- controller.send("new_resource_#{path_or_url}")
532
-
533
- mock_polymorphic(controller, "edit_house_dishwasher_fork_spot_#{path_or_url}").with(house, fork, spot).once
534
- controller.send("edit_resource_#{path_or_url}")
535
-
536
- mock_polymorphic(controller, "house_dishwasher_fork_#{path_or_url}").with(house, fork).once
537
- controller.send("parent_#{path_or_url}")
538
-
539
- mock_polymorphic(controller, "edit_house_dishwasher_fork_#{path_or_url}").with(house, fork).once
540
- controller.send("edit_parent_#{path_or_url}")
541
- end
542
- end
543
-
544
- def test_url_helpers_on_polymorphic_belongs_to
545
- house = House.new
546
- bed = Bed.new
547
-
548
- new_bed = Bed.new
549
- Bed.stubs(:new).returns(new_bed)
550
- new_bed.stubs(:persisted?).returns(false)
551
-
552
- controller = BedsController.new
553
- controller.instance_variable_set('@parent_type', :house)
554
- controller.instance_variable_set('@house', house)
555
- controller.instance_variable_set('@bed', bed)
556
-
557
- [:url, :path].each do |path_or_url|
558
- mock_polymorphic(controller, "house_beds_#{path_or_url}").with(house).once
559
- controller.send("collection_#{path_or_url}")
560
-
561
- mock_polymorphic(controller, "house_bed_#{path_or_url}").with(house, bed).once
562
- controller.send("resource_#{path_or_url}")
563
-
564
- mock_polymorphic(controller, "new_house_bed_#{path_or_url}").with(house).once
565
- controller.send("new_resource_#{path_or_url}")
566
-
567
- mock_polymorphic(controller, "edit_house_bed_#{path_or_url}").with(house, bed).once
568
- controller.send("edit_resource_#{path_or_url}")
569
-
570
- mock_polymorphic(controller, "house_#{path_or_url}").with(house).once
571
- controller.send("parent_#{path_or_url}")
572
-
573
- mock_polymorphic(controller, "edit_house_#{path_or_url}").with(house).once
574
- controller.send("edit_parent_#{path_or_url}")
575
- end
576
-
577
- # With options
578
- mock_polymorphic(controller, "house_bed_url").with(house, bed, :page => 1).once
579
- controller.send("resource_url", :page => 1)
580
-
581
- mock_polymorphic(controller, "house_url").with(house, :page => 1).once
582
- controller.send("parent_url", :page => 1)
583
-
584
- # With args
585
- controller.expects("polymorphic_url").with([:arg, new_bed], {}).once
586
- controller.send("collection_url", :arg)
587
-
588
- controller.expects("polymorphic_url").with([house, :arg], {}).once
589
- controller.send("resource_url", :arg)
590
-
591
- controller.expects("edit_polymorphic_url").with([house, :arg], {}).once
592
- controller.send("edit_resource_url", :arg)
593
-
594
- controller.expects("polymorphic_url").with([:arg], {}).once
595
- controller.send("parent_url", :arg)
596
- end
597
-
598
- def test_url_helpers_on_polymorphic_belongs_to_using_uncountable
599
- sheep = Sheep.new
600
- news = News.new
601
-
602
- new_sheep = Sheep.new
603
- Sheep.stubs(:new).returns(new_sheep)
604
- new_sheep.stubs(:persisted?).returns(false)
605
-
606
- controller = SheepController.new
607
- controller.instance_variable_set('@parent_type', :news)
608
- controller.instance_variable_set('@news', news)
609
- controller.instance_variable_set('@sheep', sheep)
610
-
611
- [:url, :path].each do |path_or_url|
612
- mock_polymorphic(controller, "news_sheep_index_#{path_or_url}").with(news).once
613
- controller.send("collection_#{path_or_url}")
614
-
615
- mock_polymorphic(controller, "news_sheep_#{path_or_url}").with(news, sheep).once
616
- controller.send("resource_#{path_or_url}")
617
-
618
- mock_polymorphic(controller, "new_news_sheep_#{path_or_url}").with(news).once
619
- controller.send("new_resource_#{path_or_url}")
620
-
621
- mock_polymorphic(controller, "edit_news_sheep_#{path_or_url}").with(news, sheep).once
622
- controller.send("edit_resource_#{path_or_url}")
623
-
624
- mock_polymorphic(controller, "news_#{path_or_url}").with(news).once
625
- controller.send("parent_#{path_or_url}")
626
-
627
- mock_polymorphic(controller, "edit_news_#{path_or_url}").with(news).once
628
- controller.send("edit_parent_#{path_or_url}")
629
- end
630
-
631
- # With options
632
- mock_polymorphic(controller, "news_sheep_url").with(news, sheep, :page => 1).once
633
- controller.send("resource_url", :page => 1)
634
-
635
- mock_polymorphic(controller, "news_url").with(news, :page => 1).once
636
- controller.send("parent_url", :page => 1)
637
-
638
- # With args
639
- controller.expects("polymorphic_url").with([:arg, new_sheep], {}).once
640
- controller.send("collection_url", :arg)
641
-
642
- controller.expects("polymorphic_url").with([news, :arg], {}).once
643
- controller.send("resource_url", :arg)
644
-
645
- controller.expects("edit_polymorphic_url").with([news, :arg], {}).once
646
- controller.send("edit_resource_url", :arg)
647
-
648
- controller.expects("polymorphic_url").with([:arg], {}).once
649
- controller.send("parent_url", :arg)
650
- end
651
-
652
- def test_url_helpers_on_shallow_belongs_to_using_uncountable
653
- fish = Fish.new
654
- bed = Bed.new
655
-
656
- new_fish = Fish.new
657
- new_fish.stubs(:persisted?).returns(false)
658
- Sheep.stubs(:new).returns(new_fish)
659
-
660
- controller = FishController.new
661
- controller.instance_variable_set('@bed', bed)
662
- controller.instance_variable_set('@fish', fish)
663
-
664
- [:url, :path].each do |path_or_url|
665
- controller.expects("bed_fish_index_#{path_or_url}").with(bed, {}).once
666
- controller.send("collection_#{path_or_url}")
667
-
668
- controller.expects("fish_#{path_or_url}").with(fish, {}).once
669
- controller.send("resource_#{path_or_url}")
670
-
671
- controller.expects("new_bed_fish_#{path_or_url}").with(bed, {}).once
672
- controller.send("new_resource_#{path_or_url}")
673
-
674
- controller.expects("edit_fish_#{path_or_url}").with(fish, {}).once
675
- controller.send("edit_resource_#{path_or_url}")
676
-
677
- controller.expects("bed_#{path_or_url}").with(bed, {}).once
678
- controller.send("parent_#{path_or_url}")
679
-
680
- controller.expects("edit_bed_#{path_or_url}").with(bed, {}).once
681
- controller.send("edit_parent_#{path_or_url}")
682
- end
683
- end
684
-
685
- def test_url_helpers_on_namespaced_polymorphic_belongs_to
686
- house = House.new
687
- desk = Desk.new
688
-
689
- new_desk = Desk.new
690
- Desk.stubs(:new).returns(new_desk)
691
- new_desk.stubs(:persisted?).returns(false)
692
-
693
- controller = Admin::DesksController.new
694
- controller.instance_variable_set('@parent_type', :house)
695
- controller.instance_variable_set('@house', house)
696
- controller.instance_variable_set('@desk', desk)
697
-
698
- [:url, :path].each do |path_or_url|
699
- mock_polymorphic(controller, "admin_house_desks_#{path_or_url}").with(house).once
700
- controller.send("collection_#{path_or_url}")
701
-
702
- mock_polymorphic(controller, "admin_house_desk_#{path_or_url}").with(house, desk).once
703
- controller.send("resource_#{path_or_url}")
704
-
705
- mock_polymorphic(controller, "new_admin_house_desk_#{path_or_url}").with(house).once
706
- controller.send("new_resource_#{path_or_url}")
707
-
708
- mock_polymorphic(controller, "edit_admin_house_desk_#{path_or_url}").with(house, desk).once
709
- controller.send("edit_resource_#{path_or_url}")
710
-
711
- mock_polymorphic(controller, "admin_house_#{path_or_url}").with(house).once
712
- controller.send("parent_#{path_or_url}")
713
-
714
- mock_polymorphic(controller, "edit_admin_house_#{path_or_url}").with(house).once
715
- controller.send("edit_parent_#{path_or_url}")
716
- end
717
-
718
- # With options
719
- mock_polymorphic(controller, "admin_house_desk_url").with(house, desk, :page => 1).once
720
- controller.send("resource_url", :page => 1)
721
-
722
- mock_polymorphic(controller, "admin_house_url").with(house, :page => 1).once
723
- controller.send("parent_url", :page => 1)
724
-
725
- # With args
726
- controller.expects("polymorphic_url").with(['admin', :arg, new_desk], {}).once
727
- controller.send("collection_url", :arg)
728
-
729
- controller.expects("polymorphic_url").with(['admin', house, :arg], {}).once
730
- controller.send("resource_url", :arg)
731
-
732
- controller.expects("edit_polymorphic_url").with(['admin', house, :arg], {}).once
733
- controller.send("edit_resource_url", :arg)
734
-
735
- controller.expects("polymorphic_url").with(['admin', :arg], {}).once
736
- controller.send("parent_url", :arg)
737
- end
738
-
739
- def test_url_helpers_on_nested_polymorphic_belongs_to
740
- house = House.new
741
- table = Table.new
742
- dish = Dish.new
743
-
744
- new_dish = Dish.new
745
- Dish.stubs(:new).returns(new_dish)
746
- new_dish.stubs(:persisted?).returns(false)
747
-
748
- controller = DishesController.new
749
- controller.instance_variable_set('@parent_type', :table)
750
- controller.instance_variable_set('@house', house)
751
- controller.instance_variable_set('@table', table)
752
- controller.instance_variable_set('@dish', dish)
753
-
754
- [:url, :path].each do |path_or_url|
755
- mock_polymorphic(controller, "house_table_dishes_#{path_or_url}").with(house, table).once
756
- controller.send("collection_#{path_or_url}")
757
-
758
- mock_polymorphic(controller, "house_table_dish_#{path_or_url}").with(house, table, dish).once
759
- controller.send("resource_#{path_or_url}")
760
-
761
- mock_polymorphic(controller, "new_house_table_dish_#{path_or_url}").with(house, table).once
762
- controller.send("new_resource_#{path_or_url}")
763
-
764
- mock_polymorphic(controller, "edit_house_table_dish_#{path_or_url}").with(house, table, dish).once
765
- controller.send("edit_resource_#{path_or_url}")
766
-
767
- mock_polymorphic(controller, "house_table_#{path_or_url}").with(house, table).once
768
- controller.send("parent_#{path_or_url}")
769
-
770
- mock_polymorphic(controller, "edit_house_table_#{path_or_url}").with(house, table).once
771
- controller.send("edit_parent_#{path_or_url}")
772
- end
773
-
774
- # With options
775
- mock_polymorphic(controller, "house_table_dish_url").with(house, table, dish, :page => 1).once
776
- controller.send("resource_url", :page => 1)
777
-
778
- mock_polymorphic(controller, "house_table_url").with(house, table, :page => 1).once
779
- controller.send("parent_url", :page => 1)
780
-
781
- # With args
782
- controller.expects("polymorphic_url").with([house, table, :arg], {}).once
783
- controller.send("resource_url", :arg)
784
-
785
- controller.expects("edit_polymorphic_url").with([house, table, :arg], {}).once
786
- controller.send("edit_resource_url", :arg)
787
-
788
- controller.expects("polymorphic_url").with([house, :arg], {}).once
789
- controller.send("parent_url", :arg)
790
- end
791
-
792
- def test_url_helpers_on_singleton_nested_polymorphic_belongs_to
793
- # This must not be usefull in singleton controllers...
794
- # Center.new
795
- house = House.new
796
- table = Table.new
797
-
798
- controller = CentersController.new
799
- controller.instance_variable_set('@parent_type', :table)
800
- controller.instance_variable_set('@house', house)
801
- controller.instance_variable_set('@table', table)
802
-
803
- # This must not be useful in singleton controllers...
804
- # controller.instance_variable_set('@center', :center)
805
-
806
- [:url, :path].each do |path_or_url|
807
- mock_polymorphic(controller, "house_table_#{path_or_url}").with(house, table).once
808
- controller.send("collection_#{path_or_url}")
809
-
810
- mock_polymorphic(controller, "house_table_center_#{path_or_url}").with(house, table).once
811
- controller.send("resource_#{path_or_url}")
812
-
813
- mock_polymorphic(controller, "new_house_table_center_#{path_or_url}").with(house, table).once
814
- controller.send("new_resource_#{path_or_url}")
815
-
816
- mock_polymorphic(controller, "edit_house_table_center_#{path_or_url}").with(house, table).once
817
- controller.send("edit_resource_#{path_or_url}")
818
-
819
- mock_polymorphic(controller, "house_table_#{path_or_url}").with(house, table).once
820
- controller.send("parent_#{path_or_url}")
821
-
822
- mock_polymorphic(controller, "edit_house_table_#{path_or_url}").with(house, table).once
823
- controller.send("edit_parent_#{path_or_url}")
824
- end
825
-
826
- # With options
827
- mock_polymorphic(controller, "house_table_center_url").with(house, table, :page => 1)
828
- controller.send("resource_url", :page => 1)
829
-
830
- mock_polymorphic(controller, "house_table_url").with(house, table, :page => 1)
831
- controller.send("parent_url", :page => 1)
832
-
833
- # With args
834
- controller.expects("polymorphic_url").with([house, table, :center], {}).once
835
- controller.send("resource_url", :arg)
836
-
837
- controller.expects("polymorphic_url").with([house, :arg], {}).once
838
- controller.send("parent_url", :arg)
839
- end
840
-
841
- def test_url_helpers_on_optional_polymorphic_belongs_to
842
- bed = Bed.new
843
- new_bed = Bed.new
844
- Bed.stubs(:new).returns(new_bed)
845
- new_bed.stubs(:persisted?).returns(false)
846
-
847
- controller = BedsController.new
848
- controller.stubs(:parent_type).returns(nil)
849
- controller.instance_variable_set('@bed', bed)
850
-
851
- [:url, :path].each do |path_or_url|
852
- mock_polymorphic(controller, "beds_#{path_or_url}").with().once
853
- controller.send("collection_#{path_or_url}")
854
-
855
- mock_polymorphic(controller, "bed_#{path_or_url}").with(bed).once
856
- controller.send("resource_#{path_or_url}")
857
-
858
- mock_polymorphic(controller, "new_bed_#{path_or_url}").with().once
859
- controller.send("new_resource_#{path_or_url}")
860
-
861
- mock_polymorphic(controller, "edit_bed_#{path_or_url}").with(bed).once
862
- controller.send("edit_resource_#{path_or_url}")
863
- end
864
-
865
- # With options
866
- mock_polymorphic(controller, "bed_url").with(bed, :page => 1).once
867
- controller.send("resource_url", :page => 1)
868
-
869
- # With args
870
- controller.expects("polymorphic_url").with([:arg], {}).once
871
- controller.send("resource_url", :arg)
872
-
873
- controller.expects("edit_polymorphic_url").with([:arg], {}).once
874
- controller.send("edit_resource_url", :arg)
875
- end
876
-
877
-
878
- def test_url_helpers_on_belongs_to_with_shallowed_route
879
- controller = MirrorsController.new
880
- controller.instance_variable_set('@house', :house)
881
- controller.instance_variable_set('@mirror', :mirror)
882
-
883
- [:url, :path].each do |path_or_url|
884
- controller.expects("house_mirrors_#{path_or_url}").with(:house, {}).once
885
- controller.send("collection_#{path_or_url}")
886
-
887
- controller.expects("mirror_#{path_or_url}").with(:mirror, {}).once
888
- controller.send("resource_#{path_or_url}")
889
-
890
- controller.expects("new_house_mirror_#{path_or_url}").with(:house, {}).once
891
- controller.send("new_resource_#{path_or_url}")
892
-
893
- controller.expects("edit_mirror_#{path_or_url}").with(:mirror, {}).once
894
- controller.send("edit_resource_#{path_or_url}")
895
-
896
- controller.expects("house_#{path_or_url}").with(:house, {}).once
897
- controller.send("parent_#{path_or_url}")
898
-
899
- controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
900
- controller.send("edit_parent_#{path_or_url}")
901
- end
902
- end
903
-
904
- def test_url_helpers_on_nested_belongs_to_with_shallowed_route
905
- controller = ButtonsController.new
906
- controller.instance_variable_set('@display', :display)
907
- controller.instance_variable_set('@window', :window)
908
- controller.instance_variable_set('@button', :button)
909
-
910
- [:url, :path].each do |path_or_url|
911
- controller.expects("window_buttons_#{path_or_url}").with(:window, {}).once
912
- controller.send("collection_#{path_or_url}")
913
-
914
- controller.expects("button_#{path_or_url}").with(:button, {}).once
915
- controller.send("resource_#{path_or_url}")
916
-
917
- controller.expects("new_window_button_#{path_or_url}").with(:window, {}).once
918
- controller.send("new_resource_#{path_or_url}")
919
-
920
- controller.expects("edit_button_#{path_or_url}").with(:button, {}).once
921
- controller.send("edit_resource_#{path_or_url}")
922
-
923
- controller.expects("window_#{path_or_url}").with(:window, {}).once
924
- controller.send("parent_#{path_or_url}")
925
-
926
- controller.expects("edit_window_#{path_or_url}").with(:window, {}).once
927
- controller.send("edit_parent_#{path_or_url}")
928
- end
929
- end
930
-
931
- def test_url_helpers_with_custom_actions
932
- controller = ButtonsController.new
933
- controller.instance_variable_set('@display', :display)
934
- controller.instance_variable_set('@window', :window)
935
- controller.instance_variable_set('@button', :button)
936
- [:url, :path].each do |path_or_url|
937
- controller.expects("delete_button_#{path_or_url}").with(:button, {}).once
938
- controller.send("delete_resource_#{path_or_url}")
939
-
940
- controller.expects("search_window_buttons_#{path_or_url}").with(:window, {}).once
941
- controller.send("search_resources_#{path_or_url}")
942
- end
943
- end
944
-
945
- def test_helper_methods_with_custom_actions
946
- controller = ButtonsController.new
947
- helper_methods = controller.class._helpers.instance_methods.map {|m| m.to_s }
948
- [:url, :path].each do |path_or_url|
949
- assert helper_methods.include?("delete_resource_#{path_or_url}")
950
- assert helper_methods.include?("search_resources_#{path_or_url}")
951
- end
952
- end
953
-
954
- def test_helpers_on_inherited_controller
955
- controller = ImageButtonsController.new
956
- controller.expects("edit_image_button_path").once
957
- controller.send("edit_resource_path")
958
- controller.expects("delete_image_button_path").once
959
- controller.send("delete_resource_path")
960
- end
961
-
962
- def test_url_helpers_on_namespaced_resource_with_shallowed_route
963
- controller = Admin::MirrorsController.new
964
- controller.instance_variable_set('@house', :house)
965
- controller.instance_variable_set('@mirror', :mirror)
966
-
967
- [:url, :path].each do |path_or_url|
968
-
969
- controller.expects("admin_house_mirrors_#{path_or_url}").with(:house, {}).once
970
- controller.send("collection_#{path_or_url}")
971
-
972
- controller.expects("admin_mirror_#{path_or_url}").with(:mirror, {}).once
973
- controller.send("resource_#{path_or_url}")
974
-
975
- controller.expects("new_admin_house_mirror_#{path_or_url}").with(:house, {}).once
976
- controller.send("new_resource_#{path_or_url}")
977
-
978
- controller.expects("edit_admin_mirror_#{path_or_url}").with(:mirror, {}).once
979
- controller.send("edit_resource_#{path_or_url}")
980
-
981
- controller.expects("admin_house_#{path_or_url}").with(:house, {}).once
982
- controller.send("parent_#{path_or_url}")
983
-
984
- controller.expects("edit_admin_house_#{path_or_url}").with(:house, {}).once
985
- controller.send("edit_parent_#{path_or_url}")
986
- end
987
- end
988
- end