thoughtbot/shoulda-matchers · error · ActiveModel::CouldNotSetPasswordError

The validation failed because your #{model_name} model decla

Error message

The validation failed because your #{model_name} model declares `has_secure_password`, and
`validate_presence_of` was called on a #{record_name} which has `password` already set to a value.
Please use a #{record_name} with an empty `password` instead.

What it means

Error "The validation failed because your #{model_name} model declares `has_secure_password`, and `validate_presence_of` was called on a #{record_name} which has `password` already set to a value. Please use a #{record_name} with an empty `password` instead." thrown in thoughtbot/shoulda-matchers.

Source

Thrown at lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb:272

        end

        def secure_password_being_validated?
          Shoulda::Matchers::RailsShim.digestible_attribute?(
            @subject,
            @attribute,
          )
        end

        def possibly_ignore_interference_by_writer
          if secure_password_being_validated? && RailsShim.active_model_lt_7?
            ignore_interference_by_writer.default_to(when: :blank?)
          end
        end

        def allows_and_double_checks_value_of!(value)
          allows_value_of(value, @expected_message)
        rescue ActiveModel::AllowValueMatcher::AttributeChangedValueError
          raise ActiveModel::CouldNotSetPasswordError.create(model)
        end

        def allows_original_or_typecast_value?(value)
          allows_value_of(value, @expected_message)
        end

        def disallows_and_double_checks_value_of!(value)
          disallows_value_of(value, @expected_message)
        rescue ActiveModel::AllowValueMatcher::AttributeChangedValueError
          raise ActiveModel::CouldNotSetPasswordError.create(model)
        end

        def disallows_original_or_typecast_value?(value)
          disallows_value_of(value, @expected_message)
        end

        def disallowed_values
          if collection_association?

View on GitHub (pinned to 79cdfbc326)

When it happens

Trigger: Thrown at lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb:272 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/cb4574148312e74b. Report an issue: GitHub.