FIX: hitting '/t/:id/posts.json' should return the first page of posts

This commit is contained in:
Régis Hanol 2016-04-05 19:12:14 +02:00
parent a1add415e5
commit d402a45781
3 changed files with 12 additions and 2 deletions

View file

@ -154,7 +154,7 @@ class TopicsController < ApplicationController
def posts def posts
params.require(:topic_id) params.require(:topic_id)
params.require(:post_ids) params.permit(:post_ids)
@topic_view = TopicView.new(params[:topic_id], current_user, post_ids: params[:post_ids]) @topic_view = TopicView.new(params[:topic_id], current_user, post_ids: params[:post_ids])
render_json_dump(TopicViewPostsSerializer.new(@topic_view, scope: guardian, root: false, include_raw: !!params[:include_raw])) render_json_dump(TopicViewPostsSerializer.new(@topic_view, scope: guardian, root: false, include_raw: !!params[:include_raw]))

View file

@ -544,7 +544,7 @@ Discourse::Application.routes.draw do
get "t/:slug/:topic_id" => "topics#show", constraints: {topic_id: /\d+/} get "t/:slug/:topic_id" => "topics#show", constraints: {topic_id: /\d+/}
get "t/:slug/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/} get "t/:slug/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/}
get "t/:slug/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/} get "t/:slug/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/}
get "t/:topic_id/posts" => "topics#posts", constraints: {topic_id: /\d+/} get "t/:topic_id/posts" => "topics#posts", constraints: {topic_id: /\d+/}, format: :json
post "t/:topic_id/timings" => "topics#timings", constraints: {topic_id: /\d+/} post "t/:topic_id/timings" => "topics#timings", constraints: {topic_id: /\d+/}
post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/} post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/}
post "t/:topic_id/move-posts" => "topics#move_posts", constraints: {topic_id: /\d+/} post "t/:topic_id/move-posts" => "topics#move_posts", constraints: {topic_id: /\d+/}

View file

@ -813,6 +813,16 @@ describe TopicsController do
end end
end end
describe '#posts' do
let(:topic) { Fabricate(:post).topic }
it 'returns first posts of the topic' do
get :posts, topic_id: topic.id, format: :json
expect(response).to be_success
expect(response.content_type).to eq('application/json')
end
end
describe '#feed' do describe '#feed' do
let(:topic) { Fabricate(:post).topic } let(:topic) { Fabricate(:post).topic }