diff --git a/app/controllers/forum_posts_controller.rb b/app/controllers/forum_posts_controller.rb index 30edd5690..8280101c5 100644 --- a/app/controllers/forum_posts_controller.rb +++ b/app/controllers/forum_posts_controller.rb @@ -42,7 +42,7 @@ class ForumPostsController < ApplicationController @forum_post = ForumPost.find(params[:id]) check_privilege(@forum_post) @forum_post.update_attributes(params[:forum_post]) - respond_with(@forum_post, :location => forum_post_path(@forum_post)) + respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.forum_topic_page)) end def destroy diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 4f141f9a8..78979ad89 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -114,6 +114,10 @@ class ForumPost < ActiveRecord::Base "[quote]\n#{creator_name} said:\n\n#{stripped_body}\n[/quote]\n\n" end + def forum_topic_page + ((ForumPost.where("topic_id = ? and created_at < ?", topic_id, created_at).count + 1) / Danbooru.config.posts_per_page.to_f).ceil + end + def build_response dup.tap do |x| x.body = x.quoted_response diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 5799bcf9c..541774436 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -56,7 +56,7 @@ class ForumTopic < ActiveRecord::Base end def last_page - (posts.count / Danbooru.config.posts_per_page.to_f).ceil + ((posts.count + 1) / Danbooru.config.posts_per_page.to_f).ceil end def presenter(forum_posts) diff --git a/test/unit/forum_post_test.rb b/test/unit/forum_post_test.rb index 32324bde8..a33a1ad96 100644 --- a/test/unit/forum_post_test.rb +++ b/test/unit/forum_post_test.rb @@ -14,6 +14,23 @@ class ForumPostTest < ActiveSupport::TestCase CurrentUser.ip_addr = nil end + context "that belongs to a topic with several pages of posts" do + setup do + Danbooru.config.stubs(:posts_per_page).returns(3) + @posts = [] + 10.times do + @posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000)) + end + end + + should "know which page it's on" do + assert_equal(2, @posts[3].forum_topic_page) + assert_equal(2, @posts[4].forum_topic_page) + assert_equal(2, @posts[5].forum_topic_page) + assert_equal(3, @posts[6].forum_topic_page) + end + end + context "belonging to a locked topic" do setup do @post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "zzz")