sparkly-auth 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. data/.document +5 -0
  2. data/.gitignore +25 -0
  3. data/HISTORY.txt +7 -0
  4. data/README.rdoc +127 -1
  5. data/Rakefile +45 -13
  6. data/TODO +4 -0
  7. data/VERSION +1 -1
  8. data/app/controllers/sparkly_accounts_controller.rb +20 -13
  9. data/app/controllers/sparkly_controller.rb +5 -4
  10. data/app/controllers/sparkly_sessions_controller.rb +16 -9
  11. data/app/helpers/sparkly_accounts_helper.rb +2 -0
  12. data/app/helpers/sparkly_helper.rb +2 -0
  13. data/app/helpers/sparkly_sessions_helper.rb +2 -0
  14. data/app/models/remembrance_token.rb +3 -1
  15. data/app/views/sparkly_accounts/_rails2_form.html.erb +24 -0
  16. data/app/views/sparkly_accounts/_rails3_form.html.erb +26 -0
  17. data/app/views/sparkly_accounts/edit.html.erb +5 -23
  18. data/app/views/sparkly_accounts/new.html.erb +4 -23
  19. data/app/views/sparkly_sessions/_rails2_form.html.erb +22 -0
  20. data/app/views/sparkly_sessions/_rails3_form.html.erb +22 -0
  21. data/app/views/sparkly_sessions/new.html.erb +4 -21
  22. data/features/create_sparkly_account.feature +12 -0
  23. data/features/delete_sparkly_account.feature +12 -0
  24. data/features/edit_sparkly_account.feature +54 -0
  25. data/features/lock_abused_sparkly_account.feature +7 -0
  26. data/features/login_sparkly_session.feature +43 -0
  27. data/features/logout_sparkly_session.feature +16 -0
  28. data/features/setup/sparkly.rb +4 -0
  29. data/features/show_sparkly_account.feature +13 -0
  30. data/features/sparkly_session_timeout.feature +6 -0
  31. data/features/step_definitions/account/account_steps.rb +16 -0
  32. data/features/step_definitions/account/brief_steps.rb +9 -0
  33. data/features/step_definitions/debug_steps.rb +3 -0
  34. data/features/step_definitions/email_steps.rb +182 -0
  35. data/features/step_definitions/session/brief_steps.rb +0 -0
  36. data/features/step_definitions/session/logged_in_steps.rb +42 -0
  37. data/features/step_definitions/session/login_steps.rb +37 -0
  38. data/features/step_definitions/session/logout_steps.rb +5 -0
  39. data/features/step_definitions/session_steps.rb +16 -0
  40. data/features/step_definitions/sparkly_auth_steps.rb +0 -0
  41. data/features/step_definitions/web_steps.rb +287 -0
  42. data/features/support/env.rb +10 -0
  43. data/features/support/paths.rb +35 -0
  44. data/features/support/sparkly_helpers.rb +42 -0
  45. data/generators/sparkly/rails2.rb +79 -0
  46. data/generators/sparkly/rails3.rb +89 -0
  47. data/generators/sparkly/sparkly_generator.rb +4 -75
  48. data/generators/sparkly/templates/accounts_controller.rb +14 -13
  49. data/generators/sparkly/templates/accounts_helper.rb +1 -1
  50. data/generators/sparkly/templates/sessions_controller.rb +26 -12
  51. data/generators/sparkly/templates/sessions_helper.rb +1 -1
  52. data/generators/sparkly/templates/views/sparkly_accounts/_rails2_form.html.erb +24 -0
  53. data/generators/sparkly/templates/views/sparkly_accounts/_rails3_form.html.erb +26 -0
  54. data/generators/sparkly/templates/views/sparkly_accounts/edit.html.erb +5 -23
  55. data/generators/sparkly/templates/views/sparkly_accounts/new.html.erb +4 -23
  56. data/generators/sparkly/templates/views/sparkly_sessions/_rails2_form.html.erb +22 -0
  57. data/generators/sparkly/templates/views/sparkly_sessions/_rails3_form.html.erb +22 -0
  58. data/generators/sparkly/templates/views/sparkly_sessions/new.html.erb +4 -21
  59. data/lib/auth.rb +22 -1
  60. data/lib/auth/behavior/base.rb +25 -18
  61. data/lib/auth/behavior/base/configuration.rb +37 -0
  62. data/lib/auth/behavior/core.rb +22 -14
  63. data/lib/auth/behavior/core/authenticated_model_methods.rb +9 -1
  64. data/lib/auth/behavior/core/controller_extensions.rb +2 -2
  65. data/lib/auth/behavior/core/controller_extensions/class_methods.rb +1 -1
  66. data/lib/auth/behavior/core/password_methods.rb +5 -5
  67. data/lib/auth/behavior/remember_me.rb +7 -3
  68. data/lib/auth/behavior/remember_me/configuration.rb +8 -11
  69. data/lib/auth/behavior/remember_me/controller_extensions.rb +1 -1
  70. data/lib/auth/behavior_lookup.rb +4 -4
  71. data/lib/auth/builtin_behaviors.rb +3 -0
  72. data/lib/auth/configuration.rb +71 -25
  73. data/lib/auth/configuration/keys.rb +50 -0
  74. data/lib/auth/engine.rb +33 -0
  75. data/lib/auth/generators/views_generator.rb +13 -4
  76. data/lib/auth/model.rb +52 -22
  77. data/{init.rb → rails/hacks/rails2.rb} +1 -14
  78. data/rails/hacks/rails3.rb +22 -0
  79. data/rails/init.rb +7 -17
  80. data/rails/init_rails2.rb +39 -0
  81. data/rails/init_rails3.rb +2 -0
  82. data/rails/routes_rails3.rb +37 -0
  83. data/rake3 +1 -0
  84. data/rerun.txt +1 -0
  85. data/run_all_tests +1 -0
  86. data/sparkly-auth.gemspec +481 -23
  87. data/spec/behaviors/core/controller_extensions_spec.rb +49 -0
  88. data/spec/{lib/auth/behavior → behaviors}/core_spec.rb +29 -12
  89. data/spec/behaviors/remember_me/configuration_spec.rb +16 -0
  90. data/spec/behaviors/remember_me_spec.rb +167 -0
  91. data/spec/generators/sanity_checks_spec.rb +58 -0
  92. data/spec/lib/auth/configuration_spec.rb +61 -0
  93. data/spec/lib/auth/model_spec.rb +6 -9
  94. data/spec/lib/auth_spec.rb +2 -2
  95. data/spec/lib/hacks/rename_attributes_spec.rb +49 -0
  96. data/spec/routes_spec.rb +8 -2
  97. data/spec/spec2_helper.rb +52 -0
  98. data/spec/spec3_helper.rb +72 -0
  99. data/spec/spec_helper.rb +109 -49
  100. data/spec_env/rails2/README.1ST +23 -0
  101. data/spec_env/rails2/Rakefile +10 -0
  102. data/spec_env/rails2/app/controllers/application_controller.rb +13 -0
  103. data/spec_env/rails2/app/helpers/application_helper.rb +3 -0
  104. data/spec_env/rails2/app/models/user.rb +2 -0
  105. data/spec_env/rails2/app/views/application/not_found.html.erb +9 -0
  106. data/spec_env/rails2/app/views/layouts/application.html.erb +9 -0
  107. data/spec_env/rails2/config/boot.rb +110 -0
  108. data/spec_env/rails2/config/cucumber.yml +7 -0
  109. data/spec_env/rails2/config/database.yml +25 -0
  110. data/spec_env/rails2/config/environment.rb +46 -0
  111. data/spec_env/rails2/config/environments/cucumber.rb +35 -0
  112. data/spec_env/rails2/config/environments/development.rb +17 -0
  113. data/spec_env/rails2/config/environments/production.rb +28 -0
  114. data/spec_env/rails2/config/environments/test.rb +31 -0
  115. data/spec_env/rails2/config/initializers/backtrace_silencers.rb +7 -0
  116. data/spec_env/rails2/config/initializers/inflections.rb +10 -0
  117. data/spec_env/rails2/config/initializers/mime_types.rb +5 -0
  118. data/spec_env/rails2/config/initializers/new_rails_defaults.rb +21 -0
  119. data/spec_env/rails2/config/initializers/session_store.rb +15 -0
  120. data/spec_env/rails2/config/initializers/sparkly_authentication.rb +30 -0
  121. data/spec_env/rails2/config/locales/en.yml +5 -0
  122. data/spec_env/rails2/config/routes.rb +46 -0
  123. data/spec_env/rails2/db/development.sqlite3 +0 -0
  124. data/spec_env/rails2/db/migrate/001_create_sparkly_passwords.rb +19 -0
  125. data/spec_env/rails2/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
  126. data/spec_env/rails2/db/migrate/003_add_confirmed_to_sparkly_passwords.rb +9 -0
  127. data/spec_env/rails2/db/migrate/20100607103543_create_users.rb +12 -0
  128. data/spec_env/rails2/db/migrate/20100609152058_add_email_to_users.rb +9 -0
  129. data/spec_env/rails2/db/schema.rb +42 -0
  130. data/spec_env/rails2/db/seeds.rb +7 -0
  131. data/spec_env/rails2/db/test.sqlite3 +0 -0
  132. data/spec_env/rails2/doc/README_FOR_APP +2 -0
  133. data/spec_env/rails2/doc/sparkly_authentication.txt +56 -0
  134. data/spec_env/rails2/features/support/env.rb +58 -0
  135. data/spec_env/rails2/lib/tasks/cucumber.rake +47 -0
  136. data/spec_env/rails2/lib/tasks/rspec.rake +144 -0
  137. data/spec_env/rails2/lib/tasks/sparkly_migration.rb +1 -0
  138. data/spec_env/rails2/log/cucumber.log +8412 -0
  139. data/spec_env/rails2/log/development.log +317 -0
  140. data/spec_env/rails2/log/test.log +32053 -0
  141. data/spec_env/rails2/public/404.html +30 -0
  142. data/spec_env/rails2/public/422.html +30 -0
  143. data/spec_env/rails2/public/500.html +30 -0
  144. data/spec_env/rails2/public/favicon.ico +0 -0
  145. data/spec_env/rails2/public/images/rails.png +0 -0
  146. data/spec_env/rails2/public/javascripts/application.js +2 -0
  147. data/spec_env/rails2/public/javascripts/controls.js +963 -0
  148. data/spec_env/rails2/public/javascripts/dragdrop.js +973 -0
  149. data/spec_env/rails2/public/javascripts/effects.js +1128 -0
  150. data/spec_env/rails2/public/javascripts/prototype.js +4320 -0
  151. data/spec_env/rails2/public/robots.txt +5 -0
  152. data/spec_env/rails2/rerun.txt +1 -0
  153. data/spec_env/rails2/script/about +4 -0
  154. data/spec_env/rails2/script/autospec +6 -0
  155. data/spec_env/rails2/script/console +3 -0
  156. data/spec_env/rails2/script/cucumber +10 -0
  157. data/spec_env/rails2/script/dbconsole +3 -0
  158. data/spec_env/rails2/script/destroy +3 -0
  159. data/spec_env/rails2/script/generate +3 -0
  160. data/spec_env/rails2/script/performance/benchmarker +3 -0
  161. data/spec_env/rails2/script/performance/profiler +3 -0
  162. data/spec_env/rails2/script/plugin +3 -0
  163. data/spec_env/rails2/script/runner +3 -0
  164. data/spec_env/rails2/script/server +3 -0
  165. data/spec_env/rails2/script/spec +10 -0
  166. data/spec_env/rails2/spec/controllers/sparkly_user_sessions_controller_spec.rb +10 -0
  167. data/spec_env/rails2/spec/rcov.opts +2 -0
  168. data/spec_env/rails2/spec/spec.opts +4 -0
  169. data/spec_env/rails2/spec/spec_helper.rb +54 -0
  170. data/spec_env/rails2/test/fixtures/users.yml +7 -0
  171. data/spec_env/rails2/test/performance/browsing_test.rb +9 -0
  172. data/spec_env/rails2/test/test_helper.rb +38 -0
  173. data/spec_env/rails2/test/unit/user_test.rb +8 -0
  174. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/.specification +63 -0
  175. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/generators/sparkly/sparkly_generator.rb +1 -0
  176. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/lib/sparkly-auth-bootstrap.rb +6 -0
  177. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/rails/init.rb +1 -0
  178. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/sparkly-auth-bootstrap.gemspec +55 -0
  179. data/spec_env/rails3/.gitignore +4 -0
  180. data/spec_env/rails3/Gemfile +43 -0
  181. data/spec_env/rails3/Gemfile.lock +124 -0
  182. data/spec_env/rails3/README +256 -0
  183. data/spec_env/rails3/Rakefile +7 -0
  184. data/spec_env/rails3/app/controllers/application_controller.rb +6 -0
  185. data/spec_env/rails3/app/helpers/application_helper.rb +2 -0
  186. data/spec_env/rails3/app/models/user.rb +3 -0
  187. data/spec_env/rails3/app/views/application/not_found.html.erb +9 -0
  188. data/spec_env/rails3/app/views/layouts/application.html.erb +22 -0
  189. data/spec_env/rails3/config.ru +4 -0
  190. data/spec_env/rails3/config/application.rb +47 -0
  191. data/spec_env/rails3/config/boot.rb +13 -0
  192. data/spec_env/rails3/config/cucumber.yml +8 -0
  193. data/spec_env/rails3/config/database.yml +28 -0
  194. data/spec_env/rails3/config/environment.rb +5 -0
  195. data/spec_env/rails3/config/environments/development.rb +22 -0
  196. data/spec_env/rails3/config/environments/production.rb +49 -0
  197. data/spec_env/rails3/config/environments/spec.rb +35 -0
  198. data/spec_env/rails3/config/environments/test.rb +43 -0
  199. data/spec_env/rails3/config/initializers/backtrace_silencers.rb +7 -0
  200. data/spec_env/rails3/config/initializers/inflections.rb +10 -0
  201. data/spec_env/rails3/config/initializers/mime_types.rb +5 -0
  202. data/spec_env/rails3/config/initializers/secret_token.rb +7 -0
  203. data/spec_env/rails3/config/initializers/session_store.rb +8 -0
  204. data/spec_env/rails3/config/initializers/sparkly_authentication.rb +30 -0
  205. data/spec_env/rails3/config/locales/en.yml +5 -0
  206. data/spec_env/rails3/config/routes.rb +61 -0
  207. data/spec_env/rails3/db/migrate/001_create_sparkly_passwords.rb +19 -0
  208. data/spec_env/rails3/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
  209. data/spec_env/rails3/db/migrate/20100810132843_create_users.rb +13 -0
  210. data/spec_env/rails3/db/schema.rb +42 -0
  211. data/spec_env/rails3/db/seeds.rb +7 -0
  212. data/spec_env/rails3/doc/README_FOR_APP +2 -0
  213. data/spec_env/rails3/doc/sparkly_authentication.txt +56 -0
  214. data/spec_env/rails3/features/support/env.rb +62 -0
  215. data/spec_env/rails3/lib/sparkly/bootstrap.rb +1 -0
  216. data/spec_env/rails3/lib/tasks/.gitkeep +0 -0
  217. data/spec_env/rails3/lib/tasks/cucumber.rake +53 -0
  218. data/spec_env/rails3/lib/tasks/sparkly_migration.rb +1 -0
  219. data/spec_env/rails3/public/404.html +26 -0
  220. data/spec_env/rails3/public/422.html +26 -0
  221. data/spec_env/rails3/public/500.html +26 -0
  222. data/spec_env/rails3/public/favicon.ico +0 -0
  223. data/spec_env/rails3/public/images/rails.png +0 -0
  224. data/spec_env/rails3/public/javascripts/application.js +2 -0
  225. data/spec_env/rails3/public/javascripts/controls.js +965 -0
  226. data/spec_env/rails3/public/javascripts/dragdrop.js +974 -0
  227. data/spec_env/rails3/public/javascripts/effects.js +1123 -0
  228. data/spec_env/rails3/public/javascripts/prototype.js +6001 -0
  229. data/spec_env/rails3/public/javascripts/rails.js +175 -0
  230. data/spec_env/rails3/public/robots.txt +5 -0
  231. data/spec_env/rails3/public/stylesheets/.gitkeep +0 -0
  232. data/spec_env/rails3/script/cucumber +10 -0
  233. data/spec_env/rails3/script/rails +6 -0
  234. data/spec_env/rails3/test/fixtures/users.yml +7 -0
  235. data/spec_env/rails3/test/performance/browsing_test.rb +9 -0
  236. data/spec_env/rails3/test/test_helper.rb +13 -0
  237. data/spec_env/rails3/test/unit/user_test.rb +8 -0
  238. data/spec_env/rails3/vendor/plugins/.gitkeep +0 -0
  239. data/spec_env/rails3/webrat.log +5 -0
  240. metadata +393 -15
  241. data/dependencies.rb +0 -1
  242. data/spec/lib/auth/behavior/remember_me_spec.rb +0 -127
  243. data/spec/lib/auth/extensions/controller_spec.rb +0 -32
File without changes
@@ -0,0 +1,42 @@
1
+ Given /^I am logged in$/ do
2
+ Given 'I am logged in as "generic@example.com"'
3
+ end
4
+
5
+ Given /^I am logged in as "([^"]*)"$/ do |email|
6
+ if logged_in?
7
+ When 'I log out'
8
+ end
9
+
10
+ if User.find_by_email(email).nil?
11
+ Given "I create an account for \"#{email}\""
12
+ end
13
+
14
+ visit new_user_session_path
15
+ fill_in :email, :with => email
16
+ fill_in :password, :with => "Generic12"
17
+ click_button "Sign in"
18
+ handle_redirect!
19
+ response.should contain("Signed in successfully.")
20
+ end
21
+
22
+ Given /^I am logged in and remembered$/ do
23
+ Given 'I am logged in and remembered as "generic@example.com"'
24
+ end
25
+
26
+ Given /^I am logged in and remembered as "([^"]*)"$/ do |email|
27
+ if User.find_by_email(email).nil?
28
+ Given "I create an account for \"#{email}\""
29
+ end
30
+
31
+ visit new_user_session_path
32
+ fill_in :email, :with => email
33
+ fill_in :password, :with => "Generic12"
34
+ check "Remember me"
35
+ click_button "Sign in"
36
+ handle_redirect!
37
+ response.should contain("Signed in successfully.")
38
+ end
39
+
40
+ Then /^I should be logged in$/ do
41
+ logged_in?.should == true
42
+ end
@@ -0,0 +1,37 @@
1
+ When /^I enter valid login credentials$/ do
2
+ When 'I enter valid login credentials for "generic@example.com"'
3
+ end
4
+
5
+ When /^I enter valid login credentials for "([^"]*)"$/ do |email|
6
+ fill_in :email, :with => email
7
+ fill_in :password, :with => "Generic12"
8
+ click_button "Sign in"
9
+ handle_redirect!
10
+ end
11
+
12
+ When /^I enter invalid login credentials$/ do
13
+ fill_in :email, :with => "generic@example.com"
14
+ fill_in :password, :with => "Generic1"
15
+ click_button "Sign in"
16
+ handle_redirect!
17
+ end
18
+
19
+ When /^I enter invalid login credentials (\d+) times$/ do |count|
20
+ count.to_i.times do
21
+ fill_in :email, :with => "generic@example.com"
22
+ fill_in :password, :with => "Generic1"
23
+ click_button "Sign in"
24
+ handle_redirect!
25
+ end
26
+ end
27
+
28
+ When /^I fail to log in (\d+) times$/ do |count|
29
+ count.to_i.times do
30
+ visit new_user_session_path
31
+ fill_in :email, :with => "generic@example.com"
32
+ fill_in :password, :with => "Generic1"
33
+ click_button "Sign in"
34
+ handle_redirect!
35
+ end
36
+ end
37
+
@@ -0,0 +1,5 @@
1
+ When /^I log out$/ do
2
+ delete user_session_path
3
+ handle_redirect!
4
+ response.should contain("You have been signed out.")
5
+ end
@@ -0,0 +1,16 @@
1
+
2
+ Given /^my session is expired$/ do
3
+ Auth.configuration.session_duration = -1.second
4
+ end
5
+
6
+ Then /^I should not be logged in$/ do
7
+ logged_in?.should == false
8
+ end
9
+
10
+ Then /^I should have a remembrance token$/ do
11
+ cookie('remembrance_token').should_not be_blank
12
+ end
13
+
14
+ Then /^I should not have a remembrance token$/ do
15
+ cookie('remembrance_token').should be_blank
16
+ end
File without changes
@@ -0,0 +1,287 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ require 'uri'
9
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
10
+
11
+ # Commonly used webrat steps
12
+ # http://github.com/brynary/webrat
13
+
14
+ Given /^(?:|I )am on (.+)$/ do |page_name|
15
+ visit path_to(page_name)
16
+ handle_redirect!
17
+ end
18
+
19
+ When /^(?:|I )go to (.+)$/ do |page_name|
20
+ visit path_to(page_name)
21
+ handle_redirect!
22
+ end
23
+
24
+ When /^(?:|I )press "([^\"]*)"$/ do |button|
25
+ click_button(button)
26
+ handle_redirect!
27
+ end
28
+
29
+ When /^(?:|I )follow "([^\"]*)"$/ do |link|
30
+ click_link(link)
31
+ handle_redirect!
32
+ end
33
+
34
+ When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
35
+ click_link_within(parent, link)
36
+ handle_redirect!
37
+ end
38
+
39
+ When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
40
+ fill_in(field, :with => value)
41
+ end
42
+
43
+ When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
44
+ fill_in(field, :with => value)
45
+ end
46
+
47
+ # Use this to fill in an entire form with data from a table. Example:
48
+ #
49
+ # When I fill in the following:
50
+ # | Account Number | 5002 |
51
+ # | Expiry date | 2009-11-01 |
52
+ # | Note | Nice guy |
53
+ # | Wants Email? | |
54
+ #
55
+ # TODO: Add support for checkbox, select og option
56
+ # based on naming conventions.
57
+ #
58
+ When /^(?:|I )fill in the following:$/ do |fields|
59
+ fields.rows_hash.each do |name, value|
60
+ When %{I fill in "#{name}" with "#{value}"}
61
+ end
62
+ end
63
+
64
+ When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
65
+ select(value, :from => field)
66
+ end
67
+
68
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
69
+ # When I select "December 25, 2008 10:00" as the date and time
70
+ When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
71
+ select_datetime(time)
72
+ end
73
+
74
+ # Use this step when using multiple datetime_select helpers on a page or
75
+ # you want to specify which datetime to select. Given the following view:
76
+ # <%= f.label :preferred %><br />
77
+ # <%= f.datetime_select :preferred %>
78
+ # <%= f.label :alternative %><br />
79
+ # <%= f.datetime_select :alternative %>
80
+ # The following steps would fill out the form:
81
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
82
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
83
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
84
+ select_datetime(datetime, :from => datetime_label)
85
+ end
86
+
87
+ # Use this step in conjunction with Rail's time_select helper. For example:
88
+ # When I select "2:20PM" as the time
89
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
90
+ # will convert the 2:20PM to 14:20 and then select it.
91
+ When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
92
+ select_time(time)
93
+ end
94
+
95
+ # Use this step when using multiple time_select helpers on a page or you want to
96
+ # specify the name of the time on the form. For example:
97
+ # When I select "7:30AM" as the "Gym" time
98
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
99
+ select_time(time, :from => time_label)
100
+ end
101
+
102
+ # Use this step in conjunction with Rail's date_select helper. For example:
103
+ # When I select "February 20, 1981" as the date
104
+ When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
105
+ select_date(date)
106
+ end
107
+
108
+ # Use this step when using multiple date_select helpers on one page or
109
+ # you want to specify the name of the date on the form. For example:
110
+ # When I select "April 26, 1982" as the "Date of Birth" date
111
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
112
+ select_date(date, :from => date_label)
113
+ end
114
+
115
+ When /^(?:|I )check "([^\"]*)"$/ do |field|
116
+ check(field)
117
+ end
118
+
119
+ When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
120
+ uncheck(field)
121
+ end
122
+
123
+ When /^(?:|I )choose "([^\"]*)"$/ do |field|
124
+ choose(field)
125
+ end
126
+
127
+ # Adds support for validates_attachment_content_type. Without the mime-type getting
128
+ # passed to attach_file() you will get a "Photo file is not one of the allowed file types."
129
+ # error message
130
+ When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
131
+ type = path.split(".")[1]
132
+
133
+ case type
134
+ when "jpg"
135
+ type = "image/jpg"
136
+ when "jpeg"
137
+ type = "image/jpeg"
138
+ when "png"
139
+ type = "image/png"
140
+ when "gif"
141
+ type = "image/gif"
142
+ end
143
+
144
+ attach_file(field, path, type)
145
+ end
146
+
147
+ Then /^(?:|I )should see "([^\"]*)"$/ do |text|
148
+ handle_redirect!
149
+ if defined?(Spec::Rails::Matchers)
150
+ response.should contain(text)
151
+ else
152
+ assert_contain text
153
+ end
154
+ end
155
+
156
+ Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
157
+ handle_redirect!
158
+ within(selector) do |content|
159
+ if defined?(Spec::Rails::Matchers)
160
+ content.should contain(text)
161
+ else
162
+ hc = Webrat::Matchers::HasContent.new(text)
163
+ assert hc.matches?(content), hc.failure_message
164
+ end
165
+ end
166
+ end
167
+
168
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
169
+ handle_redirect!
170
+ regexp = Regexp.new(regexp)
171
+ if defined?(Spec::Rails::Matchers)
172
+ response.should contain(regexp)
173
+ else
174
+ assert_match(regexp, response_body)
175
+ end
176
+ end
177
+
178
+ Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
179
+ handle_redirect!
180
+ within(selector) do |content|
181
+ regexp = Regexp.new(regexp)
182
+ if defined?(Spec::Rails::Matchers)
183
+ content.should contain(regexp)
184
+ else
185
+ assert_match(regexp, content)
186
+ end
187
+ end
188
+ end
189
+
190
+ Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
191
+ handle_redirect!
192
+ if defined?(Spec::Rails::Matchers)
193
+ response.should_not contain(text)
194
+ else
195
+ assert_not_contain(text)
196
+ end
197
+ end
198
+
199
+ Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
200
+ handle_redirect!
201
+ within(selector) do |content|
202
+ if defined?(Spec::Rails::Matchers)
203
+ content.should_not contain(text)
204
+ else
205
+ hc = Webrat::Matchers::HasContent.new(text)
206
+ assert !hc.matches?(content), hc.negative_failure_message
207
+ end
208
+ end
209
+ end
210
+
211
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
212
+ handle_redirect!
213
+ regexp = Regexp.new(regexp)
214
+ if defined?(Spec::Rails::Matchers)
215
+ response.should_not contain(regexp)
216
+ else
217
+ assert_not_contain(regexp)
218
+ end
219
+ end
220
+
221
+ Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
222
+ handle_redirect!
223
+ within(selector) do |content|
224
+ regexp = Regexp.new(regexp)
225
+ if defined?(Spec::Rails::Matchers)
226
+ content.should_not contain(regexp)
227
+ else
228
+ assert_no_match(regexp, content)
229
+ end
230
+ end
231
+ end
232
+
233
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
234
+ if defined?(Spec::Rails::Matchers)
235
+ field_labeled(field).value.should =~ /#{value}/
236
+ else
237
+ assert_match(/#{value}/, field_labeled(field).value)
238
+ end
239
+ end
240
+
241
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
242
+ if defined?(Spec::Rails::Matchers)
243
+ field_labeled(field).value.should_not =~ /#{value}/
244
+ else
245
+ assert_no_match(/#{value}/, field_labeled(field).value)
246
+ end
247
+ end
248
+
249
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
250
+ if defined?(Spec::Rails::Matchers)
251
+ field_labeled(label).should be_checked
252
+ else
253
+ assert field_labeled(label).checked?
254
+ end
255
+ end
256
+
257
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
258
+ if defined?(Spec::Rails::Matchers)
259
+ field_labeled(label).should_not be_checked
260
+ else
261
+ assert !field_labeled(label).checked?
262
+ end
263
+ end
264
+
265
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
266
+ handle_redirect!
267
+ if defined?(Spec::Rails::Matchers)
268
+ URI.parse(current_url).path.should == path_to(page_name)
269
+ else
270
+ assert_equal path_to(page_name), URI.parse(current_url).path
271
+ end
272
+ end
273
+
274
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
275
+ actual_params = CGI.parse(URI.parse(current_url).query)
276
+ expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
277
+
278
+ if defined?(Spec::Rails::Matchers)
279
+ actual_params.should == expected_params
280
+ else
281
+ assert_equal expected_params, actual_params
282
+ end
283
+ end
284
+
285
+ Then /^show me the page$/ do
286
+ save_and_open_page
287
+ end
@@ -0,0 +1,10 @@
1
+ if defined?(RSpec)
2
+ require File.join(File.dirname(__FILE__), "../../spec_env/rails3/features/support/env")
3
+
4
+ # REALLY not sure why this is necessary. Something keeps dirtying the test DB -- only in Rails 3.
5
+ User.destroy_all
6
+ Password.destroy_all
7
+ RemembranceToken.destroy_all
8
+ else
9
+ require File.join(File.dirname(__FILE__), "../../spec_env/rails2/features/support/env")
10
+ end
@@ -0,0 +1,35 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+ when /the new user page/
14
+ new_user_path
15
+ when /the show user page/
16
+ user_path
17
+ when /the edit user page/
18
+ edit_user_path
19
+ when /the new user session page/
20
+ new_user_session_path
21
+
22
+ # Add more mappings here.
23
+ # Here is an example that pulls values out of the Regexp:
24
+ #
25
+ # when /^(.*)'s profile page$/i
26
+ # user_profile_path(User.find_by_login($1))
27
+
28
+ else
29
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
30
+ "Now, go and add a mapping in #{__FILE__}"
31
+ end
32
+ end
33
+ end
34
+
35
+ World(NavigationHelpers)
@@ -0,0 +1,42 @@
1
+ #def verify_user_exists!(email, password)
2
+ # User.find_by_email(email).should be_nil # I had some generic users show up in the test DB. Drove me nuts.
3
+ #
4
+ # user = User.new(:email => email)
5
+ # user.password = password
6
+ # user.password_confirmation = password
7
+ # user.save!
8
+ # user
9
+ #end
10
+
11
+ def logged_in?
12
+ if respond_to?(:controller) && controller
13
+ (!!controller.current_user)
14
+ # elsif (respond_to?(:response) && response rescue false) # Rails3/RSpec2 raises 'No response yet. Request a page first.'
15
+ # (!!response.template.controller.current_user)
16
+ else
17
+ !!(session[:session_token] && session[:active_at] rescue false) # can raise NoMethodError if there's no request
18
+ end
19
+ end
20
+
21
+ def current_user
22
+ controller.send(:current_user)
23
+ end
24
+
25
+ def cookie(name)
26
+ cookies[name]
27
+ # if response && response.respond_to?(:template)
28
+ # response.template.controller.send(:cookies)[:remembrance_token].should_not be_blank
29
+ # else
30
+ #
31
+ end
32
+
33
+ # no idea why I need this
34
+ module RedirectWTF
35
+ def handle_redirect!
36
+ while redirect? || response.body =~ /You are being .*?redirected/
37
+ follow_redirect!
38
+ end
39
+ end
40
+ end
41
+
42
+ World(RedirectWTF)