Migrate custom pages data to their locale
This commit is contained in:
@@ -22,8 +22,14 @@ namespace :globalize do
|
|||||||
|
|
||||||
model_class.find_each do |record|
|
model_class.find_each do |record|
|
||||||
fields.each do |field|
|
fields.each do |field|
|
||||||
if record.send(:"#{field}_#{I18n.locale}").blank?
|
locale = if model_class == SiteCustomization::Page && record.locale.present?
|
||||||
record.send(:"#{field}_#{I18n.locale}=", record.untranslated_attributes[field.to_s])
|
record.locale
|
||||||
|
else
|
||||||
|
I18n.locale
|
||||||
|
end
|
||||||
|
|
||||||
|
if record.send(:"#{field}_#{locale}").blank?
|
||||||
|
record.send(:"#{field}_#{locale}=", record.untranslated_attributes[field.to_s])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -72,5 +72,48 @@ describe "Globalize tasks" do
|
|||||||
expect(notification.send(:"title_#{I18n.locale}")).to eq("Translated")
|
expect(notification.send(:"title_#{I18n.locale}")).to eq("Translated")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "Custom page with a different locale and no translations" do
|
||||||
|
let(:page) do
|
||||||
|
create(:site_customization_page, locale: :fr).tap do |page|
|
||||||
|
page.translations.delete_all
|
||||||
|
page.update_column(:title, "en Français")
|
||||||
|
page.reload
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "copies the original data to both the page's locale" do
|
||||||
|
expect(page.title).to eq("en Français")
|
||||||
|
expect(page.title_fr).to be nil
|
||||||
|
expect(page.send(:"title_#{I18n.locale}")).to be nil
|
||||||
|
|
||||||
|
run_rake_task
|
||||||
|
page.reload
|
||||||
|
|
||||||
|
expect(page.title).to eq("en Français")
|
||||||
|
expect(page.title_fr).to eq("en Français")
|
||||||
|
expect(page.send(:"title_#{I18n.locale}")).to be nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Custom page with a different locale and existing translations" do
|
||||||
|
let(:page) do
|
||||||
|
create(:site_customization_page, title: "In English", locale: :fr).tap do |page|
|
||||||
|
page.update_column(:title, "en Français")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "copies the original data to the page's locale" do
|
||||||
|
expect(page.title_fr).to be nil
|
||||||
|
expect(page.title).to eq("In English")
|
||||||
|
|
||||||
|
run_rake_task
|
||||||
|
page.reload
|
||||||
|
|
||||||
|
expect(page.title).to eq("In English")
|
||||||
|
expect(page.title_fr).to eq("en Français")
|
||||||
|
expect(page.send(:"title_#{I18n.locale}")).to eq("In English")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user