Add information about budget actions
Both the calculate winners and delete actions benefit from some kind of hint. The "calculate winners" hint informs administrators that results won't be publicly available unless the "show results" option is enabled. The delete action was redirecting with an error message when the budget couldn't be deleted; IMHO it's better to disable it and inform administrators why it's disabled. Alternatively we could remove the button completely; however, users might be looking for a way to delete a budget and wouldn't find any hint about it. We're now removing the "Delete" action from the budgets index table, since most of the time it isn't possible to delete a budget and so the action takes up space and we get little gain in return. We could keep the "Delete" icon just for budgets which can be deleted; however, the alignment of the table rows would suffer, making it harder to find the intended action.
This commit is contained in:
@@ -22,4 +22,41 @@ describe Admin::BudgetsController, :admin do
|
||||
end.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
let(:budget) { create(:budget) }
|
||||
|
||||
it "allows destroying budgets without investments but with administrators and valuators" do
|
||||
budget.administrators << Administrator.first
|
||||
budget.valuators << create(:valuator)
|
||||
|
||||
delete :destroy, params: { id: budget }
|
||||
|
||||
expect(response).to redirect_to admin_budgets_path
|
||||
expect(flash[:notice]).to eq "Budget deleted successfully"
|
||||
expect(Budget.count).to eq 0
|
||||
expect(BudgetAdministrator.count).to eq 0
|
||||
expect(BudgetValuator.count).to eq 0
|
||||
end
|
||||
|
||||
it "does not destroy budgets with investments" do
|
||||
create(:budget_investment, budget: budget)
|
||||
|
||||
delete :destroy, params: { id: budget }
|
||||
|
||||
expect(response).to redirect_to admin_budget_path(budget)
|
||||
expect(flash[:alert]).to eq "You cannot delete a budget that has associated investments"
|
||||
expect(Budget.all).to eq [budget]
|
||||
end
|
||||
|
||||
it "does not destroy budgets with a poll" do
|
||||
create(:poll, budget: budget)
|
||||
|
||||
delete :destroy, params: { id: budget }
|
||||
|
||||
expect(response).to redirect_to admin_budget_path(budget)
|
||||
expect(flash[:alert]).to eq "You cannot delete a budget that has an associated poll"
|
||||
expect(Budget.all).to eq [budget]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user