FIX: Do not raise an error if the post action type is nil (#9458)

This commit is contained in:
Roman Rizzi 2020-04-17 14:23:33 -03:00 committed by GitHub
parent 0e4497b6be
commit dce46086f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -27,7 +27,7 @@ class PostActionUsersController < ApplicationController
end
action_type = PostActionType.types.key(post_action_type_id)
total_count = post["#{action_type}_count"]
total_count = post["#{action_type}_count"].to_i
data = { post_action_users: serialize_data(post_actions.to_a, PostActionUserSerializer) }

View File

@ -15,8 +15,8 @@ describe PostActionUsersController do
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"]
users = response.parsed_body["post_action_users"]
expect(users.length).to eq(1)
expect(users[0]["id"]).to eq(post.user.id)
@ -69,14 +69,27 @@ describe PostActionUsersController do
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"]
total = json["total_rows_post_action_users"]
users = response.parsed_body["post_action_users"]
total = response.parsed_body["total_rows_post_action_users"]
expect(users.length).to eq(2)
expect(users.map { |u| u["id"] }).to eq(user_ids[2..3])
expect(total).to eq(5)
end
it 'returns no users when the action type id is invalid' do
get "/post_action_users.json", params: {
id: post.id, post_action_type_id: "invalid_action_type"
}
expect(response.status).to eq(200)
users = response.parsed_body["post_action_users"]
total = response.parsed_body["total_rows_post_action_users"]
expect(users.length).to eq(0)
expect(total).to be_nil
end
end