diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 0ce6426..0e44f19 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -17,7 +17,7 @@ _('%{value} is not a valid format') % { :value => data[:value] } end } - validates :plan, :format, presence: true + validates :plan, :format, presence: {message: _("can't be blank")} # Store settings with the exported plan so it can be recreated later # if necessary (otherwise the settings associated with the plan at a diff --git a/app/models/guidance.rb b/app/models/guidance.rb index f22cf3b..dfec5dc 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -25,7 +25,7 @@ - validates :text, presence: true + validates :text, presence: {message: _("can't be blank")} ## diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index 9686c27..96e6dab 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -13,7 +13,7 @@ attr_accessible :org_id, :name, :optional_subset, :published, :org, :guidances, :as => [:default, :admin] - validates :name, :org, presence: true + validates :name, :org, presence: {message: _("can't be blank")} # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/identifier_scheme.rb b/app/models/identifier_scheme.rb index 45b8922..d07aafc 100644 --- a/app/models/identifier_scheme.rb +++ b/app/models/identifier_scheme.rb @@ -2,5 +2,5 @@ has_many :user_identifiers has_many :users, through: :user_identifiers - validates :name, uniqueness: true, presence: true + validates :name, uniqueness: {message: _("must be unique")}, presence: {message: _("can't be blank")} end \ No newline at end of file diff --git a/app/models/language.rb b/app/models/language.rb index 3e5e3bd..2d02783 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -6,7 +6,8 @@ ## # Validations - validates :abbreviation, presence: true, uniqueness: true + # Cannot do FastGettext translations here because we constantize LANGUAGES in initializers/constants.rb + validates :abbreviation, presence: {message: "can't be blank"}, uniqueness: {message: "must be unique"} scope :sorted_by_abbreviation, -> { all.order(:abbreviation) } scope :default, -> { where(default_language: true).first } diff --git a/app/models/note.rb b/app/models/note.rb index 74b3078..4341c2a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -10,5 +10,5 @@ attr_accessible :text, :user_id, :answer_id, :archived, :archived_by, :answer, :user, :as => [:default, :admin] - validates :text, :answer, :user, presence: true + validates :text, :answer, :user, presence: {message: _("can't be blank")} end diff --git a/app/models/org.rb b/app/models/org.rb index 61e6691..3c23dcc 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -26,14 +26,14 @@ ## # Validators validates :contact_email, email: true, allow_nil: true - validates :name, presence: true, uniqueness: true + validates :name, presence: {message: _("can't be blank")}, uniqueness: {message: _("must be unique")} # allow validations for logo upload dragonfly_accessor :logo do after_assign :resize_image end - validates_property :height, of: :logo, in: (0..100) - validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'] - validates_size_of :logo, maximum: 500.kilobytes + validates_property :height, of: :logo, in: (0..100), message: _("height must be less than 100px") + validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'], message: _("must be one of the following formats: jpeg, jpg, png, gif, bmp") + validates_size_of :logo, maximum: 500.kilobytes, message: _("can't be larger than 500KB") ## # Define Bit Field values diff --git a/app/models/perm.rb b/app/models/perm.rb index 2bc5aad..58aad3e 100644 --- a/app/models/perm.rb +++ b/app/models/perm.rb @@ -8,7 +8,7 @@ # -relies on protected_attributes gem as syntax depricated in rails 4.2 #attr_accessible :name, :as => [:default, :admin] - validates :name, presence: true, uniqueness: true + validates :name, presence: {message: _("can't be blank")}, uniqueness: {message: _("must be unique")} ## # Constant perms diff --git a/app/models/phase.rb b/app/models/phase.rb index 88429fd..d3e813a 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -23,7 +23,7 @@ #friendly_id :title, use: [:slugged, :history, :finders] - validates :title, :number, :template, presence: true + validates :title, :number, :template, presence: {message: _("can't be blank")} diff --git a/app/models/question.rb b/app/models/question.rb index 4c0efdc..eac588d 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -27,7 +27,7 @@ :question_options, :suggested_answers, :answers, :themes, :modifiable, :option_comment_display, :as => [:default, :admin] - validates :text, :section, :number, presence: true + validates :text, :section, :number, presence: {message: _("can't be blank")} # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/question_format.rb b/app/models/question_format.rb index 3a08be8..061961a 100644 --- a/app/models/question_format.rb +++ b/app/models/question_format.rb @@ -7,7 +7,7 @@ enum formattype: [ :textarea, :textfield, :radiobuttons, :checkbox, :dropdown, :multiselectbox, :date ] attr_accessible :formattype - validates :title, presence: true, uniqueness: true + validates :title, presence: {message: _("can't be blank")}, uniqueness: {message: _("must be unique")} ## # Possibly needed for active_admin diff --git a/app/models/question_option.rb b/app/models/question_option.rb index 11552b0..84266ab 100644 --- a/app/models/question_option.rb +++ b/app/models/question_option.rb @@ -10,7 +10,7 @@ attr_accessible :text, :question_id, :is_default, :number, :question, :as => [:default, :admin] - validates :text, :question, :number, presence: true + validates :text, :question, :number, presence: {message: _("can't be blank")} ## # deep copy the given question_option and all it's associations diff --git a/app/models/region.rb b/app/models/region.rb index 2c57e79..a7e366a 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -3,6 +3,6 @@ belongs_to :super_region, class_name: 'Region' - validates :name, presence: true, uniqueness: true - validates :abbreviation, uniqueness: true, allow_nil: true + validates :name, presence: {message: _("can't be blank")}, uniqueness: {message: _("must be unique")} + validates :abbreviation, uniqueness: {message: _("must be unique")}, allow_nil: true end \ No newline at end of file diff --git a/app/models/role.rb b/app/models/role.rb index 75ad26c..a51177d 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -16,8 +16,8 @@ 4 => :commenter, # 8 column: 'access' - validates :user, :plan, :access, presence: true - validates :access, numericality: {greater_than: 0} + validates :user, :plan, :access, presence: {message: _("can't be blank")} + validates :access, numericality: {greater_than: 0, message: _("can't be less than zero")} ## # return the access level for the current project group diff --git a/app/models/section.rb b/app/models/section.rb index b88ee79..2a38972 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -14,7 +14,7 @@ :questions_attributes, :organisation, :phase, :modifiable, :as => [:default, :admin] - validates :phase, :title, :number, presence: true + validates :phase, :title, :number, presence: {message: _("can't be blank")} ## # return the title of the section diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index 91ce3aa..881f302 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -12,7 +12,7 @@ :org, :question, :as => [:default, :admin] - validates :question, :org, presence: true + validates :question, :org, presence: {message: _("can't be blank")} # EVALUATE CLASS AND INSTANCE METHODS BELOW # diff --git a/app/models/template.rb b/app/models/template.rb index 16b7ac4..de44b10 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -24,7 +24,7 @@ s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS end - validates :org, :title, :version, presence: true + validates :org, :title, :version, presence: {message: _("can't be blank")} # EVALUATE CLASS AND INSTANCE METHODS BELOW # diff --git a/app/models/theme.rb b/app/models/theme.rb index 315dfe8..bd787f6 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -13,7 +13,7 @@ attr_accessible :description, :title, :locale , :as => [:default, :admin] - validates :title, presence: true + validates :title, presence: {message: _("can't be blank")} # EVALUATE CLASS AND INSTANCE METHODS BELOW # diff --git a/app/models/token_permission_type.rb b/app/models/token_permission_type.rb index 71d4acb..5770e6c 100644 --- a/app/models/token_permission_type.rb +++ b/app/models/token_permission_type.rb @@ -12,7 +12,7 @@ ## # Validators - validates :token_type, presence: true, uniqueness: true + validates :token_type, presence: {message: _("can't be blank")}, uniqueness: {message: _("must be unique")} ## # Constant Token Permission Types diff --git a/app/models/user.rb b/app/models/user.rb index dc53469..ba37779 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -49,7 +49,9 @@ # :organisation, :language, :language_id, :org, :perms, # :confirmed_at, :org_id - validates :email, email: true, allow_nil: true, uniqueness: true + validates :email, email: true, allow_nil: true, uniqueness: {message: _("must be unique")} + validates :email, :password, presence: {message: _("can't be blank")} + ## # Settings diff --git a/app/models/user_identifier.rb b/app/models/user_identifier.rb index 6623765..840e394 100644 --- a/app/models/user_identifier.rb +++ b/app/models/user_identifier.rb @@ -5,5 +5,5 @@ # Should only be able to have one identifier per scheme! validates_uniqueness_of :identifier_scheme, scope: :user - validates :identifier, :user, :identifier_scheme, presence: true + validates :identifier, :user, :identifier_scheme, presence: {message: _("can't be blank")} end \ No newline at end of file diff --git a/config/locale/app.pot b/config/locale/app.pot index 6f79684..6f281bc 100644 --- a/config/locale/app.pot +++ b/config/locale/app.pot @@ -2933,4 +2933,10 @@ msgstr "" #years msgid "%{d} years" -msgstr "" \ No newline at end of file +msgstr "" + +# ActiveRecord model errors that we could not override in the model's validation definition +msgid "activerecord.errors.models.user.attributes.email.blank" +msgstr "can't be blank" +msgid "activerecord.errors.models.user.attributes.password.blank" +msgstr "can't be blank" \ No newline at end of file diff --git a/config/locale/de/app.po b/config/locale/de/app.po index 7176a36..a37ae09 100644 --- a/config/locale/de/app.po +++ b/config/locale/de/app.po @@ -2924,4 +2924,10 @@ msgstr "" #years msgid "%{d} years" +msgstr "" + +# ActiveRecord model errors that we could not override in the model's validation definition +msgid "activerecord.errors.models.user.attributes.email.blank" +msgstr "" +msgid "activerecord.errors.models.user.attributes.password.blank" msgstr "" \ No newline at end of file diff --git a/config/locale/en_GB/app.po b/config/locale/en_GB/app.po index 74ca475..d4bf139 100644 --- a/config/locale/en_GB/app.po +++ b/config/locale/en_GB/app.po @@ -2924,4 +2924,10 @@ msgstr "about a year" #years msgid "%{d} years" -msgstr "%{d} years" \ No newline at end of file +msgstr "%{d} years" + +# ActiveRecord model errors that we could not override in the model's validation definition +msgid "activerecord.errors.models.user.attributes.email.blank" +msgstr "can't be blank" +msgid "activerecord.errors.models.user.attributes.password.blank" +msgstr "can't be blank" \ No newline at end of file diff --git a/config/locale/en_US/app.po b/config/locale/en_US/app.po index 181c931..a6660d2 100644 --- a/config/locale/en_US/app.po +++ b/config/locale/en_US/app.po @@ -2924,4 +2924,10 @@ msgstr "about a year" #years msgid "%{d} years" -msgstr "%{d} years" \ No newline at end of file +msgstr "%{d} years" + +# ActiveRecord model errors that we could not override in the model's validation definition +msgid "activerecord.errors.models.user.attributes.email.blank" +msgstr "can't be blank" +msgid "activerecord.errors.models.user.attributes.password.blank" +msgstr "can't be blank" \ No newline at end of file diff --git a/config/locale/es/app.po b/config/locale/es/app.po index b67e612..a8b2cbe 100644 --- a/config/locale/es/app.po +++ b/config/locale/es/app.po @@ -2828,4 +2828,10 @@ msgstr "" #years msgid "%{d} years" +msgstr "" + +# ActiveRecord model errors that we could not override in the model's validation definition +msgid "activerecord.errors.models.user.attributes.email.blank" +msgstr "" +msgid "activerecord.errors.models.user.attributes.password.blank" msgstr "" \ No newline at end of file diff --git a/config/locale/fr/app.po b/config/locale/fr/app.po index 189cc3c..01dd7a9 100644 --- a/config/locale/fr/app.po +++ b/config/locale/fr/app.po @@ -2932,4 +2932,10 @@ msgstr "" #years msgid "%{d} years" +msgstr "" + +# ActiveRecord model errors that we could not override in the model's validation definition +msgid "activerecord.errors.models.user.attributes.email.blank" +msgstr "" +msgid "activerecord.errors.models.user.attributes.password.blank" msgstr "" \ No newline at end of file diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 7840311..05c9622 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ConfigurationHelper < ActionDispatch::IntegrationTest +class ConfigurationTest < ActionDispatch::IntegrationTest # -------------------------------------------------------------------- test "Make sure that all of the example YAML files have been setup properly" do diff --git a/test/missing_translation_test.rb b/test/missing_translation_test.rb new file mode 100644 index 0000000..53c81d9 --- /dev/null +++ b/test/missing_translation_test.rb @@ -0,0 +1,66 @@ +require 'test_helper' + +class MissingTranslationTest < ActionDispatch::IntegrationTest + + # -------------------------------------------------------------------- + test "Make sure that all FastGettext localisations are defined in the .pot/.po files" do + missing = [] + + # Scan through the /app directory for localisations + getFiles(Rails.root.join("app")).each do |file| + contents = File.open(file, 'r').read + localisations = contents.scan(/_\(['"][^\)]+['"]\)/) + + localisations.each do |localisation| + translation = _(localisation) + missing << localisation if translation.include?('translation missing') + end + end + + assert missing.empty?, "Found some missing translations: #{missing.join("\n")}" + missing = [] + + # Loop through all of the models and force all validation errors to be translated + dir = Rails.root.join("app", "models").to_s + getFiles(dir).each do |model| + unless model.start_with?('.') + name = model.gsub('.rb', '').gsub("#{dir}/", '').split('_').collect{|p| p.capitalize }.join('') + name = name.split('/').collect{|p| p }.join('::').gsub(/::[a-z]{1}/, &:upcase) + + # Skip the Settings module classes since they throw errors when validating + unless name.include?('Settings::') + clazz = name.split('::').inject(Object){ |o,c| o.const_get(c) } + obj = clazz.new + + unless obj.valid? + obj.errors.each do |e,m| + missing << m if _(m).include?('translation missing') + end + end + end + end + end + + assert missing.empty?, "Found some missing translations for model errors:\n #{missing.join("\n")}" + + end + + + private + # Recursively collect the file names within the directory and its subdirectories + # -------------------------------------------------------------------- + def getFiles(dir) + files = [] + Dir.foreach(dir) do |f| + unless f.start_with?('.') + if File.directory?("#{dir}/#{f}") + files << getFiles("#{dir}/#{f}") + else + files << "#{dir}/#{f}" + end + end + end + files.flatten.uniq + end + +end