Ability to edit geozones from admin dashboard
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
13
app/views/admin/geozones/edit.html.erb
Normal file
13
app/views/admin/geozones/edit.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= link_to admin_geozones_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.geozones.edit.back") %>
|
||||
<% end %>
|
||||
|
||||
<h1><%= t("admin.geozones.edit.editing") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -9,6 +9,7 @@
|
||||
<th><%= t("admin.geozones.geozone.name") %></th>
|
||||
<th><%= t("admin.geozones.geozone.external_code") %></th>
|
||||
<th><%= t("admin.geozones.geozone.census_code") %></th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -18,6 +19,9 @@
|
||||
<td><%= geozone.name %></td>
|
||||
<td><%= geozone.external_code %></td>
|
||||
<td><%= geozone.census_code %></td>
|
||||
<td>
|
||||
<%= link_to t("admin.geozones.index.edit"), edit_admin_geozone_path(geozone), class: 'edit-banner button hollow' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -284,6 +284,8 @@ en:
|
||||
edit:
|
||||
form:
|
||||
submit_button: Save changes
|
||||
editing: Editing geozone
|
||||
back: Go back
|
||||
new:
|
||||
back: Volver
|
||||
creating: Crear distrito
|
||||
|
||||
@@ -282,6 +282,8 @@ es:
|
||||
edit:
|
||||
form:
|
||||
submit_button: Guardar cambios
|
||||
editing: Editando distrito
|
||||
back: Volver
|
||||
new:
|
||||
back: Volver
|
||||
creating: Crear distrito
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user