hello-rails 0.0.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Access do
|
4
|
+
it 'validations' do
|
5
|
+
subject.valid?
|
6
|
+
|
7
|
+
expect(subject.errors.messages).to eq(user: ["can't be blank"],
|
8
|
+
user_agent_string: ["can't be blank"])
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'methods' do
|
12
|
+
it '#full_device_name' do
|
13
|
+
# Mock
|
14
|
+
expect(Hello::Utils::DeviceName.instance).to receive(:parse)
|
15
|
+
# When
|
16
|
+
subject.full_device_name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EmailCredential do
|
4
|
+
example 'Validations' do
|
5
|
+
subject.valid?
|
6
|
+
expect(subject.errors.messages).to eq(user: ["can't be blank"],
|
7
|
+
email: ["can't be blank"])
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'Fields' do
|
11
|
+
describe '#email' do
|
12
|
+
context 'Validations' do
|
13
|
+
after do
|
14
|
+
reload_initializer!
|
15
|
+
end
|
16
|
+
|
17
|
+
example 'Presence' do
|
18
|
+
subject.valid?
|
19
|
+
expect(subject.errors[:email]).to include "can't be blank"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'Format' do
|
23
|
+
describe 'config.email_regex = DEFAULT' do
|
24
|
+
it 'invalid' do
|
25
|
+
subject.email = 'aaaa'
|
26
|
+
subject.valid?
|
27
|
+
expect(subject.errors[:email]).to eq ['is invalid']
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'valid' do
|
31
|
+
subject.email = 'email@hello.com'
|
32
|
+
subject.valid?
|
33
|
+
expect(subject.errors[:email]).to be_empty
|
34
|
+
end
|
35
|
+
end # describe config
|
36
|
+
|
37
|
+
describe 'config.email_regex = LETTERS' do
|
38
|
+
before do
|
39
|
+
Hello.configure { |config| config.email_regex = /\A[a-z]+\z/i }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'valid' do
|
43
|
+
subject.email = 'aaaa'
|
44
|
+
subject.valid?
|
45
|
+
expect(subject.errors[:email]).to be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'invalid' do
|
49
|
+
subject.email = 'aaaa1234'
|
50
|
+
subject.valid?
|
51
|
+
expect(subject.errors[:email]).to eq ['is invalid']
|
52
|
+
end
|
53
|
+
end # describe config
|
54
|
+
|
55
|
+
describe 'config.email_regex = LETTERS_AND_NUMBERS' do
|
56
|
+
before do
|
57
|
+
Hello.configure { |config| config.email_regex = /\A[a-z0-9]+\z/i }
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'valid 1' do
|
61
|
+
subject.email = 'aaaa'
|
62
|
+
subject.valid?
|
63
|
+
expect(subject.errors[:email]).to eq([])
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'valid 2' do
|
67
|
+
subject.email = 'aaaa1234'
|
68
|
+
subject.valid?
|
69
|
+
expect(subject.errors[:email]).to eq([])
|
70
|
+
end
|
71
|
+
end # describe config
|
72
|
+
end # describe Format
|
73
|
+
|
74
|
+
describe 'Length' do
|
75
|
+
describe 'config.email_length = DEFAULT (4..250)' do
|
76
|
+
it '3 is invalid' do
|
77
|
+
subject.email = '123'
|
78
|
+
subject.valid?
|
79
|
+
expect(subject.errors[:email]).to include 'is too short (minimum is 4 characters)'
|
80
|
+
end
|
81
|
+
|
82
|
+
it '4 is valid' do
|
83
|
+
subject.email = '1234'
|
84
|
+
subject.valid?
|
85
|
+
expect(subject.errors[:email]).to eq(['is invalid']) # but is valid in this context
|
86
|
+
end
|
87
|
+
|
88
|
+
it '250 is valid' do
|
89
|
+
subject.email = '1' * 250
|
90
|
+
subject.valid?
|
91
|
+
expect(subject.errors[:email]).to eq(['is invalid']) # but is valid in this context
|
92
|
+
end
|
93
|
+
|
94
|
+
it '251 is invalid' do
|
95
|
+
subject.email = '1' * 251
|
96
|
+
subject.valid?
|
97
|
+
expect(subject.errors[:email]).to include 'is too long (maximum is 250 characters)'
|
98
|
+
end
|
99
|
+
end # describe config
|
100
|
+
|
101
|
+
describe 'config.email_length = 2..10' do
|
102
|
+
before do
|
103
|
+
Hello.configure { |config| config.email_length = 2..10 }
|
104
|
+
end
|
105
|
+
|
106
|
+
it '1 is invalid' do
|
107
|
+
subject.email = '1'
|
108
|
+
subject.valid?
|
109
|
+
expect(subject.errors[:email]).to include 'is too short (minimum is 2 characters)'
|
110
|
+
end
|
111
|
+
|
112
|
+
it '2 is valid' do
|
113
|
+
subject.email = '22'
|
114
|
+
subject.valid?
|
115
|
+
expect(subject.errors[:email]).to eq(['is invalid']) # but is valid in this context
|
116
|
+
end
|
117
|
+
|
118
|
+
it '10 is valid' do
|
119
|
+
subject.email = '1234567890'
|
120
|
+
subject.valid?
|
121
|
+
expect(subject.errors[:email]).to eq(['is invalid']) # but is valid in this context
|
122
|
+
end
|
123
|
+
|
124
|
+
it '11 is invalid' do
|
125
|
+
subject.email = '12345678901'
|
126
|
+
subject.valid?
|
127
|
+
expect(subject.errors[:email]).to include 'is too long (maximum is 10 characters)'
|
128
|
+
end
|
129
|
+
end # describe config
|
130
|
+
end # describe Length
|
131
|
+
|
132
|
+
describe 'Uniqueness' do
|
133
|
+
def test_uniqueness(a, b)
|
134
|
+
create(:email_credential, email: a)
|
135
|
+
subject.email = b
|
136
|
+
subject.valid?
|
137
|
+
expect(subject.errors.added?(:email, :taken)).to eq(true)
|
138
|
+
end
|
139
|
+
|
140
|
+
example 'With normal case' do
|
141
|
+
test_uniqueness('james@hello.com', 'james@hello.com')
|
142
|
+
end
|
143
|
+
|
144
|
+
example 'Downcased' do
|
145
|
+
test_uniqueness('JaMeS@HELLO.com', 'james@hello.com')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#email=' do
|
151
|
+
example 'nil' do
|
152
|
+
subject.email = nil
|
153
|
+
expect(subject.email).to eq('')
|
154
|
+
end
|
155
|
+
|
156
|
+
example 'spaced' do
|
157
|
+
subject.email = ' jame s @hello.com '
|
158
|
+
expect(subject.email).to eq('james@hello.com')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# require 'spec_helper'
|
2
|
+
|
3
|
+
# module Hello
|
4
|
+
# describe SignUp do
|
5
|
+
|
6
|
+
# before(:each) do
|
7
|
+
# # @sign_up = SignUp.new
|
8
|
+
# end
|
9
|
+
|
10
|
+
# describe "validations" do
|
11
|
+
# # describe "email" do
|
12
|
+
|
13
|
+
# # it "presence" do
|
14
|
+
# # @sign_up.valid?
|
15
|
+
# # @sign_up.errors[:email].should include "can't be blank"
|
16
|
+
# # end
|
17
|
+
|
18
|
+
# # it "format" do
|
19
|
+
# # @sign_up.email = 'aaa'
|
20
|
+
# # @sign_up.valid?
|
21
|
+
# # @sign_up.errors[:email].should == ["does not appear to be valid"]
|
22
|
+
|
23
|
+
# # @sign_up.email = 'email@hello.com'
|
24
|
+
# # @sign_up.valid?
|
25
|
+
# # @sign_up.errors[:email].should be_empty
|
26
|
+
# # end
|
27
|
+
|
28
|
+
# # it "uniqueness" do
|
29
|
+
# # pending "todo"
|
30
|
+
# # end
|
31
|
+
|
32
|
+
# # end
|
33
|
+
|
34
|
+
# # describe "password" do
|
35
|
+
|
36
|
+
# # it "presence" do
|
37
|
+
# # @sign_up.valid?
|
38
|
+
# # @sign_up.errors[:password].should include "can't be blank"
|
39
|
+
# # end
|
40
|
+
|
41
|
+
# # it "length" do
|
42
|
+
# # @sign_up.password = '1' * 1
|
43
|
+
# # @sign_up.valid?
|
44
|
+
# # @sign_up.errors[:password].should == ["pick a shorter password"]
|
45
|
+
|
46
|
+
# # @sign_up.password = '1' * 4
|
47
|
+
# # @sign_up.valid?
|
48
|
+
# # @sign_up.errors[:password].should be_empty
|
49
|
+
|
50
|
+
# # @sign_up.password = '1' * 201
|
51
|
+
# # @sign_up.valid?
|
52
|
+
# # @sign_up.errors[:password].should == ["pick a longer password"]
|
53
|
+
# # end
|
54
|
+
|
55
|
+
# # end
|
56
|
+
# end
|
57
|
+
|
58
|
+
# it "saves" do
|
59
|
+
# pending "creates user"
|
60
|
+
|
61
|
+
# end
|
62
|
+
|
63
|
+
# end
|
64
|
+
# end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PasswordCredential do
|
4
|
+
describe 'validations' do
|
5
|
+
it 'presence of name' do
|
6
|
+
subject.valid?
|
7
|
+
expect(subject.errors.messages).to eq(user: ["can't be blank"],
|
8
|
+
password: ["can't be blank"])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'password' do
|
13
|
+
describe 'validations' do
|
14
|
+
it 'presence' do
|
15
|
+
subject.valid?
|
16
|
+
expect(subject.errors[:password]).to eq ["can't be blank"]
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'length' do
|
20
|
+
subject.password = '1' * 1
|
21
|
+
subject.valid?
|
22
|
+
expect(subject.errors[:password]).to eq ['is too short (minimum is 4 characters)']
|
23
|
+
|
24
|
+
subject.password = '1' * 4
|
25
|
+
subject.valid?
|
26
|
+
expect(subject.errors[:password]).to be_empty
|
27
|
+
|
28
|
+
subject.password = '1' * 251
|
29
|
+
subject.valid?
|
30
|
+
expect(subject.errors[:password]).to eq ['is too long (maximum is 250 characters)']
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'spaced' do
|
34
|
+
subject.password = ' 123 4 '
|
35
|
+
expect(subject.password_is?('1234')).to eq(false)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'cased' do
|
39
|
+
subject.password = 'Abcd'
|
40
|
+
expect(subject.password_is?('Abcd')).to eq(true)
|
41
|
+
expect(subject.password_is?('abcd')).to eq(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'format' do
|
45
|
+
describe 'acceptable' do
|
46
|
+
it('can have only letters') { @string = 'abcdef' }
|
47
|
+
|
48
|
+
it('can have only numbers') { @string = '123456' }
|
49
|
+
|
50
|
+
it('can start with letter') { @string = 'a12345' }
|
51
|
+
|
52
|
+
it('can start with number') { @string = '1abcde' }
|
53
|
+
|
54
|
+
after do
|
55
|
+
subject.password = @string
|
56
|
+
subject.valid?
|
57
|
+
expect(subject.errors[:password]).to eq([])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'not acceptable' do
|
62
|
+
it('cannot have spaces') { @string = 'abc 123' }
|
63
|
+
|
64
|
+
it('cannot have symbols') { @string = 'abc!123' }
|
65
|
+
|
66
|
+
after do
|
67
|
+
subject.password = @string
|
68
|
+
subject.valid?
|
69
|
+
expect(subject.errors[:password]).to eq(['is invalid'])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
before(:each) do
|
5
|
+
@user = User.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'setter' do
|
9
|
+
it 'nil' do
|
10
|
+
expect { User.new.username = nil }.not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'spaced' do
|
14
|
+
user = User.new
|
15
|
+
user.username = ' jame s '
|
16
|
+
expect(user.username).to eq('james')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'validations' do
|
21
|
+
it 'validations' do
|
22
|
+
@user.valid?
|
23
|
+
# city is only here because we need to test code customization, and this is how we are currently testing it
|
24
|
+
expect(@user.errors.messages).to eq(
|
25
|
+
name: ["can't be blank"],
|
26
|
+
locale: ["can't be blank", 'is not included in the list'],
|
27
|
+
time_zone: ["can't be blank", 'is not included in the list'],
|
28
|
+
city: ["can't be blank"],
|
29
|
+
username: ["can't be blank", 'is invalid', 'is too short (minimum is 4 characters)']
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'passwords' do
|
35
|
+
example 'one is automatically created with factories' do
|
36
|
+
expect do
|
37
|
+
create(:user)
|
38
|
+
end.to change { PasswordCredential.count }.from(0).to(1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'username' do
|
43
|
+
describe 'validations' do
|
44
|
+
describe 'uniqueness' do
|
45
|
+
def test_uniqueness(a, b)
|
46
|
+
create(:user, username: a)
|
47
|
+
user = build(:user, username: b)
|
48
|
+
user.valid?
|
49
|
+
# expect(user.errors.messages).to eq(1)
|
50
|
+
expect(user.errors.added?(:username, :taken)).to eq(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'normal case' do
|
54
|
+
test_uniqueness('james', 'james')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'downcase' do
|
58
|
+
test_uniqueness('JaMeS', 'james')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'format' do
|
63
|
+
user = build(:user)
|
64
|
+
|
65
|
+
invalid_usernames = ['*****', 'James!', 'James@', '@James', 'James?', 'james#', 'james$', 'james%', 'james&', 'james*', 'james(']
|
66
|
+
invalid_usernames.each do |username|
|
67
|
+
user.username = username
|
68
|
+
user.valid?
|
69
|
+
err = user.errors[:username]
|
70
|
+
expect(err).to eq(['is invalid']), "'#{err}' when username is '#{username}'"
|
71
|
+
end
|
72
|
+
|
73
|
+
valid_usernames = ['james', 'James', 'JAMES', 'James88', '88James', '88-james', 'james_88']
|
74
|
+
valid_usernames.each do |username|
|
75
|
+
user.username = username
|
76
|
+
user.valid?
|
77
|
+
err = user.errors[:username]
|
78
|
+
expect(err).to eq([]), "'#{err}' when username is '#{username}'"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'private ._make_up_new_username' do
|
84
|
+
let(:model) { build(:user, username: '') }
|
85
|
+
|
86
|
+
it 'works when called' do
|
87
|
+
a_username = model.send(:_make_up_new_username)
|
88
|
+
expect(a_username.length).to eq(32)
|
89
|
+
expect(model.username).to eq('')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe 'Configuration' do
|
5
|
+
let(:hello_config) { Hello.configuration }
|
6
|
+
let(:rails_config) { Rails.configuration.hello }
|
7
|
+
|
8
|
+
describe 'Works With Rails' do
|
9
|
+
it 'is the same instance' do
|
10
|
+
expect(hello_config).to eq(rails_config)
|
11
|
+
expect(hello_config.object_id).to eq(rails_config.object_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Sets in Hello, Gets in Rails' do
|
15
|
+
hello_config.mailer_sender = 'foo'
|
16
|
+
expect(rails_config.mailer_sender).to eq('foo')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'Sets in Rails, Gets in Hello' do
|
20
|
+
rails_config.mailer_sender = 'bar'
|
21
|
+
expect(hello_config.mailer_sender).to eq('bar')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|