Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Moved error messages to translation file #899

Closed
wants to merge 4 commits into from
Closed
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 .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ CAMO_HOST=https://rgsoc-teams-camo.herokuapp.com
CAMO_KEY=supersecret

# Google Maps API key for e.g. city autocomplete
GOOGLE_MAPS_API_KEY=YourGoogleMapsAPIKey
GOOGLE_MAPS_API_KEY=YourGoogleMapsAPIKey
8 changes: 4 additions & 4 deletions app/models/application_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ def ready?

def different_projects_required
if project1 && project1 == project2
errors.add(:projects, 'must not be selected twice')
errors.add(:projects, :too_many_selected)
end
end

def accepted_projects_required
if projects.any? { |p| p && !p.accepted? } # if they don't exist, the presence validation will handle it
errors.add(:projects, 'must have been accepted')
errors.add(:projects, :none_accepted)
end
end

def only_one_application_draft_allowed
unless team.application_drafts.where(season: season).none?
errors.add(:base, 'Only one application may be lodged')
errors.add(:base, :too_many_applications)
end
end

Expand All @@ -195,7 +195,7 @@ def set_current_season

def students_confirmed?
unless team.present? && team.students.all?{|student| student.confirmed? }
errors.add(:base, 'Please make sure every student confirmed the email address.')
errors.add(:base, :unconfirmed_email_address)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def date_range

def chronological_dates
unless starts_on <= ends_on
errors.add(:ends_on, 'must be a later date than start date')
errors.add(:ends_on, :chronology_violation)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def disallow_duplicate_members
def limit_number_of_students
students = roles.select{|r| r.name == 'student' && !r.marked_for_destruction?}
return unless students.size > 2
errors.add(:roles, 'there cannot be more than 2 students on a team.')
errors.add(:roles, :too_many_students)
end

def two_students_present?
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def complete_from_github

def immutable_github_handle
return if new_record?
errors.add(:github_handle, "can't be changed") if changes_include?(:github_handle)
errors.add(:github_handle, :immutabilty_violation) if changes_include?(:github_handle)
end

end
2 changes: 1 addition & 1 deletion config/database.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ test:
production:
adapter: postgresql
database: rgsocteams_production
host: localhost
host: localhost
21 changes: 21 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,24 @@ en:
attributes:
user:
too_many_reviewers: too many reviewers
application_draft:
attributes:
projects:
too_many_selected: must not be selected twice
none_accepted: must have been accepted
base:
too_many_applications: Only one application may be lodged
unconfirmed_email_address: Please make sure every student confirmed the email address.
conference:
attributes:
ends_on:
chronology_violation: must be a later date than start date
team:
attributes:
roles:
too_many_students: there cannot be more than 2 students on a team.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the team, two base errors are missing here. (line 175 and 183)

MSGS = {
duplicate_student_roles_singular: "%s already is a student on another team for #{Season.current.name}.",
duplicate_student_roles_plural: "%s already are students on another team for #{Season.current.name}."
}
def disallow_multiple_student_roles
students = User.with_role('student').joins(roles: :team).where(id: roles.map(&:user_id)).
where.not('roles.team_id' => id).where('teams.season_id' => season_id)
return if students.empty?
msg = MSGS[:"duplicate_student_roles_#{students.size == 1 ? 'singular' : 'plural'}"]
errors.add :base, msg % students.map(&:name).join(', ')
end
def disallow_duplicate_members
new_members = roles.map { |role| role.user }
duplicate_role_users = new_members.find_all { |member| new_members.count(member) > 1 }.uniq
return if duplicate_role_users.empty?
msg = "%s can't have more than one role in this team!"
errors.add :base, msg % duplicate_role_users.map(&:name).join(', ')
end

It is a bit more challenging than the other errors. Are you up to that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh,I guess I had missed it, I will have a look at it :)

user:
attributes:
github_handle:
immutabilty_violation: can't be changed