Make it possible to select investments without JavaScript

This commit is contained in:
Javi Martín
2024-10-09 13:03:27 +02:00
parent 54a48d63e1
commit 173b1bb07c
2 changed files with 26 additions and 2 deletions

View File

@@ -64,14 +64,20 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
authorize! :select, @investment
@investment.update!(selected: true)
render :toggle_selection
respond_to do |format|
format.html { redirect_to request.referer, notice: t("flash.actions.update.budget_investment") }
format.js { render :toggle_selection }
end
end
def deselect
authorize! :deselect, @investment
@investment.update!(selected: false)
render :toggle_selection
respond_to do |format|
format.html { redirect_to request.referer, notice: t("flash.actions.update.budget_investment") }
format.js { render :toggle_selection }
end
end
private

View File

@@ -66,6 +66,15 @@ describe Admin::BudgetInvestmentsController, :admin do
"'select' on Investment."
expect(investment).not_to be_selected
end
it "redirects admins without JavaScript to the same page" do
request.env["HTTP_REFERER"] = admin_budget_budget_investments_path(investment.budget)
patch :select, params: { id: investment, budget_id: investment.budget }
expect(response).to redirect_to admin_budget_budget_investments_path(investment.budget)
expect(flash[:notice]).to eq "Investment project updated successfully."
end
end
describe "PATCH deselect" do
@@ -96,5 +105,14 @@ describe Admin::BudgetInvestmentsController, :admin do
"'deselect' on Investment."
expect(investment).to be_selected
end
it "redirects admins without JavaScript to the same page" do
request.env["HTTP_REFERER"] = admin_budget_budget_investments_path(investment.budget)
patch :deselect, params: { id: investment, budget_id: investment.budget }
expect(response).to redirect_to admin_budget_budget_investments_path(investment.budget)
expect(flash[:notice]).to eq "Investment project updated successfully."
end
end
end