shoulda-matchers 3.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,86 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher, type: :model do
|
4
|
-
context 'an attribute with a format validation' do
|
5
|
-
it 'does not match if the value is allowed' do
|
6
|
-
expect(validating_format(with: /abc/)).not_to matcher('abcde').for(:attr)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'matches if the value is not allowed' do
|
10
|
-
expect(validating_format(with: /abc/)).to matcher('xyz').for(:attr)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "an attribute with a context-dependent validation" do
|
15
|
-
context "without the validation context" do
|
16
|
-
it "does not match" do
|
17
|
-
expect(validating_format(with: /abc/, on: :customisable)).not_to matcher("xyz").for(:attr)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "with the validation context" do
|
22
|
-
it "disallows a bad value" do
|
23
|
-
expect(validating_format(with: /abc/, on: :customisable)).to matcher("xyz").for(:attr).on(:customisable)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "does not match a good value" do
|
27
|
-
expect(validating_format(with: /abc/, on: :customisable)).not_to matcher("abcde").for(:attr).on(:customisable)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'an attribute with a format validation and a custom message' do
|
33
|
-
it 'does not match if the value and message are both correct' do
|
34
|
-
expect(validating_format(with: /abc/, message: 'good message')).
|
35
|
-
not_to matcher('abcde').for(:attr).with_message('good message')
|
36
|
-
end
|
37
|
-
|
38
|
-
it "delegates its failure message to its allow matcher's negative failure message" do
|
39
|
-
allow_matcher = double('allow_matcher',
|
40
|
-
failure_message_when_negated: 'allow matcher failure',
|
41
|
-
).as_null_object
|
42
|
-
allow(Shoulda::Matchers::ActiveModel::AllowValueMatcher).
|
43
|
-
to receive(:new).
|
44
|
-
and_return(allow_matcher)
|
45
|
-
|
46
|
-
matcher = matcher('abcde').for(:attr).with_message('good message')
|
47
|
-
matcher.matches?(validating_format(with: /abc/, message: 'good message'))
|
48
|
-
|
49
|
-
expect(matcher.failure_message).to eq 'allow matcher failure'
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'matches if the message is correct but the value is not' do
|
53
|
-
expect(validating_format(with: /abc/, message: 'good message')).
|
54
|
-
to matcher('xyz').for(:attr).with_message('good message')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'an attribute where the message occurs on another attribute' do
|
59
|
-
it 'matches if the message is correct but the value is not' do
|
60
|
-
expect(record_with_custom_validation).to \
|
61
|
-
matcher('bad value').for(:attr).with_message(/some message/, against: :attr2)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'does not match if the value and message are both correct' do
|
65
|
-
expect(record_with_custom_validation).not_to \
|
66
|
-
matcher('good value').for(:attr).with_message(/some message/, against: :attr2)
|
67
|
-
end
|
68
|
-
|
69
|
-
def record_with_custom_validation
|
70
|
-
define_model :example, attr: :string, attr2: :string do
|
71
|
-
validate :custom_validation
|
72
|
-
|
73
|
-
def custom_validation
|
74
|
-
if self[:attr] != 'good value'
|
75
|
-
self.errors[:attr2] << 'some message'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end.new
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def matcher(value)
|
83
|
-
described_class.new(value)
|
84
|
-
end
|
85
|
-
alias_method :disallow_value, :matcher
|
86
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher, type: :model do
|
4
|
-
if active_model_3_1?
|
5
|
-
it 'matches when the subject configures has_secure_password with default options' do
|
6
|
-
working_model = define_model(:example, password_digest: :string) { has_secure_password }
|
7
|
-
expect(working_model.new).to have_secure_password
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'does not match when the subject does not authenticate a password' do
|
11
|
-
no_secure_password = define_model(:example)
|
12
|
-
expect(no_secure_password.new).not_to have_secure_password
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'does not match when the subject is missing the password_digest attribute' do
|
16
|
-
no_digest_column = define_model(:example) { has_secure_password }
|
17
|
-
expect(no_digest_column.new).not_to have_secure_password
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'unit_spec_helper'
|
3
|
-
|
4
|
-
describe Shoulda::Matchers::ActiveModel::Helpers do
|
5
|
-
include Shoulda::Matchers::ActiveModel
|
6
|
-
after { I18n.backend.reload! }
|
7
|
-
|
8
|
-
describe 'default_error_message' do
|
9
|
-
context 'if the translation for the model attribute’s error exists' do
|
10
|
-
it 'provides the right error message for validate_presence_of' do
|
11
|
-
store_translations
|
12
|
-
|
13
|
-
assert_presence_validation_has_correct_message
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'provides the right error message for validates_length_of' do
|
17
|
-
store_translations
|
18
|
-
|
19
|
-
assert_length_validation_has_correct_message
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'if no translation for the model attribute’s error exists' do
|
24
|
-
context 'and the translation for the model’s error exists' do
|
25
|
-
it 'provides the right error message for validate_presence_of' do
|
26
|
-
store_translations(without: :model_attribute)
|
27
|
-
|
28
|
-
assert_presence_validation_has_correct_message
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'provides the right error message for validates_length_of' do
|
32
|
-
store_translations(without: :model_attribute)
|
33
|
-
|
34
|
-
assert_length_validation_has_correct_message
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'and no translation for the model’s error exists' do
|
39
|
-
context 'and the translation for the message exists' do
|
40
|
-
it 'provides the right error message for validate_presence_of' do
|
41
|
-
store_translations(without: [:model_attribute, :model])
|
42
|
-
|
43
|
-
assert_presence_validation_has_correct_message
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'provides the right error message for validates_length_of' do
|
47
|
-
store_translations(without: [:model_attribute, :model])
|
48
|
-
|
49
|
-
assert_length_validation_has_correct_message
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'and no translation for the message exists' do
|
54
|
-
context 'and the translation for the attribute exists' do
|
55
|
-
it 'provides the right error message for validate_presence_of' do
|
56
|
-
store_translations(without: [:model_attribute, :model, :message])
|
57
|
-
|
58
|
-
assert_presence_validation_has_correct_message
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'provides the right error message for validates_length_of' do
|
62
|
-
store_translations(without: [:model_attribute, :model, :message])
|
63
|
-
|
64
|
-
assert_length_validation_has_correct_message
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'and no translation for the attribute exists' do
|
69
|
-
it 'provides the general error message for validate_presence_of' do
|
70
|
-
assert_presence_validation_has_correct_message
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'provides the general error message for validates_length_of' do
|
74
|
-
assert_length_validation_has_correct_message
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'if ActiveModel::Errors#generate_message behavior has changed' do
|
82
|
-
it 'provides the right error message for validate_presence_of' do
|
83
|
-
stub_active_model_message_generation(type: :blank,
|
84
|
-
message: 'Behavior has diverged.')
|
85
|
-
assert_presence_validation_has_correct_message
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def assert_presence_validation_has_correct_message
|
91
|
-
record = define_model :example, attr: :string do
|
92
|
-
validates_presence_of :attr
|
93
|
-
end.new
|
94
|
-
expect(record).to validate_presence_of(:attr)
|
95
|
-
end
|
96
|
-
|
97
|
-
def assert_length_validation_has_correct_message
|
98
|
-
record = define_model :example, attr: :string do
|
99
|
-
validates_length_of :attr, is: 40, allow_blank: true
|
100
|
-
end.new
|
101
|
-
expect(record).to validate_length_of(:attr).is_equal_to(40)
|
102
|
-
end
|
103
|
-
|
104
|
-
def store_translations(options = {without: []})
|
105
|
-
options[:without] = Array.wrap(options[:without] || [])
|
106
|
-
|
107
|
-
translations = {
|
108
|
-
activerecord: {
|
109
|
-
errors: {
|
110
|
-
models: {
|
111
|
-
example: {
|
112
|
-
attributes: {
|
113
|
-
attr: {}
|
114
|
-
}
|
115
|
-
}
|
116
|
-
},
|
117
|
-
messages: {}
|
118
|
-
}
|
119
|
-
},
|
120
|
-
errors: {
|
121
|
-
attributes: {
|
122
|
-
attr: {}
|
123
|
-
},
|
124
|
-
messages: {}
|
125
|
-
}
|
126
|
-
}
|
127
|
-
|
128
|
-
unless options[:without].include?(:model_attribute)
|
129
|
-
translations[:activerecord][:errors][:models][:example][:attributes][:attr][:blank] = "Don't you do that to me!"
|
130
|
-
translations[:activerecord][:errors][:models][:example][:attributes][:attr][:wrong_length] = "Don't you do that to me!"
|
131
|
-
end
|
132
|
-
|
133
|
-
unless options[:without].include?(:model)
|
134
|
-
translations[:activerecord][:errors][:models][:example][:blank] = 'Give it one more try!'
|
135
|
-
translations[:activerecord][:errors][:models][:example][:wrong_length] = 'Give it one more try!'
|
136
|
-
end
|
137
|
-
|
138
|
-
unless options[:without].include?(:message)
|
139
|
-
translations[:activerecord][:errors][:messages][:blank] = 'Oh no!'
|
140
|
-
translations[:activerecord][:errors][:messages][:wrong_length] = 'Oh no!'
|
141
|
-
end
|
142
|
-
|
143
|
-
unless options[:without].include?(:attribute)
|
144
|
-
translations[:errors][:attributes][:attr][:blank] = 'Seriously?'
|
145
|
-
translations[:errors][:attributes][:attr][:wrong_length] = 'Seriously?'
|
146
|
-
end
|
147
|
-
|
148
|
-
I18n.backend.store_translations(:en, translations)
|
149
|
-
end
|
150
|
-
|
151
|
-
def stub_active_model_message_generation(options = {})
|
152
|
-
attribute = options.delete(:attribute) || :attr
|
153
|
-
message = options.delete(:message)
|
154
|
-
type = options.delete(:type)
|
155
|
-
|
156
|
-
expect_any_instance_of(ActiveModel::Errors).
|
157
|
-
to receive(:generate_message).
|
158
|
-
with(attribute, type, {}).
|
159
|
-
at_least(1).
|
160
|
-
and_return(message)
|
161
|
-
end
|
162
|
-
end
|
@@ -1,266 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher, type: :model do
|
4
|
-
if active_model_4_0?
|
5
|
-
def self.available_column_types
|
6
|
-
[
|
7
|
-
:string,
|
8
|
-
:text,
|
9
|
-
:integer,
|
10
|
-
:float,
|
11
|
-
:decimal,
|
12
|
-
:datetime,
|
13
|
-
:timestamp,
|
14
|
-
:time,
|
15
|
-
:date,
|
16
|
-
:binary
|
17
|
-
]
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'a model with an absence validation' do
|
21
|
-
it 'accepts' do
|
22
|
-
expect(validating_absence_of(:attr)).to validate_absence_of(:attr)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'does not override the default message with a present' do
|
26
|
-
expect(validating_absence_of(:attr)).to validate_absence_of(:attr).with_message(nil)
|
27
|
-
end
|
28
|
-
|
29
|
-
available_column_types.each do |type|
|
30
|
-
context "when column is of type #{type}" do
|
31
|
-
it "accepts" do
|
32
|
-
expect(validating_absence_of(:attr, {}, type: type)).
|
33
|
-
to validate_absence_of(:attr)
|
34
|
-
end
|
35
|
-
|
36
|
-
it_supports(
|
37
|
-
'ignoring_interference_by_writer',
|
38
|
-
tests: {
|
39
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
40
|
-
changing_values_with: :next_value
|
41
|
-
},
|
42
|
-
}
|
43
|
-
)
|
44
|
-
|
45
|
-
define_method(:validation_matcher_scenario_args) do |*args|
|
46
|
-
super(*args).deep_merge(column_type: type)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def validation_matcher_scenario_args
|
52
|
-
super.deep_merge(model_creator: :active_record)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'a model without an absence validation' do
|
57
|
-
it 'rejects with the correct failure message' do
|
58
|
-
record = define_model(:example, attr: :string).new
|
59
|
-
|
60
|
-
message = <<-MESSAGE
|
61
|
-
Example did not properly validate that :attr is empty/falsy.
|
62
|
-
After setting :attr to ‹"an arbitrary value"›, the matcher expected
|
63
|
-
the Example to be invalid, but it was valid instead.
|
64
|
-
MESSAGE
|
65
|
-
|
66
|
-
assertion = lambda do
|
67
|
-
expect(record).to validate_absence_of(:attr)
|
68
|
-
end
|
69
|
-
|
70
|
-
expect(&assertion).to fail_with_message(message)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'an ActiveModel class with an absence validation' do
|
75
|
-
it 'accepts' do
|
76
|
-
expect(active_model_validating_absence_of(:attr)).to validate_absence_of(:attr)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'does not override the default message with a blank' do
|
80
|
-
expect(active_model_validating_absence_of(:attr)).to validate_absence_of(:attr).with_message(nil)
|
81
|
-
end
|
82
|
-
|
83
|
-
it_supports(
|
84
|
-
'ignoring_interference_by_writer',
|
85
|
-
tests: {
|
86
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
87
|
-
changing_values_with: :upcase
|
88
|
-
},
|
89
|
-
}
|
90
|
-
)
|
91
|
-
|
92
|
-
def validation_matcher_scenario_args
|
93
|
-
super.deep_merge(model_creator: :active_model)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'an ActiveModel class without an absence validation' do
|
98
|
-
it 'rejects with the correct failure message' do
|
99
|
-
message = <<-MESSAGE
|
100
|
-
Example did not properly validate that :attr is empty/falsy.
|
101
|
-
After setting :attr to ‹"an arbitrary value"›, the matcher expected
|
102
|
-
the Example to be invalid, but it was valid instead.
|
103
|
-
MESSAGE
|
104
|
-
|
105
|
-
assertion = lambda do
|
106
|
-
expect(active_model_with(:attr)).to validate_absence_of(:attr)
|
107
|
-
end
|
108
|
-
|
109
|
-
expect(&assertion).to fail_with_message(message)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'a has_many association with an absence validation' do
|
114
|
-
it 'requires the attribute to not be set' do
|
115
|
-
expect(having_many(:children, absence: true)).to validate_absence_of(:children)
|
116
|
-
end
|
117
|
-
|
118
|
-
it_supports(
|
119
|
-
'ignoring_interference_by_writer',
|
120
|
-
tests: {
|
121
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
122
|
-
changing_values_with: :next_value
|
123
|
-
},
|
124
|
-
}
|
125
|
-
)
|
126
|
-
|
127
|
-
def validation_matcher_scenario_args
|
128
|
-
super.deep_merge(model_creator: :"active_record/has_many")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context 'a has_many association without an absence validation' do
|
133
|
-
it 'does not require the attribute to not be set' do
|
134
|
-
expect(having_many(:children, absence: false)).
|
135
|
-
not_to validate_absence_of(:children)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'an absent has_and_belongs_to_many association' do
|
140
|
-
it 'accepts' do
|
141
|
-
model = having_and_belonging_to_many(:children, absence: true)
|
142
|
-
expect(model).to validate_absence_of(:children)
|
143
|
-
end
|
144
|
-
|
145
|
-
it_supports(
|
146
|
-
'ignoring_interference_by_writer',
|
147
|
-
tests: {
|
148
|
-
accept_if_qualified_but_changing_value_does_not_interfere: {
|
149
|
-
changing_values_with: :next_value
|
150
|
-
},
|
151
|
-
}
|
152
|
-
)
|
153
|
-
|
154
|
-
def validation_matcher_scenario_args
|
155
|
-
super.deep_merge(model_creator: :"active_record/habtm")
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'a non-absent has_and_belongs_to_many association' do
|
160
|
-
it 'rejects with the correct failure message' do
|
161
|
-
model = having_and_belonging_to_many(:children, absence: false)
|
162
|
-
|
163
|
-
message = <<-MESSAGE
|
164
|
-
Parent did not properly validate that :children is empty/falsy.
|
165
|
-
After setting :children to ‹[#<Child id: nil>]›, the matcher expected
|
166
|
-
the Parent to be invalid, but it was valid instead.
|
167
|
-
MESSAGE
|
168
|
-
|
169
|
-
assertion = lambda do
|
170
|
-
expect(model).to validate_absence_of(:children)
|
171
|
-
end
|
172
|
-
|
173
|
-
expect(&assertion).to fail_with_message(message)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context "an i18n translation containing %{attribute} and %{model}" do
|
178
|
-
after { I18n.backend.reload! }
|
179
|
-
|
180
|
-
it "does not raise an exception" do
|
181
|
-
stub_translation("activerecord.errors.messages.present",
|
182
|
-
"%{attribute} must be blank in a %{model}")
|
183
|
-
|
184
|
-
expect {
|
185
|
-
expect(validating_absence_of(:attr)).to validate_absence_of(:attr)
|
186
|
-
}.to_not raise_exception
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "an attribute with a context-dependent validation" do
|
191
|
-
context "without the validation context" do
|
192
|
-
it "does not match" do
|
193
|
-
expect(validating_absence_of(:attr, on: :customisable)).not_to validate_absence_of(:attr)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "with the validation context" do
|
198
|
-
it "matches" do
|
199
|
-
expect(validating_absence_of(:attr, on: :customisable)).to validate_absence_of(:attr).on(:customisable)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def define_model_validating_absence_of(attr, validation_options = {}, given_column_options = {})
|
205
|
-
default_column_options = { type: :string, options: {} }
|
206
|
-
column_options = default_column_options.merge(given_column_options)
|
207
|
-
|
208
|
-
define_model :example, attr => column_options do |model|
|
209
|
-
model.validates_absence_of(attr, validation_options)
|
210
|
-
|
211
|
-
if block_given?
|
212
|
-
yield model
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
def validating_absence_of(attr, validation_options = {}, given_column_options = {})
|
218
|
-
model = define_model_validating_absence_of(
|
219
|
-
attr,
|
220
|
-
validation_options,
|
221
|
-
given_column_options
|
222
|
-
)
|
223
|
-
model.new
|
224
|
-
end
|
225
|
-
alias_method :build_record_validating_absence_of, :validating_absence_of
|
226
|
-
|
227
|
-
def active_model_with(attr, &block)
|
228
|
-
define_active_model_class('Example', accessors: [attr], &block).new
|
229
|
-
end
|
230
|
-
|
231
|
-
def active_model_validating_absence_of(attr)
|
232
|
-
active_model_with(attr) do
|
233
|
-
validates_absence_of attr
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def having_many(plural_name, options = {})
|
238
|
-
define_model plural_name.to_s.singularize
|
239
|
-
define_model :parent do
|
240
|
-
has_many plural_name
|
241
|
-
if options[:absence]
|
242
|
-
validates_absence_of plural_name
|
243
|
-
end
|
244
|
-
end.new
|
245
|
-
end
|
246
|
-
|
247
|
-
def having_and_belonging_to_many(plural_name, options = {})
|
248
|
-
create_table 'children_parents', id: false do |t|
|
249
|
-
t.integer "#{plural_name.to_s.singularize}_id"
|
250
|
-
t.integer :parent_id
|
251
|
-
end
|
252
|
-
|
253
|
-
define_model plural_name.to_s.singularize
|
254
|
-
define_model :parent do
|
255
|
-
has_and_belongs_to_many plural_name
|
256
|
-
if options[:absence]
|
257
|
-
validates_absence_of plural_name
|
258
|
-
end
|
259
|
-
end.new
|
260
|
-
end
|
261
|
-
|
262
|
-
def validation_matcher_scenario_args
|
263
|
-
super.deep_merge(matcher_name: :validate_absence_of)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher, type: :model do
|
4
|
-
context 'a model with an acceptance validation' do
|
5
|
-
it 'accepts when the attributes match' do
|
6
|
-
expect(record_validating_acceptance).to matcher
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'does not overwrite the default message with nil' do
|
10
|
-
expect(record_validating_acceptance).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: :never_falsy,
|
18
|
-
},
|
19
|
-
reject_if_qualified_but_changing_value_interferes: {
|
20
|
-
model_name: 'Example',
|
21
|
-
attribute_name: :attr,
|
22
|
-
changing_values_with: :always_nil,
|
23
|
-
expected_message: <<-MESSAGE.strip
|
24
|
-
Example did not properly validate that :attr has been set to "1".
|
25
|
-
After setting :attr to ‹false› -- which was read back as ‹nil› -- the
|
26
|
-
matcher expected the Example to be invalid, but it was valid instead.
|
27
|
-
|
28
|
-
As indicated in the message above, :attr seems to be changing certain
|
29
|
-
values as they are set, and this could have something to do with why
|
30
|
-
this test is failing. If you've overridden the writer method for this
|
31
|
-
attribute, then you may need to change it to make this test pass, or
|
32
|
-
do something else entirely.
|
33
|
-
MESSAGE
|
34
|
-
},
|
35
|
-
},
|
36
|
-
model_creator: :active_model
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'a model without an acceptance validation' do
|
41
|
-
it 'rejects' do
|
42
|
-
expect(record_validating_nothing).not_to matcher
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'an attribute which must be accepted with a custom message' do
|
47
|
-
it 'accepts when the message matches' do
|
48
|
-
expect(record_validating_acceptance(message: 'custom')).
|
49
|
-
to matcher.with_message(/custom/)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'rejects when the message does not match' do
|
53
|
-
expect(record_validating_acceptance(message: 'custom')).
|
54
|
-
not_to matcher.with_message(/wrong/)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def matcher
|
59
|
-
validate_acceptance_of(:attr)
|
60
|
-
end
|
61
|
-
|
62
|
-
def model_validating_nothing(options = {}, &block)
|
63
|
-
attribute_name = options.fetch(:attribute_name, :attr)
|
64
|
-
define_active_model_class(:example, accessors: [attribute_name], &block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def record_validating_nothing
|
68
|
-
model_validating_nothing.new
|
69
|
-
end
|
70
|
-
|
71
|
-
def model_validating_acceptance(options = {})
|
72
|
-
attribute_name = options.fetch(:attribute_name, :attr)
|
73
|
-
|
74
|
-
model_validating_nothing(attribute_name: attribute_name) do
|
75
|
-
validates_acceptance_of attribute_name, options
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
alias_method :define_model_validating_acceptance, :model_validating_acceptance
|
80
|
-
|
81
|
-
def record_validating_acceptance(options = {})
|
82
|
-
model_validating_acceptance(options).new
|
83
|
-
end
|
84
|
-
|
85
|
-
alias_method :build_record_validating_acceptance,
|
86
|
-
:record_validating_acceptance
|
87
|
-
|
88
|
-
def validation_matcher_scenario_args
|
89
|
-
{ matcher_name: :validate_acceptance_of }
|
90
|
-
end
|
91
|
-
end
|