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

Moved error messages to translation file #899

wants to merge 4 commits into from

Conversation

nileshgulia1
Copy link

Related issue #878

Error messages are moved to en.yml file.Tests are also passing.

Copy link
Member

@emcoding emcoding left a comment

Choose a reason for hiding this comment

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

Hi @nileshgulia! Congrats with your first contribution to the RGSoC Teams app! 🎉
This is a great start!
I propose alternatives for the error messages names. In general, we aim for readability, and also keep them in line with the existing Rails error names where possible.

@@ -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, :multiple_sel_error)
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this: 'too_many_selected' ? For better readability :-) and dev happiness 🎁
Sorry, I know I said to use 'error' in the key before. But now that I see them all together, it doesn't looks so nice.

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, :must_accepted)
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this: none_accepted ?

Copy link
Author

Choose a reason for hiding this comment

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

yeah,sure 👍

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, :one_app_allowed)
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this too_many_applications?

@@ -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, :confirmed_email_address)
Copy link
Member

Choose a reason for hiding this comment

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

How about: unconfirmed_email_address.

@@ -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, :wrong_date_sel)
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this more expressive, maybe reference the method name : 'chronology_violation'

application_draft:
attributes:
projects:
must_accepted: must have been accepted
Copy link
Member

Choose a reason for hiding this comment

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

As this is a yml file, you can collect similar values under the same key. So, you can reuse the keys:

errors:  
    models:  
        todo:   
            .....  
        application_draft:

from line 86 and 87.
(See for an example how all the time formats are collected in line 6 and after. )

In the same way, you can put the message in line 105 right after the message in current line 99.
That goes for the rest of the file as well. I'll leave that for you to try. So I won't point out all the changes.
Let me know if something is unclear!

Copy link
Member

Choose a reason for hiding this comment

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

Also, can you follow the same indentation as the rest of the file? It seems not to be super consistent, with sometimes 4 and sometimes 2 spaces. At first sight, it looks like it is easy to copy the same indentations.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for being patient.I need another help :)

        models:
          todo:
          application_draft:
          conference:
          team:
          user:
            attributes:
              user:
                too_many_reviewers: too many reviewers
              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.
              ends_on:
                chronology_violation: must be a later date than start date
              roles:
                too_many_students: there cannot be more than 2 students on a team.
              github_handle:
                immutabilty_violation: can't be changed

What's wrong with this code, my local tests are failing?

Copy link
Member

Choose a reason for hiding this comment

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

No worries :-) We've all been there! I really appreciate your effort.

Take a look at this: http://docs.ansible.com/ansible/latest/YAMLSyntax.html
You should collect the attributes for each key.
Like this:

errors:  
    models:  
        todo:   
            attributes:
                user:
                    too_many_reviewers: too many reviewers
        application_draft:
              attributes:
                  projects:
                      must_accepted: must have been accepted
                      # other error messages for projects here
                  #other_attribute:
                      #error messages on other_attribute 
       #yet another model:
              attributes:
                   #etc
 

Does that make sense?

Copy link
Author

Choose a reason for hiding this comment

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

Yes,exactly I have already written the above code you mentioned earlier, but this is not showing in the changes .please check my latest commit 9dba120

.env-example Outdated
CAMO_KEY=supersecret

# Google Maps API key for e.g. city autocomplete
GOOGLE_MAPS_API_KEY=YourGoogleMapsAPIKey
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to remove this file from the repo. (I don't think you need to remove it locally, either 🤔 ).
Anyway, removing it should not be part of this PR.

Copy link
Author

Choose a reason for hiding this comment

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

yes,sorry for that,the file got accidentally removed ,will add it back now :)

production:
adapter: postgresql
database: rgsocteams_production
host: localhost
Copy link
Member

Choose a reason for hiding this comment

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

Same as for the other removed file: we don't want this file removed. Can you leave the removal out of this PR please?

Copy link
Author

Choose a reason for hiding this comment

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

yeah,sure :)

@@ -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, :can't_be_changed) if changes_include?(:github_handle)
end

Copy link
Member

Choose a reason for hiding this comment

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

Remove this whiteline please.

github_handle:
can't_be_changed: can't be changed


Copy link
Member

Choose a reason for hiding this comment

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

And remove the redundant whitelines please

Copy link
Author

@nileshgulia1 nileshgulia1 left a comment

Choose a reason for hiding this comment

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

made some changes

.env-example Outdated
CAMO_KEY=supersecret

# Google Maps API key for e.g. city autocomplete
GOOGLE_MAPS_API_KEY=YourGoogleMapsAPIKey
Copy link
Author

Choose a reason for hiding this comment

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

yes,sorry for that,the file got accidentally removed ,will add it back now :)

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, :must_accepted)
Copy link
Author

Choose a reason for hiding this comment

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

yeah,sure 👍

production:
adapter: postgresql
database: rgsocteams_production
host: localhost
Copy link
Author

Choose a reason for hiding this comment

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

yeah,sure :)

Copy link
Author

@nileshgulia1 nileshgulia1 left a comment

Choose a reason for hiding this comment

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

@F3PiX please review

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 :)

Copy link
Member

@emcoding emcoding left a comment

Choose a reason for hiding this comment

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

Great jump!
The two unchanged files shouldn't be part of this PR. Depending on how comfortable you are with using git; the quickest solution might be: close this PR, open a new one and copy the changes you made in the files concerning the error messages.
Otherwise : 👍 Great way to say goodbye to the old year ;-)

@nileshgulia1
Copy link
Author

@F3PiX thanks for the help so far,I will close the PR for now and will submit a clean PR soon :)

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

Successfully merging this pull request may close these issues.

2 participants