Make card title mandatory
We didn't add any validation rules to the card model. At the very least, the title should be mandatory. The fact that the label field is marked as optional in the form but the other fields are not probably means description and link should be mandatory as well. However, since there might be institutions using cards with descriptions but no link or cards with links but no description, so we're keeping these fields optional for compatibility reasons. We might change our minds in the future, though.
This commit is contained in:
@@ -14,6 +14,8 @@ class Widget::Card < ApplicationRecord
|
|||||||
translates :link_text, touch: true
|
translates :link_text, touch: true
|
||||||
include Globalizable
|
include Globalizable
|
||||||
|
|
||||||
|
validates_translation :title, presence: true
|
||||||
|
|
||||||
def self.header
|
def self.header
|
||||||
where(header: true)
|
where(header: true)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<%= render "shared/globalize_locales", resource: @card %>
|
<%= render "shared/globalize_locales", resource: @card %>
|
||||||
|
|
||||||
<%= translatable_form_for [:admin, @card] do |f| %>
|
<%= translatable_form_for [:admin, @card] do |f| %>
|
||||||
|
<%= render "shared/errors", resource: @card %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<%= f.translatable_fields do |translations_form| %>
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
@@ -49,7 +50,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<%= f.submit(t("admin.homepage.#{action_name}.#{@card.header? ? "submit_header" : "submit_card"}"), class: "button success") %>
|
<%= f.submit(
|
||||||
|
t("admin.homepage.#{admin_submit_action(@card)}.#{@card.header? ? "submit_header" : "submit_card"}"),
|
||||||
|
class: "button success"
|
||||||
|
) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ describe Widget::Card do
|
|||||||
it "is valid" do
|
it "is valid" do
|
||||||
expect(card).to be_valid
|
expect(card).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is not valid without a title" do
|
||||||
|
expect(build(:widget_card, title: "")).not_to be_valid
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#header" do
|
describe "#header" do
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ module Notifications
|
|||||||
def error_message(resource_model = nil)
|
def error_message(resource_model = nil)
|
||||||
resource_model ||= "(.*)"
|
resource_model ||= "(.*)"
|
||||||
field_check_message = "Please check the marked fields to know how to correct them:"
|
field_check_message = "Please check the marked fields to know how to correct them:"
|
||||||
/\d errors? prevented this #{resource_model} from being saved. #{field_check_message}/
|
/\d errors? prevented this #{resource_model} from being saved.(\n| )#{field_check_message}/
|
||||||
end
|
end
|
||||||
|
|
||||||
def fill_in_admin_notification_form(options = {})
|
def fill_in_admin_notification_form(options = {})
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ describe "Cards", :admin do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Create with errors", :js do
|
||||||
|
visit admin_homepage_path
|
||||||
|
click_link "Create card"
|
||||||
|
click_button "Create card"
|
||||||
|
|
||||||
|
expect(page).to have_text error_message
|
||||||
|
expect(page).to have_button "Create card"
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Index" do
|
scenario "Index" do
|
||||||
3.times { create(:widget_card) }
|
3.times { create(:widget_card) }
|
||||||
|
|
||||||
@@ -130,6 +139,15 @@ describe "Cards", :admin do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Create with errors", :js do
|
||||||
|
visit admin_homepage_path
|
||||||
|
click_link "Create header"
|
||||||
|
click_button "Create header"
|
||||||
|
|
||||||
|
expect(page).to have_text error_message
|
||||||
|
expect(page).to have_button "Create header"
|
||||||
|
end
|
||||||
|
|
||||||
context "Page card" do
|
context "Page card" do
|
||||||
let!(:custom_page) { create(:site_customization_page, :published) }
|
let!(:custom_page) { create(:site_customization_page, :published) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user