Fix all the errors to get our tests green on Rails 5.1.

This commit is contained in:
Guo Xiang Tan
2017-08-31 12:06:56 +08:00
parent 898ee93547
commit 77d4c4d8dc
989 changed files with 5114 additions and 3117 deletions

View File

@ -11,7 +11,7 @@ describe PostActionUsersController do
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!')
xhr :get, :index, id: post.id, post_action_type_id: notify_mod
get :index, params: { id: post.id, post_action_type_id: notify_mod }, format: :json
expect(response.status).to eq(200)
json = JSON.parse(response.body)
users = json["post_action_users"]
@ -22,30 +22,43 @@ describe PostActionUsersController do
end
it 'raises an error without an id' do
expect {
xhr :get, :index, post_action_type_id: PostActionType.types[:like]
}.to raise_error(ActionController::ParameterMissing)
expect do
get :index,
params: { post_action_type_id: PostActionType.types[:like] },
format: :json
end.to raise_error(ActionController::ParameterMissing)
end
it 'raises an error without a post action type' do
expect {
xhr :get, :index, id: post.id
}.to raise_error(ActionController::ParameterMissing)
expect do
get :index, params: { id: post.id }, format: :json
end.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, :index, id: post.id, post_action_type_id: PostActionType.types[:like]
get :index, 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
xhr :get, :index, id: Fabricate(:post).id, post_action_type_id: PostActionType.types[:notify_moderators]
get :index, params: {
id: Fabricate(:post).id,
post_action_type_id: PostActionType.types[:notify_moderators]
}, format: :json
expect(response).to be_forbidden
end
it 'succeeds' do
xhr :get, :index, id: post.id, post_action_type_id: PostActionType.types[:like]
get :index, params: {
id: post.id, post_action_type_id: PostActionType.types[:like]
}
expect(response).to be_success
end
end