Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use consistent names for recent_topic/recent_post associations. disti…

…nguish between Topic#recent_post and Topic#last_post

git-svn-id: http://svn.techno-weenie.net/projects/beast/trunk@3031 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information...
commit a0b490fc2e1fdb7e0cdabd983ea231b734e21dbb 1 parent 6df8e05
technoweenie authored
4 app/helpers/forums_helper.rb
View
@@ -8,8 +8,8 @@ def recent_topic_activity(topic)
# used to know if a forum has changed since we read it last
def recent_forum_activity(forum)
- return false unless logged_in? && forum.first_topic
- return forum.first_topic.replied_at > (session[:forums][forum.id] || last_active)
+ return false unless logged_in? && forum.recent_topic
+ return forum.recent_topic.replied_at > (session[:forums][forum.id] || last_active)
end
end
4 app/models/forum.rb
View
@@ -7,7 +7,7 @@ class Forum < ActiveRecord::Base
has_many :moderators, :through => :moderatorships, :source => :user, :order => "#{User.table_name}.login"
has_many :topics, :order => 'sticky desc, replied_at desc', :dependent => :delete_all
- has_one :first_topic, :class_name => 'Topic', :order => 'sticky desc, replied_at desc'
+ has_one :recent_topic, :class_name => 'Topic', :order => 'sticky desc, replied_at desc'
# this is used to see if a forum is "fresh"... we can't use topics because it puts
# stickies first even if they are not the most recently modified
@@ -15,7 +15,7 @@ class Forum < ActiveRecord::Base
has_one :recent_topic, :class_name => 'Topic', :order => 'replied_at DESC'
has_many :posts, :order => "#{Post.table_name}.created_at DESC", :dependent => :delete_all
- has_one :last_post, :order => "#{Post.table_name}.created_at DESC", :class_name => 'Post'
+ has_one :recent_post, :order => "#{Post.table_name}.created_at DESC", :class_name => 'Post'
format_attribute :description
end
5 app/models/topic.rb
View
@@ -8,11 +8,12 @@ class Topic < ActiveRecord::Base
belongs_to :forum
belongs_to :user
+ belongs_to :last_post, :class_name => "Post", :foreign_key => 'last_post_id'
has_many :monitorships
has_many :monitors, :through => :monitorships, :conditions => ["#{Monitorship.table_name}.active = ?", true], :source => :user, :order => "#{User.table_name}.login"
has_many :posts, :order => "#{Post.table_name}.created_at", :dependent => :delete_all
- has_one :last_post, :order => "#{Post.table_name}.created_at DESC", :class_name => 'Post'
+ has_one :recent_post, :order => "#{Post.table_name}.created_at DESC", :class_name => 'Post'
has_many :voices, :through => :posts, :source => :user, :uniq => true
@@ -42,7 +43,7 @@ def editable_by?(user)
def update_cached_post_fields(post)
# these fields are not accessible to mass assignment
- remaining_post = post.frozen? ? last_post : post
+ remaining_post = post.frozen? ? recent_post : post
if remaining_post
self.class.update_all(['replied_at = ?, replied_by = ?, last_post_id = ?, posts_count = ?',
remaining_post.created_at, remaining_post.user_id, remaining_post.id, posts.count], ['id = ?', id])
8 app/views/forums/index.html.erb
View
@@ -54,10 +54,10 @@
</td>
<td class="inv lp">
- <% if forum.last_post %>
- <%= time_ago_in_words(forum.last_post.created_at) %><br />
- <%= 'by {user}'[:by_user,"<strong>#{h(forum.last_post.user.display_name)}</strong>"] %>
- <span>(<%= link_to 'view'[], topic_path(:forum_id => forum, :id => forum.last_post.topic_id, :page => forum.last_post.topic.last_page, :anchor => forum.last_post.dom_id) %>)</span>
+ <% if forum.recent_post %>
+ <%= time_ago_in_words(forum.recent_post.created_at) %><br />
+ <%= 'by {user}'[:by_user,"<strong>#{h(forum.recent_post.user.display_name)}</strong>"] %>
+ <span>(<%= link_to 'view'[], topic_path(:forum_id => forum, :id => forum.recent_post.topic_id, :page => forum.recent_post.topic.last_page, :anchor => forum.recent_post.dom_id) %>)</span>
<% end %>
</td>
</tr>
8 test/unit/forum_test.rb
View
@@ -11,12 +11,12 @@ def test_should_list_recent_posts
assert_models_equal [posts(:il8n), posts(:ponies), posts(:pdi_rebuttal), posts(:pdi_reply), posts(:pdi),posts(:sticky) ], forums(:rails).posts
end
- def test_should_find_last_post
- assert_equal posts(:il8n), forums(:rails).last_post
+ def test_should_find_recent_post
+ assert_equal posts(:il8n), forums(:rails).recent_post
end
- def test_should_find_first_topic
- assert_equal topics(:sticky), forums(:rails).first_topic
+ def test_should_find_recent_topic
+ assert_equal topics(:il8n), forums(:rails).recent_topic
end
def test_should_find_first_recent_post
2  test/unit/post_test.rb
View
@@ -43,7 +43,7 @@ def test_should_update_cached_data
def test_should_delete_last_post_and_fix_topic_cached_data
posts(:pdi_rebuttal).destroy
- assert_equal posts(:pdi_reply).id, topics(:pdi).last_post_id
+ assert_equal posts(:pdi_reply), topics(:pdi).last_post
assert_equal posts(:pdi_reply).user_id, topics(:pdi).replied_by
assert_equal posts(:pdi_reply).created_at.to_i, topics(:pdi).replied_at.to_i
end
Please sign in to comment.
Something went wrong with that request. Please try again.