diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 226c0d6..9b0e948 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -54,7 +54,7 @@ class ContentViewerController < ApplicationController return end - redirect_to_translation + redirect_to_translation if @page.profile.redirect_l10n # At this point the page will be showed @page.hit diff --git a/app/models/profile.rb b/app/models/profile.rb index 4467bc6..aa80706 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -115,6 +115,7 @@ class Profile < ActiveRecord::Base acts_as_having_settings :field => :data + settings_items :redirect_l10n, :type => :boolean, :default => false settings_items :public_content, :type => :boolean, :default => true settings_items :description diff --git a/app/views/profile_editor/edit.rhtml b/app/views/profile_editor/edit.rhtml index 9ff179e..4e96c0a 100644 --- a/app/views/profile_editor/edit.rhtml +++ b/app/views/profile_editor/edit.rhtml @@ -73,6 +73,12 @@ <% end %> +

<%= _('Other options') %>

+ <%= labelled_check_box( + _('Automatic redirect the visitor to the translated article of him language'), + 'profile_data[redirect_l10n]', true, @profile.redirect_l10n + )%> + <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %> <% button_bar do %> diff --git a/features/language_redirection.feature b/features/language_redirection.feature new file mode 100644 index 0000000..0475e84 --- /dev/null +++ b/features/language_redirection.feature @@ -0,0 +1,40 @@ +Feature: language redirection + As a guest + I want to see an article + + Background: + Given the following users + | login | name | + | manuel | Manuel Silva | + And the following articles + | owner | name | body | lang | translation_of | + | manuel | Meu Artigo | isso é um teste | pt | nil | + | manuel | My Article | this is a test | en | Meu Artigo | + + Scenario: view page in Pt as Pt guest + Given my browser prefers Portuguese + When I go to /manuel/meu-artigo + Then the site should be in Portuguese + + Scenario: view page in Pt as En guest with redirection disabled by default + Given my browser prefers English + When I go to /manuel/meu-artigo + Then the site should be in Portuguese + + Scenario: view page in Pt as En guest with redirection enabled + #Given manuel enabled translation redirection in his profile + # Testing the web UI + Given I am logged in as "manuel" + And my browser prefers English + And I go to manuel's profile editor + And I check "Automatic redirect the visitor to the translated article of him language" + And I press "save" + When I go to /manuel/meu-artigo + Then the site should be in English + + Scenario: view page in Pt as En guest with redirection disabled + Given manuel disabled translation redirection in his profile + And my browser prefers English + When I go to /manuel/meu-artigo + Then the site should be in Portuguese + diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 573d70b..ce2f5f5 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -94,7 +94,20 @@ Given /^the following (articles|events|blogs|folders|forums|galleries)$/ do |con parent = item.delete("parent") owner = Profile[owner_identifier] home = item.delete("homepage") - result = klass.new(item.merge(:profile => owner)) + language = item.delete("lang") + translation_of_id = nil + if item["translation_of"] + if item["translation_of"] != "nil" + article = owner.articles.find_by_name(item["translation_of"]) + translation_of_id = article.id if article + end + item.delete("translation_of") + end + result = klass.new(item.merge( + :profile => owner, + :language => language, + :translation_of_id => translation_of_id + )) if parent result.parent = Article.find_by_name(parent) end @@ -488,3 +501,10 @@ Then /^"([^\"]*)" profile should not exist$/ do |profile_selector| profile.nil?.should be_true end end + +Given /^([^\s]+) (enabled|disabled) translation redirection in (?:his|her) profile$/ do + |login, status| + profile = Profile[login] + profile.redirect_l10n = ( status == "enabled" ) + profile.save +end diff --git a/features/support/paths.rb b/features/support/paths.rb index a292fca..35638ea 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -36,7 +36,7 @@ module NavigationHelpers when /^(.*)'s sitemap/ '/profile/%s/sitemap' % Profile.find_by_name($1).identifier - when /^(.*)'s profile/ + when /^(.*)'s profile$/ '/profile/%s' % Profile.find_by_name($1).identifier when /^the profile$/ @@ -48,6 +48,9 @@ module NavigationHelpers when /^(.*)'s leave page/ '/profile/%s/leave' % Profile.find_by_name($1).identifier + when /^(.*)'s profile editor$/ + "myprofile/manuel/profile_editor/edit" + when /^login page$/ '/account/login' diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 4373cdb..543b108 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1113,26 +1113,6 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :a, :attributes => { :class => /article-translations-menu/, :onclick => /toggleSubmenu/ } end - should 'be redirected to translation if article is a root' do - @request.env['HTTP_REFERER'] = 'http://some.path' - FastGettext.stubs(:locale).returns('es') - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) - get :view_page, :profile => @profile.identifier, :page => en_article.explode_path - assert_redirected_to :profile => @profile.identifier, :page => es_article.explode_path - assert_equal es_article, assigns(:page) - end - - should 'be redirected to translation' do - @request.env['HTTP_REFERER'] = 'http://some.path' - FastGettext.stubs(:locale).returns('en') - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) - get :view_page, :profile => @profile.identifier, :page => es_article.explode_path - assert_redirected_to :profile => @profile.identifier, :page => en_article.explode_path - assert_equal en_article, assigns(:page) - end - should 'not be redirected if already in translation' do en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) @@ -1161,16 +1141,6 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_equal en_article, assigns(:page) end - should 'be redirected if http_referer is nil' do - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) - @request.env['HTTP_REFERER'] = nil - FastGettext.stubs(:locale).returns('es') - get :view_page, :profile => @profile.identifier, :page => en_article.explode_path - assert_redirected_to :profile => @profile.identifier, :page => es_article.explode_path - assert_equal es_article, assigns(:page) - end - should 'not be redirected to transition if came from edit' do en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) -- libgit2 0.21.2