diff --git a/app/controllers/admin/geozones_controller.rb b/app/controllers/admin/geozones_controller.rb
index 10747912a..eb8119a91 100644
--- a/app/controllers/admin/geozones_controller.rb
+++ b/app/controllers/admin/geozones_controller.rb
@@ -9,6 +9,8 @@ class Admin::GeozonesController < Admin::BaseController
def new
end
+ def edit
+ end
def create
@geozone = Geozone.new(geozone_params)
@@ -20,6 +22,13 @@ class Admin::GeozonesController < Admin::BaseController
end
end
+ def update
+ if @geozone.update(geozone_params)
+ redirect_to admin_geozones_path
+ else
+ render :edit
+ end
+ end
private
def geozone_params
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index be5bed1ac..975ba7a8d 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -43,7 +43,7 @@ module Abilities
can [:read, :update, :destroy, :summary], SpendingProposal
can [:search, :edit, :update, :create, :index, :destroy], Banner
- can [:index, :create], Geozone
+ can [:index, :create, :edit, :update, :destroy], Geozone
end
end
end
diff --git a/app/views/admin/geozones/edit.html.erb b/app/views/admin/geozones/edit.html.erb
new file mode 100644
index 000000000..b6b8c3fd9
--- /dev/null
+++ b/app/views/admin/geozones/edit.html.erb
@@ -0,0 +1,13 @@
+
+
+
+ <%= link_to admin_geozones_path, class: "back" do %>
+
+ <%= t("admin.geozones.edit.back") %>
+ <% end %>
+
+
<%= t("admin.geozones.edit.editing") %>
+
+ <%= render "form" %>
+
+
diff --git a/app/views/admin/geozones/index.html.erb b/app/views/admin/geozones/index.html.erb
index 78b4c4312..9cedca9c6 100644
--- a/app/views/admin/geozones/index.html.erb
+++ b/app/views/admin/geozones/index.html.erb
@@ -9,6 +9,7 @@
<%= t("admin.geozones.geozone.name") %> |
<%= t("admin.geozones.geozone.external_code") %> |
<%= t("admin.geozones.geozone.census_code") %> |
+ |
@@ -18,6 +19,9 @@
<%= geozone.name %> |
<%= geozone.external_code %> |
<%= geozone.census_code %> |
+
+ <%= link_to t("admin.geozones.index.edit"), edit_admin_geozone_path(geozone), class: 'edit-banner button hollow' %>
+ |
<% end %>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 6ddfddc47..c46efd04d 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -284,6 +284,8 @@ en:
edit:
form:
submit_button: Save changes
+ editing: Editing geozone
+ back: Go back
new:
back: Volver
creating: Crear distrito
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 1a28fa162..3d14a717f 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -282,6 +282,8 @@ es:
edit:
form:
submit_button: Guardar cambios
+ editing: Editando distrito
+ back: Volver
new:
back: Volver
creating: Crear distrito
diff --git a/config/routes.rb b/config/routes.rb
index 0a621a0d5..885d155db 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -193,7 +193,7 @@ Rails.application.routes.draw do
resource :stats, only: :show
end
- resources :geozones, only: [:index, :new, :create]
+ resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
end
namespace :moderation do
diff --git a/spec/features/admin/geozones_spec.rb b/spec/features/admin/geozones_spec.rb
index 46bfc9a0c..d571f6616 100644
--- a/spec/features/admin/geozones_spec.rb
+++ b/spec/features/admin/geozones_spec.rb
@@ -37,4 +37,41 @@ feature 'Admin geozones' do
expect(page).to have_content 'Fancy District'
end
+
+ scenario 'Edit geozone with no associated elements' do
+ target_geozone = create(:geozone, name: 'Edit me!', census_code: '012')
+
+ visit admin_geozones_path
+
+ within("#geozone_#{target_geozone.id}") do
+ click_link "Edit"
+ end
+
+ fill_in 'geozone_name', with: 'New geozone name'
+ fill_in 'geozone_census_code', with: '333'
+
+ click_button 'Save changes'
+
+ within("#geozone_#{target_geozone.id}") do
+ expect(page).to have_content 'New geozone name'
+ expect(page).to have_content '333'
+ end
+ end
+
+ scenario 'Edit geozone with associated elements' do
+ target_geozone = create(:geozone, name: 'Edit me!')
+ proposal = create(:proposal, title: 'Proposal with geozone', geozone: target_geozone)
+
+ visit admin_geozones_path
+
+ within("#geozone_#{target_geozone.id}") do
+ click_link "Edit"
+ end
+
+ fill_in 'geozone_name', with: 'New geozone name'
+
+ click_button 'Save changes'
+
+ expect(proposal.geozone.name).to eq('New geozone name')
+ end
end