Commit f1416f69cb9d90bbcd4f141d7a9e6c4a7a256177
Committed by
Antonio Terceiro
1 parent
3e6f0186
Exists in
master
and in
28 other branches
Only published articles should be counted on profile
(ActionItem1452)
Showing
4 changed files
with
35 additions
and
5 deletions
Show diff stats
app/models/article.rb
@@ -224,6 +224,7 @@ class Article < ActiveRecord::Base | @@ -224,6 +224,7 @@ class Article < ActiveRecord::Base | ||
224 | end | 224 | end |
225 | end | 225 | end |
226 | 226 | ||
227 | + named_scope :published, :conditions => { :published => true } | ||
227 | named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] } | 228 | named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] } |
228 | 229 | ||
229 | def display_unpublished_article_to?(user) | 230 | def display_unpublished_article_to?(user) |
app/views/profile/index.rhtml
@@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
21 | <tr> | 21 | <tr> |
22 | <td><%= blog.name + ':' %></td> | 22 | <td><%= blog.name + ':' %></td> |
23 | <td> | 23 | <td> |
24 | - <%= link_to(n_('One post', '%{num} posts', blog.posts.count) % { :num => blog.posts.count }, blog.url) %> | 24 | + <%= link_to(n_('One post', '%{num} posts', blog.posts.published.count) % { :num => blog.posts.published.count }, blog.url) %> |
25 | </td> | 25 | </td> |
26 | </tr> | 26 | </tr> |
27 | <% end %> | 27 | <% end %> |
@@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
29 | <tr> | 29 | <tr> |
30 | <td><%= gallery.name + ':' %></td> | 30 | <td><%= gallery.name + ':' %></td> |
31 | <td> | 31 | <td> |
32 | - <%= link_to(n_('One picture', '%{num} pictures', gallery.images.count) % { :num => gallery.images.count }, gallery.url) %> | 32 | + <%= link_to(n_('One picture', '%{num} pictures', gallery.images.published.count) % { :num => gallery.images.published.count }, gallery.url) %> |
33 | </td> | 33 | </td> |
34 | </tr> | 34 | </tr> |
35 | <% end %> | 35 | <% end %> |
@@ -37,7 +37,7 @@ | @@ -37,7 +37,7 @@ | ||
37 | <tr> | 37 | <tr> |
38 | <td><%= _('Events:') %></td> | 38 | <td><%= _('Events:') %></td> |
39 | <td> | 39 | <td> |
40 | - <%= link_to profile.events.count, :controller => 'events', :action => 'events' %> | 40 | + <%= link_to profile.events.published.count, :controller => 'events', :action => 'events' %> |
41 | </td> | 41 | </td> |
42 | </tr> | 42 | </tr> |
43 | <tr> | 43 | <tr> |
test/functional/profile_controller_test.rb
@@ -639,9 +639,30 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -639,9 +639,30 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
639 | assert_nil @request.session[:before_join] | 639 | assert_nil @request.session[:before_join] |
640 | end | 640 | end |
641 | 641 | ||
642 | - should 'show link to events in index' do | 642 | + should 'show number of published events in index' do |
643 | + profile.articles << Event.new(:name => 'Published event', :start_date => Date.today) | ||
644 | + profile.articles << Event.new(:name => 'Unpublished event', :start_date => Date.today, :published => false) | ||
645 | + | ||
646 | + get :index, :profile => profile.identifier | ||
647 | + assert_tag :tag => 'a', :content => '1', :attributes => { :href => "/profile/testuser/events" } | ||
648 | + end | ||
649 | + | ||
650 | + should 'show number of published posts in index' do | ||
651 | + profile.articles << blog = Blog.create(:name => 'Blog', :profile_id => profile.id) | ||
652 | + blog.posts << TextileArticle.new(:name => 'Published post', :parent => profile.blog, :profile => profile) | ||
653 | + blog.posts << TextileArticle.new(:name => 'Other published post', :parent => profile.blog, :profile => profile) | ||
654 | + blog.posts << TextileArticle.new(:name => 'Unpublished post', :parent => profile.blog, :profile => profile, :published => false) | ||
655 | + | ||
643 | get :index, :profile => profile.identifier | 656 | get :index, :profile => profile.identifier |
644 | - assert_tag :tag => 'a', :attributes => { :href => "/profile/#{profile.identifier}/events" } | 657 | + assert_tag :tag => 'a', :content => '2 posts', :attributes => { :href => /\/testuser\/blog/ } |
645 | end | 658 | end |
646 | 659 | ||
660 | + should 'show number of published images in index' do | ||
661 | + folder = Folder.create!(:name => 'gallery', :profile => profile, :view_as => 'image_gallery') | ||
662 | + published_file = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
663 | + unpublished_file = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :published => false) | ||
664 | + | ||
665 | + get :index, :profile => profile.identifier | ||
666 | + assert_tag :tag => 'a', :content => 'One picture', :attributes => { :href => /\/testuser\/gallery/ } | ||
667 | + end | ||
647 | end | 668 | end |
test/unit/article_test.rb
@@ -829,4 +829,12 @@ class ArticleTest < Test::Unit::TestCase | @@ -829,4 +829,12 @@ class ArticleTest < Test::Unit::TestCase | ||
829 | assert_equal 'http://url.without.http', article.external_link | 829 | assert_equal 'http://url.without.http', article.external_link |
830 | end | 830 | end |
831 | 831 | ||
832 | + should 'list only published articles' do | ||
833 | + profile = fast_create(Person) | ||
834 | + | ||
835 | + published = profile.articles.create(:name => 'Published', :published => true) | ||
836 | + unpublished = profile.articles.create(:name => 'Unpublished', :published => false) | ||
837 | + | ||
838 | + assert_equal [ published ], profile.articles.published | ||
839 | + end | ||
832 | end | 840 | end |