Permalink
Browse files

Add helper method for finding the last visible post for a topic

  • Loading branch information...
1 parent 26acc50 commit e47ec54e51d05e664db9fe5a1ba8362985224958 @radar radar committed Sep 15, 2011
Showing with 14 additions and 0 deletions.
  1. +4 −0 app/models/forem/forum.rb
  2. +10 −0 spec/models/forum_spec.rb
@@ -10,5 +10,9 @@ class Forum < ActiveRecord::Base
def last_post
posts.last
end
+
+ def last_visible_post
+ posts.where("forem_topics.hidden = ?", false).last
+ end
end
end
View
@@ -24,4 +24,14 @@
@forum.should_not be_valid
end
end
+
+ describe "helper methods" do
+ it "finds the last visible post" do
+ visible_topic = FactoryGirl.create(:topic, :forum => @forum)
+ hidden_topic = FactoryGirl.create(:topic, :forum => @forum, :hidden => true)
+
+ @forum.last_post.should == hidden_topic.posts.last
+ @forum.last_visible_post.should == visible_topic.posts.last
+ end
+ end
end

0 comments on commit e47ec54

Please sign in to comment.