Merge pull request #10938 from jibees/10931-white-label-custom-tab-without-a-title-impossible-to-disable-the-custom-tab

[White Label] Validate the presence of a custom tab title before creating it (+ max 20 characters length)
This commit is contained in:
Konrad
2023-06-09 19:01:13 +02:00
committed by GitHub
3 changed files with 27 additions and 0 deletions

View File

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

View File

@@ -6,4 +6,10 @@ describe CustomTab do
describe 'associations' do
it { is_expected.to belong_to(:enterprise).required }
end
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,25 @@ describe '
expect(distributor1.reload.custom_tab.content).to eq("<div>Custom tab content</div>")
end
context "managing errors" do
it "can't save custom tab fields if title is blank" do
fill_in "enterprise_custom_tab_attributes_title", with: ""
fill_in_trix_editor "custom_tab_content", with: "Custom tab content"
click_button 'Update'
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
let(:custom_tab) {
create(:custom_tab, title: "Custom tab title",