From 2688cc624104164f1ea675554cc88deac8b4a3f5 Mon Sep 17 00:00:00 2001 From: OsamaSayegh Date: Tue, 5 Jun 2018 16:35:54 +0300 Subject: [PATCH] REFACTOR: post action users controller specs to requests --- .../post_action_users_controller_spec.rb | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) rename spec/{controllers => requests}/post_action_users_controller_spec.rb (68%) diff --git a/spec/controllers/post_action_users_controller_spec.rb b/spec/requests/post_action_users_controller_spec.rb similarity index 68% rename from spec/controllers/post_action_users_controller_spec.rb rename to spec/requests/post_action_users_controller_spec.rb index 302156f5d92..04d40eb866c 100644 --- a/spec/controllers/post_action_users_controller_spec.rb +++ b/spec/requests/post_action_users_controller_spec.rb @@ -1,17 +1,16 @@ require 'rails_helper' describe PostActionUsersController do - let(:post) { Fabricate(:post, user: log_in) } + let(:post) { Fabricate(:post, user: sign_in(Fabricate(:user))) } context 'with render' do - render_views it 'always allows you to see your own actions' do notify_mod = PostActionType.types[:notify_moderators] PostAction.act(post.user, post, notify_mod, message: 'well something is wrong here!') PostAction.act(Fabricate(:user), post, notify_mod, message: 'well something is not wrong here!') - get :index, params: { id: post.id, post_action_type_id: notify_mod }, format: :json + get "/post_action_users.json", params: { id: post.id, post_action_type_id: notify_mod } expect(response.status).to eq(200) json = JSON.parse(response.body) users = json["post_action_users"] @@ -22,40 +21,35 @@ describe PostActionUsersController do end it 'raises an error without an id' do - expect do - get :index, - params: { post_action_type_id: PostActionType.types[:like] }, - format: :json - end.to raise_error(ActionController::ParameterMissing) + get "/post_action_users.json", params: { post_action_type_id: PostActionType.types[:like] } + expect(response.status).to eq(400) end it 'raises an error without a post action type' do - expect do - get :index, params: { id: post.id }, format: :json - end.to raise_error(ActionController::ParameterMissing) + get "/post_action_users.json", params: { id: post.id } + expect(response.status).to eq(400) 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) - - get :index, params: { + post.trash! + get "/post_action_users.json", params: { id: post.id, post_action_type_id: PostActionType.types[:like] - }, format: :json + } expect(response).to be_forbidden end it 'raises an error when anon tries to look at an invalid action' do - get :index, params: { + get "/post_action_users.json", params: { id: Fabricate(:post).id, post_action_type_id: PostActionType.types[:notify_moderators] - }, format: :json + } expect(response).to be_forbidden end it 'succeeds' do - get :index, params: { + get "/post_action_users.json", params: { id: post.id, post_action_type_id: PostActionType.types[:like] } @@ -70,7 +64,8 @@ describe PostActionUsersController do PostAction.act(user, post, PostActionType.types[:like]) end - get :index, params: { id: post.id, post_action_type_id: PostActionType.types[:like], page: 1, limit: 2 }, format: :json + get "/post_action_users.json", + params: { id: post.id, post_action_type_id: PostActionType.types[:like], page: 1, limit: 2 } json = JSON.parse(response.body) users = json["post_action_users"]