fixes #1546
This commit is contained in:
@@ -7,7 +7,8 @@ class ForumPost < ActiveRecord::Base
|
|||||||
before_validation :initialize_creator, :on => :create
|
before_validation :initialize_creator, :on => :create
|
||||||
before_validation :initialize_updater
|
before_validation :initialize_updater
|
||||||
before_validation :initialize_is_deleted, :on => :create
|
before_validation :initialize_is_deleted, :on => :create
|
||||||
after_create :update_topic_updated_at
|
after_create :update_topic_updated_at_on_create
|
||||||
|
after_destroy :update_topic_updated_at_on_destroy
|
||||||
validates_presence_of :body, :creator_id
|
validates_presence_of :body, :creator_id
|
||||||
validate :validate_topic_is_unlocked
|
validate :validate_topic_is_unlocked
|
||||||
before_destroy :validate_topic_is_unlocked
|
before_destroy :validate_topic_is_unlocked
|
||||||
@@ -87,7 +88,7 @@ class ForumPost < ActiveRecord::Base
|
|||||||
creator_id == user.id || user.is_janitor?
|
creator_id == user.id || user.is_janitor?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_topic_updated_at
|
def update_topic_updated_at_on_create
|
||||||
if topic
|
if topic
|
||||||
topic.updater_id = CurrentUser.id
|
topic.updater_id = CurrentUser.id
|
||||||
topic.response_count = topic.response_count + 1
|
topic.response_count = topic.response_count + 1
|
||||||
@@ -95,6 +96,10 @@ class ForumPost < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_topic_updated_at_on_destroy
|
||||||
|
topic.update_column(:updated_at, ForumPost.where(:topic_id => topic.id).maximum(:updated_at))
|
||||||
|
end
|
||||||
|
|
||||||
def initialize_creator
|
def initialize_creator
|
||||||
self.creator_id = CurrentUser.id
|
self.creator_id = CurrentUser.id
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
setup do
|
setup do
|
||||||
Danbooru.config.stubs(:posts_per_page).returns(3)
|
Danbooru.config.stubs(:posts_per_page).returns(3)
|
||||||
@posts = []
|
@posts = []
|
||||||
10.times do
|
9.times do
|
||||||
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||||
end
|
end
|
||||||
|
sleep 2
|
||||||
|
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "know which page it's on" do
|
should "know which page it's on" do
|
||||||
@@ -29,6 +31,12 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
assert_equal(2, @posts[5].forum_topic_page)
|
assert_equal(2, @posts[5].forum_topic_page)
|
||||||
assert_equal(3, @posts[6].forum_topic_page)
|
assert_equal(3, @posts[6].forum_topic_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "update the topic's updated_at when deleted" do
|
||||||
|
@posts.last.destroy
|
||||||
|
@topic.reload
|
||||||
|
assert_equal(@posts[0].updated_at.to_s, @topic.updated_at.to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "belonging to a locked topic" do
|
context "belonging to a locked topic" do
|
||||||
|
|||||||
Reference in New Issue
Block a user