Rspec / shoulda: testing, that a custom validator is called

后端 未结 2 1804
陌清茗
陌清茗 2021-01-21 11:23

I have a custom validator (located in app/validators/uri_validator.rb) which is used in:

validates :link, uri: true

How do I specify this in my

2条回答
  •  粉色の甜心
    2021-01-21 12:20

    Use factory girl to build a model object with invalid data and one with valid data and call the be_valid matcher.

    #factory girl
    build(:model, link: valid_uri).should be_valid
    build(:model, link: invalid_uri).should_not be_valid
    

提交回复
热议问题