karsthammer-inherited_resources 1.1.2.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG +11 -0
  3. data/Gemfile +12 -0
  4. data/Gemfile.lock +86 -0
  5. data/README.rdoc +78 -50
  6. data/Rakefile +0 -22
  7. data/karsthammer-inherited_resources.gemspec +24 -0
  8. data/lib/inherited_resources/actions.rb +4 -4
  9. data/lib/inherited_resources/base.rb +11 -10
  10. data/lib/inherited_resources/base_helpers.rb +40 -3
  11. data/lib/inherited_resources/class_methods.rb +100 -9
  12. data/lib/inherited_resources/shallow_helpers.rb +87 -0
  13. data/lib/inherited_resources/url_helpers.rb +44 -4
  14. data/lib/inherited_resources/version.rb +1 -1
  15. data/lib/karsthammer-inherited_resources.rb +7 -2
  16. data/test/base_test.rb +33 -13
  17. data/test/belongs_to_test.rb +29 -4
  18. data/test/belongs_to_with_shallow_test.rb +93 -0
  19. data/test/class_methods_test.rb +13 -11
  20. data/test/customized_belongs_to_test.rb +1 -1
  21. data/test/customized_redirect_to_test.rb +32 -0
  22. data/test/defaults_test.rb +137 -10
  23. data/test/locales/en.yml +17 -0
  24. data/test/nested_belongs_to_with_shallow_test.rb +123 -0
  25. data/test/nested_model_with_shallow_test.rb +147 -0
  26. data/test/optional_belongs_to_test.rb +3 -3
  27. data/test/polymorphic_test.rb +4 -4
  28. data/test/singleton_test.rb +4 -1
  29. data/test/test_helper.rb +4 -3
  30. data/test/url_helpers_test.rb +146 -2
  31. data/test/views/cars/edit.html.erb +1 -0
  32. data/test/views/cars/index.html.erb +1 -0
  33. data/test/views/cars/new.html.erb +1 -0
  34. data/test/views/cars/show.html.erb +1 -0
  35. data/test/views/cities/edit.html.erb +1 -0
  36. data/test/views/cities/index.html.erb +1 -0
  37. data/test/views/cities/new.html.erb +1 -0
  38. data/test/views/cities/show.html.erb +1 -0
  39. data/test/views/comments/edit.html.erb +1 -0
  40. data/test/views/comments/index.html.erb +1 -0
  41. data/test/views/comments/new.html.erb +1 -0
  42. data/test/views/comments/show.html.erb +1 -0
  43. data/test/views/educations/new.html.erb +0 -0
  44. data/test/views/employees/edit.html.erb +1 -0
  45. data/test/views/employees/index.html.erb +1 -0
  46. data/test/views/employees/new.html.erb +1 -0
  47. data/test/views/employees/show.html.erb +1 -0
  48. data/test/views/groups/edit.html.erb +0 -0
  49. data/test/views/managers/edit.html.erb +1 -0
  50. data/test/views/managers/new.html.erb +1 -0
  51. data/test/views/managers/show.html.erb +1 -0
  52. data/test/views/painters/edit.html.erb +1 -0
  53. data/test/views/painters/index.html.erb +1 -0
  54. data/test/views/painters/new.html.erb +1 -0
  55. data/test/views/painters/show.html.erb +1 -0
  56. data/test/views/pets/edit.html.erb +1 -0
  57. data/test/views/pets/index.html.erb +1 -0
  58. data/test/views/pets/new.html.erb +1 -0
  59. data/test/views/pets/show.html.erb +1 -0
  60. data/test/views/plates/edit.html.erb +1 -0
  61. data/test/views/plates/index.html.erb +1 -0
  62. data/test/views/plates/new.html.erb +1 -0
  63. data/test/views/plates/show.html.erb +1 -0
  64. data/test/views/products/edit.html.erb +1 -0
  65. data/test/views/products/index.html.erb +1 -0
  66. data/test/views/products/new.html.erb +1 -0
  67. data/test/views/products/show.html.erb +1 -0
  68. data/test/views/professors/edit.html.erb +1 -0
  69. data/test/views/professors/index.html.erb +1 -0
  70. data/test/views/professors/new.html.erb +1 -0
  71. data/test/views/professors/show.html.erb +1 -0
  72. data/test/views/projects/index.html.erb +1 -0
  73. data/test/views/projects/index.json.erb +1 -0
  74. data/test/views/projects/respond_to_skip_default_template.html.erb +1 -0
  75. data/test/views/projects/respond_with_resource.html.erb +1 -0
  76. data/test/views/students/edit.html.erb +1 -0
  77. data/test/views/students/new.html.erb +1 -0
  78. data/test/views/tags/edit.html.erb +1 -0
  79. data/test/views/tags/index.html.erb +1 -0
  80. data/test/views/tags/new.html.erb +1 -0
  81. data/test/views/tags/show.html.erb +1 -0
  82. data/test/views/trees/edit.html.erb +1 -0
  83. data/test/views/trees/index.html.erb +1 -0
  84. data/test/views/trees/new.html.erb +1 -0
  85. data/test/views/trees/show.html.erb +1 -0
  86. data/test/views/university/professors/edit.html.erb +1 -0
  87. data/test/views/university/professors/index.html.erb +1 -0
  88. data/test/views/university/professors/new.html.erb +1 -0
  89. data/test/views/university/professors/show.html.erb +1 -0
  90. data/test/views/users/create.js.erb +1 -0
  91. data/test/views/users/destroy.js.erb +1 -0
  92. data/test/views/users/edit.html.erb +1 -0
  93. data/test/views/users/index.html.erb +1 -0
  94. data/test/views/users/new.html.erb +1 -0
  95. data/test/views/users/show.html.erb +1 -0
  96. data/test/views/users/update.js.erb +1 -0
  97. metadata +178 -29
@@ -0,0 +1,17 @@
1
+ en:
2
+ flash:
3
+ addresses:
4
+ create:
5
+ notice: "You created a new address close to <b>{{reference}}</b>."
6
+ update:
7
+ notice: "Nice! {{resource_name}} was updated with success!"
8
+ error: "Oh no! We could not update your address!"
9
+ admin:
10
+ actions:
11
+ create:
12
+ notice: "Admin notice message."
13
+ error: "Admin error message."
14
+ addresses:
15
+ create:
16
+ notice: "Admin, you created a new address close to <b>{{reference}}</b>."
17
+
@@ -0,0 +1,123 @@
1
+ require File.expand_path('test_helper', File.dirname(__FILE__))
2
+
3
+ class Dresser
4
+ end
5
+
6
+ class Shelf
7
+ end
8
+
9
+ class Plate
10
+ end
11
+
12
+ class PlatesController < InheritedResources::Base
13
+ belongs_to :dresser, :shelf, :shallow => true
14
+ end
15
+
16
+ class NestedBelongsToWithShallowTest < ActionController::TestCase
17
+ tests PlatesController
18
+
19
+ def setup
20
+ mock_shelf.expects(:dresser).returns(mock_dresser)
21
+ mock_dresser.expects(:to_param).returns('13')
22
+
23
+ Dresser.expects(:find).with('13').returns(mock_dresser)
24
+ mock_dresser.expects(:shelves).returns(Shelf)
25
+ mock_shelf.expects(:plates).returns(Plate)
26
+
27
+ @controller.stubs(:resource_url).returns('/')
28
+ @controller.stubs(:collection_url).returns('/')
29
+ end
30
+
31
+ def test_assigns_dresser_and_shelf_and_plate_on_index
32
+ Shelf.expects(:find).with('37').twice.returns(mock_shelf)
33
+ Plate.expects(:scoped).returns([mock_plate])
34
+ get :index, :shelf_id => '37'
35
+
36
+ assert_equal mock_dresser, assigns(:dresser)
37
+ assert_equal mock_shelf, assigns(:shelf)
38
+ assert_equal [mock_plate], assigns(:plates)
39
+ end
40
+
41
+ def test_assigns_dresser_and_shelf_and_plate_on_show
42
+ should_find_parents
43
+ get :show, :id => '42'
44
+
45
+ assert_equal mock_dresser, assigns(:dresser)
46
+ assert_equal mock_shelf, assigns(:shelf)
47
+ assert_equal mock_plate, assigns(:plate)
48
+ end
49
+
50
+ def test_assigns_dresser_and_shelf_and_plate_on_new
51
+ Plate.expects(:build).returns(mock_plate)
52
+ Shelf.expects(:find).with('37').twice.returns(mock_shelf)
53
+ get :new, :shelf_id => '37'
54
+
55
+ assert_equal mock_dresser, assigns(:dresser)
56
+ assert_equal mock_shelf, assigns(:shelf)
57
+ assert_equal mock_plate, assigns(:plate)
58
+ end
59
+
60
+ def test_assigns_dresser_and_shelf_and_plate_on_edit
61
+ should_find_parents
62
+ get :edit, :id => '42'
63
+
64
+ assert_equal mock_dresser, assigns(:dresser)
65
+ assert_equal mock_shelf, assigns(:shelf)
66
+ assert_equal mock_plate, assigns(:plate)
67
+ end
68
+
69
+
70
+ def test_assigns_dresser_and_shelf_and_plate_on_create
71
+ Shelf.expects(:find).with('37').twice.returns(mock_shelf)
72
+
73
+ Plate.expects(:build).with({'these' => 'params'}).returns(mock_plate)
74
+ mock_plate.expects(:save).returns(true)
75
+ post :create, :shelf_id => '37', :plate => {:these => 'params'}
76
+
77
+ assert_equal mock_dresser, assigns(:dresser)
78
+ assert_equal mock_shelf, assigns(:shelf)
79
+ assert_equal mock_plate, assigns(:plate)
80
+ end
81
+
82
+ def test_assigns_dresser_and_shelf_and_plate_on_update
83
+ should_find_parents
84
+ mock_plate.expects(:update_attributes).returns(true)
85
+ put :update, :id => '42', :plate => {:these => 'params'}
86
+
87
+ assert_equal mock_dresser, assigns(:dresser)
88
+ assert_equal mock_shelf, assigns(:shelf)
89
+ assert_equal mock_plate, assigns(:plate)
90
+ end
91
+
92
+ def test_assigns_dresser_and_shelf_and_plate_on_destroy
93
+ should_find_parents
94
+ mock_plate.expects(:destroy)
95
+ delete :destroy, :id => '42'
96
+
97
+ assert_equal mock_dresser, assigns(:dresser)
98
+ assert_equal mock_shelf, assigns(:shelf)
99
+ assert_equal mock_plate, assigns(:plate)
100
+ end
101
+
102
+
103
+ protected
104
+ def should_find_parents
105
+ Plate.expects(:find).with('42').returns(mock_plate)
106
+ mock_plate.expects(:shelf).returns(mock_shelf)
107
+ mock_shelf.expects(:to_param).returns('37')
108
+ Plate.expects(:find).with('42').returns(mock_plate)
109
+ Shelf.expects(:find).with('37').returns(mock_shelf)
110
+ end
111
+
112
+ def mock_dresser(stubs={})
113
+ @mock_dresser ||= mock(stubs)
114
+ end
115
+
116
+ def mock_shelf(stubs={})
117
+ @mock_shelf ||= mock(stubs)
118
+ end
119
+
120
+ def mock_plate(stubs={})
121
+ @mock_plate ||= mock(stubs)
122
+ end
123
+ end
@@ -0,0 +1,147 @@
1
+ require File.expand_path('test_helper', File.dirname(__FILE__))
2
+
3
+ class Subfaculty
4
+ end
5
+
6
+ class Speciality
7
+ end
8
+
9
+ module Plan
10
+ class Group
11
+ end
12
+
13
+ class Education
14
+ end
15
+ end
16
+
17
+ class GroupsController < InheritedResources::Base
18
+ defaults :resource_class => Plan::Group, :finder => :find_by_slug
19
+ belongs_to :subfaculty, :shallow => true do
20
+ belongs_to :speciality
21
+ end
22
+ end
23
+
24
+ class EducationsController < InheritedResources::Base
25
+ defaults :resource_class => Plan::Education
26
+ belongs_to :subfaculty, :shallow => true do
27
+ belongs_to :speciality do
28
+ belongs_to :group, :parent_class => Plan::Group,
29
+ :instance_name => :plan_group,
30
+ :param => :group_id,
31
+ :finder => :find_by_slug
32
+ end
33
+ end
34
+ end
35
+
36
+ class NestedModelWithShallowTest < ActionController::TestCase
37
+ tests GroupsController
38
+
39
+ def setup
40
+ mock_speciality.expects(:subfaculty).returns(mock_subfaculty)
41
+ mock_subfaculty.expects(:to_param).returns('13')
42
+
43
+ Subfaculty.expects(:find).with('13').returns(mock_subfaculty)
44
+ mock_subfaculty.expects(:specialities).returns(Speciality)
45
+ mock_speciality.expects(:groups).returns(Plan::Group)
46
+
47
+ @controller.stubs(:resource_url).returns('/')
48
+ @controller.stubs(:collection_url).returns('/')
49
+ end
50
+
51
+ def test_assigns_subfaculty_and_speciality_and_group_on_edit
52
+ should_find_parents
53
+ get :edit, :id => 'forty_two'
54
+
55
+ assert_equal mock_subfaculty, assigns(:subfaculty)
56
+ assert_equal mock_speciality, assigns(:speciality)
57
+ assert_equal mock_group, assigns(:group)
58
+ end
59
+
60
+ def test_expose_a_newly_create_group_with_speciality
61
+ Speciality.expects(:find).with('37').twice.returns(mock_speciality)
62
+ Plan::Group.expects(:build).with({'these' => :params}).returns(mock_group(:save => true))
63
+ post :create, :speciality_id => '37', :group => {:these => :params}
64
+ assert_equal mock_group, assigns(:group)
65
+ end
66
+
67
+ def test_expose_a_update_group_with_speciality
68
+ should_find_parents
69
+ mock_group.expects(:update_attributes).with('these' => :params).returns(true)
70
+ post :update, :id => 'forty_two', :group => {:these => :params}
71
+ assert_equal mock_group, assigns(:group)
72
+ end
73
+
74
+ protected
75
+ def should_find_parents
76
+ Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
77
+ mock_group.expects(:speciality).returns(mock_speciality)
78
+ mock_speciality.expects(:to_param).returns('37')
79
+ Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
80
+ Speciality.expects(:find).with('37').returns(mock_speciality)
81
+ end
82
+
83
+ def mock_group(stubs={})
84
+ @mock_group ||= mock(stubs)
85
+ end
86
+
87
+ def mock_speciality(stubs={})
88
+ @mock_speciality ||= mock(stubs)
89
+ end
90
+
91
+ def mock_subfaculty(stubs={})
92
+ @mock_subfaculty ||= mock(stubs)
93
+ end
94
+ end
95
+
96
+ class TwoNestedModelWithShallowTest < ActionController::TestCase
97
+ tests EducationsController
98
+
99
+ def setup
100
+ mock_speciality.expects(:subfaculty).returns(mock_subfaculty)
101
+ mock_subfaculty.expects(:to_param).returns('13')
102
+ Subfaculty.expects(:find).with('13').returns(mock_subfaculty)
103
+ mock_subfaculty.expects(:specialities).returns(Speciality)
104
+ mock_speciality.expects(:groups).returns(Plan::Group)
105
+
106
+ @controller.stubs(:resource_url).returns('/')
107
+ @controller.stubs(:collection_url).returns('/')
108
+ end
109
+
110
+ def test_assigns_subfaculty_and_speciality_and_group_on_new
111
+ should_find_parents
112
+ get :new, :group_id => 'forty_two'
113
+
114
+ assert_equal mock_subfaculty, assigns(:subfaculty)
115
+ assert_equal mock_speciality, assigns(:speciality)
116
+ assert_equal mock_group, assigns(:plan_group)
117
+ assert_equal mock_education, assigns(:education)
118
+ end
119
+
120
+
121
+ protected
122
+ def should_find_parents
123
+ Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
124
+ mock_group.expects(:speciality).returns(mock_speciality)
125
+ mock_group.expects(:educations).returns(mock_education)
126
+ mock_education.expects(:build).returns(mock_education)
127
+ mock_speciality.expects(:to_param).returns('37')
128
+ Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
129
+ Speciality.expects(:find).with('37').returns(mock_speciality)
130
+ end
131
+
132
+ def mock_group(stubs={})
133
+ @mock_group ||= mock(stubs)
134
+ end
135
+
136
+ def mock_education(stubs={})
137
+ @mock_education ||= mock(stubs)
138
+ end
139
+
140
+ def mock_speciality(stubs={})
141
+ @mock_speciality ||= mock(stubs)
142
+ end
143
+
144
+ def mock_subfaculty(stubs={})
145
+ @mock_subfaculty ||= mock(stubs)
146
+ end
147
+ end
@@ -22,14 +22,14 @@ class OptionalTest < ActionController::TestCase
22
22
  def test_expose_all_products_as_instance_variable_with_category
23
23
  Category.expects(:find).with('37').returns(mock_category)
24
24
  mock_category.expects(:products).returns(Product)
25
- Product.expects(:all).returns([mock_product])
25
+ Product.expects(:scoped).returns([mock_product])
26
26
  get :index, :category_id => '37'
27
27
  assert_equal mock_category, assigns(:category)
28
28
  assert_equal [mock_product], assigns(:products)
29
29
  end
30
30
 
31
31
  def test_expose_all_products_as_instance_variable_without_category
32
- Product.expects(:all).returns([mock_product])
32
+ Product.expects(:scoped).returns([mock_product])
33
33
  get :index
34
34
  assert_equal nil, assigns(:category)
35
35
  assert_equal [mock_product], assigns(:products)
@@ -142,7 +142,7 @@ class OptionalTest < ActionController::TestCase
142
142
  end
143
143
 
144
144
  def test_polymorphic_helpers
145
- Product.expects(:all).returns([mock_product])
145
+ Product.expects(:scoped).returns([mock_product])
146
146
  get :index
147
147
 
148
148
  assert !@controller.send(:parent?)
@@ -23,7 +23,7 @@ class PolymorphicFactoriesTest < ActionController::TestCase
23
23
  end
24
24
 
25
25
  def test_expose_all_employees_as_instance_variable_on_index
26
- Employee.expects(:all).returns([mock_employee])
26
+ Employee.expects(:scoped).returns([mock_employee])
27
27
  get :index, :factory_id => '37'
28
28
  assert_equal mock_factory, assigns(:factory)
29
29
  assert_equal [mock_employee], assigns(:employees)
@@ -77,7 +77,7 @@ class PolymorphicFactoriesTest < ActionController::TestCase
77
77
  def test_polymorphic_helpers
78
78
  mock_factory.stubs(:class).returns(Factory)
79
79
 
80
- Employee.expects(:all).returns([mock_employee])
80
+ Employee.expects(:scoped).returns([mock_employee])
81
81
  get :index, :factory_id => '37'
82
82
 
83
83
  assert @controller.send(:parent?)
@@ -110,7 +110,7 @@ class PolymorphicCompanyTest < ActionController::TestCase
110
110
  end
111
111
 
112
112
  def test_expose_all_employees_as_instance_variable_on_index
113
- Employee.expects(:all).returns([mock_employee])
113
+ Employee.expects(:scoped).returns([mock_employee])
114
114
  get :index, :company_id => '37'
115
115
  assert_equal mock_company, assigns(:company)
116
116
  assert_equal [mock_employee], assigns(:employees)
@@ -164,7 +164,7 @@ class PolymorphicCompanyTest < ActionController::TestCase
164
164
  def test_polymorphic_helpers
165
165
  mock_company.stubs(:class).returns(Company)
166
166
 
167
- Employee.expects(:all).returns([mock_employee])
167
+ Employee.expects(:scoped).returns([mock_employee])
168
168
  get :index, :company_id => '37'
169
169
 
170
170
  assert @controller.send(:parent?)
@@ -4,10 +4,12 @@ require File.expand_path('test_helper', File.dirname(__FILE__))
4
4
  # using a belongs_to association. This is done using mocks a la rspec.
5
5
  #
6
6
  class Store
7
+ extend ActiveModel::Naming
7
8
  end
8
9
 
9
10
  class Manager
10
- def self.human_name; 'Manager'; end
11
+ extend ActiveModel::Naming
12
+ # def self.human_name; 'Manager'; end
11
13
  end
12
14
 
13
15
  class ManagersController < InheritedResources::Base
@@ -66,6 +68,7 @@ class SingletonTest < ActionController::TestCase
66
68
  def test_the_requested_manager_is_destroyed_on_destroy
67
69
  Store.expects(:find).with('37').returns(mock_store)
68
70
  mock_store.expects(:manager).returns(mock_manager)
71
+ @controller.expects(:parent_url).returns('http://test.host/')
69
72
  mock_manager.expects(:destroy)
70
73
  delete :destroy, :store_id => '37'
71
74
  assert_equal mock_store, assigns(:store)
data/test/test_helper.rb CHANGED
@@ -26,9 +26,10 @@ require 'inherited_resources'
26
26
  ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
27
27
 
28
28
  InheritedResources::Routes = ActionDispatch::Routing::RouteSet.new
29
- InheritedResources::Routes.draw do |map|
30
- map.connect ':controller/:action/:id'
31
- map.connect ':controller/:action'
29
+ InheritedResources::Routes.draw do
30
+ match ':controller(/:action(/:id))'
31
+ match ':controller(/:action)'
32
+ resources 'posts'
32
33
  end
33
34
 
34
35
  ActionController::Base.send :include, InheritedResources::Routes.url_helpers
@@ -91,6 +91,38 @@ class CentersController < InheritedResources::Base
91
91
  end
92
92
  end
93
93
 
94
+ class Mirror
95
+ extend ActiveModel::Naming
96
+ end
97
+ class MirrorsController < InheritedResources::Base
98
+ belongs_to :house, :shallow => true
99
+ end
100
+ class Admin::MirrorsController < InheritedResources::Base
101
+ belongs_to :house, :shallow => true
102
+ end
103
+
104
+
105
+ class Display
106
+ extend ActiveModel::Naming
107
+ end
108
+
109
+ class Window
110
+ extend ActiveModel::Naming
111
+ end
112
+
113
+ class Button
114
+ extend ActiveModel::Naming
115
+ end
116
+
117
+ class ButtonsController < InheritedResources::Base
118
+ belongs_to :display, :window, :shallow => true
119
+ custom_actions :resource => :delete, :collection => :search
120
+ end
121
+
122
+ class ImageButtonsController < ButtonsController
123
+ end
124
+
125
+
94
126
  # Create a TestHelper module with some helpers
95
127
  class UrlHelpersTest < ActiveSupport::TestCase
96
128
 
@@ -365,7 +397,7 @@ class UrlHelpersTest < ActiveSupport::TestCase
365
397
  def test_url_helpers_on_polymorphic_belongs_to
366
398
  house = House.new
367
399
  bed = Bed.new
368
-
400
+
369
401
  new_bed = Bed.new
370
402
  Bed.stubs(:new).returns(new_bed)
371
403
  new_bed.stubs(:persisted?).returns(false)
@@ -419,7 +451,7 @@ class UrlHelpersTest < ActiveSupport::TestCase
419
451
  def test_url_helpers_on_polymorphic_belongs_to_using_uncountable
420
452
  sheep = Sheep.new
421
453
  news = News.new
422
-
454
+
423
455
  new_sheep = Sheep.new
424
456
  Sheep.stubs(:new).returns(new_sheep)
425
457
  new_sheep.stubs(:persisted?).returns(false)
@@ -662,4 +694,116 @@ class UrlHelpersTest < ActiveSupport::TestCase
662
694
  controller.send("edit_resource_url", :arg)
663
695
  end
664
696
 
697
+
698
+ def test_url_helpers_on_belongs_to_with_shallowed_route
699
+ controller = MirrorsController.new
700
+ controller.instance_variable_set('@house', :house)
701
+ controller.instance_variable_set('@mirror', :mirror)
702
+
703
+ [:url, :path].each do |path_or_url|
704
+
705
+ controller.expects("house_mirrors_#{path_or_url}").with(:house, {}).once
706
+ controller.send("collection_#{path_or_url}")
707
+
708
+ controller.expects("mirror_#{path_or_url}").with(:mirror, {}).once
709
+ controller.send("resource_#{path_or_url}")
710
+
711
+ controller.expects("new_house_mirror_#{path_or_url}").with(:house, {}).once
712
+ controller.send("new_resource_#{path_or_url}")
713
+
714
+ controller.expects("edit_mirror_#{path_or_url}").with(:mirror, {}).once
715
+ controller.send("edit_resource_#{path_or_url}")
716
+
717
+ controller.expects("house_#{path_or_url}").with(:house, {}).once
718
+ controller.send("parent_#{path_or_url}")
719
+
720
+ controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
721
+ controller.send("edit_parent_#{path_or_url}")
722
+ end
723
+ end
724
+
725
+ def test_url_helpers_on_nested_belongs_to_with_shallowed_route
726
+ controller = ButtonsController.new
727
+ controller.instance_variable_set('@display', :display)
728
+ controller.instance_variable_set('@window', :window)
729
+ controller.instance_variable_set('@button', :button)
730
+
731
+ [:url, :path].each do |path_or_url|
732
+ controller.expects("window_buttons_#{path_or_url}").with(:window, {}).once
733
+ controller.send("collection_#{path_or_url}")
734
+
735
+ controller.expects("button_#{path_or_url}").with(:button, {}).once
736
+ controller.send("resource_#{path_or_url}")
737
+
738
+ controller.expects("new_window_button_#{path_or_url}").with(:window, {}).once
739
+ controller.send("new_resource_#{path_or_url}")
740
+
741
+ controller.expects("edit_button_#{path_or_url}").with(:button, {}).once
742
+ controller.send("edit_resource_#{path_or_url}")
743
+
744
+ controller.expects("window_#{path_or_url}").with(:window, {}).once
745
+ controller.send("parent_#{path_or_url}")
746
+
747
+ controller.expects("edit_window_#{path_or_url}").with(:window, {}).once
748
+ controller.send("edit_parent_#{path_or_url}")
749
+ end
750
+ end
751
+
752
+ def test_url_helpers_with_custom_actions
753
+ controller = ButtonsController.new
754
+ controller.instance_variable_set('@display', :display)
755
+ controller.instance_variable_set('@window', :window)
756
+ controller.instance_variable_set('@button', :button)
757
+ [:url, :path].each do |path_or_url|
758
+ controller.expects("delete_button_#{path_or_url}").with(:button, {}).once
759
+ controller.send("delete_resource_#{path_or_url}")
760
+
761
+ controller.expects("search_window_buttons_#{path_or_url}").with(:window, {}).once
762
+ controller.send("search_resources_#{path_or_url}")
763
+ end
764
+ end
765
+
766
+ def test_helper_methods_with_custom_actions
767
+ controller = ButtonsController.new
768
+ helper_methods = controller.class._helpers.instance_methods.map {|m| m.to_s }
769
+ [:url, :path].each do |path_or_url|
770
+ assert helper_methods.include?("delete_resource_#{path_or_url}")
771
+ assert helper_methods.include?("search_resources_#{path_or_url}")
772
+ end
773
+ end
774
+
775
+ def test_helpers_on_inherited_controller
776
+ controller = ImageButtonsController.new
777
+ controller.expects("edit_image_button_path").once
778
+ controller.send("edit_resource_path")
779
+ controller.expects("delete_image_button_path").once
780
+ controller.send("delete_resource_path")
781
+ end
782
+
783
+ def test_url_helpers_on_namespaced_resource_with_shallowed_route
784
+ controller = Admin::MirrorsController.new
785
+ controller.instance_variable_set('@house', :house)
786
+ controller.instance_variable_set('@mirror', :mirror)
787
+
788
+ [:url, :path].each do |path_or_url|
789
+
790
+ controller.expects("admin_house_mirrors_#{path_or_url}").with(:house, {}).once
791
+ controller.send("collection_#{path_or_url}")
792
+
793
+ controller.expects("admin_mirror_#{path_or_url}").with(:mirror, {}).once
794
+ controller.send("resource_#{path_or_url}")
795
+
796
+ controller.expects("new_admin_house_mirror_#{path_or_url}").with(:house, {}).once
797
+ controller.send("new_resource_#{path_or_url}")
798
+
799
+ controller.expects("edit_admin_mirror_#{path_or_url}").with(:mirror, {}).once
800
+ controller.send("edit_resource_#{path_or_url}")
801
+
802
+ controller.expects("admin_house_#{path_or_url}").with(:house, {}).once
803
+ controller.send("parent_#{path_or_url}")
804
+
805
+ controller.expects("edit_admin_house_#{path_or_url}").with(:house, {}).once
806
+ controller.send("edit_parent_#{path_or_url}")
807
+ end
808
+ end
665
809
  end