adds spending proposals to Management
This commit is contained in:
40
app/controllers/management/spending_proposals_controller.rb
Normal file
40
app/controllers/management/spending_proposals_controller.rb
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
class Management::SpendingProposalsController < Management::BaseController
|
||||||
|
|
||||||
|
before_action :check_verified_user
|
||||||
|
|
||||||
|
def new
|
||||||
|
@spending_proposal = SpendingProposal.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@spending_proposal = SpendingProposal.new(spending_proposal_params)
|
||||||
|
@spending_proposal.author = managed_user
|
||||||
|
|
||||||
|
if @spending_proposal.save_with_captcha
|
||||||
|
redirect_to management_spending_proposal_path(@spending_proposal), notice: t('flash.actions.create.notice', resource_name: t("activerecord.models.spending_proposal", count: 1))
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@spending_proposal = SpendingProposal.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def spending_proposal_params
|
||||||
|
params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :terms_of_service, :captcha, :captcha_key)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_verified_user
|
||||||
|
unless current_user.level_two_or_three_verified?
|
||||||
|
redirect_to management_document_verifications_path, alert: t("management.spending_proposals.alert.unverified_user")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_user
|
||||||
|
managed_user
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
10
app/views/management/spending_proposals/new.html.erb
Normal file
10
app/views/management/spending_proposals/new.html.erb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<div class="spending-proposal-new row">
|
||||||
|
|
||||||
|
<%= render '/shared/print' %>
|
||||||
|
|
||||||
|
<div class="small-12 medium-9 column">
|
||||||
|
<h1 class=""><%= t("management.spending_proposals.create") %></h1>
|
||||||
|
<%= render "spending_proposals/form", form_url: management_spending_proposals_url %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
3
app/views/management/spending_proposals/show.html.erb
Normal file
3
app/views/management/spending_proposals/show.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render '/shared/print' %>
|
||||||
|
|
||||||
|
<%= render template: 'spending_proposals/show' %>
|
||||||
@@ -400,7 +400,7 @@ en:
|
|||||||
unauthorized:
|
unauthorized:
|
||||||
default: You do not have permission to access this page.
|
default: You do not have permission to access this page.
|
||||||
manage:
|
manage:
|
||||||
all: You do not have permission to carry out the action '%{action}' on %{subject}.
|
all: "You do not have permission to carry out the action '%{action}' on %{subject}."
|
||||||
users:
|
users:
|
||||||
show:
|
show:
|
||||||
deleted: Deleted
|
deleted: Deleted
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ es:
|
|||||||
debate_title: Título del debate
|
debate_title: Título del debate
|
||||||
tags_instructions: Etiqueta este debate. Puedes elegir entre nuestras propuestas o introducir las que desees.
|
tags_instructions: Etiqueta este debate. Puedes elegir entre nuestras propuestas o introducir las que desees.
|
||||||
tags_label: Temas
|
tags_label: Temas
|
||||||
tags_placeholder: Escribe las etiquetas que desees separadas por coma (',')
|
tags_placeholder: "Escribe las etiquetas que desees separadas por coma (',')"
|
||||||
index:
|
index:
|
||||||
featured_debates: Destacados
|
featured_debates: Destacados
|
||||||
filter_topic:
|
filter_topic:
|
||||||
@@ -261,7 +261,7 @@ es:
|
|||||||
proposal_video_url_note: Puedes añadir un enlace a YouTube o Vimeo
|
proposal_video_url_note: Puedes añadir un enlace a YouTube o Vimeo
|
||||||
tags_instructions: Etiqueta esta propuesta. Puedes elegir entre nuestras sugerencias o introducir las que desees.
|
tags_instructions: Etiqueta esta propuesta. Puedes elegir entre nuestras sugerencias o introducir las que desees.
|
||||||
tags_label: Temas
|
tags_label: Temas
|
||||||
tags_placeholder: Escribe las etiquetas que desees separadas por una coma (',')
|
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
||||||
index:
|
index:
|
||||||
featured_proposals: Destacadas
|
featured_proposals: Destacadas
|
||||||
filter_topic:
|
filter_topic:
|
||||||
@@ -400,7 +400,7 @@ es:
|
|||||||
unauthorized:
|
unauthorized:
|
||||||
default: No tienes permiso para acceder a esta página.
|
default: No tienes permiso para acceder a esta página.
|
||||||
manage:
|
manage:
|
||||||
all: No tienes permiso para realizar la acción '%{action}' sobre %{subject}.
|
all: "No tienes permiso para realizar la acción '%{action}' sobre %{subject}."
|
||||||
users:
|
users:
|
||||||
show:
|
show:
|
||||||
deleted: Eliminado
|
deleted: Eliminado
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ en:
|
|||||||
create_proposal: Create proposal
|
create_proposal: Create proposal
|
||||||
print_proposals: Print proposals
|
print_proposals: Print proposals
|
||||||
support_proposals: Support proposals
|
support_proposals: Support proposals
|
||||||
|
create_spending_proposal: Create spending proposal
|
||||||
title: Management
|
title: Management
|
||||||
users: Users
|
users: Users
|
||||||
permissions:
|
permissions:
|
||||||
@@ -58,6 +59,10 @@ en:
|
|||||||
create_proposal: Create proposal
|
create_proposal: Create proposal
|
||||||
print:
|
print:
|
||||||
print_button: Print
|
print_button: Print
|
||||||
|
spending_proposals:
|
||||||
|
alert:
|
||||||
|
unverified_user: User is not verified
|
||||||
|
create: Create spending proposal
|
||||||
sessions:
|
sessions:
|
||||||
signed_out: Signed out successfully.
|
signed_out: Signed out successfully.
|
||||||
signed_out_managed_user: User session signed out successfully.
|
signed_out_managed_user: User session signed out successfully.
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ es:
|
|||||||
create_proposal: Crear propuesta
|
create_proposal: Crear propuesta
|
||||||
print_proposals: Imprimir propuestas
|
print_proposals: Imprimir propuestas
|
||||||
support_proposals: Apoyar propuestas
|
support_proposals: Apoyar propuestas
|
||||||
|
create_spending_proposal: Crear propuesta de gasto
|
||||||
title: Gestión
|
title: Gestión
|
||||||
users: Usuarios
|
users: Usuarios
|
||||||
permissions:
|
permissions:
|
||||||
@@ -58,6 +59,10 @@ es:
|
|||||||
create_proposal: Crear propuesta
|
create_proposal: Crear propuesta
|
||||||
print:
|
print:
|
||||||
print_button: Imprimir
|
print_button: Imprimir
|
||||||
|
spending_proposals:
|
||||||
|
alert:
|
||||||
|
unverified_user: Este usuario no está verificado
|
||||||
|
create: Crear propuesta de gasto
|
||||||
sessions:
|
sessions:
|
||||||
signed_out: Has cerrado la sesión correctamente.
|
signed_out: Has cerrado la sesión correctamente.
|
||||||
signed_out_managed_user: Se ha cerrado correctamente la sesión del usuario.
|
signed_out_managed_user: Se ha cerrado correctamente la sesión del usuario.
|
||||||
|
|||||||
@@ -225,6 +225,8 @@ Rails.application.routes.draw do
|
|||||||
get :print
|
get :print
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :spending_proposals, only: [:new, :create, :show]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
|
|||||||
54
spec/features/management/spending_proposals_spec.rb
Normal file
54
spec/features/management/spending_proposals_spec.rb
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Spending Proposals' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
login_as_manager
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Create" do
|
||||||
|
|
||||||
|
scenario 'Creating spending proposals on behalf of someone' do
|
||||||
|
user = create(:user, :level_two)
|
||||||
|
login_managed_user(user)
|
||||||
|
|
||||||
|
click_link "Create spending proposal"
|
||||||
|
|
||||||
|
within(".account-info") do
|
||||||
|
expect(page).to have_content "Identified as"
|
||||||
|
expect(page).to have_content "#{user.username}"
|
||||||
|
expect(page).to have_content "#{user.email}"
|
||||||
|
expect(page).to have_content "#{user.document_number}"
|
||||||
|
end
|
||||||
|
|
||||||
|
fill_in 'spending_proposal_title', with: 'Build a park in my neighborhood'
|
||||||
|
fill_in 'spending_proposal_description', with: 'There is no parks here...'
|
||||||
|
fill_in 'spending_proposal_external_url', with: 'http://moarparks.com'
|
||||||
|
fill_in 'spending_proposal_captcha', with: correct_captcha_text
|
||||||
|
check 'spending_proposal_terms_of_service'
|
||||||
|
|
||||||
|
click_button 'Create'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Spending proposal created successfully.'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Build a park in my neighborhood'
|
||||||
|
expect(page).to have_content 'There is no parks here...'
|
||||||
|
expect(page).to have_content 'All city'
|
||||||
|
expect(page).to have_content 'http://moarparks.com'
|
||||||
|
expect(page).to have_content user.name
|
||||||
|
expect(page).to have_content I18n.l(SpendingProposal.last.created_at.to_date)
|
||||||
|
|
||||||
|
expect(current_path).to eq(management_spending_proposal_path(SpendingProposal.last))
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not allow unverified users to create spending proposals" do
|
||||||
|
user = create(:user)
|
||||||
|
login_managed_user(user)
|
||||||
|
|
||||||
|
click_link "Create spending proposal"
|
||||||
|
|
||||||
|
expect(page).to have_content "User is not verified"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user