Merge pull request from velesin/posts_controller_replies_tests

Adds tests for PostsController#replies.
This commit is contained in:
Robin Ward 2014-02-20 13:36:31 -05:00
commit b8448b6e39
2 changed files with 18 additions and 16 deletions
app/controllers
spec/controllers

View file

@ -128,9 +128,8 @@ class PostsController < ApplicationController
end end
def reply_history def reply_history
@post = Post.where(id: params[:id]).first post = find_post_from_params
guardian.ensure_can_see!(@post) render_serialized(post.reply_history, PostSerializer)
render_serialized(@post.reply_history, PostSerializer)
end end
def destroy def destroy

View file

@ -16,7 +16,6 @@ shared_examples 'finding and showing post' do
end end
context "deleted post" do context "deleted post" do
before do before do
post.trash!(user) post.trash!(user)
end end
@ -37,7 +36,6 @@ shared_examples 'finding and showing post' do
xhr :get, action, params xhr :get, action, params
response.should be_success response.should be_success
end end
end end
end end
@ -67,19 +65,26 @@ describe PostsController do
end end
describe 'reply_history' do describe 'reply_history' do
let(:user) { log_in } include_examples 'finding and showing post' do
let(:post) { Fabricate(:post, user: user) } let(:action) { :reply_history }
let(:params) { {id: post.id} }
it 'ensures the user can see the post' do
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
xhr :get, :reply_history, id: post.id
response.should be_forbidden
end end
it 'succeeds' do it 'asks post for reply history' do
Post.any_instance.expects(:reply_history) Post.any_instance.expects(:reply_history)
xhr :get, :reply_history, id: post.id xhr :get, :reply_history, id: post.id
response.should be_success end
end
describe 'replies' do
include_examples 'finding and showing post' do
let(:action) { :replies }
let(:params) { {post_id: post.id} }
end
it 'asks post for replies' do
Post.any_instance.expects(:replies)
xhr :get, :replies, post_id: post.id
end end
end end
@ -148,7 +153,6 @@ describe PostsController do
end end
end end
describe 'destroy_many' do describe 'destroy_many' do
it 'raises an exception when not logged in' do it 'raises an exception when not logged in' do
lambda { xhr :delete, :destroy_many, post_ids: [123, 345] }.should raise_error(Discourse::NotLoggedIn) lambda { xhr :delete, :destroy_many, post_ids: [123, 345] }.should raise_error(Discourse::NotLoggedIn)
@ -201,7 +205,6 @@ describe PostsController do
end end
describe 'edit a post' do describe 'edit a post' do
it 'raises an exception when not logged in' do it 'raises an exception when not logged in' do