incline 0.1.5
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 +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,267 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'cgi/util'
|
|
3
|
+
|
|
4
|
+
class ActionViewBaseExtensionsTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
class TestModel
|
|
7
|
+
def errors
|
|
8
|
+
@errors ||= TestErrors.new
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class TestErrors
|
|
13
|
+
def any?
|
|
14
|
+
true
|
|
15
|
+
end
|
|
16
|
+
def count
|
|
17
|
+
10
|
|
18
|
+
end
|
|
19
|
+
def full_messages
|
|
20
|
+
@full_messages ||= (1..10).to_a.map{ |v| "This is error ##{v}." }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def setup
|
|
26
|
+
@view = ActionView::Base.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'should have extension methods' do
|
|
30
|
+
assert @view.respond_to?(:full_title)
|
|
31
|
+
assert @view.respond_to?(:show_check_if)
|
|
32
|
+
assert @view.respond_to?(:glyph)
|
|
33
|
+
assert @view.respond_to?(:render_alert)
|
|
34
|
+
assert @view.respond_to?(:error_summary)
|
|
35
|
+
assert @view.respond_to?(:fmt_date)
|
|
36
|
+
assert @view.respond_to?(:fmt_num)
|
|
37
|
+
assert @view.respond_to?(:gravatar_for)
|
|
38
|
+
assert @view.respond_to?(:panel)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'full_title should work as expected' do
|
|
42
|
+
app_name = Rails.application.app_name.strip
|
|
43
|
+
assert_equal app_name, @view.full_title
|
|
44
|
+
assert_equal "Hello World | #{app_name}", @view.full_title('Hello World')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test 'show_check_if should work as expected' do
|
|
48
|
+
# false should be nil.
|
|
49
|
+
assert_nil @view.show_check_if(false)
|
|
50
|
+
assert_nil @view.show_check_if(nil)
|
|
51
|
+
|
|
52
|
+
# true should not be nil.
|
|
53
|
+
expected = '<i class="glyphicon glyphicon-ok glyphicon-small"></i>'
|
|
54
|
+
val = @view.show_check_if(true)
|
|
55
|
+
assert_not val.blank?
|
|
56
|
+
assert_equal expected, val
|
|
57
|
+
assert val.html_safe?
|
|
58
|
+
|
|
59
|
+
# values that convert to true should also work.
|
|
60
|
+
assert_equal val, @view.show_check_if(:true)
|
|
61
|
+
assert_equal val, @view.show_check_if('true')
|
|
62
|
+
assert_equal val, @view.show_check_if('yes')
|
|
63
|
+
assert_equal val, @view.show_check_if('1')
|
|
64
|
+
assert_equal val, @view.show_check_if(1)
|
|
65
|
+
|
|
66
|
+
# and those that convert to false should be nil
|
|
67
|
+
assert_nil @view.show_check_if(:false)
|
|
68
|
+
assert_nil @view.show_check_if('false')
|
|
69
|
+
assert_nil @view.show_check_if('no')
|
|
70
|
+
assert_nil @view.show_check_if('0')
|
|
71
|
+
assert_nil @view.show_check_if(0)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test 'glyph should work as expected' do
|
|
75
|
+
# blank values should return nil.
|
|
76
|
+
assert_nil @view.glyph(nil)
|
|
77
|
+
assert_nil @view.glyph('')
|
|
78
|
+
assert_nil @view.glyph(' ')
|
|
79
|
+
|
|
80
|
+
expected = '<i class="glyphicon glyphicon-ok"></i>'
|
|
81
|
+
assert_equal expected, @view.glyph(:ok)
|
|
82
|
+
assert_equal expected, @view.glyph('ok')
|
|
83
|
+
assert_equal expected, @view.glyph(' ok ')
|
|
84
|
+
assert_equal expected, @view.glyph(:ok, :normal) # invalid size
|
|
85
|
+
assert_equal expected, @view.glyph(:ok, :big) # invalid size
|
|
86
|
+
assert_equal expected, @view.glyph(:ok, :tiny) # invalid size
|
|
87
|
+
|
|
88
|
+
expected = '<i class="glyphicon glyphicon-cloud glyphicon-small"></i>'
|
|
89
|
+
assert_equal expected, @view.glyph(:cloud, :small)
|
|
90
|
+
assert_equal expected, @view.glyph('cloud', 'small')
|
|
91
|
+
assert_equal expected, @view.glyph(:cloud, 'sm')
|
|
92
|
+
assert_equal expected, @view.glyph('cloud', :sm)
|
|
93
|
+
|
|
94
|
+
expected = '<i class="glyphicon glyphicon-remove glyphicon-large"></i>'
|
|
95
|
+
assert_equal expected, @view.glyph(:remove, :large)
|
|
96
|
+
assert_equal expected, @view.glyph(:remove, 'lg')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
test 'fmt_date should work as expected' do
|
|
100
|
+
assert_nil @view.fmt_date(nil)
|
|
101
|
+
assert_nil @view.fmt_date('')
|
|
102
|
+
assert_nil @view.fmt_date(' ')
|
|
103
|
+
|
|
104
|
+
# test the string formats.
|
|
105
|
+
assert_equal '1/1/2017', @view.fmt_date('1/1/2017')
|
|
106
|
+
assert_equal '12/31/2017', @view.fmt_date('12/31/2017')
|
|
107
|
+
assert_equal '1/1/2017', @view.fmt_date('2017-01-01')
|
|
108
|
+
assert_equal '12/31/2017', @view.fmt_date('2017-12-31')
|
|
109
|
+
assert_equal '1/1/2017', @view.fmt_date('2017-1-1 12:30 PM')
|
|
110
|
+
assert_equal '12/31/2017', @view.fmt_date('12/31/2017 12:30 PM')
|
|
111
|
+
|
|
112
|
+
val = Time.parse('2016-05-08')
|
|
113
|
+
assert_equal '5/8/2016', @view.fmt_date(val)
|
|
114
|
+
|
|
115
|
+
val = Date.new(2016,12,31)
|
|
116
|
+
assert_equal '12/31/2016', @view.fmt_date(val)
|
|
117
|
+
|
|
118
|
+
val = Time.parse('2016-12-31 23:00:00 -04:00')
|
|
119
|
+
assert_equal '12/31/2016', @view.fmt_date(val)
|
|
120
|
+
assert_equal '1/1/2017', @view.fmt_date(val.utc)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
test 'fmt_num should work as expected' do
|
|
124
|
+
assert_nil @view.fmt_num(nil)
|
|
125
|
+
assert_nil @view.fmt_num('')
|
|
126
|
+
assert_nil @view.fmt_num(' ')
|
|
127
|
+
|
|
128
|
+
assert_equal '0.00', @view.fmt_num(0)
|
|
129
|
+
assert_equal '0.00', @view.fmt_num('0')
|
|
130
|
+
|
|
131
|
+
assert_equal '1.50', @view.fmt_num(1.499997)
|
|
132
|
+
assert_equal '123.45', @view.fmt_num('123.450678')
|
|
133
|
+
|
|
134
|
+
assert_equal '150', @view.fmt_num(150, 0)
|
|
135
|
+
assert_equal '123', @view.fmt_num(123.456, 0)
|
|
136
|
+
|
|
137
|
+
assert_equal '1.0000', @view.fmt_num(1, 4)
|
|
138
|
+
assert_equal '123.4567', @view.fmt_num(123.4567, 4)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
test 'render_alert accepts valid alert types' do
|
|
142
|
+
{
|
|
143
|
+
:success => :success,
|
|
144
|
+
:info => :info,
|
|
145
|
+
:warning => :warning,
|
|
146
|
+
:danger => :danger,
|
|
147
|
+
:notice => :info,
|
|
148
|
+
:alert => :danger,
|
|
149
|
+
:error => :danger,
|
|
150
|
+
:warn => :warning,
|
|
151
|
+
:safe_success => :success,
|
|
152
|
+
:safe_info => :info,
|
|
153
|
+
:safe_warning => :warning,
|
|
154
|
+
:safe_danger => :danger,
|
|
155
|
+
:safe_notice => :info,
|
|
156
|
+
:safe_alert => :danger,
|
|
157
|
+
:safe_error => :danger,
|
|
158
|
+
:safe_warn => :warning
|
|
159
|
+
}.each do |type, klass|
|
|
160
|
+
expected = "<div class=\"alert alert-#{klass} alert-dismissible\">" +
|
|
161
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
162
|
+
'<span>Hello World</span>' +
|
|
163
|
+
'</div>'
|
|
164
|
+
assert_equal expected, @view.render_alert(type, 'Hello World'), "Mismatch for #{type.inspect}"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
test 'render_alert converts invalid alert types to info' do
|
|
169
|
+
[
|
|
170
|
+
:good, :not_good, :fatal, :information, :xyz
|
|
171
|
+
].each do |type|
|
|
172
|
+
expected = '<div class="alert alert-info alert-dismissible">' +
|
|
173
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
174
|
+
'<span>Hello World</span>' +
|
|
175
|
+
'</div>'
|
|
176
|
+
assert_equal expected, @view.render_alert(type, 'Hello World')
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
test 'render_alert supports simple markdown' do
|
|
181
|
+
expected = '<div class="alert alert-info alert-dismissible">' +
|
|
182
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
183
|
+
'<span><strong>Hello</strong> World</span>' +
|
|
184
|
+
'</div>'
|
|
185
|
+
assert_equal expected, @view.render_alert(:info, '__Hello__ World')
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
test 'render_alert handles arrays correctly' do
|
|
189
|
+
expected = '<div class="alert alert-info alert-dismissible">' +
|
|
190
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
191
|
+
'<span>Line 1</span><br>' +
|
|
192
|
+
'<span>Line 2</span>' +
|
|
193
|
+
'</div>'
|
|
194
|
+
assert_equal expected, @view.render_alert(:info, [ 'Line 1', 'Line 2' ])
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
test 'render_alert handles hashes correctly' do
|
|
198
|
+
expected = '<div class="alert alert-danger alert-dismissible">' +
|
|
199
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
200
|
+
'<div>Name<ul><li>cannot be blank</li><li>must be unique</li></ul></div>' +
|
|
201
|
+
'<div>Age<ul><li>must be greater than 18</li></ul></div>' +
|
|
202
|
+
'</div>'
|
|
203
|
+
assert_equal expected, @view.render_alert(:error, { :name => [ 'cannot be blank', 'must be unique' ], :age => 'must be greater than 18' })
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
test 'render_alert handles mixed message correctly' do
|
|
207
|
+
expected = '<div class="alert alert-danger alert-dismissible">' +
|
|
208
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
209
|
+
'<span><strong>The model could not be saved.</strong></span><br>' +
|
|
210
|
+
'<div>Name<ul><li>cannot be blank</li><li>must be unique</li></ul></div>' +
|
|
211
|
+
'<div>Age<ul><li>must be greater than 18</li></ul></div>' +
|
|
212
|
+
'</div>'
|
|
213
|
+
assert_equal expected, @view.render_alert(:error, [ '__The model could not be saved.__', { :name => [ 'cannot be blank', 'must be unique' ], :age => 'must be greater than 18' } ])
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
test 'render_alert safe vs unsafe test' do
|
|
217
|
+
|
|
218
|
+
text = 'This is <em>my</em> test value ☺<br>There is <strong>nothing</strong> you can do about it.'
|
|
219
|
+
safe_text = CGI::escape_html(text)
|
|
220
|
+
|
|
221
|
+
expected = '<div class="alert alert-info alert-dismissible">' +
|
|
222
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
223
|
+
"<span>#{safe_text}</span>" +
|
|
224
|
+
'</div>'
|
|
225
|
+
assert_equal expected, @view.render_alert(:info, text)
|
|
226
|
+
|
|
227
|
+
expected = '<div class="alert alert-info alert-dismissible">' +
|
|
228
|
+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
|
229
|
+
"<span>#{text}</span>" +
|
|
230
|
+
'</div>'
|
|
231
|
+
assert_equal expected, @view.render_alert(:safe_info, text)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
test 'error_summary should work as expected' do
|
|
235
|
+
expected = "<div id=\"error_explanation\"><div class=\"alert alert-danger\">" +
|
|
236
|
+
"<div><strong>The form contains 10 errors.</strong><ul>" +
|
|
237
|
+
"<li>This is error #1.</li><li>This is error #2.</li><li>This is error #3.</li><li>This is error #4.</li>" +
|
|
238
|
+
"<li>This is error #5.</li>" +
|
|
239
|
+
"<li class=\"alert_52444_show\"><a href=\"javascript:show_alert_52444()\" title=\"Show 5 more\">... plus 5 more</a></li>" +
|
|
240
|
+
"<li class=\"alert_52444\" style=\"display: none;\">This is error #6.</li>" +
|
|
241
|
+
"<li class=\"alert_52444\" style=\"display: none;\">This is error #7.</li>" +
|
|
242
|
+
"<li class=\"alert_52444\" style=\"display: none;\">This is error #8.</li>" +
|
|
243
|
+
"<li class=\"alert_52444\" style=\"display: none;\">This is error #9.</li>" +
|
|
244
|
+
"<li class=\"alert_52444\" style=\"display: none;\">This is error #10.</li>" +
|
|
245
|
+
"</ul></div>" +
|
|
246
|
+
"<script type=\"text/javascript\">\n<![CDATA[\nfunction show_alert_52444() { $('.alert_52444_show').hide(); $('.alert_52444').show(); }\n\n]]>\n</script>\n" +
|
|
247
|
+
"</div></div>"
|
|
248
|
+
|
|
249
|
+
val = @view.error_summary(TestModel.new)
|
|
250
|
+
|
|
251
|
+
assert val
|
|
252
|
+
assert val =~ /show_alert_([0-9a-fA-F]{5})\(\)/
|
|
253
|
+
id = $1
|
|
254
|
+
expected = expected.gsub('52444', id)
|
|
255
|
+
|
|
256
|
+
assert_equal expected, val
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
test 'gravatar_for should work as expected' do
|
|
260
|
+
# TODO: Fill in test.
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
test 'panel should work as expected' do
|
|
264
|
+
# TODO: Fill in test.
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ActiveRecordExtensionsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
TEST_TABLE_NAME = "test_table_#{SecureRandom.random_number(1<<16).to_s(16).rjust(4,'0')}"
|
|
6
|
+
TEST_TABLE_CLASS = TEST_TABLE_NAME.classify.to_sym
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
# Create a test table.
|
|
10
|
+
silence_stream STDOUT do
|
|
11
|
+
ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
|
|
12
|
+
t.string :name
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# And then create a test model.
|
|
17
|
+
eval <<-EOM
|
|
18
|
+
class #{TEST_TABLE_CLASS} < ActiveRecord::Base
|
|
19
|
+
self.table_name = #{TEST_TABLE_NAME.inspect}
|
|
20
|
+
end
|
|
21
|
+
EOM
|
|
22
|
+
|
|
23
|
+
# Store the model class for use.
|
|
24
|
+
@model_class = self.class.const_get TEST_TABLE_CLASS
|
|
25
|
+
|
|
26
|
+
# Add a few records just to have something to play with.
|
|
27
|
+
@model_class.create name: 'Item 1'
|
|
28
|
+
@model_class.create name: 'Item 2'
|
|
29
|
+
@model_class.create name: 'Item 3'
|
|
30
|
+
@model_class.create name: 'Item 2' # one duplicate name...
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def teardown
|
|
34
|
+
# Undefine the model class (or at least remove it from the Object namespace).
|
|
35
|
+
self.class.send :remove_const, TEST_TABLE_CLASS
|
|
36
|
+
|
|
37
|
+
# Remove the table from the database.
|
|
38
|
+
silence_stream STDOUT do
|
|
39
|
+
ActiveRecord::Migration::drop_table TEST_TABLE_NAME
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test 'has extension methods' do
|
|
44
|
+
assert @model_class.respond_to?(:get_id)
|
|
45
|
+
assert @model_class.respond_to?(:get)
|
|
46
|
+
assert @model_class.respond_to?('[]')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'to_s and inspect are overridden' do
|
|
50
|
+
item = @model_class.first
|
|
51
|
+
assert_equal item.name, item.to_s
|
|
52
|
+
assert_equal "#<#{item.class}:#{item.object_pointer} #{item.to_s}>", item.inspect
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'get_id returns ids' do
|
|
56
|
+
item = @model_class.first
|
|
57
|
+
# recognize a model and return the ID.
|
|
58
|
+
assert_equal item.id, @model_class.get_id(item)
|
|
59
|
+
|
|
60
|
+
# return the integer value unmodified.
|
|
61
|
+
assert_equal item.id, @model_class.get_id(item.id)
|
|
62
|
+
|
|
63
|
+
# recognize an integer string and return the integer value.
|
|
64
|
+
assert_equal item.id, @model_class.get_id(item.id.to_s)
|
|
65
|
+
|
|
66
|
+
# locate the item by name and return the ID.
|
|
67
|
+
assert_equal item.id, @model_class.get_id(item.name)
|
|
68
|
+
|
|
69
|
+
# do it all again with arrays.
|
|
70
|
+
assert_equal [ item.id ], @model_class.get_id([ item ])
|
|
71
|
+
assert_equal [ item.id ], @model_class.get_id([ item.id ])
|
|
72
|
+
assert_equal [ item.id ], @model_class.get_id([ item.id.to_s ])
|
|
73
|
+
assert_equal [ item.id ], @model_class.get_id([ item.name ])
|
|
74
|
+
|
|
75
|
+
# does not validate integers.
|
|
76
|
+
assert_equal 99, @model_class.get_id(99)
|
|
77
|
+
|
|
78
|
+
# Searches by :code and :name attributes if the model has them.
|
|
79
|
+
# This is apparent where we are searching with the item name.
|
|
80
|
+
# However if the name doesn't match, nil should be returned.
|
|
81
|
+
assert_nil @model_class.get_id('Item 4')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
test 'get works as expected' do
|
|
85
|
+
# get() will always return an array unless there are no results.
|
|
86
|
+
# It will search by :code and :name attributes if the model has them.
|
|
87
|
+
|
|
88
|
+
# There should be two items named 'Item 2'.
|
|
89
|
+
ids = @model_class.get_id('Item 2')
|
|
90
|
+
assert_equal 2, ids.count
|
|
91
|
+
|
|
92
|
+
items = @model_class.get('Item 2')
|
|
93
|
+
assert items
|
|
94
|
+
assert_equal 2, items.count
|
|
95
|
+
assert_equal ids, items.map{|i| i.id}
|
|
96
|
+
|
|
97
|
+
items = @model_class.get(ids)
|
|
98
|
+
assert items
|
|
99
|
+
assert_equal 2, items.count
|
|
100
|
+
assert_equal ids, items.map{|i| i.id}
|
|
101
|
+
|
|
102
|
+
# There should only be one item named 'Item 3'.
|
|
103
|
+
ids = @model_class.get_id('Item 3')
|
|
104
|
+
assert ids.is_a?(::Integer)
|
|
105
|
+
|
|
106
|
+
items = @model_class.get('Item 3')
|
|
107
|
+
assert items
|
|
108
|
+
assert_equal 1, items.count
|
|
109
|
+
assert_equal ids, items.first.id
|
|
110
|
+
|
|
111
|
+
items = @model_class.get(ids)
|
|
112
|
+
assert items
|
|
113
|
+
assert_equal 1, items.count
|
|
114
|
+
assert_equal ids, items.first.id
|
|
115
|
+
|
|
116
|
+
# Should allow an array as an argument.
|
|
117
|
+
items = @model_class.get(['Item 1', 'Item 3'])
|
|
118
|
+
assert items
|
|
119
|
+
assert_equal 2, items.count
|
|
120
|
+
assert items.find{|i| i.name == 'Item 1'}
|
|
121
|
+
assert items.find{|i| i.name == 'Item 3'}
|
|
122
|
+
|
|
123
|
+
# There should be no item named 'Item 4'.
|
|
124
|
+
assert_nil @model_class.get('Item 4')
|
|
125
|
+
|
|
126
|
+
# There should be no ID of 99.
|
|
127
|
+
assert_nil @model_class.get(99)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
test '[] works as expected' do
|
|
131
|
+
# [] will always return one item if any items are found or nil if none are found.
|
|
132
|
+
# It will search by :code and :name attributes if the model has them.
|
|
133
|
+
|
|
134
|
+
# There should be two items named 'Item 2'.
|
|
135
|
+
# But [] will only return the first, sorted by ID since the name is the same.
|
|
136
|
+
ids = @model_class.get_id('Item 2')
|
|
137
|
+
assert_equal 2, ids.count
|
|
138
|
+
|
|
139
|
+
item = @model_class['Item 2']
|
|
140
|
+
assert item
|
|
141
|
+
assert_equal ids.first, item.id
|
|
142
|
+
|
|
143
|
+
# Even when an array is used for the argument, only one item will be returned.
|
|
144
|
+
item = @model_class[ids]
|
|
145
|
+
assert item
|
|
146
|
+
assert_equal ids.first, item.id
|
|
147
|
+
|
|
148
|
+
# There should only be one item named 'Item 3'.
|
|
149
|
+
id = @model_class.get_id('Item 3')
|
|
150
|
+
assert id.is_a?(::Integer)
|
|
151
|
+
|
|
152
|
+
item = @model_class['Item 3']
|
|
153
|
+
assert item
|
|
154
|
+
assert_equal id, item.id
|
|
155
|
+
|
|
156
|
+
item = @model_class[id]
|
|
157
|
+
assert item
|
|
158
|
+
assert_equal id, item.id
|
|
159
|
+
|
|
160
|
+
# Should allow an array as an argument, but only the first item will be returned.
|
|
161
|
+
item = @model_class[['Item 1', 'Item 3']]
|
|
162
|
+
assert item
|
|
163
|
+
assert_equal @model_class.get_id('Item 1'), item.id
|
|
164
|
+
|
|
165
|
+
# There should be no item named 'Item 4'.
|
|
166
|
+
assert_nil @model_class['Item 4']
|
|
167
|
+
|
|
168
|
+
# There should be no ID of 99.
|
|
169
|
+
assert_nil @model_class[99]
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ApplicationConfigurationExtensionsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test 'Rails.application.config has extension' do
|
|
6
|
+
cfg = Rails.application&.config
|
|
7
|
+
skip unless cfg
|
|
8
|
+
assert cfg.respond_to?(:incline_appconfig_original_database_configuration)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'provide default when config missing' do
|
|
12
|
+
cfg = Rails::Application::Configuration.new
|
|
13
|
+
|
|
14
|
+
# method must already be defined.
|
|
15
|
+
assert cfg.methods.include?(:incline_appconfig_original_database_configuration)
|
|
16
|
+
|
|
17
|
+
# first we'll confirm that the overridden method is getting called.
|
|
18
|
+
silence_warnings do
|
|
19
|
+
def cfg.incline_appconfig_original_database_configuration
|
|
20
|
+
raise 'Just Testing'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
cfg.database_configuration
|
|
26
|
+
assert false
|
|
27
|
+
rescue
|
|
28
|
+
assert $!.message =~ /just testing/i
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# now we'll pretend there is no configuration file.
|
|
32
|
+
silence_warnings do
|
|
33
|
+
def cfg.incline_appconfig_original_database_configuration
|
|
34
|
+
raise 'Could not load database configuration. No such file - fake/database.yml'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
db_cfg = cfg.database_configuration
|
|
39
|
+
|
|
40
|
+
assert db_cfg.is_a?(::Hash)
|
|
41
|
+
assert db_cfg['test']
|
|
42
|
+
assert db_cfg['development']
|
|
43
|
+
assert_nil db_cfg['production']
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ApplicationExtensionsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test 'should have extension methods' do
|
|
6
|
+
app = Rails.application
|
|
7
|
+
skip unless app
|
|
8
|
+
assert app.respond_to?(:running?)
|
|
9
|
+
assert app.respond_to?(:app_name)
|
|
10
|
+
assert app.respond_to?(:app_instance_name)
|
|
11
|
+
assert app.respond_to?(:app_version)
|
|
12
|
+
assert app.respond_to?(:app_company)
|
|
13
|
+
assert app.respond_to?(:app_info)
|
|
14
|
+
assert app.respond_to?(:app_copyright_year)
|
|
15
|
+
assert app.respond_to?(:app_copyright)
|
|
16
|
+
assert app.respond_to?(:restart_pending?)
|
|
17
|
+
assert app.respond_to?(:request_restart!)
|
|
18
|
+
assert app.respond_to?(:cookie_name)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# TODO: Test output of various methods.
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ConnectionAdapterExtensionsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
TEST_OBJECT_NAME = "test_object_#{SecureRandom.random_number(1<<16).to_s(16).rjust(4, '0')}"
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@conn = ActiveRecord::Base::connection
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'should have extension methods' do
|
|
12
|
+
assert @conn.respond_to?(:object_exists?)
|
|
13
|
+
assert @conn.respond_to?(:exec_sp)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'should be able to determine existence' do
|
|
17
|
+
assert_not @conn.object_exists?(TEST_OBJECT_NAME)
|
|
18
|
+
@conn.execute "CREATE TABLE #{TEST_OBJECT_NAME} ( some_value INTEGER NOT NULL )"
|
|
19
|
+
begin
|
|
20
|
+
assert @conn.object_exists?(TEST_OBJECT_NAME)
|
|
21
|
+
ensure
|
|
22
|
+
@conn.execute "DROP TABLE #{TEST_OBJECT_NAME}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test 'should be able to execute a stored proc' do
|
|
27
|
+
skip if MsSqlTestConn.skip_tests?
|
|
28
|
+
@conn = MsSqlTestConn.connection
|
|
29
|
+
|
|
30
|
+
assert_not @conn.object_exists?(TEST_OBJECT_NAME)
|
|
31
|
+
|
|
32
|
+
@conn.execute <<-EOS
|
|
33
|
+
CREATE PROCEDURE #{TEST_OBJECT_NAME}
|
|
34
|
+
@i_val INTEGER
|
|
35
|
+
AS
|
|
36
|
+
BEGIN
|
|
37
|
+
SET NOCOUNT ON;
|
|
38
|
+
DECLARE @d_val INTEGER;
|
|
39
|
+
SELECT @d_val = ISNULL(@i_val, 0) + 55;
|
|
40
|
+
RETURN @d_val;
|
|
41
|
+
END
|
|
42
|
+
EOS
|
|
43
|
+
begin
|
|
44
|
+
# It should exist now.
|
|
45
|
+
assert @conn.object_exists?(TEST_OBJECT_NAME)
|
|
46
|
+
# And it should retrieve the return value.
|
|
47
|
+
assert_equal 55, @conn.exec_sp("exec #{TEST_OBJECT_NAME} NULL")
|
|
48
|
+
assert_equal 100, @conn.exec_sp("exec #{TEST_OBJECT_NAME} 45")
|
|
49
|
+
ensure
|
|
50
|
+
@conn.execute "DROP PROCEDURE #{TEST_OBJECT_NAME}"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DateTimeValueExtensionsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
TEST_TABLE_NAME = "test_table_#{SecureRandom.random_number(1<<16).to_s(16).rjust(4,'0')}"
|
|
6
|
+
TEST_TABLE_CLASS = TEST_TABLE_NAME.classify.to_sym
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
# Create a test table.
|
|
10
|
+
silence_stream STDOUT do
|
|
11
|
+
ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
|
|
12
|
+
t.datetime :tz_value
|
|
13
|
+
t.datetime :utc_value
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# And then create a test model.
|
|
18
|
+
eval <<-EOM
|
|
19
|
+
class #{TEST_TABLE_CLASS} < ActiveRecord::Base
|
|
20
|
+
self.table_name = #{TEST_TABLE_NAME.inspect}
|
|
21
|
+
self.time_zone_aware_attributes = true
|
|
22
|
+
self.skip_time_zone_conversion_for_attributes << :utc_value
|
|
23
|
+
end
|
|
24
|
+
EOM
|
|
25
|
+
|
|
26
|
+
@backup_ar_tz = ActiveRecord::Base.default_timezone
|
|
27
|
+
@backup_tm_tz = Time.zone.name
|
|
28
|
+
ActiveRecord::Base.default_timezone = :utc
|
|
29
|
+
Time.zone = 'EST'
|
|
30
|
+
|
|
31
|
+
# Store the model class for use.
|
|
32
|
+
@model_class = self.class.const_get TEST_TABLE_CLASS
|
|
33
|
+
@item = @model_class.new
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def teardown
|
|
37
|
+
# Undefine the model class (or at least remove it from the Object namespace).
|
|
38
|
+
self.class.send :remove_const, TEST_TABLE_CLASS
|
|
39
|
+
|
|
40
|
+
# Remove the table from the database.
|
|
41
|
+
silence_stream STDOUT do
|
|
42
|
+
ActiveRecord::Migration::drop_table TEST_TABLE_NAME
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
ActiveRecord::Base.default_timezone = @backup_ar_tz
|
|
46
|
+
Time.zone = @backup_tm_tz
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'uses correct types' do
|
|
50
|
+
col = @model_class.columns.find{|c| c.name == 'tz_value'}
|
|
51
|
+
assert col
|
|
52
|
+
assert col.cast_type.is_a?(::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter)
|
|
53
|
+
col = @model_class.columns.find{|c| c.name == 'utc_value'}
|
|
54
|
+
assert col
|
|
55
|
+
assert_not col.cast_type.is_a?(::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter)
|
|
56
|
+
assert col.cast_type.is_a?(::ActiveRecord::Type::DateTime)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
test 'accepts valid values' do
|
|
60
|
+
{
|
|
61
|
+
'2016-12-31' => Time.utc(2016,12,31),
|
|
62
|
+
'12/31/2016' => Time.utc(2016,12,31),
|
|
63
|
+
'16-12-31' => Time.utc(2016,12,31),
|
|
64
|
+
'12/31/16' => Time.utc(2016,12,31),
|
|
65
|
+
'2016-12-31 1:20' => Time.utc(2016,12,31,1,20),
|
|
66
|
+
'12/31/2016 1:20' => Time.utc(2016,12,31,1,20),
|
|
67
|
+
'12/31/2016 1:20 PM' => Time.utc(2016,12,31,13,20),
|
|
68
|
+
'12/31/2016 12:20 AM' => Time.utc(2016,12,31,0,20),
|
|
69
|
+
'12/31/2016 12:20 PM' => Time.utc(2016,12,31,12,20),
|
|
70
|
+
'12/31/2016 24:00' => Time.utc(2017,1,1,0,0),
|
|
71
|
+
'2016-12-31T24:00' => Time.utc(2017,1,1,0,0),
|
|
72
|
+
'2016-12-31 24:00+01:00' => Time.utc(2016,12,31,23,0),
|
|
73
|
+
}.each do |s,v|
|
|
74
|
+
@item.utc_value = s
|
|
75
|
+
assert_equal v, @item.utc_value, "Should have accepted #{s.inspect}"
|
|
76
|
+
@item.tz_value = s
|
|
77
|
+
assert_equal v.in_time_zone, @item.tz_value, "Should have accepted #{s.inspect}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
test 'rejects invalid values' do
|
|
83
|
+
|
|
84
|
+
[
|
|
85
|
+
'',
|
|
86
|
+
' ',
|
|
87
|
+
'0000-00-00',
|
|
88
|
+
'0000-00-00 00:00:00',
|
|
89
|
+
'2016-13-31',
|
|
90
|
+
'2016-12-32',
|
|
91
|
+
'2016-02-30',
|
|
92
|
+
'2/30/2016',
|
|
93
|
+
'1/1/2017 24:01',
|
|
94
|
+
'12:30'
|
|
95
|
+
].each do |val|
|
|
96
|
+
@item.tz_value = val
|
|
97
|
+
assert_nil @item.tz_value, "Should have rejected #{val.inspect}"
|
|
98
|
+
@item.utc_value = val
|
|
99
|
+
assert_nil @item.utc_value, "Should have rejected #{val.inspect}"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|