Make it possible to select investments without JavaScript
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user