mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -2,4 +2,6 @@
|
||||
|
||||
class CustomTab < ApplicationRecord
|
||||
belongs_to :enterprise, optional: false
|
||||
|
||||
validates :title, presence: true, length: { maximum: 20 }
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user