Skip to content

Commit

Permalink
Issue 51 (#53)
Browse files Browse the repository at this point in the history
* #48 display tags

* #51 fix some tests

* #51 fix some tests

* #51 fix some tests related to census_api

* #51 fix some tests related to age

* #51 fix some tests related to age
  • Loading branch information
clairezed committed May 16, 2018
1 parent a676059 commit c743d3e
Show file tree
Hide file tree
Showing 26 changed files with 474 additions and 258 deletions.
13 changes: 13 additions & 0 deletions app/models/custom/tag_cloud.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_dependency Rails.root.join('app', 'models', 'tag_cloud').to_s

class TagCloud

def tags
resource_model_scoped.
tag_counts.
where("lower(name) NOT IN (?)", category_names + geozone_names + default_blacklist).
order("#{table_name}_count": :desc, name: :asc).
limit(10)
end

end
6 changes: 3 additions & 3 deletions app/models/custom/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class User < ActiveRecord::Base
:postal_code,
presence: true, if: :username_required?

validate :postal_code_in_aude
validate :postal_code_in_aude, if: :username_required?
private def postal_code_in_aude
errors.add(:postal_code, :not_allowed) unless valid_postal_code?
end

validate :age_in_allowed_range
validate :age_in_allowed_range, if: :username_required?
private def age_in_allowed_range
errors.add(:date_of_birth, :not_allowed) unless valid_age?
end
Expand Down Expand Up @@ -51,7 +51,7 @@ def erase(erase_reason = nil)


def self.maximum_required_age
(Setting['max_age_to_participate'] || 16).to_i
(Setting['max_age_to_participate'] || 25).to_i
end

private
Expand Down
79 changes: 79 additions & 0 deletions app/views/custom/users/registrations/_new_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<div class="row">
<div class="small-12 column">

<%= f.hidden_field :use_redeemable_code %>
<%= f.hidden_field :locale, value: I18n.locale %>
<%= f.text_field :lastname, autofocus: true,
placeholder: t("devise_views.users.registrations.new.lastname_label")
%>
<%= f.text_field :firstname, placeholder: t("devise_views.users.registrations.new.firstname_label")
%>
<%= f.label :username %>
<p class="help-text" id="username-help-text"><%= t("devise_views.users.registrations.new.username_note") %></p>
<%= f.text_field :username, maxlength: User.username_max_length,
placeholder: t("devise_views.users.registrations.new.username_label"),
label: false,
aria: {describedby: "username-help-text"} %>
<%= f.invisible_captcha :family_name %>


<div class="date-of-birth">
<%= f.label t("devise_views.users.registrations.new.date_of_birth") %>
<p class="help-text" id="date-of-birth-help-text"><%= t("devise_views.users.registrations.new.date_of_birth_note") %></p>
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 26.years.ago.year, end_year: 16.years.ago.year,
label: false,
aria: {describedby: "date-of-birth-help-text"} %>
</div>

<div class="gender">
<%= f.select :gender, user_genders_select_options, label: t("devise_views.users.registrations.new.gender_label"), prompt: t("devise_views.users.registrations.new.gender_placeholder") %>
</div>

<!-- Address -->

<%= f.text_field :address, label: t("devise_views.users.registrations.new.address_label") %>

<div class="medium-6">
<%= f.text_field :postal_code %>
</div>

<%= f.text_field :city, label: t("devise_views.users.registrations.new.city_label") %>

<!-- Connexion info -->

<%= f.text_field :phone_number, placeholder: t("devise_views.organizations.registrations.new.phone_number_label"), label: t("devise_views.users.registrations.new.phone_label") %>
<%= f.email_field :email, placeholder: t("devise_views.users.registrations.new.email_label") %>
<% if resource.use_redeemable_code %>
<%= f.text_field :redeemable_code, placeholder: t("devise_views.users.registrations.new.redeemable_code") %>
<% end %>
<%= f.label :ca_wanabee do %>
<%= f.check_box :ca_wanabee, title: t('devise_views.users.registrations.new.ca_wanabee'), label: false %>
<span class="checkbox">
<%= t("devise_views.users.registrations.new.ca_wanabee", title: "devise_views.users.registrations.new.ca_wanabee").html_safe %>
</span>
<% end %>
<%= f.label :terms_of_service do %>
<%= f.check_box :terms_of_service, title: t('devise_views.users.registrations.new.terms_title'), label: false %>
<span class="checkbox">
<%= t("devise_views.users.registrations.new.terms",
terms: link_to(t("devise_views.users.registrations.new.terms_link"), "/conditions",
title: t('shared.target_blank_html'),
target: "_blank")).html_safe %>
</span>
<% end %>
<div class="small-12 medium-6 small-centered">
<%= f.submit t("devise_views.users.registrations.new.submit"), class: "button expanded", id: "register-btn" %>
</div>
</div>
</div>
16 changes: 16 additions & 0 deletions app/views/custom/users/registrations/finish_signup.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2><%= t('omniauth.finish_signup.title') %></h2>

<%= form_for current_user, as: :user, url: do_finish_signup_path, html: { role: 'form'} do |f| %>
<%= render 'shared/errors', resource: current_user %>

<div class='callout primary'>
<%= t("omniauth.finish_signup.username_warning") %>
</div>

<%= render 'custom/users/registrations/new_form', f: f %>


<div class="text-center">
<%= link_to t("devise_views.users.registrations.new.cancel"), destroy_user_session_path, class: 'delete', method: :delete %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion db/custom_seeds/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def unique_document_number
confirmed_at: Time.current,
terms_of_service: "1",
gender: ['Male', 'Female'].sample,
date_of_birth: rand((Time.current - 26.years)..(Time.current - 16.years)),
date_of_birth: rand((Time.current - 25.years)..(Time.current - 16.years)),
public_activity: (rand(1..100) > 30),
residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number,
Expand Down
28 changes: 27 additions & 1 deletion lib/census_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ def stubbed_response(document_type, document_number)
end
end

# Custom method (with CJAude valid date_of_birth)
def stubbed_valid_response
{
get_habita_datos_response: {
get_habita_datos_return: {
datos_habitante: {
item: {
fecha_nacimiento_string: "31-12-1980",
fecha_nacimiento_string: "31-12-#{20.years.ago.year}",
identificador_documento: "12345678Z",
descripcion_sexo: "Varón",
nombre: "José",
Expand All @@ -115,6 +116,31 @@ def stubbed_valid_response
}
end

# Consul method (invalid date for CJAude)
# def stubbed_valid_response
# {
# get_habita_datos_response: {
# get_habita_datos_return: {
# datos_habitante: {
# item: {
# fecha_nacimiento_string: "31-12-1980",
# identificador_documento: "12345678Z",
# descripcion_sexo: "Varón",
# nombre: "José",
# apellido1: "García"
# }
# },
# datos_vivienda: {
# item: {
# codigo_postal: "28013",
# codigo_distrito: "01"
# }
# }
# }
# }
# }
# end

def stubbed_invalid_response
{get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {}, datos_vivienda: {}}}}
end
Expand Down
8 changes: 4 additions & 4 deletions spec/custom/features/management/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

fill_in 'user_username', with: 'pepe'
fill_in 'user_email', with: '[email protected]'
select_date '31-December-1980', from: 'user_date_of_birth'
select_date "31-December-#{valid_date_of_birth_year}", from: 'user_date_of_birth'
fill_in 'user_lastname', with: 'mirza'
fill_in 'user_firstname', with: 'zuliani'
fill_in 'user_postal_code', with: '11000'
Expand All @@ -32,7 +32,7 @@
expect(user).to be_level_three_verified
expect(user).to be_residence_verified
expect(user).not_to be_confirmed
expect(user.date_of_birth).to have_content Date.new(1980, 12, 31)
expect(user.date_of_birth).to have_content Date.new(valid_date_of_birth_year, 12, 31)

sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1]
visit user_confirmation_path(confirmation_token: sent_token)
Expand Down Expand Up @@ -60,7 +60,7 @@

fill_in 'user_username', with: 'Kelly Sue'
fill_in 'user_email', with: ''
select_date '31-December-1980', from: 'user_date_of_birth'
select_date "31-December-#{valid_date_of_birth_year}", from: 'user_date_of_birth'
fill_in 'user_lastname', with: 'mirza'
fill_in 'user_firstname', with: 'zuliani'
fill_in 'user_postal_code', with: '11000'
Expand All @@ -75,7 +75,7 @@
expect(user).to be_level_three_verified
expect(user).to be_residence_verified
expect(user).to be_confirmed
expect(user.date_of_birth).to have_content Date.new(1980, 12, 31)
expect(user.date_of_birth).to have_content Date.new(valid_date_of_birth_year, 12, 31)
end

end
32 changes: 32 additions & 0 deletions spec/custom/features/officing/residence_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rails_helper'

feature 'Residence' do
let(:officer) { create(:poll_officer) }



feature "Assigned officers" do

background do
create(:poll_officer_assignment, officer: officer)
login_as(officer.user)
visit officing_root_path
end

scenario "Verify voter" do
within("#side_menu") do
click_link "Validate document"
end

select 'DNI', from: 'residence_document_type'
fill_in 'residence_document_number', with: "12345678Z"
fill_in 'residence_year_of_birth', with: "#{valid_date_of_birth_year}"

click_button 'Validate document'

expect(page).to have_content 'Document verified with Census'
end

end

end
67 changes: 67 additions & 0 deletions spec/custom/features/officing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'rails_helper'
require 'sessions_helper'

feature 'Poll Officing' do
let(:user) { create(:user) }

scenario 'Officing dashboard available for multiple sessions', :js do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)

user1 = create(:user)
user2 = create(:user)
officer1 = create(:poll_officer, user: user1)
officer2 = create(:poll_officer, user: user2)

create(:poll_shift, officer: officer1, booth: booth, date: Date.current, task: :vote_collection)
create(:poll_shift, officer: officer2, booth: booth, date: Date.current, task: :vote_collection)

officer_assignment_1 = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer1)
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer2)

in_browser(:one) do
login_as user1
visit officing_root_path
end

in_browser(:two) do
login_as user2
visit officing_root_path
end

in_browser(:one) do
expect(page).to have_content("Here you can validate user documents and store voting results")

visit new_officing_residence_path
select 'DNI', from: 'residence_document_type'
fill_in 'residence_document_number', with: "12345678Z"
fill_in 'residence_year_of_birth', with: "#{valid_date_of_birth_year}"
click_button 'Validate document'
expect(page).to have_content 'Document verified with Census'
click_button "Confirm vote"
expect(page).to have_content "Vote introduced!"
expect(Poll::Voter.where(document_number: '12345678Z', poll_id: poll, origin: 'booth', officer_id: officer1).count).to be(1)

visit final_officing_polls_path
expect(page).to have_content("Polls ready for final recounting")
end

in_browser(:two) do
expect(page).to have_content("Here you can validate user documents and store voting results")

visit new_officing_residence_path
select 'DNI', from: 'residence_document_type'
fill_in 'residence_document_number', with: "12345678Y"
fill_in 'residence_year_of_birth', with: "#{valid_date_of_birth_year}"
click_button 'Validate document'
expect(page).to have_content 'Document verified with Census'
click_button "Confirm vote"
expect(page).to have_content "Vote introduced!"
expect(Poll::Voter.where(document_number: '12345678Y', poll_id: poll, origin: 'booth', officer_id: officer2).count).to be(1)

visit final_officing_polls_path
expect(page).to have_content("Polls ready for final recounting")
end
end
end
50 changes: 50 additions & 0 deletions spec/custom/features/verification/residence_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'rails_helper'

feature 'Residence' do

background { create(:geozone) }

scenario 'Verify resident' do
user = create(:user)
login_as(user)

visit account_path
click_link 'Verify my account'

fill_in 'residence_document_number', with: "12345678Z"
select 'DNI', from: 'residence_document_type'
select_date "31-December-#{valid_date_of_birth_year}", from: 'residence_date_of_birth'
fill_in 'residence_postal_code', with: '28013'
check 'residence_terms_of_service'

click_button 'Verify residence'

expect(page).to have_content 'Residence verified'
end

xscenario 'When trying to verify a deregistered account old votes are reassigned' do
erased_user = create(:user, document_number: '12345678Z', document_type: '1', erased_at: Time.current)
vote = create(:vote, voter: erased_user)
new_user = create(:user)

login_as(new_user)

visit account_path
click_link 'Verify my account'

fill_in 'residence_document_number', with: '12345678Z'
select 'DNI', from: 'residence_document_type'
select_date '31-December-1980', from: 'residence_date_of_birth'
fill_in 'residence_postal_code', with: '28013'
check 'residence_terms_of_service'

click_button 'Verify residence'

expect(page).to have_content 'Residence verified'

expect(vote.reload.voter).to eq(new_user)
expect(erased_user.reload.document_number).to be_blank
expect(new_user.reload.document_number).to eq('12345678Z')
end

end
Loading

0 comments on commit c743d3e

Please sign in to comment.