hello-rails 0.0.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +97 -0
  4. data/Rakefile +23 -0
  5. data/app/controllers/hello/application_controller.rb +27 -0
  6. data/app/controllers/hello/authentication/sessions_controller.rb +81 -0
  7. data/app/controllers/hello/authentication/sign_in_controller.rb +39 -0
  8. data/app/controllers/hello/authentication/sudo_mode_controller.rb +40 -0
  9. data/app/controllers/hello/concerns/authentication/sign_in.rb +44 -0
  10. data/app/controllers/hello/concerns/management/forgot_password.rb +45 -0
  11. data/app/controllers/hello/concerns/management/reset_password.rb +33 -0
  12. data/app/controllers/hello/concerns/registration/sign_up.rb +64 -0
  13. data/app/controllers/hello/internationalization/locale_controller.rb +28 -0
  14. data/app/controllers/hello/management/accesses_controller.rb +29 -0
  15. data/app/controllers/hello/management/confirm_emails_controller.rb +41 -0
  16. data/app/controllers/hello/management/emails_controller.rb +67 -0
  17. data/app/controllers/hello/management/forgot_password_controller.rb +41 -0
  18. data/app/controllers/hello/management/passwords_controller.rb +57 -0
  19. data/app/controllers/hello/management/profiles_controller.rb +71 -0
  20. data/app/controllers/hello/management/reset_password_controller.rb +53 -0
  21. data/app/controllers/hello/registration/sign_up_controller.rb +63 -0
  22. data/app/helpers/hello/application_helper.rb +5 -0
  23. data/app/mailers/hello/mailer.rb +26 -0
  24. data/app/models/access.rb +2 -0
  25. data/app/models/credential.rb +2 -0
  26. data/app/models/email_credential.rb +2 -0
  27. data/app/models/password_credential.rb +2 -0
  28. data/app/models/user.rb +2 -0
  29. data/app/views/hello/authentication/_sign_in.html.erb +64 -0
  30. data/app/views/hello/authentication/new_session.html.erb +4 -0
  31. data/app/views/hello/authentication/sessions.html.erb +36 -0
  32. data/app/views/hello/authentication/sign_in.html.erb +3 -0
  33. data/app/views/hello/authentication/sudo_mode.html.erb +37 -0
  34. data/app/views/hello/internationalization/locales.html.erb +7 -0
  35. data/app/views/hello/mailer/confirm_email.html.erb +12 -0
  36. data/app/views/hello/mailer/forgot_password.html.erb +12 -0
  37. data/app/views/hello/mailer/welcome.html.erb +11 -0
  38. data/app/views/hello/management/accesses.html.erb +47 -0
  39. data/app/views/hello/management/cancel.html.erb +14 -0
  40. data/app/views/hello/management/email_credentials/expired_confirmation_token.html.erb +1 -0
  41. data/app/views/hello/management/email_credentials/index.html.erb +84 -0
  42. data/app/views/hello/management/password_credentials/_forgot_form.html.erb +17 -0
  43. data/app/views/hello/management/password_credentials/_reset_form.html.erb +39 -0
  44. data/app/views/hello/management/password_credentials/forgot.html.erb +10 -0
  45. data/app/views/hello/management/password_credentials/forgot_success.html.erb +26 -0
  46. data/app/views/hello/management/password_credentials/reset.html.erb +3 -0
  47. data/app/views/hello/management/password_credentials/show.html.erb +25 -0
  48. data/app/views/hello/management/user.html.erb +73 -0
  49. data/app/views/hello/registration/_sign_up.html.erb +86 -0
  50. data/app/views/hello/registration/sign_up.html.erb +3 -0
  51. data/app/views/hello/registration/sign_up_widget.html.erb +3 -0
  52. data/app/views/hello/shared/_errors.html.erb +11 -0
  53. data/app/views/hello/shared/_flash.html.erb +8 -0
  54. data/app/views/hello/shared/_nav_pills.html.erb +15 -0
  55. data/app/views/hello/shared/_session_expiration.html.erb +15 -0
  56. data/app/views/hello/shared/_settings.html.erb +41 -0
  57. data/config/locales/hello.en.yml +69 -0
  58. data/config/locales/hello.es.yml +71 -0
  59. data/config/locales/hello.fr.yml +71 -0
  60. data/config/locales/hello.pl.yml +71 -0
  61. data/config/locales/hello.pt-BR.yml +71 -0
  62. data/config/locales/hello.zh-CN.yml +71 -0
  63. data/config/locales/hello.zh-TW.yml +71 -0
  64. data/config/routes.rb +74 -0
  65. data/db/migrate/1_create_credentials.rb +17 -0
  66. data/db/migrate/2_create_accesses.rb +15 -0
  67. data/db/migrate/3_create_users.rb +23 -0
  68. data/lib/generators/hello/concerns/USAGE +8 -0
  69. data/lib/generators/hello/concerns/concerns_generator.rb +10 -0
  70. data/lib/generators/hello/from_devise/USAGE +8 -0
  71. data/lib/generators/hello/from_devise/from_devise_generator.rb +13 -0
  72. data/lib/generators/hello/from_devise/templates/from_devise.migration.rb +39 -0
  73. data/lib/generators/hello/install/USAGE +8 -0
  74. data/lib/generators/hello/install/install_generator.rb +94 -0
  75. data/lib/generators/hello/install/templates/application.html.erb +35 -0
  76. data/lib/generators/hello/install/templates/hello_helper.rb +16 -0
  77. data/lib/generators/hello/install/templates/initializer.rb +24 -0
  78. data/lib/generators/hello/install/templates/models/concerns/user/authorization.rb +21 -0
  79. data/lib/generators/hello/install/templates/models/user.rb +9 -0
  80. data/lib/generators/hello/install/templates/onboarding/index.html.erb +5 -0
  81. data/lib/generators/hello/install/templates/onboarding/onboarding_controller.rb +33 -0
  82. data/lib/generators/hello/install/templates/root/index.html.erb +7 -0
  83. data/lib/generators/hello/install/templates/root/root_controller.rb +6 -0
  84. data/lib/generators/hello/install/templates/users/controllers/users_controller.rb +71 -0
  85. data/lib/generators/hello/install/templates/users/views/users/index.html.erb +29 -0
  86. data/lib/generators/hello/install/templates/users/views/users/list.html.erb +35 -0
  87. data/lib/generators/hello/install/templates/users/views/users/new.html.erb +60 -0
  88. data/lib/generators/hello/install/templates/users/views/users/show.html.erb +74 -0
  89. data/lib/generators/hello/locales/USAGE +12 -0
  90. data/lib/generators/hello/locales/locales_generator.rb +64 -0
  91. data/lib/generators/hello/views/USAGE +8 -0
  92. data/lib/generators/hello/views/views_generator.rb +9 -0
  93. data/lib/hello-rails.rb +1 -0
  94. data/lib/hello.rb +36 -0
  95. data/lib/hello/CHANGES.md +26 -0
  96. data/lib/hello/business.rb +47 -0
  97. data/lib/hello/business/authentication/sign_in.rb +92 -0
  98. data/lib/hello/business/authentication/sign_out.rb +8 -0
  99. data/lib/hello/business/authentication/sudo_mode_authentication.rb +25 -0
  100. data/lib/hello/business/authentication/sudo_mode_expiration.rb +17 -0
  101. data/lib/hello/business/base.rb +33 -0
  102. data/lib/hello/business/internationalization/update_locale.rb +33 -0
  103. data/lib/hello/business/management/add_email.rb +19 -0
  104. data/lib/hello/business/management/cancel_account.rb +22 -0
  105. data/lib/hello/business/management/confirm_email.rb +36 -0
  106. data/lib/hello/business/management/forgot_password.rb +47 -0
  107. data/lib/hello/business/management/remove_email.rb +19 -0
  108. data/lib/hello/business/management/reset_password.rb +34 -0
  109. data/lib/hello/business/management/send_confirmation_email.rb +40 -0
  110. data/lib/hello/business/management/unlink_access.rb +8 -0
  111. data/lib/hello/business/management/update_profile.rb +44 -0
  112. data/lib/hello/business/registration/sign_up.rb +159 -0
  113. data/lib/hello/configuration.rb +12 -0
  114. data/lib/hello/encryptors.rb +6 -0
  115. data/lib/hello/encryptors/complex.rb +25 -0
  116. data/lib/hello/encryptors/simple.rb +27 -0
  117. data/lib/hello/engine.rb +23 -0
  118. data/lib/hello/errors.rb +12 -0
  119. data/lib/hello/locales.rb +238 -0
  120. data/lib/hello/middleware.rb +13 -0
  121. data/lib/hello/rails_active_record.rb +10 -0
  122. data/lib/hello/rails_active_record/access.rb +65 -0
  123. data/lib/hello/rails_active_record/credential.rb +51 -0
  124. data/lib/hello/rails_active_record/email_credential.rb +60 -0
  125. data/lib/hello/rails_active_record/password_credential.rb +70 -0
  126. data/lib/hello/rails_active_record/user.rb +99 -0
  127. data/lib/hello/rails_controller.rb +124 -0
  128. data/lib/hello/rails_controller/restrict_by_role.rb +79 -0
  129. data/lib/hello/rails_helper.rb +35 -0
  130. data/lib/hello/request_manager.rb +14 -0
  131. data/lib/hello/request_manager/abstract.rb +77 -0
  132. data/lib/hello/request_manager/factory.rb +32 -0
  133. data/lib/hello/request_manager/stateful.rb +53 -0
  134. data/lib/hello/request_manager/stateful/finder.rb +58 -0
  135. data/lib/hello/request_manager/stateful/session_wrapper.rb +37 -0
  136. data/lib/hello/request_manager/stateless.rb +35 -0
  137. data/lib/hello/time_zones.rb +7 -0
  138. data/lib/hello/utils.rb +11 -0
  139. data/lib/hello/utils/device_name.rb +34 -0
  140. data/lib/hello/version.rb +4 -0
  141. data/lib/tasks/hello_tasks.rake +4 -0
  142. data/spec/bdd/hello/authentication/authorization/authorization_role_restriction_spec.rb +291 -0
  143. data/spec/bdd/hello/authentication/authorization/authorization_router_constraints_spec.rb +41 -0
  144. data/spec/bdd/hello/authentication/authorization/authorization_sensitive_restriction_spec.rb +84 -0
  145. data/spec/bdd/hello/authentication/authorization/bdd.yml +1 -0
  146. data/spec/bdd/hello/authentication/bdd.yml +1 -0
  147. data/spec/bdd/hello/authentication/classic_sign_in_spec.rb +264 -0
  148. data/spec/bdd/hello/authentication/manage_sessions_spec.rb +292 -0
  149. data/spec/bdd/hello/authentication/sign_out_spec.rb +159 -0
  150. data/spec/bdd/hello/bdd.yml +1 -0
  151. data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/bdd.yml +1 -0
  152. data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_locale_page_spec.rb +90 -0
  153. data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_profile_page_spec.rb +64 -0
  154. data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_in_form_spec.rb +31 -0
  155. data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_up_form_spec.rb +34 -0
  156. data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/bdd.yml +1 -0
  157. data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_profile_page_spec.rb +14 -0
  158. data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_sign_in_form_spec.rb +14 -0
  159. data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_sign_up_form_spec.rb +14 -0
  160. data/spec/bdd/hello/internalionalization/bdd.yml +1 -0
  161. data/spec/bdd/hello/management/bdd.yml +1 -0
  162. data/spec/bdd/hello/management/cancel_account_spec.rb +128 -0
  163. data/spec/bdd/hello/management/manage_email_credentials/bdd.yml +1 -0
  164. data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_api_spec.rb +7 -0
  165. data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_page_spec.rb +252 -0
  166. data/spec/bdd/hello/management/manage_password_credentials/bdd.yml +1 -0
  167. data/spec/bdd/hello/management/manage_password_credentials/manage_password_forgot_password_spec.rb +68 -0
  168. data/spec/bdd/hello/management/manage_password_credentials/manage_password_page_spec.rb +60 -0
  169. data/spec/bdd/hello/management/manage_password_credentials/manage_password_reset_password_spec.rb +145 -0
  170. data/spec/bdd/hello/management/manage_profile/bdd.yml +1 -0
  171. data/spec/bdd/hello/management/manage_profile/manage_profile_api_spec.rb +7 -0
  172. data/spec/bdd/hello/management/manage_profile/manage_profile_page_spec.rb +65 -0
  173. data/spec/bdd/hello/management/manage_social_credentials/bdd.yml +1 -0
  174. data/spec/bdd/hello/management/manage_social_credentials/manage_social_credentials_pending_spec.rb +7 -0
  175. data/spec/bdd/hello/management/unlink_sessions_spec.rb +59 -0
  176. data/spec/bdd/hello/other/bdd.yml +1 -0
  177. data/spec/bdd/hello/other/create_user_spec.rb +70 -0
  178. data/spec/bdd/hello/other/impersonate_user_spec.rb +58 -0
  179. data/spec/bdd/hello/other/list_users_spec.rb +86 -0
  180. data/spec/bdd/hello/registration/bdd.yml +1 -0
  181. data/spec/bdd/hello/registration/classic_sign_up_spec.rb +228 -0
  182. data/spec/bdd/hello/registration/onboarding_process_spec.rb +101 -0
  183. data/spec/bdd/hello/support.rb +62 -0
  184. data/spec/business/hello/authentication/sign_in_spec.rb +72 -0
  185. data/spec/business/hello/registration/sign_up_spec.rb +258 -0
  186. data/spec/controllers/authentication_spec.rb +97 -0
  187. data/spec/controllers/localization_spec.rb +65 -0
  188. data/spec/controllers/request_can_carry_an_access_token_spec.rb +223 -0
  189. data/spec/fixtures/hello/password_mailer/confirmation +3 -0
  190. data/spec/fixtures/hello/password_mailer/forgot +3 -0
  191. data/spec/fixtures/hello/password_mailer/sign_up +3 -0
  192. data/spec/mailers/hello/mailer_spec.rb +53 -0
  193. data/spec/models/access_spec.rb +19 -0
  194. data/spec/models/credential_spec.rb +9 -0
  195. data/spec/models/email_credential_spec.rb +163 -0
  196. data/spec/models/hello/sign_up_model_spec.rb +64 -0
  197. data/spec/models/password_credential_spec.rb +75 -0
  198. data/spec/models/user_spec.rb +93 -0
  199. data/spec/others/configuration_spec.rb +25 -0
  200. data/spec/others/encryptors/complex_spec.rb +26 -0
  201. data/spec/others/encryptors/simple_spec.rb +21 -0
  202. data/spec/others/helper_spec.rb +10 -0
  203. data/spec/others/localization_consistency_spec.rb +73 -0
  204. data/spec/requests/forgot_password_spec.rb +36 -0
  205. data/spec/requests/reset_password_spec.rb +7 -0
  206. data/spec/requests/security/user_spec.rb +19 -0
  207. data/spec/routing/hello/accesses_routing_spec.rb +17 -0
  208. data/spec/routing/hello/emails_routing_spec.rb +37 -0
  209. data/spec/routing/hello/locale_routing_spec.rb +17 -0
  210. data/spec/routing/hello/profile_routing_spec.rb +29 -0
  211. data/spec/routing/hello/registration_routing_spec.rb +23 -0
  212. data/spec/routing/hello/sign_out_routing_spec.rb +11 -0
  213. data/spec/routing/hello/sudo_mode_routing_spec.rb +23 -0
  214. data/spec/routing/hello/users_routing_spec.rb +15 -0
  215. data/spec/spec_helper.rb +9 -0
  216. data/spec/spec_helper/codeclimate.rb +2 -0
  217. data/spec/spec_helper/configure_rspec.rb +23 -0
  218. data/spec/spec_helper/create_database.rb +5 -0
  219. data/spec/spec_helper/dummy_and_test_dependencies.rb +17 -0
  220. data/spec/spec_helper/support.rb +1 -0
  221. data/spec/support/factories.rb +60 -0
  222. data/spec/support/feature_injection.rb +118 -0
  223. data/spec/support/features/feature_support_given.rb +46 -0
  224. data/spec/support/features/feature_support_then.rb +43 -0
  225. data/spec/support/helpers/aliases.rb +76 -0
  226. data/spec/support/helpers/configuration.rb +6 -0
  227. data/spec/support/helpers/current.rb +16 -0
  228. data/spec/support/helpers/expect.rb +61 -0
  229. data/spec/support/helpers/given.rb +49 -0
  230. data/spec/support/helpers/shortcuts.rb +24 -0
  231. data/spec/support/helpers/then.rb +29 -0
  232. data/spec/support/helpers/when.rb +108 -0
  233. data/spec/support/requests/request_support.rb +8 -0
  234. data/spec/utils/device_name_spec.rb +228 -0
  235. metadata +562 -11
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ module Hello::Management
4
+ describe 'Authentication' do
5
+ routes { Hello::Engine.routes }
6
+
7
+ # As anyone
8
+ # I can visit various URLs
9
+ # So I have differenct access and restrictions
10
+
11
+ describe 'Not Authenticated' do
12
+ describe ProfilesController do
13
+ it 'HTML' do
14
+ get :show
15
+ expect(response.status).to eq(302)
16
+ expect(response.status_message).to eq('Found')
17
+
18
+ # expect(session.keys).to match_array ["flash", "locale", "url"]
19
+ expect(session.keys).to match_array %w(locale url)
20
+ expect(session['locale']).to eq 'en'
21
+ expect(session['url']).to eq '/hello/'
22
+ # expect(flash[:alert]).to eq "You must sign in to continue."
23
+
24
+ # expect(session.to_hash).to eq({"locale" => "en", "url"=>"/hello/user", "flash"=>{"discard"=>[], "flashes"=>{:alert=>"You must sign in to continue."}}})
25
+
26
+ expect(response).to redirect_to('/hello/sign_in')
27
+ end
28
+
29
+ it 'JSON' do
30
+ get :show, format: :json
31
+ json_body = JSON(response.body)
32
+ expect(response.status).to eq(401)
33
+ expect(response.status_message).to eq('Unauthorized')
34
+ expect(json_body).to eq('message' => 'An active access token must be used to query information about the current user.')
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'Authenticated' do
40
+ describe ProfilesController do
41
+ before { @access = given_I_have_a_classic_access_token }
42
+
43
+ it 'PARAMS' do
44
+ @request.host = 'api.test.host'
45
+ get :show, format: :json, access_token: @access.token
46
+ json_body = JSON(response.body)
47
+ expect(response.status).to eq(200)
48
+ expect(response.status_message).to eq('OK')
49
+ expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count city))
50
+ end
51
+
52
+ it 'SESSION' do
53
+ @request.session['tokens'] = [@access.token]
54
+ @request.session['token'] = @access.token
55
+ get :show, format: :json # , {access_token: @access.token}
56
+ json_body = JSON(response.body)
57
+ expect(response.status).to eq(200)
58
+ expect(response.status_message).to eq('OK')
59
+ expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count city))
60
+ end
61
+
62
+ it 'HEADER' do
63
+ @request.host = 'api.test.host'
64
+ @request.headers['HTTP_ACCESS_TOKEN'] = @access.token
65
+ get :show, format: :json
66
+ json_body = JSON(response.body)
67
+ expect(response.status).to eq(200)
68
+ expect(response.status_message).to eq('OK')
69
+ expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count city))
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'Others' do
75
+ describe ProfilesController do
76
+ it 'Access Token Expired' do
77
+ @access = given_I_have_a_classic_access_token
78
+ @access.update! expires_at: 1.second.ago
79
+
80
+ get :show, format: :json, access_token: @access.token
81
+ json_body = JSON(response.body)
82
+ expect(response.status).to eq(401)
83
+ expect(response.status_message).to eq('Unauthorized')
84
+ expect(json_body).to eq('message' => 'An active access token must be used to query information about the current user.')
85
+ end
86
+
87
+ it 'Sudo Mode Required' do
88
+ skip 'important, but not urgent'
89
+ end
90
+
91
+ it 'Sudo Mode Expired' do
92
+ skip 'important, but not urgent'
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ module Hello
4
+ describe 'Browser Locale' do
5
+ routes { Hello::Engine.routes }
6
+
7
+ # As a Guest
8
+ # I can see the website
9
+ # So I don't face missing translation issues
10
+
11
+ describe Internationalization::LocaleController do
12
+ describe 'Browser locale or default' do
13
+ hash = {
14
+ nil => 'en',
15
+ 'en-US,en;q=0.8,pt;q=0.6' => 'en',
16
+ 'en-US;q=0.8,pt;q=0.6' => 'en',
17
+ 'en' => 'en',
18
+ 'de-AT' => 'en',
19
+ 'de-CH' => 'en',
20
+ 'de' => 'en',
21
+ 'en-AU' => 'en',
22
+ 'en-BORK' => 'en',
23
+ 'en-CA' => 'en',
24
+ 'en-GB' => 'en',
25
+ 'en-IND' => 'en',
26
+ 'nep' => 'en',
27
+ 'es' => 'es',
28
+ 'fa' => 'en',
29
+ 'fr' => 'fr',
30
+ 'fr-FR' => 'fr',
31
+ 'fr-CA' => 'fr',
32
+ 'fr-CH' => 'fr',
33
+ 'it' => 'en',
34
+ 'ja' => 'en',
35
+ 'ko' => 'en',
36
+ 'nb-NO' => 'en',
37
+ 'nl' => 'en',
38
+ 'pl' => 'pl',
39
+ 'pt' => 'pt-BR',
40
+ 'pt-BR' => 'pt-BR',
41
+ 'ru' => 'en',
42
+ 'sk' => 'en',
43
+ 'vi' => 'en',
44
+ 'zh' => 'zh-CN',
45
+ 'zh-CN' => 'zh-CN',
46
+ 'zh-HK' => 'zh-CN',
47
+ 'zh-MO' => 'zh-CN',
48
+ 'zh-SG' => 'zh-CN',
49
+ 'zh-TW' => 'zh-CN',
50
+ 'zh-YUE' => 'zh-CN',
51
+ }
52
+
53
+ hash.each do |value, expected|
54
+ it "#{value || 'nil'} \t -> #{expected}" do
55
+ @request.headers['HTTP_ACCEPT_LANGUAGE'] = value if value
56
+ get :index
57
+ expect(response.status).to eq(200)
58
+ expect(response.status_message).to eq('OK')
59
+ expect(session['locale'].to_s).to eq(expected)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,223 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Hello Gem', type: :controller do
4
+ routes { Hello::Engine.routes }
5
+ context 'Authentication' do
6
+ context 'Request Can Carry an Access Token' do
7
+ before do
8
+ @token = given_I_have_a_classic_access_token.token
9
+ end
10
+
11
+ def self.via_session_feature
12
+ context 'Via Session' do
13
+ before(:each) do
14
+ Given 'a valid access token will be passed via session' do
15
+ @request.session['token'] = @token
16
+ @request.session['tokens'] = [@token]
17
+ end
18
+ end
19
+
20
+ story 'With a standard URL' do
21
+ before(:each) do
22
+ Given "the hostname is 'test.host'" do
23
+ @request.host = 'test.host'
24
+ end
25
+ end
26
+ scenario 'As HTML' do
27
+ When 'I send a GET HTML request' do
28
+ get :show, format: :html
29
+ end
30
+
31
+ Then 'it should have a status 200 OK' do
32
+ expect(response.status).to eq(200)
33
+ expect(response.status_message).to eq('OK')
34
+ end
35
+ end
36
+
37
+ scenario 'As JSON' do
38
+ When 'I send a GET JSON request' do
39
+ get :show, format: :json
40
+ end
41
+
42
+ Then 'it should have a status 200 OK' do
43
+ expect(response.status).to eq(200)
44
+ expect(response.status_message).to eq('OK')
45
+ end
46
+ end
47
+ end
48
+
49
+ story 'With an API subdomain' do
50
+ before(:each) do
51
+ Given "the hostname is 'api.test.host'" do
52
+ @request.host = 'api.test.host'
53
+ end
54
+ end
55
+ scenario 'As HTML' do
56
+ When 'I send a GET HTML request' do
57
+ get :show, format: :html
58
+ end
59
+
60
+ Then 'it should have a status 302 Found' do
61
+ expect(response.status).to eq(302)
62
+ expect(response.status_message).to eq('Found')
63
+ end
64
+ end
65
+
66
+ scenario 'As JSON' do
67
+ When 'I send a GET JSON request' do
68
+ get :show, format: :json
69
+ end
70
+
71
+ Then 'it should have a status 401 Unauthorized' do
72
+ expect(response.status).to eq(401)
73
+ expect(response.status_message).to eq('Unauthorized')
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def self.via_headers_feature
81
+ context 'Via Session' do
82
+ before(:each) do
83
+ Given 'a valid access token will be passed via headers' do
84
+ @request.headers['HTTP_ACCESS_TOKEN'] = @token
85
+ end
86
+ end
87
+
88
+ story 'With a standard URL' do
89
+ before(:each) do
90
+ Given "the hostname is 'test.host'" do
91
+ @request.host = 'test.host'
92
+ end
93
+ end
94
+ scenario 'As HTML' do
95
+ When 'I send a GET HTML request' do
96
+ get :show, format: :html
97
+ end
98
+
99
+ Then 'it should have a status 302 Found' do
100
+ expect(response.status).to eq(302)
101
+ expect(response.status_message).to eq('Found')
102
+ end
103
+ end
104
+
105
+ scenario 'As JSON' do
106
+ When 'I send a GET JSON request' do
107
+ get :show, format: :json
108
+ end
109
+ Then 'it should have a status 401 Unauthorized' do
110
+ expect(response.status).to eq(401)
111
+ expect(response.status_message).to eq('Unauthorized')
112
+ end
113
+ end
114
+ end
115
+
116
+ story 'With an API subdomain' do
117
+ before(:each) do
118
+ Given "the hostname is 'api.test.host'" do
119
+ @request.host = 'api.test.host'
120
+ end
121
+ end
122
+ scenario 'As HTML' do
123
+ When 'I send a GET HTML request' do
124
+ get :show, format: :html
125
+ end
126
+
127
+ Then 'it should have a status 200 OK' do
128
+ expect(response.status).to eq(200)
129
+ expect(response.status_message).to eq('OK')
130
+ end
131
+ end
132
+
133
+ scenario 'As JSON' do
134
+ When 'I send a GET JSON request' do
135
+ get :show, format: :json
136
+ end
137
+
138
+ Then 'it should have a status 200 OK' do
139
+ expect(response.status).to eq(200)
140
+ expect(response.status_message).to eq('OK')
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ def self.via_params_feature
148
+ context 'Via Params' do
149
+ before(:each) do
150
+ Given 'a valid access token will be passed via params' do
151
+ # intentionally left blank
152
+ end
153
+ end
154
+
155
+ story 'With a standard URL' do
156
+ before(:each) do
157
+ Given "the hostname is 'test.host'" do
158
+ @request.host = 'test.host'
159
+ end
160
+ end
161
+ scenario 'As HTML' do
162
+ When 'I send a GET HTML request' do
163
+ get :show, format: :html, access_token: @token
164
+ end
165
+
166
+ Then 'it should have a status 302 Found' do
167
+ expect(response.status).to eq(302)
168
+ expect(response.status_message).to eq('Found')
169
+ end
170
+ end
171
+
172
+ scenario 'As JSON' do
173
+ When 'I send a GET JSON request' do
174
+ get :show, format: :json, access_token: @token
175
+ end
176
+ Then 'it should have a status 401 Unauthorized' do
177
+ expect(response.status).to eq(401)
178
+ expect(response.status_message).to eq('Unauthorized')
179
+ end
180
+ end
181
+ end
182
+
183
+ story 'With an API subdomain' do
184
+ before(:each) do
185
+ Given "the hostname is 'api.test.host'" do
186
+ @request.host = 'api.test.host'
187
+ end
188
+ end
189
+ scenario 'As HTML' do
190
+ When 'I send a GET HTML request' do
191
+ get :show, format: :html, access_token: @token
192
+ end
193
+
194
+ Then 'it should have a status 200 OK' do
195
+ expect(response.status).to eq(200)
196
+ expect(response.status_message).to eq('OK')
197
+ end
198
+ end
199
+
200
+ scenario 'As JSON' do
201
+ When 'I send a GET JSON request' do
202
+ get :show, format: :json, access_token: @token
203
+ end
204
+
205
+ Then 'it should have a status 200 OK' do
206
+ expect(response.status).to eq(200)
207
+ expect(response.status_message).to eq('OK')
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ describe Hello::Management::ProfilesController do
215
+ via_session_feature
216
+
217
+ via_headers_feature
218
+
219
+ via_params_feature
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,3 @@
1
+ PasswordMailer#confirmation
2
+
3
+ Hi, find me in app/views/hello/password_mailer/confirmation
@@ -0,0 +1,3 @@
1
+ PasswordMailer#forgot
2
+
3
+ Hi, find me in app/views/hello/password_mailer/forgot
@@ -0,0 +1,3 @@
1
+ PasswordMailer#sign_up
2
+
3
+ Hi, find me in app/views/hello/password_mailer/sign_up
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module Hello
4
+ describe Mailer do
5
+ let(:email_credential) { create(:email_credential, user: create(:user, name: "John O'Cornel")) }
6
+ let(:name) { 'John O'Cornel' }
7
+
8
+ describe 'welcome' do
9
+ let(:mail) { Mailer.welcome(email_credential.email, email_credential.user, 'THE_PASSWORD') }
10
+
11
+ it 'renders the headers' do
12
+ expect(mail.subject).to eq('Welcome to our website')
13
+ expect(mail.to).to eq([email_credential.email])
14
+ expect(mail.from).to eq(['hello@example.com'])
15
+ end
16
+
17
+ it 'renders the body' do
18
+ expect(mail.body.to_s).to match("Hello #{name},")
19
+ expect(mail.body.to_s).to match('Welcome')
20
+ end
21
+ end
22
+
23
+ describe 'confirm_email' do
24
+ let(:mail) { Mailer.confirm_email(email_credential.email, email_credential.user, 'THE_URL') }
25
+
26
+ it 'renders the headers' do
27
+ expect(mail.subject).to eq('Confirm This Email')
28
+ expect(mail.to).to eq([email_credential.email])
29
+ expect(mail.from).to eq(['hello@example.com'])
30
+ end
31
+
32
+ it 'renders the body' do
33
+ expect(mail.body.to_s).to match("Hello #{name},")
34
+ expect(mail.body.to_s).to match('>THE_URL</a>')
35
+ end
36
+ end
37
+
38
+ describe 'forgot_password' do
39
+ let(:mail) { Mailer.forgot_password(email_credential.email, email_credential.user, 'THE_URL') }
40
+
41
+ it 'renders the headers' do
42
+ expect(mail.subject).to eq('Reset Password Instructions')
43
+ expect(mail.to).to eq([email_credential.email])
44
+ expect(mail.from).to eq(['hello@example.com'])
45
+ end
46
+
47
+ it 'renders the body' do
48
+ expect(mail.body.to_s).to match("Hello #{name},")
49
+ expect(mail.body.to_s).to match('>THE_URL</a>')
50
+ end
51
+ end
52
+ end
53
+ end