Skip to content

Commit 9547ddd

Browse files
committed
fix(PictureDescriptionSelect): Add site name to identifier
In a multi site environment, the languages have the same code. Adding the site name helps to identify the language per site. Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
1 parent aa85178 commit 9547ddd

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

app/components/alchemy/admin/picture_description_select.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def language_options
3838
end
3939

4040
def language_label(language)
41-
language.code.upcase
41+
language_name = language.name
42+
multi_site? ? "#{language_name} (#{language.site.name})" : language_name
4243
end
4344
end
4445
end

spec/components/alchemy/admin/picture_description_select_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,24 @@
2727
end
2828

2929
it "renders the select box with both languages" do
30-
expect(page).to have_select("Language", options: ["EN", "DE"], selected: "EN")
30+
expect(page).to have_select("Language", options: ["English", "Deutsch"], selected: "English")
31+
expect(page).to have_selector("alchemy-picture-description-select[url='/some/url']")
32+
end
33+
end
34+
35+
context "when there are multiple sites" do
36+
let!(:language) { create(:alchemy_language, :english, site: site1) }
37+
let!(:german) { create(:alchemy_language, :german, site: site2) }
38+
let(:site1) { create(:alchemy_site, host: "demo.example.com", name: "Demo") }
39+
let(:site2) { create(:alchemy_site, host: "www.example.com", name: "Default") }
40+
41+
before do
42+
allow_any_instance_of(described_class).to receive(:multi_site?).and_return(true)
43+
render
44+
end
45+
46+
it "renders select with site names" do
47+
expect(page).to have_select("Language", options: ["English (Demo)", "Deutsch (Default)"], selected: "English (Demo)")
3148
expect(page).to have_selector("alchemy-picture-description-select[url='/some/url']")
3249
end
3350
end

spec/features/admin/picture_library_integration_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,16 @@
231231
expect(page).to have_content("Picture updated successfully")
232232
end
233233

234-
select(german.language_code.upcase, from: "Language")
234+
select(german.name, from: "Language")
235235
fill_in "Description", with: "Tolles Bild."
236236
click_button "Save"
237237
within "#flash_notices" do
238238
expect(page).to have_content("Picture updated successfully")
239239
end
240240

241-
select(language.language_code.upcase, from: "Language")
241+
select(language.name, from: "Language")
242242
expect(page).to have_field("Description", with: "This is an amazing image.")
243-
select(german.language_code.upcase, from: "Language")
243+
select(german.name, from: "Language")
244244
expect(page).to have_field("Description", with: "Tolles Bild.")
245245
end
246246
end

0 commit comments

Comments
 (0)