mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Do not raise an error if the post action type is nil (#9458)
This commit is contained in:
parent
0e4497b6be
commit
dce46086f4
@ -27,7 +27,7 @@ class PostActionUsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
action_type = PostActionType.types.key(post_action_type_id)
|
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) }
|
data = { post_action_users: serialize_data(post_actions.to_a, PostActionUserSerializer) }
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ describe PostActionUsersController do
|
|||||||
|
|
||||||
get "/post_action_users.json", params: { id: post.id, post_action_type_id: notify_mod }
|
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)
|
|
||||||
users = json["post_action_users"]
|
users = response.parsed_body["post_action_users"]
|
||||||
|
|
||||||
expect(users.length).to eq(1)
|
expect(users.length).to eq(1)
|
||||||
expect(users[0]["id"]).to eq(post.user.id)
|
expect(users[0]["id"]).to eq(post.user.id)
|
||||||
@ -69,14 +69,27 @@ describe PostActionUsersController do
|
|||||||
|
|
||||||
get "/post_action_users.json",
|
get "/post_action_users.json",
|
||||||
params: { id: post.id, post_action_type_id: PostActionType.types[:like], page: 1, limit: 2 }
|
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"]
|
users = response.parsed_body["post_action_users"]
|
||||||
total = json["total_rows_post_action_users"]
|
total = response.parsed_body["total_rows_post_action_users"]
|
||||||
|
|
||||||
expect(users.length).to eq(2)
|
expect(users.length).to eq(2)
|
||||||
expect(users.map { |u| u["id"] }).to eq(user_ids[2..3])
|
expect(users.map { |u| u["id"] }).to eq(user_ids[2..3])
|
||||||
|
|
||||||
expect(total).to eq(5)
|
expect(total).to eq(5)
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user