REFACTOR: post action users controller specs to requests
This commit is contained in:
parent
e2e566214d
commit
2688cc6241
|
@ -1,17 +1,16 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe PostActionUsersController do
|
describe PostActionUsersController do
|
||||||
let(:post) { Fabricate(:post, user: log_in) }
|
let(:post) { Fabricate(:post, user: sign_in(Fabricate(:user))) }
|
||||||
|
|
||||||
context 'with render' do
|
context 'with render' do
|
||||||
render_views
|
|
||||||
it 'always allows you to see your own actions' do
|
it 'always allows you to see your own actions' do
|
||||||
notify_mod = PostActionType.types[:notify_moderators]
|
notify_mod = PostActionType.types[:notify_moderators]
|
||||||
|
|
||||||
PostAction.act(post.user, post, notify_mod, message: 'well something is wrong here!')
|
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!')
|
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)
|
expect(response.status).to eq(200)
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
users = json["post_action_users"]
|
users = json["post_action_users"]
|
||||||
|
@ -22,40 +21,35 @@ describe PostActionUsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error without an id' do
|
it 'raises an error without an id' do
|
||||||
expect do
|
get "/post_action_users.json", params: { post_action_type_id: PostActionType.types[:like] }
|
||||||
get :index,
|
expect(response.status).to eq(400)
|
||||||
params: { post_action_type_id: PostActionType.types[:like] },
|
|
||||||
format: :json
|
|
||||||
end.to raise_error(ActionController::ParameterMissing)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error without a post action type' do
|
it 'raises an error without a post action type' do
|
||||||
expect do
|
get "/post_action_users.json", params: { id: post.id }
|
||||||
get :index, params: { id: post.id }, format: :json
|
expect(response.status).to eq(400)
|
||||||
end.to raise_error(ActionController::ParameterMissing)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails when the user doesn't have permission to see the post" do
|
it "fails when the user doesn't have permission to see the post" do
|
||||||
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
|
post.trash!
|
||||||
|
get "/post_action_users.json", params: {
|
||||||
get :index, params: {
|
|
||||||
id: post.id, post_action_type_id: PostActionType.types[:like]
|
id: post.id, post_action_type_id: PostActionType.types[:like]
|
||||||
}, format: :json
|
}
|
||||||
|
|
||||||
expect(response).to be_forbidden
|
expect(response).to be_forbidden
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error when anon tries to look at an invalid action' do
|
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,
|
id: Fabricate(:post).id,
|
||||||
post_action_type_id: PostActionType.types[:notify_moderators]
|
post_action_type_id: PostActionType.types[:notify_moderators]
|
||||||
}, format: :json
|
}
|
||||||
|
|
||||||
expect(response).to be_forbidden
|
expect(response).to be_forbidden
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
get :index, params: {
|
get "/post_action_users.json", params: {
|
||||||
id: post.id, post_action_type_id: PostActionType.types[:like]
|
id: post.id, post_action_type_id: PostActionType.types[:like]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +64,8 @@ describe PostActionUsersController do
|
||||||
PostAction.act(user, post, PostActionType.types[:like])
|
PostAction.act(user, post, PostActionType.types[:like])
|
||||||
end
|
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)
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
users = json["post_action_users"]
|
users = json["post_action_users"]
|
Loading…
Reference in New Issue