hello-rails 0.0.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,101 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.capability "I can Complete the Onboarding Process" do
4
+
5
+ role "Onboarding" do
6
+
7
+ uic "Onboarding Process Form", type: :feature do
8
+ Given "I am an onboarding" do
9
+ create(:user_onboarding)
10
+ visit "/hello/sign_in"
11
+ fill_in_login_form('onboarding')
12
+ click_button 'Sign In'
13
+ expect_to_be_on '/onboarding'
14
+ end
15
+
16
+ scenario "Continue As a User" do
17
+
18
+ When "I Continue As a User" do
19
+ click_button "Continue As a User"
20
+ end
21
+
22
+ Then "I should now be a User" do
23
+ then_I_expect_to_be_signed_in_with_role('user')
24
+ end
25
+
26
+ end # scenario
27
+
28
+ scenario "Continue As a Webmaster" do
29
+
30
+ When "I Continue As a Webmaster" do
31
+ click_button "Continue As a Webmaster"
32
+ end
33
+
34
+ Then "I should now be a Webmaster" do
35
+ then_I_expect_to_be_signed_in_with_role('webmaster')
36
+ end
37
+
38
+ end # scenario
39
+
40
+ Then "I should see a confirmation message" do
41
+ expect_flash_notice "Welcome!"
42
+ end
43
+ end # uic
44
+
45
+ api "API", type: :request do
46
+ Given "I am an onboarding" do
47
+ @access_token = create(:valid_access, user: create(:user_onboarding)).token
48
+ end
49
+
50
+ scenario "Continue As Invalid" do
51
+
52
+ When "I Continue As a User" do
53
+ post "/onboarding.json", access_token: @access_token, role: 'invalid'
54
+ end
55
+
56
+ Then "I should get a 422 Unprocessable Entity response" do
57
+ expect(response_status).to eq [422, "Unprocessable Entity"]
58
+ end
59
+
60
+ Then "I should see error messages" do
61
+ expect(json_response).to eq({"errors" => "invalid role supplied"})
62
+ end
63
+
64
+ end # scenario
65
+
66
+ scenario "Continue As a User" do
67
+
68
+ When "I Continue As a User" do
69
+ post "/onboarding.json", access_token: @access_token, role: 'user'
70
+ end
71
+
72
+ Then "I should get a 200 OK response" do
73
+ expect(response_status).to eq [200, "OK"]
74
+ end
75
+
76
+ Then "My new role should be 'user'" do
77
+ expect(json_response['user']['role']).to eq 'user'
78
+ end
79
+
80
+ end # scenario
81
+
82
+ scenario "Continue As a Webmaster" do
83
+
84
+ When "I Continue As a User" do
85
+ post "/onboarding.json", access_token: @access_token, role: 'webmaster'
86
+ end
87
+
88
+ Then "I should get a 200 OK response" do
89
+ expect(response_status).to eq [200, "OK"]
90
+ end
91
+
92
+ Then "My new role should be 'webmaster'" do
93
+ expect(json_response['user']['role']).to eq 'webmaster'
94
+ end
95
+
96
+ end # scenario
97
+ end # api
98
+
99
+ end # role
100
+
101
+ end # capability
@@ -0,0 +1,62 @@
1
+
2
+ def fill_in_registration_form
3
+ within("form#new_sign_up") do
4
+ fill_in 'sign_up_name', with: 'James Pinto'
5
+ fill_in 'sign_up_email', with: 'foo@bar.com'
6
+ fill_in 'sign_up_username', with: 'foobar'
7
+ fill_in 'sign_up_password', with: '1234'
8
+ fill_in 'sign_up_city', with: 'OMG! I can customize Hello!'
9
+ end
10
+ end
11
+
12
+ def fill_in_login_form(username, password='1234')
13
+ within("form#new_sign_in") do
14
+ fill_in 'sign_in_login', with: username
15
+ fill_in 'sign_in_password', with: password
16
+ end
17
+ end
18
+
19
+ def sign_in_with(login, password='1234')
20
+ visit '/hello/sign_in'
21
+ fill_in_login_form(login, password)
22
+ click_button 'Sign In'
23
+ click_link 'expire'
24
+ __fetch_current_access
25
+ end
26
+
27
+ def sign_in_as_an_onboarding
28
+ u = create(:user_onboarding)
29
+ create(:email_credential, user: u, email: "#{u.username}@example.com")
30
+ sign_in_with(u.username)
31
+ expect(current_user.role).to eq('onboarding')
32
+ end
33
+
34
+ def sign_in_as_a_user
35
+ u = create(:user_user)
36
+ create(:email_credential, user: u, email: "#{u.username}@example.com")
37
+ sign_in_with(u.username)
38
+ expect(current_user.role).to eq('user')
39
+ end
40
+
41
+ def sign_in_as_a_webmaster
42
+ u = create(:user_webmaster)
43
+ create(:email_credential, user: u, email: "#{u.username}@example.com")
44
+ sign_in_with(u.username)
45
+ expect(current_user.role).to eq('webmaster')
46
+ end
47
+
48
+ def sign_in_as_a(role)
49
+ case role.to_sym
50
+ when :guest # nothing to do
51
+ when :onboarding then sign_in_as_an_onboarding
52
+ when :user then sign_in_as_a_user
53
+ when :webmaster then sign_in_as_a_webmaster
54
+ else raise("Role #{role} is unknown")
55
+ end
56
+ end
57
+
58
+ def visit_path_after(path, delay)
59
+ current_access.update expires_at: (current_access.expires_at - delay + 1.second)
60
+ visit path
61
+ end
62
+
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ module Hello
4
+ describe Business::Authentication::SignIn do
5
+ describe '.authenticate(string, string)' do
6
+ describe 'original state' do
7
+ it('no errors') { expect(subject.errors.messages).to eq({}) }
8
+ it('good login') { expect(subject.bad_login?).to eq(false) }
9
+ it('good password') { expect(subject.bad_password?).to eq(false) }
10
+ it('user not persisted') { expect(subject.user).not_to be_persisted }
11
+ end
12
+
13
+ describe 'blank, blank' do
14
+ before do
15
+ subject.authenticate('', '')
16
+ end
17
+
18
+ it('has errors') { expect(subject.errors.messages).to eq(login: ["can't be blank"], password: ["can't be blank"]) }
19
+ it('not bad login') { expect(subject.bad_login?).to eq(false) }
20
+ it('not bad password') { expect(subject.bad_password?).to eq(false) }
21
+ it('user not persisted') { expect(subject.user).not_to be_persisted }
22
+ end
23
+
24
+ describe 'not found, blank' do
25
+ before do
26
+ subject.authenticate('notfound', '')
27
+ end
28
+
29
+ it('has errors') { expect(subject.errors.messages).to eq(password: ["can't be blank"]) }
30
+ it('not bad login') { expect(subject.bad_login?).to eq(false) }
31
+ it('not bad password') { expect(subject.bad_password?).to eq(false) }
32
+ it('user not persisted') { expect(subject.user).not_to be_persisted }
33
+ end
34
+
35
+ describe 'found, blank' do
36
+ before do
37
+ create(:user_user)
38
+ subject.authenticate('user', '')
39
+ end
40
+
41
+ it('no errors') { expect(subject.errors.messages).to eq(password: ["can't be blank"]) }
42
+ it('good login') { expect(subject.bad_login?).to eq(false) }
43
+ it('not bad password') { expect(subject.bad_password?).to eq(false) }
44
+ it('user not persisted') { expect(subject.user).not_to be_persisted }
45
+ end
46
+
47
+ describe 'found, incorrect' do
48
+ before do
49
+ create(:user_user)
50
+ subject.authenticate('user', 'wrong')
51
+ end
52
+
53
+ it('has errors') { expect(subject.errors.messages).to eq(password: ['is incorrect']) }
54
+ it('good login') { expect(subject.bad_login?).to eq(false) }
55
+ it('has a bad password') { expect(subject.bad_password?).to eq(true) }
56
+ it('user persisted') { expect(subject.user).to be_persisted }
57
+ end
58
+
59
+ describe 'found, correct' do
60
+ before do
61
+ create(:user_user)
62
+ subject.authenticate('user', '1234')
63
+ end
64
+
65
+ it('no errors') { expect(subject.errors.messages).to eq({}) }
66
+ it('good login') { expect(subject.bad_login?).to eq(false) }
67
+ it('good password') { expect(subject.bad_password?).to eq(false) }
68
+ it('user persisted') { expect(subject.user).to be_persisted }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,258 @@
1
+ require 'spec_helper'
2
+
3
+ module Hello
4
+ describe Business::Registration::SignUp do
5
+ describe '.register(email:string, username:string, password:string)' do
6
+ let(:valid_attrs) { { city: 'Brasilia', name: 'James Pinto', email: 'foo@bar.com', username: 'foobar', password: 'foobar' } }
7
+
8
+ describe 'original state' do
9
+ it('no errors') { expect(subject.errors.messages).to eq({}) }
10
+ end # describe
11
+
12
+ describe 'all blank' do
13
+ before do
14
+ subject.register({})
15
+ end
16
+ it('a lot of errors') { expect(subject.errors.messages).to eq(email: ["can't be blank"], name: ["can't be blank"], city: ["can't be blank"], password: ["can't be blank"], username: ["can't be blank"]) }
17
+ end # describe
18
+
19
+ describe 'by field' do
20
+ def perform
21
+ if value
22
+ valid_attrs[field] = value
23
+ else
24
+ valid_attrs.delete(field)
25
+ end
26
+ subject.register(valid_attrs)
27
+ @errors = subject.errors[field]
28
+ end
29
+
30
+ after do
31
+ reload_initializer!
32
+ end
33
+
34
+ # helpers
35
+
36
+ def self.it_registers
37
+ it('registers') { expect(::User.count).to eq(1) }
38
+ end
39
+
40
+ def self.it_does_not_register
41
+ it('does not register') { expect(::User.count).to eq(0) }
42
+ end
43
+
44
+ def self.it_is_invalid
45
+ it('has errors') { expect(@errors).to eq(['is invalid']) }
46
+ end
47
+
48
+ def self.it_cant_be_blank
49
+ it('has errors') { expect(@errors).to eq(["can't be blank"]) }
50
+ end
51
+
52
+ def self.it_does_not_have_errors
53
+ it('does not have errors') { expect(@errors).to eq([]) }
54
+ end
55
+
56
+ #
57
+
58
+ describe 'email' do
59
+ let(:field) { :email }
60
+
61
+ describe 'config.email_presence = true' do
62
+ before do
63
+ Hello.configure { |config| config.email_presence = true }
64
+ perform
65
+ end
66
+
67
+ describe 'ignored' do
68
+ let(:value) { nil }
69
+ it_cant_be_blank
70
+ it_does_not_register
71
+ end # describe
72
+
73
+ describe 'blank' do
74
+ let(:value) { '' }
75
+ it_cant_be_blank
76
+ it_does_not_register
77
+ end # describe
78
+
79
+ describe 'invalid' do
80
+ let(:value) { 'foobar' }
81
+ it_is_invalid
82
+ it_does_not_register
83
+ end # describe
84
+
85
+ describe 'valid' do
86
+ let(:value) { 'foo@bar.com' }
87
+ it_does_not_have_errors
88
+ it_registers
89
+ end # describe
90
+ end # describe config
91
+
92
+ describe 'config.email_presence = false' do
93
+ before do
94
+ Hello.configure { |config| config.email_presence = false }
95
+ perform
96
+ end
97
+
98
+ describe 'ignored' do
99
+ let(:value) { nil }
100
+ it_does_not_have_errors
101
+ it_registers
102
+ end # describe
103
+
104
+ describe 'blank' do
105
+ let(:value) { '' }
106
+ it_does_not_have_errors
107
+ it_registers
108
+ end # describe
109
+
110
+ describe 'invalid' do
111
+ let(:value) { 'foobar' }
112
+ it_is_invalid
113
+ it_does_not_register
114
+ end # describe
115
+
116
+ describe 'valid' do
117
+ let(:value) { 'foo@bar.com' }
118
+ it_does_not_have_errors
119
+ it_registers
120
+ end # describe
121
+ end # describe config
122
+ end # describe email
123
+
124
+ describe 'username' do
125
+ let(:field) { :username }
126
+
127
+ describe 'config.username_presence = true' do
128
+ before do
129
+ Hello.configure { |config| config.username_presence = true }
130
+ perform
131
+ end
132
+
133
+ describe 'ignored' do
134
+ let(:value) { nil }
135
+ it_cant_be_blank
136
+ it_does_not_register
137
+ end # describe
138
+
139
+ describe 'blank' do
140
+ let(:value) { '' }
141
+ it_cant_be_blank
142
+ it_does_not_register
143
+ end # describe
144
+
145
+ describe 'invalid' do
146
+ let(:value) { 'foobar!' }
147
+ it_is_invalid
148
+ it_does_not_register
149
+ end # describe
150
+
151
+ describe 'valid' do
152
+ let(:value) { 'foobar' }
153
+ it_does_not_have_errors
154
+ it_registers
155
+ end # describe
156
+ end # describe config
157
+
158
+ describe 'config.username_presence = false' do
159
+ before do
160
+ Hello.configure { |config| config.username_presence = false }
161
+ perform
162
+ end
163
+
164
+ describe 'ignored' do
165
+ let(:value) { nil }
166
+ it_does_not_have_errors
167
+ it_registers
168
+ end # describe
169
+
170
+ describe 'blank' do
171
+ let(:value) { '' }
172
+ it_does_not_have_errors
173
+ it_registers
174
+ end # describe
175
+
176
+ describe 'invalid' do
177
+ let(:value) { 'foobar!' }
178
+ it_is_invalid
179
+ it_does_not_register
180
+ end # describe
181
+
182
+ describe 'valid' do
183
+ let(:value) { 'foobar' }
184
+ it_does_not_have_errors
185
+ it_registers
186
+ end # describe
187
+ end # describe config
188
+ end # describe username
189
+
190
+ describe 'password' do
191
+ let(:field) { :password }
192
+
193
+ describe 'config.password_presence = true' do
194
+ before do
195
+ Hello.configure { |config| config.password_presence = true }
196
+ perform
197
+ end
198
+
199
+ describe 'ignored' do
200
+ let(:value) { nil }
201
+ it_cant_be_blank
202
+ it_does_not_register
203
+ end # describe
204
+
205
+ describe 'blank' do
206
+ let(:value) { '' }
207
+ it_cant_be_blank
208
+ it_does_not_register
209
+ end # describe
210
+
211
+ describe 'invalid' do
212
+ let(:value) { 'foo bar' }
213
+ it_is_invalid
214
+ it_does_not_register
215
+ end # describe
216
+
217
+ describe 'valid' do
218
+ let(:value) { 'foobar' }
219
+ it_does_not_have_errors
220
+ it_registers
221
+ end # describe
222
+ end # describe config
223
+
224
+ describe 'config.password_presence = false' do
225
+ before do
226
+ Hello.configure { |config| config.password_presence = false }
227
+ perform
228
+ end
229
+
230
+ describe 'ignored' do
231
+ let(:value) { nil }
232
+ it_does_not_have_errors
233
+ it_registers
234
+ end # describe
235
+
236
+ describe 'blank' do
237
+ let(:value) { '' }
238
+ it_does_not_have_errors
239
+ it_registers
240
+ end # describe
241
+
242
+ describe 'invalid' do
243
+ let(:value) { 'foo bar' }
244
+ it_is_invalid
245
+ it_does_not_register
246
+ end # describe
247
+
248
+ describe 'valid' do
249
+ let(:value) { 'foobar' }
250
+ it_does_not_have_errors
251
+ it_registers
252
+ end # describe
253
+ end # describe config
254
+ end # describe password
255
+ end # describe by field
256
+ end # describe .register
257
+ end # describe Business::SignUp
258
+ end # module Hello