Merge branch 'master' into site-customization

This commit is contained in:
Amaia Castro
2017-04-07 17:29:33 +02:00
279 changed files with 9351 additions and 464 deletions

View File

@@ -112,8 +112,13 @@ feature 'Account' do
end
scenario 'Errors editing credentials' do
visit account_path
visit root_path
click_link 'My account'
expect(current_path).to eq(account_path)
expect(page).to have_link('Change my credentials')
click_link 'Change my credentials'
click_button 'Update'

View File

@@ -114,6 +114,7 @@ feature 'Admin banners magement' do
visit admin_root_path
within('#side_menu') do
click_link "Banners"
click_link "Manage banners"
end

View File

@@ -31,6 +31,7 @@ feature 'Admin feature flags' do
visit admin_root_path
within('#side_menu') do
expect(page).not_to have_link "Budgets"
expect(page).not_to have_link "Spending proposals"
end
@@ -45,6 +46,7 @@ feature 'Admin feature flags' do
visit admin_root_path
within('#side_menu') do
expect(page).not_to have_link "Budgets"
expect(page).not_to have_link "Spending proposals"
end

View File

@@ -0,0 +1,181 @@
require 'rails_helper'
feature 'Admin booths assignments' do
background do
admin = create(:administrator)
login_as(admin.user)
end
scenario 'Assign booth to poll', :js do
poll = create(:poll)
booth = create(:poll_booth)
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (0)'
end
expect(page).to have_content 'There are no booths assigned to this poll.'
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name)
within('#search-booths-results') do
click_link 'Assign booth'
end
expect(page).to have_content 'Booth assigned'
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).to_not have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
end
scenario 'Remove booth from poll', :js do
poll = create(:poll)
booth = create(:poll_booth)
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).to_not have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
within("#poll_booth_assignment_#{assignment.id}") do
click_link 'Remove booth from poll'
end
expect(page).to have_content 'Booth not assigned anymore'
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (0)'
end
expect(page).to have_content 'There are no booths assigned to this poll.'
expect(page).to_not have_content booth.name
end
feature 'Show' do
scenario 'Lists all assigned poll oficers' do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment)
officer = officer_assignment.officer
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment_2)
officer_2 = officer_assignment_2.officer
visit admin_poll_path(poll)
click_link 'Booths (2)'
within('#assigned_booths_list') { click_link booth.name }
click_link 'Officers'
within('#officers_list') do
expect(page).to have_content officer.name
expect(page).to_not have_content officer_2.name
end
end
scenario 'Lists all recounts for the booth assignment' do
poll = create(:poll, starts_at: 2.weeks.ago, ends_at: 1.week.ago)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer_assignment_1 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.starts_at)
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.ends_at)
final_officer_assignment = create(:poll_officer_assignment, :final, booth_assignment: booth_assignment, date: poll.ends_at)
recount_1 = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment_1,
date: officer_assignment_1.date,
count: 33)
recount_2 = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment_2,
date: officer_assignment_2.date,
count: 78)
final_recount = create(:poll_final_recount,
booth_assignment: booth_assignment,
officer_assignment: final_officer_assignment,
date: final_officer_assignment.date,
count: 5678)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
other_recount = create(:poll_recount, booth_assignment: booth_assignment_2, count: 100)
visit admin_poll_path(poll)
click_link 'Booths (2)'
within('#assigned_booths_list') { click_link booth.name }
click_link 'Recounts'
within('#recounts_list') do
expect(page).to_not have_content other_recount.count
within("#recounting_#{recount_1.date.strftime('%Y%m%d')}") do
expect(page).to have_content recount_1.count
end
within("#recounting_#{recount_2.date.strftime('%Y%m%d')}") do
expect(page).to have_content recount_2.count
end
within("#recounting_#{final_recount.date.strftime('%Y%m%d')}") do
expect(page).to have_content final_recount.count
end
end
end
scenario 'Marks recount values with count-errors' do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
today = Time.current.to_date
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: today)
recount = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment,
date: officer_assignment.date,
count: 1)
visit admin_poll_booth_assignment_path(poll, booth_assignment)
click_link 'Recounts'
within('#recounts_list') do
expect(page).to have_css("#recounting_#{recount.date.strftime('%Y%m%d')} td.count-error")
within("#recounting_#{recount.date.strftime('%Y%m%d')}") do
expect(page).to have_content recount.count
expect(page).to have_content 0
end
end
create(:poll_voter, :valid_document, poll: poll, booth_assignment: booth_assignment)
visit admin_poll_booth_assignment_path(poll, booth_assignment)
click_link 'Recounts'
within('#recounts_list') do
expect(page).to_not have_css('.count-error')
within("#recounting_#{recount.date.strftime('%Y%m%d')}") do
expect(page).to have_content(recount.count)
end
end
end
end
end

View File

@@ -0,0 +1,86 @@
require 'rails_helper'
feature 'Admin booths' do
background do
admin = create(:administrator)
login_as(admin.user)
end
scenario 'Index empty' do
visit admin_root_path
within('#side_menu') do
click_link "Booths location"
end
expect(page).to have_content "There are no booths"
end
scenario 'Index' do
3.times { create(:poll_booth) }
visit admin_root_path
within('#side_menu') do
click_link "Booths location"
end
booths = Poll::Booth.all
booths.each do |booth|
within("#booth_#{booth.id}") do
expect(page).to have_content booth.name
expect(page).to have_content booth.location
end
end
expect(page).to_not have_content "There are no booths"
end
scenario 'Show' do
booth = create(:poll_booth)
visit admin_booths_path
expect(page).to have_content booth.name
expect(page).to have_content booth.location
end
scenario "Create" do
visit admin_booths_path
click_link "Add booth"
fill_in "poll_booth_name", with: "Upcoming booth"
fill_in "poll_booth_location", with: "39th Street, number 2, ground floor"
click_button "Create booth"
expect(page).to have_content "Booth created successfully"
visit admin_booths_path
expect(page).to have_content "Upcoming booth"
expect(page).to have_content "39th Street, number 2, ground floor"
end
scenario "Edit" do
booth = create(:poll_booth)
visit admin_booths_path
within("#booth_#{booth.id}") do
click_link "Edit"
end
fill_in "poll_booth_name", with: "Next booth"
fill_in "poll_booth_location", with: "40th Street, number 1, firts floor"
click_button "Update booth"
expect(page).to have_content "Booth updated successfully"
visit admin_booths_path
within("#booth_#{booth.id}") do
expect(page).to have_content "Next booth"
expect(page).to have_content "40th Street, number 1, firts floor"
end
end
end

View File

@@ -0,0 +1,97 @@
require 'rails_helper'
feature 'Admin officer assignments in poll' do
background do
admin = create(:administrator)
login_as(admin.user)
end
scenario 'Assign officer to poll', :js do
booth_assignment = create(:poll_booth_assignment)
officer = create(:poll_officer)
visit admin_poll_path(booth_assignment.poll)
within('#poll-resources') do
click_link 'Officers (0)'
end
expect(page).to have_content 'There are no officers assigned to this poll'
fill_in 'search-officers', with: officer.name
click_button 'Search'
within('#search-officers-results') do
click_link 'Add shifts as officer'
end
expect(page).to have_content 'This user has no officing shifts in this poll'
expect(page).to have_content officer.name
expect(page).to have_content booth_assignment.poll.name
within('#officer_assignment_form') do
select I18n.l(booth_assignment.poll.ends_at.to_date, format: :long), from: 'date'
select "#{booth_assignment.booth.name} (#{booth_assignment.booth.location})", from: 'booth_id'
click_button 'Add shift'
end
expect(page).to have_content 'Officing shift added'
expect(page).to_not have_content 'This user has no officing shifts in this poll'
visit admin_poll_path(booth_assignment.poll)
within('#poll-resources') do
click_link 'Officers (1)'
end
expect(page).to_not have_content 'There are no officers in this poll'
expect(page).to have_content officer.name
expect(page).to have_content officer.email
end
scenario 'Remove officer assignment from poll' do
officer_assignment = create(:poll_officer_assignment)
poll = officer_assignment.booth_assignment.poll
booth = officer_assignment.booth_assignment.booth
officer = officer_assignment.officer
visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id)
expect(page).to_not have_content 'This user has no officing shifts in this poll'
within("#poll_officer_assignment_#{officer_assignment.id}") do
expect(page).to have_content booth.name
click_link 'Remove'
end
expect(page).to have_content 'Officing shift removed'
expect(page).to have_content 'This user has no officing shifts in this poll'
end
scenario 'Index view shows recounts info for officer' do
booth_assignment = create(:poll_booth_assignment)
poll = booth_assignment.poll
officer = create(:poll_officer)
officer_assignment = create(:poll_officer_assignment,
booth_assignment: booth_assignment,
officer: officer,
date: poll.starts_at)
final_officer_assignment = create(:poll_officer_assignment, :final,
booth_assignment: booth_assignment,
officer: officer,
date: poll.ends_at + 1.day)
recount = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment,
date: officer_assignment.date,
count: 77)
final_recount = create(:poll_final_recount,
booth_assignment: booth_assignment,
officer_assignment: final_officer_assignment,
date: poll.ends_at,
count: 9876)
visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id)
within('#recount_list') { expect(page).to have_content('77') }
within('#final_recount_list') { expect(page).to have_content('9876') }
end
end

View File

@@ -0,0 +1,36 @@
require 'rails_helper'
feature 'Admin poll officers' do
background do
@admin = create(:administrator)
@user = create(:user, username: 'Pedro Jose Garcia')
@officer = create(:poll_officer)
login_as(@admin.user)
visit admin_officers_path
end
scenario 'Index' do
expect(page).to have_content @officer.name
expect(page).to have_content @officer.email
expect(page).to_not have_content @user.name
end
scenario 'Create', :js do
fill_in 'email', with: @user.email
click_button 'Search'
expect(page).to have_content @user.name
click_link 'Add'
within("#officers") do
expect(page).to have_content @user.name
end
end
scenario 'Delete' do
click_link 'Delete position'
expect(page).to_not have_css '#officers'
end
end

View File

@@ -0,0 +1,366 @@
require 'rails_helper'
feature 'Admin polls' do
background do
admin = create(:administrator)
login_as(admin.user)
end
scenario 'Index empty', :js do
visit admin_root_path
click_link "Polls"
within('#polls_menu') do
click_link "Polls"
end
expect(page).to have_content "There are no polls"
end
scenario 'Index', :js do
3.times { create(:poll) }
visit admin_root_path
click_link "Polls"
within('#polls_menu') do
click_link "Polls"
end
expect(page).to have_css ".poll", count: 3
polls = Poll.all
polls.each do |poll|
within("#poll_#{poll.id}") do
expect(page).to have_content poll.name
end
end
expect(page).to_not have_content "There are no polls"
end
scenario 'Show' do
poll = create(:poll)
visit admin_polls_path
click_link poll.name
expect(page).to have_content poll.name
end
scenario "Create" do
visit admin_polls_path
click_link "Create poll"
start_date = 1.week.from_now
end_date = 2.weeks.from_now
fill_in "poll_name", with: "Upcoming poll"
fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y")
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
click_button "Create poll"
expect(page).to have_content "Poll created successfully"
expect(page).to have_content "Upcoming poll"
expect(page).to have_content I18n.l(start_date.to_date)
expect(page).to have_content I18n.l(end_date.to_date)
end
scenario "Edit" do
poll = create(:poll)
visit admin_poll_path(poll)
click_link "Edit"
end_date = 1.year.from_now
fill_in "poll_name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
click_button "Update poll"
expect(page).to have_content "Poll updated successfully"
expect(page).to have_content "Next Poll"
expect(page).to have_content I18n.l(end_date.to_date)
end
scenario 'Edit from index' do
poll = create(:poll)
visit admin_polls_path
within("#poll_#{poll.id}") do
click_link "Edit"
end
expect(current_path).to eq(edit_admin_poll_path(poll))
end
context "Booths" do
context "Poll show" do
scenario "No booths" do
poll = create(:poll)
visit admin_poll_path(poll)
click_link "Booths (0)"
expect(page).to have_content "There are no booths assigned to this poll."
end
scenario "Booth list" do
poll = create(:poll)
3.times { create(:poll_booth, polls: [poll]) }
visit admin_poll_path(poll)
click_link "Booths (3)"
expect(page).to have_css ".booth", count: 3
poll.booth_assignments.each do |ba|
within("#poll_booth_assignment_#{ba.id}") do
expect(page).to have_content ba.booth.name
expect(page).to have_content ba.booth.location
end
end
expect(page).to_not have_content "There are no booths assigned to this poll."
end
end
end
context "Officers" do
context "Poll show" do
scenario "No officers", :js do
poll = create(:poll)
visit admin_poll_path(poll)
click_link "Officers (0)"
expect(page).to have_content "There are no officers assigned to this poll"
end
scenario "Officer list", :js do
poll = create(:poll)
booth = create(:poll_booth, polls: [poll])
booth.booth_assignments.each do |booth_assignment|
3.times {create(:poll_officer_assignment, booth_assignment: booth_assignment) }
end
visit admin_poll_path(poll)
click_link "Officers (3)"
expect(page).to have_css ".officer", count: 3
officers = Poll::Officer.all
officers.each do |officer|
within("#officer_#{officer.id}") do
expect(page).to have_content officer.name
expect(page).to have_content officer.email
end
end
expect(page).to_not have_content "There are no officers assigned to this poll"
end
end
end
context "Questions" do
context "Poll show" do
scenario "Question list", :js do
poll = create(:poll)
question = create(:poll_question, poll: poll)
other_question = create(:poll_question)
visit admin_poll_path(poll)
expect(page).to have_content "Questions (1)"
expect(page).to have_content question.title
expect(page).to_not have_content other_question.title
expect(page).to_not have_content "There are no questions assigned to this poll"
end
scenario 'Add question to poll', :js do
poll = create(:poll)
question = create(:poll_question, poll: nil, title: 'Should we rebuild the city?')
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (0)'
expect(page).to have_content 'There are no questions assigned to this poll'
fill_in 'search-questions', with: 'rebuild'
click_button 'Search'
within('#search-questions-results') do
click_link 'Include question'
end
expect(page).to have_content 'Question added to this poll'
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (1)'
expect(page).to_not have_content 'There are no questions assigned to this poll'
expect(page).to have_content question.title
end
scenario 'Remove question from poll', :js do
poll = create(:poll)
question = create(:poll_question, poll: poll)
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (1)'
expect(page).to_not have_content 'There are no questions assigned to this poll'
expect(page).to have_content question.title
within("#poll_question_#{question.id}") do
click_link 'Remove question from poll'
end
expect(page).to have_content 'Question removed from this poll'
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (0)'
expect(page).to have_content 'There are no questions assigned to this poll'
expect(page).to_not have_content question.title
end
end
end
context "Recounting" do
context "Poll show" do
scenario "No recounts", :js do
poll = create(:poll)
visit admin_poll_path(poll)
click_link "Recounting"
expect(page).to have_content "There is nothing to be recounted"
end
scenario "Recounts list", :js do
poll = create(:poll)
booth_assignment = create(:poll_booth_assignment, poll: poll)
booth_assignment_recounted = create(:poll_booth_assignment, poll: poll)
booth_assignment_final_recounted = create(:poll_booth_assignment, poll: poll)
3.times { |i| create(:poll_recount,
booth_assignment: booth_assignment,
date: poll.starts_at + i.days,
count: 33) }
3.times { |i| create(:poll_final_recount,
booth_assignment: booth_assignment,
date: poll.starts_at + i.days,
count: 21) }
2.times { create(:poll_voter,
booth_assignment: booth_assignment_final_recounted) }
create(:poll_recount,
booth_assignment: booth_assignment_recounted,
date: poll.ends_at,
count: 777)
create(:poll_final_recount,
booth_assignment: booth_assignment_final_recounted,
date: poll.ends_at,
count: 55555)
visit admin_poll_path(poll)
click_link "Recounting"
expect(page).to have_css ".booth_recounts", count: 3
within("#poll_booth_assignment_#{booth_assignment.id}_recounts") do
expect(page).to have_content(booth_assignment.booth.name)
expect(page).to have_content('99')
expect(page).to have_content('63')
end
within("#poll_booth_assignment_#{booth_assignment_recounted.id}_recounts") do
expect(page).to have_content(booth_assignment_recounted.booth.name)
expect(page).to have_content('777')
expect(page).to have_content('-')
end
within("#poll_booth_assignment_#{booth_assignment_final_recounted.id}_recounts") do
expect(page).to have_content(booth_assignment_final_recounted.booth.name)
expect(page).to have_content('-')
expect(page).to have_content('55555')
expect(page).to have_content('2')
end
end
end
end
context "Results" do
context "Poll show" do
scenario "No results", :js do
poll = create(:poll)
visit admin_poll_path(poll)
click_link "Results"
expect(page).to have_content "There are no results"
end
scenario "Results by answer", :js do
poll = create(:poll)
booth_assignment_1 = create(:poll_booth_assignment, poll: poll)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
booth_assignment_3 = create(:poll_booth_assignment, poll: poll)
question_1 = create(:poll_question, poll: poll, valid_answers: "Yes,No")
question_2 = create(:poll_question, poll: poll, valid_answers: "Today,Tomorrow")
[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
booth_assignment: ba,
question: question_1,
answer: 'Yes',
amount: 11)
create(:poll_partial_result,
booth_assignment: ba,
question: question_2,
answer: 'Tomorrow',
amount: 5)
end
create(:poll_white_result,
booth_assignment: booth_assignment_1,
amount: 21)
create(:poll_null_result,
booth_assignment: booth_assignment_3,
amount: 44)
visit admin_poll_path(poll)
click_link "Results"
expect(page).to have_content(question_1.title)
question_1.valid_answers.each_with_index do |answer, i|
within("#question_#{question_1.id}_#{i}_result") do
expect(page).to have_content(answer)
expect(page).to have_content([33, 0][i])
end
end
expect(page).to have_content(question_2.title)
question_2.valid_answers.each_with_index do |answer, i|
within("#question_#{question_2.id}_#{i}_result") do
expect(page).to have_content(answer)
expect(page).to have_content([0,15][i])
end
end
within('#white_results') { expect(page).to have_content('21') }
within('#null_results') { expect(page).to have_content('44') }
end
end
end
end

View File

@@ -0,0 +1,116 @@
require 'rails_helper'
feature 'Admin poll questions' do
background do
login_as(create(:administrator).user)
end
scenario 'Index' do
question1 = create(:poll_question)
question2 = create(:poll_question)
visit admin_questions_path
expect(page).to have_content(question1.title)
expect(page).to have_content(question2.title)
end
scenario 'Show' do
geozone = create(:geozone)
poll = create(:poll, geozone_restricted: true, geozone_ids: [geozone.id])
question = create(:poll_question, poll: poll)
visit admin_question_path(question)
expect(page).to have_content(question.title)
expect(page).to have_content(question.description)
expect(page).to have_content(question.author.name)
expect(page).to have_content(question.valid_answers.join(" "))
end
scenario 'Create' do
poll = create(:poll, name: 'Movies')
title = "Star Wars: Episode IV - A New Hope"
description = %{
During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet.
Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy....
}
visit admin_questions_path
click_link "Create question"
select 'Movies', from: 'poll_question_poll_id'
fill_in 'poll_question_title', with: title
fill_in 'poll_question_description', with: description
click_button 'Save'
expect(page).to have_content(title)
expect(page).to have_content(description)
end
scenario 'Create from successful proposal index' do
poll = create(:poll, name: 'Proposals')
proposal = create(:proposal, :successful)
visit proposals_path
click_link "Create question"
expect(current_path).to eq(new_admin_question_path)
expect(page).to have_field('poll_question_title', with: proposal.title)
expect(page).to have_field('poll_question_description', with: proposal.description)
expect(page).to have_field('poll_question_valid_answers', with: "Yes, No")
select 'Proposals', from: 'poll_question_poll_id'
click_button 'Save'
expect(page).to have_content(proposal.title)
expect(page).to have_content(proposal.description)
expect(page).to have_link(proposal.title, href: proposal_path(proposal))
expect(page).to have_link(proposal.author.name, href: user_path(proposal.author))
end
pending "Create from successul proposal show"
scenario 'Update' do
question1 = create(:poll_question)
visit admin_questions_path
within("#poll_question_#{question1.id}") do
click_link "Edit"
end
old_title = question1.title
new_title = "Potatoes are great and everyone should have one"
fill_in 'poll_question_title', with: new_title
click_button 'Save'
expect(page).to have_content "Changes saved"
expect(page).to have_content new_title
visit admin_questions_path
expect(page).to have_content(new_title)
expect(page).to_not have_content(old_title)
end
scenario 'Destroy' do
question1 = create(:poll_question)
question2 = create(:poll_question)
visit admin_questions_path
within("#poll_question_#{question1.id}") do
click_link "Delete"
end
expect(page).to_not have_content(question1.title)
expect(page).to have_content(question2.title)
end
pending "Mark all city by default when creating a poll question from a successful proposal"
end

View File

@@ -93,11 +93,11 @@ feature 'Admin spending proposals' do
expect(page).to have_button("Update")
click_link("Back")
expect(page).to_not have_button("Update")
expect(page).to have_link("Back")
click_link("Back")
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
end
scenario "Filtering by admin", :js do
@@ -135,8 +135,10 @@ feature 'Admin spending proposals' do
click_link("Realocate visitors")
click_link("Edit classification")
expect(page).to have_button("Update")
expect(page).to have_link("Back")
click_link("Back")
expect(page).to_not have_button("Update")
expect(page).to have_link("Back")
click_link("Back")
expect(page).to have_content('There is 1 spending proposal')
@@ -182,8 +184,10 @@ feature 'Admin spending proposals' do
click_link("Realocate visitors")
click_link("Edit classification")
expect(page).to have_button("Update")
expect(page).to have_link("Back")
click_link("Back")
expect(page).to_not have_button("Update")
expect(page).to have_link("Back")
click_link("Back")
expect(page).to have_content('There is 1 spending proposal')

View File

@@ -16,7 +16,7 @@ feature 'Admin' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as a moderator is not authorized' do
scenario 'Access as moderator is not authorized' do
create(:moderator, user: user)
login_as(user)
visit admin_root_path
@@ -26,7 +26,7 @@ feature 'Admin' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as a valuator is not authorized' do
scenario 'Access as valuator is not authorized' do
create(:valuator, user: user)
login_as(user)
visit admin_root_path
@@ -36,7 +36,7 @@ feature 'Admin' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as a manager is not authorized' do
scenario 'Access as manager is not authorized' do
create(:manager, user: user)
login_as(user)
visit admin_root_path
@@ -46,7 +46,17 @@ feature 'Admin' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as an administrator is authorized' do
scenario 'Access as poll officer is not authorized' do
create(:poll_officer, user: user)
login_as(user)
visit admin_root_path
expect(current_path).not_to eq(admin_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as administrator is authorized' do
login_as(administrator)
visit admin_root_path

View File

@@ -0,0 +1 @@
#refactor specs and test as one more commmentable

View File

@@ -43,7 +43,7 @@ feature "Home" do
end
def ie_alert_box_xpath
"/html/body/div[@class='wrapper']/comment()[contains(.,'ie-callout')]"
"/html/body/div[@class='wrapper ']/comment()[contains(.,'ie-callout')]"
end
end
end

View File

@@ -84,6 +84,8 @@ feature 'Moderate comments' do
end
scenario "select all/none", :js do
Capybara.current_driver = :poltergeist_no_js_errors
create_list(:comment, 2)
visit moderation_comments_path

View File

@@ -91,6 +91,8 @@ feature 'Moderate debates' do
end
scenario "select all/none", :js do
Capybara.current_driver = :poltergeist_no_js_errors
create_list(:debate, 2)
visit moderation_debates_path

View File

@@ -83,6 +83,8 @@ feature 'Moderate proposals' do
end
scenario "select all/none", :js do
Capybara.current_driver = :poltergeist_no_js_errors
create_list(:proposal, 2)
visit moderation_proposals_path

View File

@@ -43,6 +43,20 @@ feature 'Moderation' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as poll officer is not authorized' do
create(:poll_officer, user: user)
login_as(user)
visit root_path
expect(page).to_not have_link("Moderation")
visit moderation_root_path
expect(current_path).not_to eq(moderation_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as a moderator is authorized' do
create(:moderator, user: user)

View File

@@ -0,0 +1,147 @@
require 'rails_helper'
feature 'Officing Final Recount' do
background do
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
@poll = @officer_assignment.booth_assignment.poll
@poll.update(ends_at: 1.day.ago)
login_as(@poll_officer.user)
end
scenario 'Only polls where user is officer for final recounts are accessible' do
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
not_allowed_poll_1 = create(:poll, :expired)
not_allowed_poll_2 = regular_officer_assignment_1.booth_assignment.poll
not_allowed_poll_2.update(ends_at: 1.day.ago)
not_allowed_poll_3 = regular_officer_assignment_2.booth_assignment.poll
visit root_path
click_link 'Polling officers'
expect(page).to have_content('Poll officing')
within('#side_menu') do
click_link 'Final recounts and results'
end
expect(page).to_not have_content(not_allowed_poll_1.name)
expect(page).to_not have_content(not_allowed_poll_2.name)
expect(page).to_not have_content(not_allowed_poll_3.name)
expect(page).to have_content(@poll.name)
visit new_officing_poll_final_recount_path(not_allowed_poll_1)
expect(page).to have_content('You are allowed to add final recounts for this poll')
end
scenario 'Add final recount' do
visit officing_root_path
within('#side_menu') do
click_link 'Final recounts and results'
end
within("#poll_#{@poll.id}") do
expect(page).to have_content(@poll.name)
click_link 'Add final recount'
end
expect(page).to_not have_content('Your recounts')
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@poll.starts_at.to_date, format: :long)
select booth_name, from: 'officer_assignment_id'
select date, from: 'date'
fill_in :count, with: '33'
click_button 'Save'
expect(page).to have_content('Your final recounts')
within("#poll_final_recount_#{@officer_assignment.booth_assignment.final_recounts.first.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('33')
end
end
scenario 'Edit final recount' do
final_recount = create(:poll_final_recount,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.starts_at,
count: 100)
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(final_recount.date.to_date, format: :long)
visit new_officing_poll_final_recount_path(@poll)
expect(page).to have_content('Your final recounts')
within("#poll_final_recount_#{final_recount.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('100')
end
select booth_name, from: 'officer_assignment_id'
select date, from: 'date'
fill_in :count, with: '42'
click_button 'Save'
expect(page).to have_content "Data added"
within("#poll_final_recount_#{final_recount.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('42')
end
expect(page).to_not have_content('100')
end
scenario 'Show final and system recounts to compare' do
final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
poll = final_officer_assignment.booth_assignment.poll
poll.update(ends_at: 1.day.ago)
final_recount = create(:poll_final_recount,
officer_assignment: final_officer_assignment,
booth_assignment: final_officer_assignment.booth_assignment,
date: 7.days.ago,
count: 100)
33.times { create(:poll_voter, :valid_document,
poll: poll,
booth_assignment: final_officer_assignment.booth_assignment,
created_at: final_recount.date) }
visit new_officing_poll_final_recount_path(poll)
within("#poll_final_recount_#{final_recount.id}") do
expect(page).to have_content(I18n.l(final_recount.date.to_date, format: :long))
expect(page).to have_content(final_officer_assignment.booth_assignment.booth.name)
expect(page).to have_content('100')
expect(page).to have_content('33')
end
end
scenario "Show link to add results for same booth/date" do
final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
poll = final_officer_assignment.booth_assignment.poll
poll.update(ends_at: 1.day.ago)
final_recount = create(:poll_final_recount,
officer_assignment: final_officer_assignment,
booth_assignment: final_officer_assignment.booth_assignment,
date: 7.days.ago,
count: 100)
visit new_officing_poll_final_recount_path(poll)
within("#poll_final_recount_#{final_recount.id}") do
click_link "Add results"
end
expected_path = new_officing_poll_result_path(poll, oa: final_recount.officer_assignment.id, d: I18n.l(final_recount.date.to_date))
expect(page).to have_current_path(expected_path)
expect(page).to have_select('officer_assignment_id', selected: final_recount.booth_assignment.booth.name)
expect(page).to have_select('date', selected: I18n.l(final_recount.date.to_date, format: :long))
end
end

View File

@@ -0,0 +1,87 @@
require 'rails_helper'
feature 'Officing Recount' do
background do
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, officer: @poll_officer)
@poll = @officer_assignment.booth_assignment.poll
login_as(@poll_officer.user)
end
scenario 'Only polls where user is officer are accessible' do
not_allowed_poll = create(:poll)
visit root_path
click_link 'Polling officers'
expect(page).to have_content('Poll officing')
within('#side_menu') do
click_link 'Store recount'
end
expect(page).to_not have_content(not_allowed_poll.name)
expect(page).to have_content(@poll.name)
visit new_officing_poll_recount_path(not_allowed_poll)
expect(page).to have_content('You are not a poll officer for this poll')
end
scenario 'Add recount' do
visit officing_root_path
within('#side_menu') do
click_link 'Store recount'
end
click_link @poll.name
expect(page).to_not have_content('Your recounts')
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@officer_assignment.date.to_date, format: :long)
select "#{booth_name}: #{date}", from: 'officer_assignment_id'
fill_in :count, with: '33'
click_button 'Save'
expect(page).to have_content('Your recounts')
within("#poll_recount_#{@officer_assignment.booth_assignment.recounts.first.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('33')
end
end
scenario 'Edit recount' do
recount = create(:poll_recount,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @officer_assignment.date,
count: 100)
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@officer_assignment.date.to_date, format: :long)
visit new_officing_poll_recount_path(@poll)
expect(page).to have_content('Your recounts')
within("#poll_recount_#{recount.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('100')
end
select "#{booth_name}: #{date}", from: 'officer_assignment_id'
fill_in :count, with: '42'
click_button 'Save'
within("#poll_recount_#{recount.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('42')
end
expect(page).to_not have_content('100')
end
end

View File

@@ -0,0 +1,96 @@
require 'rails_helper'
feature 'Residence' do
let(:officer) { create(:poll_officer) }
feature "Officers without assignments" do
scenario "Can not access residence verification" do
login_as(officer.user)
visit officing_root_path
within("#side_menu") do
click_link "Validate document"
end
expect(page).to have_content("You don't have officing shifts today")
create(:poll_officer_assignment, officer: officer, date: 1.day.from_now)
visit new_officing_residence_path
expect(page).to have_content("You don't have officing shifts today")
end
end
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: '1980'
click_button 'Validate document'
expect(page).to have_content 'Document verified with Census'
end
scenario "Error on verify" do
within("#side_menu") do
click_link "Validate document"
end
click_button 'Validate document'
expect(page).to have_content(/\d errors? prevented the verification of this document/)
end
scenario "Error on Census (document number)" do
initial_failed_census_calls_count = officer.failed_census_calls_count
within("#side_menu") do
click_link "Validate document"
end
select 'DNI', from: 'residence_document_type'
fill_in 'residence_document_number', with: "9999999A"
fill_in 'residence_year_of_birth', with: '1980'
click_button 'Validate document'
expect(page).to have_content 'The Census was unable to verify this document'
officer.reload
fcc = FailedCensusCall.last
expect(fcc).to be
expect(fcc.poll_officer).to eq(officer)
expect(officer.failed_census_calls.last).to eq(fcc)
expect(officer.failed_census_calls_count).to eq(initial_failed_census_calls_count + 1)
end
scenario "Error on Census (year of birth)" 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: '1981'
click_button 'Validate document'
expect(page).to have_content 'The Census was unable to verify this document'
end
end
end

View File

@@ -0,0 +1,159 @@
require 'rails_helper'
feature 'Officing Results' do
background do
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
@poll = @officer_assignment.booth_assignment.poll
@poll.update(ends_at: 1.day.ago)
@question_1 = create(:poll_question, poll: @poll, valid_answers: "Yes,No")
@question_2 = create(:poll_question, poll: @poll, valid_answers: "Today,Tomorrow")
login_as(@poll_officer.user)
end
scenario 'Only polls where user is officer for results are accessible' do
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
not_allowed_poll_1 = create(:poll, :expired)
not_allowed_poll_2 = regular_officer_assignment_1.booth_assignment.poll
not_allowed_poll_2.update(ends_at: 1.day.ago)
not_allowed_poll_3 = regular_officer_assignment_2.booth_assignment.poll
visit root_path
click_link 'Polling officers'
expect(page).to have_content('Poll officing')
within('#side_menu') do
click_link 'Final recounts and results'
end
expect(page).to_not have_content(not_allowed_poll_1.name)
expect(page).to_not have_content(not_allowed_poll_2.name)
expect(page).to_not have_content(not_allowed_poll_3.name)
expect(page).to have_content(@poll.name)
visit new_officing_poll_result_path(not_allowed_poll_1)
expect(page).to have_content('You are allowed to add results for this poll')
end
scenario 'Add results' do
visit officing_root_path
within('#side_menu') do
click_link 'Final recounts and results'
end
within("#poll_#{@poll.id}") do
expect(page).to have_content(@poll.name)
click_link 'Add results'
end
expect(page).to_not have_content('Your results')
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@poll.starts_at.to_date, format: :long)
select booth_name, from: 'officer_assignment_id'
select date, from: 'date'
fill_in "questions[#{@question_1.id}][0]", with: '100'
fill_in "questions[#{@question_1.id}][1]", with: '200'
fill_in "questions[#{@question_2.id}][0]", with: '333'
fill_in "questions[#{@question_2.id}][1]", with: '444'
fill_in "whites", with: '66'
fill_in "nulls", with: '77'
click_button 'Save'
expect(page).to have_content('Your results')
within("#results_#{@officer_assignment.booth_assignment_id}_#{@poll.starts_at.to_date.strftime('%Y%m%d')}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
end
end
scenario 'Edit result' do
partial_result = create(:poll_partial_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.starts_at,
question: @question_1,
answer: @question_1.valid_answers[0],
author: @poll_officer.user,
amount: 7777)
visit officing_poll_results_path(@poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id)
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content('7777') }
visit new_officing_poll_result_path(@poll)
booth_name = partial_result.booth_assignment.booth.name
date = I18n.l(partial_result.date, format: :long)
select booth_name, from: 'officer_assignment_id'
select date, from: 'date'
fill_in "questions[#{@question_1.id}][0]", with: '5555'
fill_in "questions[#{@question_1.id}][1]", with: '200'
fill_in "whites", with: '6'
fill_in "nulls", with: '7'
click_button 'Save'
within("#results_#{partial_result.booth_assignment_id}_#{partial_result.date.strftime('%Y%m%d')}") do
expect(page).to have_content(I18n.l(partial_result.date, format: :long))
expect(page).to have_content(partial_result.booth_assignment.booth.name)
click_link "See results"
end
expect(page).to_not have_content('7777')
within("#white_results") { expect(page).to have_content('6') }
within("#null_results") { expect(page).to have_content('7') }
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content('5555') }
within("#question_#{@question_1.id}_1_result") { expect(page).to have_content('200') }
end
scenario 'Index lists all questions and answers' do
partial_result = create(:poll_partial_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
question: @question_1,
amount: 33)
white_result = create(:poll_white_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
amount: 21)
null_result = create(:poll_null_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
amount: 44)
visit officing_poll_results_path(@poll,
date: I18n.l(@poll.ends_at.to_date),
booth_assignment_id: @officer_assignment.booth_assignment_id)
expect(page).to have_content(I18n.l(@poll.ends_at.to_date, format: :long))
expect(page).to have_content(@officer_assignment.booth_assignment.booth.name)
expect(page).to have_content(@question_1.title)
@question_1.valid_answers.each_with_index do |answer, i|
within("#question_#{@question_1.id}_#{i}_result") { expect(page).to have_content(answer) }
end
expect(page).to have_content(@question_2.title)
@question_2.valid_answers.each_with_index do |answer, i|
within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer) }
end
within('#white_results') { expect(page).to have_content('21') }
within('#null_results') { expect(page).to have_content('44') }
end
end

View File

@@ -0,0 +1,67 @@
require 'rails_helper'
feature 'Voters' do
let(:officer) { create(:poll_officer) }
background do
login_as(officer.user)
create(:geozone, :in_census)
#remove once foundation.equalizer js error has been fixed
Capybara.current_driver = :poltergeist_no_js_errors
end
scenario "Can vote", :js do
poll = create(:poll_officer_assignment, officer: officer).booth_assignment.poll
visit new_officing_residence_path
officing_verify_residence
expect(page).to have_content "Polls"
expect(page).to have_content poll.name
click_button "Confirm vote"
expect(page).to have_content "Vote introduced!"
expect(page).to_not have_button "Confirm vote"
page.evaluate_script("window.location.reload()")
expect(page).to have_content "Has already participated in this poll"
expect(page).to_not have_button "Confirm vote"
end
scenario "Already voted", :js do
poll1 = create(:poll)
poll2 = create(:poll)
user = create(:user, :level_two)
voter = create(:poll_voter, poll: poll1, user: user)
visit new_officing_voter_path(id: voter.user.id)
within("#poll_#{poll1.id}") do
expect(page).to have_content "Has already participated in this poll"
expect(page).to_not have_button "Confirm vote"
end
within("#poll_#{poll2.id}") do
expect(page).to have_button "Confirm vote"
end
end
scenario "Had already verified his residence, but is not level 2 yet", :js do
user = create(:user, residence_verified_at: Time.current, document_type: "1", document_number: "12345678Z")
expect(user).to_not be_level_two_verified
poll = create(:poll_officer_assignment, officer: officer).booth_assignment.poll
visit new_officing_residence_path
officing_verify_residence
expect(page).to have_content "Polls"
expect(page).to have_content poll.name
end
#Fix and use answerable_by(user)
xscenario "Display only answerable polls"
end

View File

@@ -0,0 +1,109 @@
require 'rails_helper'
feature 'Poll Officing' do
let(:user) { create(:user) }
scenario 'Access as regular user is not authorized' do
login_as(user)
visit root_path
expect(page).to_not have_link("Polling officers")
visit officing_root_path
expect(current_path).not_to eq(officing_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as moderator is not authorized' do
create(:moderator, user: user)
login_as(user)
visit root_path
expect(page).to_not have_link("Polling officers")
visit officing_root_path
expect(current_path).not_to eq(officing_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as manager is not authorized' do
create(:manager, user: user)
login_as(user)
visit root_path
expect(page).to_not have_link("Polling officers")
visit officing_root_path
expect(current_path).not_to eq(officing_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as a valuator is not authorized' do
create(:valuator, user: user)
login_as(user)
visit root_path
expect(page).to_not have_link("Polling officers")
visit officing_root_path
expect(current_path).not_to eq(officing_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as an poll officer is authorized' do
create(:poll_officer, user: user)
create(:poll)
login_as(user)
visit root_path
expect(page).to have_link("Polling officers")
click_on "Polling officers"
expect(current_path).to eq(officing_root_path)
expect(page).to_not have_content "You do not have permission to access this page"
end
scenario 'Access as an administrator is authorized' do
create(:administrator, user: user)
create(:poll)
login_as(user)
visit root_path
expect(page).to have_link("Polling officers")
click_on "Polling officers"
expect(current_path).to eq(officing_root_path)
expect(page).to_not have_content "You do not have permission to access this page"
end
scenario "Poll officer access links" do
create(:poll_officer, user: user)
login_as(user)
visit root_path
expect(page).to have_link("Polling officers")
expect(page).to_not have_link('Valuation')
expect(page).to_not have_link('Administration')
expect(page).to_not have_link('Moderation')
end
scenario 'Officing dashboard' do
create(:poll_officer, user: user)
create(:poll)
login_as(user)
visit root_path
click_link 'Polling officers'
expect(current_path).to eq(officing_root_path)
expect(page).to have_css('#officing_menu')
expect(page).to_not have_css('#valuation_menu')
expect(page).to_not have_css('#admin_menu')
expect(page).to_not have_css('#moderation_menu')
end
end

View File

@@ -0,0 +1,197 @@
require 'rails_helper'
feature 'Polls' do
context '#index' do
scenario 'Polls can be listed' do
polls = create_list(:poll, 3)
visit polls_path
polls.each do |poll|
expect(page).to have_content(poll.name)
expect(page).to have_link("Participate in this poll")
end
end
scenario 'Filtering polls' do
create(:poll, name: "Current poll")
create(:poll, :incoming, name: "Incoming poll")
create(:poll, :expired, name: "Expired poll")
visit polls_path
expect(page).to have_content('Current poll')
expect(page).to have_link('Participate in this poll')
expect(page).to_not have_content('Incoming poll')
expect(page).to_not have_content('Expired poll')
visit polls_path(filter: 'incoming')
expect(page).to_not have_content('Current poll')
expect(page).to have_content('Incoming poll')
expect(page).to have_link('More information')
expect(page).to_not have_content('Expired poll')
visit polls_path(filter: 'expired')
expect(page).to_not have_content('Current poll')
expect(page).to_not have_content('Incoming poll')
expect(page).to have_content('Expired poll')
expect(page).to have_link('Poll ended')
end
scenario "Current filter is properly highlighted" do
visit polls_path
expect(page).to_not have_link('Open')
expect(page).to have_link('Incoming')
expect(page).to have_link('Expired')
visit polls_path(filter: 'incoming')
expect(page).to have_link('Open')
expect(page).to_not have_link('Incoming')
expect(page).to have_link('Expired')
visit polls_path(filter: 'expired')
expect(page).to have_link('Open')
expect(page).to have_link('Incoming')
expect(page).to_not have_link('Expired')
end
end
context 'Show' do
let(:geozone) { create(:geozone) }
let(:poll) { create(:poll) }
scenario 'Lists questions from proposals as well as regular ones' do
normal_question = create(:poll_question, poll: poll)
proposal_question = create(:poll_question, poll: poll, proposal: create(:proposal))
visit poll_path(poll)
expect(page).to have_content(poll.name)
expect(page).to have_content(normal_question.title)
expect(page).to have_content(proposal_question.title)
end
scenario 'Non-logged in users' do
create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
visit poll_path(poll)
expect(page).to have_content('Han Solo')
expect(page).to have_content('Chewbacca')
expect(page).to have_content('You must Sign in or Sign up to participate')
expect(page).to_not have_link('Han Solo')
expect(page).to_not have_link('Chewbacca')
end
scenario 'Level 1 users' do
poll.update(geozone_restricted: true)
poll.geozones << geozone
create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
login_as(create(:user, geozone: geozone))
visit poll_path(poll)
expect(page).to have_content('You must verify your account in order to answer')
expect(page).to have_content('Han Solo')
expect(page).to have_content('Chewbacca')
expect(page).to_not have_link('Han Solo')
expect(page).to_not have_link('Chewbacca')
end
scenario 'Level 2 users in an incoming poll' do
incoming_poll = create(:poll, :incoming, geozone_restricted: true)
incoming_poll.geozones << geozone
create(:poll_question, poll: incoming_poll, valid_answers: 'Rey, Finn')
login_as(create(:user, :level_two, geozone: geozone))
visit poll_path(incoming_poll)
expect(page).to have_content('Rey')
expect(page).to have_content('Finn')
expect(page).to_not have_link('Rey')
expect(page).to_not have_link('Finn')
expect(page).to have_content('This poll has not yet started')
end
scenario 'Level 2 users in an expired poll' do
expired_poll = create(:poll, :expired, geozone_restricted: true)
expired_poll.geozones << geozone
create(:poll_question, poll: expired_poll, valid_answers: 'Luke, Leia')
login_as(create(:user, :level_two, geozone: geozone))
visit poll_path(expired_poll)
expect(page).to have_content('Luke')
expect(page).to have_content('Leia')
expect(page).to_not have_link('Luke')
expect(page).to_not have_link('Leia')
expect(page).to have_content('This poll has finished')
end
scenario 'Level 2 users in a poll with questions for a geozone which is not theirs' do
poll.update(geozone_restricted: true)
poll.geozones << create(:geozone)
create(:poll_question, poll: poll, valid_answers: 'Vader, Palpatine')
login_as(create(:user, :level_two))
visit poll_path(poll)
expect(page).to have_content('Vader')
expect(page).to have_content('Palpatine')
expect(page).to_not have_link('Vader')
expect(page).to_not have_link('Palpatine')
end
scenario 'Level 2 users reading a same-geozone poll' do
poll.update(geozone_restricted: true)
poll.geozones << geozone
create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
login_as(create(:user, :level_two, geozone: geozone))
visit poll_path(poll)
expect(page).to have_link('Han Solo')
expect(page).to have_link('Chewbacca')
end
scenario 'Level 2 users reading a all-geozones poll' do
create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
login_as(create(:user, :level_two))
visit poll_path(poll)
expect(page).to have_link('Han Solo')
expect(page).to have_link('Chewbacca')
end
scenario 'Level 2 users who have already answered' do
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
user = create(:user, :level_two)
create(:poll_answer, question: question, author: user, answer: 'Chewbacca')
login_as user
visit poll_path(poll)
expect(page).to have_link('Han Solo')
expect(page).to_not have_link('Chewbacca')
expect(page).to have_content('Chewbacca')
end
scenario 'Level 2 users answering', :js do
poll.update(geozone_restricted: true)
poll.geozones << geozone
create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
user = create(:user, :level_two, geozone: geozone)
login_as user
visit poll_path(poll)
click_link 'Han Solo'
expect(page).to_not have_link('Han Solo')
expect(page).to have_link('Chewbacca')
end
end
end

View File

@@ -0,0 +1,112 @@
require 'rails_helper'
feature 'Poll Questions' do
scenario 'Lists questions from proposals before regular questions' do
poll = create(:poll)
normal_question = create(:poll_question, poll: poll)
proposal_question = create(:poll_question, proposal: create(:proposal), poll: poll)
visit poll_path(poll)
expect(proposal_question.title).to appear_before(normal_question.title)
end
scenario 'shows the author visible name instead of a link to the author' do
poll = create(:poll)
question_with_author = create(:poll_question, poll: poll)
question_with_author_visible_name = create(:poll_question, poll: poll, author_visible_name: 'potato')
visit question_path(question_with_author)
expect(page).to have_link(question_with_author.author.name)
visit question_path(question_with_author_visible_name)
expect(page).to_not have_link(question_with_author_visible_name.author.name)
expect(page).to have_content(question_with_author_visible_name.author_visible_name)
end
context 'Answering' do
let(:geozone) { create(:geozone) }
let(:poll) { create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) }
scenario 'Non-logged in users' do
question = create(:poll_question, valid_answers: 'Han Solo, Chewbacca')
visit question_path(question)
expect(page).to have_content('You must Sign in or Sign up to participate')
end
scenario 'Level 1 users' do
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
login_as(create(:user, geozone: geozone))
visit question_path(question)
expect(page).to have_content('You must verify your account in order to answer')
end
scenario 'Level 2 users in an poll question for a geozone which is not theirs' do
other_poll = create(:poll, geozone_restricted: true, geozone_ids: [create(:geozone).id])
question = create(:poll_question, poll: other_poll, valid_answers: 'Vader, Palpatine')
login_as(create(:user, :level_two, geozone: geozone))
visit question_path(question)
expect(page).to have_content('This question is not available on your geozone')
end
scenario 'Level 2 users who can answer' do
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
login_as(create(:user, :level_two, geozone: geozone))
visit question_path(question)
expect(page).to have_link('Answer this question')
end
scenario 'Level 2 users who have already answered' do
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
user = create(:user, :level_two, geozone: geozone)
create(:poll_answer, question: question, author: user, answer: 'Chewbacca')
login_as user
visit question_path(question)
expect(page).to have_link('Answer this question')
end
scenario 'Level 2 users answering', :js do
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
user = create(:user, :level_two, geozone: geozone)
login_as user
visit question_path(question)
expect(page).to have_link('Answer this question')
end
scenario 'Records participation', :js do
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
user = create(:user, :level_two, geozone: geozone, gender: 'female', date_of_birth: 33.years.ago)
login_as user
visit question_path(question)
click_link 'Answer this question'
click_link 'Han Solo'
expect(page).to_not have_link('Han Solo')
voter = poll.voters.first
expect(voter.document_number).to eq(user.document_number)
expect(voter.geozone_id).to eq(user.geozone_id)
expect(voter.gender).to eq(user.gender)
expect(voter.age).to eq(33)
expect(voter.poll_id).to eq(poll.id)
end
end
end

View File

@@ -10,7 +10,7 @@ feature 'Proposal ballots' do
expect(page).to_not have_css("#next-voting")
expect(page).to have_css("#featured-proposals")
create_successfull_proposals
create_successful_proposals
visit proposals_path
@@ -18,22 +18,22 @@ feature 'Proposal ballots' do
expect(page).to_not have_css("#featured-proposals")
end
scenario 'Successfull proposals do not show support buttons in index' do
successfull_proposals = create_successfull_proposals
scenario 'Successful proposals do not show support buttons in index' do
successful_proposals = create_successful_proposals
visit proposals_path
successfull_proposals.each do |proposal|
successful_proposals.each do |proposal|
within("#proposal_#{proposal.id}_votes") do
expect(page).to have_content "This proposal has reached the required supports"
end
end
end
scenario 'Successfull proposals do not show support buttons in show' do
successfull_proposals = create_successfull_proposals
scenario 'Successful proposals do not show support buttons in show' do
successful_proposals = create_successful_proposals
successfull_proposals.each do |proposal|
successful_proposals.each do |proposal|
visit proposal_path(proposal)
within("#proposal_#{proposal.id}_votes") do
expect(page).to have_content "This proposal has reached the required supports"
@@ -41,15 +41,5 @@ feature 'Proposal ballots' do
end
end
scenario 'Successfull proposals are listed in the proposal ballots index' do
successfull_proposals = create_successfull_proposals
visit proposal_ballots_path
successfull_proposals.each do |proposal|
expect(page).to have_content(proposal.title)
end
end
end

View File

@@ -1372,3 +1372,69 @@ feature 'Proposals' do
end
end
feature 'Successful proposals' do
scenario 'Banner shows in proposal index' do
create_featured_proposals
visit proposals_path
expect(page).to_not have_css("#next-voting")
expect(page).to have_css("#featured-proposals")
create_successful_proposals
visit proposals_path
expect(page).to have_css("#next-voting")
expect(page).to_not have_css("#featured-proposals")
end
scenario 'Successful proposals do not show support buttons in index' do
successful_proposals = create_successful_proposals
visit proposals_path
successful_proposals.each do |proposal|
within("#proposal_#{proposal.id}_votes") do
expect(page).to_not have_css(".supports")
expect(page).to have_content "This proposal has reached the required supports"
end
end
end
scenario 'Successful proposals do not show support buttons in show' do
successful_proposals = create_successful_proposals
successful_proposals.each do |proposal|
visit proposal_path(proposal)
within("#proposal_#{proposal.id}_votes") do
expect(page).to_not have_css(".supports")
expect(page).to have_content "This proposal has reached the required supports"
end
end
end
scenario 'Successful proposals show create question button to admin users' do
successful_proposals = create_successful_proposals
visit proposals_path
successful_proposals.each do |proposal|
within("#proposal_#{proposal.id}_votes") do
expect(page).to_not have_link "Create question"
end
end
login_as(create(:administrator).user)
visit proposals_path
successful_proposals.each do |proposal|
within("#proposal_#{proposal.id}_votes") do
expect(page).to have_link "Create question"
end
end
end
end

View File

@@ -61,6 +61,8 @@ feature 'Valuation budget investments' do
end
scenario "Index filtering by heading", :js do
Capybara.current_driver = :poltergeist_no_js_errors
group = create(:budget_group, budget: @budget)
heading1 = create(:budget_heading, name: "District 9", group: group)
heading2 = create(:budget_heading, name: "Down to the river", group: group)

View File

@@ -83,6 +83,8 @@ feature 'Valuation spending proposals' do
end
scenario "Index filtering by geozone", :js do
Capybara.current_driver = :poltergeist_no_js_errors
geozone = create(:geozone, name: "District 9")
spending_proposal1 = create(:spending_proposal, title: "Realocate visitors", geozone: geozone)
spending_proposal2 = create(:spending_proposal, title: "Destroy the city")

View File

@@ -46,6 +46,19 @@ feature 'Valuation' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as poll officer is not authorized' do
create(:poll_officer, user: user)
login_as(user)
visit root_path
expect(page).to_not have_link("Valuation")
visit valuation_root_path
expect(current_path).not_to eq(valuation_root_path)
expect(current_path).to eq(proposals_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as a valuator is authorized' do
create(:valuator, user: user)
login_as(user)

View File

@@ -22,6 +22,31 @@ feature 'Residence' do
expect(page).to have_content 'Residence verified'
end
scenario '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
scenario 'Error on verify' do
user = create(:user)
login_as(user)
@@ -102,24 +127,4 @@ feature 'Residence' do
expect(page).to have_content "You have reached the maximum number of attempts. Please try again later."
expect(current_path).to eq(account_path)
end
scenario 'Error when trying to verify a deregistered account' do
create(:user, document_number: '12345678Z', document_type: '1', erased_at: Time.now)
login_as(create(: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_not have_content 'Residence verified'
expect(page).to have_content 'has already been taken'
end
end