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

Chore: Rename Validator Classes #982

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Activity < ApplicationRecord
validates :action, presence: true, inclusion: { in: %w[create update destroy] }
validates :project, presence: true
validates :user, presence: true
validates :subject, presence: true, subject_changed: true
validates :subject, presence: true, changed: true

serialize :subject_changes, Hash

Expand Down
6 changes: 3 additions & 3 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def from_csv_row(row)
enumerize :story_type, in: STORY_TYPES, predicates: true, scope: true
validates :project, presence: true
validates :title, presence: true
validates :requested_by_id, user_belongs_to_project: true
validates :owned_by_id, user_belongs_to_project: true
validates :requested_by_id, belongs_to_project: true
validates :owned_by_id, belongs_to_project: true
validates :story_type, presence: true
validates :estimate, central_estimate: true, allow_nil: true
validates :estimate, estimate: true, allow_nil: true
validate :validate_non_estimable_story

def self.csv_headers
Expand Down
11 changes: 11 additions & 0 deletions app/validators/belongs_to_project_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class BelongsToProjectValidator < ActiveModel::EachValidator
# Checks that the parameter being validated represents a User#id that
# is a member of the object.project
def validate_each(record, attribute, value)
return if record.project.blank? || value.blank?

return if record.project.user_ids.include?(value)

record.errors.add(attribute, message: 'user is not a member of this project')
end
end
11 changes: 0 additions & 11 deletions app/validators/central_estimate_validator.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# TODO: Change the class name to ChangedValidator when remove cm42-central-support gem
class SubjectChangedValidator < ActiveModel::EachValidator
class ChangedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if record.action != 'update'
return if record.action != 'update'
return if value&.valid? && value&.saved_changes.present?

record.errors.add(attribute, message: (options[:message] || "Record didn't change"))
end
end
10 changes: 10 additions & 0 deletions app/validators/estimate_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class EstimateValidator < ActiveModel::EachValidator
# Checks that the estimate being validated is valid for record.project
def validate_each(record, attribute, value)
return if record.project.blank?

return if record.project.point_values.include?(value)

record.errors.add(attribute, message: 'is not an allowed value for this project')
end
end
12 changes: 0 additions & 12 deletions app/validators/user_belongs_to_project_validator.rb

This file was deleted.

Loading