Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 'Fix budgets zero single view' to v0.27 #11015

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -108,6 +108,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