Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Factory: Create default language in host app's locale #1884

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/alchemy/test_support/factories/language_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

FactoryBot.define do
factory :alchemy_language, class: "Alchemy::Language" do
name { "Deutsch" }
code { "de" }
name { "Your Language" }
code { ::I18n.available_locales.first.to_s }
default { true }
frontpage_name { "Intro" }
page_layout { Alchemy::Config.get(:default_language)["page_layout"] }
Expand All @@ -25,7 +25,12 @@
trait :english do
name { "English" }
code { "en" }
frontpage_name { "Intro" }
default { false }
end

trait :german do
name { "Deutsch" }
code { "de" }
default { false }
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/alchemy/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ module Alchemy
end

context "requesting non default locale" do
let!(:english) do
create(:alchemy_language, :english, default: false)
let!(:klingon) do
create(:alchemy_language, :klingon, default: false)
end

let!(:start_page) do
create :alchemy_page, :language_root,
language: english,
language: klingon,
name: "Start Page"
end

Expand All @@ -153,12 +153,12 @@ module Alchemy
end

it "loads the root page of that language" do
get :index, params: { locale: "en" }
get :index, params: { locale: "kl" }
expect(assigns(:page)).to eq(start_page)
end

it "sets @root_page to root page of that language" do
get :index, params: { locale: "en" }
get :index, params: { locale: "kl" }
expect(assigns(:root_page)).to eq(start_page)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/languages_features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
end

describe "editing an language" do
let!(:language) { create(:alchemy_language) }
let!(:language) { create(:alchemy_language, :german) }

context "when selected locale has multiple matching locale files" do
before do
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ module Alchemy
context "with options[:reverse]" do
context "set to false" do
it "should render the language links in an ascending order" do
expect(helper.language_links(reverse: false)).to have_selector("a.de + a.kl")
expect(helper.language_links(reverse: false)).to have_selector("a.kl + a.en")
end
end

context "set to true" do
it "should render the language links in a descending order" do
expect(helper.language_links(reverse: true)).to have_selector("a.kl + a.de")
expect(helper.language_links(reverse: true)).to have_selector("a.en + a.kl")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/libraries/configuration_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SomeController < ActionController::Base
end

context "if more than one language is present" do
let!(:german) { create(:alchemy_language) }
let!(:german) { create(:alchemy_language, :german, default: true) }
let!(:english) { create(:alchemy_language, :english) }

subject { controller.prefix_locale?(args) }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ module Alchemy
end

before do
expect(::I18n).to receive(:available_locales) do
expect(::I18n).to receive(:available_locales).twice do
[:de, :'de-at', :'en-uk']
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module Alchemy
let!(:parent_node) { create(:alchemy_node, children: [node]) }

it "does not destroy the node and children either but adds an error" do
parent_node.destroy
parent_node.reload.destroy
expect(parent_node).not_to be_destroyed
expect(parent_node.errors.full_messages).to eq(["This menu item is in use inside an Alchemy element on the following pages: #{page.name}."])
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Alchemy
describe Page do
let(:language) { create(:alchemy_language, :english, default: true) }
let(:language) { create(:alchemy_language, :german, default: true) }
let(:klingon) { create(:alchemy_language, :klingon) }
let(:language_root) { create(:alchemy_page, :language_root) }
let(:page) { mock_model(Page, page_layout: "foo") }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module Alchemy
end

let!(:other_language) do
create(:alchemy_language, :english, default: false, site: site)
create(:alchemy_language, :german, default: false, site: site)
end

subject(:site_default_language) do
Expand Down