-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor redundant status validation that raises exceptions #43
Copy link
Copy link
Open
Labels
good first issueGood for newcomersGood for newcomersrefactorStuff we should improveStuff we should improve
Description
Description
The Publishable concern has a validate_status_value method that raises an ArgumentError during validation. This breaks Rails conventions and is also redundant with the existing inclusion validation.
Current code
lib/bunko/models/post_methods/publishable.rb:41-46:
def validate_status_value
return if status.blank?
unless Bunko.configuration.valid_statuses.include?(status)
raise ArgumentError, "#{status} is not a valid status"
end
endProblems this causes
- Validators should add to
errors, not raise exceptions - Impossible to recover from - breaks form error handling
- The
inclusionvalidation on line 11-14 already handles this exact check - Inconsistent with how other validations work in the gem
- Users can't build forms with graceful error messages
Pros of refactoring
- Follows Rails validation conventions
- Allows graceful error handling in forms
- Removes duplicate validation logic
- Consistent behavior with other validations
- Cleaner, less code
Cons of refactoring
- None - the inclusion validation already provides this functionality
Recommended approach
Simply delete the validate_status_value method and the validate :validate_status_value callback. The existing inclusion validation already validates that status is in the configured list of valid statuses.
References
lib/bunko/models/post_methods/publishable.rb:41-46lib/bunko/models/post_methods/publishable.rb:11-14(existing inclusion validation)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomersrefactorStuff we should improveStuff we should improve