thoughtbot/shoulda-matchers · error · NonCaseSwappableValueError
Your #{model.name} model has a uniqueness validation on :#{a
Error message
Your #{model.name} model has a uniqueness validation on :#{attribute} which is
declared to be case-sensitive, but the value the uniqueness matcher used,
#{value.inspect}, doesn't contain any alpha characters, so using it to
test the case-sensitivity part of the validation is ineffective. There are
two possible solutions for this depending on what you're trying to do here:
a) If you meant for the validation to be case-sensitive, then you need to give
the uniqueness matcher a saved instance of #{model.name} with a value for
:#{attribute} that contains alpha characters.
b) If you meant for the validation to be case-insensitive, then you need to
add `case_sensitive: false` to the validation and add `case_insensitive` to
the matcher.
For more information, please see:
https://matchers.shoulda.io/docs/v#{Shoulda::Matchers::VERSION}/file.NonCaseSwappableValueError.html What it means
Error "Your #{model.name} model has a uniqueness validation on :#{attribute} which is declared to be case-sensitive, but the value the uniqueness matcher used, #{value.inspect}, doesn't contain any alpha characters, so using it to test the case-sensitivity part of the validation is ineffective. There are two possible solutions for this depending on what you're trying to do here: a) If you meant for the validation to be case-sensitive, then you need to give the uniqueness matcher a saved instance of #{model.name} with a value for :#{attribute} that contains alpha characters. b) If you meant for the validation to be case-insensitive, then you need to add `case_sensitive: false` to the validation and add `case_insensitive` to the matcher. For more information, please see: https://matchers.shoulda.io/docs/v#{Shoulda::Matchers::VERSION}/file.NonCaseSwappableValueError.html" thrown in thoughtbot/shoulda-matchers.
Source
Thrown at lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb:750
def does_not_match_uniqueness_without_scopes?
@failure_reason = nil
if existing_value_read.blank?
update_existing_record!(arbitrary_non_blank_value)
end
allows_value_of(existing_value_read, @expected_message)
end
def matches_uniqueness_with_case_sensitivity_strategy?
if should_test_case_sensitivity?
value = existing_value_read
swapcased_value = value.swapcase
if case_sensitivity_strategy == :sensitive
if value == swapcased_value
raise NonCaseSwappableValueError.create(
model:,
attribute: @attribute,
value:,
)
end
allows_value_of(swapcased_value, @expected_message)
else
disallows_value_of(swapcased_value, @expected_message)
end
else
true
end
end
def does_not_match_uniqueness_with_case_sensitivity_strategy?
if should_test_case_sensitivity?
@failure_reason = nilView on GitHub (pinned to 79cdfbc326)
When it happens
Trigger: Thrown at lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb:750 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of thoughtbot/shoulda-matchers@79cdfbc326 (2026-08-23).
Data as JSON: /api/errors/058163b799b12511.
Report an issue: GitHub.