Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #app/models/season_storage.rb
- before_validation :sanitize_inputs
- ...
- validates :storage_id, uniqueness: { scope: :epoch }
- validates :epoch, presence: true
- validates :epoch, format: /A20[0-9]{2}-(spring|autumn)Z/
- ...
- def sanitize_inputs
- storage_id.upcase!
- end
- #spec/models/season_storage.rb
- it { is_expected.to validate_uniqueness_of(:storage_id).ignoring_case_sensitivity.scoped_to(:epoch) }
- Failure/Error: it { is_expected.to validate_uniqueness_of(:storage_id).ignoring_case_sensitivity.scoped_to(:epoch) }
- Expected SeasonStorage to validate that :storage_id is unique within the
- scope of :epoch, but this could not be proved.
- After taking the given SeasonStorage, setting its :storage_id to
- ‹"dummy value"›, and saving it as the existing record, then making a
- new SeasonStorage and setting its :storage_id to ‹"dummy value"› (read
- back as ‹"DUMMY VALUE"›) as well e its :epoch to a different value,
- ‹nil›, the matcher expected the new SeasonStorage to be invalid, but
- it was valid instead.
- As indicated in the message above, :storage_id seems to be changing
- certain values as they are set, and this could have something to do
- with why this test is failing. If you or something else has overridden
- the writer method for this attribute to normalize values by changing
- their case in any way (for instance, ensuring that the attribute is
- always downcased), then try adding `ignoring_case_sensitivity` onto
- the end of the uniqueness matcher. Otherwise, you may need to write
- the test yourself, or do something different altogether.
- as well e its :epoch to a different value,
- ‹nil›, the matcher expected the new SeasonStorage to be invalid, but
- it was valid instead
Add Comment
Please, Sign In to add comment