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,251 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection do
|
4
|
-
it 'delegates other methods to the given Reflection object' do
|
5
|
-
define_model(:country)
|
6
|
-
person_model = define_model(:person, country_id: :integer) do
|
7
|
-
belongs_to :country
|
8
|
-
end
|
9
|
-
delegate_reflection = person_model.reflect_on_association(:country)
|
10
|
-
allow(delegate_reflection).to receive(:foo).and_return('bar')
|
11
|
-
reflection = described_class.new(delegate_reflection)
|
12
|
-
|
13
|
-
expect(reflection.foo).to eq 'bar'
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#associated_class' do
|
17
|
-
it 'returns the model that the association refers to' do
|
18
|
-
define_model(:country)
|
19
|
-
person_model = define_model(:person, country_id: :integer) do
|
20
|
-
belongs_to :country
|
21
|
-
end
|
22
|
-
delegate_reflection = person_model.reflect_on_association(:country)
|
23
|
-
reflection = described_class.new(delegate_reflection)
|
24
|
-
|
25
|
-
expect(reflection.associated_class).to be Country
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#through?' do
|
30
|
-
it 'returns true if the reflection is for a has_many :through association' do
|
31
|
-
define_model(:city, person_id: :integer)
|
32
|
-
define_model(:person, country_id: :integer) do
|
33
|
-
has_many :cities
|
34
|
-
end
|
35
|
-
country_model = define_model(:country) do
|
36
|
-
has_many :people
|
37
|
-
has_many :cities, through: :people
|
38
|
-
end
|
39
|
-
delegate_reflection = country_model.reflect_on_association(:cities)
|
40
|
-
reflection = described_class.new(delegate_reflection)
|
41
|
-
|
42
|
-
expect(reflection).to be_through
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns false if not' do
|
46
|
-
define_model(:person, country_id: :integer)
|
47
|
-
country_model = define_model(:country) do
|
48
|
-
has_many :people
|
49
|
-
end
|
50
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
51
|
-
reflection = described_class.new(delegate_reflection)
|
52
|
-
|
53
|
-
expect(reflection).not_to be_through
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#join_table_name' do
|
58
|
-
context 'when the association was defined with a :join_table option' do
|
59
|
-
it 'returns the value of the option' do
|
60
|
-
create_table :foos, id: false do |t|
|
61
|
-
t.integer :person_id
|
62
|
-
t.integer :country_id
|
63
|
-
end
|
64
|
-
define_model(:person, country_id: :integer)
|
65
|
-
country_model = define_model(:country) do
|
66
|
-
has_and_belongs_to_many :people, join_table: 'foos'
|
67
|
-
end
|
68
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
69
|
-
reflection = described_class.new(delegate_reflection)
|
70
|
-
|
71
|
-
expect(reflection.join_table_name).to eq 'foos'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'when the association was not defined with :join_table' do
|
76
|
-
it 'returns the default join_table that ActiveRecord generates' do
|
77
|
-
define_model(:person, country_id: :integer)
|
78
|
-
country_model = define_model(:country) do
|
79
|
-
has_and_belongs_to_many :people
|
80
|
-
end
|
81
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
82
|
-
reflection = described_class.new(delegate_reflection)
|
83
|
-
|
84
|
-
expect(reflection.join_table_name).to eq 'countries_people'
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe '#association_relation' do
|
90
|
-
if rails_4_x?
|
91
|
-
context 'when the reflection object has a #scope method' do
|
92
|
-
context 'when the scope is a block' do
|
93
|
-
it 'executes the block in the context of an empty scope' do
|
94
|
-
define_model(:country, mood: :string)
|
95
|
-
person_model = define_model(:person, country_id: :integer) do
|
96
|
-
belongs_to :country, -> { where(mood: 'nice') }
|
97
|
-
end
|
98
|
-
delegate_reflection = person_model.reflect_on_association(:country)
|
99
|
-
reflection = described_class.new(delegate_reflection)
|
100
|
-
|
101
|
-
actual_sql = reflection.association_relation.to_sql
|
102
|
-
expected_sql = Country.where(mood: 'nice').to_sql
|
103
|
-
expect(actual_sql).to eq expected_sql
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when the scope is nil' do
|
108
|
-
it 'returns an empty scope' do
|
109
|
-
define_model(:country)
|
110
|
-
person_model = define_model(:person, country_id: :integer) do
|
111
|
-
belongs_to :country
|
112
|
-
end
|
113
|
-
delegate_reflection = person_model.reflect_on_association(:country)
|
114
|
-
reflection = described_class.new(delegate_reflection)
|
115
|
-
|
116
|
-
actual_sql = reflection.association_relation.to_sql
|
117
|
-
expected_sql = Country.all.to_sql
|
118
|
-
expect(actual_sql).to eq expected_sql
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
if rails_3_x?
|
125
|
-
context 'when the reflection object does not have a #scope method' do
|
126
|
-
context 'when the reflection options contain :conditions' do
|
127
|
-
it 'creates an ActiveRecord::Relation from the conditions' do
|
128
|
-
define_model(:country, mood: :string)
|
129
|
-
person_model = define_model(:person, country_id: :integer) do
|
130
|
-
belongs_to :country, conditions: { mood: 'nice' }
|
131
|
-
end
|
132
|
-
delegate_reflection = person_model.reflect_on_association(:country)
|
133
|
-
reflection = described_class.new(delegate_reflection)
|
134
|
-
|
135
|
-
actual_sql = reflection.association_relation.to_sql
|
136
|
-
expected_sql = Country.where(mood: 'nice').to_sql
|
137
|
-
expect(actual_sql).to eq expected_sql
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context 'when the reflection options contain :order' do
|
142
|
-
it 'creates an ActiveRecord::Relation from the order' do
|
143
|
-
define_model(:person, country_id: :integer, age: :integer)
|
144
|
-
country_model = define_model(:country) do
|
145
|
-
has_many :people, order: 'age'
|
146
|
-
end
|
147
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
148
|
-
reflection = described_class.new(delegate_reflection)
|
149
|
-
|
150
|
-
actual_sql = reflection.association_relation.to_sql
|
151
|
-
expected_sql = Person.order('age').to_sql
|
152
|
-
expect(actual_sql).to eq expected_sql
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'when the reflection options contain :include' do
|
157
|
-
it 'creates an ActiveRecord::Relation from the include' do
|
158
|
-
define_model(:city, country_id: :integer)
|
159
|
-
define_model(:country) do
|
160
|
-
has_many :cities
|
161
|
-
end
|
162
|
-
person_model = define_model(:person, country_id: :integer) do
|
163
|
-
belongs_to :country, include: :cities
|
164
|
-
end
|
165
|
-
delegate_reflection = person_model.reflect_on_association(:country)
|
166
|
-
reflection = described_class.new(delegate_reflection)
|
167
|
-
|
168
|
-
actual_includes = reflection.association_relation.includes_values
|
169
|
-
expected_includes = Country.includes(:cities).includes_values
|
170
|
-
expect(actual_includes).to eq expected_includes
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context 'when the reflection options contain :group' do
|
175
|
-
it 'creates an ActiveRecord::Relation from the group' do
|
176
|
-
country_model = define_model(:country, mood: :string) do
|
177
|
-
has_many :people, group: 'age'
|
178
|
-
end
|
179
|
-
define_model(:person, country_id: :integer, age: :integer)
|
180
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
181
|
-
reflection = described_class.new(delegate_reflection)
|
182
|
-
|
183
|
-
actual_sql = reflection.association_relation.to_sql
|
184
|
-
expected_sql = Person.group('age').to_sql
|
185
|
-
expect(actual_sql).to eq expected_sql
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context 'when the reflection options contain :having' do
|
190
|
-
it 'creates an ActiveRecord::Relation from the having' do
|
191
|
-
country_model = define_model(:country) do
|
192
|
-
has_many :people, having: 'country_id > 1'
|
193
|
-
end
|
194
|
-
define_model(:person, country_id: :integer)
|
195
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
196
|
-
reflection = described_class.new(delegate_reflection)
|
197
|
-
|
198
|
-
actual_sql = reflection.association_relation.to_sql
|
199
|
-
expected_sql = Person.having('country_id > 1').to_sql
|
200
|
-
expect(actual_sql).to eq expected_sql
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'when the reflection options contain :limit' do
|
205
|
-
it 'creates an ActiveRecord::Relation from the limit' do
|
206
|
-
country_model = define_model(:country) do
|
207
|
-
has_many :people, limit: 10
|
208
|
-
end
|
209
|
-
define_model(:person, country_id: :integer)
|
210
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
211
|
-
reflection = described_class.new(delegate_reflection)
|
212
|
-
|
213
|
-
actual_sql = reflection.association_relation.to_sql
|
214
|
-
expected_sql = Person.limit(10).to_sql
|
215
|
-
expect(actual_sql).to eq expected_sql
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context 'when the reflection options contain :offset' do
|
220
|
-
it 'creates an ActiveRecord::Relation from the offset' do
|
221
|
-
country_model = define_model(:country) do
|
222
|
-
has_many :people, offset: 5
|
223
|
-
end
|
224
|
-
define_model(:person, country_id: :integer)
|
225
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
226
|
-
reflection = described_class.new(delegate_reflection)
|
227
|
-
|
228
|
-
actual_sql = reflection.association_relation.to_sql
|
229
|
-
expected_sql = Person.offset(5).to_sql
|
230
|
-
expect(actual_sql).to eq expected_sql
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context 'when the reflection options contain :select' do
|
235
|
-
it 'creates an ActiveRecord::Relation from the select' do
|
236
|
-
country_model = define_model(:country) do
|
237
|
-
has_many :people, select: 'age'
|
238
|
-
end
|
239
|
-
define_model(:person, country_id: :integer, age: :integer)
|
240
|
-
delegate_reflection = country_model.reflect_on_association(:people)
|
241
|
-
reflection = described_class.new(delegate_reflection)
|
242
|
-
|
243
|
-
actual_sql = reflection.association_relation.to_sql
|
244
|
-
expected_sql = Person.select('age').to_sql
|
245
|
-
expect(actual_sql).to eq expected_sql
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
@@ -1,168 +0,0 @@
|
|
1
|
-
require "unit_spec_helper"
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher, type: :model do
|
4
|
-
if active_record_supports_enum?
|
5
|
-
context 'if the attribute is given in plural form accidentally' do
|
6
|
-
it 'rejects' do
|
7
|
-
record = record_with_array_values
|
8
|
-
plural_enum_attribute = enum_attribute.to_s.pluralize
|
9
|
-
message = "Expected #{record.class} to define :#{plural_enum_attribute} as an enum and store the value in a column with an integer type"
|
10
|
-
|
11
|
-
assertion = lambda do
|
12
|
-
expect(record).to define_enum_for(plural_enum_attribute)
|
13
|
-
end
|
14
|
-
|
15
|
-
expect(&assertion).to fail_with_message(message)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'if a method to hold enum values exists on the model but was not created via the enum macro' do
|
20
|
-
it 'rejects' do
|
21
|
-
model = define_model :example do
|
22
|
-
def self.statuses; end
|
23
|
-
end
|
24
|
-
|
25
|
-
message = "Expected #{model} to define :statuses as an enum and store the value in a column with an integer type"
|
26
|
-
|
27
|
-
assertion = lambda do
|
28
|
-
expect(model.new).to define_enum_for(:statuses)
|
29
|
-
end
|
30
|
-
|
31
|
-
expect(&assertion).to fail_with_message(message)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "with only the attribute name specified" do
|
36
|
-
it "accepts a record where the attribute is defined as an enum" do
|
37
|
-
expect(record_with_array_values).to define_enum_for(enum_attribute)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "rejects a record where the attribute is not defined as an enum" do
|
41
|
-
message = "Expected #{record_with_array_values.class} to define :#{non_enum_attribute} as an enum and store the value in a column with an integer type"
|
42
|
-
|
43
|
-
assertion = lambda do
|
44
|
-
expect(record_with_array_values).
|
45
|
-
to define_enum_for(non_enum_attribute)
|
46
|
-
end
|
47
|
-
|
48
|
-
expect(&assertion).to fail_with_message(message)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "rejects a record where the attribute is not defined as an enum with should not" do
|
52
|
-
message = "Did not expect #{record_with_array_values.class} to define :#{enum_attribute} as an enum and store the value in a column with an integer type"
|
53
|
-
|
54
|
-
assertion = lambda do
|
55
|
-
expect(record_with_array_values).
|
56
|
-
not_to define_enum_for(enum_attribute)
|
57
|
-
end
|
58
|
-
|
59
|
-
expect(&assertion).to fail_with_message(message)
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'if the column storing the attribute is not an integer type' do
|
63
|
-
it 'rejects' do
|
64
|
-
record = record_with_array_values(column_type: :string)
|
65
|
-
message = "Expected #{record.class} to define :statuses as an enum and store the value in a column with an integer type"
|
66
|
-
|
67
|
-
assertion = lambda do
|
68
|
-
expect(record).to define_enum_for(:statuses)
|
69
|
-
end
|
70
|
-
|
71
|
-
expect(&assertion).to fail_with_message(message)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "with both attribute name and enum values specified" do
|
77
|
-
context "when the actual enum values are an array" do
|
78
|
-
it "accepts a record where the attribute is defined as an enum and the enum values match" do
|
79
|
-
expect(record_with_array_values).to define_enum_for(enum_attribute).
|
80
|
-
with(["published", "unpublished", "draft"])
|
81
|
-
end
|
82
|
-
|
83
|
-
it "accepts a record where the attribute is not defined as an enum" do
|
84
|
-
message = %{Expected #{record_with_array_values.class} to define :#{non_enum_attribute} as an enum with ["open", "close"] and store the value in a column with an integer type}
|
85
|
-
|
86
|
-
assertion = lambda do
|
87
|
-
expect(record_with_array_values).
|
88
|
-
to define_enum_for(non_enum_attribute).with(['open', 'close'])
|
89
|
-
end
|
90
|
-
|
91
|
-
expect(&assertion).to fail_with_message(message)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "accepts a record where the attribute is defined as an enum but the enum values do not match" do
|
95
|
-
message = %{Expected #{record_with_array_values.class} to define :#{enum_attribute} as an enum with ["open", "close"] and store the value in a column with an integer type}
|
96
|
-
|
97
|
-
assertion = lambda do
|
98
|
-
expect(record_with_array_values).
|
99
|
-
to define_enum_for(enum_attribute).
|
100
|
-
with(["open", "close"])
|
101
|
-
end
|
102
|
-
|
103
|
-
expect(&assertion).to fail_with_message(message)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when the actual enum values are a hash" do
|
108
|
-
it "accepts a record where the attribute is defined as an enum and the enum values match" do
|
109
|
-
expect(record_with_hash_values).to define_enum_for(enum_attribute).with(active: 0, archived: 1)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "accepts a record where the enum values match when expected enum values are given as an array" do
|
113
|
-
expect(record_with_hash_values).to define_enum_for(enum_attribute).with(["active", "archived"])
|
114
|
-
end
|
115
|
-
|
116
|
-
it "accepts a record where the attribute is defined as an enum but the enum values do not match" do
|
117
|
-
message = %{Expected #{record_with_hash_values.class} to define :#{enum_attribute} as an enum with {:active=>5, :archived=>10} and store the value in a column with an integer type}
|
118
|
-
|
119
|
-
assertion = lambda do
|
120
|
-
expect(record_with_hash_values).
|
121
|
-
to define_enum_for(enum_attribute).
|
122
|
-
with(active: 5, archived: 10)
|
123
|
-
end
|
124
|
-
|
125
|
-
expect(&assertion).to fail_with_message(message)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "rejects a record where the attribute is not defined as an enum" do
|
129
|
-
message = %{Expected #{record_with_hash_values.class} to define :record_with_hash_values as an enum with {:active=>5, :archived=>10} and store the value in a column with an integer type}
|
130
|
-
|
131
|
-
assertion = lambda do
|
132
|
-
expect(record_with_hash_values).
|
133
|
-
to define_enum_for(:record_with_hash_values).
|
134
|
-
with(active: 5, archived: 10)
|
135
|
-
end
|
136
|
-
|
137
|
-
expect(&assertion).to fail_with_message(message)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def enum_attribute
|
143
|
-
:status
|
144
|
-
end
|
145
|
-
|
146
|
-
def non_enum_attribute
|
147
|
-
:condition
|
148
|
-
end
|
149
|
-
|
150
|
-
def record_with_array_values(column_type: :integer)
|
151
|
-
model = define_model(
|
152
|
-
:record_with_array_values,
|
153
|
-
enum_attribute => { type: column_type },
|
154
|
-
)
|
155
|
-
model.enum(enum_attribute => ['published', 'unpublished', 'draft'])
|
156
|
-
model.new
|
157
|
-
end
|
158
|
-
|
159
|
-
def record_with_hash_values
|
160
|
-
model = define_model(
|
161
|
-
:record_with_hash_values,
|
162
|
-
enum_attribute => { type: :integer },
|
163
|
-
)
|
164
|
-
model.enum(enum_attribute => { active: 0, archived: 1 })
|
165
|
-
model.new
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher, type: :model do
|
4
|
-
it 'accepts an existing database column' do
|
5
|
-
expect(model(nickname: :string)).to have_db_column(:nickname)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'rejects a nonexistent database column' do
|
9
|
-
expect(define_model(:employee).new).not_to have_db_column(:nickname)
|
10
|
-
end
|
11
|
-
|
12
|
-
context '#of_type' do
|
13
|
-
it 'accepts a column of correct type' do
|
14
|
-
expect(model(nickname: :string)).
|
15
|
-
to have_db_column(:nickname).of_type(:string)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'rejects a nonexistent database column' do
|
19
|
-
expect(define_model(:superhero).new).
|
20
|
-
not_to have_db_column(:nickname).of_type(:string)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'rejects a column of wrong type' do
|
24
|
-
expect(model(nickname: :integer)).
|
25
|
-
not_to have_db_column(:nickname).of_type(:string)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with precision option' do
|
30
|
-
it 'accepts a column of correct precision' do
|
31
|
-
expect(with_table(:salary, :decimal, precision: 5)).
|
32
|
-
to have_db_column(:salary).with_options(precision: 5)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'rejects a column of wrong precision' do
|
36
|
-
expect(with_table(:salary, :decimal, precision: 6)).
|
37
|
-
not_to have_db_column(:salary).with_options(precision: 5)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with limit option' do
|
42
|
-
it 'accepts a column of correct limit' do
|
43
|
-
expect(with_table(:email, :string, limit: 255)).
|
44
|
-
to have_db_column(:email).with_options(limit: 255)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'rejects a column of wrong limit' do
|
48
|
-
expect(with_table(:email, :string, limit: 100)).
|
49
|
-
not_to have_db_column(:email).with_options(limit: 255)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with default option' do
|
54
|
-
it 'accepts a column with correct default' do
|
55
|
-
expect(with_table(:admin, :boolean, default: false)).
|
56
|
-
to have_db_column(:admin).with_options(default: false)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'rejects a column with wrong default' do
|
60
|
-
expect(with_table(:admin, :boolean, default: true)).
|
61
|
-
not_to have_db_column(:admin).with_options(default: false)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'with null option' do
|
66
|
-
it 'accepts a column of correct null' do
|
67
|
-
expect(with_table(:admin, :boolean, null: false)).
|
68
|
-
to have_db_column(:admin).with_options(null: false)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'rejects a column of wrong null' do
|
72
|
-
expect(with_table(:admin, :boolean, null: true)).
|
73
|
-
not_to have_db_column(:admin).with_options(null: false)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'with scale option' do
|
78
|
-
it 'accepts a column of correct scale' do
|
79
|
-
expect(with_table(:salary, :decimal, precision: 10, scale: 2)).
|
80
|
-
to have_db_column(:salary).with_options(scale: 2)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'rejects a column of wrong scale' do
|
84
|
-
expect(with_table(:salary, :decimal, precision: 10, scale: 4)).
|
85
|
-
not_to have_db_column(:salary).with_options(scale: 2)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'with primary option' do
|
90
|
-
it 'accepts a column that is primary' do
|
91
|
-
expect(with_table(:custom_id, :integer, primary: true)).
|
92
|
-
to have_db_column(:id).with_options(primary: true)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'rejects a column that is not primary' do
|
96
|
-
expect(with_table(:whatever, :integer, primary: false)).
|
97
|
-
not_to have_db_column(:whatever).with_options(primary: true)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def model(options = {})
|
102
|
-
define_model(:employee, options).new
|
103
|
-
end
|
104
|
-
|
105
|
-
def with_table(column_name, column_type, options)
|
106
|
-
create_table 'employees' do |table|
|
107
|
-
table.__send__(column_type, column_name, options)
|
108
|
-
end
|
109
|
-
define_model_class('Employee').new
|
110
|
-
end
|
111
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher, type: :model do
|
4
|
-
context 'have_db_index' do
|
5
|
-
it 'accepts an existing index' do
|
6
|
-
expect(with_index_on(:age)).to have_db_index(:age)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'rejects a nonexistent index' do
|
10
|
-
expect(define_model(:employee).new).not_to have_db_index(:age)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'have_db_index with unique option' do
|
15
|
-
it 'accepts an index of correct unique' do
|
16
|
-
expect(with_index_on(:ssn, unique: true)).
|
17
|
-
to have_db_index(:ssn).unique(true)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'rejects an index of wrong unique' do
|
21
|
-
expect(with_index_on(:ssn, unique: false)).
|
22
|
-
not_to have_db_index(:ssn).unique(true)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'have_db_index on multiple columns' do
|
27
|
-
it 'accepts an existing index' do
|
28
|
-
db_connection = create_table 'geocodings' do |table|
|
29
|
-
table.integer :geocodable_id
|
30
|
-
table.string :geocodable_type
|
31
|
-
end
|
32
|
-
db_connection.add_index :geocodings, [:geocodable_type, :geocodable_id]
|
33
|
-
expect(define_model_class('Geocoding').new).
|
34
|
-
to have_db_index([:geocodable_type, :geocodable_id])
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'rejects a nonexistent index' do
|
38
|
-
create_table 'geocodings' do |table|
|
39
|
-
table.integer :geocodable_id
|
40
|
-
table.string :geocodable_type
|
41
|
-
end
|
42
|
-
expect(define_model_class('Geocoding').new).
|
43
|
-
not_to have_db_index([:geocodable_type, :geocodable_id])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'join columns with and when describing multiple columns' do
|
48
|
-
expect(have_db_index([:user_id, :post_id]).description).to match(/on columns user_id and post_id/)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'describes a unique index as unique' do
|
52
|
-
expect(have_db_index(:user_id).unique(true).description).to match(/a unique index/)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'describes a unique index as unique when no argument is given' do
|
56
|
-
expect(have_db_index(:user_id).unique.description).to match(/a unique index/)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'describes a non-unique index as non-unique' do
|
60
|
-
expect(have_db_index(:user_id).unique(false).description).to match(/a non-unique index/)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "does not display an index's uniqueness when it's not important" do
|
64
|
-
expect(have_db_index(:user_id).description).not_to match(/unique/)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'allows an IndexDefinition to have a truthy value for unique' do
|
68
|
-
index_definition = double(
|
69
|
-
'ActiveRecord::ConnectionAdapters::IndexDefinition',
|
70
|
-
unique: 7,
|
71
|
-
name: :age
|
72
|
-
)
|
73
|
-
matcher = have_db_index(:age).unique(true)
|
74
|
-
allow(matcher).to receive(:matched_index).and_return(index_definition)
|
75
|
-
|
76
|
-
expect(with_index_on(:age)).to matcher
|
77
|
-
end
|
78
|
-
|
79
|
-
def with_index_on(column_name, index_options = {})
|
80
|
-
create_table 'employees' do |table|
|
81
|
-
table.integer column_name
|
82
|
-
end.add_index(:employees, column_name, index_options)
|
83
|
-
define_model_class('Employee').new
|
84
|
-
end
|
85
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher, type: :model do
|
4
|
-
context 'a read-only attribute' do
|
5
|
-
it 'accepts' do
|
6
|
-
expect(with_readonly_attr).to have_readonly_attribute(:attr)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'an attribute that is not part of the read-only set' do
|
11
|
-
it 'rejects being read-only' do
|
12
|
-
model = define_model :example, attr: :string, other: :string do
|
13
|
-
attr_readonly :attr
|
14
|
-
end.new
|
15
|
-
|
16
|
-
expect(model).not_to have_readonly_attribute(:other)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'an attribute on a class with no readonly attributes' do
|
21
|
-
it 'rejects being read-only' do
|
22
|
-
expect(define_model(:example, attr: :string).new).
|
23
|
-
not_to have_readonly_attribute(:attr)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'assigns a failure message' do
|
27
|
-
model = define_model(:example, attr: :string).new
|
28
|
-
matcher = have_readonly_attribute(:attr)
|
29
|
-
|
30
|
-
matcher.matches?(model)
|
31
|
-
|
32
|
-
expect(matcher.failure_message).not_to be_nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def with_readonly_attr
|
37
|
-
define_model :example, attr: :string do
|
38
|
-
attr_readonly :attr
|
39
|
-
end.new
|
40
|
-
end
|
41
|
-
end
|