diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 36e1c65..92f38e3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -2,7 +2,7 @@ # Build variable column headings for the project list # -------------------------------------------------------- - def project_list_column_heading(column) + def plan_list_column_heading(column) if column.kind_of?(Array) heading = (column.first.kind_of?(String) ? column.first : t("helpers.project.columns.unknown")) @@ -26,13 +26,13 @@ klass, content = case col when 'name' - [ "dmp_td_big", link_to(plan.title, plan_path(plan), class: "dmp_table_link") ] + [ "dmp_td_big", link_to(plan.title, plan_path(I18n.locale, plan), class: "dmp_table_link") ] when 'owner' user = plan.owner text = if user.nil? - "Unknown" + t("helpers.settings.unknown") elsif user == current_user t("helpers.me") else @@ -45,19 +45,19 @@ text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") [ "dmp_td_small", text ] when 'visibility' - ["dmp_td_small", (plan.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{project.visibility}"))] + ["dmp_td_small", (plan.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{plan.visibility}"))] when 'last_edited' [ "dmp_td_small", l(plan.latest_update.to_date, formats: :short) ] when 'description' - [ "dmp_td_medium", (plan.try(col) || "Unknown") ] + [ "dmp_td_medium", (plan.try(col) || t("helpers.settings.unknown")) ] when 'non_link_name' [ "dmp_td_big", plan.title ] when 'template' ["dmp_td_big", plan.template.title] when 'organisation' - ["dmp_td_medium", (plan.org.nil? ? plan.owner.org.name : plan.org.name)] + ["dmp_td_medium", (plan.owner.org.nil? ? t("helpers.settings.unknown") : plan.owner.org.name) ] else - [ "dmp_td_small", (plan.try(col) || "Unknown") ] + [ "dmp_td_small", (plan.try(col) || t("helpers.settings.unknown")) ] end content_tag(:td, content, class: klass) diff --git a/app/views/plans/_plan_list_head.html.erb b/app/views/plans/_plan_list_head.html.erb index efb2503..c924411 100644 --- a/app/views/plans/_plan_list_head.html.erb +++ b/app/views/plans/_plan_list_head.html.erb @@ -1,6 +1,6 @@ <% @selected_columns.each do |column| %> - <%= project_list_column_heading(column) %> + <%= plan_list_column_heading(column) %> <% end %> <%= t("helpers.select_action")%> diff --git a/app/views/static_pages/public_plans.html.erb b/app/views/static_pages/public_plans.html.erb index 03c2159..0e1dda0 100644 --- a/app/views/static_pages/public_plans.html.erb +++ b/app/views/static_pages/public_plans.html.erb @@ -13,7 +13,7 @@ <% ['name', 'template', 'organisation', 'owner'].each do |column| %> - <%= project_list_column_heading(column) %> + <%= plan_list_column_heading(column) %> <% end %> @@ -22,7 +22,7 @@ <% @plans.each do |plan| %> <% ['non_link_name', 'template', 'organisation', 'owner'].each do |column| %> - <%= project_list_column_body(column, plan) %> + <%= plant_list_column_body(column, plan) %> <% end %> diff --git a/config/locales/de.yml b/config/locales/de.yml index d010da5..07037bf 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -625,6 +625,7 @@ settings: title: "Einstellungen" + unknown: "Unbekannt" projects: title: "Einstellungen - Meine Pläne" desc: "Die untere Tabelle listet die verfügbaren Spalten auf, welche in der Liste 'Meine Pläne' gezeigt werden können. diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 45caa75..a99a922 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -695,6 +695,7 @@ settings: title: "Settings" + unknown: "Unknown" projects: title: "Settings - My plans" desc: "The table below lists the available columns that can be shown on the 'My plans' list. Choose which you would like to appear." diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 2d9b60b..bf5d52a 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -675,6 +675,7 @@ settings: title: "Settings" + unknown: "Unknown" projects: title: "Settings - My plans" desc: "The table below lists the available columns that can be shown on the 'My plans' list. Choose which you would like to appear." diff --git a/config/locales/es.yml b/config/locales/es.yml index a7e52e5..cf520e7 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -551,6 +551,7 @@ settings: title: "Preferencias" + unknown: "Desconocido" projects: title: "Preferencias - Mis planes" desc: "La siguiente tabla muestra las columnas que pueden mostrarse en la lista 'Mis planes'. Elija cuales quiere que se muestren." diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d045462..e8ec81e 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -565,6 +565,7 @@ settings: title: "Réglages" + unknown: "Inconnu" projects: title: "Réglages - Mes plans" desc: "Le tableau suivant donne la liste des colonnes que lon peut faire apparaître dans la liste Mes Plans. Choisissez celles que vous voulez voir." diff --git a/test/functional/answers_controller_test.rb b/test/functional/answers_controller_test.rb index a671b57..fdd684f 100644 --- a/test/functional/answers_controller_test.rb +++ b/test/functional/answers_controller_test.rb @@ -68,7 +68,7 @@ follow_redirects assert_response :success - assert_select '.main_page_content h1', Plan.model_name.human.pluralize.titleize + assert_select '.main_page_content h1', I18n.t("helpers.project.projects_title") end end \ No newline at end of file diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 0eb97aa..11aec2a 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -23,8 +23,8 @@ assert_equal nil, resource.id, "Expected resource() to return a User with an Id" # If @resource is set then we should receive that object - @resource = Organisation.first - assert resource.is_a?(Organisation), "Expected resource() to return @resource" + @resource = Org.first + assert resource.is_a?(Org), "Expected resource() to return @resource" assert_equal @resource.id, resource.id, "Expected resource() to return the first Organisation" end diff --git a/test/helpers/projects_helper_test.rb b/test/helpers/projects_helper_test.rb new file mode 100644 index 0000000..d3a55be --- /dev/null +++ b/test/helpers/projects_helper_test.rb @@ -0,0 +1,68 @@ +require 'test_helper' + +class ProjectsHelperTest < ActionView::TestCase + + include Devise::Test::IntegrationHelpers + + def setup + scaffold_plan + + @user = User.last + sign_in @user + end + + # ----------------------------------------------------------------------- + test "plan_list_column_heading should return the localized text for the column heading" do + cols = I18n.t("helpers.project.columns") + + cols.each do |k,v| + assert plan_list_column_heading(k.to_s).include?(">#{I18n.t("helpers.project.columns.#{k}")}<"), "expected #{k} to return a column heading labeled #{v}" + end + end + + # ----------------------------------------------------------------------- + test "plan_list_column_body should return the localized text for the column heading" do + cols = I18n.t("helpers.project.columns") + + cols.each do |k,v| + val = plan_list_column_body(k.to_s, @plan) + + if Plan.respond_to?(k) + assert plan_list_column_body(k.to_s, @plan).include?(">#{@plan.send(k)}<"), "expected #{k} to return a column containing the Plan's value for that column. Instead got: #{val}" + + else + if k == :owner + assert val.include?(">#{@plan.users.first.name}<") || val.include?(t("helpers.me")), "expected :owner to return a column containing the Plan's value for that column or #{I18n.t("helpers.me")}. Instead got: #{val}" + + elsif k == :shared? + assert val.include?(">Yes<") || val.include?(">No<"), "expected :shared? to return a column containing Yes/No. Instead got: #{val}" + else + + end + end + + end + end + + # TODO: 'custom_template' is part of the case logic in this method but it is unreachable because both + # the plan and template settings objects use "Settings::Template". We should remove it from logic + # ----------------------------------------------------------------------- + test "plan_settings_indicator should return the correct export formatting settings" do + assert plan_settings_indicator(@plan).include?(">#{I18n.t("helpers.settings.plans.default_formatting")}<"), "expected the default plan to use default export settings" + + @plan.settings(:export).formatting = {margin: {top: 5, bottom: 5, left: 5, right: 5}, + font_face: Settings::Template::VALID_FONT_FACES.last, + font_size: 12} + @plan.save! + + assert plan_settings_indicator(@plan).include?(">#{I18n.t("helpers.settings.plans.template_formatting")}<"), "expected the default plan to use default export settings" + + @plan.template.settings(:export).formatting = {margin: {top: 10, bottom: 10, left: 10, right: 10}, + font_face: Settings::Template::VALID_FONT_FACES.first, + font_size: 11} + @plan.save! + + assert plan_settings_indicator(@plan).include?(">#{I18n.t("helpers.settings.plans.template_formatting")}<"), "expected the default plan to use default export settings" + end + +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0765120..5dd32e6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,6 +25,12 @@ require_relative '../db/seeds.rb' # Add more helper methods to be used by all tests here... + + # Return the user instance variable + # ---------------------------------------------------------------------- + def current_user + return @user + end # Convert Ruby Class Names into attribute names (e.g. MyClass --> my_class) # ----------------------------------------------------------------------