Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #287 from spree-contrib/page-title-and-meta-title
Browse files Browse the repository at this point in the history
Fix rendering page title and meta title
  • Loading branch information
KacperMekarski authored Mar 31, 2021
2 parents ac3a3c6 + bcf461c commit 57953ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spree/static_content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/views/spree/static_content/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<% else %>
<% content_for :head do -%>
<%- if @page.meta_title.present? -%>
<meta name="title" content="<%= @page.title %>">
<%- else -%>
<meta name="title" content="<%= @page.meta_title %>">
<%- else -%>
<meta name="title" content="<%= @page.title %>">
<%- end -%>
<meta name="keywords" content="<%= @page.meta_keywords %>">
<meta name="description" content="<%= @page.meta_description %>">
Expand Down
22 changes: 22 additions & 0 deletions spec/features/static_content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 57953ab

Please sign in to comment.