<% end %>
- <% no_balloted_groups = @budget.groups.order(name: :asc) - ballot_groups %>
+ <% no_balloted_groups = @budget.groups.sort_by_name - ballot_groups %>
<% no_balloted_groups.each do |group| %>
diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb
index d2a95e395..349483767 100644
--- a/config/initializers/routes_hierarchy.rb
+++ b/config/initializers/routes_hierarchy.rb
@@ -5,7 +5,7 @@
module ActionDispatch::Routing::UrlFor
def resource_hierarchy_for(resource)
case resource.class.name
- when "Budget::Investment", "Budget::Phase"
+ when "Budget::Investment", "Budget::Phase", "Budget::Group"
[resource.budget, resource]
when "Milestone"
[*resource_hierarchy_for(resource.milestoneable), resource]
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index a53e0ed8d..17ba3fbfa 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -181,6 +181,7 @@ en:
proposal_notification: "Notification"
spending_proposal: Spending proposal
budget/investment: Investment
+ budget/group: Budget Group
budget/heading: Budget Heading
poll/shift: Shift
poll/question/answer: Answer
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 3acbb6a23..144716687 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -181,6 +181,7 @@ es:
proposal_notification: "la notificación"
spending_proposal: la propuesta de gasto
budget/investment: el proyecto de gasto
+ budget/group: el grupo de partidas presupuestarias
budget/heading: la partida presupuestaria
poll/shift: el turno
poll/question/answer: la respuesta
diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb
index 72fb523cc..2e346d154 100644
--- a/db/dev_seeds/budgets.rb
+++ b/db/dev_seeds/budgets.rb
@@ -52,14 +52,22 @@ section "Creating Budgets" do
end
Budget.all.each do |budget|
- city_group = budget.groups.create!(name: I18n.t('seeds.budgets.groups.all_city'))
+ city_group_params = {
+ name_en: I18n.t("seeds.budgets.groups.all_city", locale: :en),
+ name_es: I18n.t("seeds.budgets.groups.all_city", locale: :es)
+ }
+ city_group = budget.groups.create!(city_group_params)
city_group.headings.create!(name: I18n.t('seeds.budgets.groups.all_city'),
price: 1000000,
population: 1000000,
latitude: '40.416775',
longitude: '-3.703790')
- districts_group = budget.groups.create!(name: I18n.t('seeds.budgets.groups.districts'))
+ districts_group_params = {
+ name_en: I18n.t("seeds.budgets.groups.districts", locale: :en),
+ name_es: I18n.t("seeds.budgets.groups.districts", locale: :es)
+ }
+ districts_group = budget.groups.create!(districts_group_params)
districts_group.headings.create!(name: I18n.t('seeds.geozones.north_district'),
price: rand(5..10) * 100000,
population: 350000,
diff --git a/db/migrate/20190120155819_add_budget_group_translations.rb b/db/migrate/20190120155819_add_budget_group_translations.rb
new file mode 100644
index 000000000..7be1575d3
--- /dev/null
+++ b/db/migrate/20190120155819_add_budget_group_translations.rb
@@ -0,0 +1,16 @@
+class AddBudgetGroupTranslations < ActiveRecord::Migration
+
+ def self.up
+ Budget::Group.create_translation_table!(
+ {
+ name: :string
+ },
+ { migrate_data: true }
+ )
+ end
+
+ def self.down
+ Budget::Group.drop_translation_table!
+ end
+
+end
diff --git a/db/schema.rb b/db/schema.rb
index 02e3db15b..3ed86662a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -138,6 +138,17 @@ ActiveRecord::Schema.define(version: 20190205131722) do
add_index "budget_content_blocks", ["heading_id"], name: "index_budget_content_blocks_on_heading_id", using: :btree
+ create_table "budget_group_translations", force: :cascade do |t|
+ t.integer "budget_group_id", null: false
+ t.string "locale", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "name"
+ end
+
+ add_index "budget_group_translations", ["budget_group_id"], name: "index_budget_group_translations_on_budget_group_id", using: :btree
+ add_index "budget_group_translations", ["locale"], name: "index_budget_group_translations_on_locale", using: :btree
+
create_table "budget_groups", force: :cascade do |t|
t.integer "budget_id"
t.string "name", limit: 50
diff --git a/spec/features/admin/budget_groups_spec.rb b/spec/features/admin/budget_groups_spec.rb
index 869ef55e9..a1bb01bcf 100644
--- a/spec/features/admin/budget_groups_spec.rb
+++ b/spec/features/admin/budget_groups_spec.rb
@@ -9,6 +9,11 @@ feature "Admin budget groups" do
login_as(admin.user)
end
+ it_behaves_like "translatable",
+ "budget_group",
+ "edit_admin_budget_group_path",
+ %w[name]
+
context "Feature flag" do
background do
@@ -140,6 +145,30 @@ feature "Admin budget groups" do
expect(page).to have_field "Maximum number of headings in which a user can vote", with: "2"
end
+ scenario "Changing name for current locale will update the slug if budget is in draft phase", :js do
+ group = create(:budget_group, budget: budget)
+ old_slug = group.slug
+
+ visit edit_admin_budget_group_path(budget, group)
+
+ select "Español", from: "translation_locale"
+ fill_in "Group name", with: "Spanish name"
+ click_button "Save group"
+
+ expect(page).to have_content "Group updated successfully"
+ expect(group.reload.slug).to eq old_slug
+
+ visit edit_admin_budget_group_path(budget, group)
+
+ click_link "English"
+ fill_in "Group name", with: "New English Name"
+ click_button "Save group"
+
+ expect(page).to have_content "Group updated successfully"
+ expect(group.reload.slug).not_to eq old_slug
+ expect(group.slug).to eq "new-english-name"
+ end
+
end
context "Update" do
@@ -173,7 +202,7 @@ feature "Admin budget groups" do
expect(page).not_to have_content "Group updated successfully"
expect(page).to have_css("label.error", text: "Group name")
- expect(page).to have_content "has already been taken"
+ expect(page).to have_css("small.error", text: "has already been taken")
end
end
diff --git a/spec/models/budget/group_spec.rb b/spec/models/budget/group_spec.rb
index 27392e81f..2ab137ba5 100644
--- a/spec/models/budget/group_spec.rb
+++ b/spec/models/budget/group_spec.rb
@@ -1,23 +1,35 @@
-require 'rails_helper'
+require "rails_helper"
describe Budget::Group do
-
- let(:budget) { create(:budget) }
-
it_behaves_like "sluggable", updatable_slug_trait: :drafting_budget
- describe "name" do
- before do
- create(:budget_group, budget: budget, name: 'object name')
+ describe "Validations" do
+
+ let(:budget) { create(:budget) }
+ let(:group) { create(:budget_group, budget: budget) }
+
+ describe "name" do
+ before do
+ group.update(name: "object name")
+ end
+
+ it "can be repeatead in other budget's groups" do
+ expect(build(:budget_group, budget: create(:budget), name: "object name")).to be_valid
+ end
+
+ it "may be repeated for the same group and a different locale" do
+ group.update(name_fr: "object name")
+
+ expect(group.translations.last).to be_valid
+ end
+
+ it "must not be repeated for a different group in any locale" do
+ group.update(name_en: "English", name_es: "Español")
+
+ expect(build(:budget_group, budget: budget, name_en: "English")).not_to be_valid
+ expect(build(:budget_group, budget: budget, name_en: "Español")).not_to be_valid
+ end
end
- it "can be repeatead in other budget's groups" do
- expect(build(:budget_group, budget: create(:budget), name: 'object name')).to be_valid
- end
-
- it "must be unique among all budget's groups" do
- expect(build(:budget_group, budget: budget, name: 'object name')).not_to be_valid
- end
end
-
end
diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb
index b76467a9c..09235ac69 100644
--- a/spec/shared/features/translatable.rb
+++ b/spec/shared/features/translatable.rb
@@ -345,6 +345,8 @@ def update_button_text
"Update Custom page"
when "Widget::Card"
"Save card"
+ when "Budget::Group"
+ "Save group"
else
"Save changes"
end