barkest_core 1.5.3.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 +7 -0
- data/.gitignore +13 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +254 -0
- data/MIT-LICENSE +20 -0
- data/README.md +364 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Bold.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-BoldItalic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Italic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Regular.ttf +0 -0
- data/app/assets/images/barkest_core/.keep +0 -0
- data/app/assets/images/barkest_core/barcode-B.svg +181 -0
- data/app/assets/javascripts/barkest_core/.keep +0 -0
- data/app/assets/javascripts/barkest_core/application.js +22 -0
- data/app/assets/javascripts/barkest_core/bootstrap-datepicker.js +1800 -0
- data/app/assets/javascripts/barkest_core/field_init.js +7 -0
- data/app/assets/javascripts/barkest_core/jquery.doubleScroll.js +112 -0
- data/app/assets/javascripts/barkest_core/masked_edit.js +25 -0
- data/app/assets/javascripts/barkest_core/system_status.js.erb +201 -0
- data/app/assets/stylesheets/barkest_core/.keep +0 -0
- data/app/assets/stylesheets/barkest_core/application.css +17 -0
- data/app/assets/stylesheets/barkest_core/custom.css.scss +264 -0
- data/app/assets/stylesheets/barkest_core/datepicker3.css +790 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/access_groups_controller.rb +74 -0
- data/app/controllers/account_activations_controller.rb +29 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/barkest_core/application_controller_base.rb +113 -0
- data/app/controllers/barkest_core/engine_controller_base.rb +15 -0
- data/app/controllers/barkest_core/testsub_controller.rb +21 -0
- data/app/controllers/contact_controller.rb +32 -0
- data/app/controllers/log_view_controller.rb +31 -0
- data/app/controllers/password_resets_controller.rb +126 -0
- data/app/controllers/sessions_controller.rb +64 -0
- data/app/controllers/status_controller.rb +150 -0
- data/app/controllers/system_config_controller.rb +238 -0
- data/app/controllers/system_update_controller.rb +164 -0
- data/app/controllers/test_access_controller.rb +44 -0
- data/app/controllers/test_report_controller.rb +75 -0
- data/app/controllers/users_controller.rb +218 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/barkest_core/application_helper.rb +134 -0
- data/app/helpers/barkest_core/form_helper.rb +469 -0
- data/app/helpers/barkest_core/html_helper.rb +70 -0
- data/app/helpers/barkest_core/misc_helper.rb +68 -0
- data/app/helpers/barkest_core/pdf_helper.rb +180 -0
- data/app/helpers/barkest_core/recaptcha_helper.rb +115 -0
- data/app/helpers/barkest_core/sessions_helper.rb +94 -0
- data/app/helpers/barkest_core/status_helper.rb +118 -0
- data/app/helpers/barkest_core/users_helper.rb +32 -0
- data/app/mailers/.keep +0 -0
- data/app/mailers/application_mailer.rb +5 -0
- data/app/mailers/barkest_core/application_mailer_base.rb +30 -0
- data/app/mailers/barkest_core/contact_form.rb +20 -0
- data/app/mailers/barkest_core/user_mailer.rb +44 -0
- data/app/models/.keep +0 -0
- data/app/models/access_group.rb +121 -0
- data/app/models/access_group_group_member.rb +13 -0
- data/app/models/access_group_user_member.rb +11 -0
- data/app/models/barkest_core/auth_config.rb +95 -0
- data/app/models/barkest_core/authorize_failure.rb +7 -0
- data/app/models/barkest_core/contact_message.rb +37 -0
- data/app/models/barkest_core/database_config.rb +223 -0
- data/app/models/barkest_core/db_table.rb +21 -0
- data/app/models/barkest_core/email_config.rb +132 -0
- data/app/models/barkest_core/global_status.rb +267 -0
- data/app/models/barkest_core/log_entry.rb +101 -0
- data/app/models/barkest_core/log_view_options.rb +51 -0
- data/app/models/barkest_core/ms_sql_db_definition.rb +441 -0
- data/app/models/barkest_core/ms_sql_definition.rb +221 -0
- data/app/models/barkest_core/ms_sql_function.rb +423 -0
- data/app/models/barkest_core/not_logged_in.rb +7 -0
- data/app/models/barkest_core/pdf_table_builder.rb +407 -0
- data/app/models/barkest_core/self_update_config.rb +37 -0
- data/app/models/barkest_core/user_alert.rb +29 -0
- data/app/models/barkest_core/user_alert_generators.rb +58 -0
- data/app/models/barkest_core/user_manager.rb +404 -0
- data/app/models/barkest_core/work_path.rb +74 -0
- data/app/models/disable_user.rb +18 -0
- data/app/models/ldap_access_group.rb +15 -0
- data/app/models/system_config.rb +99 -0
- data/app/models/user.rb +405 -0
- data/app/models/user_login_history.rb +11 -0
- data/app/views/.keep +0 -0
- data/app/views/access_groups/_form.html.erb +19 -0
- data/app/views/access_groups/edit.html.erb +2 -0
- data/app/views/access_groups/index.html.erb +32 -0
- data/app/views/access_groups/new.html.erb +2 -0
- data/app/views/access_groups/show.html.erb +4 -0
- data/app/views/barkest_core/contact_form/contact.html.erb +16 -0
- data/app/views/barkest_core/contact_form/contact.text.erb +13 -0
- data/app/views/barkest_core/testsub/_links.html.erb +5 -0
- data/app/views/barkest_core/testsub/page1.html.erb +3 -0
- data/app/views/barkest_core/testsub/page2.html.erb +2 -0
- data/app/views/barkest_core/testsub/page3.html.erb +2 -0
- data/app/views/barkest_core/user_mailer/account_activation.html.erb +7 -0
- data/app/views/barkest_core/user_mailer/account_activation.text.erb +6 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.html.erb +3 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.text.erb +5 -0
- data/app/views/barkest_core/user_mailer/password_reset.html.erb +8 -0
- data/app/views/barkest_core/user_mailer/password_reset.text.erb +7 -0
- data/app/views/contact/index.html.erb +24 -0
- data/app/views/layouts/_footer_copyright.html.erb +1 -0
- data/app/views/layouts/_menu_admin.html.erb +5 -0
- data/app/views/layouts/_menu_anon.html.erb +0 -0
- data/app/views/layouts/_menu_auth.html.erb +3 -0
- data/app/views/layouts/_menu_footer.html.erb +1 -0
- data/app/views/layouts/_nav_logo.html.erb +1 -0
- data/app/views/layouts/application.html.erb +2 -0
- data/app/views/layouts/barkest_core/_application.html.erb +24 -0
- data/app/views/layouts/barkest_core/_footer.html.erb +18 -0
- data/app/views/layouts/barkest_core/_header.html.erb +38 -0
- data/app/views/layouts/barkest_core/_html_mailer.html.erb +11 -0
- data/app/views/layouts/barkest_core/_menu_account.html.erb +14 -0
- data/app/views/layouts/barkest_core/_menu_sample.html.erb +1 -0
- data/app/views/layouts/barkest_core/_messages.html.erb +4 -0
- data/app/views/layouts/barkest_core/_shim.html.erb +4 -0
- data/app/views/layouts/barkest_core/_subheader.html.erb +1 -0
- data/app/views/layouts/barkest_core/_text_mailer.text.erb +4 -0
- data/app/views/layouts/mailer.html.erb +1 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/log_view/index.html.erb +100 -0
- data/app/views/password_resets/edit.html.erb +20 -0
- data/app/views/password_resets/new.html.erb +14 -0
- data/app/views/sessions/new.html.erb +27 -0
- data/app/views/shared/_error_messages.html.erb +29 -0
- data/app/views/shared/_generic_user_alert.html.erb +4 -0
- data/app/views/status/current.html.erb +34 -0
- data/app/views/status/test.html.erb +50 -0
- data/app/views/system_config/index.html.erb +25 -0
- data/app/views/system_config/show_auth.html.erb +28 -0
- data/app/views/system_config/show_database.html.erb +36 -0
- data/app/views/system_config/show_email.html.erb +21 -0
- data/app/views/system_config/show_self_update.html.erb +13 -0
- data/app/views/system_update/index.html.erb +31 -0
- data/app/views/system_update/new.html.erb +2 -0
- data/app/views/test_access/allow_anon.html.erb +2 -0
- data/app/views/test_access/require_admin.html.erb +2 -0
- data/app/views/test_access/require_group_x.html.erb +2 -0
- data/app/views/test_access/require_user.html.erb +2 -0
- data/app/views/test_report/index.csv.csvrb +23 -0
- data/app/views/test_report/index.html.erb +6 -0
- data/app/views/test_report/index.pdf.prawn +50 -0
- data/app/views/test_report/index.xlsx.axlsx +28 -0
- data/app/views/users/_user.html.erb +57 -0
- data/app/views/users/_user_details.html.erb +15 -0
- data/app/views/users/_user_details_for_list.html.erb +1 -0
- data/app/views/users/_user_form.html.erb +13 -0
- data/app/views/users/disable_confirm.html.erb +19 -0
- data/app/views/users/edit.html.erb +15 -0
- data/app/views/users/index.html.erb +9 -0
- data/app/views/users/new.html.erb +10 -0
- data/app/views/users/show.html.erb +46 -0
- data/bin/rails +12 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160617172539_create_access_groups.rb +10 -0
- data/db/migrate/20160617172725_create_users.rb +26 -0
- data/db/migrate/20160617172833_create_user_login_histories.rb +12 -0
- data/db/migrate/20160622151720_create_access_group_user_members.rb +9 -0
- data/db/migrate/20160622151925_create_access_group_group_members.rb +9 -0
- data/db/migrate/20160701005706_create_ldap_access_groups.rb +11 -0
- data/db/migrate/20161108155029_create_system_configs.rb +11 -0
- data/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/db/seeds.rb +53 -0
- data/lib/barkest_core/concerns/association_with_defaults.rb +55 -0
- data/lib/barkest_core/concerns/boolean_parser.rb +88 -0
- data/lib/barkest_core/concerns/date_parser.rb +181 -0
- data/lib/barkest_core/concerns/email_tester.rb +55 -0
- data/lib/barkest_core/concerns/encrypted_fields.rb +156 -0
- data/lib/barkest_core/concerns/named_model.rb +73 -0
- data/lib/barkest_core/concerns/number_parser.rb +145 -0
- data/lib/barkest_core/concerns/utc_conversion.rb +60 -0
- data/lib/barkest_core/engine.rb +105 -0
- data/lib/barkest_core/extensions/active_record_extensions.rb +120 -0
- data/lib/barkest_core/extensions/application_configuration_extensions.rb +38 -0
- data/lib/barkest_core/extensions/application_extensions.rb +50 -0
- data/lib/barkest_core/extensions/axlsx_extenstions.rb +157 -0
- data/lib/barkest_core/extensions/fixture_set_extensions.rb +107 -0
- data/lib/barkest_core/extensions/generator_extensions.rb +271 -0
- data/lib/barkest_core/extensions/main_app_extensions.rb +35 -0
- data/lib/barkest_core/extensions/prawn_document_extensions.rb +367 -0
- data/lib/barkest_core/extensions/prawn_table_extensions.rb +131 -0
- data/lib/barkest_core/extensions/router_extensions.rb +106 -0
- data/lib/barkest_core/extensions/simple_formatter_extensions.rb +66 -0
- data/lib/barkest_core/extensions/test_case_extensions.rb +348 -0
- data/lib/barkest_core/extensions/time_extensions.rb +164 -0
- data/lib/barkest_core/handlers/csv_handler.rb +30 -0
- data/lib/barkest_core/version.rb +3 -0
- data/lib/barkest_core.rb +324 -0
- data/lib/generators/barkest/install_generator.rb +102 -0
- data/lib/generators/barkest_core/actions/01_patch_application_controller.rb +55 -0
- data/lib/generators/barkest_core/actions/02_patch_application_mailer.rb +56 -0
- data/lib/generators/barkest_core/actions/03_patch_assets.rb +62 -0
- data/lib/generators/barkest_core/actions/04_patch_layouts.rb +36 -0
- data/lib/generators/barkest_core/actions/05_patch_routes.rb +93 -0
- data/lib/generators/barkest_core/actions/06_patch_seeds.rb +60 -0
- data/lib/generators/barkest_core/actions/07_copy_migrations.rb +51 -0
- data/lib/generators/barkest_core/actions/08_configure_database.rb +52 -0
- data/lib/generators/barkest_core/actions/09_configure_secrets.rb +29 -0
- data/lib/generators/barkest_core/actions/99_patch_gitignore.rb +57 -0
- data/lib/generators/barkest_core/install_generator.rb +17 -0
- data/test/barkest_core_test.rb +83 -0
- data/test/controllers/access_groups_controller_test.rb +53 -0
- data/test/controllers/contact_controller_test.rb +10 -0
- data/test/controllers/sessions_controller_test.rb +10 -0
- data/test/controllers/users_controller_test.rb +10 -0
- data/test/dummy/.gitignore +10 -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 +14 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -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/mailers/application_mailer.rb +3 -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/mailer.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/system_config/show_fake.html.erb +3 -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 +27 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +47 -0
- data/test/dummy/config/environments/production.rb +79 -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/db_updater_ext.rb +33 -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/sys_config_ext.rb +12 -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 +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +95 -0
- data/test/dummy/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/test/dummy/db/seeds.rb +51 -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/dummy/sql/my_test_view.sql +3 -0
- data/test/fixtures/access_groups.yml +21 -0
- data/test/fixtures/users.yml +71 -0
- data/test/helpers/barkest_core/sessions_helper_test.rb +22 -0
- data/test/integration/access_group_mgmt_test.rb +33 -0
- data/test/integration/access_test.rb +24 -0
- data/test/integration/account_activations_access_test.rb +12 -0
- data/test/integration/contact_test.rb +98 -0
- data/test/integration/extra_partial_test.rb +41 -0
- data/test/integration/log_view_access_test.rb +12 -0
- data/test/integration/password_resets_test.rb +101 -0
- data/test/integration/reports_test.rb +53 -0
- data/test/integration/status_access_test.rb +27 -0
- data/test/integration/system_config_access_test.rb +24 -0
- data/test/integration/system_update_access_test.rb +19 -0
- data/test/integration/users_access_test.rb +34 -0
- data/test/integration/users_edit_test.rb +178 -0
- data/test/integration/users_index_test.rb +62 -0
- data/test/integration/users_login_test.rb +67 -0
- data/test/integration/users_signup_test.rb +54 -0
- data/test/mailers/.keep +0 -0
- data/test/mailers/barkest_core/contact_form_test.rb +28 -0
- data/test/mailers/barkest_core/user_mailer_test.rb +43 -0
- data/test/mailers/previews/barkest_core/contact_form_preview.rb +17 -0
- data/test/mailers/previews/barkest_core/user_mailer_preview.rb +26 -0
- data/test/models/access_group_group_member_test.rb +28 -0
- data/test/models/access_group_test.rb +114 -0
- data/test/models/access_group_user_member_test.rb +28 -0
- data/test/models/barkest_core/auth_config_test.rb +57 -0
- data/test/models/barkest_core/bool_parser_test.rb +28 -0
- data/test/models/barkest_core/contact_message_test.rb +61 -0
- data/test/models/barkest_core/database_config_test.rb +33 -0
- data/test/models/barkest_core/date_parser_test.rb +110 -0
- data/test/models/barkest_core/email_config_test.rb +57 -0
- data/test/models/barkest_core/global_status_test.rb +50 -0
- data/test/models/barkest_core/ms_sql_db_updater_test.rb +115 -0
- data/test/models/barkest_core/ms_sql_definition_test.rb +102 -0
- data/test/models/barkest_core/ms_sql_function_test.rb +131 -0
- data/test/models/barkest_core/number_parser_test.rb +29 -0
- data/test/models/barkest_core/self_update_config_test.rb +29 -0
- data/test/models/barkest_core/user_alert_test.rb +19 -0
- data/test/models/barkest_core/user_manager_test.rb +34 -0
- data/test/models/barkest_core/work_path_test.rb +26 -0
- data/test/models/disable_user_test.rb +27 -0
- data/test/models/generic_time_test.rb +66 -0
- data/test/models/ldap_access_group_test.rb +31 -0
- data/test/models/pdf_table_builder_test.rb +6 -0
- data/test/models/system_config_test.rb +78 -0
- data/test/models/user_login_history_test.rb +37 -0
- data/test/models/user_test.rb +130 -0
- data/test/test_helper.rb +63 -0
- metadata +798 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
module BarkestCore
|
|
3
|
+
class MsSqlFunctionTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
# There is a weird glitch? in ActiveRecord.
|
|
6
|
+
# If I establish a connection here then ALL ActiveRecord transactions seem to hit up the
|
|
7
|
+
# SQL server for at least a "reset!" call. On a high latency (VPN) connection, this is
|
|
8
|
+
# very noticeable and causes the entire test routine to take several minutes.
|
|
9
|
+
#
|
|
10
|
+
# Instead we establish the connection before our tests here and remove the connection
|
|
11
|
+
# immediately after. That seems to keep the test suite running quickly.
|
|
12
|
+
#
|
|
13
|
+
# Hopefully this is not an issue that occurs during production, I have not noticed it in
|
|
14
|
+
# development yet, only testing.
|
|
15
|
+
class MyTestFunctionParentTable < ActiveRecord::Base
|
|
16
|
+
self.abstract_class = true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class MyTestFunction < ::BarkestCore::MsSqlFunction
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
MY_TEST_FUNCTION_NAME = 'zz_barkest_core_test_function'
|
|
24
|
+
|
|
25
|
+
MY_TEST_FUNCTION_DEFINITION = <<-EOSQL
|
|
26
|
+
CREATE FUNCTION #{MY_TEST_FUNCTION_NAME}(
|
|
27
|
+
@alpha INTEGER,
|
|
28
|
+
@bravo VARCHAR(100),
|
|
29
|
+
@charlie DATETIME
|
|
30
|
+
) RETURNS TABLE AS RETURN
|
|
31
|
+
SELECT
|
|
32
|
+
LEN(ISNULL(@bravo,'')) AS [bravo_len],
|
|
33
|
+
LEN(ISNULL(@bravo,'')) * ISNULL(@alpha,0) AS [alpha_bravo],
|
|
34
|
+
CONVERT(FLOAT, LEN(ISNULL(@bravo, ''))) / 100.0 AS [bravo_len_pct],
|
|
35
|
+
CONVERT(BIT, CASE
|
|
36
|
+
WHEN @alpha > 25 THEN 1
|
|
37
|
+
ELSE 0
|
|
38
|
+
END) AS [alpha_gt_25],
|
|
39
|
+
ISNULL(@alpha,0) AS [alpha],
|
|
40
|
+
ISNULL(@bravo,'') AS [bravo],
|
|
41
|
+
ISNULL(@charlie, GETDATE()) AS [charlie]
|
|
42
|
+
EOSQL
|
|
43
|
+
|
|
44
|
+
MY_TEST_FUNCTION_PARAMS = {
|
|
45
|
+
:alpha=>{:type=>:integer, :data_type=>'integer'},
|
|
46
|
+
:bravo=>{:type=>:string, :data_type=>'varchar(100)'},
|
|
47
|
+
:charlie=>{:type=>:datetime, :data_type=>'datetime'}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
MY_TEST_FUNCTION_COLUMNS = [
|
|
51
|
+
{:name=>'bravo_len', :key=>:bravo_len, :data_type=>'int', :type=>:integer},
|
|
52
|
+
{:name=>'alpha_bravo', :key=>:alpha_bravo, :data_type=>'int', :type=>:integer},
|
|
53
|
+
{:name=>'bravo_len_pct', :key=>:bravo_len_pct, :data_type=>'float', :type=>:float},
|
|
54
|
+
{:name=>'alpha_gt_25', :key=>:alpha_gt_25, :data_type=>'bit', :type=>:boolean},
|
|
55
|
+
{:name=>'alpha', :key=>:alpha, :data_type=>'int', :type=>:integer},
|
|
56
|
+
{:name=>'bravo', :key=>:bravo, :data_type=>'varchar(100)', :type=>:string, :length=>100},
|
|
57
|
+
{:name=>'charlie', :key=>:charlie, :data_type=>'datetime', :type=>:datetime}
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
test 'ms sql function parsing' do
|
|
61
|
+
begin
|
|
62
|
+
MyTestFunctionParentTable.establish_connection BarkestCore.db_config(:ms_sql_test)
|
|
63
|
+
# set the connection handler
|
|
64
|
+
MyTestFunction.use_connection MyTestFunctionParentTable
|
|
65
|
+
# create the UDF
|
|
66
|
+
MyTestFunction.connection.execute MY_TEST_FUNCTION_DEFINITION
|
|
67
|
+
rescue Exception => e
|
|
68
|
+
MyTestFunctionParentTable.remove_connection
|
|
69
|
+
skip "Invalid test MSSQL configuration: #{e.message}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
begin
|
|
73
|
+
# parse the function
|
|
74
|
+
MyTestFunction.function_name = MY_TEST_FUNCTION_NAME
|
|
75
|
+
|
|
76
|
+
# params should match up.
|
|
77
|
+
MyTestFunction.parameters.each do |param_key, param_attrib|
|
|
78
|
+
valid = MY_TEST_FUNCTION_PARAMS[param_key]
|
|
79
|
+
assert_not_nil valid, "Function has extra #{param_key} parameter."
|
|
80
|
+
assert_equal valid[:type], param_attrib[:type], "Parameter #{param_key} has the wrong type."
|
|
81
|
+
assert_equal valid[:data_type], param_attrib[:data_type], "Parameter #{param_key} has the wrong data_type."
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
MY_TEST_FUNCTION_PARAMS.each do |param_key, _|
|
|
85
|
+
assert_not_nil MyTestFunction.parameters[param_key], "Function is missing #{param_key} parameter."
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# columns should match up.
|
|
89
|
+
MyTestFunction.columns.each do |attribs|
|
|
90
|
+
valid = MY_TEST_FUNCTION_COLUMNS.find{|v| v[:name] == attribs[:name]}
|
|
91
|
+
assert_not_nil valid, "Function has extra #{attribs[:name]} column."
|
|
92
|
+
assert_equal valid[:key], attribs[:key], "Column #{attribs[:name]} has the wrong key."
|
|
93
|
+
assert_equal valid[:data_type], attribs[:data_type], "Column #{attribs[:name]} has the wrong data type."
|
|
94
|
+
assert_equal valid[:type], attribs[:type], "Column #{attribs[:name]} has the wrong type."
|
|
95
|
+
if valid[:length]
|
|
96
|
+
assert_equal valid[:length], attribs[:length], "Column #{attribs[:name]} has the wrong length."
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
MY_TEST_FUNCTION_COLUMNS.each do |valid|
|
|
101
|
+
col = MyTestFunction.columns.find{|v| v[:name] == valid[:name]}
|
|
102
|
+
assert_not_nil col, "Function is missing #{valid[:name]} column."
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# and then tests.
|
|
106
|
+
[
|
|
107
|
+
[10, 'Hello', 5.days.ago],
|
|
108
|
+
[61, 'Some test text to test with!', Time.zone.now + 5.days]
|
|
109
|
+
].each do |(alpha, bravo, charlie)|
|
|
110
|
+
|
|
111
|
+
result = MyTestFunction.select(alpha: alpha, bravo: bravo, charlie: charlie)
|
|
112
|
+
|
|
113
|
+
assert_not_nil result
|
|
114
|
+
assert_equal 1, result.count
|
|
115
|
+
result = result.first
|
|
116
|
+
|
|
117
|
+
assert_equal bravo.length, result.bravo_len
|
|
118
|
+
assert_equal alpha * bravo.length, result.alpha_bravo
|
|
119
|
+
assert_equal bravo.length * 0.01, result.bravo_len_pct
|
|
120
|
+
assert_equal alpha > 25, result.alpha_gt_25?
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
ensure
|
|
124
|
+
MyTestFunction.connection.execute "DROP FUNCTION #{MY_TEST_FUNCTION_NAME}"
|
|
125
|
+
MyTestFunctionParentTable.remove_connection
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
class NumberParserTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
test 'should parse valid numbers' do
|
|
7
|
+
{
|
|
8
|
+
'0' => 0.0, '123' => 123.0, '123.4' => 123.4, '12345' => 12345.0, '12,345' => 12345.0, '12,345.678' => 12345.678, '1,234,567' => 1234567.0,
|
|
9
|
+
'-123' => -123.0, '-123.4' => -123.4, '-12345' => -12345.0, '-12,345' => -12345.0, '-12,345.678' => -12345.678, '-1,234,567' => -1234567.0,
|
|
10
|
+
'+123' => 123.0, '+123.4' => 123.4, '+12345' => 12345.0, '+12,345' => 12345.0, '+12,345.678' => 12345.678, '+1,234,567' => 1234567.0,
|
|
11
|
+
}.each do |k,v|
|
|
12
|
+
assert_equal v, BarkestCore::NumberParser.parse_for_float_column(k), "#{k} should be a valid float"
|
|
13
|
+
assert_equal v.to_i, BarkestCore::NumberParser.parse_for_int_column(k), "#{k} should be a valid int"
|
|
14
|
+
assert_equal v, BarkestCore::NumberParser.parse_for_float_filter(k).to_f, "#{k} should be a valid float filter"
|
|
15
|
+
assert_equal v.to_i, BarkestCore::NumberParser.parse_for_int_filter(k).to_i, "#{k} should be a valid int filter"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'should parse nil values' do
|
|
20
|
+
[ nil, '', ' ' ].each do |v|
|
|
21
|
+
assert_nil BarkestCore::NumberParser.parse_for_float_column(v), "#{v.inspect} should not be a valid float"
|
|
22
|
+
assert_nil BarkestCore::NumberParser.parse_for_int_column(v), "#{v.inspect} should not be a valid int"
|
|
23
|
+
assert_equal "NULL", BarkestCore::NumberParser.parse_for_float_filter(v), "#{v.inspect} should be a NULL float filter"
|
|
24
|
+
assert_equal "NULL", BarkestCore::NumberParser.parse_for_int_filter(v), "#{v.inspect} should be a NULL int filter"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
class SelfUpdateConfigTest < ActiveSupport::TestCase
|
|
3
|
+
|
|
4
|
+
def setup
|
|
5
|
+
@item = BarkestCore::SelfUpdateConfig.new(
|
|
6
|
+
host: '127.0.0.1',
|
|
7
|
+
user: 'somebody',
|
|
8
|
+
password: 'secret',
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'should be valid' do
|
|
13
|
+
assert @item.valid?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'should require host' do
|
|
17
|
+
assert_required @item, :host
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'should require user' do
|
|
21
|
+
assert_required @item, :user
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test 'should require password' do
|
|
25
|
+
assert_required @item, :password
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
module BarkestCore
|
|
3
|
+
class UserAlertTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@item = BarkestCore::UserAlert.new(message: 'Something you need to know.')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test 'should be valid' do
|
|
10
|
+
assert @item.valid?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test 'should require message' do
|
|
14
|
+
assert_required @item, :message
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
module BarkestCore
|
|
3
|
+
class UserManagerTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@user = users(:standard)
|
|
7
|
+
@cfg = BarkestCore.auth_config
|
|
8
|
+
@db_only = BarkestCore::UserManager.new(@cfg.merge({enable_ldap_auth: false, enable_db_auth: true}))
|
|
9
|
+
@ldap_only = @cfg[:enable_ldap_auth] ? BarkestCore::UserManager.new(@cfg.merge({enable_db_auth: false})) : nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'should be able to authenticate with default admin for db-only' do
|
|
13
|
+
assert @db_only.authenticate( @user.email, 'password', '0.0.0.0' )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'should not be able to authenticate with default admin for ldap-only' do
|
|
17
|
+
skip 'LDAP not configured.' unless @ldap_only
|
|
18
|
+
assert_not @ldap_only.authenticate( 'admin@barkerest.com', 'Password1', '0.0.0.0' )
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'should be able to login with test credentials for ldap-only' do
|
|
22
|
+
skip 'LDAP not configured.' unless @ldap_only
|
|
23
|
+
skip 'Missing :ldap_test_email or :ldap_ldap_password configuration.' if @cfg[:ldap_test_email].blank? || @cfg[:ldap_test_password].blank?
|
|
24
|
+
assert @ldap_only.authenticate(@cfg[:ldap_test_email], @cfg[:ldap_test_password], '0.0.0.0' )
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'should not be able to login with test credentials for db-only' do
|
|
28
|
+
skip 'LDAP not configured.' unless @ldap_only
|
|
29
|
+
skip 'Missing :ldap_test_email or :ldap_test_password configuration.' if @cfg[:ldap_test_email].blank? || @cfg[:ldap_test_password].blank?
|
|
30
|
+
assert_not @db_only.authenticate(@cfg[:ldap_test_email], @cfg[:ldap_test_password], '0.0.0.0' )
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
class WorkPathTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
test 'should get a valid location' do
|
|
7
|
+
assert_not_nil BarkestCore::WorkPath.location
|
|
8
|
+
assert Dir.exist?(BarkestCore::WorkPath.location)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'should get valid path for temp file' do
|
|
12
|
+
path = BarkestCore::WorkPath.path_for('test.file')
|
|
13
|
+
assert_not_nil path
|
|
14
|
+
|
|
15
|
+
# we should be able to write and delete the test file successfully.
|
|
16
|
+
# ironically, this is the same code used in the WorkPath class
|
|
17
|
+
# to verify the path is usable, which makes this redundant, but
|
|
18
|
+
# testing is supposed to be thorough, so I'm leaving it in place.
|
|
19
|
+
File.write path, 'This is a test.'
|
|
20
|
+
File.delete path
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DisableUserTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@user = users(:user_5)
|
|
7
|
+
@item = DisableUser.new(user: @user, reason: 'Some valid reason')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test 'should be valid' do
|
|
11
|
+
assert @item.valid?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'should require reason' do
|
|
15
|
+
assert_required @item, :reason
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'should require user' do
|
|
19
|
+
assert_required @item, :user
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test 'user must be enabled' do
|
|
23
|
+
@user.enabled = false
|
|
24
|
+
assert_not @item.valid?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class GenericTimeTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test 'should handle time objects' do
|
|
6
|
+
[
|
|
7
|
+
Time.utc(2016, 12, 19, 15, 45),
|
|
8
|
+
Time.new(2016, 12, 19, 15, 45),
|
|
9
|
+
Time.new,
|
|
10
|
+
Time.zone.now,
|
|
11
|
+
Time.zone.local(2016, 12, 19, 15, 45),
|
|
12
|
+
Date.today,
|
|
13
|
+
].each do |item|
|
|
14
|
+
assert_equal item.to_time.utc, Time.utc_parse(item), "Item #{item.inspect} does not parse to #{item.to_time.utc.inspect}."
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'should handle ISO formatted strings' do
|
|
19
|
+
{
|
|
20
|
+
'2016-12-19' => Time.utc(2016, 12, 19),
|
|
21
|
+
'2016-12-19 15:45' => Time.utc(2016, 12, 19, 15, 45),
|
|
22
|
+
'2016-12-19 15:45:15' => Time.utc(2016, 12, 19, 15, 45, 15),
|
|
23
|
+
'2016-12-19 15:45 -500' => Time.utc(2016, 12, 19, 20, 45),
|
|
24
|
+
'2016-12-19 15:45 -0500' => Time.utc(2016, 12, 19, 20, 45),
|
|
25
|
+
'2016-12-19 15:45 -05:00' => Time.utc(2016, 12, 19, 20, 45),
|
|
26
|
+
'2016-12-19 20:45 +500' => Time.utc(2016, 12, 19, 15, 45),
|
|
27
|
+
'2016-12-19 20:45 +0500' => Time.utc(2016, 12, 19, 15, 45),
|
|
28
|
+
'2016-12-19 20:45 +05:00' => Time.utc(2016, 12, 19, 15, 45),
|
|
29
|
+
'2016-12-19 20:45 UTC' => Time.utc(2016, 12, 19, 20, 45),
|
|
30
|
+
}.each do |key, val|
|
|
31
|
+
assert_equal val, Time.utc_parse(key), "Item #{key} does not parse to #{val.inspect}."
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test 'should handle other select formats' do
|
|
36
|
+
{
|
|
37
|
+
'16-12-19' => Time.utc(2016, 12, 19),
|
|
38
|
+
'12/19/16' => Time.utc(2016, 12, 19),
|
|
39
|
+
'12/19/2016' => Time.utc(2016, 12, 19),
|
|
40
|
+
'12/19' => Time.utc(Time.now.utc.year, 12, 19),
|
|
41
|
+
'1219' => Time.utc(Time.now.utc.year, 12, 19),
|
|
42
|
+
'121916' => Time.utc(2016, 12, 19),
|
|
43
|
+
'12192016' => Time.utc(2016, 12, 19),
|
|
44
|
+
'12/19/16 15:45' => Time.utc(2016, 12, 19, 15, 45),
|
|
45
|
+
'12/19/16 3:45pm' => Time.utc(2016, 12, 19, 15, 45),
|
|
46
|
+
'12/19/16 3:45 pm' => Time.utc(2016, 12, 19, 15, 45),
|
|
47
|
+
'12/19/16 3:45 pm -500' => Time.utc(2016, 12, 19, 20, 45),
|
|
48
|
+
'12/19/16 12 am' => Time.utc(2016, 12, 19, 0, 0),
|
|
49
|
+
'12/19/16 12 pm' => Time.utc(2016, 12, 19, 12, 0),
|
|
50
|
+
'12/19/16 3 am' => Time.utc(2016, 12, 19, 3, 0),
|
|
51
|
+
'12/19/16 3 pm' => Time.utc(2016, 12, 19, 15, 0),
|
|
52
|
+
'15:45:30' => Time.utc(1900, 1, 1, 15, 45, 30),
|
|
53
|
+
'15:45:30 -500' => Time.utc(1900, 1, 1, 20, 45, 30),
|
|
54
|
+
'12' => Time.utc(1900, 1, 1, 12, 0),
|
|
55
|
+
'12am' => Time.utc(1900, 1, 1, 0, 0),
|
|
56
|
+
'12 am' => Time.utc(1900, 1, 1, 0, 0),
|
|
57
|
+
'12PM' => Time.utc(1900, 1, 1, 12, 0),
|
|
58
|
+
'12 PM -500' => Time.utc(1900, 1, 1, 17, 0),
|
|
59
|
+
'3:45 pm' => Time.utc(1900, 1, 1, 15, 45),
|
|
60
|
+
'3:45 pm -05:00' => Time.utc(1900, 1, 1, 20, 45),
|
|
61
|
+
}.each do |key, val|
|
|
62
|
+
assert_equal val, Time.utc_parse(key), "Item #{key} does not parse to #{val.inspect}."
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class LdapAccessGroupTest < ActiveSupport::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@item = LdapAccessGroup.new(
|
|
6
|
+
group: access_groups(:two),
|
|
7
|
+
name: 'Ldap Group 2'
|
|
8
|
+
)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'should be valid' do
|
|
12
|
+
assert @item.valid?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test 'should require group' do
|
|
16
|
+
assert_required @item, :group
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'should require name' do
|
|
20
|
+
assert_required @item, :name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'name should not be too long' do
|
|
24
|
+
assert_max_length @item, :name, 200
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'name should be unique' do
|
|
28
|
+
assert_uniqueness @item, :name, :group => access_groups(:three)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class SystemConfigTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
TEST_VALUES = [
|
|
6
|
+
'world',
|
|
7
|
+
:world,
|
|
8
|
+
1234,
|
|
9
|
+
56.789,
|
|
10
|
+
true,
|
|
11
|
+
false,
|
|
12
|
+
[ 1, 2, 3 ],
|
|
13
|
+
{a: 1, b: 2, c: 3},
|
|
14
|
+
Time.now
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
def setup
|
|
18
|
+
@item = SystemConfig.new(key: 'hello')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'should be valid' do
|
|
22
|
+
assert @item.valid?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'should allow setting value to various types' do
|
|
26
|
+
TEST_VALUES.each do |test_value|
|
|
27
|
+
@item.value = test_value
|
|
28
|
+
@item.save!
|
|
29
|
+
assert_equal test_value, @item.value
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'should require key' do
|
|
34
|
+
assert_required @item, :key
|
|
35
|
+
assert_not SystemConfig.set('', '')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'key should not be too long' do
|
|
39
|
+
assert_max_length @item, :key, 128
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'key should be unique' do
|
|
43
|
+
assert_uniqueness @item, :key
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test 'get and set should support encryption' do
|
|
47
|
+
TEST_VALUES.each do |test_value|
|
|
48
|
+
SystemConfig.set 'abc', test_value, true
|
|
49
|
+
test = SystemConfig.find_by(key: 'abc')
|
|
50
|
+
|
|
51
|
+
assert_not_nil test
|
|
52
|
+
|
|
53
|
+
assert_not_equal test_value, test.value
|
|
54
|
+
assert_equal test_value, SystemConfig.get('abc')
|
|
55
|
+
|
|
56
|
+
assert test.value.is_a?(Hash)
|
|
57
|
+
assert test.value.keys.include?(:encrypted_value)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'get and set methods should work' do
|
|
62
|
+
TEST_VALUES.each do |test_value|
|
|
63
|
+
SystemConfig.set 'abc', test_value
|
|
64
|
+
SystemConfig.set 'Xyz', test_value
|
|
65
|
+
assert_equal test_value, SystemConfig.get('abc')
|
|
66
|
+
assert_equal test_value, SystemConfig.get('xyz')
|
|
67
|
+
assert_equal test_value, SystemConfig.get('ABC')
|
|
68
|
+
assert_equal test_value, SystemConfig.get('XYZ')
|
|
69
|
+
end
|
|
70
|
+
SystemConfig.set 'abc', nil
|
|
71
|
+
SystemConfig.set 'Xyz', nil
|
|
72
|
+
assert_nil SystemConfig.get('abc')
|
|
73
|
+
assert_nil SystemConfig.get('xyz')
|
|
74
|
+
assert_nil SystemConfig.get('ABC')
|
|
75
|
+
assert_nil SystemConfig.get('XYZ')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|