From a5e802b82dbbb037c7b3ba91615dd3bf3462485a Mon Sep 17 00:00:00 2001 From: KacperMekarski Date: Tue, 30 Mar 2021 16:12:48 +0200 Subject: [PATCH 1/4] fix rendering title and meta title --- .../spree/static_content_controller.rb | 2 +- app/views/spree/static_content/show.html.erb | 4 ++-- spec/features/static_content_spec.rb | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/static_content_controller.rb b/app/controllers/spree/static_content_controller.rb index 7ef41b0e..44e43ee5 100644 --- a/app/controllers/spree/static_content_controller.rb +++ b/app/controllers/spree/static_content_controller.rb @@ -15,7 +15,7 @@ def determine_layout end def accurate_title - @page ? (@page.meta_title.present? ? @page.meta_title : @page.title) : nil + @page&.title || @page&.meta_title end end end diff --git a/app/views/spree/static_content/show.html.erb b/app/views/spree/static_content/show.html.erb index 3e8e885b..95e6d94c 100644 --- a/app/views/spree/static_content/show.html.erb +++ b/app/views/spree/static_content/show.html.erb @@ -3,9 +3,9 @@ <% else %> <% content_for :head do -%> <%- if @page.meta_title.present? -%> - - <%- else -%> + <%- else -%> + <%- end -%> diff --git a/spec/features/static_content_spec.rb b/spec/features/static_content_spec.rb index f12055c7..42cd3f32 100644 --- a/spec/features/static_content_spec.rb +++ b/spec/features/static_content_spec.rb @@ -60,5 +60,27 @@ expect(page).to have_text 'WOMEN'.upcase end + + scenario 'has valid title' do + create(:page, title: 'Title', meta_title: 'Meta Title', stores: [store]) + visit '/page' + expect(page).to have(:title, 'Title') + end + + context 'when meta title is present' do + scenario 'has valid meta title' do + create(:page, title: 'Title', meta_title: 'Meta Title', stores: [store]) + visit '/page' + expect(page).to have_meta(:title, 'Meta Title') + end + end + + context 'when meta title is not present' do + scenario 'has meta title like title' do + create(:page, title: 'Title', meta_title: nil, stores: [store]) + visit '/page' + expect(page).to have_meta(:title, 'Title') + end + end end end From 0ba04efd6332ed173092de39337c7989632989b8 Mon Sep 17 00:00:00 2001 From: KacperMekarski Date: Tue, 30 Mar 2021 16:42:00 +0200 Subject: [PATCH 2/4] fix tests --- spec/features/static_content_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/static_content_spec.rb b/spec/features/static_content_spec.rb index 42cd3f32..6fc77650 100644 --- a/spec/features/static_content_spec.rb +++ b/spec/features/static_content_spec.rb @@ -62,14 +62,14 @@ end scenario 'has valid title' do - create(:page, title: 'Title', meta_title: 'Meta Title', stores: [store]) + create(:page, slug: '/page', title: 'Title', meta_title: 'Meta Title', stores: [store]) visit '/page' - expect(page).to have(:title, 'Title') + expect(page).to have_title('Title') end context 'when meta title is present' do scenario 'has valid meta title' do - create(:page, title: 'Title', meta_title: 'Meta Title', stores: [store]) + create(:page, slug: '/page', title: 'Title', meta_title: 'Meta Title', stores: [store]) visit '/page' expect(page).to have_meta(:title, 'Meta Title') end @@ -77,7 +77,7 @@ context 'when meta title is not present' do scenario 'has meta title like title' do - create(:page, title: 'Title', meta_title: nil, stores: [store]) + create(:page, slug: '/page', title: 'Title', meta_title: nil, stores: [store]) visit '/page' expect(page).to have_meta(:title, 'Title') end From ce6ee7fc657ac78183f80897fe8a0abc468da214 Mon Sep 17 00:00:00 2001 From: KacperMekarski Date: Tue, 30 Mar 2021 17:02:55 +0200 Subject: [PATCH 3/4] fix tests --- spec/features/static_content_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/static_content_spec.rb b/spec/features/static_content_spec.rb index 6fc77650..ecac2e77 100644 --- a/spec/features/static_content_spec.rb +++ b/spec/features/static_content_spec.rb @@ -71,7 +71,7 @@ scenario 'has valid meta title' do create(:page, slug: '/page', title: 'Title', meta_title: 'Meta Title', stores: [store]) visit '/page' - expect(page).to have_meta(:title, 'Meta Title') + expect(page.has_css?("meta[name='title'][content='Meta Title']", visible: false)).to eq true end end @@ -79,7 +79,7 @@ scenario 'has meta title like title' do create(:page, slug: '/page', title: 'Title', meta_title: nil, stores: [store]) visit '/page' - expect(page).to have_meta(:title, 'Title') + expect(page.has_css?("meta[name='title'][content='Title']", visible: false)).to eq true end end end From bcf461c36828835170fbc6fd1c71a7845566c97b Mon Sep 17 00:00:00 2001 From: KacperMekarski Date: Tue, 30 Mar 2021 17:48:16 +0200 Subject: [PATCH 4/4] Trigger Build