-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure .valid? called only once #125
Comments
Good catch! If I understand you correctly, this example shows what you're talking about: class ClearArray < ActiveInteraction::Base
array :array
validate { errors.add(:array, 'is empty') if array.empty? }
def execute
array.clear
end
end ClearArray.run!(array: [1, 2, 3])
# => ActiveInteraction::InvalidInteractionError: Array is empty outcome = ClearArray.run(array: [1, 2, 3])
outcome.valid?
# => nil interaction = ClearArray.new(array: [1, 2, 3])
interaction.valid?
# => true
interaction.execute
# => []
interaction.valid?
# => nil |
Yes. And your examples in the README should better use errors.empty? or something of the like. |
I think this is a bug. You should be calling |
You are right. What I meant was a way of asking The way I do it now is:
I hope I make sense :). |
Ah language. I think you already caught my drift. |
Fixed in version 1.0.1. Thanks for reporting this! |
I ran into an issue where the execute code changes the conditions for an interaction to be valid.
For instance uniqueness of something. When .valid? is called again, after execute, these conditions are not valid anymore.
The text was updated successfully, but these errors were encountered: