mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Don't error on posts#latest if a post does not have a topic
This commit is contained in:
parent
ccdd614d7f
commit
695b366a03
3 changed files with 28 additions and 2 deletions
|
@ -42,7 +42,7 @@ class PostsController < ApplicationController
|
||||||
.limit(50)
|
.limit(50)
|
||||||
# Remove posts the user doesn't have permission to see
|
# Remove posts the user doesn't have permission to see
|
||||||
# This isn't leaking any information we weren't already through the post ID numbers
|
# This isn't leaking any information we weren't already through the post ID numbers
|
||||||
posts = posts.reject { |post| !guardian.can_see?(post) }
|
posts = posts.reject { |post| !guardian.can_see?(post) || post.topic.blank? }
|
||||||
counts = PostAction.counts_for(posts, current_user)
|
counts = PostAction.counts_for(posts, current_user)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<link><%= @link %></link>
|
<link><%= @link %></link>
|
||||||
<description><%= @description %></description>
|
<description><%= @description %></description>
|
||||||
<% @posts.each do |post| %>
|
<% @posts.each do |post| %>
|
||||||
<% next unless post.user && post.topic %>
|
<% next unless post.user %>
|
||||||
<item>
|
<item>
|
||||||
<title><%= post.topic.title %></title>
|
<title><%= post.topic.title %></title>
|
||||||
<dc:creator><![CDATA[<%= "@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>
|
<dc:creator><![CDATA[<%= "@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>
|
||||||
|
|
|
@ -53,6 +53,32 @@ end
|
||||||
|
|
||||||
describe PostsController do
|
describe PostsController do
|
||||||
|
|
||||||
|
describe 'latest' do
|
||||||
|
let(:user) { log_in }
|
||||||
|
let!(:post) { Fabricate(:post, user: user) }
|
||||||
|
let!(:topicless_post) { Fabricate(:post, user: user, raw: '<p>Car 54, where are you?</p>') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
topicless_post.update topic_id: -100
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not return posts without a topic for json' do
|
||||||
|
xhr :get, :latest, format: :json
|
||||||
|
expect(response).to be_success
|
||||||
|
json = ::JSON.parse(response.body)
|
||||||
|
post_ids = json['latest_posts'].map { |p| p['id'] }
|
||||||
|
expect(post_ids).to include post.id
|
||||||
|
expect(post_ids).to_not include topicless_post.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not return posts without a topic for rss' do
|
||||||
|
xhr :get, :latest, format: :rss
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(assigns(:posts)).to include post
|
||||||
|
expect(assigns(:posts)).to_not include topicless_post
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'cooked' do
|
describe 'cooked' do
|
||||||
before do
|
before do
|
||||||
post = Post.new(cooked: 'wat')
|
post = Post.new(cooked: 'wat')
|
||||||
|
|
Loading…
Reference in a new issue