mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-07 12:16:14 +00:00
Use enum validation instead of ArgumentError
rescue for List
replies policy check (#34452)
This commit is contained in:
parent
5991caae87
commit
2eaef09166
|
@ -7,10 +7,6 @@ class Api::V1::ListsController < Api::BaseController
|
||||||
before_action :require_user!
|
before_action :require_user!
|
||||||
before_action :set_list, except: [:index, :create]
|
before_action :set_list, except: [:index, :create]
|
||||||
|
|
||||||
rescue_from ArgumentError do |e|
|
|
||||||
render json: { error: e.to_s }, status: 422
|
|
||||||
end
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@lists = List.where(account: current_account).all
|
@lists = List.where(account: current_account).all
|
||||||
render json: @lists, each_serializer: REST::ListSerializer
|
render json: @lists, each_serializer: REST::ListSerializer
|
||||||
|
|
|
@ -18,7 +18,7 @@ class List < ApplicationRecord
|
||||||
|
|
||||||
PER_ACCOUNT_LIMIT = 50
|
PER_ACCOUNT_LIMIT = 50
|
||||||
|
|
||||||
enum :replies_policy, { list: 0, followed: 1, none: 2 }, prefix: :show
|
enum :replies_policy, { list: 0, followed: 1, none: 2 }, prefix: :show, validate: true
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
|
||||||
|
|
|
@ -132,9 +132,12 @@ RSpec.describe 'Lists' do
|
||||||
it 'returns http unprocessable entity' do
|
it 'returns http unprocessable entity' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(422)
|
expect(response)
|
||||||
|
.to have_http_status(422)
|
||||||
expect(response.content_type)
|
expect(response.content_type)
|
||||||
.to start_with('application/json')
|
.to start_with('application/json')
|
||||||
|
expect(response.parsed_body)
|
||||||
|
.to include(error: /Replies policy is not included/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user