Skip to content

Commit

Permalink
404 comments for unpublished posts (forem#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhao-Andy authored and benhalpern committed Oct 26, 2018
1 parent 5287d4a commit db9c16d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def index
@user.articles.find_by_slug(params[:slug]) ||
not_found
@article = @commentable
not_found unless @commentable.published
end
@commentable_type = @commentable.class.name
if params[:id_code].present?
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
expect(response).to have_http_status(200)
end
end

context "when the article is unpublished" do
before do
new_markdown = article.body_markdown.gsub("published: true", "published: false")
comment
article.update(body_markdown: new_markdown)
end

it "raises a Not Found error" do
expect { get comment.path }.to raise_error("Not Found")
end
end
end

describe "GET /:username/:slug/comments/:id_code/edit" do
Expand Down

0 comments on commit db9c16d

Please sign in to comment.