Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rails 3 compatability

  • Loading branch information...
commit cf487585eb4420db50f04a6a79a018793e99e216 1 parent 06933ae
@rwdaigle authored
Showing with 449 additions and 25,453 deletions.
  1. +9 −8 Gemfile
  2. +96 −69 Gemfile.lock
  3. +0 −24 app/controllers/application.rb
  4. +2 −0  app/controllers/application_controller.rb
  5. +41 −0 app/controllers/sessions_controller.rb
  6. +51 −7 app/models/user.rb
  7. +6 −6 config/database.yml
  8. +2 −2 config/initializers/libs.rb
  9. +38 −0 config/initializers/site_keys.rb
  10. +1 −1  config/unicorn.rb
  11. +49 −0 lib/acts_as_timed.rb
  12. +85 −11 lib/authenticated_system.rb
  13. +3 −2 lib/authenticated_test_helper.rb
  14. +0 −19 spec/fixtures/users.yml
  15. +0 −4 spec/scenarios/default_scenario.rb
  16. +0 −7 spec/scenarios/users_scenario.rb
  17. +65 −32 spec/spec_helper.rb
  18. +0 −4 stories/all.rb
  19. +0 −3  stories/helper.rb
  20. 0  test/fixtures/.gitkeep
  21. 0  test/functional/.gitkeep
  22. 0  test/integration/.gitkeep
  23. +0 −12 test/performance/browsing_test.rb
  24. +0 −13 test/test_helper.rb
  25. 0  test/unit/.gitkeep
  26. +0 −51 vendor/plugins/acts_as_timed/lib/active_record/acts/timed.rb
  27. +0 −18 vendor/plugins/haml/init.rb
  28. +0 −87 vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb
  29. +0 −5 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb
  30. +0 −10 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml
  31. +0 −57 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb
  32. +0 −2  vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb
  33. +0 −13 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb
  34. +0 −2  vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb
  35. +0 −7 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb
  36. +0 −5 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml
  37. +0 −11 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml
  38. +0 −5 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml
  39. +0 −9 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml
  40. +0 −12 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml
  41. +0 −14 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml
  42. +0 −335 vendor/plugins/make_resourceful/lib/resourceful/builder.rb
  43. +0 −346 vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb
  44. +0 −92 vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb
  45. +0 −50 vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb
  46. +0 −118 vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb
  47. +0 −137 vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb
  48. +0 −83 vendor/plugins/make_resourceful/lib/resourceful/maker.rb
  49. +0 −33 vendor/plugins/make_resourceful/lib/resourceful/response.rb
  50. +0 −181 vendor/plugins/make_resourceful/lib/resourceful/serialize.rb
  51. +0 −35 vendor/plugins/make_resourceful/spec/rspec_on_rails/LICENSE
  52. +0 −81 vendor/plugins/make_resourceful/spec/rspec_on_rails/redirect_to.rb
  53. +0 −28 vendor/plugins/make_resourceful/spec/rspec_on_rails/render_template.rb
  54. +0 −11 vendor/plugins/permalink_fu/README
  55. +0 −1  vendor/plugins/permalink_fu/init.rb
  56. +1 −0  vendor/plugins/restful-authentication
  57. +0 −1  vendor/plugins/restful_authentication/generators/authenticated/USAGE
  58. +0 −263 vendor/plugins/restful_authentication/generators/authenticated/authenticated_generator.rb
  59. +0 −3  vendor/plugins/restful_authentication/generators/authenticated/templates/activation.html.erb
  60. +0 −115 vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb
  61. +0 −10 vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_test_helper.rb
  62. +0 −31 vendor/plugins/restful_authentication/generators/authenticated/templates/controller.rb
  63. +0 −19 vendor/plugins/restful_authentication/generators/authenticated/templates/fixtures.yml
  64. +0 −74 vendor/plugins/restful_authentication/generators/authenticated/templates/functional_spec.rb
  65. +0 −85 vendor/plugins/restful_authentication/generators/authenticated/templates/functional_test.rb
  66. +0 −2  vendor/plugins/restful_authentication/generators/authenticated/templates/helper.rb
  67. +0 −14 vendor/plugins/restful_authentication/generators/authenticated/templates/login.html.erb
  68. +0 −25 vendor/plugins/restful_authentication/generators/authenticated/templates/mailer.rb
  69. +0 −31 vendor/plugins/restful_authentication/generators/authenticated/templates/mailer_test.rb
  70. +0 −22 vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb
  71. +0 −142 vendor/plugins/restful_authentication/generators/authenticated/templates/model.rb
  72. +0 −65 vendor/plugins/restful_authentication/generators/authenticated/templates/model_controller.rb
  73. +0 −86 vendor/plugins/restful_authentication/generators/authenticated/templates/model_functional_spec.rb
  74. +0 −99 vendor/plugins/restful_authentication/generators/authenticated/templates/model_functional_test.rb
  75. +0 −2  vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper.rb
  76. +0 −11 vendor/plugins/restful_authentication/generators/authenticated/templates/observer.rb
  77. +0 −16 vendor/plugins/restful_authentication/generators/authenticated/templates/signup.html.erb
  78. +0 −8 vendor/plugins/restful_authentication/generators/authenticated/templates/signup_notification.html.erb
  79. +0 −174 vendor/plugins/restful_authentication/generators/authenticated/templates/unit_spec.rb
  80. +0 −164 vendor/plugins/restful_authentication/generators/authenticated/templates/unit_test.rb
  81. +0 −29 vendor/plugins/restful_authentication/lib/restful_authentication/rails_commands.rb
  82. +0 −3  vendor/plugins/rspec/.autotest
  83. +0 −1,045 vendor/plugins/rspec/CHANGES
  84. +0 −20 vendor/plugins/rspec/MIT-LICENSE
  85. +0 −71 vendor/plugins/rspec/README
  86. +0 −279 vendor/plugins/rspec/Rakefile
  87. +0 −2  vendor/plugins/rspec/TODO
  88. +0 −31 vendor/plugins/rspec/UPGRADE
  89. +0 −4 vendor/plugins/rspec/bin/spec
  90. +0 −19 vendor/plugins/rspec/examples/pure/autogenerated_docstrings_example.rb
  91. +0 −40 vendor/plugins/rspec/examples/pure/before_and_after_example.rb
  92. +0 −54 vendor/plugins/rspec/examples/pure/custom_expectation_matchers.rb
  93. +0 −38 vendor/plugins/rspec/examples/pure/file_accessor_spec.rb
  94. +0 −14 vendor/plugins/rspec/examples/pure/helper_method_example.rb
  95. +0 −28 vendor/plugins/rspec/examples/pure/multi_threaded_behaviour_runner.rb
  96. +0 −36 vendor/plugins/rspec/examples/pure/nested_classes_example.rb
  97. +0 −28 vendor/plugins/rspec/examples/pure/partial_mock_example.rb
  98. +0 −81 vendor/plugins/rspec/examples/pure/shared_example_group_example.rb
  99. +0 −38 vendor/plugins/rspec/examples/pure/shared_stack_examples.rb
  100. +0 −67 vendor/plugins/rspec/examples/pure/stack_spec_with_nested_example_groups.rb
  101. +0 −5 vendor/plugins/rspec/examples/stories/game-of-life/.loadpath
  102. +0 −21 vendor/plugins/rspec/examples/stories/game-of-life/README.txt
  103. +0 −6 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/everything.rb
  104. +0 −3  vendor/plugins/rspec/examples/stories/game-of-life/behaviour/examples/examples.rb
  105. +0 −35 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb
  106. +0 −66 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
  107. +0 −21 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story
  108. +0 −21 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story
  109. +0 −42 ...ugins/rspec/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story
  110. +0 −42 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story
  111. +0 −17 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story
  112. +0 −53 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story
  113. +0 −52 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb
  114. +0 −6 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/helper.rb
  115. +0 −26 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb
  116. +0 −5 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/steps.rb
  117. +0 −3  vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/stories.rb
  118. +0 −22 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/stories/stories.txt
  119. +0 −3  vendor/plugins/rspec/examples/stories/game-of-life/life.rb
  120. +0 −23 vendor/plugins/rspec/examples/stories/game-of-life/life/game.rb
  121. +0 −43 vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb
  122. +0 −18 vendor/plugins/rspec/examples/stories/steps/addition_steps.rb
  123. +0 −19 vendor/plugins/rspec/failing_examples/failing_autogenerated_docstrings_example.rb
  124. +0 −10 vendor/plugins/rspec/failing_examples/failure_in_setup.rb
  125. +0 −10 vendor/plugins/rspec/failing_examples/failure_in_teardown.rb
  126. +0 −40 vendor/plugins/rspec/failing_examples/mocking_example.rb
  127. +0 −26 vendor/plugins/rspec/failing_examples/mocking_with_flexmock.rb
  128. +0 −25 vendor/plugins/rspec/failing_examples/mocking_with_mocha.rb
  129. +0 −27 vendor/plugins/rspec/failing_examples/mocking_with_rr.rb
  130. +0 −20 vendor/plugins/rspec/failing_examples/partial_mock_example.rb
  131. +0 −29 vendor/plugins/rspec/failing_examples/predicate_example.rb
  132. +0 −47 vendor/plugins/rspec/failing_examples/raising_example.rb
  133. +0 −7 vendor/plugins/rspec/failing_examples/syntax_error_example.rb
  134. +0 −7 vendor/plugins/rspec/failing_examples/timeout_behaviour.rb
  135. +0 −9 vendor/plugins/rspec/init.rb
  136. +0 −30 vendor/plugins/rspec/lib/spec.rb
  137. +0 −62 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
  138. +0 −424 vendor/plugins/rspec/lib/spec/example/example_group_methods.rb
  139. +0 −42 vendor/plugins/rspec/lib/spec/example/example_matcher.rb
  140. +0 −106 vendor/plugins/rspec/lib/spec/example/example_methods.rb
  141. +0 −21 vendor/plugins/rspec/lib/spec/example/module_reopening_fix.rb
  142. +0 −58 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
  143. +0 −66 vendor/plugins/rspec/lib/spec/expectations/differs/default.rb
  144. +0 −2  vendor/plugins/rspec/lib/spec/expectations/extensions.rb
  145. +0 −71 vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb
  146. +0 −17 vendor/plugins/rspec/lib/spec/expectations/extensions/string_and_symbol.rb
  147. +0 −6 vendor/plugins/rspec/lib/spec/interop/test/unit/autorunner.rb
  148. +0 −61 vendor/plugins/rspec/lib/spec/interop/test/unit/testcase.rb
  149. +0 −6 vendor/plugins/rspec/lib/spec/interop/test/unit/testresult.rb
  150. +0 −34 vendor/plugins/rspec/lib/spec/interop/test/unit/testsuite_adapter.rb
  151. +0 −61 vendor/plugins/rspec/lib/spec/interop/test/unit/ui/console/testrunner.rb
  152. +0 −73 vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb
  153. +0 −27 vendor/plugins/rspec/lib/spec/mocks/argument_constraint_matchers.rb
  154. +0 −183 vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb
  155. +0 −3  vendor/plugins/rspec/lib/spec/mocks/extensions/object.rb
  156. +0 −267 vendor/plugins/rspec/lib/spec/mocks/message_expectation.rb
  157. +0 −57 vendor/plugins/rspec/lib/spec/runner/backtrace_tweaker.rb
  158. +0 −16 vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb
  159. +0 −20 vendor/plugins/rspec/lib/spec/runner/drb_command_line.rb
  160. +0 −59 vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb
  161. +0 −78 vendor/plugins/rspec/lib/spec/runner/formatter/base_formatter.rb
  162. +0 −130 vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb
  163. +0 −31 vendor/plugins/rspec/lib/spec/runner/formatter/failing_example_groups_formatter.rb
  164. +0 −20 vendor/plugins/rspec/lib/spec/runner/formatter/failing_examples_formatter.rb
  165. +0 −333 vendor/plugins/rspec/lib/spec/runner/formatter/html_formatter.rb
  166. +0 −47 vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
  167. +0 −30 vendor/plugins/rspec/lib/spec/runner/formatter/progress_bar_formatter.rb
  168. +0 −52 vendor/plugins/rspec/lib/spec/runner/formatter/snippet_extractor.rb
  169. +0 −39 vendor/plugins/rspec/lib/spec/runner/formatter/specdoc_formatter.rb
  170. +0 −128 vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb
  171. +0 −131 vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb
  172. +0 −16 vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb
  173. +0 −10 vendor/plugins/rspec/lib/spec/runner/heckle_runner_unsupported.rb
  174. +0 −9 vendor/plugins/rspec/lib/spec/story/extensions/regexp.rb
  175. +0 −9 vendor/plugins/rspec/lib/spec/story/extensions/string.rb
  176. +0 −48 vendor/plugins/rspec/lib/spec/story/runner/plain_text_story_runner.rb
  177. +0 −18 vendor/plugins/rspec/lib/spec/story/runner/scenario_collector.rb
  178. +0 −46 vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb
  179. +0 −123 vendor/plugins/rspec/lib/spec/story/runner/story_mediator.rb
  180. +0 −227 vendor/plugins/rspec/lib/spec/story/runner/story_parser.rb
  181. +0 −68 vendor/plugins/rspec/lib/spec/story/runner/story_runner.rb
  182. +0 −23 vendor/plugins/rspec/plugins/mock_frameworks/flexmock.rb
  183. +0 −54 vendor/plugins/rspec/pre_commit/lib/pre_commit/pre_commit.rb
  184. +0 −313 vendor/plugins/rspec/pre_commit/lib/pre_commit/rspec_on_rails.rb
  185. +0 −15 vendor/plugins/rspec/pre_commit/spec/pre_commit/pre_commit_spec.rb
  186. +0 −36 vendor/plugins/rspec/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb
  187. +0 −9 vendor/plugins/rspec/rake_tasks/failing_examples_with_html.rake
  188. +0 −4,358 vendor/plugins/rspec/report.html
  189. +0 −6 vendor/plugins/rspec/spec/spec.opts
  190. +0 −282 vendor/plugins/rspec/spec/spec/example/configuration_spec.rb
  191. +0 −48 vendor/plugins/rspec/spec/spec/example/example_group_class_definition_spec.rb
  192. +0 −129 vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb
  193. +0 −489 vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb
  194. +0 −711 vendor/plugins/rspec/spec/spec/example/example_group_spec.rb
  195. +0 −96 vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb
  196. +0 −104 vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb
  197. +0 −194 vendor/plugins/rspec/spec/spec/example/example_runner_spec.rb
  198. +0 −59 vendor/plugins/rspec/spec/spec/example/nested_example_group_spec.rb
  199. +0 −31 vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb
  200. +0 −21 vendor/plugins/rspec/spec/spec/example/predicate_matcher_spec.rb
  201. +0 −265 vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb
  202. +0 −25 vendor/plugins/rspec/spec/spec/example/subclassing_example_group_spec.rb
  203. +0 −109 vendor/plugins/rspec/spec/spec/expectations/differs/default_spec.rb
  204. +0 −107 vendor/plugins/rspec/spec/spec/expectations/extensions/object_spec.rb
  205. +0 −71 vendor/plugins/rspec/spec/spec/expectations/fail_with_spec.rb
  206. +0 −10 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_that_fails.rb
  207. +0 −10 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_that_passes.rb
  208. +0 −10 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_errors.rb
  209. +0 −10 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/test_case_that_fails.rb
  210. +0 −10 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/test_case_that_passes.rb
  211. +0 −10 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/test_case_with_errors.rb
  212. +0 −38 vendor/plugins/rspec/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb
  213. +0 −45 vendor/plugins/rspec/spec/spec/interop/test/unit/spec_spec.rb
  214. +0 −14 vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb
  215. +0 −45 vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb
  216. +0 −9 vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec.rb
  217. +0 −39 vendor/plugins/rspec/spec/spec/matchers/be_close_spec.rb
  218. +0 −153 vendor/plugins/rspec/spec/spec/matchers/description_generation_spec.rb
  219. +0 −78 vendor/plugins/rspec/spec/spec/matchers/matcher_methods_spec.rb
  220. +0 −24 vendor/plugins/rspec/spec/spec/matchers/mock_constraint_matchers_spec.rb
  221. +0 −158 vendor/plugins/rspec/spec/spec/matchers/operator_matcher_spec.rb
  222. +0 −191 vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb
  223. +0 −54 vendor/plugins/rspec/spec/spec/matchers/respond_to_spec.rb
  224. +0 −31 vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb
  225. +0 −54 vendor/plugins/rspec/spec/spec/matchers/throw_symbol_spec.rb
  226. +0 −29 vendor/plugins/rspec/spec/spec/mocks/any_number_of_times_spec.rb
  227. +0 −23 vendor/plugins/rspec/spec/spec/mocks/argument_expectation_spec.rb
  228. +0 −8 vendor/plugins/rspec/spec/spec/mocks/bug_report_10260_spec.rb
  229. +0 −24 vendor/plugins/rspec/spec/spec/mocks/bug_report_10263.rb
  230. +0 −31 vendor/plugins/rspec/spec/spec/mocks/bug_report_11545_spec.rb
  231. +0 −30 vendor/plugins/rspec/spec/spec/mocks/bug_report_15719_spec.rb
  232. +0 −19 vendor/plugins/rspec/spec/spec/mocks/bug_report_7611_spec.rb
  233. +0 −22 vendor/plugins/rspec/spec/spec/mocks/bug_report_7805_spec.rb
  234. +0 −31 vendor/plugins/rspec/spec/spec/mocks/bug_report_8165_spec.rb
  235. +0 −26 vendor/plugins/rspec/spec/spec/mocks/bug_report_8302_spec.rb
  236. +0 −115 vendor/plugins/rspec/spec/spec/mocks/failing_mock_argument_constraints_spec.rb
  237. +0 −84 vendor/plugins/rspec/spec/spec/mocks/mock_ordering_spec.rb
  238. +0 −113 vendor/plugins/rspec/spec/spec/mocks/multiple_return_value_spec.rb
  239. +0 −40 vendor/plugins/rspec/spec/spec/mocks/null_object_mock_spec.rb
  240. +0 −53 vendor/plugins/rspec/spec/spec/mocks/once_counts_spec.rb
  241. +0 −45 vendor/plugins/rspec/spec/spec/mocks/options_hash_spec.rb
  242. +0 −106 vendor/plugins/rspec/spec/spec/mocks/partial_mock_spec.rb
  243. +0 −66 vendor/plugins/rspec/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb
  244. +0 −154 vendor/plugins/rspec/spec/spec/mocks/passing_mock_argument_constraints_spec.rb
  245. +0 −52 vendor/plugins/rspec/spec/spec/mocks/precise_counts_spec.rb
  246. +0 −26 vendor/plugins/rspec/spec/spec/mocks/record_messages_spec.rb
  247. +0 −67 vendor/plugins/rspec/spec/spec/mocks/twice_counts_spec.rb
  248. +0 −23 vendor/plugins/rspec/spec/spec/runner/class_and_argument_parser_spec.rb
  249. +0 −147 vendor/plugins/rspec/spec/spec/runner/command_line_spec.rb
  250. +0 −92 vendor/plugins/rspec/spec/spec/runner/drb_command_line_spec.rb
  251. +0 −31 vendor/plugins/rspec/spec/spec/runner/execution_context_spec.rb
  252. +0 −44 vendor/plugins/rspec/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb
  253. +0 −33 vendor/plugins/rspec/spec/spec/runner/formatter/failing_examples_formatter_spec.rb
  254. +0 −365 vendor/plugins/rspec/spec/spec/runner/formatter/html_formatted-1.8.4.html
  255. +0 −387 vendor/plugins/rspec/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html
  256. +0 −371 vendor/plugins/rspec/spec/spec/runner/formatter/html_formatted-1.8.5.html
  257. +0 −381 vendor/plugins/rspec/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html
  258. +0 −365 vendor/plugins/rspec/spec/spec/runner/formatter/html_formatted-1.8.6.html
  259. +0 −66 vendor/plugins/rspec/spec/spec/runner/formatter/html_formatter_spec.rb
  260. +0 −65 vendor/plugins/rspec/spec/spec/runner/formatter/profile_formatter_spec.rb
  261. +0 −127 vendor/plugins/rspec/spec/spec/runner/formatter/progress_bar_formatter_spec.rb
  262. +0 −18 vendor/plugins/rspec/spec/spec/runner/formatter/snippet_extractor_spec.rb
  263. +0 −103 vendor/plugins/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb
  264. +0 −126 vendor/plugins/rspec/spec/spec/runner/formatter/specdoc_formatter_spec.rb
  265. +0 −61 vendor/plugins/rspec/spec/spec/runner/formatter/story/html_formatter_spec.rb
  266. +0 −335 vendor/plugins/rspec/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb
  267. +0 −365 vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html
  268. +0 −365 vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html
  269. +0 −78 vendor/plugins/rspec/spec/spec/runner/heckle_runner_spec.rb
  270. +0 −45 vendor/plugins/rspec/spec/spec/runner/noisy_backtrace_tweaker_spec.rb
  271. +0 −378 vendor/plugins/rspec/spec/spec/runner/option_parser_spec.rb
  272. +0 −7 vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture.rb
  273. +0 −8 vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture_runner.rb
  274. +0 −16 vendor/plugins/rspec/spec/spec/runner/output_one_time_spec.rb
  275. +0 −56 vendor/plugins/rspec/spec/spec/runner/quiet_backtrace_tweaker_spec.rb
  276. 0  vendor/plugins/rspec/spec/spec/runner/resources/a_bar.rb
  277. 0  vendor/plugins/rspec/spec/spec/runner/resources/a_foo.rb
  278. +0 −1  vendor/plugins/rspec/spec/spec/runner/resources/a_spec.rb
  279. +0 −70 vendor/plugins/rspec/spec/spec/runner/spec_parser/spec_parser_fixture.rb
  280. +0 −79 vendor/plugins/rspec/spec/spec/runner/spec_parser_spec.rb
  281. +0 −161 vendor/plugins/rspec/spec/spec/story/extensions/main_spec.rb
  282. +0 −27 vendor/plugins/rspec/spec/spec/story/given_scenario_spec.rb
  283. +0 −92 vendor/plugins/rspec/spec/spec/story/runner/plain_text_story_runner_spec.rb
  284. +0 −27 vendor/plugins/rspec/spec/spec/story/runner/scenario_collector_spec.rb
  285. +0 −142 vendor/plugins/rspec/spec/spec/story/runner/scenario_runner_spec.rb
  286. +0 −133 vendor/plugins/rspec/spec/spec/story/runner/story_mediator_spec.rb
  287. +0 −384 vendor/plugins/rspec/spec/spec/story/runner/story_parser_spec.rb
  288. +0 −256 vendor/plugins/rspec/spec/spec/story/runner/story_runner_spec.rb
  289. +0 −72 vendor/plugins/rspec/spec/spec/story/step_mother_spec.rb
  290. +0 −5 vendor/plugins/rspec/stories/all.rb
  291. +0 −45 vendor/plugins/rspec/stories/example_groups/autogenerated_docstrings
  292. +0 −17 vendor/plugins/rspec/stories/example_groups/example_group_with_should_methods
  293. +0 −17 vendor/plugins/rspec/stories/example_groups/nested_groups
  294. +0 −30 vendor/plugins/rspec/stories/interop/examples_and_tests_together
  295. +0 −17 vendor/plugins/rspec/stories/interop/test_case_with_should_methods
  296. +0 −9 vendor/plugins/rspec/stories/resources/helpers/cmdline.rb
  297. +0 −16 vendor/plugins/rspec/stories/resources/helpers/story_helper.rb
  298. +0 −37 vendor/plugins/rspec/stories/resources/matchers/smart_match.rb
  299. +0 −12 vendor/plugins/rspec/stories/resources/spec/example_group_with_should_methods.rb
  300. +0 −8 vendor/plugins/rspec/stories/resources/spec/simple_spec.rb
Sorry, we could not display the entire diff because too many files (448) changed.
View
17 Gemfile
@@ -1,32 +1,33 @@
source 'http://rubygems.org'
-gem 'rails', '~> 3.1'
+gem 'rails', '~> 3.2'
+gem 'rails_log_stdout'
gem 'will_paginate'
gem 'permalink_fu'
gem 'pg'
+gem 'make_resourceful'
gem 'haml'
+gem 'sass'
gem 'jquery-rails'
gem 'unicorn'
group :development do
+ gem 'rspec-rails'
+ gem 'heroku'
gem 'foreman'
end
group :test do
- # Pretty printed test output
gem 'turn', '0.8.2', :require => false
gem 'scenarios'
end
-group :production do
-end
-
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'sass-rails', '~> 3.1.5'
- gem 'coffee-rails', '~> 3.1.1'
- gem 'uglifier', '>= 1.0.3'
+ gem 'sass-rails'
+ gem 'coffee-rails'
+ gem 'uglifier'
end
View
165 Gemfile.lock
@@ -1,106 +1,128 @@
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.1.3)
- actionpack (= 3.1.3)
- mail (~> 2.3.0)
- actionpack (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- i18n (~> 0.6)
- rack (~> 1.3.5)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
rack-cache (~> 1.1)
- rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.0.3)
- activemodel (3.1.3)
- activesupport (= 3.1.3)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
builder (~> 3.0.0)
- i18n (~> 0.6)
- activerecord (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
- arel (~> 2.2.1)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
- activesupport (3.1.3)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
multi_json (~> 1.0)
- ansi (1.4.1)
- arel (2.2.1)
+ addressable (2.2.7)
+ ansi (1.4.2)
+ arel (3.0.2)
builder (3.0.0)
- coffee-rails (3.1.1)
+ coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
- railties (~> 3.1.0)
+ railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ diff-lcs (1.1.3)
erubis (2.7.0)
- execjs (1.2.13)
+ execjs (1.3.0)
multi_json (~> 1.0)
- foreman (0.27.0)
- term-ansicolor (~> 1.0.5)
+ foreman (0.40.0)
+ term-ansicolor (~> 1.0.7)
thor (>= 0.13.6)
haml (3.1.4)
+ heroku (2.21.2)
+ launchy (>= 0.3.2)
+ rest-client (~> 1.6.1)
+ rubyzip
+ term-ansicolor (~> 1.0.5)
hike (1.2.1)
i18n (0.6.0)
- jquery-rails (1.0.19)
- railties (~> 3.0)
+ journey (1.0.3)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
- json (1.6.3)
- kgio (2.7.0)
- mail (2.3.0)
+ json (1.6.5)
+ kgio (2.7.2)
+ launchy (2.0.5)
+ addressable (~> 2.2.6)
+ mail (2.4.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ make_resourceful (1.0.1)
mime-types (1.17.2)
- multi_json (1.0.4)
+ multi_json (1.1.0)
permalink_fu (1.0.0)
- pg (0.12.0)
- rake-compiler (~> 0.7)
+ pg (0.13.2)
polyglot (0.3.3)
- rack (1.3.5)
- rack-cache (1.1)
+ rack (1.4.1)
+ rack-cache (1.2)
rack (>= 0.4)
- rack-mount (0.8.3)
- rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.1.3)
- actionmailer (= 3.1.3)
- actionpack (= 3.1.3)
- activerecord (= 3.1.3)
- activeresource (= 3.1.3)
- activesupport (= 3.1.3)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
bundler (~> 1.0)
- railties (= 3.1.3)
- railties (3.1.3)
- actionpack (= 3.1.3)
- activesupport (= 3.1.3)
+ railties (= 3.2.2)
+ rails_log_stdout (0.1.1)
+ rails (~> 3.2.0)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
raindrops (0.8.0)
rake (0.9.2.2)
- rake-compiler (0.7.9)
- rake
rdoc (3.12)
json (~> 1.4)
- sass (3.1.12)
- sass-rails (3.1.5)
- actionpack (~> 3.1.0)
- railties (~> 3.1.0)
- sass (~> 3.1.10)
- tilt (~> 1.3.2)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
+ rubyzip (0.9.6.1)
+ sass (3.1.15)
+ sass-rails (3.2.4)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
scenarios (0.1.1)
- sprockets (2.0.3)
+ sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
@@ -112,30 +134,35 @@ GEM
polyglot (>= 0.3.1)
turn (0.8.2)
ansi (>= 1.2.2)
- tzinfo (0.3.31)
- uglifier (1.2.0)
+ tzinfo (0.3.32)
+ uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
- unicorn (4.1.1)
- kgio (~> 2.4)
+ unicorn (4.2.0)
+ kgio (~> 2.6)
rack
- raindrops (~> 0.6)
- will_paginate (3.0.2)
+ raindrops (~> 0.7)
+ will_paginate (3.0.3)
PLATFORMS
ruby
DEPENDENCIES
- coffee-rails (~> 3.1.1)
+ coffee-rails
foreman
haml
+ heroku
jquery-rails
+ make_resourceful
permalink_fu
pg
- rails (~> 3.1)
- sass-rails (~> 3.1.5)
+ rails (~> 3.2)
+ rails_log_stdout
+ rspec-rails
+ sass
+ sass-rails
scenarios
turn (= 0.8.2)
- uglifier (>= 1.0.3)
+ uglifier
unicorn
will_paginate
View
24 app/controllers/application.rb
@@ -1,24 +0,0 @@
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class ApplicationController < ActionController::Base
-
- # Standard configs
- helper :all
- include AuthenticatedSystem
- protect_from_forgery
-
- # Most everything requires a logged in user
- before_filter :login_required
- before_filter :set_user_time_zone
-
- # Assume we want the subject-relevant layout unless told otherwise
- layout 'subject'
-
- private
-
- # User-specific time zones
- def set_user_time_zone
- Time.zone = current_user.time_zone if logged_in?
- end
-end
View
2  app/controllers/application_controller.rb
@@ -1,3 +1,5 @@
+require 'authenticated_system'
+
class ApplicationController < ActionController::Base
# Standard configs
View
41 app/controllers/sessions_controller.rb
@@ -0,0 +1,41 @@
+# This controller handles the login/logout function of the site.
+class SessionsController < ApplicationController
+
+ skip_before_filter :login_required
+
+ # render new.rhtml
+ def new
+ end
+
+ def create
+ logout_keeping_session!
+ user = User.authenticate(params[:login], params[:password])
+ if user
+ # Protects against session fixation attacks, causes request forgery
+ # protection if user resubmits an earlier form using back
+ # button. Uncomment if you understand the tradeoffs.
+ # reset_session
+ self.current_user = user
+ new_cookie_flag = (params[:remember_me] == "1")
+ handle_remember_cookie! new_cookie_flag
+ redirect_back_or_default('/', :notice => "Logged in successfully")
+ else
+ note_failed_signin
+ @login = params[:login]
+ @remember_me = params[:remember_me]
+ render :action => 'new'
+ end
+ end
+
+ def destroy
+ logout_killing_session!
+ redirect_back_or_default('/', :notice => "You have been logged out.")
+ end
+
+protected
+ # Track failed login attempts
+ def note_failed_signin
+ flash.now[:error] = "Couldn't log you in as '#{params[:login]}'"
+ logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}"
+ end
+end
View
58 app/models/user.rb
@@ -1,24 +1,68 @@
-# require 'authentication/restful'
require 'ptls/learning'
require 'ptls/reviewing'
+require 'digest/sha1'
class User < ActiveRecord::Base
-
- # include Authentication::Restful
+
+ include Authentication
+ include Authentication::ByPassword
+ include Authentication::ByCookieToken
+
include Ptls::User::Learning
include Ptls::User::Reviewing
-
+
+ validates :login, :presence => true,
+ :uniqueness => true,
+ :length => { :within => 3..40 },
+ :format => { :with => Authentication.login_regex, :message => Authentication.bad_login_message }
+
+ validates :name, :format => { :with => Authentication.name_regex, :message => Authentication.bad_name_message },
+ :length => { :maximum => 100 },
+ :allow_nil => true
+
+ validates :email, :presence => true,
+ :uniqueness => true,
+ :format => { :with => Authentication.email_regex, :message => Authentication.bad_email_message },
+ :length => { :within => 6..100 }
+
# Basic validations
validates_numericality_of :daily_units, :integer_only => true, :less_than_or_equal_to => 100, :greater_than_or_equal_to => 1
-
+
+
+ # HACK HACK HACK -- how to do attr_accessible from here?
+ # prevents a user from submitting a crafted form that bypasses activation
+ # anything else you want your user to change should be added here.
+ attr_accessible :login, :email, :name, :password, :password_confirmation
+
# Basic associations
has_many :learnings
has_many :reviews
has_many :associations
has_many :subjects, :foreign_key => :owner_id
-
+
+ # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
+ #
+ # uff. this is really an authorization, not authentication routine.
+ # We really need a Dispatch Chain here or something.
+ # This will also let us return a human error message.
+ #
+ def self.authenticate(login, password)
+ return nil if login.blank? || password.blank?
+ u = find_by_login(login.downcase) # need to get the salt
+ u && u.authenticated?(password) ? u : nil
+ end
+
+ def login=(value)
+ write_attribute :login, (value ? value.downcase : nil)
+ end
+
+ def email=(value)
+ write_attribute :email, (value ? value.downcase : nil)
+ end
+
# Does this user own the given subject?
def owns?(subject)
subjects.include?(subject)
end
-end
+
+end
View
12 config/database.yml
@@ -1,14 +1,14 @@
development:
adapter: postgresql
database: ptls
- username: root
+ username: rdaigle
password:
- # Connect on a TCP socket. Omitted by default since the client uses a
- # domain socket that doesn't need configuration. Windows does not have
- # domain sockets, so uncomment these lines.
- host: localhost
- port: 5432
+test:
+ adapter: postgresql
+ database: ptls-test
+ username: rdaigle
+ password:
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
View
4 config/initializers/libs.rb
@@ -1,3 +1,3 @@
-# require 'acts_as_timed'
+require 'acts_as_timed'
# Learning.class_eval { include ActsAsTimed }
-# ActiveRecord::Base.class_eval { include ActsAsTimed }
+ActiveRecord::Base.class_eval { include ActiveRecord::ActsAsTimed }
View
38 config/initializers/site_keys.rb
@@ -0,0 +1,38 @@
+
+# A Site key gives additional protection against a dictionary attack if your
+# DB is ever compromised. With no site key, we store
+# DB_password = hash(user_password, DB_user_salt)
+# If your database were to be compromised you'd be vulnerable to a dictionary
+# attack on all your stupid users' passwords. With a site key, we store
+# DB_password = hash(user_password, DB_user_salt, Code_site_key)
+# That means an attacker needs access to both your site's code *and* its
+# database to mount an "offline dictionary attack.":http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/web-authentication.html
+#
+# It's probably of minor importance, but recommended by best practices: 'defense
+# in depth'. Needless to say, if you upload this to github or the youtubes or
+# otherwise place it in public view you'll kinda defeat the point. Your users'
+# passwords are still secure, and the world won't end, but defense_in_depth -= 1.
+#
+# Please note: if you change this, all the passwords will be invalidated, so DO
+# keep it someplace secure. Use the random value given or type in the lyrics to
+# your favorite Jay-Z song or something; any moderately long, unpredictable text.
+# REST_AUTH_SITE_KEY = 'a7effc79c514bfb828e90c6c110bfa12a3b1e277'
+
+# Repeated applications of the hash make brute force (even with a compromised
+# database and site key) harder, and scale with Moore's law.
+#
+# bq. "To squeeze the most security out of a limited-entropy password or
+# passphrase, we can use two techniques [salting and stretching]... that are
+# so simple and obvious that they should be used in every password system.
+# There is really no excuse not to use them." http://tinyurl.com/37lb73
+# Practical Security (Ferguson & Scheier) p350
+#
+# A modest 10 foldings (the default here) adds 3ms. This makes brute forcing 10
+# times harder, while reducing an app that otherwise serves 100 reqs/s to 78 signin
+# reqs/s, an app that does 10reqs/s to 9.7 reqs/s
+#
+# More:
+# * http://www.owasp.org/index.php/Hashing_Java
+# * "An Illustrated Guide to Cryptographic Hashes":http://www.unixwiz.net/techtips/iguide-crypto-hashes.html
+
+# REST_AUTH_DIGEST_STRETCHES = 10
View
2  config/unicorn.rb
@@ -1,2 +1,2 @@
- worker_processes ENV['UNICORN_CONCURRENCY'] || 2
+ worker_processes ENV['UNICORN_CONCURRENCY'] || 1
timeout 45
View
49 lib/acts_as_timed.rb
@@ -0,0 +1,49 @@
+module ActiveRecord
+ module ActsAsTimed #:nodoc:
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def acts_as_timed
+
+ class_eval { extend SingletonMethods }
+ class_eval { include InstanceMethods }
+
+ attr_reader :started_at
+
+ # On save, calculate time spent
+ before_validation :increment_time_spent
+
+ # Convenience scope
+ scope :timed, :conditions => ['time_spent IS NOT NULL']
+ end
+ end
+
+ module SingletonMethods
+
+ # How much time was spent on each items' initial learning phase
+ def time_spent
+ self.sum(:time_spent)
+ end
+
+ # Get the average time spent over all timed learnings
+ def avg_time_spent
+ self.average(:time_spent)
+ end
+ end
+
+ module InstanceMethods
+
+ # Increment time_spent based on started_at time
+ def increment_time_spent
+ seconds = Time.zone.now - self.started_at if not self.started_at.blank?
+ self.time_spent = (self.time_spent || 0) + (seconds || 0)
+ end
+
+ def started_at=(time)
+ @started_at = time.is_a?(Time) ? time : Time.zone.parse(time)
+ end
+ end
+ end
+end
View
96 lib/authenticated_system.rb
@@ -6,7 +6,7 @@ def logged_in?
!!current_user
end
- # Accesses the current user from the session.
+ # Accesses the current user from the session.
# Future calls avoid the database because nil is not equal to false.
def current_user
@current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie) unless @current_user == false
@@ -30,7 +30,8 @@ def current_user=(new_user)
# def authorized?
# current_user.login != "bob"
# end
- def authorized?
+ #
+ def authorized?(action = action_name, resource = nil)
logged_in?
end
@@ -66,7 +67,11 @@ def access_denied
store_location
redirect_to new_session_path
end
- format.any do
+ # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
+ # Add any other API formats here. (Some browsers, notably IE6, send Accept: */* and trigger
+ # the 'format.any' block incorrectly. See http://bit.ly/ie6_borken or http://bit.ly/ie6_borken2
+ # for a workaround.)
+ format.any(:json, :xml) do
request_http_basic_authentication 'Web Password'
end
end
@@ -76,22 +81,28 @@ def access_denied
#
# We can return to this location by calling #redirect_back_or_default.
def store_location
- session[:return_to] = request.request_uri
+ session[:return_to] = request.fullpath
end
# Redirect to the URI stored by the most recent store_location call or
- # to the passed default.
- def redirect_back_or_default(default)
- redirect_to(session[:return_to] || default)
+ # to the passed default. Set an appropriately modified
+ # after_filter :store_location, :only => [:index, :new, :show, :edit]
+ # for any controller you want to be bounce-backable.
+ def redirect_back_or_default(default, options = {})
+ redirect_to((session[:return_to] || default), options)
session[:return_to] = nil
end
# Inclusion hook to make #current_user and #logged_in?
# available as ActionView helper methods.
def self.included(base)
- base.send :helper_method, :current_user, :logged_in?
+ base.send :helper_method, :current_user, :logged_in?, :authorized? if base.respond_to? :helper_method
end
+ #
+ # Login
+ #
+
# Called from #current_user. First attempt to login by the user id stored in the session.
def login_from_session
self.current_user = User.find_by_id(session[:user_id]) if session[:user_id]
@@ -99,17 +110,80 @@ def login_from_session
# Called from #current_user. Now, attempt to login by basic authentication information.
def login_from_basic_auth
- authenticate_with_http_basic do |username, password|
- self.current_user = User.authenticate(username, password)
+ authenticate_with_http_basic do |login, password|
+ self.current_user = User.authenticate(login, password)
end
end
+
+ #
+ # Logout
+ #
# Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
+ # for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP)
def login_from_cookie
user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token])
if user && user.remember_token?
- cookies[:auth_token] = { :value => user.remember_token, :expires => user.remember_token_expires_at }
self.current_user = user
+ handle_remember_cookie! false # freshen cookie token (keeping date)
+ self.current_user
+ end
+ end
+
+ # This is ususally what you want; resetting the session willy-nilly wreaks
+ # havoc with forgery protection, and is only strictly necessary on login.
+ # However, **all session state variables should be unset here**.
+ def logout_keeping_session!
+ # Kill server-side auth cookie
+ @current_user.forget_me if @current_user.is_a? User
+# @current_user = false # not logged in, and don't do it for me
+ kill_remember_cookie! # Kill client-side auth cookie
+ session[:user_id] = nil # keeps the session but kill our variable
+ # explicitly kill any other session variables you set
+ end
+
+ # The session should only be reset at the tail end of a form POST --
+ # otherwise the request forgery protection fails. It's only really necessary
+ # when you cross quarantine (logged-out to logged-in).
+ def logout_killing_session!
+ logout_keeping_session!
+ reset_session
+ end
+
+ #
+ # Remember_me Tokens
+ #
+ # Cookies shouldn't be allowed to persist past their freshness date,
+ # and they should be changed at each login
+
+ # Cookies shouldn't be allowed to persist past their freshness date,
+ # and they should be changed at each login
+
+ def valid_remember_cookie?
+ return nil unless @current_user
+ (@current_user.remember_token?) &&
+ (cookies[:auth_token] == @current_user.remember_token)
+ end
+
+ # Refresh the cookie auth token if it exists, create it otherwise
+ def handle_remember_cookie!(new_cookie_flag)
+ return unless @current_user
+ case
+ when valid_remember_cookie? then @current_user.refresh_token # keeping same expiry date
+ when new_cookie_flag then @current_user.remember_me
+ else @current_user.forget_me
end
+ send_remember_cookie!
+ end
+
+ def kill_remember_cookie!
+ cookies.delete :auth_token
end
+
+ def send_remember_cookie!
+ cookies[:auth_token] = {
+ :value => @current_user.remember_token,
+ :expires => @current_user.remember_token_expires_at }
+ end
+
end
View
5 lib/authenticated_test_helper.rb
@@ -1,10 +1,11 @@
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
- @request.session[:user_id] = user ? users(user).id : nil
+ @request.session[:user_id] = user ? (user.is_a?(User) ? user.id : users(user).id) : nil
end
def authorize_as(user)
- @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'test') : nil
+ @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'monkey') : nil
end
+
end
View
19 spec/fixtures/users.yml
@@ -1,19 +0,0 @@
-quentin:
- id: 1
- login: quentin
- email: quentin@example.com
- salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
- crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
- created_at: <%= 5.days.ago.to_s :db %>
-
-
-
-aaron:
- id: 2
- login: aaron
- email: aaron@example.com
- salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
- crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
- created_at: <%= 1.days.ago.to_s :db %>
-
-
View
4 spec/scenarios/default_scenario.rb
@@ -1,4 +0,0 @@
-class DefaultScenario < Scenario::Base
- uses :languages
- uses :users
-end
View
7 spec/scenarios/users_scenario.rb
@@ -1,7 +0,0 @@
-class UsersScenario < Scenario::Base
- def load
- create_record :user, :ryan, :login => 'ryan', :daily_units => 3, :email => 'ryan.daigle@gmail.com', :crypted_password => User.encrypt('password', 'salt'), :salt => 'salt'
- create_record :user, :guest, :login => 'guest', :daily_units => 3, :email => 'guest@gmail.com', :crypted_password => User.encrypt('password', 'salt'), :salt => 'salt'
- Subject.all.each { |s| users(:ryan).subjects << s }
- end
-end
View
97 spec/spec_helper.rb
@@ -1,40 +1,73 @@
-# This file is copied to ~/spec when you run 'ruby script/generate rspec'
-# from the project root directory.
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-require 'spec'
-require 'spec/rails'
-require 'scenarios'
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
-Spec::Runner.configure do |config|
- # If you're not using ActiveRecord you should remove these
- # lines, delete config/database.yml and disable :active_record
- # in your config/boot.rb
- config.use_transactional_fixtures = true
- config.use_instantiated_fixtures = false
- config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
- # == Fixtures
- #
- # You can declare fixtures for each example_group like this:
- # describe "...." do
- # fixtures :table_a, :table_b
- #
- # Alternatively, if you prefer to declare them only once, you can
- # do so right here. Just uncomment the next line and replace the fixture
- # names with your fixtures.
- #
- # config.global_fixtures = :table_a, :table_b
- #
- # If you declare global fixtures, be aware that they will be declared
- # for all of your examples, even those that don't use them.
- #
- # == Mock Framework
+RSpec.configure do |config|
+ # ## Mock Framework
#
- # RSpec uses it's own mocking framework by default. If you prefer to
- # use mocha, flexmock or RR, uncomment the appropriate line:
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
end
+
+# Old
+# # This file is copied to ~/spec when you run 'ruby script/generate rspec'
+# # from the project root directory.
+# ENV["RAILS_ENV"] = "test"
+# require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+# require 'spec'
+# require 'spec/rails'
+#
+# Spec::Runner.configure do |config|
+# # If you're not using ActiveRecord you should remove these
+# # lines, delete config/database.yml and disable :active_record
+# # in your config/boot.rb
+# config.use_transactional_fixtures = true
+# config.use_instantiated_fixtures = false
+# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+
+# # == Fixtures
+# #
+# # You can declare fixtures for each example_group like this:
+# # describe "...." do
+# # fixtures :table_a, :table_b
+# #
+# # Alternatively, if you prefer to declare them only once, you can
+# # do so right here. Just uncomment the next line and replace the fixture
+# # names with your fixtures.
+# #
+# # config.global_fixtures = :table_a, :table_b
+# #
+# # If you declare global fixtures, be aware that they will be declared
+# # for all of your examples, even those that don't use them.
+# #
+# # == Mock Framework
+# #
+# # RSpec uses it's own mocking framework by default. If you prefer to
+# # use mocha, flexmock or RR, uncomment the appropriate line:
+# #
+# # config.mock_with :mocha
+# # config.mock_with :flexmock
+# # config.mock_with :rr
+# end
View
4 stories/all.rb
@@ -1,4 +0,0 @@
-dir = File.dirname(__FILE__)
-Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file|
- require file
-end
View
3  stories/helper.rb
@@ -1,3 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-require 'spec/rails/story_adapter'
View
0  test/fixtures/.gitkeep
No changes.
View
0  test/functional/.gitkeep
No changes.
View
0  test/integration/.gitkeep
No changes.
View
12 test/performance/browsing_test.rb
@@ -1,12 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-class BrowsingTest < ActionDispatch::PerformanceTest
- # Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
- # :output => 'tmp/performance', :formats => [:flat] }
-
- def test_homepage
- get '/'
- end
-end
View
13 test/test_helper.rb
@@ -1,13 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
-end
View
0  test/unit/.gitkeep
No changes.
View
51 vendor/plugins/acts_as_timed/lib/active_record/acts/timed.rb
@@ -1,51 +0,0 @@
-module ActiveRecord
- module Acts #:nodoc:
- module Timed #:nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- def acts_as_timed
-
- class_eval { extend SingletonMethods }
- class_eval { include InstanceMethods }
-
- attr_reader :started_at
-
- # On save, calculate time spent
- before_validation :increment_time_spent
-
- # Convenience scope
- named_scope :timed, :conditions => ['time_spent IS NOT NULL']
- end
- end
-
- module SingletonMethods
-
- # How much time was spent on each items' initial learning phase
- def time_spent
- self.sum(:time_spent)
- end
-
- # Get the average time spent over all timed learnings
- def avg_time_spent
- self.average(:time_spent)
- end
- end
-
- module InstanceMethods
-
- # Increment time_spent based on started_at time
- def increment_time_spent
- seconds = Time.zone.now - self.started_at if not self.started_at.blank?
- self.time_spent = (self.time_spent || 0) + (seconds || 0)
- end
-
- def started_at=(time)
- @started_at = time.is_a?(Time) ? time : Time.zone.parse(time)
- end
- end
- end
- end
-end
View
18 vendor/plugins/haml/init.rb
@@ -1,18 +0,0 @@
-begin
- require File.join(File.dirname(__FILE__), 'lib', 'haml') # From here
-rescue LoadError
- begin
- require 'haml' # From gem
- rescue LoadError => e
- # gems:install may be run to install Haml with the skeleton plugin
- # but not the gem itself installed.
- # Don't die if this is the case.
- raise e unless defined?(Rake) &&
- (Rake.application.top_level_tasks.include?('gems') ||
- Rake.application.top_level_tasks.include?('gems:install'))
- end
-end
-
-# Load Haml.
-# Haml may be undefined if we're running gems:install.
-Haml.init_rails(binding) if defined?(Haml)
View
87 vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb
@@ -1,87 +0,0 @@
-class ResourcefulScaffoldGenerator < Rails::Generator::NamedBase
- attr_reader :controller_class_path,
- :controller_file_path,
- :controller_class_nesting,
- :controller_class_nesting_depth,
- :controller_class_name,
- :controller_underscore_name,
- :controller_plural_name
- alias_method :controller_file_name, :controller_underscore_name
- alias_method :controller_table_name, :controller_plural_name
-
- def initialize(runtime_args, runtime_options = {})
- super
-
- base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@name.pluralize)
- @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
-
- if @controller_class_nesting.empty?
- @controller_class_name = @controller_class_name_without_nesting
- else
- @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
- end
- end
-
- def manifest
- record do |m|
- # Check for class naming collisions.
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
- m.class_collisions(class_path, "#{class_name}")
-
- # Controller, helper, views, and test directories.
- m.directory(File.join('app/models', class_path))
- m.directory(File.join('app/controllers', controller_class_path))
- m.directory(File.join('app/helpers', controller_class_path))
- m.directory(File.join('app/views', controller_class_path, controller_file_name))
- m.directory(File.join('test/functional', controller_class_path))
- m.directory(File.join('test/unit', class_path))
- m.directory(File.join('test/fixtures', class_path))
-
- # Views
- for action in scaffold_views
- m.template("view_#{action}.haml", File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml"))
- end
- m.template('view_partial.haml', File.join('app/views', controller_class_path, controller_file_name, "_#{singular_name}.html.haml"))
-
- # Helper
- m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
-
- # Model
- m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
-
- unless options[:skip_migration]
- m.migration_template('migration.rb', 'db/migrate',
- :assigns => {
- :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
- :attributes => attributes
- },
- :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}")
- end
-
- # Controller
- m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
-
- # Tests
- m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
- m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))
- m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))
-
- # Route
- m.route_resources controller_file_name
- end
- end
-
- protected
-
- def banner
- "Usage: #{$0} resourcefulscaffold ModelName [field:type, field:type]"
- end
-
- def scaffold_views
- %w[ index show new edit _form ]
- end
-
- def model_name
- class_name.demodulize
- end
-end
View
5 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb
@@ -1,5 +0,0 @@
-class <%= controller_class_name %>Controller < ApplicationController
- make_resourceful do
- actions :all
- end
-end
View
10 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml
@@ -1,10 +0,0 @@
-one:
- id: 1
-<% for attribute in attributes -%>
- <%= attribute.name %>: <%= attribute.default %>
-<% end -%>
-two:
- id: 2
-<% for attribute in attributes -%>
- <%= attribute.name %>: <%= attribute.default %>
-<% end -%>
View
57 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb
@@ -1,57 +0,0 @@
-require File.dirname(__FILE__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper'
-require '<%= controller_file_path %>_controller'
-
-# Re-raise errors caught by the controller.
-class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
-
-class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
- fixtures :<%= table_name %>
-
- def setup
- @controller = <%= controller_class_name %>Controller.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
-
- def test_should_get_index
- get :index
- assert_response :success
- assert assigns(:<%= table_name %>)
- end
-
- def test_should_get_new
- get :new
- assert_response :success
- end
-
- def test_should_create_<%= file_name %>
- old_count = <%= class_name %>.count
- post :create, :<%= file_name %> => { }
- assert_equal old_count + 1, <%= class_name %>.count
-
- assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
- end
-
- def test_should_show_<%= file_name %>
- get :show, :id => 1
- assert_response :success
- end
-
- def test_should_get_edit
- get :edit, :id => 1
- assert_response :success
- end
-
- def test_should_update_<%= file_name %>
- put :update, :id => 1, :<%= file_name %> => { }
- assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
- end
-
- def test_should_destroy_<%= file_name %>
- old_count = <%= class_name %>.count
- delete :destroy, :id => 1
- assert_equal old_count-1, <%= class_name %>.count
-
- assert_redirected_to <%= table_name %>_path
- end
-end
View
2  vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb
@@ -1,2 +0,0 @@
-module <%= controller_class_name %>Helper
-end
View
13 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb
@@ -1,13 +0,0 @@
-class <%= migration_name %> < ActiveRecord::Migration
- def self.up
- create_table :<%= table_name %>, :force => true do |t|
-<% for attribute in attributes -%>
- t.column :<%= attribute.name %>, :<%= attribute.type %>
-<% end -%>
- end
- end
-
- def self.down
- drop_table :<%= table_name %>
- end
-end
View
2  vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb
@@ -1,2 +0,0 @@
-class <%= class_name %> < ActiveRecord::Base
-end
View
7 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb
@@ -1,7 +0,0 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
-
-class <%= class_name %>Test < Test::Unit::TestCase
- def test_truth
- assert true
- end
-end
View
5 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml
@@ -1,5 +0,0 @@
-<%- for attribute in attributes -%>
-%p
- %label{:for => "<%= singular_name %>_<%= attribute.name %>"} <%= attribute.column.human_name %>:
- = f.<%= attribute.field_type %> :<%= attribute.name %>
-<% end -%>
View
11 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml
@@ -1,11 +0,0 @@
-%h1 Editing <%= singular_name %>
-
-= error_messages_for :<%= singular_name %>
-
-- form_for(:<%= singular_name %>, :url => object_url, :html => { :method => :put }) do |f|
- = render :partial => "form", :locals => {:f => f}
- %p= submit_tag "Update"
-
-= link_to 'Show', object_path
-|
-= link_to 'Back', objects_path
View
5 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml
@@ -1,5 +0,0 @@
-%h1 Listing <%= plural_name %>
-
-= render :partial => '<%= singular_name %>', :collection => current_objects
-
-= link_to 'New <%= singular_name %>', new_object_path
View
9 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml
@@ -1,9 +0,0 @@
-%h1 Creating <%= singular_name %>
-
-= error_messages_for :<%= singular_name %>
-
-- form_for(:<%= singular_name %>, :url => objects_url) do |f|
- = render :partial => "form", :locals => {:f => f}
- %p= submit_tag "Create"
-
-= link_to 'Back', objects_path
View
12 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml
@@ -1,12 +0,0 @@
-%div[<%= singular_name %>]
-<% for attribute in attributes -%>
- %p.<%= attribute.name %>
- %strong <%= attribute.column.human_name %>
- = h <%= singular_name %>.<%= attribute.name %>
-<% end -%>
-
- = link_to 'Show', object_path(<%= singular_name %>)
- |
- = link_to 'Edit', edit_object_path(<%= singular_name %>)
- |
- = link_to 'Destroy', object_path(<%= singular_name %>), :confirm => 'Really destroy <%= singular_name %>?', :method => :delete
View
14 vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml
@@ -1,14 +0,0 @@
-%h1 Viewing <%= singular_name %>
-
-%div[current_object]
-<% for attribute in attributes -%>
- %p.<%= attribute.name %>
- %strong <%= attribute.column.human_name %>
- = h current_object.<%= attribute.name %>
-<% end -%>
-
-= link_to 'Edit', edit_object_path
-|
-= link_to 'Destroy', object_path, :confirm => 'Really destroy <%= singular_name %>?', :method => :delete
-|
-= link_to 'Back', objects_path
View
335 vendor/plugins/make_resourceful/lib/resourceful/builder.rb
@@ -1,335 +0,0 @@
-require 'resourceful/response'
-require 'resourceful/serialize'
-require 'resourceful/default/actions'
-
-module Resourceful
- # The Maker#make_resourceful block is evaluated in the context
- # of an instance of this class.
- # It provides various methods for customizing the behavior of the actions
- # built by make_resourceful.
- #
- # All instance methods of this class are available in the +make_resourceful+ block.
- class Builder
- # The klass of the controller on which the builder is working.
- attr :controller, true
-
- # The constructor is only meant to be called internally.
- #
- # This takes the klass (class object) of a controller
- # and constructs a Builder ready to apply the make_resourceful
- # additions to the controller.
- def initialize(kontroller)
- @controller = kontroller
- @inherited = !kontroller.read_inheritable_attribute(:resourceful_responses).blank?
- @action_module = Resourceful::Default::Actions.dup
- @ok_actions = []
- @callbacks = {:before => {}, :after => {}}
- @responses = {}
- @publish = {}
- @parents = []
- end
-
- # This method is only meant to be called internally.
- #
- # Applies all the changes that have been declared
- # via the instance methods of this Builder
- # to the kontroller passed in to the constructor.
- def apply
- apply_publish
-
- kontroller = @controller
- Resourceful::ACTIONS.each do |action_named|
- # See if this is a method listed by #actions
- unless @ok_actions.include? action_named
- # If its not listed, then remove the method
- # No one can hit it... if its DEAD!
- @action_module.send :remove_method, action_named
- end
- end
-
- kontroller.hidden_actions.reject! &@ok_actions.method(:include?)
- kontroller.send :include, @action_module
-
- kontroller.read_inheritable_attribute(:resourceful_callbacks).merge! @callbacks
- kontroller.read_inheritable_attribute(:resourceful_responses).merge! @responses
- kontroller.write_inheritable_attribute(:made_resourceful, true)
-
- kontroller.write_inheritable_attribute(:parents, @parents)
- kontroller.before_filter :load_parent_object, :only => @ok_actions
- end
-
- # :call-seq:
- # actions(*available_actions)
- # actions :all
- #
- # Adds the default RESTful actions to the controller.
- #
- # If the only argument is <tt>:all</tt>,
- # adds all the actions listed in Resourceful::ACTIONS[link:classes/Resourceful.html]
- # (or Resourceful::SINGULAR_ACTIONS[link:classes/Resourceful.html]
- # for a singular controller).
- #
- # Otherwise, this adds all actions
- # whose names were passed as arguments.
- #
- # For example:
- #
- # actions :show, :new, :create
- #
- # This adds the +show+, +new+, and +create+ actions
- # to the controller.
- #
- # The available actions are defined in Default::Actions.
- def actions(*available_actions)
- if available_actions.first == :all
- available_actions = controller.new.plural? ? ACTIONS : SINGULAR_ACTIONS
- end
-
- available_actions.each { |action| @ok_actions << action.to_sym }
- end
- alias build actions
-
- # :call-seq:
- # before(*events) { ... }
- #
- # Sets up a block of code to run before one or more events.
- #
- # All the default actions can be used as +before+ events:
- # <tt>:index</tt>, <tt>:show</tt>, <tt>:create</tt>, <tt>:update</tt>, <tt>:new</tt>, <tt>:edit</tt>, and <tt>:destroy</tt>.
- #
- # +before+ events are run after any objects are loaded[link:classes/Resourceful/Default/Accessors.html#M000015],
- # but before any database operations or responses.
- #
- # For example:
- #
- # before :show, :edit do
- # @page_title = current_object.title
- # end
- #
- # This will set the <tt>@page_title</tt> variable
- # to the current object's title
- # for the show and edit actions.
- def before(*events, &block)
- events.each do |event|
- @callbacks[:before][event.to_sym] = block
- end
- end
-
- # :call-seq:
- # after(*events) { ... }
- #
- # Sets up a block of code to run after one or more events.
- #
- # There are two sorts of +after+ events.
- # <tt>:create</tt>, <tt>:update</tt>, and <tt>:destroy</tt>
- # are run after their respective database operations
- # have been completed successfully.
- # <tt>:create_fails</tt>, <tt>:update_fails</tt>, and <tt>:destroy_fails</tt>,
- # on the other hand,
- # are run after the database operations fail.
- #
- # +after+ events are run after the database operations
- # but before any responses.
- #
- # For example:
- #
- # after :create_fails, :update_fails do
- # current_object.password = nil
- # end
- #
- # This will nillify the password of the current object
- # if the object creation/modification failed.
- def after(*events, &block)
- events.each do |event|
- @callbacks[:after][event.to_sym] = block
- end
- end
-
- # :call-seq:
- # response_for(*actions) { ... }
- # response_for(*actions) { |format| ... }
- #
- # Sets up a block of code to run
- # instead of the default responses for one or more events.
- #
- # If the block takes a format parameter,
- # it has the same semantics as Rails' +respond_to+ method.
- # Various format methods are called on the format object
- # with blocks that say what to do for each format.
- # For example:
- #
- # response_for :index do |format|
- # format.html
- # format.atom do
- # headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
- # render :action => 'atom', :layout => false
- # end
- # end
- #
- # This doesn't do anything special for the HTML
- # other than ensure that the proper view will be rendered,
- # but for ATOM it sets the proper content type
- # and renders the atom template.
- #
- # If you only need to set the HTML response,
- # you can omit the format parameter.
- # For example:
- #
- # response_for :new do
- # render :action => 'edit'
- # end
- #
- # This is the same as
- #
- # response_for :new do |format|
- # format.html { render :action => 'edit' }
- # end
- #
- # The default responses are defined by
- # Default::Responses.included[link:classes/Resourceful/Default/Responses.html#M000011].
- def response_for(*actions, &block)
- raise "Must specify one or more actions for response_for." if actions.empty?
-
- if block.arity < 1
- response_for(*actions) do |format|
- format.html(&block)
- end
- else
- response = Response.new
- block.call response
-
- actions.each do |action|
- @responses[action.to_sym] = response.formats
- end
- end
- end
-
- # :call-seq:
- # publish *formats, options = {}, :attributes => [ ... ]
- #
- # publish allows you to easily expose information about resourcess in a variety of formats.
- # The +formats+ parameter is a list of formats
- # in which to publish the resources.
- # The formats supported by default are +xml+, +yaml+, and +json+,
- # but other formats may be added by defining +to_format+ methods
- # for the Array and Hash classes
- # and registering the mime type with Rails' Mime::Type.register[http://api.rubyonrails.org/classes/Mime/Type.html#M001115].
- # See Resourceful::Serialize for more details..
- #
- # The <tt>:attributes</tt> option is mandatory.
- # It takes an array of attributes (as symbols) to make public.
- # These attributes can refer to any method on current_object;
- # they aren't limited to database fields.
- # For example:
- #
- # # posts_controller.rb
- # publish :yaml, :attributes => [:title, :created_at, :rendered_content]
- #
- # Then GET /posts/12.yaml would render
- #
- # ---
- # post:
- # title: Cool Stuff
- # rendered_content: |-
- # <p>This is a post.</p>
- # <p>It's about <strong>really</strong> cool stuff.</p>
- # created_at: 2007-04-28 04:32:08 -07:00
- #
- # The <tt>:attributes</tt> array can even contain attributes
- # that are themselves models.
- # In this case, you must use a hash to specify their attributes as well.
- # For example:
- #
- # # person_controller.rb
- # publish :xml, :json, :attributes => [
- # :name, :favorite_color, {
- # :pet_cat => [:name, :breed],
- # :hat => [:type]
- # }]
- #
- # Then GET /people/18.xml would render
- #
- # <?xml version="1.0" encoding="UTF-8"?>
- # <person>
- # <name>Nathan</name>
- # <favorite-color>blue</favorite_color>
- # <pet-cat>
- # <name>Jasmine</name>
- # <breed>panther</breed>
- # </pet-cat>
- # <hat>
- # <type>top</type>
- # </hat>
- # </person>
- #
- # publish will also allow the +index+ action
- # to render lists of objects.
- # An example would be too big,
- # but play with it a little on your own to see.
- #
- # publish takes only one optional option: <tt>only</tt>.
- # This specifies which action to publish the resources for.
- # By default, they're published for both +show+ and +index+.
- # For example:
- #
- # # cats_controller.rb
- # publish :json, :only => :index, :attributes => [:name, :breed]
- #
- # Then GET /cats.json would work, but GET /cats/294.json would fail.
- def publish(*formats)
- options = {
- :only => [:show, :index]
- }.merge(Hash === formats.last ? formats.pop : {})
- raise "Must specify :attributes option" unless options[:attributes]
-
- Array(options.delete(:only)).each do |action|
- @publish[action] ||= []
- formats.each do |format|
- format = format.to_sym
- @publish[action] << [format, proc do
- render_action = [:json, :xml].include?(format) ? format : :text
- render render_action => (plural_action? ? current_objects : current_object).serialize(format, options)
- end]
- end
- end
- end
-
- # Specifies parent resources for the current resource.
- # Each of these parents will be loaded automatically
- # if the proper id parameter is given.
- # For example,
- #
- # # cake_controller.rb
- # belongs_to :baker, :customer
- #
- # Then on GET /bakers/12/cakes,
- #
- # params[:baker_id] #=> 12
- # parent? #=> true
- # parent_name #=> "baker"
- # parent_model #=> Baker
- # parent_object #=> Baker.find(12)
- # current_objects #=> Baker.find(12).cakes
- #
- def belongs_to(*parents)
- @parents = parents.map(&:to_s)
- end
-
- # This method is only meant to be called internally.
- #
- # Returns whether or not the Builder's controller
- # inherits make_resourceful settings from a parent controller.
- def inherited?
- @inherited
- end
-
- private
-
- def apply_publish
- @publish.each do |action, types|
- @responses[action.to_sym] ||= []
- @responses[action.to_sym] += types
- end
- end
- end
-end
View
346 vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb
@@ -1,346 +0,0 @@
-module Resourceful
- # This module contains various methods
- # that are available from actions and callbacks.
- # Default::Accessors and Default::URLs are the most useful to users;
- # the rest are mostly used internally.
- #
- # However, if you want to poke around the internals a little,
- # check out Default::Actions, which has the default Action definitions,
- # and Default::Responses.included, which defines the default response_for[link:classes/Resourceful/Builder.html#M000061] blocks.
- module Default
- # This module contains all sorts of useful methods
- # that allow access to the resources being worked with,
- # metadata about the controller and action,
- # and so forth.
- #
- # Many of these accessors call other accessors
- # and are called by the default make_resourceful actions[link:classes/Resourceful/Default/Actions.html].
- # This means that overriding one method
- # can affect everything else.
- #
- # This can be dangerous, but it can also be very powerful.
- # make_resourceful is designed to take advantage of overriding,
- # so as long as the new methods accomplish the same purpose as the old ones,
- # everything will just work.
- # Even if you make a small mistake,
- # it's hard to break the controller in any unexpected ways.
- #
- # For example, suppose your controller is called TagsController,
- # but your model is called PhotoTag.
- # All you have to do is override current_model_name:
- #
- # def current_model_name
- # "PhotoTag"
- # end
- #
- # Then current_model will return the PhotoTag model,
- # current_object will call <tt>PhotoTag.find</tt>,
- # and so forth.
- #
- # Overriding current_objects and current_object is particularly useful
- # for providing customized model lookup logic.
- module Accessors
- # Returns an array of all the objects of the model corresponding to the controller.
- # For UsersController, it essentially runs <tt>User.find(:all)</tt>.
- #
- # However, there are a few important differences.
- # First, this method caches is results in the <tt>@current_objects</tt> instance variable.
- # That way, multiple calls won't run multiple queries.
- #
- # Second, this method uses the current_model accessor,
- # which provides a lot of flexibility
- # (see the documentation for current_model for details).
- def current_objects
- @current_objects ||= current_model.find(:all)
- end
-
- # Calls current_objects and stores
- # the result in an instance variable
- # named after the controller.
- #
- # This is called automatically by the default make_resourceful actions.
- # You shouldn't need to use it directly unless you're creating a new action.
- #
- # For example, in UsersController,
- # calling +load_objects+ sets <tt>@users = current_objects</tt>.
- def load_objects
- instance_variable_set("@#{instance_variable_name}", current_objects)
- end
-
- # Returns the object referenced by the id parameter
- # (or the newly-created object for the +new+ and +create+ actions).
- # For UsersController, it essentially runs <tt>User.find(params[:id])</tt>.
- #
- # However, there are a few important differences.
- # First, this method caches is results in the <tt>@current_objects</tt> instance variable.
- # That way, multiple calls won't run multiple queries.
- #
- # Second, this method uses the current_model accessor,
- # which provides a lot of flexibility
- # (see the documentation for current_model for details).
- #
- # Note that this is different for a singleton controller,
- # where there's only one resource per parent resource.
- # Then this just returns that resource.
- # For example, if Person has_one Hat,
- # then in HatsController current_object essentially runs <tt>Person.find(params[:person_id]).hat</tt>.
- def current_object
- @current_object ||= if plural?
- current_model.find(params[:id])
- else
- parent_object.send(instance_variable_name)
- end
- end
-
-
- # Calls current_object and stores
- # the result in an instance variable
- # named after the controller.
- #
- # This is called automatically by the default make_resourceful actions.
- # You shouldn't need to use it directly unless you're creating a new action.
- #
- # For example, in UsersController,
- # calling +load_object+ sets <tt>@user = current_object</tt>.
- def load_object
- instance_variable_set("@#{instance_variable_name.singularize}", current_object)
- end
-
- # Creates a new object of the type of the current model
- # with the current object's parameters.
- # +current_object+ then returns this object for this action
- # instead of looking up a new object.
- #
- # This is called automatically by the default make_resourceful actions.
- # You shouldn't need to use it directly unless you're creating a new action.
- #
- # Note that if a parent object exists,
- # the newly created object will automatically be a child of the parent object.
- # For example, on POST /people/4/things,
- #
- # build_object
- # current_object.person.id #=> 4
- #
- def build_object
- @current_object = if current_model.respond_to? :build
- current_model.build(object_parameters)
- else
- returning(current_model.new(object_parameters)) do |obj|
- obj.send("#{parent_name}_id=", parent_object.id) if singular? && parent?
- end
- end
- end
-
- # The string name of the current model.
- # By default, this is derived from the name of the controller.
- def current_model_name
- controller_name.singularize.camelize
- end
-
- # An array of namespaces under which the current controller is.
- # For example, in Admin::Content::PagesController:
- #
- # namespaces #=> [:admin, :content]
- #
- def namespaces
- @namespaces ||= self.class.name.split('::').slice(0...-1).map(&:underscore).map(&:to_sym)
- end
-
- # The name of the instance variable that load_object and load_objects should assign to.
- def instance_variable_name
- controller_name
- end
-
- # The class of the current model.
- # Note that if a parent object exists,
- # this instead returns the association object.
- # For example, in HatsController where Person has_many :hats,
- #
- # current_model #=> Person.find(params[:person_id]).hats
- #
- # This is useful because the association object uses duck typing
- # to act like a model class.
- # It supplies a find method that's automatically scoped
- # to ensure that the object returned is actually a child of the parent,
- # and so forth.
- def current_model
- if !parent? || singular?
- current_model_name.constantize
- else
- parent_object.send(instance_variable_name)
- end
- end
-
- # Returns the hash passed as HTTP parameters
- # that defines the new (or updated) attributes
- # of the current object.
- # This is only meaningful for +create+ or +update+.
- def object_parameters
- params[current_model_name.underscore]
- end
-
- # Returns a list of the names of all the potential parents of the current model.
- # For a non-nested controller, this is <tt>[]</tt>.
- # For example, in HatsController where Rack has_many :hats and Person has_many :hats,
- #
- # parents #=> ["rack", "person"]
- #
- # Note that the parents must be declared via Builder#belongs_to.
- def parent_names
- self.class.read_inheritable_attribute :parents
- end
-
- # Returns true if an appropriate parent id parameter has been supplied.
- # For example, in HatsController where Rack has_many :hats and Person has_many :hats,
- # if <tt>params[:rack_id]</tt> or <tt>params[:person_id]</tt> is given,
- #
- # parent? #=> true
- #
- # Otherwise, if both <tt>params[:rack_id]</tt> and <tt>params[:rack_id]</tt> are nil,
- #
- # parent? #=> false
- #
- # Note that parents must be declared via Builder#belongs_to.
- def parent?
- !!parent_name
- end
-
- # Returns the name of the current parent object if a parent id is given, or nil otherwise.
- # For example, in HatsController where Rack has_many :hats and Person has_many :hats,
- # if <tt>params[:rack_id]</tt> is given,
- #
- # parent_name #=> "rack"
- #
- # If <tt>params[:person_id]</tt> is given,
- #
- # parent_name #=> "person"
- #
- # If both <tt>params[:rack_id]</tt> and <tt>params[:rack_id]</tt> are nil,
- #
- # parent_name #=> nil
- #