Skip to content

Commit

Permalink
Fix admin promotions controller
Browse files Browse the repository at this point in the history
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 2eccd6d)
  • Loading branch information
mamhoff committed Dec 6, 2024
1 parent 6daf063 commit b33ec15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ en:
status:
active: Active
inactive: Inactive
codes: Codes
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b33ec15

Please sign in to comment.