From: Tom Hughes Date: Wed, 3 Jan 2024 18:49:59 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/4451' X-Git-Tag: live~848 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/945c9a635ab815753550006cfe5c1f8c4999a68d?hp=12d4d3fb65b888c3d83cc9e27b4a7a511da02ff5 Merge remote-tracking branch 'upstream/pull/4451' --- diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index 6db32797a..1f9574b9c 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -47,6 +47,8 @@ class DiaryEntriesController < ApplicationController @title = t ".in_language_title", :language => Language.find(params[:language]).english_name entries = entries.where(:language_code => params[:language]) else + candidate_codes = preferred_languages.flat_map(&:candidates).uniq.map(&:to_s) + @languages = Language.where(:code => candidate_codes).in_order_of(:code, candidate_codes) @title = t ".title" end end diff --git a/app/views/diary_entries/index.html.erb b/app/views/diary_entries/index.html.erb index e464b99b4..78ac0dcf8 100644 --- a/app/views/diary_entries/index.html.erb +++ b/app/views/diary_entries/index.html.erb @@ -14,15 +14,19 @@ diff --git a/test/system/diary_entry_test.rb b/test/system/diary_entry_test.rb index 554b89a6d..290b94207 100644 --- a/test/system/diary_entry_test.rb +++ b/test/system/diary_entry_test.rb @@ -3,6 +3,9 @@ require "application_system_test_case" class DiaryEntrySystemTest < ApplicationSystemTestCase def setup create(:language, :code => "en") + create(:language, :code => "pt", :english_name => "Portuguese", :native_name => "Português") + create(:language, :code => "pt-BR", :english_name => "Brazilian Portuguese", :native_name => "Português do Brasil") + create(:language, :code => "ru", :english_name => "Russian", :native_name => "Русский") @diary_entry = create(:diary_entry) end @@ -61,4 +64,14 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase assert_content @deleted_comment.body end + + test "should have links to preferred languages" do + sign_in_as(create(:user, :languages => %w[en-US pt-BR])) + visit diary_entries_path + + assert_link "Diary Entries in English", :href => "/diary/en" + assert_link "Diary Entries in Brazilian Portuguese", :href => "/diary/pt-BR" + assert_link "Diary Entries in Portuguese", :href => "/diary/pt" + assert_no_link "Diary Entries in Russian" + end end