a guest Feb 15th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #app/models/season_storage.rb
  3. before_validation :sanitize_inputs
  4. ...  
  5. validates :storage_id, uniqueness: { scope: :epoch }
  6. validates :epoch, presence: true
  7. validates :epoch, format: /A20[0-9]{2}-(spring|autumn)Z/
  8. ...
  9. def sanitize_inputs
  10.   storage_id.upcase!
  11. end
  15. #spec/models/season_storage.rb
  17. it { validate_uniqueness_of(:storage_id).ignoring_case_sensitivity.scoped_to(:epoch) }
  19. Failure/Error: it { validate_uniqueness_of(:storage_id).ignoring_case_sensitivity.scoped_to(:epoch) }              
  21.        Expected SeasonStorage to validate that :storage_id is unique within the                                                        
  22.        scope of :epoch, but this could not be proved.
  23.          After taking the given SeasonStorage, setting its :storage_id to                                                              
  24.          ‹"dummy value"›, and saving it as the existing record, then making a                                                          
  25.          new SeasonStorage and setting its :storage_id to ‹"dummy value"› (read                                                        
  26.          back as ‹"DUMMY VALUE"›) as well e its :epoch to a different value,                                                          
  27.          ‹nil›, the matcher expected the new SeasonStorage to be invalid, but                                                          
  28.          it was valid instead.
  30.          As indicated in the message above, :storage_id seems to be changing                                                          
  31.          certain values as they are set, and this could have something to do                                                          
  32.          with why this test is failing. If you or something else has overridden                                                        
  33.          the writer method for this attribute to normalize values by changing                                                          
  34.          their case in any way (for instance, ensuring that the attribute is                                                          
  35.          always downcased), then try adding `ignoring_case_sensitivity` onto                                                          
  36.          the end of the uniqueness matcher. Otherwise, you may need to write                                                          
  37.          the test yourself, or do something different altogether.
  39. as well e its :epoch to a different value,                                                          
  40. ‹nil›, the matcher expected the new SeasonStorage to be invalid, but                                                          
  41. it was valid instead
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand