mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
controllers with rspec3 syntax
This commit is contained in:
@@ -4,7 +4,7 @@ describe PostActionsController do
|
||||
|
||||
describe 'create' do
|
||||
it 'requires you to be logged in' do
|
||||
lambda { xhr :post, :create }.should raise_error(Discourse::NotLoggedIn)
|
||||
expect { xhr :post, :create }.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
describe 'logged in' do
|
||||
@@ -14,23 +14,23 @@ describe PostActionsController do
|
||||
end
|
||||
|
||||
it 'raises an error when the id is missing' do
|
||||
lambda { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.should raise_error(ActionController::ParameterMissing)
|
||||
expect { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it 'raises an error when the post_action_type_id index is missing' do
|
||||
lambda { xhr :post, :create, id: @post.id }.should raise_error(ActionController::ParameterMissing)
|
||||
expect { xhr :post, :create, id: @post.id }.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "fails when the user doesn't have permission to see the post" do
|
||||
Guardian.any_instance.expects(:can_see?).with(@post).returns(false)
|
||||
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like]
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "fails when the user doesn't have permission to perform that action" do
|
||||
Guardian.any_instance.expects(:post_can_act?).with(@post, :like, taken_actions: nil).returns(false)
|
||||
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like]
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'allows us to create an post action on a post' do
|
||||
@@ -69,19 +69,19 @@ describe PostActionsController do
|
||||
let(:post) { Fabricate(:post, user: Fabricate(:coding_horror)) }
|
||||
|
||||
it 'requires you to be logged in' do
|
||||
lambda { xhr :delete, :destroy, id: post.id }.should raise_error(Discourse::NotLoggedIn)
|
||||
expect { xhr :delete, :destroy, id: post.id }.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
context 'logged in' do
|
||||
let!(:user) { log_in }
|
||||
|
||||
it 'raises an error when the post_action_type_id is missing' do
|
||||
lambda { xhr :delete, :destroy, id: post.id }.should raise_error(ActionController::ParameterMissing)
|
||||
expect { xhr :delete, :destroy, id: post.id }.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "returns 404 when the post action type doesn't exist for that user" do
|
||||
xhr :delete, :destroy, id: post.id, post_action_type_id: 1
|
||||
response.code.should == '404'
|
||||
expect(response.code).to eq('404')
|
||||
end
|
||||
|
||||
context 'with a post_action record ' do
|
||||
@@ -89,18 +89,18 @@ describe PostActionsController do
|
||||
|
||||
it 'returns success' do
|
||||
xhr :delete, :destroy, id: post.id, post_action_type_id: 1
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'deletes the action' do
|
||||
xhr :delete, :destroy, id: post.id, post_action_type_id: 1
|
||||
PostAction.exists?(user_id: user.id, post_id: post.id, post_action_type_id: 1, deleted_at: nil).should == false
|
||||
expect(PostAction.exists?(user_id: user.id, post_id: post.id, post_action_type_id: 1, deleted_at: nil)).to eq(false)
|
||||
end
|
||||
|
||||
it 'ensures it can be deleted' do
|
||||
Guardian.any_instance.expects(:can_delete?).with(post_action).returns(false)
|
||||
xhr :delete, :destroy, id: post.id, post_action_type_id: 1
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,7 +114,7 @@ describe PostActionsController do
|
||||
|
||||
context "not logged in" do
|
||||
it "should not allow them to clear flags" do
|
||||
lambda { xhr :post, :defer_flags }.should raise_error(Discourse::NotLoggedIn)
|
||||
expect { xhr :post, :defer_flags }.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -122,13 +122,13 @@ describe PostActionsController do
|
||||
let!(:user) { log_in(:moderator) }
|
||||
|
||||
it "raises an error without a post_action_type_id" do
|
||||
-> { xhr :post, :defer_flags, id: flagged_post.id }.should raise_error(ActionController::ParameterMissing)
|
||||
expect { xhr :post, :defer_flags, id: flagged_post.id }.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have access" do
|
||||
Guardian.any_instance.expects(:can_defer_flags?).returns(false)
|
||||
xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam]
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
context "success" do
|
||||
@@ -139,13 +139,13 @@ describe PostActionsController do
|
||||
|
||||
it "delegates to defer_flags" do
|
||||
xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam]
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "works with a deleted post" do
|
||||
flagged_post.trash!(user)
|
||||
xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam]
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
end
|
||||
@@ -159,32 +159,32 @@ describe PostActionsController do
|
||||
let!(:post) { Fabricate(:post, user: log_in) }
|
||||
|
||||
it 'raises an error without an id' do
|
||||
lambda {
|
||||
expect {
|
||||
xhr :get, :users, post_action_type_id: PostActionType.types[:like]
|
||||
}.should raise_error(ActionController::ParameterMissing)
|
||||
}.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it 'raises an error without a post action type' do
|
||||
lambda {
|
||||
expect {
|
||||
xhr :get, :users, id: post.id
|
||||
}.should raise_error(ActionController::ParameterMissing)
|
||||
}.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "fails when the user doesn't have permission to see the post" do
|
||||
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
|
||||
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like]
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'raises an error when the post action type cannot be seen' do
|
||||
Guardian.any_instance.expects(:can_see_post_actors?).with(instance_of(Topic), PostActionType.types[:like]).returns(false)
|
||||
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like]
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'succeeds' do
|
||||
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like]
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user