Validation in model and in form added. When users makes the on focus on population field an explanation appears. Some specs added to test the model validations
This commit is contained in:
@@ -10,6 +10,7 @@ class Budget
|
|||||||
validates :name, presence: true, uniqueness: { if: :name_exists_in_budget_headings }
|
validates :name, presence: true, uniqueness: { if: :name_exists_in_budget_headings }
|
||||||
validates :price, presence: true
|
validates :price, presence: true
|
||||||
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
||||||
|
validates :population, numericality: { greater_than: 0 }, allow_nil: true
|
||||||
|
|
||||||
delegate :budget, :budget_id, to: :group, allow_nil: true
|
delegate :budget, :budget_id, to: :group, allow_nil: true
|
||||||
|
|
||||||
|
|||||||
@@ -49,10 +49,17 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<label><%= t("admin.budgets.form.population") %></label>
|
<label><%= t("admin.budgets.form.population") %></label>
|
||||||
<%= f.text_field :population,
|
<%= f.number_field :population,
|
||||||
label: false,
|
label: false,
|
||||||
maxlength: 8,
|
maxlength: 8,
|
||||||
placeholder: t("admin.budgets.form.population") %>
|
min: 1,
|
||||||
|
placeholder: t("admin.budgets.form.population"),
|
||||||
|
data: {toggle_focus: "population-info"} %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 column " >
|
||||||
|
<div id="population-info" class="is-hidden" data-toggler="is-hidden">
|
||||||
|
<%= t("admin.budgets.form.population_info") %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ en:
|
|||||||
table_heading: Heading
|
table_heading: Heading
|
||||||
table_amount: Amount
|
table_amount: Amount
|
||||||
table_population: Population
|
table_population: Population
|
||||||
|
population_info: "Budget Heading population field is used for Statistic purposes at the end of the Budget to show for each Heading that represents an area with population what percentage voted. The field is optional so you can leave it empty if it doesn't apply."
|
||||||
winners:
|
winners:
|
||||||
calculate: Calculate Winner Investments
|
calculate: Calculate Winner Investments
|
||||||
calculated: Winners being calculated, it may take a minute.
|
calculated: Winners being calculated, it may take a minute.
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ es:
|
|||||||
table_heading: Partida
|
table_heading: Partida
|
||||||
table_amount: Cantidad
|
table_amount: Cantidad
|
||||||
table_population: Población
|
table_population: Población
|
||||||
|
population_info: "El campo población de las partidas presupuestarias se usa con fines estadísticos únicamente, con el objetivo de mostrar el porcentaje de votos habidos en cada partida que represente un área con población. Es un campo opcional, así que puedes dejarlo en blanco si no aplica."
|
||||||
winners:
|
winners:
|
||||||
calculate: Calcular propuestas ganadoras
|
calculate: Calcular propuestas ganadoras
|
||||||
calculated: Calculando ganadoras, puede tardar un minuto.
|
calculated: Calculando ganadoras, puede tardar un minuto.
|
||||||
|
|||||||
@@ -25,4 +25,18 @@ describe Budget::Heading do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Save population" do
|
||||||
|
it "Allows nil for population" do
|
||||||
|
expect(create(:budget_heading, group: group, name: 'Population is nil')).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "Doesn't allow 0 for population" do
|
||||||
|
expect(create(:budget_heading, group: group, name: 'Population is 0', population: 0)).not_to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "Allows value > 0 for population" do
|
||||||
|
expect(create(:budget_heading, group: group, name: 'Population is 10', population: 10)).to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user