Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inclusion to correctly disallow outside values #1135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ is now:
* *PR: [#1073]*
* *Original issue: [#949]*

* Fix `validate_inclusion_of` so that if it fails, it will no longer blow up
with the error "undefined method \`attribute_setter' for nil:NilClass".

* *Original issue: [#904]*

### Features

* Add `required` and `optional` qualifiers to `belong_to` and `have_one`
Expand Down Expand Up @@ -143,6 +148,7 @@ is now:
[#961]: https://github.com/thoughtbot/shoulda-matchers/issues/961
[795ca68]: https://github.com/thoughtbot/shoulda-matchers/commit/795ca688bff08590dbd2ab6f2b51ea415e0c7473
[#1089]: https://github.com/thoughtbot/shoulda-matchers/pulls/1089
[#904]: https://github.com/thoughtbot/shoulda-matchers/issues/904

### Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ def disallows_value_outside_of_array?
end
end

!values_outside_of_array.any? do |value|
allows_value_of(value, @low_message)
values_outside_of_array.all? do |value|
disallows_value_of(value, @low_message)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,21 @@ def configure_validation_matcher(matcher)

define_method(:valid_values) { args.fetch(:possible_values) }

it 'does not match a record with no validations' do
builder = build_object
expect_not_to_match_on_values(builder, possible_values)
context 'when the record has no validations' do
it 'passes when used in the negative' do
builder = build_object
expect_not_to_match_on_values(builder, possible_values)
end

it 'fails when used in the positive with an appropriate failure message' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]

builder = build_object

assertion = lambda do
expect_to_match_on_values(builder, possible_values)
end

expect(&assertion).to fail
end
end

it 'matches given the same array of valid values' do
Expand Down
3 changes: 3 additions & 0 deletions spec/unit_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative 'support/unit/load_environment'

require 'rspec/rails'
require 'rspec/matchers/fail_matchers'
require 'shoulda-matchers'

require 'spec_helper'
Expand All @@ -10,6 +11,8 @@
end

RSpec.configure do |config|
config.include RSpec::Matchers::FailMatchers

UnitTests::ActionPackVersions.configure_example_group(config)
UnitTests::ActiveModelHelpers.configure_example_group(config)
UnitTests::ActiveModelVersions.configure_example_group(config)
Expand Down