Merge pull request #2004 from velesin/posts_controller_tests_refactoring

PostsController tests clean up.
This commit is contained in:
Robin Ward 2014-02-24 12:53:54 -05:00
commit 7f2512b707

View File

@ -39,13 +39,20 @@ shared_examples 'finding and showing post' do
end end
end end
shared_examples 'action requires login' do |method, action, params|
it 'raises an exception when not logged in' do
lambda { xhr method, action, params }.should raise_error(Discourse::NotLoggedIn)
end
end
describe PostsController do describe PostsController do
describe 'short_link' do describe 'short_link' do
let(:post) { Fabricate(:post) }
it 'logs the incoming link once' do it 'logs the incoming link once' do
IncomingLink.expects(:add).once.returns(true) IncomingLink.expects(:add).once.returns(true)
p = Fabricate(:post) get :short_link, post_id: post.id, user_id: 999
get :short_link, post_id: p.id, user_id: 999
response.should be_redirect response.should be_redirect
end end
end end
@ -89,9 +96,7 @@ describe PostsController do
end end
describe 'delete a post' do describe 'delete a post' do
it 'raises an exception when not logged in' do include_examples 'action requires login', :delete, :destroy, id: 123
lambda { xhr :delete, :destroy, id: 123 }.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do describe 'when logged in' do
@ -125,9 +130,7 @@ describe PostsController do
end end
describe 'recover a post' do describe 'recover a post' do
it 'raises an exception when not logged in' do include_examples 'action requires login', :put, :recover, post_id: 123
lambda { xhr :put, :recover, post_id: 123 }.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do describe 'when logged in' do
@ -154,9 +157,7 @@ describe PostsController do
end end
describe 'destroy_many' do describe 'destroy_many' do
it 'raises an exception when not logged in' do include_examples 'action requires login', :delete, :destroy_many, post_ids: [123, 345]
lambda { xhr :delete, :destroy_many, post_ids: [123, 345] }.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do describe 'when logged in' do
@ -207,9 +208,7 @@ describe PostsController do
describe 'edit a post' do describe 'edit a post' do
it 'raises an exception when not logged in' do include_examples 'action requires login', :put, :update, id: 2
lambda { xhr :put, :update, id: 2 }.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do describe 'when logged in' do
@ -271,9 +270,7 @@ describe PostsController do
describe 'bookmark a post' do describe 'bookmark a post' do
it 'raises an exception when not logged in' do include_examples 'action requires login', :put, :bookmark, post_id: 2
lambda { xhr :put, :bookmark, post_id: 2 }.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do describe 'when logged in' do
@ -301,9 +298,7 @@ describe PostsController do
describe 'creating a post' do describe 'creating a post' do
it 'raises an exception when not logged in' do include_examples 'action requires login', :post, :create
lambda { xhr :post, :create }.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do describe 'when logged in' do