Skip to content
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

Adding an error doesn't mark the outcome as invalid #34

Closed
tfausak opened this issue Jul 17, 2013 · 1 comment · Fixed by #55
Closed

Adding an error doesn't mark the outcome as invalid #34

tfausak opened this issue Jul 17, 2013 · 1 comment · Fixed by #55
Assignees
Labels
Milestone

Comments

@tfausak
Copy link
Collaborator

tfausak commented Jul 17, 2013

class Interaction < ActiveInteraction::Base
  boolean :b
  def execute; errors.add(:b) end
end
p Interaction.run(b: true).valid?
# => true
@tfausak
Copy link
Collaborator Author

tfausak commented Jul 17, 2013

You shouldn't modify errors from within the execute method. Instead, define custom validators:

class Interaction < ActiveInteraction::Base
  boolean :b
  validate :v
  def v; errors.add(:b) end
  def execute; b end
end
p Interaction.run(b: true).valid?
# => false

The expected behavior for valid? is to clear custom errors. Check out this Stack Overflow question or the ActiveModel::Validations documentation. The documentation has the source for valid?, which includes:

errors.clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant