Commit 6f93cb796b70ace418ce18486c9e79173a5cc40f

Authored by Daniela Feitosa
2 parents 8d889f08 e8325928

Merge branch 'stable'

Conflicts:
	features/step_definitions/noosfero_steps.rb
app/controllers/public/content_viewer_controller.rb
@@ -54,7 +54,7 @@ class ContentViewerController < ApplicationController @@ -54,7 +54,7 @@ class ContentViewerController < ApplicationController
54 return 54 return
55 end 55 end
56 56
57 - redirect_to_translation 57 + redirect_to_translation if @page.profile.redirect_l10n
58 58
59 # At this point the page will be showed 59 # At this point the page will be showed
60 @page.hit 60 @page.hit
app/models/profile.rb
@@ -115,6 +115,7 @@ class Profile < ActiveRecord::Base @@ -115,6 +115,7 @@ class Profile < ActiveRecord::Base
115 115
116 acts_as_having_settings :field => :data 116 acts_as_having_settings :field => :data
117 117
  118 + settings_items :redirect_l10n, :type => :boolean, :default => false
118 settings_items :public_content, :type => :boolean, :default => true 119 settings_items :public_content, :type => :boolean, :default => true
119 settings_items :description 120 settings_items :description
120 121
app/views/profile_editor/edit.rhtml
@@ -73,6 +73,12 @@ @@ -73,6 +73,12 @@
73 </table> 73 </table>
74 <% end %> 74 <% end %>
75 75
  76 + <h2><%= _('Other options') %></h2>
  77 + <%= labelled_check_box(
  78 + _('Automatic redirect the visitor to the translated article of him language'),
  79 + 'profile_data[redirect_l10n]', true, @profile.redirect_l10n
  80 + )%>
  81 +
76 <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %> 82 <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %>
77 83
78 <%= 84 <%=
features/language_redirection.feature 0 → 100644
@@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
  1 +Feature: language redirection
  2 + As a guest
  3 + I want to see an article
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | manuel | Manuel Silva |
  9 + And the following articles
  10 + | owner | name | body | lang | translation_of |
  11 + | manuel | Meu Artigo | isso é um teste | pt | nil |
  12 + | manuel | My Article | this is a test | en | Meu Artigo |
  13 +
  14 + Scenario: view page in Pt as Pt guest
  15 + Given my browser prefers Portuguese
  16 + When I go to /manuel/meu-artigo
  17 + Then the site should be in Portuguese
  18 +
  19 + Scenario: view page in Pt as En guest with redirection disabled by default
  20 + Given my browser prefers English
  21 + When I go to /manuel/meu-artigo
  22 + Then the site should be in Portuguese
  23 +
  24 + Scenario: view page in Pt as En guest with redirection enabled
  25 + #Given manuel enabled translation redirection in his profile
  26 + # Testing the web UI
  27 + Given I am logged in as "manuel"
  28 + And my browser prefers English
  29 + And I go to manuel's profile editor
  30 + And I check "Automatic redirect the visitor to the translated article of him language"
  31 + And I press "save"
  32 + When I go to /manuel/meu-artigo
  33 + Then the site should be in English
  34 +
  35 + Scenario: view page in Pt as En guest with redirection disabled
  36 + Given manuel disabled translation redirection in his profile
  37 + And my browser prefers English
  38 + When I go to /manuel/meu-artigo
  39 + Then the site should be in Portuguese
  40 +
features/step_definitions/noosfero_steps.rb
@@ -94,7 +94,20 @@ Given /^the following (articles|events|blogs|folders|forums|galleries)$/ do |con @@ -94,7 +94,20 @@ Given /^the following (articles|events|blogs|folders|forums|galleries)$/ do |con
94 parent = item.delete("parent") 94 parent = item.delete("parent")
95 owner = Profile[owner_identifier] 95 owner = Profile[owner_identifier]
96 home = item.delete("homepage") 96 home = item.delete("homepage")
97 - result = klass.new(item.merge(:profile => owner)) 97 + language = item.delete("lang")
  98 + translation_of_id = nil
  99 + if item["translation_of"]
  100 + if item["translation_of"] != "nil"
  101 + article = owner.articles.find_by_name(item["translation_of"])
  102 + translation_of_id = article.id if article
  103 + end
  104 + item.delete("translation_of")
  105 + end
  106 + result = klass.new(item.merge(
  107 + :profile => owner,
  108 + :language => language,
  109 + :translation_of_id => translation_of_id
  110 + ))
98 if parent 111 if parent
99 result.parent = Article.find_by_name(parent) 112 result.parent = Article.find_by_name(parent)
100 end 113 end
@@ -541,3 +554,10 @@ end @@ -541,3 +554,10 @@ end
541 And /^I want to add "([^\"]*)" as cost$/ do |string| 554 And /^I want to add "([^\"]*)" as cost$/ do |string|
542 selenium.answer_on_next_prompt(string) 555 selenium.answer_on_next_prompt(string)
543 end 556 end
  557 +
  558 +Given /^([^\s]+) (enabled|disabled) translation redirection in (?:his|her) profile$/ do
  559 + |login, status|
  560 + profile = Profile[login]
  561 + profile.redirect_l10n = ( status == "enabled" )
  562 + profile.save
  563 +end
features/support/paths.rb
@@ -36,7 +36,7 @@ module NavigationHelpers @@ -36,7 +36,7 @@ module NavigationHelpers
36 when /^(.*)'s sitemap/ 36 when /^(.*)'s sitemap/
37 '/profile/%s/sitemap' % Profile.find_by_name($1).identifier 37 '/profile/%s/sitemap' % Profile.find_by_name($1).identifier
38 38
39 - when /^(.*)'s profile/ 39 + when /^(.*)'s profile$/
40 '/profile/%s' % Profile.find_by_name($1).identifier 40 '/profile/%s' % Profile.find_by_name($1).identifier
41 41
42 when /^the profile$/ 42 when /^the profile$/
@@ -48,6 +48,9 @@ module NavigationHelpers @@ -48,6 +48,9 @@ module NavigationHelpers
48 when /^(.*)'s leave page/ 48 when /^(.*)'s leave page/
49 '/profile/%s/leave' % Profile.find_by_name($1).identifier 49 '/profile/%s/leave' % Profile.find_by_name($1).identifier
50 50
  51 + when /^(.*)'s profile editor$/
  52 + "myprofile/manuel/profile_editor/edit"
  53 +
51 when /^login page$/ 54 when /^login page$/
52 '/account/login' 55 '/account/login'
53 56
test/functional/content_viewer_controller_test.rb
@@ -1113,26 +1113,6 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -1113,26 +1113,6 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
1113 assert_tag :a, :attributes => { :class => /article-translations-menu/, :onclick => /toggleSubmenu/ } 1113 assert_tag :a, :attributes => { :class => /article-translations-menu/, :onclick => /toggleSubmenu/ }
1114 end 1114 end
1115 1115
1116 - should 'be redirected to translation if article is a root' do  
1117 - @request.env['HTTP_REFERER'] = 'http://some.path'  
1118 - FastGettext.stubs(:locale).returns('es')  
1119 - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en')  
1120 - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article)  
1121 - get :view_page, :profile => @profile.identifier, :page => en_article.explode_path  
1122 - assert_redirected_to :profile => @profile.identifier, :page => es_article.explode_path  
1123 - assert_equal es_article, assigns(:page)  
1124 - end  
1125 -  
1126 - should 'be redirected to translation' do  
1127 - @request.env['HTTP_REFERER'] = 'http://some.path'  
1128 - FastGettext.stubs(:locale).returns('en')  
1129 - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en')  
1130 - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article)  
1131 - get :view_page, :profile => @profile.identifier, :page => es_article.explode_path  
1132 - assert_redirected_to :profile => @profile.identifier, :page => en_article.explode_path  
1133 - assert_equal en_article, assigns(:page)  
1134 - end  
1135 -  
1136 should 'not be redirected if already in translation' do 1116 should 'not be redirected if already in translation' do
1137 en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') 1117 en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en')
1138 es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) 1118 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 &lt; Test::Unit::TestCase @@ -1161,16 +1141,6 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
1161 assert_equal en_article, assigns(:page) 1141 assert_equal en_article, assigns(:page)
1162 end 1142 end
1163 1143
1164 - should 'be redirected if http_referer is nil' do  
1165 - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en')  
1166 - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article)  
1167 - @request.env['HTTP_REFERER'] = nil  
1168 - FastGettext.stubs(:locale).returns('es')  
1169 - get :view_page, :profile => @profile.identifier, :page => en_article.explode_path  
1170 - assert_redirected_to :profile => @profile.identifier, :page => es_article.explode_path  
1171 - assert_equal es_article, assigns(:page)  
1172 - end  
1173 -  
1174 should 'not be redirected to transition if came from edit' do 1144 should 'not be redirected to transition if came from edit' do
1175 en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') 1145 en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en')
1176 es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) 1146 es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article)