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
@@ -0,0 +1,26 @@
1
+ <%=form_for model, :url => model_path do |f|%>
2
+ <p>
3
+ <%model.errors.each do |error, message|%>
4
+ <%=error.to_s.titleize%> <%=message%>
5
+ <%end%>
6
+ </p>
7
+
8
+ <p>
9
+ <%=f.label model_config.key%><br/>
10
+ <%=f.text_field model_config.key%>
11
+ </p>
12
+
13
+ <p>
14
+ <%=f.label :password%><br/>
15
+ <%=f.password_field :password, :value => ''%>
16
+ </p>
17
+
18
+ <p>
19
+ <%=f.label :password_confirmation%><br/>
20
+ <%=f.password_field :password_confirmation, :value => ''%>
21
+ </p>
22
+
23
+ <p>
24
+ <%=f.submit(model.new_record? ? "Sign up" : "Update Profile")%>
25
+ </p>
26
+ <%end%>
@@ -1,24 +1,6 @@
1
- <%form_for model, :url => model_path do |f|%>
2
- <p>
3
- <%=f.error_messages%>
4
- </p>
5
-
6
- <p>
7
- <%=f.label model_config.key%><br/>
8
- <%=f.text_field model_config.key%>
9
- </p>
10
-
11
- <p>
12
- <%=f.label :password%><br/>
13
- <%=f.password_field :password, :value => ''%>
14
- </p>
15
-
16
- <p>
17
- <%=f.label :password_confirmation%><br/>
18
- <%=f.password_field :password_confirmation, :value => ''%>
19
- </p>
20
-
21
- <p>
22
- <%=f.submit "Update Profile"%>
23
- </p>
1
+ <%if Rails::VERSION::MAJOR == 2%>
2
+ <%=render :partial => 'rails2_form'%>
3
+ <%else%>
4
+ <%=render :partial => 'rails3_form'%>
24
5
  <%end%>
6
+
@@ -1,24 +1,5 @@
1
- <%form_for model, :url => model_path do |f|%>
2
- <p>
3
- <%=f.error_messages%>
4
- </p>
5
-
6
- <p>
7
- <%=f.label model_config.key%><br/>
8
- <%=f.text_field model_config.key%>
9
- </p>
10
-
11
- <p>
12
- <%=f.label :password%><br/>
13
- <%=f.password_field :password, :value => ''%>
14
- </p>
15
-
16
- <p>
17
- <%=f.label :password_confirmation%><br/>
18
- <%=f.password_field :password_confirmation, :value => ''%>
19
- </p>
20
-
21
- <p>
22
- <%=f.submit "Sign up"%>
23
- </p>
1
+ <%if Rails::VERSION::MAJOR == 2%>
2
+ <%=render :partial => 'rails2_form'%>
3
+ <%else%>
4
+ <%=render :partial => 'rails3_form'%>
24
5
  <%end%>
@@ -0,0 +1,22 @@
1
+ <%form_for model, :url => model_session_path do |f|%>
2
+ <p>
3
+ <%=f.label model_config.key%><br/>
4
+ <%=f.text_field model_config.key%>
5
+ </p>
6
+
7
+ <p>
8
+ <%=f.label :password%><br/>
9
+ <%=f.password_field :password, :value => ''%>
10
+ </p>
11
+
12
+ <%if sparkly_config.remember_me.enabled?%>
13
+ <p>
14
+ <%=f.check_box :remember_me, :checked => false%>
15
+ <%=f.label :remember_me%>
16
+ </p>
17
+ <%end%>
18
+
19
+ <p>
20
+ <%=f.submit "Sign in"%>
21
+ </p>
22
+ <%end%>
@@ -0,0 +1,22 @@
1
+ <%=form_for model, :url => model_session_path do |f|%>
2
+ <p>
3
+ <%=f.label model_config.key%><br/>
4
+ <%=f.text_field model_config.key%>
5
+ </p>
6
+
7
+ <p>
8
+ <%=f.label :password%><br/>
9
+ <%=f.password_field :password, :value => ''%>
10
+ </p>
11
+
12
+ <%if sparkly_config.remember_me.enabled?%>
13
+ <p>
14
+ <%=f.check_box :remember_me, :checked => false%>
15
+ <%=f.label :remember_me%>
16
+ </p>
17
+ <%end%>
18
+
19
+ <p>
20
+ <%=f.submit "Sign in"%>
21
+ </p>
22
+ <%end%>
@@ -1,22 +1,5 @@
1
- <%form_for model, :url => model_session_path do |f|%>
2
- <p>
3
- <%=f.label model_config.key%><br/>
4
- <%=f.text_field model_config.key%>
5
- </p>
6
-
7
- <p>
8
- <%=f.label :password%><br/>
9
- <%=f.password_field :password, :value => ''%>
10
- </p>
11
-
12
- <%if Auth.remember_me.enabled?%>
13
- <p>
14
- <%=f.check_box :remember_me, :checked => false%>
15
- <%=f.label :remember_me%>
16
- </p>
17
- <%end%>
18
-
19
- <p>
20
- <%=f.submit "Sign in"%>
21
- </p>
1
+ <%if Rails::VERSION::MAJOR == 2%>
2
+ <%=render :partial => 'rails2_form'%>
3
+ <%else%>
4
+ <%=render :partial => 'rails3_form'%>
22
5
  <%end%>
@@ -0,0 +1,12 @@
1
+ Feature: Create an account using Sparkly Auth
2
+
3
+ Scenario: Create account with valid details
4
+ Given I am on the new user page
5
+ When I enter new user details
6
+ Then I should see "account has been created"
7
+
8
+ Scenario: Create account with missing password
9
+ Given I am on the new user page
10
+ When I fill in "email" with "generic@example.com"
11
+ Then I should not see "account has been created"
12
+
@@ -0,0 +1,12 @@
1
+ Feature: delete sparkly account
2
+
3
+ Scenario: not logged in
4
+ When I delete my account
5
+ Then I should see "You must be signed in to view this page."
6
+
7
+ Scenario: logged in
8
+ Given I am logged in
9
+ When I delete my account
10
+ Then I should see "Your account has been deleted."
11
+ And I should not be logged in
12
+
@@ -0,0 +1,54 @@
1
+ Feature: Edit sparkly account
2
+
3
+ Scenario: not logged in
4
+ Given I am on the edit user page
5
+ Then I should see "You must be signed in to view this page."
6
+
7
+ Scenario: logged in
8
+ Given I am logged in
9
+ And I am on the edit user page
10
+ Then I should not see "You must be signed in to view this page."
11
+ And I should be on the edit user page
12
+
13
+ Scenario: Change email address
14
+ Given I am logged in
15
+ And I am on the edit user page
16
+ When I fill in "email" with "generic_new@example.com"
17
+ And I press "Update Profile"
18
+ Then I should see "Your changes have been saved."
19
+
20
+ Scenario: Change password
21
+ Given I am logged in
22
+ And I am on the edit user page
23
+ When I fill in "password" with "Generic13"
24
+ And I fill in "password confirmation" with "Generic13"
25
+ And I press "Update Profile"
26
+ Then I should see "Your changes have been saved."
27
+
28
+ Scenario: Change password (already used)
29
+ Given I am logged in
30
+ And I am on the edit user page
31
+ When I fill in "password" with "Generic12"
32
+ And I fill in "password confirmation" with "Generic12"
33
+ And I press "Update Profile"
34
+ Then I should see "Password must not be the same as any of your recent passwords"
35
+
36
+ Scenario: Change password (invalid)
37
+ Given I am logged in
38
+ And I am on the edit user page
39
+ When I fill in "password" with "Generic13"
40
+ And I fill in "password confirmation" with "Generic14"
41
+ And I press "Update Profile"
42
+ Then I should not see "Your changes have been saved."
43
+ And I should see "Password doesn't match confirmation"
44
+ # can't remember the exact error message but whatever - if other tests pass, then this should be fine.
45
+
46
+ Scenario: Change email and password
47
+ Given I am logged in
48
+ And I am on the edit user page
49
+ When I fill in "password" with "Generic13"
50
+ And I fill in "password confirmation" with "Generic13"
51
+ And I press "Update Profile"
52
+ Then I should see "Your changes have been saved."
53
+
54
+
@@ -0,0 +1,7 @@
1
+ Feature: Lock abused sparkly accounts
2
+
3
+ Scenario: Lock a user out of a sparkly account after too many failures
4
+ Given I am on the new user session page
5
+ When I fail to log in 5 times
6
+ Then I should see "Account is locked due to too many invalid attempts"
7
+
@@ -0,0 +1,43 @@
1
+ Feature: Login sparkly session
2
+ Background:
3
+ Given I create an account
4
+
5
+ Scenario: Valid credentials
6
+ Given I am on the new user session page
7
+ When I enter valid login credentials
8
+ Then I should see "Signed in successfully."
9
+
10
+ Scenario: Invalid credentials
11
+ Given I am on the new user session page
12
+ When I enter invalid login credentials
13
+ Then I should see "Credentials were not valid."
14
+
15
+ Scenario: Sign in from a page requiring authenticated access
16
+ Given I am on the edit user page
17
+ When I enter valid login credentials
18
+ Then I should see "Signed in successfully."
19
+ #And I should be on the edit user page
20
+ And I should see "Email"
21
+ And I should see "Password"
22
+ And I should see "Password confirmation"
23
+
24
+ Scenario: Locked due to too many failed attempts
25
+ Given I am on the new user session page
26
+ When I enter invalid login credentials 6 times
27
+ Then I should see "Account is locked due to too many invalid attempts"
28
+
29
+ # moved to rspec, these work in rails 2 but not in rails 3 (controller is nil??)
30
+ # Scenario: Log in with remember box checked
31
+ # Given I am on the new user session page
32
+ # When I check "Remember me"
33
+ # And I enter valid login credentials
34
+ # Then I should have a remembrance token
35
+ # And I should see "Signed in successfully."
36
+ #
37
+ # Scenario: Log in with remember box unchecked
38
+ # Given I am on the new user session page
39
+ # When I uncheck "Remember me"
40
+ # And I enter valid login credentials
41
+ # Then I should see "Signed in successfully."
42
+ # And I should not have a remembrance token
43
+
@@ -0,0 +1,16 @@
1
+ Feature: Logout sparkly session
2
+ Scenario: when logged in
3
+ Given I am logged in
4
+ When I log out
5
+ Then I should see "You have been signed out."
6
+
7
+ Scenario: when already logged out
8
+ When I log out
9
+ Then I should see "You have been signed out."
10
+
11
+ Scenario: when logged in and remembered
12
+ Given I am logged in and remembered
13
+ When I log out
14
+ Then I should see "You have been signed out."
15
+ And I should not have a remembrance token
16
+
@@ -0,0 +1,4 @@
1
+ Before do
2
+ # because some of the session tests modify this.
3
+ Auth.configuration.session_duration = 30.minutes
4
+ end
@@ -0,0 +1,13 @@
1
+ Feature: Show sparkly account
2
+
3
+ Scenario: While not logged in
4
+ When I go to the show user page
5
+ Then I should see "You must be signed in to view this page."
6
+
7
+ Scenario: While logged in
8
+ Given I am logged in
9
+ When I go to the show user page
10
+ Then I should not see "You must be signed in to view this page."
11
+ And I should be on the show user page
12
+ # As in, not redirected.
13
+
@@ -0,0 +1,6 @@
1
+ Feature: Sparkly session timeout
2
+ Scenario: Session times out
3
+ Given I am logged in
4
+ And my session is expired
5
+ When I go to the edit user page
6
+ Then I should see "You have been signed out due to inactivity. Please sign in again."
@@ -0,0 +1,16 @@
1
+ Given /^I enter new user details$/ do
2
+ Given 'I enter new user details for "generic@example.com"'
3
+ end
4
+
5
+ Given /^I enter new user details for "([^"]*)"$/ do |email|
6
+ fill_in 'email', :with => email
7
+ fill_in 'password', :with => 'Generic12'
8
+ fill_in 'password confirmation', :with => 'Generic12'
9
+ click_button "Sign up"
10
+ handle_redirect!
11
+ end
12
+
13
+ Given /^I delete my account$/ do
14
+ delete user_path
15
+ handle_redirect!
16
+ end
@@ -0,0 +1,9 @@
1
+ When /^I create an account for "([^"]*)"$/ do |email|
2
+ Given "I am on the new user page"
3
+ When "I enter new user details for \"#{email}\""
4
+ Then 'I should see "account has been created"'
5
+ end
6
+
7
+ When /^I create an account$/ do
8
+ Given 'I create an account for "generic@example.com"'
9
+ end
@@ -0,0 +1,3 @@
1
+ Then /^show me the response$/ do
2
+ puts response.body
3
+ end
@@ -0,0 +1,182 @@
1
+ # Commonly used email steps
2
+ #
3
+ # To add your own steps make a custom_email_steps.rb
4
+ # The provided methods are:
5
+ #
6
+ # last_email_address
7
+ # reset_mailer
8
+ # open_last_email
9
+ # visit_in_email
10
+ # unread_emails_for
11
+ # mailbox_for
12
+ # current_email
13
+ # open_email
14
+ # read_emails_for
15
+ # find_email
16
+ #
17
+ # General form for email scenarios are:
18
+ # - clear the email queue (done automatically by email_spec)
19
+ # - execute steps that sends an email
20
+ # - check the user received an/no/[0-9] emails
21
+ # - open the email
22
+ # - inspect the email contents
23
+ # - interact with the email (e.g. click links)
24
+ #
25
+ # The Cucumber steps below are setup in this order.
26
+
27
+ module EmailHelpers
28
+ def current_email_address
29
+ # Replace with your a way to find your current email. e.g @current_user.email
30
+ # last_email_address will return the last email address used by email spec to find an email.
31
+ # Note that last_email_address will be reset after each Scenario.
32
+ last_email_address || "example@example.com"
33
+ end
34
+ end
35
+
36
+ World(EmailHelpers)
37
+
38
+ #
39
+ # Reset the e-mail queue within a scenario.
40
+ # This is done automatically before each scenario.
41
+ #
42
+
43
+ Given /^(?:a clear email queue|no emails have been sent)$/ do
44
+ reset_mailer
45
+ end
46
+
47
+ #
48
+ # Check how many emails have been sent/received
49
+ #
50
+
51
+ Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
52
+ unread_emails_for(address).size.should == parse_email_count(amount)
53
+ end
54
+
55
+ Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
56
+ mailbox_for(address).size.should == parse_email_count(amount)
57
+ end
58
+
59
+ Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
60
+ unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
61
+ end
62
+
63
+ Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
64
+ open_email(address, :with_text => expected_body)
65
+ end
66
+
67
+ #
68
+ # Accessing emails
69
+ #
70
+
71
+ # Opens the most recently received email
72
+ When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
73
+ open_email(address)
74
+ end
75
+
76
+ When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
77
+ open_email(address, :with_subject => subject)
78
+ end
79
+
80
+ When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
81
+ open_email(address, :with_text => text)
82
+ end
83
+
84
+ #
85
+ # Inspect the Email Contents
86
+ #
87
+
88
+ Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
89
+ current_email.should have_subject(text)
90
+ end
91
+
92
+ Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
93
+ current_email.should have_subject(Regexp.new(text))
94
+ end
95
+
96
+ Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
97
+ current_email.body.should include(text)
98
+ end
99
+
100
+ Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
101
+ current_email.body.should =~ Regexp.new(text)
102
+ end
103
+
104
+ Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
105
+ current_email.should be_delivered_from(text)
106
+ end
107
+
108
+ Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
109
+ current_email.should have_header(name, text)
110
+ end
111
+
112
+ Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
113
+ current_email.should have_header(name, Regexp.new(text))
114
+ end
115
+
116
+ #
117
+ # Inspect the Email Attachments
118
+ #
119
+
120
+ Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
121
+ current_email_attachments.size.should == parse_email_count(amount)
122
+ end
123
+
124
+ Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
125
+ current_email_attachments.select { |a| a.original_filename == filename }.size.should == parse_email_count(amount)
126
+ end
127
+
128
+ Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
129
+ current_email_attachments[(index.to_i - 1)].original_filename.should == filename
130
+ end
131
+
132
+ Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
133
+ current_email_attachments.select { |a| a.content_type == content_type }.size.should == parse_email_count(amount)
134
+ end
135
+
136
+ Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
137
+ current_email_attachments[(index.to_i - 1)].content_type.should == content_type
138
+ end
139
+
140
+ Then /^all attachments should not be blank$/ do
141
+ current_email_attachments.each do |attachment|
142
+ attachment.size.should_not == 0
143
+ end
144
+ end
145
+
146
+ Then /^show me a list of email attachments$/ do
147
+ EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
148
+ end
149
+
150
+ #
151
+ # Interact with Email Contents
152
+ #
153
+
154
+ When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
155
+ visit_in_email(link)
156
+ end
157
+
158
+ When /^(?:I|they) click the first link in the email$/ do
159
+ click_first_link_in_email
160
+ end
161
+
162
+ #
163
+ # Debugging
164
+ # These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command.
165
+ # Patches accepted. ;)
166
+ #
167
+
168
+ Then /^save and open current email$/ do
169
+ EmailSpec::EmailViewer::save_and_open_email(current_email)
170
+ end
171
+
172
+ Then /^save and open all text emails$/ do
173
+ EmailSpec::EmailViewer::save_and_open_all_text_emails
174
+ end
175
+
176
+ Then /^save and open all html emails$/ do
177
+ EmailSpec::EmailViewer::save_and_open_all_html_emails
178
+ end
179
+
180
+ Then /^save and open all raw emails$/ do
181
+ EmailSpec::EmailViewer::save_and_open_all_raw_emails
182
+ end