From 4e9d5d8c5a7b39e4e124e9c70596bc3f831080d3 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 27 Oct 2023 10:59:13 +0200 Subject: [PATCH] Allow sorting widget_cards on custom pages --- app/controllers/pages_controller.rb | 2 +- spec/system/site_customization/custom_pages_spec.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index bc997297b..267f659e0 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -8,7 +8,7 @@ class PagesController < ApplicationController @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id]) if @custom_page.present? - @cards = @custom_page.cards + @cards = @custom_page.cards.sort_by_order render action: :custom_page else render action: params[:id].split(".").first diff --git a/spec/system/site_customization/custom_pages_spec.rb b/spec/system/site_customization/custom_pages_spec.rb index 79ba0da43..9a9ad7738 100644 --- a/spec/system/site_customization/custom_pages_spec.rb +++ b/spec/system/site_customization/custom_pages_spec.rb @@ -94,11 +94,14 @@ describe "Custom Pages" do scenario "Show widget cards for that page" do custom_page = create(:site_customization_page, :published) - create(:widget_card, cardable: custom_page, title: "Card Highlights") + create(:widget_card, cardable: custom_page, title: "Medium prominent card", order: 2) + create(:widget_card, cardable: custom_page, title: "Less prominent card", order: 2) + create(:widget_card, cardable: custom_page, title: "Card Highlights", order: 1) visit custom_page.url - expect(page).to have_content "CARD HIGHLIGHTS" + expect("CARD HIGHLIGHTS").to appear_before("MEDIUM PROMINENT CARD") + expect("MEDIUM PROMINENT CARD").to appear_before("LESS PROMINENT CARD") end end end