Skip to content

Commit

Permalink
Added tests, found bugs, finished canonical support.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed May 25, 2012
1 parent bcec0bb commit 67b949c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pages/app/models/refinery/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def expire_page_caching
# Consists of:
# * The default locale's translated slug
def canonical
with_locale_param url_marketable, ::Refinery::I18n.default_frontend_locale
Globalize.with_locale(::Refinery::I18n.default_frontend_locale){ url }
end

# Returns in cascading order: custom_slug or menu_title or title depending on
Expand Down
10 changes: 4 additions & 6 deletions pages/app/views/refinery/admin/pages/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
<% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
<span class='preview'>
<% page.translations.each do |translation| %>
<% if translation.title.present? %>
<%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
refinery.edit_admin_page_path(page, :switch_locale => translation.locale),
:class => 'locale' %>
<% end %>
<%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
refinery.edit_admin_page_path(page, :switch_locale => translation.locale),
:class => 'locale' if translation.title.present? %>
<% end %>
</span>
<% end %>
</span>

<span class='actions'>
<%= link_to refinery_icon_tag('application_go.png'),
refinery.page_path(page),
refinery.page_path(page.uncached_nested_url),
:target => "_blank",
:title => t('.view_live_html') %>
<%= link_to refinery_icon_tag('page_add.png'),
Expand Down
29 changes: 28 additions & 1 deletion pages/spec/models/refinery/page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
require 'spec_helper'

module Refinery
Expand Down Expand Up @@ -104,11 +105,37 @@ def turn_on_marketable_urls
end

describe '#canonical' do
before do
::Refinery::I18n.stub(:default_frontend_locale).and_return(:en)
::Refinery::I18n.stub(:frontend_locales).and_return([Refinery::I18n.default_frontend_locale, :ru])
::Refinery::I18n.stub(:current_frontend_locale).and_return(Refinery::I18n.default_frontend_locale)

page.save
end
let(:page_title) { 'team' }
let(:child_title) { 'about' }
let(:ru_page_title) { 'Новости' }
let!(:default_canonical) {
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
page.canonical
}
}

specify '' do
specify 'page returns itself' do
page.canonical.should == page.url
end

specify 'default canonical matches page#canonical' do
default_canonical.should == page.canonical
end

specify 'translated page returns master page' do
Globalize.with_locale(:ru) do
page.title = ru_page_title
page.save

page.canonical.should == default_canonical
end
end
end

Expand Down

0 comments on commit 67b949c

Please sign in to comment.