Merge pull request #641 from AyuntamientoMadrid/management-polishing

Management polishing
This commit is contained in:
Raimond Garcia
2015-10-24 15:02:58 +02:00
17 changed files with 232 additions and 40 deletions

View File

@@ -2,6 +2,7 @@ class Management::BaseController < ActionController::Base
layout 'management'
before_action :verify_manager
before_action :set_locale
helper_method :managed_user
@@ -12,11 +13,21 @@ class Management::BaseController < ActionController::Base
end
def current_manager
session["manager"]
session[:manager]
end
def managed_user
@managed_user ||= Verification::Management::ManagedUser.find(session[:document_type], session[:document_number])
end
def set_locale
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
session[:locale] = params[:locale]
end
session[:locale] ||= I18n.default_locale
I18n.locale = session[:locale]
end
end

View File

@@ -5,7 +5,7 @@ class Management::SessionsController < ActionController::Base
def create
destroy_session
if manager = ManagerAuthenticator.new(params).auth
session["manager"] = manager
session[:manager] = manager
redirect_to management_root_path
else
raise ActionController::RoutingError.new('Not Found')
@@ -20,7 +20,9 @@ class Management::SessionsController < ActionController::Base
private
def destroy_session
session["manager"] = nil
session[:manager] = nil
session[:document_type] = nil
session[:document_number] = nil
end
end

View File

@@ -30,7 +30,7 @@ class Management::UsersController < Management::BaseController
end
def destroy_session
session[:document_type] = nil
session[:document_type] = nil
session[:document_number] = nil
end

View File

@@ -22,10 +22,7 @@ class Verification::EmailController < ApplicationController
@email.encrypted_token,
@verified_user.document_type,
@verified_user.document_number).deliver_later
###CHANGE ME
#we should not have access to the account_page of a managed_user
redirect_to account_path, notice: t('verification.email.create.flash.success', email: @verified_user.email)
###
else
redirect_to verified_user_path, alert: t('verification.email.create.alert.failure')
end

View File

@@ -18,4 +18,14 @@ module ProposalsHelper
end
end
def namespaced_proposal_path(proposal, options={})
@namespace_proposal_path ||= namespace
case @namespace_proposal_path
when "management"
management_proposal_path(proposal, options)
else
proposal_path(proposal, options)
end
end
end

View File

@@ -1,5 +1,5 @@
<div class="alert-box success radius">
<%= t("management.email_verifications.document_found_in_census") %>
<%= t("management.email_verifications.document_found_in_census") %> <%= t("management.email_verifications.choose_options") %>
</div>
<ul>

View File

@@ -6,10 +6,10 @@
<div class="proposal-content">
<span class="label-proposal left"><%= t("proposals.proposal.proposal") %></span>
<i class="icon-proposals"></i>
<h3><%= link_to proposal.title, proposal %></h3>
<h3><%= link_to proposal.title, namespaced_proposal_path(proposal) %></h3>
<p class="proposal-info">
<i class="icon-comments"></i>&nbsp;
<%= link_to t("proposals.proposal.comments", count: proposal.comments_count), proposal_path(proposal, anchor: "comments") %>
<%= link_to t("proposals.proposal.comments", count: proposal.comments_count), namespaced_proposal_path(proposal, anchor: "comments") %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l proposal.created_at.to_date %>
@@ -39,7 +39,7 @@
<% end %>
</p>
<div class="proposal-description">
<p><%= link_to proposal.summary, proposal %></p>
<p><%= link_to proposal.summary, namespaced_proposal_path(proposal) %></p>
<div class="truncate"></div>
</div>
<%= render "shared/tags", taggable: proposal, limit: 5 %>

View File

@@ -47,7 +47,8 @@ en:
has_no_account_html: "In order to create an account, go to %{link} and click in <b>'Register'</b> in the upper-left part of the screen."
verify: "Verify"
email_verifications:
document_found_in_census: "This document was found in the census, but it has no user account associated to it. Please choose one of the following options:"
document_found_in_census: "This document was found in the census, but it has no user account associated to it."
choose_options: "Please choose one of the following options:"
if_existing_account: "If the person has already a user account created in the website,"
introduce_email: "Please introduce the email used on the account:"
email_placeholder: "Write the email this person used to create his or her account"

View File

@@ -47,7 +47,8 @@ es:
has_no_account_html: "Para crear un usuario entre en %{link} y haga clic en la opción <b>'Registrarse'</b> en la parte superior derecha de la pantalla."
verify: "Verificar usuario"
email_verifications:
document_found_in_census: "Este documento está en el registro del padrón municipal, pero todavía no tiene una cuenta de usuario asociada. Elige una de las opciones siguientes:"
document_found_in_census: "Este documento está en el registro del padrón municipal, pero todavía no tiene una cuenta de usuario asociada."
choose_options: "Elige una de las opciones siguientes:"
if_existing_account: "Si la persona ya ha creado una cuenta de usuario en la web"
introduce_email: "Introduce el email con el que creó la cuenta:"
email_placeholder: "Introduce el email de registro"

View File

@@ -0,0 +1,27 @@
require 'rails_helper'
describe Management::BaseController do
describe 'managed_user' do
it "should return existent user with session document info if present" do
session[:document_type] = "1"
session[:document_number] = "333333333E"
user = create(:user, :level_two, document_number: "333333333E")
managed_user = subject.send(:managed_user)
expect(managed_user).to eq user
end
it "should return new user if no user have the session document info" do
session[:document_type] = "1"
session[:document_number] = "333333333E"
managed_user = subject.send(:managed_user)
expect(managed_user).to be_new_record
expect(managed_user.document_type).to eq "1"
expect(managed_user.document_number).to eq "333333333E"
end
end
end

View File

@@ -18,12 +18,16 @@ describe Management::SessionsController do
end
describe 'Sign out' do
it "should destroy the session and redirect" do
it "should destroy the session data and redirect" do
session[:manager] = {user_key: "31415926" , date: "20151031135905", login: "JJB033"}
session[:document_type] = "1"
session[:document_number] = "12345678Z"
delete :destroy
expect(session[:manager]).to be_nil
expect(session[:document_type]).to be_nil
expect(session[:document_number]).to be_nil
expect(response).to be_redirect
end
end

View File

@@ -0,0 +1,20 @@
require 'rails_helper'
describe Management::UsersController do
describe 'logout' do
it "should remove user data from the session" do
session[:manager] = {user_key: "31415926" , date: "20151031135905", login: "JJB033"}
session[:document_type] = "1"
session[:document_number] = "12345678Z"
get :logout
expect(session[:manager]).to eq({user_key: "31415926" , date: "20151031135905", login: "JJB033"})
expect(session[:document_type]).to be_nil
expect(session[:document_number]).to be_nil
expect(response).to be_redirect
end
end
end

View File

@@ -0,0 +1,48 @@
require 'rails_helper'
feature 'Localization' do
background do
login_as_manager
end
scenario 'Wrong locale' do
visit management_root_path(locale: :es)
visit management_root_path(locale: :klingon)
expect(page).to have_text('Gestión')
end
scenario 'Available locales appear in the locale switcher' do
visit management_root_path
within('.locale-form .js-location-changer') do
expect(page).to have_content 'Español'
expect(page).to have_content 'English'
end
end
scenario 'The current locale is selected' do
visit management_root_path
expect(page).to have_select('locale-switcher', selected: 'English')
expect(page).to have_text('Management')
end
scenario 'Changing the locale', :js do
visit management_root_path
expect(page).to have_content('Language')
select('Español', from: 'locale-switcher')
expect(page).to have_content('Idioma')
expect(page).to_not have_content('Language')
expect(page).to have_select('locale-switcher', selected: 'Español')
end
scenario 'Locale switcher not present if only one locale' do
expect(I18n).to receive(:available_locales).and_return([:en])
visit management_root_path
expect(page).to_not have_content('Language')
expect(page).to_not have_css('div.locale')
end
end

View File

@@ -8,6 +8,11 @@ feature 'Managed User' do
context "Currently managed user" do
scenario "No managed user" do
visit management_document_verifications_path
expect(page).not_to have_css ".account-info"
end
scenario "User is already level three verified" do
user = create(:user, :level_three)
@@ -55,6 +60,15 @@ feature 'Managed User' do
fill_in 'document_verification_document_number', with: '1234'
click_button 'Check'
within(".account-info") do
expect(page).not_to have_content "Identified as"
expect(page).not_to have_content "Username"
expect(page).not_to have_content "Email"
expect(page).to have_content "Document type"
expect(page).to have_content "Document number"
expect(page).to have_content "1234"
end
expect(page).to have_content "Please introduce the email used on the account"
fill_in 'email_verification_email', with: user.email
@@ -115,6 +129,8 @@ feature 'Managed User' do
end
expect(page).to have_content "User session signed out successfully."
expect(page).to_not have_content "Identified as"
expect(page).to_not have_content "#{user.username}"
expect(current_path).to eq(management_root_path)
end

View File

@@ -14,6 +14,13 @@ feature 'Proposals' do
click_link "Create 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 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
@@ -36,7 +43,7 @@ feature 'Proposals' do
expect(page).to have_content user.name
expect(page).to have_content I18n.l(Proposal.last.created_at.to_date)
expect(URI.parse(current_url).path).to eq(management_proposal_path(Proposal.last))
expect(current_path).to eq(management_proposal_path(Proposal.last))
end
scenario "Should not allow unverified users to create proposals" do
@@ -49,9 +56,59 @@ feature 'Proposals' do
end
end
scenario "Searching" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
fill_in "search", with: "what you got"
click_button "Search"
expect(current_path).to eq(management_proposals_path)
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(proposal1.title)
expect(page).to_not have_content(proposal2.title)
expect(page).to have_css("a[href='#{management_proposal_path(proposal1)}']", text: proposal1.title)
expect(page).to have_css("a[href='#{management_proposal_path(proposal1)}']", text: proposal1.summary)
end
end
scenario "Listing" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
expect(current_path).to eq(management_proposals_path)
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
within("#proposals") do
expect(page).to have_css('.proposal', count: 2)
expect(page).to have_css("a[href='#{management_proposal_path(proposal1)}']", text: proposal1.title)
expect(page).to have_css("a[href='#{management_proposal_path(proposal1)}']", text: proposal1.summary)
expect(page).to have_css("a[href='#{management_proposal_path(proposal2)}']", text: proposal2.title)
expect(page).to have_css("a[href='#{management_proposal_path(proposal2)}']", text: proposal2.summary)
end
end
context "Voting" do
scenario 'Voting proposals on behalf of someone', :js do
scenario 'Voting proposals on behalf of someone in index view', :js do
proposal = create(:proposal)
user = create(:user, :level_two)
@@ -65,7 +122,25 @@ feature 'Proposals' do
expect(page).to have_content "1 support"
expect(page).to have_content "You already supported this proposal"
end
expect(URI.parse(current_url).path).to eq(management_proposals_path)
expect(current_path).to eq(management_proposals_path)
end
scenario 'Voting proposals on behalf of someone in show view', :js do
proposal = create(:proposal)
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
within("#proposals") do
click_link proposal.title
end
find('.in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_content "You already supported this proposal"
expect(current_path).to eq(management_proposal_path(proposal))
end
scenario "Should not allow unverified users to vote proposals" do
@@ -78,27 +153,6 @@ feature 'Proposals' do
expect(page).to have_content "User is not verified"
end
scenario "Searching" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
fill_in "search", with: "what you got"
click_button "Search"
expect(current_path).to eq(management_proposals_path)
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(proposal1.title)
expect(page).to_not have_content(proposal2.title)
end
end
end
context "Printing" do

View File

@@ -20,6 +20,7 @@ feature 'Proposals' do
proposals.each do |proposal|
within('#proposals') do
expect(page).to have_content proposal.title
expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.title)
expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.summary)
end
end

View File

@@ -260,7 +260,7 @@ feature 'Votes' do
expect(page).to have_content "1 support"
expect(page).to have_content "You already supported this proposal, share it!"
end
expect(URI.parse(current_url).path).to eq(proposals_path)
expect(current_path).to eq(proposals_path)
end
scenario 'Create in featured proposal in index', :js do
@@ -271,7 +271,7 @@ feature 'Votes' do
expect(page).to have_content "You already supported this proposal, share it!"
end
expect(URI.parse(current_url).path).to eq(proposals_path)
expect(current_path).to eq(proposals_path)
end
end
end