diff --git a/app/models/article.rb b/app/models/article.rb
index 1a45595..2209695 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -224,6 +224,7 @@ class Article < ActiveRecord::Base
end
end
+ named_scope :published, :conditions => { :published => true }
named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] }
def display_unpublished_article_to?(user)
diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml
index 3afdf5f..24f7e4e 100644
--- a/app/views/profile/index.rhtml
+++ b/app/views/profile/index.rhtml
@@ -21,7 +21,7 @@
<%= blog.name + ':' %> |
- <%= link_to(n_('One post', '%{num} posts', blog.posts.count) % { :num => blog.posts.count }, blog.url) %>
+ <%= link_to(n_('One post', '%{num} posts', blog.posts.published.count) % { :num => blog.posts.published.count }, blog.url) %>
|
<% end %>
@@ -29,7 +29,7 @@
<%= gallery.name + ':' %> |
- <%= link_to(n_('One picture', '%{num} pictures', gallery.images.count) % { :num => gallery.images.count }, gallery.url) %>
+ <%= link_to(n_('One picture', '%{num} pictures', gallery.images.published.count) % { :num => gallery.images.published.count }, gallery.url) %>
|
<% end %>
@@ -37,7 +37,7 @@
<%= _('Events:') %> |
- <%= link_to profile.events.count, :controller => 'events', :action => 'events' %>
+ <%= link_to profile.events.published.count, :controller => 'events', :action => 'events' %>
|
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index e692be5..256a1af 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -639,9 +639,30 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_nil @request.session[:before_join]
end
- should 'show link to events in index' do
+ should 'show number of published events in index' do
+ profile.articles << Event.new(:name => 'Published event', :start_date => Date.today)
+ profile.articles << Event.new(:name => 'Unpublished event', :start_date => Date.today, :published => false)
+
+ get :index, :profile => profile.identifier
+ assert_tag :tag => 'a', :content => '1', :attributes => { :href => "/profile/testuser/events" }
+ end
+
+ should 'show number of published posts in index' do
+ profile.articles << blog = Blog.create(:name => 'Blog', :profile_id => profile.id)
+ blog.posts << TextileArticle.new(:name => 'Published post', :parent => profile.blog, :profile => profile)
+ blog.posts << TextileArticle.new(:name => 'Other published post', :parent => profile.blog, :profile => profile)
+ blog.posts << TextileArticle.new(:name => 'Unpublished post', :parent => profile.blog, :profile => profile, :published => false)
+
get :index, :profile => profile.identifier
- assert_tag :tag => 'a', :attributes => { :href => "/profile/#{profile.identifier}/events" }
+ assert_tag :tag => 'a', :content => '2 posts', :attributes => { :href => /\/testuser\/blog/ }
end
+ should 'show number of published images in index' do
+ folder = Folder.create!(:name => 'gallery', :profile => profile, :view_as => 'image_gallery')
+ published_file = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ unpublished_file = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :published => false)
+
+ get :index, :profile => profile.identifier
+ assert_tag :tag => 'a', :content => 'One picture', :attributes => { :href => /\/testuser\/gallery/ }
+ end
end
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index 459bccc..416f9b7 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -829,4 +829,12 @@ class ArticleTest < Test::Unit::TestCase
assert_equal 'http://url.without.http', article.external_link
end
+ should 'list only published articles' do
+ profile = fast_create(Person)
+
+ published = profile.articles.create(:name => 'Published', :published => true)
+ unpublished = profile.articles.create(:name => 'Unpublished', :published => false)
+
+ assert_equal [ published ], profile.articles.published
+ end
end
--
libgit2 0.21.2