Skip to content

Commit

Permalink
12511: loudly fail if there are no OS CSV headers available
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperka committed Dec 27, 2023
1 parent d9c7498 commit 31468e0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/controllers/option_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def show

def export
send_data(generate_csv, filename: "#{@option_set.name}.csv")
rescue MissingTranslationError
flash[:error] = t("activerecord.errors.models.option.missing_level_translation", locale_name: I18n.locale)
redirect_to(request.referer) # Reload page.
end

# always via AJAX
Expand Down
5 changes: 5 additions & 0 deletions app/models/missing_translation_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

# Error when translations are missing.
class MissingTranslationError < StandardError
end
4 changes: 3 additions & 1 deletion app/models/option_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def headers_for_export

if multilevel?
# use the level names as column headings for a multi-level option set
headers.concat(levels.map(&:name))
names = levels.map(&:name)
raise MissingTranslationError if names.any?(&:blank?)
headers.concat(names)
else
# the human-readable name for the Option.name attribute otherwise (e.g. "Name")
headers << Option.human_attribute_name(:name)
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ en:
option:
cant_delete_if_has_response: "You can't delete this Option because it is included in at least one Response."
names_cant_be_all_blank: "At least one name translation must be given for each option."
missing_level_translation: "Missing default '%{locale_name}' translation for option level names."
names_too_long: "Names must be at most 30 characters in length."
invalid_coordinates: "The provided coordinates are not valid."
option_set:
Expand Down

0 comments on commit 31468e0

Please sign in to comment.