mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 11:55:09 +08:00
DEV: Set limits for text fields in badges
This commit is contained in:
parent
552697e194
commit
c4c2da83b4
|
@ -115,10 +115,12 @@ class Badge < ActiveRecord::Base
|
||||||
has_many :user_badges, dependent: :destroy
|
has_many :user_badges, dependent: :destroy
|
||||||
has_many :upload_references, as: :target, dependent: :destroy
|
has_many :upload_references, as: :target, dependent: :destroy
|
||||||
|
|
||||||
validates :name, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true, length: { maximum: 100 }
|
||||||
validates :badge_type, presence: true
|
validates :badge_type, presence: true
|
||||||
validates :allow_title, inclusion: [true, false]
|
validates :allow_title, inclusion: [true, false]
|
||||||
validates :multiple_grant, inclusion: [true, false]
|
validates :multiple_grant, inclusion: [true, false]
|
||||||
|
validates :description, length: { maximum: 250 }
|
||||||
|
validates :long_description, length: { maximum: 1000 }
|
||||||
|
|
||||||
scope :enabled, -> { where(enabled: true) }
|
scope :enabled, -> { where(enabled: true) }
|
||||||
|
|
||||||
|
@ -220,7 +222,7 @@ class Badge < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.i18n_name(name)
|
def self.i18n_name(name)
|
||||||
name.downcase.tr(" ", "_")
|
name.to_s.downcase.tr(" ", "_")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.display_name(name)
|
def self.display_name(name)
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe Badge do
|
RSpec.describe Badge do
|
||||||
|
describe "Validations" do
|
||||||
|
subject(:badge) { Fabricate.build(:badge) }
|
||||||
|
|
||||||
|
it { is_expected.to validate_length_of(:name).is_at_most(100) }
|
||||||
|
it { is_expected.to validate_length_of(:description).is_at_most(250) }
|
||||||
|
it { is_expected.to validate_length_of(:long_description).is_at_most(1000) }
|
||||||
|
it { is_expected.to validate_presence_of(:name) }
|
||||||
|
it { is_expected.to validate_presence_of(:badge_type) }
|
||||||
|
it { is_expected.to validate_uniqueness_of(:name) }
|
||||||
|
end
|
||||||
|
|
||||||
it "has a valid system attribute for new badges" do
|
it "has a valid system attribute for new badges" do
|
||||||
expect(Badge.create!(name: "test", badge_type_id: 1).system?).to be false
|
expect(Badge.create!(name: "test", badge_type_id: 1).system?).to be false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user