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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +97 -0
- data/Rakefile +23 -0
- data/app/controllers/hello/application_controller.rb +27 -0
- data/app/controllers/hello/authentication/sessions_controller.rb +81 -0
- data/app/controllers/hello/authentication/sign_in_controller.rb +39 -0
- data/app/controllers/hello/authentication/sudo_mode_controller.rb +40 -0
- data/app/controllers/hello/concerns/authentication/sign_in.rb +44 -0
- data/app/controllers/hello/concerns/management/forgot_password.rb +45 -0
- data/app/controllers/hello/concerns/management/reset_password.rb +33 -0
- data/app/controllers/hello/concerns/registration/sign_up.rb +64 -0
- data/app/controllers/hello/internationalization/locale_controller.rb +28 -0
- data/app/controllers/hello/management/accesses_controller.rb +29 -0
- data/app/controllers/hello/management/confirm_emails_controller.rb +41 -0
- data/app/controllers/hello/management/emails_controller.rb +67 -0
- data/app/controllers/hello/management/forgot_password_controller.rb +41 -0
- data/app/controllers/hello/management/passwords_controller.rb +57 -0
- data/app/controllers/hello/management/profiles_controller.rb +71 -0
- data/app/controllers/hello/management/reset_password_controller.rb +53 -0
- data/app/controllers/hello/registration/sign_up_controller.rb +63 -0
- data/app/helpers/hello/application_helper.rb +5 -0
- data/app/mailers/hello/mailer.rb +26 -0
- data/app/models/access.rb +2 -0
- data/app/models/credential.rb +2 -0
- data/app/models/email_credential.rb +2 -0
- data/app/models/password_credential.rb +2 -0
- data/app/models/user.rb +2 -0
- data/app/views/hello/authentication/_sign_in.html.erb +64 -0
- data/app/views/hello/authentication/new_session.html.erb +4 -0
- data/app/views/hello/authentication/sessions.html.erb +36 -0
- data/app/views/hello/authentication/sign_in.html.erb +3 -0
- data/app/views/hello/authentication/sudo_mode.html.erb +37 -0
- data/app/views/hello/internationalization/locales.html.erb +7 -0
- data/app/views/hello/mailer/confirm_email.html.erb +12 -0
- data/app/views/hello/mailer/forgot_password.html.erb +12 -0
- data/app/views/hello/mailer/welcome.html.erb +11 -0
- data/app/views/hello/management/accesses.html.erb +47 -0
- data/app/views/hello/management/cancel.html.erb +14 -0
- data/app/views/hello/management/email_credentials/expired_confirmation_token.html.erb +1 -0
- data/app/views/hello/management/email_credentials/index.html.erb +84 -0
- data/app/views/hello/management/password_credentials/_forgot_form.html.erb +17 -0
- data/app/views/hello/management/password_credentials/_reset_form.html.erb +39 -0
- data/app/views/hello/management/password_credentials/forgot.html.erb +10 -0
- data/app/views/hello/management/password_credentials/forgot_success.html.erb +26 -0
- data/app/views/hello/management/password_credentials/reset.html.erb +3 -0
- data/app/views/hello/management/password_credentials/show.html.erb +25 -0
- data/app/views/hello/management/user.html.erb +73 -0
- data/app/views/hello/registration/_sign_up.html.erb +86 -0
- data/app/views/hello/registration/sign_up.html.erb +3 -0
- data/app/views/hello/registration/sign_up_widget.html.erb +3 -0
- data/app/views/hello/shared/_errors.html.erb +11 -0
- data/app/views/hello/shared/_flash.html.erb +8 -0
- data/app/views/hello/shared/_nav_pills.html.erb +15 -0
- data/app/views/hello/shared/_session_expiration.html.erb +15 -0
- data/app/views/hello/shared/_settings.html.erb +41 -0
- data/config/locales/hello.en.yml +69 -0
- data/config/locales/hello.es.yml +71 -0
- data/config/locales/hello.fr.yml +71 -0
- data/config/locales/hello.pl.yml +71 -0
- data/config/locales/hello.pt-BR.yml +71 -0
- data/config/locales/hello.zh-CN.yml +71 -0
- data/config/locales/hello.zh-TW.yml +71 -0
- data/config/routes.rb +74 -0
- data/db/migrate/1_create_credentials.rb +17 -0
- data/db/migrate/2_create_accesses.rb +15 -0
- data/db/migrate/3_create_users.rb +23 -0
- data/lib/generators/hello/concerns/USAGE +8 -0
- data/lib/generators/hello/concerns/concerns_generator.rb +10 -0
- data/lib/generators/hello/from_devise/USAGE +8 -0
- data/lib/generators/hello/from_devise/from_devise_generator.rb +13 -0
- data/lib/generators/hello/from_devise/templates/from_devise.migration.rb +39 -0
- data/lib/generators/hello/install/USAGE +8 -0
- data/lib/generators/hello/install/install_generator.rb +94 -0
- data/lib/generators/hello/install/templates/application.html.erb +35 -0
- data/lib/generators/hello/install/templates/hello_helper.rb +16 -0
- data/lib/generators/hello/install/templates/initializer.rb +24 -0
- data/lib/generators/hello/install/templates/models/concerns/user/authorization.rb +21 -0
- data/lib/generators/hello/install/templates/models/user.rb +9 -0
- data/lib/generators/hello/install/templates/onboarding/index.html.erb +5 -0
- data/lib/generators/hello/install/templates/onboarding/onboarding_controller.rb +33 -0
- data/lib/generators/hello/install/templates/root/index.html.erb +7 -0
- data/lib/generators/hello/install/templates/root/root_controller.rb +6 -0
- data/lib/generators/hello/install/templates/users/controllers/users_controller.rb +71 -0
- data/lib/generators/hello/install/templates/users/views/users/index.html.erb +29 -0
- data/lib/generators/hello/install/templates/users/views/users/list.html.erb +35 -0
- data/lib/generators/hello/install/templates/users/views/users/new.html.erb +60 -0
- data/lib/generators/hello/install/templates/users/views/users/show.html.erb +74 -0
- data/lib/generators/hello/locales/USAGE +12 -0
- data/lib/generators/hello/locales/locales_generator.rb +64 -0
- data/lib/generators/hello/views/USAGE +8 -0
- data/lib/generators/hello/views/views_generator.rb +9 -0
- data/lib/hello-rails.rb +1 -0
- data/lib/hello.rb +36 -0
- data/lib/hello/CHANGES.md +26 -0
- data/lib/hello/business.rb +47 -0
- data/lib/hello/business/authentication/sign_in.rb +92 -0
- data/lib/hello/business/authentication/sign_out.rb +8 -0
- data/lib/hello/business/authentication/sudo_mode_authentication.rb +25 -0
- data/lib/hello/business/authentication/sudo_mode_expiration.rb +17 -0
- data/lib/hello/business/base.rb +33 -0
- data/lib/hello/business/internationalization/update_locale.rb +33 -0
- data/lib/hello/business/management/add_email.rb +19 -0
- data/lib/hello/business/management/cancel_account.rb +22 -0
- data/lib/hello/business/management/confirm_email.rb +36 -0
- data/lib/hello/business/management/forgot_password.rb +47 -0
- data/lib/hello/business/management/remove_email.rb +19 -0
- data/lib/hello/business/management/reset_password.rb +34 -0
- data/lib/hello/business/management/send_confirmation_email.rb +40 -0
- data/lib/hello/business/management/unlink_access.rb +8 -0
- data/lib/hello/business/management/update_profile.rb +44 -0
- data/lib/hello/business/registration/sign_up.rb +159 -0
- data/lib/hello/configuration.rb +12 -0
- data/lib/hello/encryptors.rb +6 -0
- data/lib/hello/encryptors/complex.rb +25 -0
- data/lib/hello/encryptors/simple.rb +27 -0
- data/lib/hello/engine.rb +23 -0
- data/lib/hello/errors.rb +12 -0
- data/lib/hello/locales.rb +238 -0
- data/lib/hello/middleware.rb +13 -0
- data/lib/hello/rails_active_record.rb +10 -0
- data/lib/hello/rails_active_record/access.rb +65 -0
- data/lib/hello/rails_active_record/credential.rb +51 -0
- data/lib/hello/rails_active_record/email_credential.rb +60 -0
- data/lib/hello/rails_active_record/password_credential.rb +70 -0
- data/lib/hello/rails_active_record/user.rb +99 -0
- data/lib/hello/rails_controller.rb +124 -0
- data/lib/hello/rails_controller/restrict_by_role.rb +79 -0
- data/lib/hello/rails_helper.rb +35 -0
- data/lib/hello/request_manager.rb +14 -0
- data/lib/hello/request_manager/abstract.rb +77 -0
- data/lib/hello/request_manager/factory.rb +32 -0
- data/lib/hello/request_manager/stateful.rb +53 -0
- data/lib/hello/request_manager/stateful/finder.rb +58 -0
- data/lib/hello/request_manager/stateful/session_wrapper.rb +37 -0
- data/lib/hello/request_manager/stateless.rb +35 -0
- data/lib/hello/time_zones.rb +7 -0
- data/lib/hello/utils.rb +11 -0
- data/lib/hello/utils/device_name.rb +34 -0
- data/lib/hello/version.rb +4 -0
- data/lib/tasks/hello_tasks.rake +4 -0
- data/spec/bdd/hello/authentication/authorization/authorization_role_restriction_spec.rb +291 -0
- data/spec/bdd/hello/authentication/authorization/authorization_router_constraints_spec.rb +41 -0
- data/spec/bdd/hello/authentication/authorization/authorization_sensitive_restriction_spec.rb +84 -0
- data/spec/bdd/hello/authentication/authorization/bdd.yml +1 -0
- data/spec/bdd/hello/authentication/bdd.yml +1 -0
- data/spec/bdd/hello/authentication/classic_sign_in_spec.rb +264 -0
- data/spec/bdd/hello/authentication/manage_sessions_spec.rb +292 -0
- data/spec/bdd/hello/authentication/sign_out_spec.rb +159 -0
- data/spec/bdd/hello/bdd.yml +1 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/bdd.yml +1 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_locale_page_spec.rb +90 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_profile_page_spec.rb +64 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_in_form_spec.rb +31 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_up_form_spec.rb +34 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/bdd.yml +1 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_profile_page_spec.rb +14 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_sign_in_form_spec.rb +14 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_sign_up_form_spec.rb +14 -0
- data/spec/bdd/hello/internalionalization/bdd.yml +1 -0
- data/spec/bdd/hello/management/bdd.yml +1 -0
- data/spec/bdd/hello/management/cancel_account_spec.rb +128 -0
- data/spec/bdd/hello/management/manage_email_credentials/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_api_spec.rb +7 -0
- data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_page_spec.rb +252 -0
- data/spec/bdd/hello/management/manage_password_credentials/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_forgot_password_spec.rb +68 -0
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_page_spec.rb +60 -0
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_reset_password_spec.rb +145 -0
- data/spec/bdd/hello/management/manage_profile/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_profile/manage_profile_api_spec.rb +7 -0
- data/spec/bdd/hello/management/manage_profile/manage_profile_page_spec.rb +65 -0
- data/spec/bdd/hello/management/manage_social_credentials/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_social_credentials/manage_social_credentials_pending_spec.rb +7 -0
- data/spec/bdd/hello/management/unlink_sessions_spec.rb +59 -0
- data/spec/bdd/hello/other/bdd.yml +1 -0
- data/spec/bdd/hello/other/create_user_spec.rb +70 -0
- data/spec/bdd/hello/other/impersonate_user_spec.rb +58 -0
- data/spec/bdd/hello/other/list_users_spec.rb +86 -0
- data/spec/bdd/hello/registration/bdd.yml +1 -0
- data/spec/bdd/hello/registration/classic_sign_up_spec.rb +228 -0
- data/spec/bdd/hello/registration/onboarding_process_spec.rb +101 -0
- data/spec/bdd/hello/support.rb +62 -0
- data/spec/business/hello/authentication/sign_in_spec.rb +72 -0
- data/spec/business/hello/registration/sign_up_spec.rb +258 -0
- data/spec/controllers/authentication_spec.rb +97 -0
- data/spec/controllers/localization_spec.rb +65 -0
- data/spec/controllers/request_can_carry_an_access_token_spec.rb +223 -0
- data/spec/fixtures/hello/password_mailer/confirmation +3 -0
- data/spec/fixtures/hello/password_mailer/forgot +3 -0
- data/spec/fixtures/hello/password_mailer/sign_up +3 -0
- data/spec/mailers/hello/mailer_spec.rb +53 -0
- data/spec/models/access_spec.rb +19 -0
- data/spec/models/credential_spec.rb +9 -0
- data/spec/models/email_credential_spec.rb +163 -0
- data/spec/models/hello/sign_up_model_spec.rb +64 -0
- data/spec/models/password_credential_spec.rb +75 -0
- data/spec/models/user_spec.rb +93 -0
- data/spec/others/configuration_spec.rb +25 -0
- data/spec/others/encryptors/complex_spec.rb +26 -0
- data/spec/others/encryptors/simple_spec.rb +21 -0
- data/spec/others/helper_spec.rb +10 -0
- data/spec/others/localization_consistency_spec.rb +73 -0
- data/spec/requests/forgot_password_spec.rb +36 -0
- data/spec/requests/reset_password_spec.rb +7 -0
- data/spec/requests/security/user_spec.rb +19 -0
- data/spec/routing/hello/accesses_routing_spec.rb +17 -0
- data/spec/routing/hello/emails_routing_spec.rb +37 -0
- data/spec/routing/hello/locale_routing_spec.rb +17 -0
- data/spec/routing/hello/profile_routing_spec.rb +29 -0
- data/spec/routing/hello/registration_routing_spec.rb +23 -0
- data/spec/routing/hello/sign_out_routing_spec.rb +11 -0
- data/spec/routing/hello/sudo_mode_routing_spec.rb +23 -0
- data/spec/routing/hello/users_routing_spec.rb +15 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/spec_helper/codeclimate.rb +2 -0
- data/spec/spec_helper/configure_rspec.rb +23 -0
- data/spec/spec_helper/create_database.rb +5 -0
- data/spec/spec_helper/dummy_and_test_dependencies.rb +17 -0
- data/spec/spec_helper/support.rb +1 -0
- data/spec/support/factories.rb +60 -0
- data/spec/support/feature_injection.rb +118 -0
- data/spec/support/features/feature_support_given.rb +46 -0
- data/spec/support/features/feature_support_then.rb +43 -0
- data/spec/support/helpers/aliases.rb +76 -0
- data/spec/support/helpers/configuration.rb +6 -0
- data/spec/support/helpers/current.rb +16 -0
- data/spec/support/helpers/expect.rb +61 -0
- data/spec/support/helpers/given.rb +49 -0
- data/spec/support/helpers/shortcuts.rb +24 -0
- data/spec/support/helpers/then.rb +29 -0
- data/spec/support/helpers/when.rb +108 -0
- data/spec/support/requests/request_support.rb +8 -0
- data/spec/utils/device_name_spec.rb +228 -0
- metadata +562 -11
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.bdd.uic "Router Constraints" do
|
4
|
+
|
5
|
+
story "For Users" do
|
6
|
+
scenario "As a Guest" do
|
7
|
+
Given "I am a Guest" do
|
8
|
+
# :)
|
9
|
+
end
|
10
|
+
|
11
|
+
When "I visit a route constrained to users" do
|
12
|
+
# :)
|
13
|
+
end
|
14
|
+
|
15
|
+
Then "I should see a 404 error" do
|
16
|
+
expect {
|
17
|
+
visit "/middleware/bad_kitty"
|
18
|
+
}.to raise_error ActionController::RoutingError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
scenario "As a User" do
|
25
|
+
Given "I am a User" do
|
26
|
+
given_I_have_signed_in
|
27
|
+
end
|
28
|
+
|
29
|
+
When "I visit a route constrained to users" do
|
30
|
+
# :)
|
31
|
+
end
|
32
|
+
|
33
|
+
Then "I should not see a 404 error" do
|
34
|
+
expect {
|
35
|
+
visit "/middleware/bad_kitty"
|
36
|
+
}.not_to raise_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.bdd.uic "Sensitive Restriction" do
|
4
|
+
|
5
|
+
story "Enable Sudo Mode" do
|
6
|
+
before do
|
7
|
+
Given "I see the Sudo Mode form" do
|
8
|
+
given_I_have_signed_in
|
9
|
+
|
10
|
+
click_link "Settings"
|
11
|
+
click_link "Devices"
|
12
|
+
|
13
|
+
expect(page).to have_content "Confirm Password to Continue"
|
14
|
+
expect(current_path).to eq hello.accesses_path
|
15
|
+
expect(Access.last.sudo_expires_at).to be < Time.now
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
scenario "Success" do
|
22
|
+
When "I submit the correct password" do
|
23
|
+
when_I_confirm_my_user_password
|
24
|
+
end
|
25
|
+
|
26
|
+
Then "and I should see a confirmation message" do
|
27
|
+
expect_flash_notice "Now we know it's really you. We won't be asking your password again for 60 minutes"
|
28
|
+
end
|
29
|
+
|
30
|
+
then_I_expect_to_be_on_sudo_mode
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
scenario "Blank Password" do
|
36
|
+
When "I submit an empty form" do
|
37
|
+
when_I_confirm_my_user_password('', false)
|
38
|
+
end
|
39
|
+
|
40
|
+
_then_failed_to_enable_sudo_mode
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
scenario "Wrong Password" do
|
46
|
+
When "I submit an incorrect password" do
|
47
|
+
when_I_confirm_my_user_password('wrong', false)
|
48
|
+
end
|
49
|
+
|
50
|
+
_then_failed_to_enable_sudo_mode
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
story "Disable Sudo Mode" do
|
57
|
+
scenario "Success" do
|
58
|
+
given_I_have_signed_in_with_sudo_mode
|
59
|
+
|
60
|
+
When "I disable sudo mode" do
|
61
|
+
click_link "expire"
|
62
|
+
end
|
63
|
+
|
64
|
+
Then "I should see a confirmation message" do
|
65
|
+
expect_flash_notice "We will now ask your password for sensitive access"
|
66
|
+
end
|
67
|
+
|
68
|
+
then_I_expect_not_to_be_on_sudo_mode
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
def _then_failed_to_enable_sudo_mode
|
75
|
+
Then "I expect to see an error message" do
|
76
|
+
expect_flash_alert "Incorrect Password"
|
77
|
+
end
|
78
|
+
|
79
|
+
then_I_expect_not_to_be_on_sudo_mode
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
capability: Authorization
|
@@ -0,0 +1 @@
|
|
1
|
+
goal: Authentication
|
@@ -0,0 +1,264 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.bdd.capability 'I can Sign In With Email' do
|
4
|
+
|
5
|
+
role 'User' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
given_I_have_an_email_credential
|
9
|
+
expect(Access.count).to eq(0)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'Components', type: :feature do
|
13
|
+
|
14
|
+
uic 'Dual Form' do
|
15
|
+
|
16
|
+
scenario 'Empty Form' do
|
17
|
+
When 'I sign in with an empty form' do
|
18
|
+
visit hello.root_path
|
19
|
+
click_button 'Sign In'
|
20
|
+
end
|
21
|
+
|
22
|
+
Then 'I should see an error message' do
|
23
|
+
expect_to_see 'found while trying to sign in'
|
24
|
+
end
|
25
|
+
|
26
|
+
Then 'and be on the sign in page' do
|
27
|
+
expect(current_path).to eq hello.sign_in_path
|
28
|
+
end
|
29
|
+
end # scenario
|
30
|
+
|
31
|
+
end # uic
|
32
|
+
|
33
|
+
uic 'Single Form' do
|
34
|
+
|
35
|
+
context 'General' do
|
36
|
+
|
37
|
+
Given 'I am on the sign in page' do
|
38
|
+
visit '/hello/sign_in'
|
39
|
+
end
|
40
|
+
|
41
|
+
story 'Valid Scearios' do
|
42
|
+
|
43
|
+
scenario 'Valid Email & Password' do
|
44
|
+
When 'I sign in with a valid form' do
|
45
|
+
fill_in_login_form('foo@bar.com')
|
46
|
+
click_button 'Sign In'
|
47
|
+
end
|
48
|
+
end # scenario
|
49
|
+
|
50
|
+
scenario 'Valid Username & Password' do
|
51
|
+
When 'I sign in with a valid form' do
|
52
|
+
fill_in_login_form('foobar')
|
53
|
+
click_button 'Sign In'
|
54
|
+
end
|
55
|
+
end # scenario
|
56
|
+
|
57
|
+
Then 'I should see a confirmation message' do
|
58
|
+
expect_flash_notice 'You have signed in successfully'
|
59
|
+
end
|
60
|
+
|
61
|
+
Then 'I should be on the home page' do
|
62
|
+
expect_to_be_on '/'
|
63
|
+
end
|
64
|
+
|
65
|
+
Then 'Database now has 1 Access' do
|
66
|
+
expect(Access.count).to eq(1)
|
67
|
+
end
|
68
|
+
|
69
|
+
end # story
|
70
|
+
|
71
|
+
story 'Invalid Scearios' do
|
72
|
+
|
73
|
+
scenario 'Empty Form' do
|
74
|
+
When 'I sign in with an empty form' do
|
75
|
+
click_button 'Sign In'
|
76
|
+
end
|
77
|
+
end # scenario
|
78
|
+
|
79
|
+
scenario 'Email not found' do
|
80
|
+
When 'I sign in with an empty form' do
|
81
|
+
click_button 'Sign In'
|
82
|
+
end
|
83
|
+
end # scenario
|
84
|
+
|
85
|
+
scenario 'Username not found' do
|
86
|
+
When 'I sign in with a bad username' do
|
87
|
+
fill_in_login_form('foobar9999')
|
88
|
+
click_button 'Sign In'
|
89
|
+
end
|
90
|
+
end # scenario
|
91
|
+
|
92
|
+
scenario 'Wrong Password' do
|
93
|
+
When 'I sign in with a bad password' do
|
94
|
+
fill_in_login_form('foobar', '9999')
|
95
|
+
click_button 'Sign In'
|
96
|
+
end
|
97
|
+
end # scenario
|
98
|
+
|
99
|
+
scenario 'Blank Password' do
|
100
|
+
When 'I sign in with a bad password' do
|
101
|
+
fill_in_login_form('foobar', '')
|
102
|
+
click_button 'Sign In'
|
103
|
+
end
|
104
|
+
end # scenario
|
105
|
+
|
106
|
+
Then 'I should see a confirmation message' do
|
107
|
+
expect_to_see 'found while trying to sign in'
|
108
|
+
end
|
109
|
+
|
110
|
+
Then 'I should be on the sign in page' do
|
111
|
+
expect_to_be_on '/hello/sign_in'
|
112
|
+
end
|
113
|
+
|
114
|
+
Then 'Database still has 0 Access' do
|
115
|
+
expect(Access.count).to eq(0)
|
116
|
+
end
|
117
|
+
end # story
|
118
|
+
|
119
|
+
end # context
|
120
|
+
|
121
|
+
context 'Extras' do
|
122
|
+
|
123
|
+
story 'Previous URL' do
|
124
|
+
|
125
|
+
scenario 'Has Previous URL' do
|
126
|
+
|
127
|
+
Given 'I visited a page that required me to authenticate' do
|
128
|
+
visit '/onboarding'
|
129
|
+
expect_to_be_on '/hello/sign_in'
|
130
|
+
end
|
131
|
+
|
132
|
+
When 'I sign in with a valid form' do
|
133
|
+
fill_in_login_form('foo@bar.com')
|
134
|
+
click_button 'Sign In'
|
135
|
+
expect_flash_notice 'You have signed in successfully'
|
136
|
+
end
|
137
|
+
|
138
|
+
Then 'I should be on the home page' do
|
139
|
+
expect_to_be_on '/'
|
140
|
+
end
|
141
|
+
|
142
|
+
end # scenario
|
143
|
+
|
144
|
+
scenario 'No Previous URL' do
|
145
|
+
|
146
|
+
Given 'I am on the sign in page' do
|
147
|
+
visit '/hello/sign_in'
|
148
|
+
end
|
149
|
+
|
150
|
+
When 'I sign in with a valid form' do
|
151
|
+
fill_in_login_form('foo@bar.com')
|
152
|
+
click_button 'Sign In'
|
153
|
+
expect_flash_notice 'You have signed in successfully'
|
154
|
+
end
|
155
|
+
|
156
|
+
Then 'I should be on the home page' do
|
157
|
+
expect_to_be_on '/'
|
158
|
+
end
|
159
|
+
|
160
|
+
end # scenario
|
161
|
+
|
162
|
+
end # story
|
163
|
+
|
164
|
+
story 'Keep me' do
|
165
|
+
|
166
|
+
Given 'I am on the sign in page' do
|
167
|
+
visit '/hello/sign_in'
|
168
|
+
end
|
169
|
+
|
170
|
+
scenario 'Checked' do
|
171
|
+
|
172
|
+
Given 'I check "keep me"' do
|
173
|
+
check 'keep_me'
|
174
|
+
end
|
175
|
+
|
176
|
+
When 'I sign in with a valid form' do
|
177
|
+
fill_in_login_form('foo@bar.com')
|
178
|
+
click_button 'Sign In'
|
179
|
+
expect_flash_notice 'You have signed in successfully'
|
180
|
+
end
|
181
|
+
|
182
|
+
Then 'and be signed in for 30 days' do
|
183
|
+
expect(Access.last.expires_at).to be > 29.days.from_now
|
184
|
+
end
|
185
|
+
|
186
|
+
end # scenario
|
187
|
+
|
188
|
+
scenario 'Unchecked' do
|
189
|
+
|
190
|
+
Given 'I do not check "keep me"' do
|
191
|
+
# left blank
|
192
|
+
end
|
193
|
+
|
194
|
+
When 'I sign in with a valid form' do
|
195
|
+
fill_in_login_form('foo@bar.com')
|
196
|
+
click_button 'Sign In'
|
197
|
+
expect_flash_notice 'You have signed in successfully'
|
198
|
+
end
|
199
|
+
|
200
|
+
Then 'and be signed in for 30 minutes' do
|
201
|
+
a = Access.last
|
202
|
+
expect(a.expires_at).to be < 31.minutes.from_now
|
203
|
+
expect(a.expires_at).to be > 29.minutes.from_now
|
204
|
+
end
|
205
|
+
|
206
|
+
end # scenario
|
207
|
+
|
208
|
+
end # story
|
209
|
+
|
210
|
+
end # context
|
211
|
+
|
212
|
+
end # uic
|
213
|
+
|
214
|
+
end # context
|
215
|
+
|
216
|
+
api 'API', type: :request do
|
217
|
+
|
218
|
+
scenario 'Valid Parameters' do
|
219
|
+
When 'I sign in with valid parameters' do
|
220
|
+
post '/hello/sign_in.json', sign_in: {login: 'foo@bar.com', password: '1234'}
|
221
|
+
end
|
222
|
+
|
223
|
+
Then 'I should see the access object' do
|
224
|
+
expect(json_response.keys).to match_array ['expires_at', 'token', 'user', 'user_id']
|
225
|
+
expect(json_response['user'].keys).to match_array ['id', 'accesses_count', 'city', 'created_at', 'credentials_count', 'locale', 'name', 'role', 'time_zone', 'updated_at', 'username']
|
226
|
+
end
|
227
|
+
|
228
|
+
Then 'I should get a 201 response' do
|
229
|
+
expect(response.status).to eq(201)
|
230
|
+
expect(response.status_message).to eq('Created')
|
231
|
+
end
|
232
|
+
|
233
|
+
Then 'Database now has 1 Access' do
|
234
|
+
expect(Access.count).to eq(1)
|
235
|
+
end
|
236
|
+
end # scenario
|
237
|
+
|
238
|
+
scenario 'Blank Parameters' do
|
239
|
+
When 'I sign in with an empty parameters' do
|
240
|
+
post '/hello/sign_in.json', sign_in: {login: ''}
|
241
|
+
end
|
242
|
+
|
243
|
+
Then 'I should see errors' do
|
244
|
+
expect(json_response).to eq({
|
245
|
+
"login"=>["can't be blank"],
|
246
|
+
"password"=>["can't be blank"]
|
247
|
+
})
|
248
|
+
end
|
249
|
+
|
250
|
+
Then 'I should get a 422 response' do
|
251
|
+
expect(response.status).to eq(422)
|
252
|
+
expect(response.status_message).to eq('Unprocessable Entity')
|
253
|
+
end
|
254
|
+
|
255
|
+
Then 'Database now has 0 Access' do
|
256
|
+
expect(Access.count).to eq(0)
|
257
|
+
end
|
258
|
+
end # scenario
|
259
|
+
|
260
|
+
end # api
|
261
|
+
|
262
|
+
end # role
|
263
|
+
|
264
|
+
end # capability
|
@@ -0,0 +1,292 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.bdd.capability 'I can Manage Sessions' do
|
4
|
+
|
5
|
+
role 'User' do
|
6
|
+
Given 'I am a User' do
|
7
|
+
sign_in_as_a('user')
|
8
|
+
expect_to_see 'dummy-accounts-1'
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'I can Add Sessions' do
|
12
|
+
|
13
|
+
context 'Components', type: :feature do
|
14
|
+
|
15
|
+
uic 'Sign In Path' do
|
16
|
+
|
17
|
+
Given 'I visit "Switch Accounts" > "Add Account" > "Sign In"' do
|
18
|
+
visit '/'
|
19
|
+
click_link 'Switch Accounts'
|
20
|
+
click_link 'Add Account'
|
21
|
+
click_link 'Sign In'
|
22
|
+
end
|
23
|
+
|
24
|
+
scenario 'Success' do
|
25
|
+
|
26
|
+
When 'I sign in as a second user' do
|
27
|
+
u = create(:user_user, username: 'foobar')
|
28
|
+
fill_in_login_form(u.username)
|
29
|
+
click_button 'Sign In'
|
30
|
+
end
|
31
|
+
|
32
|
+
Then 'I should see a confirmation message' do
|
33
|
+
expect_flash_notice 'You have signed in successfully'
|
34
|
+
end
|
35
|
+
|
36
|
+
Then 'I should be signed in with 2 sessions' do
|
37
|
+
expect_to_see 'dummy-accounts-2'
|
38
|
+
end
|
39
|
+
|
40
|
+
end # scenario
|
41
|
+
|
42
|
+
scenario 'Invalid Credentials' do
|
43
|
+
|
44
|
+
When 'I sign in as a second user' do
|
45
|
+
fill_in_login_form('doesnotexist')
|
46
|
+
click_button 'Sign In'
|
47
|
+
end
|
48
|
+
|
49
|
+
Then "I should see a validation errors" do
|
50
|
+
expect_error_message "1 error was found while trying to sign in"
|
51
|
+
expect_to_see "This login was not found in our database."
|
52
|
+
end
|
53
|
+
|
54
|
+
Then 'I should be signed in with 1 session' do
|
55
|
+
expect_to_see 'dummy-accounts-1'
|
56
|
+
end
|
57
|
+
|
58
|
+
end # scenario
|
59
|
+
|
60
|
+
end # uic
|
61
|
+
|
62
|
+
uic 'Sign Up Path' do
|
63
|
+
|
64
|
+
Given 'I visit "Switch Accounts" > "Add Account" > "Sign Up"' do
|
65
|
+
visit '/'
|
66
|
+
click_link 'Switch Accounts'
|
67
|
+
click_link 'Add Account'
|
68
|
+
click_link 'Sign Up'
|
69
|
+
end
|
70
|
+
|
71
|
+
scenario 'Success' do
|
72
|
+
|
73
|
+
When 'I sign up with valid data' do
|
74
|
+
fill_in_registration_form
|
75
|
+
click_button 'Sign Up'
|
76
|
+
end
|
77
|
+
|
78
|
+
Then 'I should see a confirmation message' do
|
79
|
+
expect_flash_notice 'You have signed up successfully'
|
80
|
+
end
|
81
|
+
|
82
|
+
Then 'I should be signed in with 2 sessions' do
|
83
|
+
expect_to_see 'dummy-accounts-2'
|
84
|
+
end
|
85
|
+
|
86
|
+
end # scenario
|
87
|
+
|
88
|
+
scenario 'Invalid Registration' do
|
89
|
+
When 'I sign up with invalid data' do
|
90
|
+
click_button 'Sign Up'
|
91
|
+
end
|
92
|
+
|
93
|
+
Then "I should see a validation errors" do
|
94
|
+
expect_error_message "errors were found while trying to sign up"
|
95
|
+
end
|
96
|
+
|
97
|
+
Then 'I should be signed in with 1 session' do
|
98
|
+
expect_to_see 'dummy-accounts-1'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end # uic
|
103
|
+
|
104
|
+
end # context
|
105
|
+
|
106
|
+
api 'API', type: :request do
|
107
|
+
|
108
|
+
skip 'TODO: write API features here too'
|
109
|
+
|
110
|
+
end # api
|
111
|
+
|
112
|
+
end # context
|
113
|
+
|
114
|
+
context 'I can Switch Sessions' do
|
115
|
+
|
116
|
+
context 'Components', type: :feature do
|
117
|
+
|
118
|
+
uic 'Switch Button' do
|
119
|
+
|
120
|
+
story 'Has One Account' do
|
121
|
+
|
122
|
+
Given 'I am signed in with a single account' do
|
123
|
+
# intentionally left blank
|
124
|
+
end
|
125
|
+
|
126
|
+
scenario 'Success' do
|
127
|
+
|
128
|
+
When 'I visit Switch Accounts' do
|
129
|
+
click_link 'Switch Accounts'
|
130
|
+
end
|
131
|
+
|
132
|
+
Then 'I should not see a button to switch accounts' do
|
133
|
+
expect(page).not_to have_link('Switch!')
|
134
|
+
end
|
135
|
+
|
136
|
+
Then 'I should be signed in with 1 session' do
|
137
|
+
expect_to_see 'dummy-accounts-1'
|
138
|
+
end
|
139
|
+
|
140
|
+
Then 'and I should be signed in' do
|
141
|
+
then_I_expect_to_be_signed_in
|
142
|
+
end
|
143
|
+
|
144
|
+
end # scenario
|
145
|
+
|
146
|
+
end # story
|
147
|
+
|
148
|
+
story 'Has Two Accounts' do
|
149
|
+
|
150
|
+
Given 'I sign in as a second user' do
|
151
|
+
u = create(:user_user, username: 'foobar')
|
152
|
+
sign_in_with(u.username)
|
153
|
+
expect_to_see 'dummy-accounts-2'
|
154
|
+
end
|
155
|
+
|
156
|
+
Given 'I visit "Switch Accounts"' do
|
157
|
+
click_link 'Switch Accounts'
|
158
|
+
# ensuring url_for context and to_param
|
159
|
+
expect(page.html).to include(%{<a href="/users/foobar">foobar</a>})
|
160
|
+
end
|
161
|
+
|
162
|
+
scenario 'Success' do
|
163
|
+
|
164
|
+
When 'I attempt to switch to another account' do
|
165
|
+
click_link 'Switch!'
|
166
|
+
end
|
167
|
+
|
168
|
+
Then 'I should see a confirmation message' do
|
169
|
+
expect_flash_notice 'You have signed in successfully'
|
170
|
+
end
|
171
|
+
|
172
|
+
Then 'I should be signed in as my first account now' do
|
173
|
+
then_I_expect_to_be_signed_in_with_role('user')
|
174
|
+
end
|
175
|
+
|
176
|
+
end # scenario
|
177
|
+
|
178
|
+
scenario 'Not Found' do
|
179
|
+
|
180
|
+
But 'My first session was dropped from the database' do
|
181
|
+
Access.first.destroy!
|
182
|
+
end
|
183
|
+
|
184
|
+
When 'I attempt to switch to my first session' do
|
185
|
+
click_link 'Switch!'
|
186
|
+
end
|
187
|
+
|
188
|
+
Then 'I should see an expiration message' do
|
189
|
+
expect_flash_notice 'You have signed out!'
|
190
|
+
end
|
191
|
+
|
192
|
+
Then 'I should be signed in as my first account now' do
|
193
|
+
then_I_expect_to_be_signed_in_with_role('user')
|
194
|
+
end
|
195
|
+
|
196
|
+
end # scenario
|
197
|
+
|
198
|
+
end # story
|
199
|
+
|
200
|
+
end # uic
|
201
|
+
|
202
|
+
end # context
|
203
|
+
|
204
|
+
api 'API', type: :request do
|
205
|
+
|
206
|
+
skip 'TODO: write API features here too'
|
207
|
+
|
208
|
+
end # api
|
209
|
+
|
210
|
+
end # context
|
211
|
+
|
212
|
+
context 'I can Forget Sessions' do
|
213
|
+
|
214
|
+
context 'Components', type: :feature do
|
215
|
+
|
216
|
+
uic 'Forget Button' do
|
217
|
+
|
218
|
+
story "Has One Account" do
|
219
|
+
|
220
|
+
Given 'I am signed in with a single account' do
|
221
|
+
# intentionally left blank
|
222
|
+
end
|
223
|
+
|
224
|
+
scenario 'Success' do
|
225
|
+
|
226
|
+
When "I attempt to forget my first session" do
|
227
|
+
click_link "Switch Accounts"
|
228
|
+
click_button "Forget"
|
229
|
+
end
|
230
|
+
|
231
|
+
Then "I should see a confirmation message" do
|
232
|
+
expect_flash_notice 'You have signed out!'
|
233
|
+
end
|
234
|
+
|
235
|
+
Then 'I should be signed in with 0 sessions' do
|
236
|
+
expect_to_see 'dummy-accounts-0'
|
237
|
+
end
|
238
|
+
|
239
|
+
Then 'and I should be signed out' do
|
240
|
+
then_I_expect_to_be_signed_out
|
241
|
+
end
|
242
|
+
|
243
|
+
end # scenario
|
244
|
+
|
245
|
+
end # story
|
246
|
+
|
247
|
+
story "Has Two Accounts" do
|
248
|
+
|
249
|
+
Given 'I sign in as a second user' do
|
250
|
+
u = create(:user_user, username: 'foobar')
|
251
|
+
sign_in_with(u.username)
|
252
|
+
expect_to_see "dummy-accounts-2"
|
253
|
+
end
|
254
|
+
|
255
|
+
scenario 'Success' do
|
256
|
+
|
257
|
+
When "I attempt to forget my first session" do
|
258
|
+
click_link "Switch Accounts"
|
259
|
+
click_nth_button("Forget", 1)
|
260
|
+
end
|
261
|
+
|
262
|
+
Then "I should see a confirmation message" do
|
263
|
+
expect_flash_notice 'You have signed out!'
|
264
|
+
end
|
265
|
+
|
266
|
+
Then 'I should be signed in with 1 session' do
|
267
|
+
expect_to_see 'dummy-accounts-1'
|
268
|
+
end
|
269
|
+
|
270
|
+
Then 'and I should be signed in' do
|
271
|
+
then_I_expect_to_be_signed_in
|
272
|
+
end
|
273
|
+
|
274
|
+
end # scenario
|
275
|
+
|
276
|
+
end # story
|
277
|
+
|
278
|
+
end # uic
|
279
|
+
|
280
|
+
end # context
|
281
|
+
|
282
|
+
api 'API', type: :request do
|
283
|
+
|
284
|
+
skip 'TODO: write API features here too'
|
285
|
+
|
286
|
+
end # api
|
287
|
+
|
288
|
+
end # context
|
289
|
+
|
290
|
+
end # role
|
291
|
+
|
292
|
+
end # capability
|