Class: UrlHelpersTest

Inherits:
ActiveSupport::TestCase
  • Object
show all
Defined in:
lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb

Overview

Create a TestHelper module with some helpers

Instance Method Summary collapse

Instance Method Details

#test_url_helpers_on_belongs_toObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 163

def test_url_helpers_on_belongs_to
  controller = TablesController.new
  controller.instance_variable_set('@house', :house)
  controller.instance_variable_set('@table', :table)

  [:url, :path].each do |path_or_url|
    controller.expects("house_tables_#{path_or_url}").with(:house, {}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_table_#{path_or_url}").with(:house, :table, {}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_table_#{path_or_url}").with(:house, {}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_table_#{path_or_url}").with(:house, :table, {}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("house_#{path_or_url}").with(:house, {}).once
    controller.send("parent_#{path_or_url}")

    # With arg
    controller.expects("house_table_#{path_or_url}").with(:house, :arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    controller.expects("edit_house_table_#{path_or_url}").with(:house, :arg, {}).once
    controller.send("edit_resource_#{path_or_url}", :arg)

    controller.expects("house_#{path_or_url}").with(:arg, {}).once
    controller.send("parent_#{path_or_url}", :arg)

    # With options
    controller.expects("house_table_#{path_or_url}").with(:house, :arg, :page => 1).once
    controller.send("resource_#{path_or_url}", :arg, :page => 1)
  end
end

#test_url_helpers_on_namespaced_polymorphic_belongs_toObject



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 354

def test_url_helpers_on_namespaced_polymorphic_belongs_to
  house = House.new
  desk  = Desk.new

  new_desk = Desk.new
  Desk.stubs(:new).returns(new_desk)
  new_desk.stubs(:new_record?).returns(true)

  controller = Admin::DesksController.new
  controller.instance_variable_set('@parent_type', :house)
  controller.instance_variable_set('@house', house)
  controller.instance_variable_set('@desk', desk)

  [:url, :path].each do |path_or_url|
    controller.expects("admin_house_desks_#{path_or_url}").with(house).once
    controller.send("collection_#{path_or_url}")

    controller.expects("admin_house_desk_#{path_or_url}").with(house, desk).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_admin_house_desk_#{path_or_url}").with(house).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_admin_house_desk_#{path_or_url}").with(house, desk).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("admin_house_#{path_or_url}").with(house).once
    controller.send("parent_#{path_or_url}")
  end

  # With options
  controller.expects("admin_house_desk_url").with(house, desk, :page => 1).once
  controller.send("resource_url", :page => 1)

  controller.expects("admin_house_url").with(house, :page => 1).once
  controller.send("parent_url", :page => 1)

  # With args
  controller.expects("polymorphic_url").with(['admin', :arg, new_desk], {}).once
  controller.send("collection_url", :arg)

  controller.expects("polymorphic_url").with(['admin', house, :arg], {}).once
  controller.send("resource_url", :arg)

  controller.expects("edit_polymorphic_url").with(['admin', house, :arg], {}).once
  controller.send("edit_resource_url", :arg)

  controller.expects("polymorphic_url").with(['admin', :arg], {}).once
  controller.send("parent_url", :arg)
end

#test_url_helpers_on_nested_belongs_toObject



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 237

def test_url_helpers_on_nested_belongs_to
  controller = ChairsController.new
  controller.instance_variable_set('@house', :house)
  controller.instance_variable_set('@table', :table)
  controller.instance_variable_set('@chair', :chair)

  [:url, :path].each do |path_or_url|
    controller.expects("house_table_chairs_#{path_or_url}").with(:house, :table, {}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :chair, {}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_table_chair_#{path_or_url}").with(:house, :table, {}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :chair, {}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("house_table_#{path_or_url}").with(:house, :table, {}).once
    controller.send("parent_#{path_or_url}")

    # With args
    controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg, {}).once
    controller.send("edit_resource_#{path_or_url}", :arg)

    controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    controller.expects("house_table_#{path_or_url}").with(:house, :arg, {}).once
    controller.send("parent_#{path_or_url}", :arg)

    # With options
    controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg, :page => 1).once
    controller.send("edit_resource_#{path_or_url}", :arg, :page => 1)
  end
end

#test_url_helpers_on_nested_polymorphic_belongs_toObject



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 405

def test_url_helpers_on_nested_polymorphic_belongs_to
  house = House.new
  table = Table.new
  dish  = Dish.new

  new_dish = Dish.new
  Dish.stubs(:new).returns(new_dish)
  new_dish.stubs(:new_record?).returns(true)

  controller = DishesController.new
  controller.instance_variable_set('@parent_type', :table)
  controller.instance_variable_set('@house', house)
  controller.instance_variable_set('@table', table)
  controller.instance_variable_set('@dish', dish)

  [:url, :path].each do |path_or_url|
    controller.expects("house_table_dishes_#{path_or_url}").with(house, table).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_table_dish_#{path_or_url}").with(house, table, dish).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_table_dish_#{path_or_url}").with(house, table).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_table_dish_#{path_or_url}").with(house, table, dish).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("house_table_#{path_or_url}").with(house, table).once
    controller.send("parent_#{path_or_url}")
  end

  # With options
  controller.expects("house_table_dish_url").with(house, table, dish, :page => 1).once
  controller.send("resource_url", :page => 1)

  controller.expects("house_table_url").with(house, table, :page => 1).once
  controller.send("parent_url", :page => 1)

  # With args
  controller.expects("polymorphic_url").with([house, table, :arg], {}).once
  controller.send("resource_url", :arg)

  controller.expects("edit_polymorphic_url").with([house, table, :arg], {}).once
  controller.send("edit_resource_url", :arg)

  controller.expects("polymorphic_url").with([house, :arg], {}).once
  controller.send("parent_url", :arg)
end

#test_url_helpers_on_not_default_belongs_toObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 200

def test_url_helpers_on_not_default_belongs_to
  controller = RoomsController.new
  controller.instance_variable_set('@house', :house)
  controller.instance_variable_set('@room', :room)

  [:url, :path].each do |path_or_url|
    controller.expects("big_house_rooms_#{path_or_url}").with(:house, {}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("big_house_room_#{path_or_url}").with(:house, :room, {}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_big_house_room_#{path_or_url}").with(:house, {}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :room, {}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("big_house_#{path_or_url}").with(:house, {}).once
    controller.send("parent_#{path_or_url}")

    # With args
    controller.expects("big_house_room_#{path_or_url}").with(:house, :arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :arg, {}).once
    controller.send("edit_resource_#{path_or_url}", :arg)

    controller.expects("big_house_#{path_or_url}").with(:arg, {}).once
    controller.send("parent_#{path_or_url}", :arg)

    # With options
    controller.expects("big_house_room_#{path_or_url}").with(:house, :arg, :page => 1).once
    controller.send("resource_#{path_or_url}", :arg, :page => 1)
  end
end

#test_url_helpers_on_optional_polymorphic_belongs_toObject



501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 501

def test_url_helpers_on_optional_polymorphic_belongs_to
  bed   = Bed.new
  new_bed = Bed.new
  Bed.stubs(:new).returns(new_bed)
  new_bed.stubs(:new_record?).returns(true)

  controller = BedsController.new
  controller.instance_variable_set('@parent_type', nil)
  controller.instance_variable_set('@bed', bed)

  [:url, :path].each do |path_or_url|
    controller.expects("beds_#{path_or_url}").with().once
    controller.send("collection_#{path_or_url}")

    controller.expects("bed_#{path_or_url}").with(bed).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_bed_#{path_or_url}").with().once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_bed_#{path_or_url}").with(bed).once
    controller.send("edit_resource_#{path_or_url}")
  end

  # With options
  controller.expects("bed_url").with(bed, :page => 1).once
  controller.send("resource_url", :page => 1)

  # With args
  controller.expects("polymorphic_url").with([:arg], {}).once
  controller.send("resource_url", :arg)

  controller.expects("edit_polymorphic_url").with([:arg], {}).once
  controller.send("edit_resource_url", :arg)
end

#test_url_helpers_on_polymorphic_belongs_toObject



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 303

def test_url_helpers_on_polymorphic_belongs_to
  house = House.new
  bed   = Bed.new
  
  new_bed = Bed.new
  Bed.stubs(:new).returns(new_bed)
  new_bed.stubs(:new_record?).returns(true)

  controller = BedsController.new
  controller.instance_variable_set('@parent_type', :house)
  controller.instance_variable_set('@house', house)
  controller.instance_variable_set('@bed', bed)

  [:url, :path].each do |path_or_url|
    controller.expects("house_beds_#{path_or_url}").with(house).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_bed_#{path_or_url}").with(house, bed).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_bed_#{path_or_url}").with(house).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_bed_#{path_or_url}").with(house, bed).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("house_#{path_or_url}").with(house).once
    controller.send("parent_#{path_or_url}")
  end

  # With options
  controller.expects("house_bed_url").with(house, bed, :page => 1).once
  controller.send("resource_url", :page => 1)

  controller.expects("house_url").with(house, :page => 1).once
  controller.send("parent_url", :page => 1)

  # With args
  controller.expects("polymorphic_url").with([:arg, new_bed], {}).once
  controller.send("collection_url", :arg)

  controller.expects("polymorphic_url").with([house, :arg], {}).once
  controller.send("resource_url", :arg)

  controller.expects("edit_polymorphic_url").with([house, :arg], {}).once
  controller.send("edit_resource_url", :arg)

  controller.expects("polymorphic_url").with([:arg], {}).once
  controller.send("parent_url", :arg)
end

#test_url_helpers_on_simple_inherited_namespaced_resourceObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 101

def test_url_helpers_on_simple_inherited_namespaced_resource
  controller = Admin::BackpacksController.new
  controller.instance_variable_set('@backpack', :backpack)

  assert_equal 'admin', controller.class.resources_configuration[:self][:route_prefix]

  [:url, :path].each do |path_or_url|
    controller.expects("admin_tour_backpacks_#{path_or_url}").with({}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("admin_backpack_#{path_or_url}").with(:backpack, {}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_admin_backpack_#{path_or_url}").with({}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_admin_backpack_#{path_or_url}").with(:backpack, {}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("admin_#{path_or_url}").with({}).once
    controller.send("parent_#{path_or_url}")

    # With arg
    controller.expects("admin_backpack_#{path_or_url}").with(:arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    controller.expects("admin_backpack_#{path_or_url}").with(:arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    # With options
    controller.expects("admin_backpack_#{path_or_url}").with(:arg, :page => 1).once
    controller.send("resource_#{path_or_url}", :arg, :page => 1)
  end
end

#test_url_helpers_on_simple_inherited_resourceObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 68

def test_url_helpers_on_simple_inherited_resource
  controller = HousesController.new
  controller.instance_variable_set('@house', :house)

  [:url, :path].each do |path_or_url|
    controller.expects("houses_#{path_or_url}").with({}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_#{path_or_url}").with(:house, {}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_#{path_or_url}").with({}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("root_#{path_or_url}").with({}).once
    controller.send("parent_#{path_or_url}")

    # With arg
    controller.expects("house_#{path_or_url}").with(:arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    controller.expects("house_#{path_or_url}").with(:arg, {}).once
    controller.send("resource_#{path_or_url}", :arg)

    # With options
    controller.expects("house_#{path_or_url}").with(:arg, :page => 1).once
    controller.send("resource_#{path_or_url}", :arg, :page => 1)
  end
end

#test_url_helpers_on_simple_inherited_singleton_resourceObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 136

def test_url_helpers_on_simple_inherited_singleton_resource
  controller = UniversesController.new
  controller.instance_variable_set('@universe', :universe)

  [:url, :path].each do |path_or_url|
    controller.expects("root_#{path_or_url}").with({}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("universum_#{path_or_url}").with({}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_universum_#{path_or_url}").with({}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_universum_#{path_or_url}").with({}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("root_#{path_or_url}").with({}).once
    controller.send("parent_#{path_or_url}")

    # With options
    # Also tests that argument sent are not used
    controller.expects("universum_#{path_or_url}").with(:page => 1).once
    controller.send("resource_#{path_or_url}", :arg, :page => 1)
  end
end

#test_url_helpers_on_singleton_nested_polymorphic_belongs_toObject



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 455

def test_url_helpers_on_singleton_nested_polymorphic_belongs_to
  # This must not be usefull in singleton controllers...
  # Center.new
  house = House.new
  table = Table.new

  controller = CentersController.new
  controller.instance_variable_set('@parent_type', :table)
  controller.instance_variable_set('@house', house)
  controller.instance_variable_set('@table', table)

  # This must not be useful in singleton controllers...
  # controller.instance_variable_set('@center', :center)

  [:url, :path].each do |path_or_url|
    controller.expects("house_table_#{path_or_url}").with(house, table).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_table_center_#{path_or_url}").with(house, table).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_table_center_#{path_or_url}").with(house, table).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_table_center_#{path_or_url}").with(house, table).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("house_table_#{path_or_url}").with(house, table).once
    controller.send("parent_#{path_or_url}")
  end

  # With options
  controller.expects("house_table_center_url").with(house, table, :page => 1)
  controller.send("resource_url", :page => 1)

  controller.expects("house_table_url").with(house, table, :page => 1)
  controller.send("parent_url", :page => 1)

  # With args
  controller.expects("polymorphic_url").with([house, table, :center], {}).once
  controller.send("resource_url", :arg)

  controller.expects("polymorphic_url").with([house, :arg], {}).once
  controller.send("parent_url", :arg)
end

#test_url_helpers_on_singletons_with_belongs_toObject



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb', line 275

def test_url_helpers_on_singletons_with_belongs_to
  controller = OwnersController.new
  controller.instance_variable_set('@house', :house)
  controller.instance_variable_set('@owner', :owner)

  [:url, :path].each do |path_or_url|
    controller.expects("house_#{path_or_url}").with(:house, {}).once
    controller.send("collection_#{path_or_url}")

    controller.expects("house_owner_#{path_or_url}").with(:house, {}).once
    controller.send("resource_#{path_or_url}")

    controller.expects("new_house_owner_#{path_or_url}").with(:house, {}).once
    controller.send("new_resource_#{path_or_url}")

    controller.expects("edit_house_owner_#{path_or_url}").with(:house, {}).once
    controller.send("edit_resource_#{path_or_url}")

    controller.expects("house_#{path_or_url}").with(:house, {}).once
    controller.send("parent_#{path_or_url}")

    # With options
    # Also tests that argument sent are not used
    controller.expects("house_owner_#{path_or_url}").with(:house, :page => 1).once
    controller.send("resource_#{path_or_url}", :arg, :page => 1)
  end
end