incline 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +186 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +208 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/incline/.keep +0 -0
- data/app/assets/images/incline/.keep +0 -0
- data/app/assets/images/incline/barcode-B.svg +181 -0
- data/app/assets/javascripts/incline/activate_classed_items.js +11 -0
- data/app/assets/javascripts/incline/application.js +30 -0
- data/app/assets/javascripts/incline/bootstrap-datepicker.js +1800 -0
- data/app/assets/javascripts/incline/datatables.js +22193 -0
- data/app/assets/javascripts/incline/escapeHtml.js +10 -0
- data/app/assets/javascripts/incline/inline_actions.js +479 -0
- data/app/assets/javascripts/incline/jquery.doubleScroll.js +112 -0
- data/app/assets/javascripts/incline/jquery.number.js +764 -0
- data/app/assets/javascripts/incline/regexMask.js +27 -0
- data/app/assets/javascripts/incline/select2/i18n/en.js +3 -0
- data/app/assets/javascripts/incline/select2/select2.full.js +6436 -0
- data/app/assets/stylesheets/incline/application.css +18 -0
- data/app/assets/stylesheets/incline/bootstrap-theme.min.css +5 -0
- data/app/assets/stylesheets/incline/custom.scss +279 -0
- data/app/assets/stylesheets/incline/datatables.css +494 -0
- data/app/assets/stylesheets/incline/datepicker3.css +790 -0
- data/app/assets/stylesheets/incline/select2.css +484 -0
- data/app/controllers/incline/access_groups_controller.rb +127 -0
- data/app/controllers/incline/access_test_controller.rb +30 -0
- data/app/controllers/incline/account_activations_controller.rb +28 -0
- data/app/controllers/incline/application_controller.rb +11 -0
- data/app/controllers/incline/contact_controller.rb +34 -0
- data/app/controllers/incline/password_resets_controller.rb +113 -0
- data/app/controllers/incline/security_controller.rb +100 -0
- data/app/controllers/incline/sessions_controller.rb +50 -0
- data/app/controllers/incline/users_controller.rb +304 -0
- data/app/controllers/incline/welcome_controller.rb +19 -0
- data/app/helpers/incline/.keep +0 -0
- data/app/mailers/incline/application_mailer_base.rb +11 -0
- data/app/mailers/incline/contact_form.rb +19 -0
- data/app/mailers/incline/user_mailer.rb +45 -0
- data/app/models/incline/access_group.rb +121 -0
- data/app/models/incline/access_group_group_member.rb +12 -0
- data/app/models/incline/access_group_user_member.rb +10 -0
- data/app/models/incline/action_group.rb +12 -0
- data/app/models/incline/action_security.rb +222 -0
- data/app/models/incline/contact_message.rb +37 -0
- data/app/models/incline/disable_info.rb +20 -0
- data/app/models/incline/password_reset.rb +14 -0
- data/app/models/incline/password_reset_request.rb +14 -0
- data/app/models/incline/user.rb +437 -0
- data/app/models/incline/user_login_history.rb +30 -0
- data/app/views/incline/access_groups/_details.json.jbuilder +10 -0
- data/app/views/incline/access_groups/_form.html.erb +19 -0
- data/app/views/incline/access_groups/_list.html.erb +60 -0
- data/app/views/incline/access_groups/_messages.json.jbuilder +6 -0
- data/app/views/incline/access_groups/edit.html.erb +2 -0
- data/app/views/incline/access_groups/index.html.erb +6 -0
- data/app/views/incline/access_groups/index.json.jbuilder +16 -0
- data/app/views/incline/access_groups/new.html.erb +2 -0
- data/app/views/incline/access_groups/show.html.erb +9 -0
- data/app/views/incline/access_groups/show.json.jbuilder +11 -0
- data/app/views/incline/contact/new.html.erb +22 -0
- data/app/views/incline/contact_form/contact.html.erb +16 -0
- data/app/views/incline/contact_form/contact.text.erb +13 -0
- data/app/views/incline/password_resets/edit.html.erb +16 -0
- data/app/views/incline/password_resets/new.html.erb +12 -0
- data/app/views/incline/security/_details.json.jbuilder +7 -0
- data/app/views/incline/security/_form.html.erb +20 -0
- data/app/views/incline/security/_list.html.erb +89 -0
- data/app/views/incline/security/_messages.json.jbuilder +6 -0
- data/app/views/incline/security/edit.html.erb +2 -0
- data/app/views/incline/security/index.html.erb +6 -0
- data/app/views/incline/security/index.json.jbuilder +16 -0
- data/app/views/incline/security/show.html.erb +31 -0
- data/app/views/incline/security/show.json.jbuilder +11 -0
- data/app/views/incline/sessions/new.html.erb +26 -0
- data/app/views/incline/user_mailer/account_activation.html.erb +7 -0
- data/app/views/incline/user_mailer/account_activation.text.erb +6 -0
- data/app/views/incline/user_mailer/invalid_password_reset.html.erb +3 -0
- data/app/views/incline/user_mailer/invalid_password_reset.text.erb +5 -0
- data/app/views/incline/user_mailer/password_reset.html.erb +8 -0
- data/app/views/incline/user_mailer/password_reset.text.erb +7 -0
- data/app/views/incline/users/_details.json.jbuilder +32 -0
- data/app/views/incline/users/_form.html.erb +21 -0
- data/app/views/incline/users/_list.html.erb +102 -0
- data/app/views/incline/users/_messages.json.jbuilder +6 -0
- data/app/views/incline/users/disable_confirm.html.erb +19 -0
- data/app/views/incline/users/edit.html.erb +5 -0
- data/app/views/incline/users/index.html.erb +6 -0
- data/app/views/incline/users/index.json.jbuilder +16 -0
- data/app/views/incline/users/new.html.erb +5 -0
- data/app/views/incline/users/show.html.erb +12 -0
- data/app/views/incline/users/show.json.jbuilder +11 -0
- data/app/views/incline/welcome/home.html.erb +5 -0
- data/app/views/layouts/application.html.erb +1 -0
- data/app/views/layouts/incline/_account_menu.html.erb +18 -0
- data/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
- data/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
- data/app/views/layouts/incline/_footer.html.erb +13 -0
- data/app/views/layouts/incline/_header.html.erb +21 -0
- data/app/views/layouts/incline/_html_mailer.html.erb +5 -0
- data/app/views/layouts/incline/_incline_app.html.erb +25 -0
- data/app/views/layouts/incline/_messages.html.erb +3 -0
- data/app/views/layouts/incline/_shim.html.erb +3 -0
- data/app/views/layouts/incline/_text_mailer.text.erb +1 -0
- data/app/views/layouts/incline/application.html.erb +1 -0
- data/app/views/layouts/mailer.html.erb +2 -0
- data/app/views/layouts/mailer.text.erb +2 -0
- data/bin/rails +12 -0
- data/bin/test_scaffold.sh +10 -0
- data/config/routes.rb +61 -0
- data/db/migrate/20170511230126_create_incline_users.rb +26 -0
- data/db/migrate/20170515003052_create_incline_access_groups.rb +10 -0
- data/db/migrate/20170515003221_create_incline_user_login_histories.rb +12 -0
- data/db/migrate/20170515150908_create_incline_access_group_user_members.rb +11 -0
- data/db/migrate/20170515151058_create_incline_access_group_group_members.rb +11 -0
- data/db/migrate/20170517193432_add_comments_to_incline_user.rb +5 -0
- data/db/migrate/20170622132700_create_incline_action_securities.rb +16 -0
- data/db/migrate/20170622172712_create_incline_action_groups.rb +11 -0
- data/db/migrate/20170622195742_add_non_standard_to_action_security.rb +5 -0
- data/db/migrate/20170622230422_add_visible_to_action_security.rb +5 -0
- data/db/seeds.rb +81 -0
- data/exe/new_incline_app +42 -0
- data/lib/generators/incline/install_generator.rb +259 -0
- data/lib/generators/incline/templates/_app_menu_anon.html.erb +1 -0
- data/lib/generators/incline/templates/_app_menu_authenticated.html.erb +1 -0
- data/lib/generators/incline/templates/incline_application.css +17 -0
- data/lib/generators/incline/templates/incline_application.html.erb +1 -0
- data/lib/generators/incline/templates/incline_application.js +12 -0
- data/lib/generators/incline/templates/incline_database.yml +25 -0
- data/lib/generators/incline/templates/incline_email.yml +20 -0
- data/lib/generators/incline/templates/incline_mailer.html.erb +2 -0
- data/lib/generators/incline/templates/incline_mailer.text.erb +2 -0
- data/lib/generators/incline/templates/incline_users.yml +64 -0
- data/lib/generators/incline/templates/incline_version.rb +3 -0
- data/lib/incline/auth_engine_base.rb +52 -0
- data/lib/incline/data_tables_request.rb +336 -0
- data/lib/incline/date_time_formats.rb +6 -0
- data/lib/incline/engine.rb +212 -0
- data/lib/incline/errors.rb +15 -0
- data/lib/incline/extensions/action_controller_base.rb +526 -0
- data/lib/incline/extensions/action_mailer_base.rb +66 -0
- data/lib/incline/extensions/action_view_base.rb +489 -0
- data/lib/incline/extensions/active_record_base.rb +308 -0
- data/lib/incline/extensions/application.rb +137 -0
- data/lib/incline/extensions/application_configuration.rb +50 -0
- data/lib/incline/extensions/connection_adapter.rb +55 -0
- data/lib/incline/extensions/date_time_value.rb +123 -0
- data/lib/incline/extensions/date_value.rb +77 -0
- data/lib/incline/extensions/decimal_value.rb +55 -0
- data/lib/incline/extensions/erb_scaffold_generator.rb +31 -0
- data/lib/incline/extensions/float_value.rb +59 -0
- data/lib/incline/extensions/form_builder.rb +617 -0
- data/lib/incline/extensions/integer_value.rb +54 -0
- data/lib/incline/extensions/jbuilder_generator.rb +38 -0
- data/lib/incline/extensions/jbuilder_template.rb +39 -0
- data/lib/incline/extensions/main_app.rb +40 -0
- data/lib/incline/extensions/numeric.rb +63 -0
- data/lib/incline/extensions/object.rb +31 -0
- data/lib/incline/extensions/resource_route_generator.rb +53 -0
- data/lib/incline/extensions/session.rb +113 -0
- data/lib/incline/extensions/string.rb +50 -0
- data/lib/incline/extensions/test_case.rb +764 -0
- data/lib/incline/extensions/time_zone_converter.rb +40 -0
- data/lib/incline/global_status.rb +236 -0
- data/lib/incline/helpers/route_hash_formatter.rb +46 -0
- data/lib/incline/json_log_formatter.rb +96 -0
- data/lib/incline/json_logger.rb +17 -0
- data/lib/incline/log.rb +153 -0
- data/lib/incline/number_formats.rb +17 -0
- data/lib/incline/recaptcha.rb +346 -0
- data/lib/incline/user_manager.rb +212 -0
- data/lib/incline/validators/email_validator.rb +45 -0
- data/lib/incline/validators/ip_address_validator.rb +32 -0
- data/lib/incline/validators/recaptcha_validator.rb +37 -0
- data/lib/incline/validators/safe_name_validator.rb +31 -0
- data/lib/incline/version.rb +3 -0
- data/lib/incline/work_path.rb +75 -0
- data/lib/incline.rb +197 -0
- data/lib/tasks/incline_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +43 -0
- data/lib/templates/erb/scaffold/_list.html.erb +81 -0
- data/lib/templates/erb/scaffold/edit.html.erb +1 -0
- data/lib/templates/erb/scaffold/index.html.erb +6 -0
- data/lib/templates/erb/scaffold/new.html.erb +1 -0
- data/lib/templates/erb/scaffold/show.html.erb +34 -0
- data/lib/templates/jbuilder/scaffold/_details.json.jbuilder +20 -0
- data/lib/templates/jbuilder/scaffold/index.json.jbuilder +16 -0
- data/lib/templates/jbuilder/scaffold/show.json.jbuilder +16 -0
- data/lib/templates/rails/scaffold_controller/controller.rb +128 -0
- data/test/controllers/incline/access_groups_controller_test.rb +65 -0
- data/test/controllers/incline/access_test_controller_test.rb +53 -0
- data/test/controllers/incline/contact_controller_test.rb +32 -0
- data/test/controllers/incline/security_controller_test.rb +39 -0
- data/test/controllers/incline/welcome_controller_test.rb +16 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +12 -0
- data/test/dummy/app/assets/stylesheets/application.css +17 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +1 -0
- data/test/dummy/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
- data/test/dummy/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +2 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +2 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +38 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +34 -0
- data/test/dummy/config/email.yml +24 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +45 -0
- data/test/dummy/config/environments/production.rb +85 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +108 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/extensions/action_controller_base_extensions_test.rb +21 -0
- data/test/extensions/action_mailer_base_extensions_test.rb +20 -0
- data/test/extensions/action_view_base_extensions_test.rb +267 -0
- data/test/extensions/active_record_extensions_test.rb +173 -0
- data/test/extensions/application_configuration_extensions_test.rb +46 -0
- data/test/extensions/application_extensions_test.rb +23 -0
- data/test/extensions/connection_adapter_extensions_test.rb +54 -0
- data/test/extensions/date_time_value_extensions_test.rb +104 -0
- data/test/extensions/date_value_extensions_test.rb +102 -0
- data/test/extensions/decimal_value_extensions_test.rb +85 -0
- data/test/extensions/erb_scaffold_generator_extensions_test.rb +17 -0
- data/test/extensions/float_value_extensions_test.rb +78 -0
- data/test/extensions/form_builder_extensions_test.rb +28 -0
- data/test/extensions/integer_value_extensions_test.rb +78 -0
- data/test/extensions/jbuilder_generator_extensions_test.rb +21 -0
- data/test/extensions/jbuilder_template_extensions_test.rb +47 -0
- data/test/extensions/main_app_extensions_test.rb +55 -0
- data/test/extensions/numeric_extensions_test.rb +76 -0
- data/test/extensions/object_extensions_test.rb +104 -0
- data/test/extensions/session_extensions_test.rb +69 -0
- data/test/extensions/string_extensions_test.rb +32 -0
- data/test/extensions/test_case_extensions_test.rb +538 -0
- data/test/extensions/time_zone_converter_extensions_test.rb +10 -0
- data/test/fixtures/incline/access_group_group_members.yml +1 -0
- data/test/fixtures/incline/access_group_user_members.yml +1 -0
- data/test/fixtures/incline/access_groups.yml +13 -0
- data/test/fixtures/incline/action_groups.yml +6 -0
- data/test/fixtures/incline/action_securities.yml +18 -0
- data/test/fixtures/incline/user_login_histories.yml +1 -0
- data/test/fixtures/incline/users.yml +64 -0
- data/test/incline_test.rb +63 -0
- data/test/integration/incline/users_edit_test.rb +180 -0
- data/test/integration/incline/users_login_test.rb +105 -0
- data/test/integration/incline/users_signup_test.rb +147 -0
- data/test/integration/navigation_test.rb +11 -0
- data/test/lib/data_tables_request_test.rb +245 -0
- data/test/lib/date_time_formats_test.rb +111 -0
- data/test/lib/global_status_test.rb +89 -0
- data/test/lib/json_log_formatter_test.rb +43 -0
- data/test/lib/log_test.rb +36 -0
- data/test/lib/recaptcha_test.rb +75 -0
- data/test/lib/user_manager_test.rb +47 -0
- data/test/lib/work_path_test.rb +18 -0
- data/test/models/incline/access_group_group_member_test.rb +30 -0
- data/test/models/incline/access_group_test.rb +60 -0
- data/test/models/incline/access_group_user_member_test.rb +29 -0
- data/test/models/incline/action_group_test.rb +27 -0
- data/test/models/incline/action_security_test.rb +176 -0
- data/test/models/incline/contact_message_test.rb +66 -0
- data/test/models/incline/disable_info_test.rb +29 -0
- data/test/models/incline/password_reset_request_test.rb +35 -0
- data/test/models/incline/password_reset_test.rb +51 -0
- data/test/models/incline/user_login_history_test.rb +31 -0
- data/test/models/incline/user_test.rb +91 -0
- data/test/test_helper.rb +42 -0
- data/test/validators/email_validator_test.rb +102 -0
- data/test/validators/ip_address_validator_test.rb +107 -0
- data/test/validators/recaptcha_validator_test.rb +57 -0
- data/test/validators/safe_name_validator_test.rb +101 -0
- metadata +584 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EmailValidatorTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class TestModel
|
6
|
+
include ActiveModel::Model
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
attr_accessor :email
|
10
|
+
|
11
|
+
validates :email, 'incline/email' => true
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@item = TestModel.new(email: 'tester@example.com')
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'initial value should be valid' do
|
19
|
+
assert @item.valid?
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'email validator ignores blank values' do
|
23
|
+
@item.email = nil
|
24
|
+
assert @item.valid?
|
25
|
+
@item.email = ''
|
26
|
+
assert @item.valid?
|
27
|
+
@item.email = ' '
|
28
|
+
assert @item.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'domain regex accepts valid domains' do
|
32
|
+
[
|
33
|
+
'localhost.localdoman',
|
34
|
+
'www.com',
|
35
|
+
'123.com',
|
36
|
+
'1.2.3.4.5.6.7.8.9.com',
|
37
|
+
'a.b.c.d.e.f.g.h.i.j.org',
|
38
|
+
'www.google.com',
|
39
|
+
'www.test-one-two-three.com',
|
40
|
+
'a.one---two.com',
|
41
|
+
].each do |dom|
|
42
|
+
assert Incline::EmailValidator::VALID_DOMAIN_REGEX =~ dom, "Domain #{dom.inspect} should be valid"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'domain regex rejects invalid domains' do
|
47
|
+
[
|
48
|
+
'localdomain',
|
49
|
+
'www.123',
|
50
|
+
'www.-hello-world-.com',
|
51
|
+
'www.-hello.com',
|
52
|
+
'www.world-.com',
|
53
|
+
'www.hello-world',
|
54
|
+
'www..com',
|
55
|
+
'.com',
|
56
|
+
'www.',
|
57
|
+
'www-com'
|
58
|
+
].each do |dom|
|
59
|
+
assert_not Incline::EmailValidator::VALID_DOMAIN_REGEX =~ dom, "Domain #{dom.inspect} should not be valid"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'should accept valid addresses' do
|
64
|
+
valid = %w(
|
65
|
+
user@example.com
|
66
|
+
USER@foo.COM
|
67
|
+
A_US-ER@foo.bar.org
|
68
|
+
first.last@foo.jp
|
69
|
+
alice+bob@bax.cn
|
70
|
+
)
|
71
|
+
|
72
|
+
valid.each do |address|
|
73
|
+
@item.email = address
|
74
|
+
assert @item.valid?, "#{address.inspect} should be valid"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'should reject invalid addresses' do
|
79
|
+
invalid = %w(
|
80
|
+
user@example,com
|
81
|
+
user_at_foo.org
|
82
|
+
user@example.
|
83
|
+
user@example.com.
|
84
|
+
foo@bar_baz.com
|
85
|
+
foo@bar+baz.com
|
86
|
+
@example.com
|
87
|
+
user@
|
88
|
+
user
|
89
|
+
user@..com
|
90
|
+
user@example..com
|
91
|
+
user@.example.com
|
92
|
+
user@@example.com
|
93
|
+
user@www@example.com
|
94
|
+
)
|
95
|
+
|
96
|
+
invalid.each do |address|
|
97
|
+
@item.email = address
|
98
|
+
assert_not @item.valid?, "#{address.inspect} should not be valid"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class IpAddressValidatorTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class TestModel
|
6
|
+
include ActiveModel::Model
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
attr_accessor :one
|
10
|
+
attr_accessor :one_or_many
|
11
|
+
attr_accessor :many
|
12
|
+
|
13
|
+
validates :one, 'incline/ip_address' => { no_mask: true }
|
14
|
+
validates :one_or_many, 'incline/ip_address' => true
|
15
|
+
validates :many, 'incline/ip_address' => { require_mask: true }
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@item = TestModel.new(one: '192.168.0.1', one_or_many: '192.168.0.1', many: '192.168.0.0/24')
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'initial values should be valid' do
|
23
|
+
assert @item.valid?
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'ip_address validator ignores blank values' do
|
27
|
+
[ :one, :one_or_many, :many ].each do |attr|
|
28
|
+
setter = :"#{attr}="
|
29
|
+
val = @item.send(attr)
|
30
|
+
|
31
|
+
@item.send setter, nil
|
32
|
+
assert @item.valid?, "#{attr} should allow nil"
|
33
|
+
|
34
|
+
@item.send setter, ''
|
35
|
+
assert @item.valid?, "#{attr} should allow ''"
|
36
|
+
|
37
|
+
@item.send setter, ' '
|
38
|
+
assert @item.valid?, "#{attr} should allow ' '"
|
39
|
+
|
40
|
+
@item.send setter, val
|
41
|
+
assert @item.valid?, "#{attr} should allow '#{val}'"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'one should not accept a mask' do
|
46
|
+
@item.one = '192.168.0.0/24'
|
47
|
+
assert_not @item.valid?
|
48
|
+
assert @item.errors[:one].to_s =~ /must not contain a mask/i
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'many should require a mask' do
|
52
|
+
@item.many = '192.168.0.1'
|
53
|
+
assert_not @item.valid?
|
54
|
+
assert @item.errors[:many].to_s =~ /must contain a mask/i
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'one_or_many should allow a mask' do
|
58
|
+
@item.one_or_many = '102.168.0.1/24'
|
59
|
+
assert @item.valid?
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'should allow valid addresses' do
|
63
|
+
%w(
|
64
|
+
127.0.0.1
|
65
|
+
127.0.0.1/8
|
66
|
+
127.0.0.1/16
|
67
|
+
127.0.0.1/24
|
68
|
+
1.2.3.4/32
|
69
|
+
0.0.0.0
|
70
|
+
255.255.255.255
|
71
|
+
::
|
72
|
+
::1
|
73
|
+
abcd::1234
|
74
|
+
abcd::/64
|
75
|
+
1:2:3:4:a:b:c:d
|
76
|
+
1111:2222:3333:4444:aaaa:bbbb:cccc:dddd/112
|
77
|
+
fe80::1234/128
|
78
|
+
).each do |addr|
|
79
|
+
@item.one_or_many = addr
|
80
|
+
assert @item.valid?, "Should allow '#{addr}'."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'should not allow invalid addresses' do
|
85
|
+
safe = @item.one_or_many
|
86
|
+
%w(
|
87
|
+
100.200.300.400
|
88
|
+
1111::2222::3333
|
89
|
+
1234:5678:90ab:cdef:ghij:klmn:opqr:stuv
|
90
|
+
12345::
|
91
|
+
::12345
|
92
|
+
1.2.3
|
93
|
+
1.2.3.4/33
|
94
|
+
1.2.3.4.5
|
95
|
+
::1/129
|
96
|
+
1::2::3
|
97
|
+
).each do |addr|
|
98
|
+
@item.one_or_many = addr
|
99
|
+
assert_not @item.valid?, "Should not allow '#{addr}'."
|
100
|
+
assert @item.errors[:one_or_many].to_s =~ /not a valid ip address/i, "address '#{addr}' did not fail for the expected reason"
|
101
|
+
@item.one_or_many = safe
|
102
|
+
assert @item.valid?, "Should allow '#{safe}'."
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RecaptchaValidatorTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class TestModel
|
6
|
+
include ActiveModel::Model
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
attr_accessor :recaptcha
|
10
|
+
|
11
|
+
validates :recaptcha, 'incline/recaptcha' => true
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@item = TestModel.new(recaptcha: Incline::Recaptcha::DISABLED)
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'initial value should be valid' do
|
19
|
+
assert @item.valid?
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'recaptcha validator ignores blank values' do
|
23
|
+
@item.recaptcha = nil
|
24
|
+
assert @item.valid?
|
25
|
+
@item.recaptcha = ''
|
26
|
+
assert @item.valid?
|
27
|
+
@item.recaptcha = ' '
|
28
|
+
assert @item.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'recaptcha validator has two error messages' do
|
32
|
+
@item.recaptcha = '127.0.0.1' # no response
|
33
|
+
assert_not @item.valid?
|
34
|
+
assert @item.errors[:base].to_s =~ /requires recaptcha challenge to be completed/i
|
35
|
+
|
36
|
+
@item.recaptcha = '127.0.0.1|invalid' # invalid response
|
37
|
+
assert_not @item.valid?
|
38
|
+
assert @item.errors[:base].to_s =~ /invalid response from recaptcha challenge/i
|
39
|
+
|
40
|
+
# make sure it did not fail because of the IP address portion.
|
41
|
+
@item.recaptcha = '127.0.0.1|disabled'
|
42
|
+
assert @item.valid?
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'recaptcha validator changes value' do
|
46
|
+
assert_not_equal :verified, @item.recaptcha
|
47
|
+
|
48
|
+
# the validator changes the value to :verified when it passes.
|
49
|
+
assert @item.valid?
|
50
|
+
assert_equal :verified, @item.recaptcha
|
51
|
+
|
52
|
+
# that way future calls to valid? will continue to pass.
|
53
|
+
assert @item.valid?
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SafeNameValidatorTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class TestModel
|
6
|
+
include ActiveModel::Model
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
validates :name, 'incline/safe_name' => true
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@item = TestModel.new(name: 'hello_world')
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'initial value should be valid' do
|
19
|
+
assert @item.valid?
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'value can be in any case' do
|
23
|
+
@item.name = 'HELLO_WORLD'
|
24
|
+
assert @item.valid?
|
25
|
+
@item.name = 'Hello_World'
|
26
|
+
assert @item.valid?
|
27
|
+
@item.name = 'hello_WORLD'
|
28
|
+
assert @item.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'safe_name validator ignores blank values' do
|
32
|
+
@item.name = nil
|
33
|
+
assert @item.valid?
|
34
|
+
@item.name = ''
|
35
|
+
assert @item.valid?
|
36
|
+
@item.name = ' '
|
37
|
+
assert @item.valid?
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'should accept valid names' do
|
41
|
+
%w(
|
42
|
+
abcd
|
43
|
+
a_b_c_d
|
44
|
+
abc123
|
45
|
+
alpha_beta_1_2_3
|
46
|
+
alpha_beta___123
|
47
|
+
).each do |name|
|
48
|
+
@item.name = name
|
49
|
+
assert @item.valid?, "should accept '#{name}'"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should reject invalid names' do
|
54
|
+
safe = @item.name
|
55
|
+
[
|
56
|
+
'123',
|
57
|
+
'_abc123',
|
58
|
+
' abc123',
|
59
|
+
'=abc123',
|
60
|
+
'+abc123',
|
61
|
+
'-abc123',
|
62
|
+
':abc123',
|
63
|
+
'@abc123',
|
64
|
+
'$abc123'
|
65
|
+
].each do |name|
|
66
|
+
@item.name = name
|
67
|
+
assert_not @item.valid?, "should not accept '#{name}'"
|
68
|
+
assert @item.errors[:name].to_s =~ /must start with a letter/i, "name '#{name}' did not fail for the expected reason"
|
69
|
+
@item.name = safe
|
70
|
+
assert @item.valid?
|
71
|
+
end
|
72
|
+
[
|
73
|
+
'abc_',
|
74
|
+
'abc_123_',
|
75
|
+
'abc 123_'
|
76
|
+
].each do |name|
|
77
|
+
@item.name = name
|
78
|
+
assert_not @item.valid?, "should not accept '#{name}'"
|
79
|
+
assert @item.errors[:name].to_s =~ /must not end with an underscore/i, "name '#{name}' did not fail for the expected reason"
|
80
|
+
@item.name = safe
|
81
|
+
assert @item.valid?
|
82
|
+
end
|
83
|
+
[
|
84
|
+
'abc 123',
|
85
|
+
'a b c d',
|
86
|
+
'abc123?',
|
87
|
+
'abc123!',
|
88
|
+
'abc_123(0)',
|
89
|
+
'abc,123',
|
90
|
+
'abc-123'
|
91
|
+
].each do |name|
|
92
|
+
@item.name = name
|
93
|
+
assert_not @item.valid?, "should not accept '#{name}'"
|
94
|
+
assert @item.errors[:name].to_s =~ /must contain only letters, numbers, and underscore/i, "name '#{name}' did not fail for the expected reason"
|
95
|
+
@item.name = safe
|
96
|
+
assert @item.valid?
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|