shoulda-matchers 3.1.0 → 5.2.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 +5 -5
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +407 -232
- data/docs/errors/NonCaseSwappableValueError.md +2 -2
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +7 -80
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +4 -3
- data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +36 -30
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +8 -10
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +7 -9
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +18 -15
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +3 -2
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -3
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +88 -29
- data/lib/shoulda/matchers/action_controller/route_params.rb +2 -2
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +4 -4
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
- data/lib/shoulda/matchers/action_controller.rb +2 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -9
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +42 -39
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +52 -26
- data/lib/shoulda/matchers/active_model/helpers.rb +2 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -30
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +2 -1
- data/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
- data/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
- data/lib/shoulda/matchers/active_model/qualifiers.rb +2 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +30 -6
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +8 -3
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +31 -16
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +52 -16
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +137 -84
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +159 -46
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +130 -66
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +251 -24
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +12 -9
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +38 -6
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
- data/lib/shoulda/matchers/active_model/validator.rb +4 -9
- data/lib/shoulda/matchers/active_model.rb +3 -5
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +10 -7
- data/lib/shoulda/matchers/active_record/association_matcher.rb +386 -111
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +14 -15
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +30 -8
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +34 -11
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +69 -0
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +74 -0
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +458 -42
- data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +185 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +63 -23
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +164 -48
- data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +106 -0
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +13 -11
- data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
- data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +18 -18
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
- data/lib/shoulda/matchers/active_record/uniqueness.rb +1 -1
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +430 -200
- data/lib/shoulda/matchers/active_record.rb +28 -20
- data/lib/shoulda/matchers/configuration.rb +12 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
- data/lib/shoulda/matchers/doublespeak/object_double.rb +6 -2
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
- data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
- data/lib/shoulda/matchers/doublespeak.rb +2 -1
- data/lib/shoulda/matchers/error.rb +1 -1
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +109 -29
- data/lib/shoulda/matchers/independent.rb +2 -2
- data/lib/shoulda/matchers/integrations/configuration.rb +8 -4
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/rails_shim.rb +172 -51
- data/lib/shoulda/matchers/routing.rb +2 -2
- data/lib/shoulda/matchers/util/word_wrap.rb +17 -12
- data/lib/shoulda/matchers/util.rb +39 -5
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +4 -3
- data/shoulda-matchers.gemspec +33 -15
- metadata +31 -338
- data/.gitignore +0 -12
- data/.hound.yml +0 -3
- data/.hound_config/ruby.yml +0 -12
- data/.travis.yml +0 -19
- data/.yardopts +0 -10
- data/Appraisals +0 -73
- data/CONTRIBUTING.md +0 -101
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -70
- data/NEWS.md +0 -986
- data/Rakefile +0 -39
- data/custom_plan.rb +0 -88
- data/doc_config/gh-pages/index.html.erb +0 -9
- data/doc_config/yard/setup.rb +0 -22
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
- data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
- data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -62
- data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
- data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -32
- data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
- data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -298
- data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
- data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
- data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -8
- data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
- data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
- data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
- data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
- data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
- data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
- data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
- data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
- data/gemfiles/4.0.0.gemfile +0 -38
- data/gemfiles/4.0.0.gemfile.lock +0 -223
- data/gemfiles/4.0.1.gemfile +0 -38
- data/gemfiles/4.0.1.gemfile.lock +0 -225
- data/gemfiles/4.1.gemfile +0 -38
- data/gemfiles/4.1.gemfile.lock +0 -220
- data/gemfiles/4.2.gemfile +0 -38
- data/gemfiles/4.2.gemfile.lock +0 -243
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
- data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +0 -37
- data/script/SUPPORTED_VERSIONS +0 -1
- data/script/install_gems_in_all_appraisals +0 -14
- data/script/run_all_tests +0 -14
- data/script/update_gem_in_all_appraisals +0 -15
- data/script/update_gems_in_all_appraisals +0 -14
- data/spec/acceptance/active_model_integration_spec.rb +0 -23
- data/spec/acceptance/independent_matchers_spec.rb +0 -125
- data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
- data/spec/acceptance/rails_integration_spec.rb +0 -156
- data/spec/acceptance_spec_helper.rb +0 -23
- data/spec/doublespeak_spec_helper.rb +0 -2
- data/spec/report_warnings.rb +0 -7
- data/spec/spec_helper.rb +0 -21
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
- data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/command_helpers.rb +0 -55
- data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
- data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
- data/spec/support/acceptance/helpers.rb +0 -31
- data/spec/support/acceptance/matchers/have_output.rb +0 -31
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
- data/spec/support/tests/bundle.rb +0 -94
- data/spec/support/tests/command_runner.rb +0 -230
- data/spec/support/tests/current_bundle.rb +0 -61
- data/spec/support/tests/database.rb +0 -28
- data/spec/support/tests/database_adapters/postgresql.rb +0 -25
- data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
- data/spec/support/tests/database_configuration.rb +0 -33
- data/spec/support/tests/database_configuration_registry.rb +0 -28
- data/spec/support/tests/filesystem.rb +0 -100
- data/spec/support/tests/version.rb +0 -45
- data/spec/support/unit/active_record/create_table.rb +0 -54
- data/spec/support/unit/attribute.rb +0 -47
- data/spec/support/unit/capture.rb +0 -40
- data/spec/support/unit/change_value.rb +0 -111
- data/spec/support/unit/create_model_arguments/basic.rb +0 -135
- data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
- data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
- data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
- data/spec/support/unit/helpers/active_model_versions.rb +0 -28
- data/spec/support/unit/helpers/active_record_versions.rb +0 -24
- data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
- data/spec/support/unit/helpers/class_builder.rb +0 -90
- data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
- data/spec/support/unit/helpers/controller_builder.rb +0 -63
- data/spec/support/unit/helpers/database_helpers.rb +0 -20
- data/spec/support/unit/helpers/i18n_faker.rb +0 -15
- data/spec/support/unit/helpers/mailer_builder.rb +0 -12
- data/spec/support/unit/helpers/model_builder.rb +0 -114
- data/spec/support/unit/helpers/rails_versions.rb +0 -28
- data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
- data/spec/support/unit/i18n.rb +0 -7
- data/spec/support/unit/load_environment.rb +0 -12
- data/spec/support/unit/matchers/deprecate.rb +0 -60
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -62
- data/spec/support/unit/matchers/print_warning_including.rb +0 -59
- data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
- data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
- data/spec/support/unit/model_creators/active_model.rb +0 -39
- data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
- data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
- data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
- data/spec/support/unit/model_creators/active_record.rb +0 -43
- data/spec/support/unit/model_creators/basic.rb +0 -97
- data/spec/support/unit/model_creators.rb +0 -19
- data/spec/support/unit/rails_application.rb +0 -126
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
- data/spec/support/unit/record_validating_confirmation_builder.rb +0 -51
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
- data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
- data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
- data/spec/support/unit/validation_matcher_scenario.rb +0 -62
- data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
- data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -592
- data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
- data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
- data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
- data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
- data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
- data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -823
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
- data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
- data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -266
- data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -91
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -149
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -207
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1015
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -288
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1837
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -380
- data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1242
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -168
- data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
- data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
- data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
- data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1418
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -80
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -517
- data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -242
- data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
- data/spec/unit_spec_helper.rb +0 -46
- data/spec/warnings_spy/filesystem.rb +0 -45
- data/spec/warnings_spy/partitioner.rb +0 -36
- data/spec/warnings_spy/reader.rb +0 -53
- data/spec/warnings_spy/reporter.rb +0 -88
- data/spec/warnings_spy.rb +0 -64
- data/tasks/documentation.rb +0 -199
- data/zeus.json +0 -11
@@ -1,380 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher, type: :model do
|
4
|
-
context 'a model with a presence validation' do
|
5
|
-
it 'accepts' do
|
6
|
-
expect(validating_presence).to matcher
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'does not override the default message with a blank' do
|
10
|
-
expect(validating_presence).to matcher.with_message(nil)
|
11
|
-
end
|
12
|
-
|
13
|
-
it_supports(
|
14
|
-
'ignoring_interference_by_writer',
|
15
|
-
tests: {
|
16
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
17
|
-
changing_values_with: :nil_to_blank
|
18
|
-
},
|
19
|
-
reject_if_qualified_but_changing_value_interferes: {
|
20
|
-
model_name: 'Example',
|
21
|
-
attribute_name: :attr,
|
22
|
-
changing_values_with: :never_falsy,
|
23
|
-
expected_message: <<-MESSAGE
|
24
|
-
Example did not properly validate that :attr cannot be empty/falsy.
|
25
|
-
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
|
26
|
-
-- the matcher expected the Example to be invalid, but it was valid
|
27
|
-
instead.
|
28
|
-
|
29
|
-
As indicated in the message above, :attr seems to be changing certain
|
30
|
-
values as they are set, and this could have something to do with why
|
31
|
-
this test is failing. If you've overridden the writer method for this
|
32
|
-
attribute, then you may need to change it to make this test pass, or
|
33
|
-
do something else entirely.
|
34
|
-
MESSAGE
|
35
|
-
}
|
36
|
-
}
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'a model without a presence validation' do
|
41
|
-
it 'rejects with the correct failure message' do
|
42
|
-
record = define_model(:example, attr: :string).new
|
43
|
-
|
44
|
-
assertion = lambda do
|
45
|
-
expect(record).to matcher
|
46
|
-
end
|
47
|
-
|
48
|
-
message = <<-MESSAGE
|
49
|
-
Example did not properly validate that :attr cannot be empty/falsy.
|
50
|
-
After setting :attr to ‹nil›, the matcher expected the Example to be
|
51
|
-
invalid, but it was valid instead.
|
52
|
-
MESSAGE
|
53
|
-
|
54
|
-
expect(&assertion).to fail_with_message(message)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'an ActiveModel class with a presence validation' do
|
59
|
-
it 'accepts' do
|
60
|
-
expect(active_model_validating_presence).to matcher
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'does not override the default message with a blank' do
|
64
|
-
expect(active_model_validating_presence).to matcher.with_message(nil)
|
65
|
-
end
|
66
|
-
|
67
|
-
it_supports(
|
68
|
-
'ignoring_interference_by_writer',
|
69
|
-
tests: {
|
70
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
71
|
-
changing_values_with: :nil_to_blank
|
72
|
-
},
|
73
|
-
reject_if_qualified_but_changing_value_interferes: {
|
74
|
-
model_name: 'Example',
|
75
|
-
attribute_name: :attr,
|
76
|
-
changing_values_with: :never_falsy,
|
77
|
-
expected_message: <<-MESSAGE
|
78
|
-
Example did not properly validate that :attr cannot be empty/falsy.
|
79
|
-
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
|
80
|
-
-- the matcher expected the Example to be invalid, but it was valid
|
81
|
-
instead.
|
82
|
-
|
83
|
-
As indicated in the message above, :attr seems to be changing certain
|
84
|
-
values as they are set, and this could have something to do with why
|
85
|
-
this test is failing. If you've overridden the writer method for this
|
86
|
-
attribute, then you may need to change it to make this test pass, or
|
87
|
-
do something else entirely.
|
88
|
-
MESSAGE
|
89
|
-
}
|
90
|
-
}
|
91
|
-
)
|
92
|
-
|
93
|
-
def model_creator
|
94
|
-
:active_model
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'an ActiveModel class without a presence validation' do
|
99
|
-
it 'rejects with the correct failure message' do
|
100
|
-
assertion = lambda do
|
101
|
-
expect(active_model).to matcher
|
102
|
-
end
|
103
|
-
|
104
|
-
message = <<-MESSAGE
|
105
|
-
Example did not properly validate that :attr cannot be empty/falsy.
|
106
|
-
After setting :attr to ‹nil›, the matcher expected the Example to be
|
107
|
-
invalid, but it was valid instead.
|
108
|
-
MESSAGE
|
109
|
-
|
110
|
-
expect(&assertion).to fail_with_message(message)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'a has_many association with a presence validation' do
|
115
|
-
it 'requires the attribute to be set' do
|
116
|
-
expect(has_many_children(presence: true)).to validate_presence_of(:children)
|
117
|
-
end
|
118
|
-
|
119
|
-
it_supports(
|
120
|
-
'ignoring_interference_by_writer',
|
121
|
-
tests: {
|
122
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
123
|
-
changing_values_with: :nil_to_blank
|
124
|
-
},
|
125
|
-
reject_if_qualified_but_changing_value_interferes: {
|
126
|
-
model_name: 'Example',
|
127
|
-
attribute_name: :attr,
|
128
|
-
changing_values_with: :never_falsy,
|
129
|
-
expected_message: <<-MESSAGE
|
130
|
-
Example did not properly validate that :attr cannot be empty/falsy.
|
131
|
-
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
|
132
|
-
-- the matcher expected the Example to be invalid, but it was valid
|
133
|
-
instead.
|
134
|
-
|
135
|
-
As indicated in the message above, :attr seems to be changing certain
|
136
|
-
values as they are set, and this could have something to do with why
|
137
|
-
this test is failing. If you've overridden the writer method for this
|
138
|
-
attribute, then you may need to change it to make this test pass, or
|
139
|
-
do something else entirely.
|
140
|
-
MESSAGE
|
141
|
-
}
|
142
|
-
}
|
143
|
-
)
|
144
|
-
|
145
|
-
def model_creator
|
146
|
-
:"active_record/has_many"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'a has_many association without a presence validation' do
|
151
|
-
it 'does not require the attribute to be set' do
|
152
|
-
expect(has_many_children(presence: false)).
|
153
|
-
not_to validate_presence_of(:children)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'a required has_and_belongs_to_many association' do
|
158
|
-
it 'accepts' do
|
159
|
-
expect(build_record_having_and_belonging_to_many).
|
160
|
-
to validate_presence_of(:children)
|
161
|
-
end
|
162
|
-
|
163
|
-
def build_record_having_and_belonging_to_many
|
164
|
-
create_table 'children_parents', id: false do |t|
|
165
|
-
t.integer :child_id
|
166
|
-
t.integer :parent_id
|
167
|
-
end
|
168
|
-
|
169
|
-
define_model :child
|
170
|
-
|
171
|
-
define_model :parent do
|
172
|
-
has_and_belongs_to_many :children
|
173
|
-
validates_presence_of :children
|
174
|
-
end.new
|
175
|
-
end
|
176
|
-
|
177
|
-
it_supports(
|
178
|
-
'ignoring_interference_by_writer',
|
179
|
-
tests: {
|
180
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
181
|
-
changing_values_with: :nil_to_blank
|
182
|
-
},
|
183
|
-
reject_if_qualified_but_changing_value_interferes: {
|
184
|
-
model_name: 'Example',
|
185
|
-
attribute_name: :attr,
|
186
|
-
changing_values_with: :never_falsy,
|
187
|
-
expected_message: <<-MESSAGE
|
188
|
-
Example did not properly validate that :attr cannot be empty/falsy.
|
189
|
-
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
|
190
|
-
-- the matcher expected the Example to be invalid, but it was valid
|
191
|
-
instead.
|
192
|
-
|
193
|
-
As indicated in the message above, :attr seems to be changing certain
|
194
|
-
values as they are set, and this could have something to do with why
|
195
|
-
this test is failing. If you've overridden the writer method for this
|
196
|
-
attribute, then you may need to change it to make this test pass, or
|
197
|
-
do something else entirely.
|
198
|
-
MESSAGE
|
199
|
-
}
|
200
|
-
}
|
201
|
-
)
|
202
|
-
|
203
|
-
def model_creator
|
204
|
-
:"active_record/has_and_belongs_to_many"
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context 'an optional has_and_belongs_to_many association' do
|
209
|
-
before do
|
210
|
-
define_model :child
|
211
|
-
@model = define_model :parent do
|
212
|
-
has_and_belongs_to_many :children
|
213
|
-
end.new
|
214
|
-
create_table 'children_parents', id: false do |t|
|
215
|
-
t.integer :child_id
|
216
|
-
t.integer :parent_id
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'rejects with the correct failure message' do
|
221
|
-
assertion = lambda do
|
222
|
-
expect(@model).to validate_presence_of(:children)
|
223
|
-
end
|
224
|
-
|
225
|
-
message = <<-MESSAGE
|
226
|
-
Parent did not properly validate that :children cannot be empty/falsy.
|
227
|
-
After setting :children to ‹[]›, the matcher expected the Parent to be
|
228
|
-
invalid, but it was valid instead.
|
229
|
-
MESSAGE
|
230
|
-
|
231
|
-
expect(&assertion).to fail_with_message(message)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context "an i18n translation containing %{attribute} and %{model}" do
|
236
|
-
before do
|
237
|
-
stub_translation(
|
238
|
-
"activerecord.errors.messages.blank",
|
239
|
-
"Please enter a %{attribute} for your %{model}")
|
240
|
-
end
|
241
|
-
|
242
|
-
after { I18n.backend.reload! }
|
243
|
-
|
244
|
-
it "does not raise an exception" do
|
245
|
-
expect {
|
246
|
-
expect(validating_presence).to validate_presence_of(:attr)
|
247
|
-
}.to_not raise_exception
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
if active_model_3_2?
|
252
|
-
context 'a strictly required attribute' do
|
253
|
-
it 'accepts when the :strict options match' do
|
254
|
-
expect(validating_presence(strict: true)).to matcher.strict
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'rejects with the correct failure message when the :strict options do not match' do
|
258
|
-
assertion = lambda do
|
259
|
-
expect(validating_presence(strict: false)).to matcher.strict
|
260
|
-
end
|
261
|
-
|
262
|
-
message = <<-MESSAGE
|
263
|
-
Example did not properly validate that :attr cannot be empty/falsy,
|
264
|
-
raising a validation exception on failure.
|
265
|
-
After setting :attr to ‹nil›, the matcher expected the Example to be
|
266
|
-
invalid and to raise a validation exception, but the record produced
|
267
|
-
validation errors instead.
|
268
|
-
MESSAGE
|
269
|
-
|
270
|
-
expect(&assertion).to fail_with_message(message)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'does not override the default message with a blank' do
|
275
|
-
expect(validating_presence(strict: true)).
|
276
|
-
to matcher.strict.with_message(nil)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
context "an attribute with a context-dependent validation" do
|
281
|
-
context "without the validation context" do
|
282
|
-
it "does not match" do
|
283
|
-
expect(validating_presence(on: :customisable)).not_to matcher
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context "with the validation context" do
|
288
|
-
it "matches" do
|
289
|
-
expect(validating_presence(on: :customisable)).to matcher.on(:customisable)
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
context 'an active_resource model' do
|
295
|
-
context 'with the validation context' do
|
296
|
-
it 'does not raise an exception' do
|
297
|
-
expect {
|
298
|
-
expect(active_resource_model).to validate_presence_of(:attr)
|
299
|
-
}.to_not raise_exception
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
if rails_4_x?
|
305
|
-
context 'against a pre-set password in a model that has_secure_password' do
|
306
|
-
it 'raises a CouldNotSetPasswordError' do
|
307
|
-
user_class = define_model :user, password_digest: :string do
|
308
|
-
has_secure_password validations: false
|
309
|
-
validates_presence_of :password
|
310
|
-
end
|
311
|
-
|
312
|
-
user = user_class.new
|
313
|
-
user.password = 'something'
|
314
|
-
|
315
|
-
assertion = lambda do
|
316
|
-
expect(user).to validate_presence_of(:password)
|
317
|
-
end
|
318
|
-
|
319
|
-
expect(&assertion).to raise_error(
|
320
|
-
Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError
|
321
|
-
)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
context 'when the attribute typecasts nil to another blank value, such as an empty array' do
|
327
|
-
it 'accepts (and does not raise an AttributeChangedValueError)' do
|
328
|
-
model = define_active_model_class :example, accessors: [:foo] do
|
329
|
-
validates_presence_of :foo
|
330
|
-
|
331
|
-
def foo=(value)
|
332
|
-
super(Array.wrap(value))
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
expect(model.new).to validate_presence_of(:foo)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
def matcher
|
341
|
-
validate_presence_of(:attr)
|
342
|
-
end
|
343
|
-
|
344
|
-
def validating_presence(options = {})
|
345
|
-
define_model :example, attr: :string do
|
346
|
-
validates_presence_of :attr, options
|
347
|
-
end.new
|
348
|
-
end
|
349
|
-
|
350
|
-
def active_model(&block)
|
351
|
-
define_active_model_class('Example', accessors: [:attr], &block).new
|
352
|
-
end
|
353
|
-
|
354
|
-
def active_model_validating_presence
|
355
|
-
active_model { validates_presence_of :attr }
|
356
|
-
end
|
357
|
-
|
358
|
-
def has_many_children(options = {})
|
359
|
-
define_model :child
|
360
|
-
define_model :parent do
|
361
|
-
has_many :children
|
362
|
-
if options[:presence]
|
363
|
-
validates_presence_of :children
|
364
|
-
end
|
365
|
-
end.new
|
366
|
-
end
|
367
|
-
|
368
|
-
def active_resource_model
|
369
|
-
define_active_resource_class :foo, attr: :string do
|
370
|
-
validates_presence_of :attr
|
371
|
-
end.new
|
372
|
-
end
|
373
|
-
|
374
|
-
def validation_matcher_scenario_args
|
375
|
-
super.deep_merge(
|
376
|
-
matcher_name: :validate_presence_of,
|
377
|
-
model_creator: :active_record
|
378
|
-
)
|
379
|
-
end
|
380
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher, type: :model do
|
4
|
-
it 'accepts an existing declaration' do
|
5
|
-
expect(accepting_children).to accept_nested_attributes_for(:children)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'rejects a missing declaration' do
|
9
|
-
matcher = children_matcher
|
10
|
-
|
11
|
-
expect(matcher.matches?(rejecting_children)).to eq false
|
12
|
-
|
13
|
-
expect(matcher.failure_message).
|
14
|
-
to eq 'Expected Parent to accept nested attributes for children (is not declared)'
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'allow_destroy' do
|
18
|
-
it 'accepts a valid truthy value' do
|
19
|
-
matching = accepting_children(allow_destroy: true)
|
20
|
-
|
21
|
-
expect(matching).to children_matcher.allow_destroy(true)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'accepts a valid falsey value' do
|
25
|
-
matching = accepting_children(allow_destroy: false)
|
26
|
-
|
27
|
-
expect(matching).to children_matcher.allow_destroy(false)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'rejects an invalid truthy value' do
|
31
|
-
matcher = children_matcher
|
32
|
-
matching = accepting_children(allow_destroy: true)
|
33
|
-
|
34
|
-
expect(matcher.allow_destroy(false).matches?(matching)).to eq false
|
35
|
-
expect(matcher.failure_message).to match(/should not allow destroy/)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'rejects an invalid falsey value' do
|
39
|
-
matcher = children_matcher
|
40
|
-
matching = accepting_children(allow_destroy: false)
|
41
|
-
|
42
|
-
expect(matcher.allow_destroy(true).matches?(matching)).to eq false
|
43
|
-
expect(matcher.failure_message).to match(/should allow destroy/)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'limit' do
|
48
|
-
it 'accepts a correct value' do
|
49
|
-
expect(accepting_children(limit: 3)).to children_matcher.limit(3)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'rejects a false value' do
|
53
|
-
matcher = children_matcher
|
54
|
-
rejecting = accepting_children(limit: 3)
|
55
|
-
|
56
|
-
expect(matcher.limit(2).matches?(rejecting)).to eq false
|
57
|
-
expect(matcher.failure_message).to match(/limit should be 2, got 3/)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'update_only' do
|
62
|
-
it 'accepts a valid truthy value' do
|
63
|
-
expect(accepting_children(update_only: true)).
|
64
|
-
to children_matcher.update_only(true)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'accepts a valid falsey value' do
|
68
|
-
expect(accepting_children(update_only: false)).
|
69
|
-
to children_matcher.update_only(false)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'rejects an invalid truthy value' do
|
73
|
-
matcher = children_matcher.update_only(false)
|
74
|
-
rejecting = accepting_children(update_only: true)
|
75
|
-
|
76
|
-
expect(matcher.matches?(rejecting)).to eq false
|
77
|
-
expect(matcher.failure_message).to match(/should not be update only/)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'rejects an invalid falsey value' do
|
81
|
-
matcher = children_matcher.update_only(true)
|
82
|
-
rejecting = accepting_children(update_only: false)
|
83
|
-
|
84
|
-
expect(matcher.matches?(rejecting)).to eq false
|
85
|
-
expect(matcher.failure_message).to match(/should be update only/)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def accepting_children(options = {})
|
90
|
-
define_model :child, parent_id: :integer
|
91
|
-
define_model :parent do
|
92
|
-
has_many :children
|
93
|
-
accepts_nested_attributes_for :children, options
|
94
|
-
end.new
|
95
|
-
end
|
96
|
-
|
97
|
-
def children_matcher
|
98
|
-
accept_nested_attributes_for(:children)
|
99
|
-
end
|
100
|
-
|
101
|
-
def rejecting_children
|
102
|
-
define_model :child, parent_id: :integer
|
103
|
-
define_model :parent do
|
104
|
-
has_many :children
|
105
|
-
end.new
|
106
|
-
end
|
107
|
-
end
|