-
-
Save edavis10/1135390 to your computer and use it in GitHub Desktop.
Refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_status_changes | |
return if changes.keys == ["status"] | |
return if changes["status"].present? && changes["status"].second == "open" | |
return if changes["status"].present? && changes["status"].first == "open" | |
errors.add_to_base(:cant_update_locked_deliverable) if locked? | |
errors.add_to_base(:cant_update_closed_deliverable) if closed? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_status_changes | |
if changes.keys == ["status"] | |
noop("Allow changes to the status only") | |
elsif changes["status"].present? && changes["status"].second == "open" | |
noop("Allow any changes when going to 'open'") | |
elsif changes["status"].present? && changes["status"].first == "open" | |
noop("Allow any changes when going from 'open' to another status") | |
else | |
errors.add_to_base(:cant_update_locked_deliverable) if locked? | |
errors.add_to_base(:cant_update_closed_deliverable) if closed? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That got me unblocked, here is what I came up with (tests all green)