Skip to content

Commit

Permalink
Fix budgets zero single view
Browse files Browse the repository at this point in the history
* Budget component set at zero in view

* Adding suggestion of Alex to patch
  • Loading branch information
greenwoodt authored and alecslupu committed Jun 14, 2023
1 parent 0988ce9 commit 9e8eafc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Expand Up @@ -16,7 +16,8 @@ class BudgetForm < Decidim::Form
attribute :decidim_scope_id, Integer

validates :title, translatable_presence: true
validates :weight, :total_budget, numericality: { greater_than_or_equal_to: 0 }
validates :weight, numericality: { greater_than_or_equal_to: 0 }
validates :total_budget, numericality: { greater_than: 0 }
validates :scope, presence: true, if: ->(form) { form.decidim_scope_id.present? }
validates :decidim_scope_id, scope_belongs_to_component: true, if: ->(form) { form.decidim_scope_id.present? }

Expand Down
1 change: 1 addition & 0 deletions decidim-budgets/app/models/decidim/budgets/order.rb
Expand Up @@ -109,6 +109,7 @@ def can_checkout?
# enabled
def budget_percent
return (total_projects.to_f / maximum_projects) * 100 if projects_rule?
return 0 if budget.total_budget.zero?

(total_budget.to_f / budget.total_budget) * 100
end
Expand Down
Expand Up @@ -51,6 +51,12 @@
it { is_expected.not_to be_valid }
end

describe "when total_budget is equal to 0" do
let(:total_budget) { 0 }

it { is_expected.not_to be_valid }
end

describe "when the scope does not exist" do
let(:scope_id) { scope.id + 10 }

Expand Down
10 changes: 10 additions & 0 deletions decidim-budgets/spec/system/orders_spec.rb
Expand Up @@ -121,6 +121,16 @@
end
end
end

context "when the total budget is zero" do
let(:budget) { create(:budget, total_budget: 0, component: component) }

it "displays total budget" do
within ".budget-summary__total" do
expect(page).to have_content("TOTAL BUDGET €0")
end
end
end
end

context "and has not a pending order" do
Expand Down

0 comments on commit 9e8eafc

Please sign in to comment.