Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # from the fixture YAML file (listings.yml):
- bad_url:
- url: google
- #from my unit test -
- test "Should not save with bad url" do
- c = listings :bad_url
- assert !c.save
- end
- #from the model -
- validate :must_be_valid_url
- def must_be_valid_url
- uri = URI.parse(url)
- if uri.class != URI::HTTP
- errors.add(:url, 'Only HTTP protocol addresses can be used.')
- end
- rescue URI::InvalidURIError
- errors.add(:url, 'The format of the url is not valid.')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement