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 DateValueExtensionsTest < 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.date :tz_value
|
13
|
+
t.date :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
|
+
# Dates should not be TZ aware.
|
51
|
+
col = @model_class.columns.find{|c| c.name == 'tz_value'}
|
52
|
+
assert col
|
53
|
+
assert_not col.cast_type.is_a?(::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter)
|
54
|
+
assert col.cast_type.is_a?(::ActiveRecord::Type::Date)
|
55
|
+
|
56
|
+
col = @model_class.columns.find{|c| c.name == 'utc_value'}
|
57
|
+
assert col
|
58
|
+
assert_not col.cast_type.is_a?(::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter)
|
59
|
+
assert col.cast_type.is_a?(::ActiveRecord::Type::Date)
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'accepts valid values' do
|
63
|
+
{
|
64
|
+
'2016-12-31' => Date.new(2016,12,31),
|
65
|
+
'12/31/2016' => Date.new(2016,12,31),
|
66
|
+
'16-12-31' => Date.new(2016,12,31),
|
67
|
+
'12/31/16' => Date.new(2016,12,31),
|
68
|
+
'1/1/2017' => Date.new(2017,1,1),
|
69
|
+
'2017-1-1' => Date.new(2017,1,1),
|
70
|
+
'01/01/2017' => Date.new(2017,1,1),
|
71
|
+
'2017-01-01' => Date.new(2017,1,1)
|
72
|
+
}.each do |s,v|
|
73
|
+
@item.utc_value = s
|
74
|
+
assert_equal v, @item.utc_value, "Should have accepted #{s.inspect}"
|
75
|
+
|
76
|
+
# Time zones should not apply to dates!
|
77
|
+
@item.tz_value = s
|
78
|
+
assert_equal v, @item.tz_value, "Should have accepted #{s.inspect}"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'rejects invalid values' do
|
84
|
+
|
85
|
+
[
|
86
|
+
'',
|
87
|
+
' ',
|
88
|
+
'0000-00-00',
|
89
|
+
'2016-13-31',
|
90
|
+
'2016-12-32',
|
91
|
+
'2016-02-30',
|
92
|
+
'2/30/2016',
|
93
|
+
].each do |val|
|
94
|
+
@item.tz_value = val
|
95
|
+
assert_nil @item.tz_value, "Should have rejected #{val.inspect}"
|
96
|
+
@item.utc_value = val
|
97
|
+
assert_nil @item.utc_value, "Should have rejected #{val.inspect}"
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DecimalValueExtensionsTest < 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.decimal :scaled_value, precision: 12, scale: 4
|
13
|
+
t.decimal :unscaled_value, precision: 12
|
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
|
+
end
|
22
|
+
EOM
|
23
|
+
|
24
|
+
# Store the model class for use.
|
25
|
+
@model_class = self.class.const_get TEST_TABLE_CLASS
|
26
|
+
@item = @model_class.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
# Undefine the model class (or at least remove it from the Object namespace).
|
31
|
+
self.class.send :remove_const, TEST_TABLE_CLASS
|
32
|
+
|
33
|
+
# Remove the table from the database.
|
34
|
+
silence_stream STDOUT do
|
35
|
+
ActiveRecord::Migration::drop_table TEST_TABLE_NAME
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'accepts valid values' do
|
40
|
+
{
|
41
|
+
'1234' => BigDecimal(1234, 12),
|
42
|
+
'1,234' => BigDecimal(1234, 12),
|
43
|
+
'12.34' => BigDecimal(12.34, 12),
|
44
|
+
'1,234.5678' => BigDecimal(1234.5678, 12),
|
45
|
+
'1234567' => BigDecimal(1234567.0, 12),
|
46
|
+
'1,234,567' => BigDecimal(1234567.0, 12),
|
47
|
+
'0' => BigDecimal(0.0, 12),
|
48
|
+
'0.0' => BigDecimal(0.0, 12),
|
49
|
+
'+125' => BigDecimal(125.0, 12),
|
50
|
+
'-125' => BigDecimal(-125.0, 12),
|
51
|
+
'+1,234' => BigDecimal(1234.0, 12),
|
52
|
+
'-1,234' => BigDecimal(-1234.0, 12)
|
53
|
+
}.each do |s,v|
|
54
|
+
@item.scaled_value = s
|
55
|
+
assert_equal v.round(4), @item.scaled_value, "#{s.inspect} did not parse to #{v}"
|
56
|
+
@item.unscaled_value = s
|
57
|
+
assert_equal v.to_i, @item.unscaled_value, "#{s.inspect} did not parse to #{v}"
|
58
|
+
end
|
59
|
+
[ 0, 1234, 567.89 ].each do |v|
|
60
|
+
@item.scaled_value = v
|
61
|
+
assert_equal BigDecimal(v, 6).round(4), @item.scaled_value
|
62
|
+
@item.unscaled_value = v
|
63
|
+
assert_equal v.to_i, @item.unscaled_value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'rejects invalid values' do
|
68
|
+
[
|
69
|
+
'',
|
70
|
+
'1,2,3,4',
|
71
|
+
',234',
|
72
|
+
'1,2345',
|
73
|
+
'0,001',
|
74
|
+
].each do |v|
|
75
|
+
@item.scaled_value = v
|
76
|
+
assert_nil @item.scaled_value
|
77
|
+
@item.unscaled_value = v
|
78
|
+
assert_nil @item.unscaled_value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ErbScaffoldGeneratorExtensionsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@gen = Erb::Generators::ScaffoldGenerator.new [ 'fake_item' ]
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should have the correct available_views' do
|
10
|
+
req = %w(index new edit show _list _form)
|
11
|
+
actual = @gen.send :available_views
|
12
|
+
req.each do |view|
|
13
|
+
assert actual.include?(view), "Missing '#{view}' view."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FloatValueExtensionsTest < 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.float :my_value
|
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
|
+
@item = @model_class.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
# Undefine the model class (or at least remove it from the Object namespace).
|
30
|
+
self.class.send :remove_const, TEST_TABLE_CLASS
|
31
|
+
|
32
|
+
# Remove the table from the database.
|
33
|
+
silence_stream STDOUT do
|
34
|
+
ActiveRecord::Migration::drop_table TEST_TABLE_NAME
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'accepts valid values' do
|
39
|
+
{
|
40
|
+
'1234' => 1234.0,
|
41
|
+
'1,234' => 1234.0,
|
42
|
+
'12.34' => 12.34,
|
43
|
+
'1,234.5678' => 1234.5678,
|
44
|
+
'1234567' => 1234567.0,
|
45
|
+
'1,234,567' => 1234567.0,
|
46
|
+
'0' => 0.0,
|
47
|
+
'0.0' => 0.0,
|
48
|
+
'+125' => 125.0,
|
49
|
+
'-125' => -125.0,
|
50
|
+
'+1,234' => 1234.0,
|
51
|
+
'-1,234' => -1234.0
|
52
|
+
}.each do |s,v|
|
53
|
+
@item.my_value = s
|
54
|
+
assert_equal v, @item.my_value, "#{s.inspect} did not parse to #{v}"
|
55
|
+
end
|
56
|
+
[ 0, 1234, 567.89 ].each do |v|
|
57
|
+
@item.my_value = v
|
58
|
+
assert_equal v.to_f, @item.my_value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'rejects invalid values' do
|
63
|
+
[
|
64
|
+
'',
|
65
|
+
'1,2,3,4',
|
66
|
+
',234',
|
67
|
+
'1,2345',
|
68
|
+
'0,001',
|
69
|
+
].each do |v|
|
70
|
+
@item.my_value = v
|
71
|
+
assert_nil @item.my_value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FormBuilderExtensionsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@builder = ActionView::Helpers::FormBuilder.new('my_object', Object.new, 'no template', { })
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should have additional methods' do
|
10
|
+
assert @builder.respond_to?(:date_picker)
|
11
|
+
assert @builder.respond_to?(:multi_input)
|
12
|
+
assert @builder.respond_to?(:currency_field)
|
13
|
+
assert @builder.respond_to?(:label_w_small)
|
14
|
+
assert @builder.respond_to?(:text_form_group)
|
15
|
+
assert @builder.respond_to?(:password_form_group)
|
16
|
+
assert @builder.respond_to?(:textarea_form_group)
|
17
|
+
assert @builder.respond_to?(:currency_form_group)
|
18
|
+
assert @builder.respond_to?(:static_form_group)
|
19
|
+
assert @builder.respond_to?(:datepicker_form_group)
|
20
|
+
assert @builder.respond_to?(:multi_input_form_group)
|
21
|
+
assert @builder.respond_to?(:check_box_form_group)
|
22
|
+
assert @builder.respond_to?(:select_form_group)
|
23
|
+
assert @builder.respond_to?(:recaptcha)
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO: Test output of various methods.
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class IntegerValueExtensionsTest < 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.integer :my_value
|
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
|
+
@item = @model_class.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
# Undefine the model class (or at least remove it from the Object namespace).
|
30
|
+
self.class.send :remove_const, TEST_TABLE_CLASS
|
31
|
+
|
32
|
+
# Remove the table from the database.
|
33
|
+
silence_stream STDOUT do
|
34
|
+
ActiveRecord::Migration::drop_table TEST_TABLE_NAME
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'accepts valid values' do
|
39
|
+
{
|
40
|
+
'1234' => 1234,
|
41
|
+
'1,234' => 1234,
|
42
|
+
'12.34' => 12,
|
43
|
+
'1,234.5678' => 1234,
|
44
|
+
'1234567' => 1234567,
|
45
|
+
'1,234,567' => 1234567,
|
46
|
+
'0' => 0,
|
47
|
+
'0.0' => 0,
|
48
|
+
'+125' => 125,
|
49
|
+
'-125' => -125,
|
50
|
+
'+1,234' => 1234,
|
51
|
+
'-1,234' => -1234
|
52
|
+
}.each do |s,v|
|
53
|
+
@item.my_value = s
|
54
|
+
assert_equal v, @item.my_value, "#{s.inspect} did not parse to #{v}"
|
55
|
+
end
|
56
|
+
[ 0, 1234, 567.89 ].each do |v|
|
57
|
+
@item.my_value = v
|
58
|
+
assert_equal v.to_i, @item.my_value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'rejects invalid values' do
|
63
|
+
[
|
64
|
+
'',
|
65
|
+
'1,2,3,4',
|
66
|
+
',234',
|
67
|
+
'1,2345',
|
68
|
+
'0,001',
|
69
|
+
].each do |v|
|
70
|
+
@item.my_value = v
|
71
|
+
assert_nil @item.my_value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class JbuilderGeneratorExtensionsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@gen = Rails::Generators::JbuilderGenerator.new [ 'fake_item' ]
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'responds to available_views' do
|
10
|
+
assert @gen.respond_to?(:available_views, true)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'should have the correct available_views' do
|
14
|
+
req = %w(index show _details)
|
15
|
+
actual = @gen.send :available_views
|
16
|
+
req.each do |view|
|
17
|
+
assert actual.include?(view), "Missing '#{view}' view."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class JbuilderTemplateExtensionsTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
class TestClass
|
7
|
+
|
8
|
+
attr_reader :errors
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@errors = {
|
12
|
+
:base => [ 'something bad happened' ],
|
13
|
+
:name => 'is too long',
|
14
|
+
:code => [ 'is not uppercase', 'is too long' ]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@json = JbuilderTemplate.new(self)
|
21
|
+
@item = TestClass.new
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'has extension methods' do
|
25
|
+
assert @json.respond_to?(:api_errors!)
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'builds expected values' do
|
29
|
+
@json.api_errors! 'test_class', @item.errors
|
30
|
+
val = JSON.parse(@json.target!)
|
31
|
+
|
32
|
+
assert val.is_a?(::Hash)
|
33
|
+
|
34
|
+
assert val['error'].is_a?(::String)
|
35
|
+
assert_equal 'Test class ' + @item.errors[:base].first, val['error']
|
36
|
+
|
37
|
+
assert val['fieldErrors'].is_a?(::Array)
|
38
|
+
assert_equal 2, val['fieldErrors'].count
|
39
|
+
e = val['fieldErrors'].find{|v| v['name'] == 'test_class.name'}
|
40
|
+
assert e
|
41
|
+
assert_equal 'Name is too long', e['status']
|
42
|
+
e = val['fieldErrors'].find{|v| v['name'] == 'test_class.code'}
|
43
|
+
assert e
|
44
|
+
assert_equal "Code is not uppercase<br>\nCode is too long", e['status']
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MainAppExtensionsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class TestClass
|
6
|
+
class Action2Class
|
7
|
+
include Incline::Extensions::MainApp
|
8
|
+
|
9
|
+
def action2
|
10
|
+
:action2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
include Incline::Extensions::MainApp
|
15
|
+
|
16
|
+
attr_accessor :called
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
self.called = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def main_app
|
23
|
+
self.called = :main_app
|
24
|
+
@main_app ||= Action2Class.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def action1
|
28
|
+
self.called = :action1
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup
|
34
|
+
@item = TestClass.new
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'main_app should be called automatically' do
|
38
|
+
# action1 belongs to the class itself.
|
39
|
+
assert_equal :action1, @item.action1
|
40
|
+
assert_equal :action1, @item.called
|
41
|
+
|
42
|
+
# action2 belongs to the :main_app object.
|
43
|
+
assert_equal :action2, @item.action2
|
44
|
+
assert_equal :main_app, @item.called
|
45
|
+
|
46
|
+
# and just to be sure, when a class does not define :main_app, we use rails.
|
47
|
+
# in this case the fake :main_app doesn't know :root_path and doesn't define
|
48
|
+
# its own :main_app, so it calls on rails to execute the method.
|
49
|
+
rp = Rails.application.class.routes.url_helpers.root_path
|
50
|
+
assert_equal rp, @item.main_app.root_path
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
class NumericExtensionsTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
test 'numeric types have to_human' do
|
7
|
+
assert Integer(123).respond_to?(:to_human)
|
8
|
+
assert Float(123).respond_to?(:to_human)
|
9
|
+
assert Rational(123).respond_to?(:to_human)
|
10
|
+
assert BigDecimal.new(123).respond_to?(:to_human)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'integers convert as expected' do
|
14
|
+
{
|
15
|
+
1 => '1',
|
16
|
+
10 => '10',
|
17
|
+
100 => '100',
|
18
|
+
1000 => '1 thousand',
|
19
|
+
1500 => '1.5 thousand',
|
20
|
+
1000000 => '1 million',
|
21
|
+
1050000 => '1.05 million',
|
22
|
+
1000000000 => '1 billion',
|
23
|
+
1245000000 => '1.25 billion', # verify that we are using round-to-nearest and not round-to-even.
|
24
|
+
1255000000 => '1.26 billion',
|
25
|
+
999999999 => '1000 million', # less than a billion, but rounding will put it at 1 billion.
|
26
|
+
Integer('1234'.ljust(40,'0')) => '1.23 duodecillion'
|
27
|
+
}.each do |v, s|
|
28
|
+
assert_equal s, v.to_human
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'floats convert as expected' do
|
33
|
+
{
|
34
|
+
0.375 => '0.38',
|
35
|
+
1.0 => '1',
|
36
|
+
10.0 => '10',
|
37
|
+
100.0 => '100',
|
38
|
+
1000.0 => '1 thousand',
|
39
|
+
1500.0 => '1.5 thousand',
|
40
|
+
(1E36 + 1.0) => '1 undecillion'
|
41
|
+
}.each do |v,s|
|
42
|
+
assert_equal s, v.to_human
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'rationals convert as expected' do
|
47
|
+
{
|
48
|
+
Rational('3/8') => '3/8',
|
49
|
+
Rational(1) => '1',
|
50
|
+
Rational('5/3') => '5/3',
|
51
|
+
Rational(10.0) => '10',
|
52
|
+
Rational(100) => '100',
|
53
|
+
Rational('100/1') => '100',
|
54
|
+
Rational(1000) => '1 thousand',
|
55
|
+
Rational(1500) => '1.5 thousand',
|
56
|
+
Rational('1'.ljust(34,'0')) => '1 decillion'
|
57
|
+
}.each do |v,s|
|
58
|
+
assert_equal s, v.to_human
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'big_decimals convert as expected' do
|
63
|
+
{
|
64
|
+
BigDecimal(Rational('3/8'), 4) => '0.38',
|
65
|
+
BigDecimal(1) => '1',
|
66
|
+
BigDecimal(10) => '10',
|
67
|
+
BigDecimal(100) => '100',
|
68
|
+
BigDecimal(1000) => '1 thousand',
|
69
|
+
BigDecimal(1500) => '1.5 thousand',
|
70
|
+
BigDecimal('1'.ljust(31,'0')) => '1 nonillion'
|
71
|
+
}.each do |v,s|
|
72
|
+
assert_equal s, v.to_human
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ObjectExtensionsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'all objects have object_pointer method' do
|
6
|
+
assert Object.respond_to?(:object_pointer)
|
7
|
+
assert Object.new.respond_to?(:object_pointer)
|
8
|
+
assert 'hello'.respond_to?(:object_pointer)
|
9
|
+
assert 12345.respond_to?(:object_pointer)
|
10
|
+
assert [1, 2, 3].respond_to?(:object_pointer)
|
11
|
+
assert Hash.new(hello: :world).respond_to?(:object_pointer)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'all objects have to_bool method' do
|
15
|
+
assert Object.respond_to?(:to_bool)
|
16
|
+
assert Object.new.respond_to?(:to_bool)
|
17
|
+
assert 'hello'.respond_to?(:to_bool)
|
18
|
+
assert 12345.respond_to?(:to_bool)
|
19
|
+
assert [1, 2, 3].respond_to?(:to_bool)
|
20
|
+
assert Hash.new(hello: :world).respond_to?(:to_bool)
|
21
|
+
assert true.respond_to?(:to_bool)
|
22
|
+
assert false.respond_to?(:to_bool)
|
23
|
+
assert nil.respond_to?(:to_bool)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
test 'object_pointer_is_formatted_correctly' do
|
28
|
+
item = Object.new
|
29
|
+
expected = '0x' + item.object_id.to_s(16).rjust(12,'0').downcase
|
30
|
+
assert_equal expected, item.object_pointer
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
test 'to_bool works as expected' do
|
35
|
+
# normal true/false
|
36
|
+
assert true.to_bool
|
37
|
+
assert_not false.to_bool
|
38
|
+
|
39
|
+
# nil => false (should not return nil!)
|
40
|
+
assert_not nil.to_bool
|
41
|
+
assert_not_nil nil.to_bool
|
42
|
+
|
43
|
+
# symbols
|
44
|
+
assert :true.to_bool
|
45
|
+
assert_not :false.to_bool
|
46
|
+
assert :yes.to_bool
|
47
|
+
assert_not :no.to_bool
|
48
|
+
assert :on.to_bool
|
49
|
+
assert_not :off.to_bool
|
50
|
+
|
51
|
+
# integers
|
52
|
+
assert_not 0.to_bool
|
53
|
+
assert 1.to_bool
|
54
|
+
assert (-1.to_bool)
|
55
|
+
|
56
|
+
# floats
|
57
|
+
assert_not 0.0.to_bool
|
58
|
+
assert 0.1.to_bool
|
59
|
+
assert 1.0.to_bool
|
60
|
+
|
61
|
+
# strings (expected true values)
|
62
|
+
assert 'true'.to_bool
|
63
|
+
assert 'True'.to_bool
|
64
|
+
assert 'TRUE'.to_bool
|
65
|
+
assert 't'.to_bool
|
66
|
+
assert 'T'.to_bool
|
67
|
+
assert 'yes'.to_bool
|
68
|
+
assert 'Yes'.to_bool
|
69
|
+
assert 'YES'.to_bool
|
70
|
+
assert 'y'.to_bool
|
71
|
+
assert 'Y'.to_bool
|
72
|
+
assert 'on'.to_bool
|
73
|
+
assert 'On'.to_bool
|
74
|
+
assert 'ON'.to_bool
|
75
|
+
assert '1'.to_bool
|
76
|
+
|
77
|
+
# strings (expected false values)
|
78
|
+
assert_not ''.to_bool
|
79
|
+
assert_not 'false'.to_bool
|
80
|
+
assert_not 'False'.to_bool
|
81
|
+
assert_not 'FALSE'.to_bool
|
82
|
+
assert_not 'f'.to_bool
|
83
|
+
assert_not 'F'.to_bool
|
84
|
+
assert_not 'no'.to_bool
|
85
|
+
assert_not 'No'.to_bool
|
86
|
+
assert_not 'NO'.to_bool
|
87
|
+
assert_not 'off'.to_bool
|
88
|
+
assert_not 'Off'.to_bool
|
89
|
+
assert_not 'OFF'.to_bool
|
90
|
+
assert_not '0'.to_bool
|
91
|
+
|
92
|
+
# strings (misc values are all false)
|
93
|
+
assert_not 'hello'.to_bool
|
94
|
+
assert_not 'maybe'.to_bool
|
95
|
+
assert_not 'true-ish'.to_bool
|
96
|
+
assert_not '123'.to_bool
|
97
|
+
|
98
|
+
# other values
|
99
|
+
assert_not Object.to_bool
|
100
|
+
assert_not Object.new.to_bool
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|