Commit fd4bcb145246fb61350625f044daf53f55ca4c49

Authored by Daniela Feitosa
2 parents dec34d91 45e5f691

Merge branch 'stable'

app/controllers/public/content_viewer_controller.rb
@@ -92,11 +92,11 @@ class ContentViewerController < ApplicationController @@ -92,11 +92,11 @@ class ContentViewerController < ApplicationController
92 @page.posts 92 @page.posts
93 end 93 end
94 94
95 - posts = posts.native_translations if @page.blog? && @page.display_posts_in_current_language? 95 + if @page.blog? && @page.display_posts_in_current_language?
  96 + posts = posts.native_translations.all(Article.display_filter(user, profile)).map{ |p| p.get_translation_to(FastGettext.locale) }.compact
  97 + end
96 98
97 @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))) 99 @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile)))
98 -  
99 - @posts.map!{ |p| p.get_translation_to(FastGettext.locale) } if @page.blog? && @page.display_posts_in_current_language?  
100 end 100 end
101 101
102 if @page.folder? && @page.gallery? 102 if @page.folder? && @page.gallery?
app/models/article.rb
@@ -319,12 +319,12 @@ class Article < ActiveRecord::Base @@ -319,12 +319,12 @@ class Article < ActiveRecord::Base
319 end 319 end
320 320
321 def get_translation_to(locale) 321 def get_translation_to(locale)
322 - if self.language.nil? || self.language == locale 322 + if self.language.nil? || self.language.blank? || self.language == locale
323 self 323 self
324 elsif self.native_translation.language == locale 324 elsif self.native_translation.language == locale
325 self.native_translation 325 self.native_translation
326 else 326 else
327 - self.native_translation.translations.first(:conditions => { :language => locale }) || self 327 + self.native_translation.translations.first(:conditions => { :language => locale })
328 end 328 end
329 end 329 end
330 330
app/views/cms/_blog.rhtml
@@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
56 56
57 <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> 57 <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %>
58 58
59 -<%= labelled_check_box(_("Try listing only translated posts"), 'article[display_posts_in_current_language]', '1', @article.display_posts_in_current_language?) %> 59 +<%= labelled_check_box(_("List only translated posts"), 'article[display_posts_in_current_language]', '1', @article.display_posts_in_current_language?) %>
60 60
61 <% f.fields_for 'feed', @article.feed do |feed| %> 61 <% f.fields_for 'feed', @article.feed do |feed| %>
62 <%= labelled_form_field(_('Limit of posts in RSS Feed'), feed.select(:limit, [5, 10, 20, 50])) %> 62 <%= labelled_form_field(_('Limit of posts in RSS Feed'), feed.select(:limit, [5, 10, 20, 50])) %>
debian/changelog
  1 +noosfero (0.29.5) unstable; urgency=low
  2 +
  3 + * Bugfix Version release. (Closes: AI#1961)
  4 +
  5 + -- Daniela Soares Feitosa <daniela@colivre.coop.br> Fri, 25 Mar 2011 16:45:27 -0300
  6 +
1 noosfero (0.29.4) unstable; urgency=low 7 noosfero (0.29.4) unstable; urgency=low
2 8
3 * Bugfixes Version release. (Closes: AI#1938 AI#1943 AI#1928 AI#1929 AI#1932 AI#1946 AI#1909 AI#1947 AI#1935 AI#1930 AI#1936 AI#1926 AI#1922) 9 * Bugfixes Version release. (Closes: AI#1938 AI#1943 AI#1928 AI#1929 AI#1932 AI#1946 AI#1909 AI#1947 AI#1935 AI#1930 AI#1936 AI#1926 AI#1922)
lib/noosfero.rb
1 module Noosfero 1 module Noosfero
2 PROJECT = 'noosfero' 2 PROJECT = 'noosfero'
3 - VERSION = '0.29.4' 3 + VERSION = '0.29.5'
4 4
5 def self.pattern_for_controllers_in_directory(dir) 5 def self.pattern_for_controllers_in_directory(dir)
6 disjunction = controllers_in_directory(dir).join('|') 6 disjunction = controllers_in_directory(dir).join('|')
test/functional/content_viewer_controller_test.rb
@@ -1223,6 +1223,23 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -1223,6 +1223,23 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
1223 assert_no_tag :div, :attributes => { :id => "post-#{en_article.id}" } 1223 assert_no_tag :div, :attributes => { :id => "post-#{en_article.id}" }
1224 end 1224 end
1225 1225
  1226 + should 'not display article at blog listing if blog option is enabled and there is no translation for the language' do
  1227 + FastGettext.stubs(:locale).returns('pt')
  1228 + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog')
  1229 + blog.stubs(:display_posts_in_current_language).returns(true)
  1230 + en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en', :parent_id => blog.id)
  1231 + es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :parent_id => blog.id, :translation_of_id => en_article)
  1232 + pt_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'pt', :parent_id => blog.id, :translation_of_id => en_article)
  1233 +
  1234 + en_article2 = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en', :parent_id => blog.id)
  1235 + es_article2 = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :parent_id => blog.id, :translation_of_id => en_article2)
  1236 +
  1237 +
  1238 + get :view_page, :profile => @profile.identifier, :page => blog.explode_path
  1239 +
  1240 + assert_equal [pt_article], assigns(:posts)
  1241 + end
  1242 +
1226 should 'list all posts at blog listing if blog option is disabled' do 1243 should 'list all posts at blog listing if blog option is disabled' do
1227 FastGettext.stubs(:locale).returns('es') 1244 FastGettext.stubs(:locale).returns('es')
1228 blog = Blog.create!(:name => 'A blog test', :profile => profile, :display_posts_in_current_language => false) 1245 blog = Blog.create!(:name => 'A blog test', :profile => profile, :display_posts_in_current_language => false)
test/unit/article_test.rb
@@ -1367,6 +1367,11 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -1367,6 +1367,11 @@ class ArticleTest &lt; Test::Unit::TestCase
1367 assert_equal article, article.get_translation_to('en') 1367 assert_equal article, article.get_translation_to('en')
1368 end 1368 end
1369 1369
  1370 + should 'get self if language article is blank' do
  1371 + article = fast_create(Article, :language => '', :profile_id => @profile.id)
  1372 + assert_equal article, article.get_translation_to('en')
  1373 + end
  1374 +
1370 should 'get self if article is the translation' do 1375 should 'get self if article is the translation' do
1371 article = fast_create(Article, :language => 'pt', :profile_id => @profile.id) 1376 article = fast_create(Article, :language => 'pt', :profile_id => @profile.id)
1372 assert_equal article, article.get_translation_to('pt') 1377 assert_equal article, article.get_translation_to('pt')
@@ -1386,7 +1391,7 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -1386,7 +1391,7 @@ class ArticleTest &lt; Test::Unit::TestCase
1386 1391
1387 should 'get self if article does not has a translation' do 1392 should 'get self if article does not has a translation' do
1388 native_article = fast_create(Article, :language => 'pt', :profile_id => @profile.id) 1393 native_article = fast_create(Article, :language => 'pt', :profile_id => @profile.id)
1389 - assert_equal native_article, native_article.get_translation_to('en') 1394 + assert_nil native_article.get_translation_to('en')
1390 end 1395 end
1391 1396
1392 should 'get only non translated articles' do 1397 should 'get only non translated articles' do