checks for verified users when creating and voting proposals

This commit is contained in:
rgarcia
2015-10-08 15:37:59 +02:00
parent e49bea806b
commit c21a78e164
2 changed files with 84 additions and 41 deletions

View File

@@ -4,6 +4,8 @@ class Management::ProposalsController < Management::BaseController
include HasOrders include HasOrders
include CommentableActions include CommentableActions
before_action :check_verified_user, except: :print
before_action :set_proposal, only: :vote before_action :set_proposal, only: :vote
before_action :parse_search_terms, only: :index before_action :parse_search_terms, only: :index
@@ -39,6 +41,12 @@ class Management::ProposalsController < Management::BaseController
Proposal Proposal
end end
def check_verified_user
unless current_user.level_two_or_three_verified?
redirect_to management_root_path, alert: 'User is not verified'
end
end
#Duplicated in application_controller. Move to a concenrn. #Duplicated in application_controller. Move to a concenrn.
def set_proposal_votes(proposals) def set_proposal_votes(proposals)
@proposal_votes = current_user ? current_user.proposal_votes(proposals) : {} @proposal_votes = current_user ? current_user.proposal_votes(proposals) : {}

View File

@@ -2,10 +2,12 @@ require 'rails_helper'
feature 'Proposals' do feature 'Proposals' do
context "Create" do
scenario 'Creating proposals on behalve of someone' do scenario 'Creating proposals on behalve of someone' do
####CHANGE ME ####CHANGE ME
####Should identify the user being managed ####Should identify the user being managed
managed_user = create(:user) managed_user = create(:user, :level_two)
#### ####
manager = create(:manager) manager = create(:manager)
@@ -19,7 +21,6 @@ feature 'Proposals' do
fill_in 'proposal_description', with: 'This is very important because...' fill_in 'proposal_description', with: 'This is very important because...'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com' fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service' check 'proposal_terms_of_service'
@@ -37,6 +38,23 @@ feature 'Proposals' do
expect(page).to have_content I18n.l(Proposal.last.created_at.to_date) expect(page).to have_content I18n.l(Proposal.last.created_at.to_date)
end end
scenario "Should not allow unverified users to create proposals" do
####CHANGE ME
####Should identify the user being managed
unverified_user = create(:user)
####
manager = create(:manager)
visit management_sign_in_path(login: manager.username, clave_usuario: manager.password)
visit new_management_proposal_path
expect(page).to have_content "User is not verified"
end
end
context "Voting" do
scenario 'Voting proposals on behalve of someone', :js do scenario 'Voting proposals on behalve of someone', :js do
proposal = create(:proposal) proposal = create(:proposal)
@@ -59,6 +77,23 @@ feature 'Proposals' do
expect(URI.parse(current_url).path).to eq(management_proposals_path) expect(URI.parse(current_url).path).to eq(management_proposals_path)
end end
scenario "Should not allow unverified users to vote proposals", :focus do
proposal = create(:proposal)
####CHANGE ME
####Should identify the user being managed
unverified_user = create(:user)
####
manager = create(:manager)
visit management_sign_in_path(login: manager.username, clave_usuario: manager.password)
visit management_proposals_path
expect(page).to have_content "User is not verified"
end
end
scenario 'Printing proposals', :js do scenario 'Printing proposals', :js do
5.times { create(:proposal) } 5.times { create(:proposal) }