base_rails_app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/LICENSE +1 -0
  2. data/README +1 -0
  3. data/lib/app/controllers/application_controller.rb +55 -0
  4. data/lib/app/controllers/password_resets_controller.rb +45 -0
  5. data/lib/app/controllers/user_sessions_controller.rb +25 -0
  6. data/lib/app/controllers/users_controller.rb +37 -0
  7. data/lib/app/helpers/application_helper.rb +4 -0
  8. data/lib/app/helpers/user_sessions_helper.rb +2 -0
  9. data/lib/app/helpers/users_helper.rb +2 -0
  10. data/lib/app/models/postman.rb +20 -0
  11. data/lib/app/models/user.rb +12 -0
  12. data/lib/app/models/user_session.rb +2 -0
  13. data/lib/app/views/application/404_not_found.html.erb +8 -0
  14. data/lib/app/views/layouts/application.html.erb +57 -0
  15. data/lib/app/views/password_resets/_sidebar.html.erb +0 -0
  16. data/lib/app/views/password_resets/edit.html.erb +33 -0
  17. data/lib/app/views/password_resets/new.html.erb +26 -0
  18. data/lib/app/views/postman/password_reset_instructions.html.erb +3 -0
  19. data/lib/app/views/postman/welcome_email.html.erb +3 -0
  20. data/lib/app/views/user_sessions/_form.html.erb +19 -0
  21. data/lib/app/views/user_sessions/_sidebar.html.erb +13 -0
  22. data/lib/app/views/user_sessions/new.html.erb +15 -0
  23. data/lib/app/views/users/_form.html.erb +28 -0
  24. data/lib/app/views/users/_sidebar.html.erb +6 -0
  25. data/lib/app/views/users/edit.html.erb +19 -0
  26. data/lib/app/views/users/new.html.erb +15 -0
  27. data/lib/app/views/users/show.html.erb +46 -0
  28. data/lib/base_rails_app.rb +5 -0
  29. data/lib/base_rails_app/boot.rb +2 -0
  30. data/lib/base_rails_app/tasks.rb +12 -0
  31. data/lib/config/configatron/cucumber.rb +0 -0
  32. data/lib/config/configatron/defaults.rb +4 -0
  33. data/lib/config/configatron/development.rb +1 -0
  34. data/lib/config/configatron/production.rb +0 -0
  35. data/lib/config/configatron/test.rb +0 -0
  36. data/lib/config/database.yml +25 -0
  37. data/lib/config/deploy.rb +15 -0
  38. data/lib/config/environments/cucumber.rb +22 -0
  39. data/lib/config/environments/development.rb +17 -0
  40. data/lib/config/environments/production.rb +28 -0
  41. data/lib/config/environments/test.rb +28 -0
  42. data/lib/config/gemtronics.rb +36 -0
  43. data/lib/config/initializers/backtrace_silencers.rb +7 -0
  44. data/lib/config/initializers/configatron.rb +1 -0
  45. data/lib/config/initializers/hoptoad.rb +3 -0
  46. data/lib/config/initializers/inflections.rb +10 -0
  47. data/lib/config/initializers/mailers.rb +1 -0
  48. data/lib/config/initializers/mime_types.rb +5 -0
  49. data/lib/config/initializers/new_rails_defaults.rb +21 -0
  50. data/lib/config/initializers/session_store.rb +17 -0
  51. data/lib/config/locales/en.yml +5 -0
  52. data/lib/config/routes.rb +51 -0
  53. data/lib/config/schedule.rb +20 -0
  54. data/lib/db/migrate/20090809175903_create_users.rb +30 -0
  55. data/lib/db/migrate/20090809204840_acts_as_taggable_on_migration.rb +29 -0
  56. data/lib/db/migrate/20090912171353_create_delayed_jobs.rb +20 -0
  57. data/lib/db/migrate/20090912171829_add_delayed_job_extras.rb +11 -0
  58. data/lib/db/migrate/20090929201455_add_more_time_columns_to_dj.rb +11 -0
  59. data/lib/db/schema.rb +72 -0
  60. data/lib/db/seeds.rb +7 -0
  61. data/lib/lib/tasks/cucumber.rake +36 -0
  62. data/lib/lib/tasks/rcov.rake +27 -0
  63. data/lib/lib/tasks/rspec.rake +183 -0
  64. data/lib/vendor/plugins/delayed_job/generators/delayed_job/delayed_job_generator.rb +22 -0
  65. data/lib/vendor/plugins/delayed_job/generators/delayed_job/templates/migration.rb +20 -0
  66. data/lib/vendor/plugins/delayed_job/init.rb +2 -0
  67. data/lib/vendor/plugins/delayed_job/lib/delayed/command.rb +65 -0
  68. data/lib/vendor/plugins/delayed_job/lib/delayed/job.rb +271 -0
  69. data/lib/vendor/plugins/delayed_job/lib/delayed/message_sending.rb +18 -0
  70. data/lib/vendor/plugins/delayed_job/lib/delayed/performable_method.rb +55 -0
  71. data/lib/vendor/plugins/delayed_job/lib/delayed/tasks.rb +15 -0
  72. data/lib/vendor/plugins/delayed_job/lib/delayed/worker.rb +54 -0
  73. data/lib/vendor/plugins/delayed_job/lib/delayed_job.rb +13 -0
  74. data/lib/vendor/plugins/delayed_job/recipes/delayed_job.rb +26 -0
  75. data/lib/vendor/plugins/delayed_job/tasks/jobs.rake +1 -0
  76. data/lib/vendor/plugins/hoptoad_notifier/install.rb +1 -0
  77. data/lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb +418 -0
  78. data/lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_tasks.rb +26 -0
  79. data/lib/vendor/plugins/hoptoad_notifier/recipes/hoptoad.rb +22 -0
  80. data/lib/vendor/plugins/hoptoad_notifier/tasks/hoptoad_notifier_tasks.rake +66 -0
  81. data/lib/vendor/plugins/inherited_resources/README.rdoc +524 -0
  82. data/lib/vendor/plugins/inherited_resources/inherited_resources.gemspec +71 -0
  83. data/lib/vendor/plugins/inherited_resources/init.rb +1 -0
  84. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources.rb +23 -0
  85. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb +79 -0
  86. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/base.rb +42 -0
  87. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/base_helpers.rb +363 -0
  88. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/belongs_to_helpers.rb +89 -0
  89. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/class_methods.rb +338 -0
  90. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/dsl.rb +26 -0
  91. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/dumb_responder.rb +20 -0
  92. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/has_scope_helpers.rb +83 -0
  93. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb +156 -0
  94. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/responder.rb +200 -0
  95. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/polymorphic_helpers.rb +155 -0
  96. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/singleton_helpers.rb +95 -0
  97. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/url_helpers.rb +179 -0
  98. data/lib/vendor/plugins/inherited_resources/test/aliases_test.rb +139 -0
  99. data/lib/vendor/plugins/inherited_resources/test/association_chain_test.rb +125 -0
  100. data/lib/vendor/plugins/inherited_resources/test/base_test.rb +225 -0
  101. data/lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb +87 -0
  102. data/lib/vendor/plugins/inherited_resources/test/class_methods_test.rb +138 -0
  103. data/lib/vendor/plugins/inherited_resources/test/customized_base_test.rb +162 -0
  104. data/lib/vendor/plugins/inherited_resources/test/customized_belongs_to_test.rb +76 -0
  105. data/lib/vendor/plugins/inherited_resources/test/defaults_test.rb +70 -0
  106. data/lib/vendor/plugins/inherited_resources/test/flash_test.rb +88 -0
  107. data/lib/vendor/plugins/inherited_resources/test/has_scope_test.rb +139 -0
  108. data/lib/vendor/plugins/inherited_resources/test/locales/en.yml +17 -0
  109. data/lib/vendor/plugins/inherited_resources/test/nested_belongs_to_test.rb +108 -0
  110. data/lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb +164 -0
  111. data/lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb +186 -0
  112. data/lib/vendor/plugins/inherited_resources/test/redirect_to_test.rb +51 -0
  113. data/lib/vendor/plugins/inherited_resources/test/respond_to_test.rb +155 -0
  114. data/lib/vendor/plugins/inherited_resources/test/singleton_test.rb +83 -0
  115. data/lib/vendor/plugins/inherited_resources/test/test_helper.rb +38 -0
  116. data/lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb +537 -0
  117. data/lib/vendor/plugins/inherited_resources/test/views/cars/edit.html.erb +1 -0
  118. data/lib/vendor/plugins/inherited_resources/test/views/cars/index.html.erb +1 -0
  119. data/lib/vendor/plugins/inherited_resources/test/views/cars/new.html.erb +1 -0
  120. data/lib/vendor/plugins/inherited_resources/test/views/cars/show.html.erb +1 -0
  121. data/lib/vendor/plugins/inherited_resources/test/views/cities/edit.html.erb +1 -0
  122. data/lib/vendor/plugins/inherited_resources/test/views/cities/index.html.erb +1 -0
  123. data/lib/vendor/plugins/inherited_resources/test/views/cities/new.html.erb +1 -0
  124. data/lib/vendor/plugins/inherited_resources/test/views/cities/show.html.erb +1 -0
  125. data/lib/vendor/plugins/inherited_resources/test/views/comments/edit.html.erb +1 -0
  126. data/lib/vendor/plugins/inherited_resources/test/views/comments/index.html.erb +1 -0
  127. data/lib/vendor/plugins/inherited_resources/test/views/comments/new.html.erb +1 -0
  128. data/lib/vendor/plugins/inherited_resources/test/views/comments/show.html.erb +1 -0
  129. data/lib/vendor/plugins/inherited_resources/test/views/employees/edit.html.erb +1 -0
  130. data/lib/vendor/plugins/inherited_resources/test/views/employees/index.html.erb +1 -0
  131. data/lib/vendor/plugins/inherited_resources/test/views/employees/new.html.erb +1 -0
  132. data/lib/vendor/plugins/inherited_resources/test/views/employees/show.html.erb +1 -0
  133. data/lib/vendor/plugins/inherited_resources/test/views/managers/edit.html.erb +1 -0
  134. data/lib/vendor/plugins/inherited_resources/test/views/managers/new.html.erb +1 -0
  135. data/lib/vendor/plugins/inherited_resources/test/views/managers/show.html.erb +1 -0
  136. data/lib/vendor/plugins/inherited_resources/test/views/painters/edit.html.erb +1 -0
  137. data/lib/vendor/plugins/inherited_resources/test/views/painters/index.html.erb +1 -0
  138. data/lib/vendor/plugins/inherited_resources/test/views/painters/new.html.erb +1 -0
  139. data/lib/vendor/plugins/inherited_resources/test/views/painters/show.html.erb +1 -0
  140. data/lib/vendor/plugins/inherited_resources/test/views/pets/edit.html.erb +1 -0
  141. data/lib/vendor/plugins/inherited_resources/test/views/pets/index.html.erb +1 -0
  142. data/lib/vendor/plugins/inherited_resources/test/views/pets/new.html.erb +1 -0
  143. data/lib/vendor/plugins/inherited_resources/test/views/pets/show.html.erb +1 -0
  144. data/lib/vendor/plugins/inherited_resources/test/views/products/edit.html.erb +1 -0
  145. data/lib/vendor/plugins/inherited_resources/test/views/products/index.html.erb +1 -0
  146. data/lib/vendor/plugins/inherited_resources/test/views/products/new.html.erb +1 -0
  147. data/lib/vendor/plugins/inherited_resources/test/views/products/show.html.erb +1 -0
  148. data/lib/vendor/plugins/inherited_resources/test/views/professors/edit.html.erb +1 -0
  149. data/lib/vendor/plugins/inherited_resources/test/views/professors/index.html.erb +1 -0
  150. data/lib/vendor/plugins/inherited_resources/test/views/professors/new.html.erb +1 -0
  151. data/lib/vendor/plugins/inherited_resources/test/views/professors/show.html.erb +1 -0
  152. data/lib/vendor/plugins/inherited_resources/test/views/projects/index.html.erb +1 -0
  153. data/lib/vendor/plugins/inherited_resources/test/views/projects/index.json.erb +1 -0
  154. data/lib/vendor/plugins/inherited_resources/test/views/projects/respond_to_skip_default_template.html.erb +1 -0
  155. data/lib/vendor/plugins/inherited_resources/test/views/projects/respond_with_resource.html.erb +1 -0
  156. data/lib/vendor/plugins/inherited_resources/test/views/students/edit.html.erb +1 -0
  157. data/lib/vendor/plugins/inherited_resources/test/views/students/new.html.erb +1 -0
  158. data/lib/vendor/plugins/inherited_resources/test/views/trees/edit.html.erb +1 -0
  159. data/lib/vendor/plugins/inherited_resources/test/views/trees/index.html.erb +1 -0
  160. data/lib/vendor/plugins/inherited_resources/test/views/trees/new.html.erb +1 -0
  161. data/lib/vendor/plugins/inherited_resources/test/views/trees/show.html.erb +1 -0
  162. data/lib/vendor/plugins/inherited_resources/test/views/users/edit.html.erb +1 -0
  163. data/lib/vendor/plugins/inherited_resources/test/views/users/index.html.erb +1 -0
  164. data/lib/vendor/plugins/inherited_resources/test/views/users/new.html.erb +1 -0
  165. data/lib/vendor/plugins/inherited_resources/test/views/users/show.html.erb +1 -0
  166. data/lib/vendor/plugins/web-app-theme/README.md +22 -0
  167. data/lib/vendor/plugins/web-app-theme/images/avatar.png +0 -0
  168. data/lib/vendor/plugins/web-app-theme/index.html +473 -0
  169. data/lib/vendor/plugins/web-app-theme/javascripts/jquery-1.3.min.js +19 -0
  170. data/lib/vendor/plugins/web-app-theme/javascripts/jquery.localscroll.js +104 -0
  171. data/lib/vendor/plugins/web-app-theme/javascripts/jquery.scrollTo.js +150 -0
  172. data/lib/vendor/plugins/web-app-theme/rails_generators/theme/templates/view_layout_administration.html.erb +48 -0
  173. data/lib/vendor/plugins/web-app-theme/rails_generators/theme/templates/view_layout_sign.html.erb +15 -0
  174. data/lib/vendor/plugins/web-app-theme/rails_generators/theme/theme_generator.rb +38 -0
  175. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_edit.html.erb +20 -0
  176. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_form.html.erb +10 -0
  177. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_new.html.erb +19 -0
  178. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_show.html.erb +23 -0
  179. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_sidebar.html.erb +13 -0
  180. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_signin.html.erb +39 -0
  181. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_signup.html.erb +56 -0
  182. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_tables.html.erb +50 -0
  183. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/themed_generator.rb +89 -0
  184. data/lib/vendor/plugins/web-app-theme/stylesheets/base.css +336 -0
  185. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/bec-green/style.css +290 -0
  186. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/bec/style.css +301 -0
  187. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/blue/style.css +280 -0
  188. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/default/style.css +267 -0
  189. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/djime-cerulean/style.css +298 -0
  190. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/drastic-dark/style.css +373 -0
  191. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/kathleene/style.css +272 -0
  192. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/orange/style.css +263 -0
  193. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/reidb-greenish/style.css +301 -0
  194. metadata +257 -0
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Machine;
4
+ def self.human_name; 'Machine'; end
5
+ end
6
+
7
+ class MachinesController < InheritedResources::Base
8
+ def create
9
+ create!{ complex_url(:create, true, true) }
10
+ end
11
+
12
+ def update
13
+ update!{ complex_url(:update, false, false) }
14
+ end
15
+
16
+ def destroy
17
+ destroy!{ complex_url(:destroy, true, false) }
18
+ end
19
+
20
+ protected
21
+ def complex_url(name, arg2, arg3)
22
+ 'http://test.host/' + name.to_s
23
+ end
24
+ end
25
+
26
+ class RedirectToWithBlockTest < ActionController::TestCase
27
+ tests MachinesController
28
+
29
+ def test_redirect_to_the_given_url_on_create
30
+ Machine.stubs(:new).returns(mock_machine(:save => true))
31
+ post :create
32
+ assert_redirected_to 'http://test.host/create'
33
+ end
34
+
35
+ def test_redirect_to_the_given_url_on_update
36
+ Machine.stubs(:find).returns(mock_machine(:update_attributes => true))
37
+ put :update
38
+ assert_redirected_to 'http://test.host/update'
39
+ end
40
+
41
+ def test_redirect_to_the_given_url_on_destroy
42
+ Machine.stubs(:find).returns(mock_machine(:destroy => true))
43
+ delete :destroy
44
+ assert_redirected_to 'http://test.host/destroy'
45
+ end
46
+
47
+ protected
48
+ def mock_machine(stubs={})
49
+ @mock_machine ||= mock(stubs)
50
+ end
51
+ end
@@ -0,0 +1,155 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Project
4
+ def to_html
5
+ 'Generated HTML'
6
+ end
7
+
8
+ def to_xml
9
+ 'Generated XML'
10
+ end
11
+
12
+ [:to_json, :to_rss, :to_rjs].each do |method|
13
+ undef_method method if respond_to? method
14
+ end
15
+ end
16
+
17
+ class ProjectsController < ActionController::Base
18
+ respond_to :html
19
+ respond_to :xml, :except => :edit
20
+ respond_to :rjs, :only => :edit
21
+ respond_to :rss, :only => :index
22
+ respond_to :json, :except => :index
23
+ respond_to :csv, :except => :index
24
+
25
+ def index
26
+ respond_with(Project.new)
27
+ end
28
+
29
+ def respond_with_resource
30
+ respond_with(Project.new)
31
+ end
32
+
33
+ def respond_with_resource_and_options
34
+ respond_with(Project.new, :location => 'http://test.host/')
35
+ end
36
+
37
+ def respond_with_resource_and_blocks
38
+ respond_with(Project.new) do |format|
39
+ format.json { render :text => 'Render JSON' }
40
+ format.rss { render :text => 'Render RSS' }
41
+ end
42
+ end
43
+
44
+ # If the user request Mime::ALL and we have a template called action.html.erb,
45
+ # the html template should be rendered *unless* html is specified inside the
46
+ # block. This tests exactly this case.
47
+ #
48
+ def respond_to_skip_default_template
49
+ respond_with(Project.new) do |format|
50
+ format.html { render :text => 'Render HTML' }
51
+ end
52
+ end
53
+ end
54
+
55
+ class SuperProjectsController < ProjectsController
56
+ end
57
+
58
+ class RespondToFunctionalTest < ActionController::TestCase
59
+ tests ProjectsController
60
+
61
+ def test_respond_with_layout_rendering
62
+ @request.accept = 'text/html'
63
+ get :index
64
+ assert_equal 'Index HTML', @response.body.strip
65
+ end
66
+
67
+ def test_respond_with_calls_to_format_on_resource
68
+ @request.accept = 'application/xml'
69
+ get :index
70
+ assert_equal 'Generated XML', @response.body.strip
71
+ end
72
+
73
+ def test_respond_with_inherits_format
74
+ @request.accept = 'application/xml'
75
+ get :index
76
+ assert_equal 'Generated XML', @response.body.strip
77
+ end
78
+
79
+ def test_respond_with_renders_status_not_acceptable_if_mime_type_is_not_registered
80
+ @request.accept = 'text/csv'
81
+ get :index
82
+ assert_equal '406 Not Acceptable', @response.status
83
+ end
84
+
85
+ def test_respond_with_raises_error_if_could_not_respond
86
+ @request.accept = 'application/rss+xml'
87
+ assert_raise ActionView::MissingTemplate do
88
+ get :index
89
+ end
90
+ end
91
+
92
+ def test_respond_to_all
93
+ @request.accept = '*/*'
94
+ get :index
95
+ assert_equal 'Index HTML', @response.body.strip
96
+ end
97
+
98
+ def test_respond_with_sets_content_type_properly
99
+ @request.accept = 'text/html'
100
+ get :index
101
+ assert_equal 'text/html', @response.content_type
102
+ assert_equal :html, @response.template.template_format
103
+
104
+ @request.accept = 'application/xml'
105
+ get :index
106
+ assert_equal 'application/xml', @response.content_type
107
+ assert_equal :xml, @response.template.template_format
108
+ end
109
+
110
+ def test_respond_with_forwads_extra_options_to_render
111
+ @request.accept = 'application/xml'
112
+ get :respond_with_resource_and_options
113
+ assert_equal 'Generated XML', @response.body.strip
114
+ assert_equal 'http://test.host/', @response.headers['Location']
115
+ end
116
+
117
+ def test_respond_to_when_a_resource_is_given_as_option
118
+ @request.accept = 'text/html'
119
+ get :respond_with_resource
120
+ assert_equal 'RespondTo HTML', @response.body.strip
121
+
122
+ @request.accept = 'application/xml'
123
+ get :respond_with_resource
124
+ assert_equal 'Generated XML', @response.body.strip
125
+
126
+ @request.accept = 'application/rss+xml'
127
+ get :respond_with_resource
128
+ assert_equal '406 Not Acceptable', @response.status
129
+
130
+ @request.accept = 'application/json'
131
+ assert_raise ActionView::MissingTemplate do
132
+ get :respond_with_resource
133
+ end
134
+ end
135
+
136
+ def test_respond_to_overwrite_class_method_definition
137
+ @request.accept = 'application/rss+xml'
138
+ get :respond_with_resource_and_blocks
139
+ assert_equal 'Render RSS', @response.body.strip
140
+ end
141
+
142
+ def test_respond_to_first_configured_mime_in_respond_to_when_mime_type_is_all
143
+ @request.accept = '*/*'
144
+ assert_raise ActionView::MissingTemplate do
145
+ get :respond_with_resource_and_blocks
146
+ end
147
+ assert_equal 'text/html', @response.content_type
148
+ end
149
+
150
+ def test_respond_to_skip_default_template_when_it_is_in_block
151
+ @request.accept = '*/*'
152
+ get :respond_to_skip_default_template
153
+ assert_equal 'Render HTML', @response.body.strip
154
+ end
155
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ # This test file is instead to test the how controller flow and actions
4
+ # using a belongs_to association. This is done using mocks a la rspec.
5
+ #
6
+ class Store
7
+ end
8
+
9
+ class Manager
10
+ def self.human_name; 'Manager'; end
11
+ end
12
+
13
+ class ManagersController < InheritedResources::Base
14
+ belongs_to :store, :singleton => true
15
+ end
16
+
17
+ class SingletonTest < ActionController::TestCase
18
+ tests ManagersController
19
+
20
+ def setup
21
+ @controller.stubs(:resource_url).returns('/')
22
+ @controller.stubs(:collection_url).returns('/')
23
+ end
24
+
25
+ def test_expose_the_resquested_manager_on_show
26
+ Store.expects(:find).with('37').returns(mock_store)
27
+ mock_store.expects(:manager).returns(mock_manager)
28
+ get :show, :store_id => '37'
29
+ assert_equal mock_store, assigns(:store)
30
+ assert_equal mock_manager, assigns(:manager)
31
+ end
32
+
33
+ def test_expose_a_new_manager_on_new
34
+ Store.expects(:find).with('37').returns(mock_store)
35
+ mock_store.expects(:build_manager).returns(mock_manager)
36
+ get :new, :store_id => '37'
37
+ assert_equal mock_store, assigns(:store)
38
+ assert_equal mock_manager, assigns(:manager)
39
+ end
40
+
41
+ def test_expose_the_resquested_manager_on_edit
42
+ Store.expects(:find).with('37').returns(mock_store)
43
+ mock_store.expects(:manager).returns(mock_manager)
44
+ get :edit, :store_id => '37'
45
+ assert_equal mock_store, assigns(:store)
46
+ assert_equal mock_manager, assigns(:manager)
47
+ assert_response :success
48
+ end
49
+
50
+ def test_expose_a_newly_create_manager_on_create
51
+ Store.expects(:find).with('37').returns(mock_store)
52
+ mock_store.expects(:build_manager).with({'these' => 'params'}).returns(mock_manager(:save => true))
53
+ post :create, :store_id => '37', :manager => {:these => 'params'}
54
+ assert_equal mock_store, assigns(:store)
55
+ assert_equal mock_manager, assigns(:manager)
56
+ end
57
+
58
+ def test_update_the_requested_object_on_update
59
+ Store.expects(:find).with('37').returns(mock_store(:manager => mock_manager))
60
+ mock_manager.expects(:update_attributes).with({'these' => 'params'}).returns(true)
61
+ put :update, :store_id => '37', :manager => {:these => 'params'}
62
+ assert_equal mock_store, assigns(:store)
63
+ assert_equal mock_manager, assigns(:manager)
64
+ end
65
+
66
+ def test_the_resquested_manager_is_destroyed_on_destroy
67
+ Store.expects(:find).with('37').returns(mock_store)
68
+ mock_store.expects(:manager).returns(mock_manager)
69
+ mock_manager.expects(:destroy)
70
+ delete :destroy, :store_id => '37'
71
+ assert_equal mock_store, assigns(:store)
72
+ assert_equal mock_manager, assigns(:manager)
73
+ end
74
+
75
+ protected
76
+ def mock_store(stubs={})
77
+ @mock_store ||= mock(stubs)
78
+ end
79
+
80
+ def mock_manager(stubs={})
81
+ @mock_manager ||= mock(stubs)
82
+ end
83
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ gem "test-unit"
5
+ rescue LoadError
6
+ end
7
+
8
+ begin
9
+ gem "ruby-debug"
10
+ require 'ruby-debug'
11
+ rescue LoadError
12
+ end
13
+
14
+ require 'test/unit'
15
+ require 'mocha'
16
+
17
+ ENV["RAILS_ENV"] = "test"
18
+ RAILS_ROOT = "anywhere"
19
+
20
+ require 'active_support'
21
+ require 'action_controller'
22
+ require 'action_controller/test_case'
23
+ require 'action_controller/test_process'
24
+
25
+ I18n.load_path << File.join(File.dirname(__FILE__), 'locales', 'en.yml')
26
+ I18n.reload!
27
+
28
+ class ApplicationController < ActionController::Base; end
29
+
30
+ # Add IR to load path and load the main file
31
+ ActiveSupport::Dependencies.load_paths << File.expand_path(File.dirname(__FILE__) + '/../lib')
32
+ require_dependency 'inherited_resources'
33
+
34
+ ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
35
+
36
+ ActionController::Routing::Routes.draw do |map|
37
+ map.connect ':controller/:action/:id'
38
+ end
@@ -0,0 +1,537 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Universe; end
4
+ class UniversesController < InheritedResources::Base
5
+ defaults :singleton => true, :route_instance_name => 'universum'
6
+ end
7
+
8
+ class House; end
9
+ class HousesController < InheritedResources::Base
10
+ end
11
+
12
+ class Backpack; end
13
+ module Admin; end
14
+ class Admin::BackpacksController < InheritedResources::Base
15
+ defaults :route_collection_name => 'tour_backpacks'
16
+ end
17
+
18
+ class Table; end
19
+ class TablesController < InheritedResources::Base
20
+ belongs_to :house
21
+ end
22
+
23
+ class RoomsController < InheritedResources::Base
24
+ belongs_to :house, :route_name => 'big_house'
25
+ end
26
+
27
+ class ChairsController < InheritedResources::Base
28
+ belongs_to :house do
29
+ belongs_to :table
30
+ end
31
+ end
32
+
33
+ class OwnersController < InheritedResources::Base
34
+ singleton_belongs_to :house
35
+ end
36
+
37
+ class Bed; end
38
+ class BedsController < InheritedResources::Base
39
+ optional_belongs_to :house, :building
40
+ end
41
+
42
+ class Desk; end
43
+ module Admin
44
+ class DesksController < InheritedResources::Base
45
+ optional_belongs_to :house
46
+ end
47
+ end
48
+
49
+ class Dish; end
50
+ class DishesController < InheritedResources::Base
51
+ belongs_to :house do
52
+ polymorphic_belongs_to :table, :kitchen
53
+ end
54
+ end
55
+
56
+ class Center; end
57
+ class CentersController < InheritedResources::Base
58
+ acts_as_singleton!
59
+
60
+ belongs_to :house do
61
+ belongs_to :table, :kitchen, :polymorphic => true
62
+ end
63
+ end
64
+
65
+ # Create a TestHelper module with some helpers
66
+ class UrlHelpersTest < ActiveSupport::TestCase
67
+
68
+ def test_url_helpers_on_simple_inherited_resource
69
+ controller = HousesController.new
70
+ controller.instance_variable_set('@house', :house)
71
+
72
+ [:url, :path].each do |path_or_url|
73
+ controller.expects("houses_#{path_or_url}").with({}).once
74
+ controller.send("collection_#{path_or_url}")
75
+
76
+ controller.expects("house_#{path_or_url}").with(:house, {}).once
77
+ controller.send("resource_#{path_or_url}")
78
+
79
+ controller.expects("new_house_#{path_or_url}").with({}).once
80
+ controller.send("new_resource_#{path_or_url}")
81
+
82
+ controller.expects("edit_house_#{path_or_url}").with(:house, {}).once
83
+ controller.send("edit_resource_#{path_or_url}")
84
+
85
+ controller.expects("root_#{path_or_url}").with({}).once
86
+ controller.send("parent_#{path_or_url}")
87
+
88
+ # With arg
89
+ controller.expects("house_#{path_or_url}").with(:arg, {}).once
90
+ controller.send("resource_#{path_or_url}", :arg)
91
+
92
+ controller.expects("house_#{path_or_url}").with(:arg, {}).once
93
+ controller.send("resource_#{path_or_url}", :arg)
94
+
95
+ # With options
96
+ controller.expects("house_#{path_or_url}").with(:arg, :page => 1).once
97
+ controller.send("resource_#{path_or_url}", :arg, :page => 1)
98
+ end
99
+ end
100
+
101
+ def test_url_helpers_on_simple_inherited_namespaced_resource
102
+ controller = Admin::BackpacksController.new
103
+ controller.instance_variable_set('@backpack', :backpack)
104
+
105
+ assert_equal 'admin', controller.class.resources_configuration[:self][:route_prefix]
106
+
107
+ [:url, :path].each do |path_or_url|
108
+ controller.expects("admin_tour_backpacks_#{path_or_url}").with({}).once
109
+ controller.send("collection_#{path_or_url}")
110
+
111
+ controller.expects("admin_backpack_#{path_or_url}").with(:backpack, {}).once
112
+ controller.send("resource_#{path_or_url}")
113
+
114
+ controller.expects("new_admin_backpack_#{path_or_url}").with({}).once
115
+ controller.send("new_resource_#{path_or_url}")
116
+
117
+ controller.expects("edit_admin_backpack_#{path_or_url}").with(:backpack, {}).once
118
+ controller.send("edit_resource_#{path_or_url}")
119
+
120
+ controller.expects("admin_#{path_or_url}").with({}).once
121
+ controller.send("parent_#{path_or_url}")
122
+
123
+ # With arg
124
+ controller.expects("admin_backpack_#{path_or_url}").with(:arg, {}).once
125
+ controller.send("resource_#{path_or_url}", :arg)
126
+
127
+ controller.expects("admin_backpack_#{path_or_url}").with(:arg, {}).once
128
+ controller.send("resource_#{path_or_url}", :arg)
129
+
130
+ # With options
131
+ controller.expects("admin_backpack_#{path_or_url}").with(:arg, :page => 1).once
132
+ controller.send("resource_#{path_or_url}", :arg, :page => 1)
133
+ end
134
+ end
135
+
136
+ def test_url_helpers_on_simple_inherited_singleton_resource
137
+ controller = UniversesController.new
138
+ controller.instance_variable_set('@universe', :universe)
139
+
140
+ [:url, :path].each do |path_or_url|
141
+ controller.expects("root_#{path_or_url}").with({}).once
142
+ controller.send("collection_#{path_or_url}")
143
+
144
+ controller.expects("universum_#{path_or_url}").with({}).once
145
+ controller.send("resource_#{path_or_url}")
146
+
147
+ controller.expects("new_universum_#{path_or_url}").with({}).once
148
+ controller.send("new_resource_#{path_or_url}")
149
+
150
+ controller.expects("edit_universum_#{path_or_url}").with({}).once
151
+ controller.send("edit_resource_#{path_or_url}")
152
+
153
+ controller.expects("root_#{path_or_url}").with({}).once
154
+ controller.send("parent_#{path_or_url}")
155
+
156
+ # With options
157
+ # Also tests that argument sent are not used
158
+ controller.expects("universum_#{path_or_url}").with(:page => 1).once
159
+ controller.send("resource_#{path_or_url}", :arg, :page => 1)
160
+ end
161
+ end
162
+
163
+ def test_url_helpers_on_belongs_to
164
+ controller = TablesController.new
165
+ controller.instance_variable_set('@house', :house)
166
+ controller.instance_variable_set('@table', :table)
167
+
168
+ [:url, :path].each do |path_or_url|
169
+ controller.expects("house_tables_#{path_or_url}").with(:house, {}).once
170
+ controller.send("collection_#{path_or_url}")
171
+
172
+ controller.expects("house_table_#{path_or_url}").with(:house, :table, {}).once
173
+ controller.send("resource_#{path_or_url}")
174
+
175
+ controller.expects("new_house_table_#{path_or_url}").with(:house, {}).once
176
+ controller.send("new_resource_#{path_or_url}")
177
+
178
+ controller.expects("edit_house_table_#{path_or_url}").with(:house, :table, {}).once
179
+ controller.send("edit_resource_#{path_or_url}")
180
+
181
+ controller.expects("house_#{path_or_url}").with(:house, {}).once
182
+ controller.send("parent_#{path_or_url}")
183
+
184
+ # With arg
185
+ controller.expects("house_table_#{path_or_url}").with(:house, :arg, {}).once
186
+ controller.send("resource_#{path_or_url}", :arg)
187
+
188
+ controller.expects("edit_house_table_#{path_or_url}").with(:house, :arg, {}).once
189
+ controller.send("edit_resource_#{path_or_url}", :arg)
190
+
191
+ controller.expects("house_#{path_or_url}").with(:arg, {}).once
192
+ controller.send("parent_#{path_or_url}", :arg)
193
+
194
+ # With options
195
+ controller.expects("house_table_#{path_or_url}").with(:house, :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_not_default_belongs_to
201
+ controller = RoomsController.new
202
+ controller.instance_variable_set('@house', :house)
203
+ controller.instance_variable_set('@room', :room)
204
+
205
+ [:url, :path].each do |path_or_url|
206
+ controller.expects("big_house_rooms_#{path_or_url}").with(:house, {}).once
207
+ controller.send("collection_#{path_or_url}")
208
+
209
+ controller.expects("big_house_room_#{path_or_url}").with(:house, :room, {}).once
210
+ controller.send("resource_#{path_or_url}")
211
+
212
+ controller.expects("new_big_house_room_#{path_or_url}").with(:house, {}).once
213
+ controller.send("new_resource_#{path_or_url}")
214
+
215
+ controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :room, {}).once
216
+ controller.send("edit_resource_#{path_or_url}")
217
+
218
+ controller.expects("big_house_#{path_or_url}").with(:house, {}).once
219
+ controller.send("parent_#{path_or_url}")
220
+
221
+ # With args
222
+ controller.expects("big_house_room_#{path_or_url}").with(:house, :arg, {}).once
223
+ controller.send("resource_#{path_or_url}", :arg)
224
+
225
+ controller.expects("edit_big_house_room_#{path_or_url}").with(:house, :arg, {}).once
226
+ controller.send("edit_resource_#{path_or_url}", :arg)
227
+
228
+ controller.expects("big_house_#{path_or_url}").with(:arg, {}).once
229
+ controller.send("parent_#{path_or_url}", :arg)
230
+
231
+ # With options
232
+ controller.expects("big_house_room_#{path_or_url}").with(:house, :arg, :page => 1).once
233
+ controller.send("resource_#{path_or_url}", :arg, :page => 1)
234
+ end
235
+ end
236
+
237
+ def test_url_helpers_on_nested_belongs_to
238
+ controller = ChairsController.new
239
+ controller.instance_variable_set('@house', :house)
240
+ controller.instance_variable_set('@table', :table)
241
+ controller.instance_variable_set('@chair', :chair)
242
+
243
+ [:url, :path].each do |path_or_url|
244
+ controller.expects("house_table_chairs_#{path_or_url}").with(:house, :table, {}).once
245
+ controller.send("collection_#{path_or_url}")
246
+
247
+ controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :chair, {}).once
248
+ controller.send("resource_#{path_or_url}")
249
+
250
+ controller.expects("new_house_table_chair_#{path_or_url}").with(:house, :table, {}).once
251
+ controller.send("new_resource_#{path_or_url}")
252
+
253
+ controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :chair, {}).once
254
+ controller.send("edit_resource_#{path_or_url}")
255
+
256
+ controller.expects("house_table_#{path_or_url}").with(:house, :table, {}).once
257
+ controller.send("parent_#{path_or_url}")
258
+
259
+ # With args
260
+ controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg, {}).once
261
+ controller.send("edit_resource_#{path_or_url}", :arg)
262
+
263
+ controller.expects("house_table_chair_#{path_or_url}").with(:house, :table, :arg, {}).once
264
+ controller.send("resource_#{path_or_url}", :arg)
265
+
266
+ controller.expects("house_table_#{path_or_url}").with(:house, :arg, {}).once
267
+ controller.send("parent_#{path_or_url}", :arg)
268
+
269
+ # With options
270
+ controller.expects("edit_house_table_chair_#{path_or_url}").with(:house, :table, :arg, :page => 1).once
271
+ controller.send("edit_resource_#{path_or_url}", :arg, :page => 1)
272
+ end
273
+ end
274
+
275
+ def test_url_helpers_on_singletons_with_belongs_to
276
+ controller = OwnersController.new
277
+ controller.instance_variable_set('@house', :house)
278
+ controller.instance_variable_set('@owner', :owner)
279
+
280
+ [:url, :path].each do |path_or_url|
281
+ controller.expects("house_#{path_or_url}").with(:house, {}).once
282
+ controller.send("collection_#{path_or_url}")
283
+
284
+ controller.expects("house_owner_#{path_or_url}").with(:house, {}).once
285
+ controller.send("resource_#{path_or_url}")
286
+
287
+ controller.expects("new_house_owner_#{path_or_url}").with(:house, {}).once
288
+ controller.send("new_resource_#{path_or_url}")
289
+
290
+ controller.expects("edit_house_owner_#{path_or_url}").with(:house, {}).once
291
+ controller.send("edit_resource_#{path_or_url}")
292
+
293
+ controller.expects("house_#{path_or_url}").with(:house, {}).once
294
+ controller.send("parent_#{path_or_url}")
295
+
296
+ # With options
297
+ # Also tests that argument sent are not used
298
+ controller.expects("house_owner_#{path_or_url}").with(:house, :page => 1).once
299
+ controller.send("resource_#{path_or_url}", :arg, :page => 1)
300
+ end
301
+ end
302
+
303
+ def test_url_helpers_on_polymorphic_belongs_to
304
+ house = House.new
305
+ bed = Bed.new
306
+
307
+ new_bed = Bed.new
308
+ Bed.stubs(:new).returns(new_bed)
309
+ new_bed.stubs(:new_record?).returns(true)
310
+
311
+ controller = BedsController.new
312
+ controller.instance_variable_set('@parent_type', :house)
313
+ controller.instance_variable_set('@house', house)
314
+ controller.instance_variable_set('@bed', bed)
315
+
316
+ [:url, :path].each do |path_or_url|
317
+ controller.expects("house_beds_#{path_or_url}").with(house).once
318
+ controller.send("collection_#{path_or_url}")
319
+
320
+ controller.expects("house_bed_#{path_or_url}").with(house, bed).once
321
+ controller.send("resource_#{path_or_url}")
322
+
323
+ controller.expects("new_house_bed_#{path_or_url}").with(house).once
324
+ controller.send("new_resource_#{path_or_url}")
325
+
326
+ controller.expects("edit_house_bed_#{path_or_url}").with(house, bed).once
327
+ controller.send("edit_resource_#{path_or_url}")
328
+
329
+ controller.expects("house_#{path_or_url}").with(house).once
330
+ controller.send("parent_#{path_or_url}")
331
+ end
332
+
333
+ # With options
334
+ controller.expects("house_bed_url").with(house, bed, :page => 1).once
335
+ controller.send("resource_url", :page => 1)
336
+
337
+ controller.expects("house_url").with(house, :page => 1).once
338
+ controller.send("parent_url", :page => 1)
339
+
340
+ # With args
341
+ controller.expects("polymorphic_url").with([:arg, new_bed], {}).once
342
+ controller.send("collection_url", :arg)
343
+
344
+ controller.expects("polymorphic_url").with([house, :arg], {}).once
345
+ controller.send("resource_url", :arg)
346
+
347
+ controller.expects("edit_polymorphic_url").with([house, :arg], {}).once
348
+ controller.send("edit_resource_url", :arg)
349
+
350
+ controller.expects("polymorphic_url").with([:arg], {}).once
351
+ controller.send("parent_url", :arg)
352
+ end
353
+
354
+ def test_url_helpers_on_namespaced_polymorphic_belongs_to
355
+ house = House.new
356
+ desk = Desk.new
357
+
358
+ new_desk = Desk.new
359
+ Desk.stubs(:new).returns(new_desk)
360
+ new_desk.stubs(:new_record?).returns(true)
361
+
362
+ controller = Admin::DesksController.new
363
+ controller.instance_variable_set('@parent_type', :house)
364
+ controller.instance_variable_set('@house', house)
365
+ controller.instance_variable_set('@desk', desk)
366
+
367
+ [:url, :path].each do |path_or_url|
368
+ controller.expects("admin_house_desks_#{path_or_url}").with(house).once
369
+ controller.send("collection_#{path_or_url}")
370
+
371
+ controller.expects("admin_house_desk_#{path_or_url}").with(house, desk).once
372
+ controller.send("resource_#{path_or_url}")
373
+
374
+ controller.expects("new_admin_house_desk_#{path_or_url}").with(house).once
375
+ controller.send("new_resource_#{path_or_url}")
376
+
377
+ controller.expects("edit_admin_house_desk_#{path_or_url}").with(house, desk).once
378
+ controller.send("edit_resource_#{path_or_url}")
379
+
380
+ controller.expects("admin_house_#{path_or_url}").with(house).once
381
+ controller.send("parent_#{path_or_url}")
382
+ end
383
+
384
+ # With options
385
+ controller.expects("admin_house_desk_url").with(house, desk, :page => 1).once
386
+ controller.send("resource_url", :page => 1)
387
+
388
+ controller.expects("admin_house_url").with(house, :page => 1).once
389
+ controller.send("parent_url", :page => 1)
390
+
391
+ # With args
392
+ controller.expects("polymorphic_url").with(['admin', :arg, new_desk], {}).once
393
+ controller.send("collection_url", :arg)
394
+
395
+ controller.expects("polymorphic_url").with(['admin', house, :arg], {}).once
396
+ controller.send("resource_url", :arg)
397
+
398
+ controller.expects("edit_polymorphic_url").with(['admin', house, :arg], {}).once
399
+ controller.send("edit_resource_url", :arg)
400
+
401
+ controller.expects("polymorphic_url").with(['admin', :arg], {}).once
402
+ controller.send("parent_url", :arg)
403
+ end
404
+
405
+ def test_url_helpers_on_nested_polymorphic_belongs_to
406
+ house = House.new
407
+ table = Table.new
408
+ dish = Dish.new
409
+
410
+ new_dish = Dish.new
411
+ Dish.stubs(:new).returns(new_dish)
412
+ new_dish.stubs(:new_record?).returns(true)
413
+
414
+ controller = DishesController.new
415
+ controller.instance_variable_set('@parent_type', :table)
416
+ controller.instance_variable_set('@house', house)
417
+ controller.instance_variable_set('@table', table)
418
+ controller.instance_variable_set('@dish', dish)
419
+
420
+ [:url, :path].each do |path_or_url|
421
+ controller.expects("house_table_dishes_#{path_or_url}").with(house, table).once
422
+ controller.send("collection_#{path_or_url}")
423
+
424
+ controller.expects("house_table_dish_#{path_or_url}").with(house, table, dish).once
425
+ controller.send("resource_#{path_or_url}")
426
+
427
+ controller.expects("new_house_table_dish_#{path_or_url}").with(house, table).once
428
+ controller.send("new_resource_#{path_or_url}")
429
+
430
+ controller.expects("edit_house_table_dish_#{path_or_url}").with(house, table, dish).once
431
+ controller.send("edit_resource_#{path_or_url}")
432
+
433
+ controller.expects("house_table_#{path_or_url}").with(house, table).once
434
+ controller.send("parent_#{path_or_url}")
435
+ end
436
+
437
+ # With options
438
+ controller.expects("house_table_dish_url").with(house, table, dish, :page => 1).once
439
+ controller.send("resource_url", :page => 1)
440
+
441
+ controller.expects("house_table_url").with(house, table, :page => 1).once
442
+ controller.send("parent_url", :page => 1)
443
+
444
+ # With args
445
+ controller.expects("polymorphic_url").with([house, table, :arg], {}).once
446
+ controller.send("resource_url", :arg)
447
+
448
+ controller.expects("edit_polymorphic_url").with([house, table, :arg], {}).once
449
+ controller.send("edit_resource_url", :arg)
450
+
451
+ controller.expects("polymorphic_url").with([house, :arg], {}).once
452
+ controller.send("parent_url", :arg)
453
+ end
454
+
455
+ def test_url_helpers_on_singleton_nested_polymorphic_belongs_to
456
+ # This must not be usefull in singleton controllers...
457
+ # Center.new
458
+ house = House.new
459
+ table = Table.new
460
+
461
+ controller = CentersController.new
462
+ controller.instance_variable_set('@parent_type', :table)
463
+ controller.instance_variable_set('@house', house)
464
+ controller.instance_variable_set('@table', table)
465
+
466
+ # This must not be useful in singleton controllers...
467
+ # controller.instance_variable_set('@center', :center)
468
+
469
+ [:url, :path].each do |path_or_url|
470
+ controller.expects("house_table_#{path_or_url}").with(house, table).once
471
+ controller.send("collection_#{path_or_url}")
472
+
473
+ controller.expects("house_table_center_#{path_or_url}").with(house, table).once
474
+ controller.send("resource_#{path_or_url}")
475
+
476
+ controller.expects("new_house_table_center_#{path_or_url}").with(house, table).once
477
+ controller.send("new_resource_#{path_or_url}")
478
+
479
+ controller.expects("edit_house_table_center_#{path_or_url}").with(house, table).once
480
+ controller.send("edit_resource_#{path_or_url}")
481
+
482
+ controller.expects("house_table_#{path_or_url}").with(house, table).once
483
+ controller.send("parent_#{path_or_url}")
484
+ end
485
+
486
+ # With options
487
+ controller.expects("house_table_center_url").with(house, table, :page => 1)
488
+ controller.send("resource_url", :page => 1)
489
+
490
+ controller.expects("house_table_url").with(house, table, :page => 1)
491
+ controller.send("parent_url", :page => 1)
492
+
493
+ # With args
494
+ controller.expects("polymorphic_url").with([house, table, :center], {}).once
495
+ controller.send("resource_url", :arg)
496
+
497
+ controller.expects("polymorphic_url").with([house, :arg], {}).once
498
+ controller.send("parent_url", :arg)
499
+ end
500
+
501
+ def test_url_helpers_on_optional_polymorphic_belongs_to
502
+ bed = Bed.new
503
+ new_bed = Bed.new
504
+ Bed.stubs(:new).returns(new_bed)
505
+ new_bed.stubs(:new_record?).returns(true)
506
+
507
+ controller = BedsController.new
508
+ controller.instance_variable_set('@parent_type', nil)
509
+ controller.instance_variable_set('@bed', bed)
510
+
511
+ [:url, :path].each do |path_or_url|
512
+ controller.expects("beds_#{path_or_url}").with().once
513
+ controller.send("collection_#{path_or_url}")
514
+
515
+ controller.expects("bed_#{path_or_url}").with(bed).once
516
+ controller.send("resource_#{path_or_url}")
517
+
518
+ controller.expects("new_bed_#{path_or_url}").with().once
519
+ controller.send("new_resource_#{path_or_url}")
520
+
521
+ controller.expects("edit_bed_#{path_or_url}").with(bed).once
522
+ controller.send("edit_resource_#{path_or_url}")
523
+ end
524
+
525
+ # With options
526
+ controller.expects("bed_url").with(bed, :page => 1).once
527
+ controller.send("resource_url", :page => 1)
528
+
529
+ # With args
530
+ controller.expects("polymorphic_url").with([:arg], {}).once
531
+ controller.send("resource_url", :arg)
532
+
533
+ controller.expects("edit_polymorphic_url").with([:arg], {}).once
534
+ controller.send("edit_resource_url", :arg)
535
+ end
536
+
537
+ end