Merge pull request #3857 from gdpelican/fix-for-untopiced-posts

Don't error on posts#latest if a post does not have a topic
This commit is contained in:
Régis Hanol 2015-10-16 14:59:36 +02:00
commit 06b799bfbf
3 changed files with 28 additions and 2 deletions

View file

@ -42,7 +42,7 @@ class PostsController < ApplicationController
.limit(50)
# 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
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)
respond_to do |format|

View file

@ -7,7 +7,7 @@
<link><%= @link %></link>
<description><%= @description %></description>
<% @posts.each do |post| %>
<% next unless post.user && post.topic %>
<% next unless post.user %>
<item>
<title><%= post.topic.title %></title>
<dc:creator><![CDATA[<%= "@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>

View file

@ -53,6 +53,32 @@ end
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
before do
post = Post.new(cooked: 'wat')