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,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hello::Encryptors::Complex do
|
4
|
+
subject { described_class.instance }
|
5
|
+
|
6
|
+
describe '#encrypt' do
|
7
|
+
def use_bcrypt
|
8
|
+
start_with('$2a$')
|
9
|
+
end
|
10
|
+
|
11
|
+
it('works with nil') { expect(subject.encrypt(nil)).to use_bcrypt }
|
12
|
+
it('works with ""') { expect(subject.encrypt('')).to use_bcrypt }
|
13
|
+
it('works with "abc"') { expect(subject.encrypt('abc')).to use_bcrypt }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#match' do
|
17
|
+
def enc(s)
|
18
|
+
subject.encrypt(s)
|
19
|
+
end
|
20
|
+
|
21
|
+
it('works with nil') { digest = enc(nil); expect(subject.match(nil, digest)) }
|
22
|
+
it('works with ""') { digest = enc(''); expect(subject.match('', digest)) }
|
23
|
+
it('works with "abc"') { digest = enc('abc'); expect(subject.match('abc', digest)) }
|
24
|
+
end
|
25
|
+
|
26
|
+
end # describe
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hello::Encryptors::Simple do
|
4
|
+
subject { described_class.instance }
|
5
|
+
|
6
|
+
describe '#encrypt' do
|
7
|
+
it('does not work with nil') { expect { subject.encrypt(nil).length }.to raise_error(TypeError) }
|
8
|
+
it('works with ""') { expect(subject.encrypt('').length ).to eq(32) }
|
9
|
+
it('works with "abc"') { expect(subject.encrypt('abc').length).to eq(32) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#match' do
|
13
|
+
def enc(s)
|
14
|
+
subject.encrypt(s)
|
15
|
+
end
|
16
|
+
|
17
|
+
it('works with ""') { digest = enc(''); expect(subject.match('', digest)) }
|
18
|
+
it('works with "abc"') { digest = enc('abc'); expect(subject.match('abc', digest)) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end # describe
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Helper' do
|
4
|
+
it 'hello_locale_select_options' do
|
5
|
+
obj = Object.new
|
6
|
+
obj.extend Hello::RailsHelper
|
7
|
+
expect(obj.hello_locale_select_options).to be_an Array
|
8
|
+
expect(obj.hello_locale_select_options).to include %w(English en)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe I18n do
|
5
|
+
def flat_hash(h, f = [], g = {})
|
6
|
+
return g.update(f => h) unless h.is_a? Hash
|
7
|
+
h.each { |k, r| flat_hash(r, f + [k], g) }
|
8
|
+
g
|
9
|
+
end
|
10
|
+
|
11
|
+
def flat_i18n_hello(locale)
|
12
|
+
flat_hash I18n.t('hello', locale: locale)
|
13
|
+
end
|
14
|
+
|
15
|
+
def h_en
|
16
|
+
@h_en ||= flat_i18n_hello(:en)
|
17
|
+
end
|
18
|
+
|
19
|
+
def extract_string_replacement(text)
|
20
|
+
regex = /%{(\w*)}/
|
21
|
+
text.scan(regex)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'extract_string_replacement' do
|
25
|
+
test_text = 'aaaaa %{bbb} c %{ddd} eeeee'
|
26
|
+
scandata = extract_string_replacement(test_text)
|
27
|
+
expect(scandata).to eq([['bbb'], ['ddd']])
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'Consistent with ENGLISH' do
|
31
|
+
|
32
|
+
def consistency_wrap(locale, &_block)
|
33
|
+
h_lo = flat_i18n_hello(locale)
|
34
|
+
|
35
|
+
array_en = Array(h_en)
|
36
|
+
array_lo = Array(h_lo)
|
37
|
+
|
38
|
+
array_en.size.times do |i|
|
39
|
+
@en_key = array_en[i][0]
|
40
|
+
en_val = array_en[i][1]
|
41
|
+
|
42
|
+
@lo_key = array_lo[i][0]
|
43
|
+
lo_val = array_lo[i][1]
|
44
|
+
|
45
|
+
@en_vars = extract_string_replacement(en_val)
|
46
|
+
@lo_vars = extract_string_replacement(lo_val)
|
47
|
+
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
available_locales = Dir[Hello.root.join('config', 'locales', '**', '*.yml')].map { |s| s.split('.')[-2] }
|
53
|
+
|
54
|
+
available_locales.each do |locale|
|
55
|
+
describe "#{locale} consistency" do
|
56
|
+
it 'Keys are consistent' do
|
57
|
+
consistency_wrap(locale) do
|
58
|
+
error_message = "I18n '#{locale}' does not match 'en'.\nExpected key '#{@lo_key}' but found key '#{@en_key}'"
|
59
|
+
expect(@lo_key).to eq(@en_key), error_message
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'Variables are consistent' do
|
64
|
+
consistency_wrap(locale) do
|
65
|
+
error_message = "I18n '#{locale}' does not match 'en'.\nExpected key '#{@lo_key}' with values '#{@en_vars}', but found '#{@lo_vars}' instead."
|
66
|
+
expect(@lo_vars).to eq(@en_vars), error_message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Forgot Password', type: :request do
|
4
|
+
describe 'POST /password/forgot.json' do
|
5
|
+
describe 'Error' do
|
6
|
+
it 'missing' do
|
7
|
+
post '/hello/passwords/forgot.json'
|
8
|
+
|
9
|
+
expect(response.status).to eq(400)
|
10
|
+
expect(response.status_message).to eq('Bad Request')
|
11
|
+
expect(json_response['exception']).to eq('class' => 'ActionController::ParameterMissing',
|
12
|
+
'message' => 'param is missing or the value is empty: forgot_password')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'blank' do
|
16
|
+
forgot_password_params = { login: '' }
|
17
|
+
post '/hello/passwords/forgot.json', forgot_password: forgot_password_params
|
18
|
+
|
19
|
+
expect(response.status).to eq(422)
|
20
|
+
expect(response.status_message).to eq('Unprocessable Entity')
|
21
|
+
expect(json_response).to eq('login' => ['was not found'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Success' do
|
26
|
+
given_I_have_an_email_credential
|
27
|
+
|
28
|
+
forgot_password_params = { login: 'foobar', password: '1234' }
|
29
|
+
post '/hello/passwords/forgot.json', forgot_password: forgot_password_params
|
30
|
+
|
31
|
+
expect(response.status).to eq(201)
|
32
|
+
expect(response.status_message).to eq('Created')
|
33
|
+
expect(json_response.keys).to match_array %w(sent)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Security', type: :request do
|
4
|
+
context 'PATCH /profile.json' do
|
5
|
+
before(:each) do
|
6
|
+
@auth_headers = { 'HTTP_ACCESS_TOKEN' => given_I_have_a_classic_access_token.token }
|
7
|
+
mock_stateless!
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'Role' do
|
11
|
+
user_params = { user: { role: 'webmaster' } }
|
12
|
+
expect do
|
13
|
+
patch '/hello/profile.json', user_params, @auth_headers
|
14
|
+
|
15
|
+
expect(response.status).to eq(200)
|
16
|
+
end.not_to change { User.last.role }.from('user')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe Management::AccessesController do
|
5
|
+
describe 'routing' do
|
6
|
+
routes { Hello::Engine.routes }
|
7
|
+
|
8
|
+
it 'routes to #index' do
|
9
|
+
expect(get: '/accesses').to route_to('hello/management/accesses#index')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'routes to #destroy' do
|
13
|
+
expect(delete: '/accesses/1').to route_to('hello/management/accesses#destroy', id: '1')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe Management::EmailsController do
|
5
|
+
describe 'routing' do
|
6
|
+
routes { Hello::Engine.routes }
|
7
|
+
|
8
|
+
it 'routes to #index' do
|
9
|
+
expect(get: '/emails').to route_to('hello/management/emails#index')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'routes to #create' do
|
13
|
+
expect(post: '/emails').to route_to('hello/management/emails#create')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'routes to #destroy' do
|
17
|
+
expect(delete: '/emails/1').to route_to('hello/management/emails#destroy', id: '1')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'routes to #deliver' do
|
21
|
+
expect(post('/emails/1/deliver')).to route_to('hello/management/emails#deliver', id: '1')
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# CONFIRM EMAIL
|
26
|
+
#
|
27
|
+
|
28
|
+
it 'routes to #confirm' do
|
29
|
+
expect(get('/emails/1/confirm/123')).to route_to('hello/management/confirm_emails#confirm', id: '1', token: '123')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'routes to #expired_token' do
|
33
|
+
expect(get: '/emails/expired_confirmation_token').to route_to('hello/management/confirm_emails#expired_confirmation_token')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe Internationalization::LocaleController do
|
5
|
+
describe 'routing' do
|
6
|
+
routes { Hello::Engine.routes }
|
7
|
+
|
8
|
+
it 'routes to #index' do
|
9
|
+
expect(get('/locale')).to route_to('hello/internationalization/locale#index')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'routes to #update' do
|
13
|
+
expect(post('/locale')).to route_to('hello/internationalization/locale#update')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe Management::ProfilesController do
|
5
|
+
describe 'routing' do
|
6
|
+
routes { Hello::Engine.routes }
|
7
|
+
|
8
|
+
it 'routes to #show too' do
|
9
|
+
expect(get('/')).to route_to('hello/management/profiles#show')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'routes to #show' do
|
13
|
+
expect(get('/profile')).to route_to('hello/management/profiles#show')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'routes to #update' do
|
17
|
+
expect(patch('/profile')).to route_to('hello/management/profiles#update')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'routes to #cancel' do
|
21
|
+
expect(get('/profile/cancel')).to route_to('hello/management/profiles#cancel')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'routes to #destroy' do
|
25
|
+
expect(delete('/profile')).to route_to('hello/management/profiles#destroy')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe 'routing' do
|
5
|
+
routes { Hello::Engine.routes }
|
6
|
+
|
7
|
+
it 'routes to #index' do
|
8
|
+
expect(get('/sign_up')).to route_to('hello/registration/sign_up#index')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'routes to #create' do
|
12
|
+
expect(post('/sign_up')).to route_to('hello/registration/sign_up#create')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'routes to #index' do
|
16
|
+
expect(get('/sign_in')).to route_to('hello/authentication/sign_in#index')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'routes to #authenticate' do
|
20
|
+
expect(post('/sign_in')).to route_to('hello/authentication/sign_in#authenticate')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
module Authentication
|
5
|
+
describe SudoModeController do
|
6
|
+
describe 'routing' do
|
7
|
+
routes { Hello::Engine.routes }
|
8
|
+
|
9
|
+
it 'routes to #form' do
|
10
|
+
expect(get: '/sudo_mode').to route_to('hello/authentication/sudo_mode#form')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'routes to #authenticate' do
|
14
|
+
expect(patch: '/sudo_mode').to route_to('hello/authentication/sudo_mode#authenticate')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'routes to #expire' do
|
18
|
+
expect(get: '/sudo_mode/expire').to route_to('hello/authentication/sudo_mode#expire')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
describe UsersController, type: :routing do
|
5
|
+
describe 'routing' do
|
6
|
+
it 'routes to #index' do
|
7
|
+
expect(get: '/users').to route_to('users#index')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'routes to #show' do
|
11
|
+
expect(get: '/users/1').to route_to('users#show', id: '1')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
SPEC_ROOT = Pathname(File.dirname(__FILE__))
|
3
|
+
DUMMY_ROOT = SPEC_ROOT.join('../dummy')
|
4
|
+
|
5
|
+
require 'spec_helper/codeclimate' # this should be atop all
|
6
|
+
require 'spec_helper/dummy_and_test_dependencies'
|
7
|
+
require 'spec_helper/support'
|
8
|
+
require 'spec_helper/create_database'
|
9
|
+
require 'spec_helper/configure_rspec'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.color = true
|
3
|
+
config.default_formatter = Bdd::RSpec::Formatter
|
4
|
+
|
5
|
+
config.mock_with :rspec
|
6
|
+
config.use_transactional_fixtures = true
|
7
|
+
config.infer_base_class_for_anonymous_controllers = false
|
8
|
+
# config.order = "random"
|
9
|
+
|
10
|
+
config.infer_spec_type_from_file_location!
|
11
|
+
|
12
|
+
config.include Hello::FeatureSupportGiven, type: :feature
|
13
|
+
config.include Hello::RequestSupport, type: :request
|
14
|
+
|
15
|
+
config.include FactoryGirl::Syntax::Methods
|
16
|
+
|
17
|
+
config.include(EmailSpec::Helpers)
|
18
|
+
config.include(EmailSpec::Matchers)
|
19
|
+
|
20
|
+
config.before(:each) { I18n.locale = :en }
|
21
|
+
|
22
|
+
config.before(:each, type: :request) { host! 'api.example.com' }
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require DUMMY_ROOT.join('config/environment.rb')
|
2
|
+
|
3
|
+
require 'factory_girl_rails'
|
4
|
+
require 'faker'
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'capybara/rails'
|
7
|
+
require 'email_spec'
|
8
|
+
require 'bdd/rspec'
|
9
|
+
|
10
|
+
# silencers
|
11
|
+
Rails.backtrace_cleaner.remove_silencers!
|
12
|
+
|
13
|
+
# deprecation
|
14
|
+
ActiveSupport::Deprecation.silenced = true
|
15
|
+
|
16
|
+
# quiet migrations
|
17
|
+
ActiveRecord::Schema.verbose = false
|