mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-26 05:31:36 +01:00
Extract TEXT_LENGTH_LIMIT
constant in Appeal
class (#30638)
This commit is contained in:
parent
28921a12fe
commit
9bf2e2eda0
2 changed files with 16 additions and 1 deletions
|
@ -18,6 +18,8 @@
|
||||||
class Appeal < ApplicationRecord
|
class Appeal < ApplicationRecord
|
||||||
MAX_STRIKE_AGE = 20.days
|
MAX_STRIKE_AGE = 20.days
|
||||||
|
|
||||||
|
TEXT_LENGTH_LIMIT = 2_000
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id', inverse_of: :appeal
|
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id', inverse_of: :appeal
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ class Appeal < ApplicationRecord
|
||||||
belongs_to :rejected_by_account
|
belongs_to :rejected_by_account
|
||||||
end
|
end
|
||||||
|
|
||||||
validates :text, presence: true, length: { maximum: 2_000 }
|
validates :text, presence: true, length: { maximum: TEXT_LENGTH_LIMIT }
|
||||||
validates :account_warning_id, uniqueness: true
|
validates :account_warning_id, uniqueness: true
|
||||||
|
|
||||||
validate :validate_time_frame, on: :create
|
validate :validate_time_frame, on: :create
|
||||||
|
|
|
@ -3,6 +3,19 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Appeal do
|
describe Appeal do
|
||||||
|
describe 'Validations' do
|
||||||
|
it 'validates text length is under limit' do
|
||||||
|
appeal = Fabricate.build(
|
||||||
|
:appeal,
|
||||||
|
strike: Fabricate(:account_warning),
|
||||||
|
text: 'a' * described_class::TEXT_LENGTH_LIMIT * 2
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(appeal).to_not be_valid
|
||||||
|
expect(appeal).to model_have_error_on_field(:text)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'scopes' do
|
describe 'scopes' do
|
||||||
describe 'approved' do
|
describe 'approved' do
|
||||||
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
|
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
|
||||||
|
|
Loading…
Reference in a new issue