To test image urls in a ruby project I can call a function as follows
validate_url("some_valid_url", "valid")
validate_url("inv#alid-url", "invalid")
The function looks like this:
def validate_url(image_url, state)
assert state === 'valid' ? new_product(image_url).valid? : new_product(image_url).invalid?,
"#{image_url} should always be " + state.upcase
end
is there a way to rewrite the line:
assert state === 'valid' ? new_product(image_url).valid? : new_product(image_url).invalid?
to something like
assert new_product(image_url).state.What-To-Do-Here?
which would then be equals to the following if state contains the string "valid"
assert new_product(image_url).valid?
new_product(image_url)return a state already? not sure I understood correctly: you method should returnvalidif URL is valid or "#{image_url} should always be " + state.upcase if it's invalid? - state being the argument that determining the validation of the URL?valid_url?(image_url).if..else