spec/models/spotlight/page_spec.rb in blacklight-spotlight-2.5.0 vs spec/models/spotlight/page_spec.rb in blacklight-spotlight-2.5.1
- old
+ new
@@ -185,36 +185,56 @@
end
end
end
describe 'syncing data between translated pages' do
- let(:parent_page_es) do
+ let!(:parent_page_es) do
FactoryBot.create(
:feature_page,
exhibit: exhibit,
locale: 'es',
default_locale_page: parent_page
)
end
- let(:child_page_es) do
+ let!(:child_page_es) do
FactoryBot.create(
:feature_page,
exhibit: exhibit,
locale: 'es',
default_locale_page: child_page,
parent_page: parent_page_es
)
end
+ let!(:another_translated_page_es) do
+ FactoryBot.create(
+ :feature_page,
+ exhibit: exhibit,
+ locale: 'es',
+ default_locale_page: another_translated_page
+ )
+ end
+ let!(:another_page) { Spotlight::FeaturePage.create exhibit: exhibit, published: true }
+ let!(:another_translated_page) { Spotlight::FeaturePage.create exhibit: exhibit, published: true }
it 'updates the translated pages weight' do
expect(parent_page_es.weight).not_to be 5
parent_page.update(weight: 5)
expect(parent_page_es.reload.weight).to be 5
end
- it 'updates the parent page id' do
+ it 'sets the parent page id to the equivalent translated parent page' do
+ child_page.update(parent_page: another_translated_page)
+ expect(child_page_es.reload.parent_page).to eq another_translated_page_es
+ end
+
+ it 'updates the parent page when the default locale page becomes a top-level page' do
expect(child_page_es.parent_page).to eq parent_page_es
child_page.update(parent_page: nil)
+ expect(child_page_es.reload.parent_page).to be_nil
+ end
+
+ it 'removes the parent page id when the child page is set to an as-yet-untranslated parent page' do
+ child_page.update(parent_page: another_page)
expect(child_page_es.reload.parent_page).to be_nil
end
it 'updates the attributes separately' do
expect(child_page_es.parent_page).to eq parent_page_es