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..ecac2e77 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, slug: '/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, slug: '/page', title: 'Title', meta_title: 'Meta Title', stores: [store])
+ visit '/page'
+ expect(page.has_css?("meta[name='title'][content='Meta Title']", visible: false)).to eq true
+ end
+ end
+
+ context 'when meta title is not present' do
+ scenario 'has meta title like title' do
+ create(:page, slug: '/page', title: 'Title', meta_title: nil, stores: [store])
+ visit '/page'
+ expect(page.has_css?("meta[name='title'][content='Title']", visible: false)).to eq true
+ end
+ end
end
end