Add order field to widget cards
We will use this field to enter the position where the cards will be shown to the user in the homepage.
This commit is contained in:
@@ -10,6 +10,7 @@ class Widget::Card < ApplicationRecord
|
||||
|
||||
validates_translation :title, presence: true
|
||||
validates :link_url, presence: true, if: -> { !header? || link_text.present? }
|
||||
validates :order, numericality: { greater_than_or_equal_to: 1 }
|
||||
|
||||
def self.header
|
||||
where(header: true)
|
||||
|
||||
5
db/migrate/20231009143355_add_order_to_widget_cards.rb
Normal file
5
db/migrate/20231009143355_add_order_to_widget_cards.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddOrderToWidgetCards < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :widget_cards, :order, :integer, null: false, default: 1
|
||||
end
|
||||
end
|
||||
@@ -1768,6 +1768,7 @@ ActiveRecord::Schema.define(version: 2023_10_12_141318) do
|
||||
t.integer "cardable_id"
|
||||
t.integer "columns", default: 4
|
||||
t.string "cardable_type", default: "SiteCustomization::Page"
|
||||
t.integer "order", default: 1, null: false
|
||||
t.index ["cardable_id"], name: "index_widget_cards_on_cardable_id"
|
||||
end
|
||||
|
||||
|
||||
@@ -18,6 +18,16 @@ describe Widget::Card do
|
||||
expect(build(:widget_card, title: "")).not_to be_valid
|
||||
end
|
||||
|
||||
describe "order" do
|
||||
it "is not valid without an order" do
|
||||
expect(build(:widget_card, order: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid with an order less than 1" do
|
||||
expect(build(:widget_card, order: 0)).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "regular cards" do
|
||||
it "is not valid without a link_url" do
|
||||
card = build(:widget_card, header: false, link_url: nil)
|
||||
|
||||
Reference in New Issue
Block a user