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,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,108 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Country
4
+ end
5
+
6
+ class State
7
+ end
8
+
9
+ class City
10
+ def self.human_name; 'City'; end
11
+ end
12
+
13
+ class CitiesController < InheritedResources::Base
14
+ belongs_to :country, :state
15
+ end
16
+
17
+ class NestedBelongsToTest < ActionController::TestCase
18
+ tests CitiesController
19
+
20
+ def setup
21
+ Country.expects(:find).with('13').returns(mock_country)
22
+ mock_country.expects(:states).returns(State)
23
+ State.expects(:find).with('37').returns(mock_state)
24
+ mock_state.expects(:cities).returns(City)
25
+
26
+ @controller.stubs(:resource_url).returns('/')
27
+ @controller.stubs(:collection_url).returns('/')
28
+ end
29
+
30
+ def test_assigns_country_and_state_and_city_on_create
31
+ City.expects(:find).with(:all).returns([mock_city])
32
+ get :index, :state_id => '37', :country_id => '13'
33
+
34
+ assert_equal mock_country, assigns(:country)
35
+ assert_equal mock_state, assigns(:state)
36
+ assert_equal [mock_city], assigns(:cities)
37
+ end
38
+
39
+ def test_assigns_country_and_state_and_city_on_show
40
+ City.expects(:find).with('42').returns(mock_city)
41
+ get :show, :id => '42', :state_id => '37', :country_id => '13'
42
+
43
+ assert_equal mock_country, assigns(:country)
44
+ assert_equal mock_state, assigns(:state)
45
+ assert_equal mock_city, assigns(:city)
46
+ end
47
+
48
+ def test_assigns_country_and_state_and_city_on_new
49
+ City.expects(:build).returns(mock_city)
50
+ get :new, :state_id => '37', :country_id => '13'
51
+
52
+ assert_equal mock_country, assigns(:country)
53
+ assert_equal mock_state, assigns(:state)
54
+ assert_equal mock_city, assigns(:city)
55
+ end
56
+
57
+ def test_assigns_country_and_state_and_city_on_edit
58
+ City.expects(:find).with('42').returns(mock_city)
59
+ get :edit, :id => '42', :state_id => '37', :country_id => '13'
60
+
61
+ assert_equal mock_country, assigns(:country)
62
+ assert_equal mock_state, assigns(:state)
63
+ assert_equal mock_city, assigns(:city)
64
+ end
65
+
66
+ def test_assigns_country_and_state_and_city_on_create
67
+ City.expects(:build).with({'these' => 'params'}).returns(mock_city)
68
+ mock_city.expects(:save).returns(true)
69
+ post :create, :state_id => '37', :country_id => '13', :city => {:these => 'params'}
70
+
71
+ assert_equal mock_country, assigns(:country)
72
+ assert_equal mock_state, assigns(:state)
73
+ assert_equal mock_city, assigns(:city)
74
+ end
75
+
76
+ def test_assigns_country_and_state_and_city_on_update
77
+ City.expects(:find).with('42').returns(mock_city)
78
+ mock_city.expects(:update_attributes).returns(true)
79
+ put :update, :id => '42', :state_id => '37', :country_id => '13', :city => {:these => 'params'}
80
+
81
+ assert_equal mock_country, assigns(:country)
82
+ assert_equal mock_state, assigns(:state)
83
+ assert_equal mock_city, assigns(:city)
84
+ end
85
+
86
+ def test_assigns_country_and_state_and_city_on_destroy
87
+ City.expects(:find).with('42').returns(mock_city)
88
+ mock_city.expects(:destroy)
89
+ delete :destroy, :id => '42', :state_id => '37', :country_id => '13'
90
+
91
+ assert_equal mock_country, assigns(:country)
92
+ assert_equal mock_state, assigns(:state)
93
+ assert_equal mock_city, assigns(:city)
94
+ end
95
+
96
+ protected
97
+ def mock_country(stubs={})
98
+ @mock_country ||= mock(stubs)
99
+ end
100
+
101
+ def mock_state(stubs={})
102
+ @mock_state ||= mock(stubs)
103
+ end
104
+
105
+ def mock_city(stubs={})
106
+ @mock_city ||= mock(stubs)
107
+ end
108
+ end
@@ -0,0 +1,164 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Brands; end
4
+ class Category; end
5
+
6
+ class Product
7
+ def self.human_name; 'Product'; end
8
+ end
9
+
10
+ class ProductsController < InheritedResources::Base
11
+ belongs_to :brand, :category, :polymorphic => true, :optional => true
12
+ end
13
+
14
+ class OptionalTest < ActionController::TestCase
15
+ tests ProductsController
16
+
17
+ def setup
18
+ @controller.stubs(:resource_url).returns('/')
19
+ @controller.stubs(:collection_url).returns('/')
20
+ end
21
+
22
+ def test_expose_all_products_as_instance_variable_with_category
23
+ Category.expects(:find).with('37').returns(mock_category)
24
+ mock_category.expects(:products).returns(Product)
25
+ Product.expects(:find).with(:all).returns([mock_product])
26
+ get :index, :category_id => '37'
27
+ assert_equal mock_category, assigns(:category)
28
+ assert_equal [mock_product], assigns(:products)
29
+ end
30
+
31
+ def test_expose_all_products_as_instance_variable_without_category
32
+ Product.expects(:find).with(:all).returns([mock_product])
33
+ get :index
34
+ assert_equal nil, assigns(:category)
35
+ assert_equal [mock_product], assigns(:products)
36
+ end
37
+
38
+ def test_expose_the_resquested_product_with_category
39
+ Category.expects(:find).with('37').returns(mock_category)
40
+ mock_category.expects(:products).returns(Product)
41
+ Product.expects(:find).with('42').returns(mock_product)
42
+ get :show, :id => '42', :category_id => '37'
43
+ assert_equal mock_category, assigns(:category)
44
+ assert_equal mock_product, assigns(:product)
45
+ end
46
+
47
+ def test_expose_the_resquested_product_without_category
48
+ Product.expects(:find).with('42').returns(mock_product)
49
+ get :show, :id => '42'
50
+ assert_equal nil, assigns(:category)
51
+ assert_equal mock_product, assigns(:product)
52
+ end
53
+
54
+ def test_expose_a_new_product_with_category
55
+ Category.expects(:find).with('37').returns(mock_category)
56
+ mock_category.expects(:products).returns(Product)
57
+ Product.expects(:build).returns(mock_product)
58
+ get :new, :category_id => '37'
59
+ assert_equal mock_category, assigns(:category)
60
+ assert_equal mock_product, assigns(:product)
61
+ end
62
+
63
+ def test_expose_a_new_product_without_category
64
+ Product.expects(:new).returns(mock_product)
65
+ get :new
66
+ assert_equal nil, assigns(:category)
67
+ assert_equal mock_product, assigns(:product)
68
+ end
69
+
70
+ def test_expose_the_resquested_product_for_edition_with_category
71
+ Category.expects(:find).with('37').returns(mock_category)
72
+ mock_category.expects(:products).returns(Product)
73
+ Product.expects(:find).with('42').returns(mock_product)
74
+ get :edit, :id => '42', :category_id => '37'
75
+ assert_equal mock_category, assigns(:category)
76
+ assert_equal mock_product, assigns(:product)
77
+ end
78
+
79
+ def test_expose_the_resquested_product_for_edition_without_category
80
+ Product.expects(:find).with('42').returns(mock_product)
81
+ get :edit, :id => '42'
82
+ assert_equal nil, assigns(:category)
83
+ assert_equal mock_product, assigns(:product)
84
+ end
85
+
86
+ def test_expose_a_newly_create_product_with_category
87
+ Category.expects(:find).with('37').returns(mock_category)
88
+ mock_category.expects(:products).returns(Product)
89
+ Product.expects(:build).with({'these' => 'params'}).returns(mock_product(:save => true))
90
+ post :create, :category_id => '37', :product => {:these => 'params'}
91
+ assert_equal mock_category, assigns(:category)
92
+ assert_equal mock_product, assigns(:product)
93
+ end
94
+
95
+ def test_expose_a_newly_create_product_without_category
96
+ Product.expects(:new).with({'these' => 'params'}).returns(mock_product(:save => true))
97
+ post :create, :product => {:these => 'params'}
98
+ assert_equal nil, assigns(:category)
99
+ assert_equal mock_product, assigns(:product)
100
+ end
101
+
102
+ def test_update_the_requested_object_with_category
103
+ Category.expects(:find).with('37').returns(mock_category)
104
+ mock_category.expects(:products).returns(Product)
105
+ Product.expects(:find).with('42').returns(mock_product)
106
+ mock_product.expects(:update_attributes).with({'these' => 'params'}).returns(true)
107
+
108
+ put :update, :id => '42', :category_id => '37', :product => {:these => 'params'}
109
+ assert_equal mock_category, assigns(:category)
110
+ assert_equal mock_product, assigns(:product)
111
+ end
112
+
113
+ def test_update_the_requested_object_without_category
114
+ Product.expects(:find).with('42').returns(mock_product)
115
+ mock_product.expects(:update_attributes).with({'these' => 'params'}).returns(true)
116
+
117
+ put :update, :id => '42', :product => {:these => 'params'}
118
+ assert_equal nil, assigns(:category)
119
+ assert_equal mock_product, assigns(:product)
120
+ end
121
+
122
+ def test_the_resquested_product_is_destroyed_with_category
123
+ Category.expects(:find).with('37').returns(mock_category)
124
+ mock_category.expects(:products).returns(Product)
125
+ Product.expects(:find).with('42').returns(mock_product)
126
+ mock_product.expects(:destroy)
127
+ @controller.expects(:collection_url).returns('/')
128
+
129
+ delete :destroy, :id => '42', :category_id => '37'
130
+ assert_equal mock_category, assigns(:category)
131
+ assert_equal mock_product, assigns(:product)
132
+ end
133
+
134
+ def test_the_resquested_product_is_destroyed_without_category
135
+ Product.expects(:find).with('42').returns(mock_product)
136
+ mock_product.expects(:destroy)
137
+ @controller.expects(:collection_url).returns('/')
138
+
139
+ delete :destroy, :id => '42'
140
+ assert_equal nil, assigns(:category)
141
+ assert_equal mock_product, assigns(:product)
142
+ end
143
+
144
+ def test_polymorphic_helpers
145
+ Product.expects(:find).with(:all).returns([mock_product])
146
+ get :index
147
+
148
+ assert !@controller.send(:parent?)
149
+ assert_equal nil, assigns(:parent_type)
150
+ assert_equal nil, @controller.send(:parent_type)
151
+ assert_equal nil, @controller.send(:parent_class)
152
+ assert_equal nil, assigns(:category)
153
+ assert_equal nil, @controller.send(:parent)
154
+ end
155
+
156
+ protected
157
+ def mock_category(stubs={})
158
+ @mock_category ||= mock(stubs)
159
+ end
160
+
161
+ def mock_product(stubs={})
162
+ @mock_product ||= mock(stubs)
163
+ end
164
+ end
@@ -0,0 +1,186 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Factory; end
4
+ class Company; end
5
+
6
+ class Employee
7
+ def self.human_name; 'Employee'; end
8
+ end
9
+
10
+ class EmployeesController < InheritedResources::Base
11
+ belongs_to :factory, :company, :polymorphic => true
12
+ end
13
+
14
+ class PolymorphicFactoriesTest < ActionController::TestCase
15
+ tests EmployeesController
16
+
17
+ def setup
18
+ Factory.expects(:find).with('37').returns(mock_factory)
19
+ mock_factory.expects(:employees).returns(Employee)
20
+
21
+ @controller.stubs(:resource_url).returns('/')
22
+ @controller.stubs(:collection_url).returns('/')
23
+ end
24
+
25
+ def test_expose_all_employees_as_instance_variable_on_index
26
+ Employee.expects(:find).with(:all).returns([mock_employee])
27
+ get :index, :factory_id => '37'
28
+ assert_equal mock_factory, assigns(:factory)
29
+ assert_equal [mock_employee], assigns(:employees)
30
+ end
31
+
32
+ def test_expose_the_resquested_employee_on_show
33
+ Employee.expects(:find).with('42').returns(mock_employee)
34
+ get :show, :id => '42', :factory_id => '37'
35
+ assert_equal mock_factory, assigns(:factory)
36
+ assert_equal mock_employee, assigns(:employee)
37
+ end
38
+
39
+ def test_expose_a_new_employee_on_new
40
+ Employee.expects(:build).returns(mock_employee)
41
+ get :new, :factory_id => '37'
42
+ assert_equal mock_factory, assigns(:factory)
43
+ assert_equal mock_employee, assigns(:employee)
44
+ end
45
+
46
+ def test_expose_the_resquested_employee_on_edit
47
+ Employee.expects(:find).with('42').returns(mock_employee)
48
+ get :edit, :id => '42', :factory_id => '37'
49
+ assert_equal mock_factory, assigns(:factory)
50
+ assert_equal mock_employee, assigns(:employee)
51
+ assert_response :success
52
+ end
53
+
54
+ def test_expose_a_newly_create_employee_on_create
55
+ Employee.expects(:build).with({'these' => 'params'}).returns(mock_employee(:save => true))
56
+ post :create, :factory_id => '37', :employee => {:these => 'params'}
57
+ assert_equal mock_factory, assigns(:factory)
58
+ assert_equal mock_employee, assigns(:employee)
59
+ end
60
+
61
+ def test_update_the_requested_object_on_update
62
+ Employee.expects(:find).with('42').returns(mock_employee)
63
+ mock_employee.expects(:update_attributes).with({'these' => 'params'}).returns(true)
64
+ put :update, :id => '42', :factory_id => '37', :employee => {:these => 'params'}
65
+ assert_equal mock_factory, assigns(:factory)
66
+ assert_equal mock_employee, assigns(:employee)
67
+ end
68
+
69
+ def test_the_resquested_employee_is_destroyed_on_destroy
70
+ Employee.expects(:find).with('42').returns(mock_employee)
71
+ mock_employee.expects(:destroy)
72
+ delete :destroy, :id => '42', :factory_id => '37'
73
+ assert_equal mock_factory, assigns(:factory)
74
+ assert_equal mock_employee, assigns(:employee)
75
+ end
76
+
77
+ def test_polymorphic_helpers
78
+ mock_factory.stubs(:class).returns(Factory)
79
+
80
+ Employee.expects(:find).with(:all).returns([mock_employee])
81
+ get :index, :factory_id => '37'
82
+
83
+ assert @controller.send(:parent?)
84
+ assert_equal :factory, assigns(:parent_type)
85
+ assert_equal :factory, @controller.send(:parent_type)
86
+ assert_equal Factory, @controller.send(:parent_class)
87
+ assert_equal mock_factory, assigns(:factory)
88
+ assert_equal mock_factory, @controller.send(:parent)
89
+ end
90
+
91
+ protected
92
+ def mock_factory(stubs={})
93
+ @mock_factory ||= mock(stubs)
94
+ end
95
+
96
+ def mock_employee(stubs={})
97
+ @mock_employee ||= mock(stubs)
98
+ end
99
+ end
100
+
101
+ class PolymorphicCompanyTest < ActionController::TestCase
102
+ tests EmployeesController
103
+
104
+ def setup
105
+ Company.expects(:find).with('37').returns(mock_company)
106
+ mock_company.expects(:employees).returns(Employee)
107
+
108
+ @controller.stubs(:resource_url).returns('/')
109
+ @controller.stubs(:collection_url).returns('/')
110
+ end
111
+
112
+ def test_expose_all_employees_as_instance_variable_on_index
113
+ Employee.expects(:find).with(:all).returns([mock_employee])
114
+ get :index, :company_id => '37'
115
+ assert_equal mock_company, assigns(:company)
116
+ assert_equal [mock_employee], assigns(:employees)
117
+ end
118
+
119
+ def test_expose_the_resquested_employee_on_show
120
+ Employee.expects(:find).with('42').returns(mock_employee)
121
+ get :show, :id => '42', :company_id => '37'
122
+ assert_equal mock_company, assigns(:company)
123
+ assert_equal mock_employee, assigns(:employee)
124
+ end
125
+
126
+ def test_expose_a_new_employee_on_new
127
+ Employee.expects(:build).returns(mock_employee)
128
+ get :new, :company_id => '37'
129
+ assert_equal mock_company, assigns(:company)
130
+ assert_equal mock_employee, assigns(:employee)
131
+ end
132
+
133
+ def test_expose_the_resquested_employee_on_edit
134
+ Employee.expects(:find).with('42').returns(mock_employee)
135
+ get :edit, :id => '42', :company_id => '37'
136
+ assert_equal mock_company, assigns(:company)
137
+ assert_equal mock_employee, assigns(:employee)
138
+ assert_response :success
139
+ end
140
+
141
+ def test_expose_a_newly_create_employee_on_create
142
+ Employee.expects(:build).with({'these' => 'params'}).returns(mock_employee(:save => true))
143
+ post :create, :company_id => '37', :employee => {:these => 'params'}
144
+ assert_equal mock_company, assigns(:company)
145
+ assert_equal mock_employee, assigns(:employee)
146
+ end
147
+
148
+ def test_update_the_requested_object_on_update
149
+ Employee.expects(:find).with('42').returns(mock_employee)
150
+ mock_employee.expects(:update_attributes).with({'these' => 'params'}).returns(true)
151
+ put :update, :id => '42', :company_id => '37', :employee => {:these => 'params'}
152
+ assert_equal mock_company, assigns(:company)
153
+ assert_equal mock_employee, assigns(:employee)
154
+ end
155
+
156
+ def test_the_resquested_employee_is_destroyed_on_destroy
157
+ Employee.expects(:find).with('42').returns(mock_employee)
158
+ mock_employee.expects(:destroy)
159
+ delete :destroy, :id => '42', :company_id => '37'
160
+ assert_equal mock_company, assigns(:company)
161
+ assert_equal mock_employee, assigns(:employee)
162
+ end
163
+
164
+ def test_polymorphic_helpers
165
+ mock_company.stubs(:class).returns(Company)
166
+
167
+ Employee.expects(:find).with(:all).returns([mock_employee])
168
+ get :index, :company_id => '37'
169
+
170
+ assert @controller.send(:parent?)
171
+ assert_equal :company, assigns(:parent_type)
172
+ assert_equal :company, @controller.send(:parent_type)
173
+ assert_equal Company, @controller.send(:parent_class)
174
+ assert_equal mock_company, assigns(:company)
175
+ assert_equal mock_company, @controller.send(:parent)
176
+ end
177
+
178
+ protected
179
+ def mock_company(stubs={})
180
+ @mock_company ||= mock(stubs)
181
+ end
182
+
183
+ def mock_employee(stubs={})
184
+ @mock_employee ||= mock(stubs)
185
+ end
186
+ end