Limit size to 20 char for the custom tab title

This commit is contained in:
Jean-Baptiste Bellet
2023-06-05 15:59:45 +02:00
parent 93cf562d59
commit d1d050e6a4
3 changed files with 12 additions and 1 deletions

View File

@@ -3,5 +3,5 @@
class CustomTab < ApplicationRecord
belongs_to :enterprise, optional: false
validates :title, presence: true
validates :title, presence: true, length: { maximum: 20 }
end

View File

@@ -9,5 +9,7 @@ describe CustomTab do
describe 'validations' do
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_length_of(:title).is_at_most(20) }
end
end

View File

@@ -753,6 +753,15 @@ describe '
expect(page).to have_content("Custom tab title can't be blank")
expect(distributor1.reload.custom_tab).to be_nil
end
it "can't save custom tab fields if title is too long" do
fill_in "enterprise_custom_tab_attributes_title", with: "a" * 21
fill_in_trix_editor "custom_tab_content", with: "Custom tab content"
click_button 'Update'
expect(page).
to have_content("Custom tab title is too long (maximum is 20 characters)")
expect(distributor1.reload.custom_tab).to be_nil
end
end
context "when custom tab is already created" do