adds spending proposals to admin
This commit is contained in:
committed by
Juanjo Bazán
parent
7c92a92537
commit
3f05864a16
26
app/controllers/admin/spending_proposals_controller.rb
Normal file
26
app/controllers/admin/spending_proposals_controller.rb
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
class Admin::SpendingProposalsController < Admin::BaseController
|
||||||
|
has_filters %w{unresolved accepted rejected}, only: :index
|
||||||
|
|
||||||
|
before_action :load_spending_proposal, except: [:index]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@spending_proposals = SpendingProposal.send(@current_filter).order(created_at: :desc).page(params[:page])
|
||||||
|
end
|
||||||
|
|
||||||
|
def accept
|
||||||
|
@spending_proposal.accept
|
||||||
|
redirect_to request.query_parameters.merge(action: :index)
|
||||||
|
end
|
||||||
|
|
||||||
|
def reject
|
||||||
|
@spending_proposal.reject
|
||||||
|
redirect_to request.query_parameters.merge(action: :index)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_spending_proposal
|
||||||
|
@spending_proposal = SpendingProposal.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -32,6 +32,13 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "spending_proposals" %>>
|
||||||
|
<%= link_to admin_spending_proposals_path do %>
|
||||||
|
<i class="icon-proposals"></i>
|
||||||
|
<%= t("admin.menu.spending_proposals") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li <%= "class=active" if controller_name == "users" %>>
|
<li <%= "class=active" if controller_name == "users" %>>
|
||||||
<%= link_to admin_users_path do %>
|
<%= link_to admin_users_path do %>
|
||||||
<i class="icon-eye"></i>
|
<i class="icon-eye"></i>
|
||||||
|
|||||||
33
app/views/admin/spending_proposals/index.html.erb
Normal file
33
app/views/admin/spending_proposals/index.html.erb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<h2><%= t("admin.spending_proposals.index.title") %></h2>
|
||||||
|
|
||||||
|
<%= render 'shared/filter_subnav', i18n_namespace: "admin.spending_proposals.index" %>
|
||||||
|
|
||||||
|
<h3><%= page_entries_info @spending_proposals %></h3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<% @spending_proposals.each do |spending_proposal| %>
|
||||||
|
<tr id="<%= dom_id(spending_proposal) %>">
|
||||||
|
<td>
|
||||||
|
<strong><%= spending_proposal.title %></strong>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<% unless spending_proposal.accepted? %>
|
||||||
|
<%= link_to t("admin.spending_proposals.actions.accept"),
|
||||||
|
accept_admin_spending_proposal_path(spending_proposal, request.query_parameters),
|
||||||
|
method: :put,
|
||||||
|
data: { confirm: t("admin.actions.confirm") },
|
||||||
|
class: "button radius tiny success no-margin" %>
|
||||||
|
<% end %>
|
||||||
|
<% unless spending_proposal.rejected? %>
|
||||||
|
<%= link_to t("admin.spending_proposals.actions.reject"),
|
||||||
|
reject_admin_spending_proposal_path(spending_proposal, request.query_parameters),
|
||||||
|
method: :put,
|
||||||
|
data: { confirm: t("admin.actions.confirm") },
|
||||||
|
class: "button radius tiny warning right" %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @spending_proposals %>
|
||||||
@@ -109,6 +109,7 @@ ignore_unused:
|
|||||||
- 'admin.comments.index.filter*'
|
- 'admin.comments.index.filter*'
|
||||||
- 'admin.debates.index.filter*'
|
- 'admin.debates.index.filter*'
|
||||||
- 'admin.proposals.index.filter*'
|
- 'admin.proposals.index.filter*'
|
||||||
|
- 'admin.spending_proposals.index.filter*'
|
||||||
- 'admin.organizations.index.filter*'
|
- 'admin.organizations.index.filter*'
|
||||||
- 'admin.users.index.filter*'
|
- 'admin.users.index.filter*'
|
||||||
- 'admin.activity.show.filter*'
|
- 'admin.activity.show.filter*'
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ en:
|
|||||||
hidden_debates: "Hidden debates"
|
hidden_debates: "Hidden debates"
|
||||||
hidden_comments: "Hidden comments"
|
hidden_comments: "Hidden comments"
|
||||||
hidden_users: "Hidden users"
|
hidden_users: "Hidden users"
|
||||||
|
spending_proposals: "Spending proposals"
|
||||||
incomplete_verifications: "Incomplete verifications"
|
incomplete_verifications: "Incomplete verifications"
|
||||||
organizations: "Organisations"
|
organizations: "Organisations"
|
||||||
officials: "Officials"
|
officials: "Officials"
|
||||||
@@ -91,6 +92,17 @@ en:
|
|||||||
all: "All"
|
all: "All"
|
||||||
with_confirmed_hide: "Confirmed"
|
with_confirmed_hide: "Confirmed"
|
||||||
without_confirmed_hide: "Pending"
|
without_confirmed_hide: "Pending"
|
||||||
|
spending_proposals:
|
||||||
|
actions:
|
||||||
|
accept: Accept
|
||||||
|
reject: Reject
|
||||||
|
index:
|
||||||
|
title: "Spending proposals for participatory budgeting"
|
||||||
|
filter: "Filter"
|
||||||
|
filters:
|
||||||
|
unresolved: "Unresolved"
|
||||||
|
accepted: "Accepted"
|
||||||
|
rejected: "Rejected"
|
||||||
users:
|
users:
|
||||||
index:
|
index:
|
||||||
title: "Hidden users"
|
title: "Hidden users"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ es:
|
|||||||
hidden_debates: "Debates ocultos"
|
hidden_debates: "Debates ocultos"
|
||||||
hidden_comments: "Comentarios ocultos"
|
hidden_comments: "Comentarios ocultos"
|
||||||
hidden_users: "Usuarios bloqueados"
|
hidden_users: "Usuarios bloqueados"
|
||||||
|
spending_proposals: "Propuestas de gasto"
|
||||||
incomplete_verifications: "Verificaciones incompletas"
|
incomplete_verifications: "Verificaciones incompletas"
|
||||||
organizations: "Organizaciones"
|
organizations: "Organizaciones"
|
||||||
officials: "Cargos públicos"
|
officials: "Cargos públicos"
|
||||||
@@ -91,6 +92,17 @@ es:
|
|||||||
all: "Todas"
|
all: "Todas"
|
||||||
with_confirmed_hide: "Confirmadas"
|
with_confirmed_hide: "Confirmadas"
|
||||||
without_confirmed_hide: "Pendientes"
|
without_confirmed_hide: "Pendientes"
|
||||||
|
spending_proposals:
|
||||||
|
actions:
|
||||||
|
accept: Aceptar
|
||||||
|
reject: Rechazar
|
||||||
|
index:
|
||||||
|
title: "Propuestas de gasto para presupuestos participativos"
|
||||||
|
filter: "Filtro"
|
||||||
|
filters:
|
||||||
|
unresolved: "Sin resolver"
|
||||||
|
accepted: "Aceptadas"
|
||||||
|
rejected: "Rechazadas"
|
||||||
users:
|
users:
|
||||||
index:
|
index:
|
||||||
title: "Usuarios bloqueados"
|
title: "Usuarios bloqueados"
|
||||||
|
|||||||
@@ -122,6 +122,13 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :spending_proposals, only: :index do
|
||||||
|
member do
|
||||||
|
put :accept
|
||||||
|
put :reject
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :comments, only: :index do
|
resources :comments, only: :index do
|
||||||
member do
|
member do
|
||||||
put :restore
|
put :restore
|
||||||
|
|||||||
100
spec/features/admin/spending_proposals_spec.rb
Normal file
100
spec/features/admin/spending_proposals_spec.rb
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Admin spending proposals' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Index shows spending proposals' do
|
||||||
|
spending_proposal = create(:spending_proposal)
|
||||||
|
visit admin_spending_proposals_path
|
||||||
|
|
||||||
|
expect(page).to have_content(spending_proposal.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Accept' do
|
||||||
|
spending_proposal = create(:spending_proposal)
|
||||||
|
visit admin_spending_proposals_path
|
||||||
|
|
||||||
|
click_link 'Accept'
|
||||||
|
|
||||||
|
expect(page).to_not have_content(spending_proposal.title)
|
||||||
|
|
||||||
|
click_link 'Accepted'
|
||||||
|
expect(page).to have_content(spending_proposal.title)
|
||||||
|
|
||||||
|
expect(spending_proposal.reload).to be_accepted
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Reject' do
|
||||||
|
spending_proposal = create(:spending_proposal)
|
||||||
|
visit admin_spending_proposals_path
|
||||||
|
|
||||||
|
click_link 'Reject'
|
||||||
|
|
||||||
|
expect(page).to_not have_content(spending_proposal.title)
|
||||||
|
|
||||||
|
click_link('Rejected')
|
||||||
|
expect(page).to have_content(spending_proposal.title)
|
||||||
|
|
||||||
|
expect(spending_proposal.reload).to be_rejected
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Current filter is properly highlighted" do
|
||||||
|
visit admin_spending_proposals_path
|
||||||
|
expect(page).to_not have_link('Unresolved')
|
||||||
|
expect(page).to have_link('Accepted')
|
||||||
|
expect(page).to have_link('Rejected')
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'unresolved')
|
||||||
|
expect(page).to_not have_link('Unresolved')
|
||||||
|
expect(page).to have_link('Accepted')
|
||||||
|
expect(page).to have_link('Rejected')
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'accepted')
|
||||||
|
expect(page).to have_link('Unresolved')
|
||||||
|
expect(page).to_not have_link('Accepted')
|
||||||
|
expect(page).to have_link('Rejected')
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'rejected')
|
||||||
|
expect(page).to have_link('Accepted')
|
||||||
|
expect(page).to have_link('Unresolved')
|
||||||
|
expect(page).to_not have_link('Rejected')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Filtering proposals" do
|
||||||
|
create(:spending_proposal, title: "Recent spending proposal")
|
||||||
|
create(:spending_proposal, title: "Good spending proposal", resolution: "accepted")
|
||||||
|
create(:spending_proposal, title: "Bad spending proposal", resolution: "rejected")
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'unresolved')
|
||||||
|
expect(page).to have_content('Recent spending proposal')
|
||||||
|
expect(page).to_not have_content('Good spending proposal')
|
||||||
|
expect(page).to_not have_content('Bad spending proposal')
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'accepted')
|
||||||
|
expect(page).to have_content('Good spending proposal')
|
||||||
|
expect(page).to_not have_content('Recent spending proposal')
|
||||||
|
expect(page).to_not have_content('Bad spending proposal')
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'rejected')
|
||||||
|
expect(page).to have_content('Bad spending proposal')
|
||||||
|
expect(page).to_not have_content('Good spending proposal')
|
||||||
|
expect(page).to_not have_content('Recent spending proposal')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Action links remember the pagination setting and the filter" do
|
||||||
|
per_page = Kaminari.config.default_per_page
|
||||||
|
(per_page + 2).times { create(:spending_proposal, resolution: "accepted") }
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path(filter: 'accepted', page: 2)
|
||||||
|
|
||||||
|
click_on('Reject', match: :first, exact: true)
|
||||||
|
|
||||||
|
expect(current_url).to include('filter=accepted')
|
||||||
|
expect(current_url).to include('page=2')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user