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 @@
1
+ capability: Manage Profile
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.api "API" do
4
+
5
+ pending "TODO: JSON suppport"
6
+
7
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.uic "Profile Page" do
4
+
5
+
6
+
7
+ def self._before__given_I_am_on_the_profile_page
8
+ before do
9
+ Given "I am on the Profile Management Page" do
10
+ given_I_have_signed_in
11
+ click_link "Settings"
12
+ expect(current_path).to eq hello_path
13
+ end
14
+ end
15
+ end
16
+
17
+
18
+
19
+ story "Update Fields" do
20
+ _before__given_I_am_on_the_profile_page
21
+
22
+
23
+
24
+ scenario "Valid" do
25
+ When "I submit new valid values in the form" do
26
+ fill_in 'user_name', with: (@new_name = 'James Pinto')
27
+ fill_in 'user_city', with: (@new_city = 'Brasilia')
28
+ fill_in 'user_username', with: (@new_username = 'new_username')
29
+ click_button 'Update'
30
+ end
31
+
32
+
33
+
34
+ Then "I should see a confirmation message" do
35
+ expect_flash_notice "You have updated your profile successfully"
36
+ end
37
+
38
+
39
+
40
+ Then "and the new values should reflect on the database" do
41
+ user = User.last
42
+ expect(user.name).to eq(@new_name)
43
+ expect(user.city).to eq(@new_city)
44
+ expect(user.username).to eq(@new_username)
45
+ end
46
+ end
47
+
48
+
49
+
50
+ scenario "Invalid" do
51
+ When "I submit new invalid values in the form" do
52
+ fill_in 'user_name', with: ''
53
+ click_button 'Update'
54
+ end
55
+
56
+
57
+
58
+ Then "I should see an alert message" do
59
+ expect_error_message "1 error was found while updating your profile"
60
+ end
61
+ end
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1 @@
1
+ capability: Manage Social Credentials
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.uic "-" do
4
+
5
+ pending
6
+
7
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.capability 'I can Unlink Sessions' do
4
+
5
+ role 'User' do
6
+ Given 'I am a User' do
7
+ sign_in_as_a('user')
8
+ expect(Access.count).to eq(1)
9
+ end
10
+
11
+ uic 'Unlink Button', type: :feature do
12
+
13
+ scenario 'Two Accesses' do
14
+
15
+ Given 'a second device has logged into my account' do
16
+ create(:valid_access, user: current_user)
17
+ end
18
+
19
+ Given 'I visit the Accesses Page' do
20
+ visit '/'
21
+ click_link 'Settings'
22
+ click_link 'Devices'
23
+ end
24
+
25
+ Given 'I go through sudo mode' do
26
+ fill_in 'user_password', with: '1234'
27
+ click_button 'Confirm'
28
+ end
29
+
30
+ Given 'I should have 2 accesses in the database but only see 1 unlink button' do
31
+ expect(Access.where(user_id: current_user.id).count).to eq(2)
32
+ expect(page).to have_button('Unlink', count: 1)
33
+ end
34
+
35
+ When 'I attempt to unlink the second device' do
36
+ click_button 'Unlink'
37
+ end
38
+
39
+ Then 'I should see a confirmation message' do
40
+ expect_flash_notice('Device has been unlinked from your account')
41
+ end
42
+
43
+ Then 'Database now has 1 Access' do
44
+ expect(Access.count).to eq(1)
45
+ end
46
+
47
+ end # scenario
48
+
49
+ end # uic
50
+
51
+ api 'API', type: :request do
52
+
53
+ skip 'TODO: write API features here too'
54
+
55
+ end # api
56
+
57
+ end # role
58
+
59
+ end # capability
@@ -0,0 +1 @@
1
+ goal: Other
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.capability "I can Create Users" do
4
+
5
+ role "Webmaster" do
6
+ context "Components", type: :feature do
7
+
8
+ Given "I am a Webmaster" do
9
+ sign_in_as_a('webmaster')
10
+ expect_to_see "dummy-accounts-1"
11
+ end
12
+
13
+ uic "New User Webmaster Page" do
14
+
15
+ Given "a user James exists" do
16
+ create(:user, id: 1234, username: 'james')
17
+ end
18
+
19
+ Given 'I visit New User Webmaster Page with Sudo Mode' do
20
+ visit '/'
21
+ click_link 'User List'
22
+ click_link "View User List as a Webmaster"
23
+ fill_in 'user_password', with: '1234'
24
+ click_button 'Confirm'
25
+ click_link "New User as a Webmaster"
26
+ end
27
+
28
+ scenario "Success" do
29
+
30
+ When 'I submit a new user John' do
31
+ fill_in 'user_city', with: 'Brasilia'
32
+ fill_in 'user_name', with: 'john'
33
+ fill_in 'user_username', with: 'john'
34
+ fill_in 'user_email', with: 'john@test.com'
35
+ fill_in 'user_password', with: '1234'
36
+ click_button 'Create'
37
+ end
38
+
39
+ Then "I should see a confirmation message" do
40
+ expect_flash_notice 'You have signed up successfully'
41
+ end
42
+
43
+ Then "There should be 3 users in the database" do
44
+ expect(User.count).to eq(3)
45
+ end
46
+ end # scenario
47
+
48
+
49
+ scenario "Failure" do
50
+
51
+ When 'I submit a new user James' do
52
+ # fill_in 'user_password', with: '1234'
53
+ click_button 'Create'
54
+ end
55
+
56
+ Then "I should see an error message" do
57
+ expect_to_see "errors were"
58
+ end
59
+
60
+ Then "There should be 2 users in the database" do
61
+ expect(User.count).to eq(2)
62
+ end
63
+ end # scenario
64
+
65
+ end # uic
66
+ end # context
67
+
68
+ end # role
69
+
70
+ end # capability
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.capability "I can Impersonate Users" do
4
+
5
+ role "Webmaster" do
6
+ context "Components", type: :feature do
7
+
8
+ Given "I am a Webmaster" do
9
+ sign_in_as_a('webmaster')
10
+ expect_to_see "dummy-accounts-1"
11
+ end
12
+
13
+ uic "Users List Webmaster Page" do
14
+
15
+ Given "a user James exists" do
16
+ create(:user, id: 1234, username: 'james')
17
+ end
18
+
19
+ scenario "Success" do
20
+ Given 'I visit Users List Webmaster Page with Sudo Mode' do
21
+ visit '/'
22
+ click_link 'User List'
23
+ click_link "View User List as a Webmaster"
24
+ end
25
+
26
+ Given 'I go through sudo mode' do
27
+ fill_in 'user_password', with: '1234'
28
+ click_button 'Confirm'
29
+ end
30
+
31
+ When "I attempt to impersonate James" do
32
+ click_button 'Impersonate!'
33
+ end
34
+
35
+ Then "I should see a confirmation message" do
36
+ expect_flash_notice "You have signed in successfully"
37
+ end
38
+
39
+ Then "I should be signed in as a User" do
40
+ then_I_should_see "dummy-logged-in-role-user"
41
+ end
42
+
43
+ Then "I should be signed in with Sudo Mode" do
44
+ then_I_should_see "dummy-logged-in-with-sudo-mode"
45
+ end
46
+
47
+ Then "I should be signed in with 2 accounts" do
48
+ expect_to_see "dummy-accounts-2"
49
+ end
50
+ end # scenario
51
+
52
+
53
+ end # uic
54
+ end # context
55
+
56
+ end # role
57
+
58
+ end # capability
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.capability "I can List Users" do
4
+
5
+ %w[guest onboarding user webmaster].each do |role_string|
6
+ role role_string.titleize do
7
+ context "Components", type: :feature do
8
+
9
+ Given "I am a #{role_string.titleize}" do
10
+ sign_in_as_a(role_string)
11
+ end
12
+
13
+ uic "User List Page" do
14
+
15
+ scenario 'I have access to the page' do
16
+
17
+ When 'I visit the users page' do
18
+ visit '/'
19
+ click_link 'User List'
20
+ end
21
+
22
+ Then 'I should be on the users page' do
23
+ expect_to_be_on('/users')
24
+ end
25
+
26
+ end # scenario
27
+
28
+ end # uic
29
+
30
+ uic "User Page" do
31
+
32
+ Given "a user James exists" do
33
+ create(:user, id: 1234, username: 'james')
34
+ end
35
+
36
+ story "Accessing the page" do
37
+
38
+ scenario "Via User List Page" do
39
+ When 'I visit james profile from the User List page' do
40
+ visit '/'
41
+ click_link 'User List'
42
+ click_link 'james'
43
+ end
44
+ end # scenario
45
+
46
+ scenario "Via Direct Link" do
47
+ When "I visit james profile from a direct link" do
48
+ visit "/users/james"
49
+ end
50
+ end # scenario
51
+
52
+ end # story
53
+
54
+ story "Redirects to username" do
55
+
56
+ scenario "Visits ID route" do
57
+ When "I visit the ID route" do
58
+ visit "/users/1234"
59
+ end
60
+ end # scenario
61
+
62
+ scenario "Visits username route" do
63
+ When "I visit the username route" do
64
+ visit "/users/james"
65
+ end
66
+ end # scenario
67
+
68
+ end # story
69
+
70
+ Then "I should be on james username route" do
71
+ expect_to_be_on '/users/james'
72
+ end
73
+
74
+ end # uic
75
+ end # context
76
+
77
+ context "API", type: :request do
78
+ api "API" do
79
+ skip "ToDo: write API features here too"
80
+ end
81
+ end # context
82
+
83
+ end # role
84
+ end
85
+
86
+ end # capability
@@ -0,0 +1 @@
1
+ goal: Registration
@@ -0,0 +1,228 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.bdd.capability "I can Sign Up With Email" do
4
+
5
+ role "Guest" do
6
+ Given "I am a Guest" do
7
+ end
8
+
9
+ describe 'config.sign_up_disabled = hash' do
10
+ Given 'Classic Sign Up is disabled' do
11
+ expect(Hello.configuration).to receive(:sign_up_disabled).at_least(:once).and_return({reason: "standard maintenance", until: "3PM"})
12
+ end
13
+
14
+ uic "Single Form", type: :feature do
15
+
16
+ scenario "-" do
17
+ When "I visit the sign up page" do
18
+ visit "/hello/sign_up"
19
+ end
20
+
21
+ Then 'I should be on the disabled page' do
22
+ expect_to_see('disabled')
23
+ expect_to_see('Reason: standard maintenance')
24
+ expect_to_see('Until: 3PM')
25
+ end
26
+ end # scenario
27
+
28
+ end # uic
29
+
30
+ uic "Widget", type: :feature do
31
+ scenario "-" do
32
+ When "I visit the sign up widget" do
33
+ visit "/hello/sign_up/widget"
34
+ expect_not_to_have_a_layout
35
+ end
36
+
37
+ Then 'I should be on the disabled page' do
38
+ expect_to_see('disabled')
39
+ expect_to_see('Reason: standard maintenance')
40
+ expect_to_see('Until: 3PM')
41
+ end
42
+ end # scenario
43
+
44
+ end # uic
45
+
46
+ api "API", type: :request do
47
+ scenario "Valid Parameters" do
48
+ When "I sign up with valid parameters" do
49
+ post "/hello/sign_up.json", sign_up: {email: "foo@bar.com", password: "foobar", name: "Foo Bar", city: "Brasilia", username: "foobar"}
50
+ end
51
+ end # scenario
52
+
53
+ scenario "Blank Parameters" do
54
+ When "I sign up with an empty parameters" do
55
+ post "/hello/sign_up.json", sign_up: {email: ''}
56
+ end
57
+ end # scenario
58
+
59
+ Then "I should see errors" do
60
+ expect(json_response).to eq({
61
+ "base" => ["Email Registration is temporarily disabled"],
62
+ "reason" => [["standard maintenance"]],
63
+ "until" => [["3PM"]],
64
+ })
65
+ end
66
+
67
+ Then "I should get a 422 response" do
68
+ expect(response.status).to eq(422)
69
+ expect(response.status_message).to eq('Unprocessable Entity')
70
+ end
71
+
72
+ Then "Database now has 0 User, 0 Email, 0 Password, 0 Access" do
73
+ expect(User.count).to eq(0)
74
+ expect(EmailCredential.count).to eq(0)
75
+ expect(PasswordCredential.count).to eq(0)
76
+ expect(Access.count).to eq(0)
77
+ end
78
+ end # api
79
+ end
80
+
81
+ describe 'config.sign_up_disabled = false' do
82
+ uic "Single Form", type: :feature do
83
+ Given "I am on the sign up page" do
84
+ visit "/hello/sign_up"
85
+ end
86
+
87
+ scenario "Valid Form" do
88
+ When "I sign up with a valid form" do
89
+ fill_in_registration_form
90
+ click_button 'Sign Up'
91
+ end
92
+
93
+ Then "I should see a confirmation message" do
94
+ expect_flash_notice "You have signed up successfully"
95
+ end
96
+
97
+ Then "I should be on the onboarding page" do
98
+ expect(User.last.role).to eq('onboarding')
99
+ expect_to_be_on '/onboarding'
100
+ end
101
+
102
+ Then "Database now has 1 User, 1 Email, 1 Password, 1 Access" do
103
+ expect(User.count).to eq(1)
104
+ expect(EmailCredential.count).to eq(1)
105
+ expect(PasswordCredential.count).to eq(1)
106
+ expect(Access.count).to eq(1)
107
+ end
108
+ end # scenario
109
+
110
+ scenario "Empty Form" do
111
+ When "I sign up with an empty form" do
112
+ click_button 'Sign Up'
113
+ end
114
+
115
+ Then "I should see an error message" do
116
+ expect_error_message "errors were found while trying to sign up"
117
+ end
118
+
119
+ Then "I should be on the sign up page" do
120
+ expect_to_be_on hello.sign_up_path
121
+ end
122
+
123
+ Then "Database now has 0 User, 0 Email, 0 Password, 0 Access" do
124
+ expect(User.count).to eq(0)
125
+ expect(EmailCredential.count).to eq(0)
126
+ expect(PasswordCredential.count).to eq(0)
127
+ expect(Access.count).to eq(0)
128
+ end
129
+ end # scenario
130
+ end # uic
131
+
132
+ uic "Widget", type: :feature do
133
+ Given "I am on the sign up widget" do
134
+ visit "/hello/sign_up/widget"
135
+ expect_not_to_have_a_layout
136
+ end
137
+
138
+ scenario "Valid Form" do
139
+ skip
140
+ end # scenario
141
+
142
+ scenario "Empty Form" do
143
+ When "I sign up with an empty form" do
144
+ click_button 'Sign Up'
145
+ end
146
+
147
+ Then "I should see an error message" do
148
+ expect_error_message "errors were found while trying to sign up"
149
+ end
150
+
151
+ Then "I should be on the sign up page" do
152
+ expect_to_be_on hello.sign_up_path
153
+ end
154
+
155
+ Then "Database now has 0 User, 0 Email, 0 Password, 0 Access" do
156
+ expect(User.count).to eq(0)
157
+ expect(EmailCredential.count).to eq(0)
158
+ expect(PasswordCredential.count).to eq(0)
159
+ expect(Access.count).to eq(0)
160
+ end
161
+
162
+ Then "page should no longer be a widget" do
163
+ expect_to_have_a_layout
164
+ end
165
+ end # scenario
166
+ end # uic
167
+
168
+ api "API", type: :request do
169
+ scenario "Valid Parameters" do
170
+ When "I sign up with valid parameters" do
171
+ post "/hello/sign_up.json", sign_up: {email: "foo@bar.com", password: "foobar", name: "Foo Bar", city: "Brasilia", username: "foobar"}
172
+ end
173
+
174
+ Then "I should see the access object" do
175
+ expect(json_response.keys).to match_array ["expires_at", "token", "user", "user_id"]
176
+ expect(json_response["user"].keys).to match_array ["id", "accesses_count", "city", "created_at", "credentials_count", "locale", "name", "role", "time_zone", "updated_at", "username"]
177
+ end
178
+
179
+ Then "I should get a 201 response" do
180
+ expect(response.status).to eq(201)
181
+ expect(response.status_message).to eq('Created')
182
+ end
183
+
184
+ Then "User should have onboarding role" do
185
+ expect(json_response['user']['role']).to eq "onboarding"
186
+ end
187
+
188
+ Then "Database now has 1 User, 1 Email, 1 Password, 1 Access" do
189
+ expect(User.count).to eq(1)
190
+ expect(EmailCredential.count).to eq(1)
191
+ expect(PasswordCredential.count).to eq(1)
192
+ expect(Access.count).to eq(1)
193
+ end
194
+ end # scenario
195
+
196
+ scenario "Blank Parameters" do
197
+ When "I sign up with an empty parameters" do
198
+ post "/hello/sign_up.json", sign_up: {email: ''}
199
+ end
200
+
201
+ Then "I should see errors" do
202
+ expect(json_response).to eq({
203
+ "username"=>["can't be blank"],
204
+ "email"=>["can't be blank"],
205
+ "password"=>["can't be blank"],
206
+ "name"=>["can't be blank"],
207
+ "city"=>["can't be blank"]
208
+ })
209
+ end
210
+
211
+ Then "I should get a 422 response" do
212
+ expect(response.status).to eq(422)
213
+ expect(response.status_message).to eq('Unprocessable Entity')
214
+ end
215
+
216
+ Then "Database now has 0 User, 0 Email, 0 Password, 0 Access" do
217
+ expect(User.count).to eq(0)
218
+ expect(EmailCredential.count).to eq(0)
219
+ expect(PasswordCredential.count).to eq(0)
220
+ expect(Access.count).to eq(0)
221
+ end
222
+ end # scenario
223
+ end # api
224
+
225
+ end # describe config
226
+ end # role
227
+
228
+ end # capability