tournament 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/History.txt +15 -0
  2. data/Manifest.txt +241 -2
  3. data/README.txt +152 -12
  4. data/Rakefile +9 -6
  5. data/bin/benchmark_pool +0 -0
  6. data/bin/gui.rb +3 -1
  7. data/bin/picker +0 -0
  8. data/bin/pool +139 -15
  9. data/lib/tournament/bracket.rb +33 -50
  10. data/lib/tournament/entry.rb +3 -0
  11. data/lib/tournament/pool.rb +144 -93
  12. data/lib/tournament/scoring_strategy.rb +69 -0
  13. data/lib/tournament/webgui_installer.rb +109 -0
  14. data/tasks/ann.rake +19 -14
  15. data/tasks/bones.rake +6 -25
  16. data/tasks/gem.rake +46 -36
  17. data/tasks/git.rake +41 -0
  18. data/tasks/jamis.rb +589 -0
  19. data/tasks/notes.rake +28 -0
  20. data/tasks/post_load.rake +18 -11
  21. data/tasks/{doc.rake → rdoc.rake} +12 -9
  22. data/tasks/rubyforge.rake +12 -12
  23. data/tasks/setup.rb +121 -80
  24. data/tasks/spec.rake +12 -13
  25. data/tasks/svn.rake +15 -11
  26. data/tasks/test.rake +6 -6
  27. data/test/test_tournament.rb +8 -0
  28. data/test/test_webgui_installer.rb +64 -0
  29. data/webgui/README +256 -0
  30. data/webgui/Rakefile +10 -0
  31. data/webgui/app/controllers/admin_controller.rb +61 -0
  32. data/webgui/app/controllers/application.rb +25 -0
  33. data/webgui/app/controllers/entry_controller.rb +97 -0
  34. data/webgui/app/controllers/pool_controller.rb +4 -0
  35. data/webgui/app/controllers/reports_controller.rb +7 -0
  36. data/webgui/app/controllers/sessions_controller.rb +43 -0
  37. data/webgui/app/controllers/teams_controller.rb +75 -0
  38. data/webgui/app/controllers/users_controller.rb +57 -0
  39. data/webgui/app/helpers/admin_helper.rb +2 -0
  40. data/webgui/app/helpers/application_helper.rb +3 -0
  41. data/webgui/app/helpers/entry_helper.rb +2 -0
  42. data/webgui/app/helpers/pool_helper.rb +2 -0
  43. data/webgui/app/helpers/reports_helper.rb +2 -0
  44. data/webgui/app/helpers/sessions_helper.rb +2 -0
  45. data/webgui/app/helpers/teams_helper.rb +2 -0
  46. data/webgui/app/helpers/users_helper.rb +93 -0
  47. data/webgui/app/models/entry.rb +42 -0
  48. data/webgui/app/models/pool.rb +141 -0
  49. data/webgui/app/models/region.rb +3 -0
  50. data/webgui/app/models/role.rb +4 -0
  51. data/webgui/app/models/seeding.rb +4 -0
  52. data/webgui/app/models/team.rb +6 -0
  53. data/webgui/app/models/user.rb +98 -0
  54. data/webgui/app/models/user_mailer.rb +25 -0
  55. data/webgui/app/views/admin/bracket.html.erb +3 -0
  56. data/webgui/app/views/admin/entries.html.erb +25 -0
  57. data/webgui/app/views/admin/index.html.erb +17 -0
  58. data/webgui/app/views/admin/pool.html.erb +53 -0
  59. data/webgui/app/views/entry/index.html.erb +16 -0
  60. data/webgui/app/views/entry/print.erb +1 -0
  61. data/webgui/app/views/entry/print.html.erb +1 -0
  62. data/webgui/app/views/entry/show.html.erb +1 -0
  63. data/webgui/app/views/layouts/bracket.html.erb +37 -0
  64. data/webgui/app/views/layouts/default.html.erb +62 -0
  65. data/webgui/app/views/layouts/print.html.erb +12 -0
  66. data/webgui/app/views/layouts/report.html.erb +38 -0
  67. data/webgui/app/views/pool/index.html.erb +36 -0
  68. data/webgui/app/views/reports/_report.html.erb +11 -0
  69. data/webgui/app/views/reports/show.html.erb +12 -0
  70. data/webgui/app/views/sessions/new.html.erb +21 -0
  71. data/webgui/app/views/shared/_admins.html.erb +8 -0
  72. data/webgui/app/views/shared/_bracket.html.erb +1296 -0
  73. data/webgui/app/views/teams/choose.html.erb +57 -0
  74. data/webgui/app/views/user_mailer/activation.erb +3 -0
  75. data/webgui/app/views/user_mailer/signup_notification.erb +8 -0
  76. data/webgui/app/views/users/_user_bar.html.erb +8 -0
  77. data/webgui/app/views/users/new.html.erb +19 -0
  78. data/webgui/config/boot.rb +109 -0
  79. data/webgui/config/database.yml +22 -0
  80. data/webgui/config/environment.rb +78 -0
  81. data/webgui/config/environments/development.rb +29 -0
  82. data/webgui/config/environments/production.rb +24 -0
  83. data/webgui/config/environments/test.rb +22 -0
  84. data/webgui/config/initializers/inflections.rb +10 -0
  85. data/webgui/config/initializers/mime_types.rb +5 -0
  86. data/webgui/config/initializers/new_rails_defaults.rb +17 -0
  87. data/webgui/config/initializers/pool.rb +33 -0
  88. data/webgui/config/initializers/site_keys.rb +38 -0
  89. data/webgui/config/locales/en.yml +5 -0
  90. data/webgui/config/routes.rb +56 -0
  91. data/webgui/db/development.sqlite3 +0 -0
  92. data/webgui/db/migrate/20090216015836_create_entries.rb +13 -0
  93. data/webgui/db/migrate/20090217001611_add_tie_break_to_entry.rb +9 -0
  94. data/webgui/db/migrate/20090217004039_create_users.rb +23 -0
  95. data/webgui/db/migrate/20090217014940_relate_entry_and_user.rb +10 -0
  96. data/webgui/db/migrate/20090218024350_create_roles.rb +17 -0
  97. data/webgui/db/migrate/20090218024657_add_postition_to_roles.rb +9 -0
  98. data/webgui/db/migrate/20090218025240_add_admin_role.rb +10 -0
  99. data/webgui/db/migrate/20090225022928_create_pools.rb +16 -0
  100. data/webgui/db/migrate/20090225030346_associate_pool_and_entry.rb +9 -0
  101. data/webgui/db/migrate/20090225072358_change_pool_data_column.rb +9 -0
  102. data/webgui/db/migrate/20090225072849_add_completed_to_entries.rb +9 -0
  103. data/webgui/db/migrate/20090225074149_add_pool_id_index_to_entries.rb +9 -0
  104. data/webgui/db/migrate/20090225084414_add_user_id_to_pool.rb +9 -0
  105. data/webgui/db/migrate/20090226021913_add_active_to_pools.rb +9 -0
  106. data/webgui/db/migrate/20090226142240_rename_bracket_column_to_data.rb +9 -0
  107. data/webgui/db/migrate/20090301014710_create_teams.rb +84 -0
  108. data/webgui/db/migrate/20090301025902_add_more_teams.rb +16 -0
  109. data/webgui/db/migrate/20090301041526_create_seedings.rb +16 -0
  110. data/webgui/db/migrate/20090301090511_create_regions.rb +14 -0
  111. data/webgui/db/migrate/teams.txt +347 -0
  112. data/webgui/db/pool.yml +408 -0
  113. data/webgui/db/schema.rb +91 -0
  114. data/webgui/db/test.sqlite3 +0 -0
  115. data/webgui/doc/README_FOR_APP +5 -0
  116. data/webgui/lib/authenticated_system.rb +189 -0
  117. data/webgui/lib/authenticated_test_helper.rb +11 -0
  118. data/webgui/lib/form_object.rb +70 -0
  119. data/webgui/lib/pdf_helper.rb +47 -0
  120. data/webgui/lib/prince.rb +74 -0
  121. data/webgui/lib/saves_picks.rb +23 -0
  122. data/webgui/lib/tasks/admin.rake +10 -0
  123. data/webgui/public/404.html +30 -0
  124. data/webgui/public/422.html +30 -0
  125. data/webgui/public/500.html +33 -0
  126. data/webgui/public/dispatch.cgi +10 -0
  127. data/webgui/public/dispatch.fcgi +24 -0
  128. data/webgui/public/dispatch.rb +10 -0
  129. data/webgui/public/favicon.ico +0 -0
  130. data/webgui/public/images/2009FinalFour.png +0 -0
  131. data/webgui/public/images/rails.png +0 -0
  132. data/webgui/public/javascripts/application.js +2 -0
  133. data/webgui/public/javascripts/bracket.js +73 -0
  134. data/webgui/public/javascripts/controls.js +963 -0
  135. data/webgui/public/javascripts/dragdrop.js +973 -0
  136. data/webgui/public/javascripts/effects.js +1128 -0
  137. data/webgui/public/javascripts/prototype.js +4320 -0
  138. data/webgui/public/robots.txt +5 -0
  139. data/webgui/public/stylesheets/bracket-print.css +39 -0
  140. data/webgui/public/stylesheets/bracket.css +125 -0
  141. data/webgui/public/stylesheets/main.css +144 -0
  142. data/webgui/public/stylesheets/prince.css +6 -0
  143. data/webgui/public/stylesheets/prince_landscape.css +1 -0
  144. data/webgui/script/about +4 -0
  145. data/webgui/script/console +3 -0
  146. data/webgui/script/dbconsole +3 -0
  147. data/webgui/script/destroy +3 -0
  148. data/webgui/script/generate +3 -0
  149. data/webgui/script/performance/benchmarker +3 -0
  150. data/webgui/script/performance/profiler +3 -0
  151. data/webgui/script/performance/request +3 -0
  152. data/webgui/script/plugin +3 -0
  153. data/webgui/script/process/inspector +3 -0
  154. data/webgui/script/process/reaper +3 -0
  155. data/webgui/script/process/spawner +3 -0
  156. data/webgui/script/runner +3 -0
  157. data/webgui/script/server +3 -0
  158. data/webgui/test/fixtures/entries.yml +10 -0
  159. data/webgui/test/fixtures/pools.yml +14 -0
  160. data/webgui/test/fixtures/regions.yml +11 -0
  161. data/webgui/test/fixtures/roles.yml +11 -0
  162. data/webgui/test/fixtures/roles_users.yml +3 -0
  163. data/webgui/test/fixtures/seedings.yml +12 -0
  164. data/webgui/test/fixtures/teams.yml +3051 -0
  165. data/webgui/test/fixtures/users.yml +44 -0
  166. data/webgui/test/functional/admin_controller_test.rb +8 -0
  167. data/webgui/test/functional/entry_controller_test.rb +27 -0
  168. data/webgui/test/functional/pool_controller_test.rb +8 -0
  169. data/webgui/test/functional/reports_controller_test.rb +8 -0
  170. data/webgui/test/functional/sessions_controller_test.rb +82 -0
  171. data/webgui/test/functional/teams_controller_test.rb +216 -0
  172. data/webgui/test/functional/users_controller_test.rb +88 -0
  173. data/webgui/test/performance/browsing_test.rb +9 -0
  174. data/webgui/test/test_helper.rb +38 -0
  175. data/webgui/test/unit/entry_test.rb +8 -0
  176. data/webgui/test/unit/pool_test.rb +8 -0
  177. data/webgui/test/unit/region_test.rb +8 -0
  178. data/webgui/test/unit/role_test.rb +8 -0
  179. data/webgui/test/unit/seeding_test.rb +8 -0
  180. data/webgui/test/unit/team_test.rb +10 -0
  181. data/webgui/test/unit/user_mailer_test.rb +31 -0
  182. data/webgui/test/unit/user_test.rb +109 -0
  183. data/webgui/vendor/plugins/auto_complete/README +23 -0
  184. data/webgui/vendor/plugins/auto_complete/Rakefile +22 -0
  185. data/webgui/vendor/plugins/auto_complete/init.rb +2 -0
  186. data/webgui/vendor/plugins/auto_complete/lib/auto_complete.rb +47 -0
  187. data/webgui/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb +143 -0
  188. data/webgui/vendor/plugins/auto_complete/test/auto_complete_test.rb +67 -0
  189. data/webgui/vendor/plugins/enumerations_mixin/ATTENTION +15 -0
  190. data/webgui/vendor/plugins/enumerations_mixin/LICENSE +20 -0
  191. data/webgui/vendor/plugins/enumerations_mixin/README_ENUMERATIONS +163 -0
  192. data/webgui/vendor/plugins/enumerations_mixin/init.rb +21 -0
  193. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/acts/enumerated.rb +177 -0
  194. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/aggregations/has_enumerated.rb +60 -0
  195. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/virtual_enumerations.rb +68 -0
  196. data/webgui/vendor/plugins/enumerations_mixin/virtual_enumerations_sample.rb +76 -0
  197. data/webgui/vendor/plugins/restful_authentication/.gitignore +21 -0
  198. data/webgui/vendor/plugins/restful_authentication/CHANGELOG +68 -0
  199. data/webgui/vendor/plugins/restful_authentication/README.textile +224 -0
  200. data/webgui/vendor/plugins/restful_authentication/Rakefile +32 -0
  201. data/webgui/vendor/plugins/restful_authentication/TODO +15 -0
  202. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/USAGE +1 -0
  203. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/authenticated_generator.rb +478 -0
  204. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/lib/insert_routes.rb +54 -0
  205. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/_model_partial.html.erb +8 -0
  206. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/activation.erb +3 -0
  207. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb +189 -0
  208. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
  209. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/controller.rb +43 -0
  210. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/helper.rb +2 -0
  211. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/login.html.erb +16 -0
  212. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/mailer.rb +25 -0
  213. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb +26 -0
  214. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model.rb +83 -0
  215. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_controller.rb +85 -0
  216. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper.rb +93 -0
  217. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper_spec.rb +158 -0
  218. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/observer.rb +11 -0
  219. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup.html.erb +19 -0
  220. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup_notification.erb +8 -0
  221. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/site_keys.rb +38 -0
  222. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
  223. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +102 -0
  224. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
  225. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +198 -0
  226. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/fixtures/users.yml +60 -0
  227. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
  228. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/models/user_spec.rb +290 -0
  229. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
  230. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
  231. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
  232. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
  233. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
  234. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
  235. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/accounts.story +186 -0
  236. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/sessions.story +134 -0
  237. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/functional_test.rb +82 -0
  238. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/mailer_test.rb +31 -0
  239. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/model_functional_test.rb +93 -0
  240. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/unit_test.rb +164 -0
  241. data/webgui/vendor/plugins/restful_authentication/init.rb +1 -0
  242. data/webgui/vendor/plugins/restful_authentication/install.rb +1 -0
  243. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb +82 -0
  244. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_password.rb +64 -0
  245. data/webgui/vendor/plugins/restful_authentication/lib/authentication.rb +40 -0
  246. data/webgui/vendor/plugins/restful_authentication/lib/authorization/aasm_roles.rb +63 -0
  247. data/webgui/vendor/plugins/restful_authentication/lib/authorization/stateful_roles.rb +62 -0
  248. data/webgui/vendor/plugins/restful_authentication/lib/authorization.rb +14 -0
  249. data/webgui/vendor/plugins/restful_authentication/lib/trustification/email_validation.rb +20 -0
  250. data/webgui/vendor/plugins/restful_authentication/lib/trustification.rb +14 -0
  251. data/webgui/vendor/plugins/restful_authentication/notes/AccessControl.txt +2 -0
  252. data/webgui/vendor/plugins/restful_authentication/notes/Authentication.txt +5 -0
  253. data/webgui/vendor/plugins/restful_authentication/notes/Authorization.txt +154 -0
  254. data/webgui/vendor/plugins/restful_authentication/notes/RailsPlugins.txt +78 -0
  255. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.graffle +0 -0
  256. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.png +0 -0
  257. data/webgui/vendor/plugins/restful_authentication/notes/SecurityPatterns.txt +163 -0
  258. data/webgui/vendor/plugins/restful_authentication/notes/Tradeoffs.txt +126 -0
  259. data/webgui/vendor/plugins/restful_authentication/notes/Trustification.txt +49 -0
  260. data/webgui/vendor/plugins/restful_authentication/rails/init.rb +3 -0
  261. data/webgui/vendor/plugins/restful_authentication/restful-authentication.gemspec +33 -0
  262. data/webgui/vendor/plugins/restful_authentication/tasks/auth.rake +33 -0
  263. metadata +288 -8
  264. data/tasks/annotations.rake +0 -22
@@ -0,0 +1,198 @@
1
+ require File.dirname(__FILE__) + '<%= ('/..'*model_controller_class_nesting_depth) + '/../spec_helper' %>'
2
+
3
+ # Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
4
+ # Then, you can remove it from this and the units test.
5
+ include AuthenticatedTestHelper
6
+
7
+ describe <%= model_controller_class_name %>Controller do
8
+ fixtures :<%= table_name %>
9
+
10
+ it 'allows signup' do
11
+ lambda do
12
+ create_<%= file_name %>
13
+ response.should be_redirect
14
+ end.should change(<%= class_name %>, :count).by(1)
15
+ end
16
+
17
+ <% if options[:stateful] %>
18
+ it 'signs up user in pending state' do
19
+ create_<%= file_name %>
20
+ assigns(:<%= file_name %>).reload
21
+ assigns(:<%= file_name %>).should be_pending
22
+ end<% end %>
23
+
24
+ <% if options[:include_activation] -%>
25
+ it 'signs up user with activation code' do
26
+ create_<%= file_name %>
27
+ assigns(:<%= file_name %>).reload
28
+ assigns(:<%= file_name %>).activation_code.should_not be_nil
29
+ end<% end -%>
30
+
31
+ it 'requires login on signup' do
32
+ lambda do
33
+ create_<%= file_name %>(:login => nil)
34
+ assigns[:<%= file_name %>].errors.on(:login).should_not be_nil
35
+ response.should be_success
36
+ end.should_not change(<%= class_name %>, :count)
37
+ end
38
+
39
+ it 'requires password on signup' do
40
+ lambda do
41
+ create_<%= file_name %>(:password => nil)
42
+ assigns[:<%= file_name %>].errors.on(:password).should_not be_nil
43
+ response.should be_success
44
+ end.should_not change(<%= class_name %>, :count)
45
+ end
46
+
47
+ it 'requires password confirmation on signup' do
48
+ lambda do
49
+ create_<%= file_name %>(:password_confirmation => nil)
50
+ assigns[:<%= file_name %>].errors.on(:password_confirmation).should_not be_nil
51
+ response.should be_success
52
+ end.should_not change(<%= class_name %>, :count)
53
+ end
54
+
55
+ it 'requires email on signup' do
56
+ lambda do
57
+ create_<%= file_name %>(:email => nil)
58
+ assigns[:<%= file_name %>].errors.on(:email).should_not be_nil
59
+ response.should be_success
60
+ end.should_not change(<%= class_name %>, :count)
61
+ end
62
+
63
+ <% if options[:include_activation] %>
64
+ it 'activates user' do
65
+ <%= class_name %>.authenticate('aaron', 'monkey').should be_nil
66
+ get :activate, :activation_code => <%= table_name %>(:aaron).activation_code
67
+ response.should redirect_to('/login')
68
+ flash[:notice].should_not be_nil
69
+ flash[:error ].should be_nil
70
+ <%= class_name %>.authenticate('aaron', 'monkey').should == <%= table_name %>(:aaron)
71
+ end
72
+
73
+ it 'does not activate user without key' do
74
+ get :activate
75
+ flash[:notice].should be_nil
76
+ flash[:error ].should_not be_nil
77
+ end
78
+
79
+ it 'does not activate user with blank key' do
80
+ get :activate, :activation_code => ''
81
+ flash[:notice].should be_nil
82
+ flash[:error ].should_not be_nil
83
+ end
84
+
85
+ it 'does not activate user with bogus key' do
86
+ get :activate, :activation_code => 'i_haxxor_joo'
87
+ flash[:notice].should be_nil
88
+ flash[:error ].should_not be_nil
89
+ end<% end %>
90
+
91
+ def create_<%= file_name %>(options = {})
92
+ post :create, :<%= file_name %> => { :login => 'quire', :email => 'quire@example.com',
93
+ :password => 'quire69', :password_confirmation => 'quire69' }.merge(options)
94
+ end
95
+ end
96
+
97
+ describe <%= model_controller_class_name %>Controller do
98
+ describe "route generation" do
99
+ it "should route <%= model_controller_controller_name %>'s 'index' action correctly" do
100
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'index').should == "/<%= model_controller_routing_path %>"
101
+ end
102
+
103
+ it "should route <%= model_controller_controller_name %>'s 'new' action correctly" do
104
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'new').should == "/signup"
105
+ end
106
+
107
+ it "should route {:controller => '<%= model_controller_controller_name %>', :action => 'create'} correctly" do
108
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'create').should == "/register"
109
+ end
110
+
111
+ it "should route <%= model_controller_controller_name %>'s 'show' action correctly" do
112
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1').should == "/<%= model_controller_routing_path %>/1"
113
+ end
114
+
115
+ it "should route <%= model_controller_controller_name %>'s 'edit' action correctly" do
116
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'edit', :id => '1').should == "/<%= model_controller_routing_path %>/1/edit"
117
+ end
118
+
119
+ it "should route <%= model_controller_controller_name %>'s 'update' action correctly" do
120
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1').should == "/<%= model_controller_routing_path %>/1"
121
+ end
122
+
123
+ it "should route <%= model_controller_controller_name %>'s 'destroy' action correctly" do
124
+ route_for(:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1').should == "/<%= model_controller_routing_path %>/1"
125
+ end
126
+ end
127
+
128
+ describe "route recognition" do
129
+ it "should generate params for <%= model_controller_controller_name %>'s index action from GET /<%= model_controller_routing_path %>" do
130
+ params_from(:get, '/<%= model_controller_routing_path %>').should == {:controller => '<%= model_controller_controller_name %>', :action => 'index'}
131
+ params_from(:get, '/<%= model_controller_routing_path %>.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'index', :format => 'xml'}
132
+ params_from(:get, '/<%= model_controller_routing_path %>.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'index', :format => 'json'}
133
+ end
134
+
135
+ it "should generate params for <%= model_controller_controller_name %>'s new action from GET /<%= model_controller_routing_path %>" do
136
+ params_from(:get, '/<%= model_controller_routing_path %>/new').should == {:controller => '<%= model_controller_controller_name %>', :action => 'new'}
137
+ params_from(:get, '/<%= model_controller_routing_path %>/new.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'new', :format => 'xml'}
138
+ params_from(:get, '/<%= model_controller_routing_path %>/new.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'new', :format => 'json'}
139
+ end
140
+
141
+ it "should generate params for <%= model_controller_controller_name %>'s create action from POST /<%= model_controller_routing_path %>" do
142
+ params_from(:post, '/<%= model_controller_routing_path %>').should == {:controller => '<%= model_controller_controller_name %>', :action => 'create'}
143
+ params_from(:post, '/<%= model_controller_routing_path %>.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'create', :format => 'xml'}
144
+ params_from(:post, '/<%= model_controller_routing_path %>.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'create', :format => 'json'}
145
+ end
146
+
147
+ it "should generate params for <%= model_controller_controller_name %>'s show action from GET /<%= model_controller_routing_path %>/1" do
148
+ params_from(:get , '/<%= model_controller_routing_path %>/1').should == {:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1'}
149
+ params_from(:get , '/<%= model_controller_routing_path %>/1.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1', :format => 'xml'}
150
+ params_from(:get , '/<%= model_controller_routing_path %>/1.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1', :format => 'json'}
151
+ end
152
+
153
+ it "should generate params for <%= model_controller_controller_name %>'s edit action from GET /<%= model_controller_routing_path %>/1/edit" do
154
+ params_from(:get , '/<%= model_controller_routing_path %>/1/edit').should == {:controller => '<%= model_controller_controller_name %>', :action => 'edit', :id => '1'}
155
+ end
156
+
157
+ it "should generate params {:controller => '<%= model_controller_controller_name %>', :action => update', :id => '1'} from PUT /<%= model_controller_routing_path %>/1" do
158
+ params_from(:put , '/<%= model_controller_routing_path %>/1').should == {:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1'}
159
+ params_from(:put , '/<%= model_controller_routing_path %>/1.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1', :format => 'xml'}
160
+ params_from(:put , '/<%= model_controller_routing_path %>/1.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1', :format => 'json'}
161
+ end
162
+
163
+ it "should generate params for <%= model_controller_controller_name %>'s destroy action from DELETE /<%= model_controller_routing_path %>/1" do
164
+ params_from(:delete, '/<%= model_controller_routing_path %>/1').should == {:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1'}
165
+ params_from(:delete, '/<%= model_controller_routing_path %>/1.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1', :format => 'xml'}
166
+ params_from(:delete, '/<%= model_controller_routing_path %>/1.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1', :format => 'json'}
167
+ end
168
+ end
169
+
170
+ describe "named routing" do
171
+ before(:each) do
172
+ get :new
173
+ end
174
+
175
+ it "should route <%= model_controller_routing_name %>_path() to /<%= model_controller_routing_path %>" do
176
+ <%= model_controller_routing_name %>_path().should == "/<%= model_controller_routing_path %>"
177
+ formatted_<%= model_controller_routing_name %>_path(:format => 'xml').should == "/<%= model_controller_routing_path %>.xml"
178
+ formatted_<%= model_controller_routing_name %>_path(:format => 'json').should == "/<%= model_controller_routing_path %>.json"
179
+ end
180
+
181
+ it "should route new_<%= model_controller_routing_name.singularize %>_path() to /<%= model_controller_routing_path %>/new" do
182
+ new_<%= model_controller_routing_name.singularize %>_path().should == "/<%= model_controller_routing_path %>/new"
183
+ formatted_new_<%= model_controller_routing_name.singularize %>_path(:format => 'xml').should == "/<%= model_controller_routing_path %>/new.xml"
184
+ formatted_new_<%= model_controller_routing_name.singularize %>_path(:format => 'json').should == "/<%= model_controller_routing_path %>/new.json"
185
+ end
186
+
187
+ it "should route <%= model_controller_routing_name.singularize %>_(:id => '1') to /<%= model_controller_routing_path %>/1" do
188
+ <%= model_controller_routing_name.singularize %>_path(:id => '1').should == "/<%= model_controller_routing_path %>/1"
189
+ formatted_<%= model_controller_routing_name.singularize %>_path(:id => '1', :format => 'xml').should == "/<%= model_controller_routing_path %>/1.xml"
190
+ formatted_<%= model_controller_routing_name.singularize %>_path(:id => '1', :format => 'json').should == "/<%= model_controller_routing_path %>/1.json"
191
+ end
192
+
193
+ it "should route edit_<%= model_controller_routing_name.singularize %>_path(:id => '1') to /<%= model_controller_routing_path %>/1/edit" do
194
+ edit_<%= model_controller_routing_name.singularize %>_path(:id => '1').should == "/<%= model_controller_routing_path %>/1/edit"
195
+ end
196
+ end
197
+
198
+ end
@@ -0,0 +1,60 @@
1
+ <%
2
+ ## this code must match that in templates/model.rb
3
+ require 'digest/sha1'
4
+ def make_fake_token
5
+ @fake_token_counter ||= 0
6
+ @fake_token_counter += 1
7
+ Digest::SHA1.hexdigest(@fake_token_counter.to_s)
8
+ end
9
+ salts = (1..2).map{ make_fake_token }
10
+ passwds = salts.map{ |salt| password_digest('monkey', salt) }
11
+ -%>
12
+
13
+ quentin:
14
+ id: 1
15
+ login: quentin
16
+ email: quentin@example.com
17
+ salt: <%= salts[0] %> # SHA1('0')
18
+ crypted_password: <%= passwds[0] %> # 'monkey'
19
+ created_at: <%%= 5.days.ago.to_s :db %>
20
+ remember_token_expires_at: <%%= 1.days.from_now.to_s %>
21
+ remember_token: <%= make_fake_token %>
22
+ <% if options[:include_activation] -%>
23
+ activation_code:
24
+ activated_at: <%%= 5.days.ago.to_s :db %>
25
+ <% end -%>
26
+ <% if options[:stateful] -%>
27
+ state: active
28
+ <% end -%>
29
+
30
+ aaron:
31
+ id: 2
32
+ login: aaron
33
+ email: aaron@example.com
34
+ salt: <%= salts[1] %> # SHA1('1')
35
+ crypted_password: <%= passwds[1] %> # 'monkey'
36
+ created_at: <%%= 1.days.ago.to_s :db %>
37
+ remember_token_expires_at:
38
+ remember_token:
39
+ <% if options[:include_activation] -%>
40
+ activation_code: <%= make_fake_token %>
41
+ activated_at:
42
+ <% end -%>
43
+ <% if options[:stateful] %>
44
+ state: pending
45
+ <% end -%>
46
+
47
+
48
+ old_password_holder:
49
+ id: 3
50
+ login: old_password_holder
51
+ email: salty_dog@example.com
52
+ salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
53
+ crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
54
+ created_at: <%%= 1.days.ago.to_s :db %>
55
+ <% if options[:include_activation] %>
56
+ activation_code:
57
+ activated_at: <%%= 5.days.ago.to_s :db %>
58
+ <% end %>
59
+ <% if options[:stateful] %>
60
+ state: active<% end %>
@@ -0,0 +1,141 @@
1
+ require File.dirname(__FILE__) + '<%= ('/..'*model_controller_class_nesting_depth) + '/../spec_helper' %>'
2
+ include ApplicationHelper
3
+ include <%= model_controller_class_name %>Helper
4
+ include AuthenticatedTestHelper
5
+
6
+ describe <%= model_controller_class_name %>Helper do
7
+ before do
8
+ @<%= file_name %> = mock_<%= file_name %>
9
+ end
10
+
11
+ describe "if_authorized" do
12
+ it "yields if authorized" do
13
+ should_receive(:authorized?).with('a','r').and_return(true)
14
+ if_authorized?('a','r'){|action,resource| [action,resource,'hi'] }.should == ['a','r','hi']
15
+ end
16
+ it "does nothing if not authorized" do
17
+ should_receive(:authorized?).with('a','r').and_return(false)
18
+ if_authorized?('a','r'){ 'hi' }.should be_nil
19
+ end
20
+ end
21
+
22
+ describe "link_to_<%= file_name %>" do
23
+ it "should give an error on a nil <%= file_name %>" do
24
+ lambda { link_to_<%= file_name %>(nil) }.should raise_error('Invalid <%= file_name %>')
25
+ end
26
+ it "should link to the given <%= file_name %>" do
27
+ should_receive(:<%= model_controller_routing_name.singularize %>_path).at_least(:once).and_return('/<%= model_controller_file_path %>/1')
28
+ link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a[href='/<%= model_controller_file_path %>/1']")
29
+ end
30
+ it "should use given link text if :content_text is specified" do
31
+ link_to_<%= file_name %>(@<%= file_name %>, :content_text => 'Hello there!').should have_tag("a", 'Hello there!')
32
+ end
33
+ it "should use the login as link text with no :content_method specified" do
34
+ link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a", 'user_name')
35
+ end
36
+ it "should use the name as link text with :content_method => :name" do
37
+ link_to_<%= file_name %>(@<%= file_name %>, :content_method => :name).should have_tag("a", 'U. Surname')
38
+ end
39
+ it "should use the login as title with no :title_method specified" do
40
+ link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a[title='user_name']")
41
+ end
42
+ it "should use the name as link title with :content_method => :name" do
43
+ link_to_<%= file_name %>(@<%= file_name %>, :title_method => :name).should have_tag("a[title='U. Surname']")
44
+ end
45
+ it "should have nickname as a class by default" do
46
+ link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a.nickname")
47
+ end
48
+ it "should take other classes and no longer have the nickname class" do
49
+ result = link_to_<%= file_name %>(@<%= file_name %>, :class => 'foo bar')
50
+ result.should have_tag("a.foo")
51
+ result.should have_tag("a.bar")
52
+ end
53
+ end
54
+
55
+ describe "link_to_login_with_IP" do
56
+ it "should link to the login_path" do
57
+ link_to_login_with_IP().should have_tag("a[href='/login']")
58
+ end
59
+ it "should use given link text if :content_text is specified" do
60
+ link_to_login_with_IP('Hello there!').should have_tag("a", 'Hello there!')
61
+ end
62
+ it "should use the login as link text with no :content_method specified" do
63
+ link_to_login_with_IP().should have_tag("a", '0.0.0.0')
64
+ end
65
+ it "should use the ip address as title" do
66
+ link_to_login_with_IP().should have_tag("a[title='0.0.0.0']")
67
+ end
68
+ it "should by default be like school in summer and have no class" do
69
+ link_to_login_with_IP().should_not have_tag("a.nickname")
70
+ end
71
+ it "should have some class if you tell it to" do
72
+ result = link_to_login_with_IP(nil, :class => 'foo bar')
73
+ result.should have_tag("a.foo")
74
+ result.should have_tag("a.bar")
75
+ end
76
+ it "should have some class if you tell it to" do
77
+ result = link_to_login_with_IP(nil, :tag => 'abbr')
78
+ result.should have_tag("abbr[title='0.0.0.0']")
79
+ end
80
+ end
81
+
82
+ describe "link_to_current_<%= file_name %>, When logged in" do
83
+ before do
84
+ stub!(:current_<%= file_name %>).and_return(@<%= file_name %>)
85
+ end
86
+ it "should link to the given <%= file_name %>" do
87
+ should_receive(:<%= model_controller_routing_name.singularize %>_path).at_least(:once).and_return('/<%= model_controller_file_path %>/1')
88
+ link_to_current_<%= file_name %>().should have_tag("a[href='/<%= model_controller_file_path %>/1']")
89
+ end
90
+ it "should use given link text if :content_text is specified" do
91
+ link_to_current_<%= file_name %>(:content_text => 'Hello there!').should have_tag("a", 'Hello there!')
92
+ end
93
+ it "should use the login as link text with no :content_method specified" do
94
+ link_to_current_<%= file_name %>().should have_tag("a", 'user_name')
95
+ end
96
+ it "should use the name as link text with :content_method => :name" do
97
+ link_to_current_<%= file_name %>(:content_method => :name).should have_tag("a", 'U. Surname')
98
+ end
99
+ it "should use the login as title with no :title_method specified" do
100
+ link_to_current_<%= file_name %>().should have_tag("a[title='user_name']")
101
+ end
102
+ it "should use the name as link title with :content_method => :name" do
103
+ link_to_current_<%= file_name %>(:title_method => :name).should have_tag("a[title='U. Surname']")
104
+ end
105
+ it "should have nickname as a class" do
106
+ link_to_current_<%= file_name %>().should have_tag("a.nickname")
107
+ end
108
+ it "should take other classes and no longer have the nickname class" do
109
+ result = link_to_current_<%= file_name %>(:class => 'foo bar')
110
+ result.should have_tag("a.foo")
111
+ result.should have_tag("a.bar")
112
+ end
113
+ end
114
+
115
+ describe "link_to_current_<%= file_name %>, When logged out" do
116
+ before do
117
+ stub!(:current_<%= file_name %>).and_return(nil)
118
+ end
119
+ it "should link to the login_path" do
120
+ link_to_current_<%= file_name %>().should have_tag("a[href='/login']")
121
+ end
122
+ it "should use given link text if :content_text is specified" do
123
+ link_to_current_<%= file_name %>(:content_text => 'Hello there!').should have_tag("a", 'Hello there!')
124
+ end
125
+ it "should use 'not signed in' as link text with no :content_method specified" do
126
+ link_to_current_<%= file_name %>().should have_tag("a", 'not signed in')
127
+ end
128
+ it "should use the ip address as title" do
129
+ link_to_current_<%= file_name %>().should have_tag("a[title='0.0.0.0']")
130
+ end
131
+ it "should by default be like school in summer and have no class" do
132
+ link_to_current_<%= file_name %>().should_not have_tag("a.nickname")
133
+ end
134
+ it "should have some class if you tell it to" do
135
+ result = link_to_current_<%= file_name %>(:class => 'foo bar')
136
+ result.should have_tag("a.foo")
137
+ result.should have_tag("a.bar")
138
+ end
139
+ end
140
+
141
+ end