fix issue #63 (Unlocalized content types on multilingual sites leads to duplicate content)

did committed Apr 20, 2016
commit 02424518ba53692d2459d9011e2897e96e103e79
Showing 4 changed files with 21 additions and 1 deletions
locomotive/steam/middlewares/templatized_page.rb b/lib/locomotive/steam/middlewares/templatized_page.rb +3 -0
@@ @@ -35,6 +35,9 @@ module Locomotive::Steam
def fetch_content_entry(slug)
if type = content_type_repository.find(page.content_type_id)
+ # don't accept a non localized entry in a locale other than the default one
+ return nil if type.localized_names.count == 0 && locale.to_s != default_locale.to_s
+
decorate(content_entry_repository.with(type).by_slug(slug))
else
nil
spec/fixtures/default/app/views/pages/404.fr.liquid.haml +10 -0
@@ @@ -0,0 +1,10 @@
+ ---
+ title: Page non trouvée
+ ---
+ {% extends index %}
+
+ {% block content %}
+
+ %p.error Page non trouvée
+
+ {% endblock %}
spec/integration/server/basic_spec.rb +7 -0
@@ @@ -115,6 +115,13 @@ describe Locomotive::Steam::Server do
expect(last_response.body).to include 'Leader: Eddie'
end
+ it 'redirects to the 404 if a locale other than the default one is asked' do
+ get '/fr/songs/song-number-2'
+ expect(last_response).to be_redirect
+ follow_redirect!
+ expect(last_response.status).to eq(404)
+ end
+
it 'redirects to the 404 if it does not match a content entry' do
get '/songs/unknown'
expect(last_response).to be_redirect
spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +1 -1
@@ @@ -16,7 +16,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page do
it 'tests various stuff' do
expect(subject.size).to eq 26
- expect(subject.first[:title]).to eq(en: 'Page not found')
+ expect(subject.first[:title]).to eq(en: 'Page not found', fr: 'Page non trouvée')
expect(subject[15][:is_layout]).to eq true
expect(subject[15][:listed]).to eq false
expect(subject[15][:published]).to eq false