From b8b0b911289569cad64e58baae793964b67731ac Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 19 Nov 2024 09:19:28 +0100 Subject: [PATCH 1/2] Add `#authorization_subject` to Promotions controllers The `authorization_subject` method from `solidus_admin` assumes that all models are in the `Spree` namespace. (cherry picked from commit c2ba46a46311acae1c3a7719494fbb8cffe1af5b) --- .../solidus_promotions/promotion_categories_controller.rb | 6 ++++++ .../admin/solidus_promotions/promotions_controller.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb index cefb9d44d5d..0218e3a94c2 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb @@ -25,5 +25,11 @@ def destroy flash[:notice] = t(".success") redirect_back_or_to solidus_promotions.promotion_categories_path, status: :see_other end + + private + + def authorization_subject + SolidusPromotions::PromotionCategory + end end end diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb index 77bc6515108..62b856006a0 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb @@ -42,5 +42,9 @@ def load_promotion def promotion_params params.require(:promotion).permit(:user_id, permitted_promotion_attributes) end + + def authorization_subject + SolidusPromotions::Promotion + end end end From 7eb51786ac1b9c27ec4758556beb9ad2efc92727 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 19 Nov 2024 09:50:49 +0100 Subject: [PATCH 2/2] Fix admin promotions controller This controller still did not know how what to authorize against, and wanted to visit a URL that doesn't exist when clicking on a promotion. This also changes at least the name of each promotion to be a link element that can easily be targeted with Capybara and works with all major browsers. (cherry picked from commit 2eccd6d6d5b4eaeaad2c3ace32409ea87d821443) --- .../solidus_promotions/promotions/index/component.rb | 10 ++++++---- .../solidus_promotions/promotions/index/component.yml | 1 + .../system/solidus_promotions/admin/promotions_spec.rb | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb index 4d64c3164e9..8416e5d343c 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb +++ b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb @@ -14,7 +14,7 @@ def search_url end def row_url(promotion) - solidus_promotions.admin_promotion_path(promotion) + solidus_promotions.edit_admin_promotion_path(promotion) end def page_actions @@ -63,14 +63,16 @@ def columns { header: :name, data: ->(promotion) do - content_tag :div, promotion.name + link_to promotion.name, row_url(promotion) end }, { header: :code, data: ->(promotion) do - count = promotion.codes.count - (count == 1) ? promotion.codes.pick(:value) : t("spree.number_of_codes", count: count) + link_to solidus_promotions.admin_promotion_promotion_codes_path(promotion), title: t(".codes") do + count = promotion.codes.count + (count == 1) ? promotion.codes.pick(:value) : t("spree.number_of_codes", count: count) + end end }, { diff --git a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml index 7ba70160390..cf53ebf0d54 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml +++ b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml @@ -8,3 +8,4 @@ en: status: active: Active inactive: Inactive + codes: Codes diff --git a/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb b/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb index 85caf2af6c8..c02a8066084 100644 --- a/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb +++ b/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb @@ -32,5 +32,9 @@ expect(page).to have_content("Promotions were successfully removed.") expect(page).not_to have_content("My active Promotion") expect(SolidusPromotions::Promotion.count).to eq(3) + + click_link("My future Promotion") + expect(page).to have_content("My future Promotion") + expect(page).to have_content("Starts at") end end