diff --git a/app/models/custom_tab.rb b/app/models/custom_tab.rb index 4f52150940..22058efcc1 100644 --- a/app/models/custom_tab.rb +++ b/app/models/custom_tab.rb @@ -3,5 +3,5 @@ class CustomTab < ApplicationRecord belongs_to :enterprise, optional: false - validates :title, presence: true + validates :title, presence: true, length: { maximum: 20 } end diff --git a/spec/models/custom_tab_spec.rb b/spec/models/custom_tab_spec.rb index f710b30461..f192068f63 100644 --- a/spec/models/custom_tab_spec.rb +++ b/spec/models/custom_tab_spec.rb @@ -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 diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 6eee1aab36..57e674c776 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -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