Merge branch 'master' into 1786-poll_results

This commit is contained in:
María Checa
2017-10-23 13:43:58 +02:00
25 changed files with 341 additions and 153 deletions

View File

@@ -7,66 +7,109 @@ feature 'Admin booths assignments' do
login_as(admin.user)
end
scenario 'Assign booth to poll', :js do
poll = create(:poll)
booth = create(:poll_booth)
feature 'Admin Booth Assignment management' do
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (0)'
let!(:poll) { create(:poll) }
let!(:booth) { create(:poll_booth) }
scenario 'List Polls and Booths to manage', :js do
second_poll = create(:poll)
second_booth = create(:poll_booth)
visit booth_assignments_admin_polls_path
expect(page).to have_content(poll.name)
expect(page).to have_content(second_poll.name)
within("#poll_#{second_poll.id}") do
click_link 'Manage assignments'
end
expect(page).to have_content "Assignments for poll '#{second_poll.name}'"
expect(page).to have_content(booth.name)
expect(page).to have_content(second_booth.name)
end
expect(page).to have_content 'There are no booths assigned to this poll.'
scenario 'Assign booth to poll', :js do
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (0)'
end
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name)
expect(page).to have_content 'There are no booths assigned to this poll.'
expect(page).to_not have_content booth.name
within('#search-booths-results') do
click_link 'Assign booth'
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name)
visit manage_admin_poll_booth_assignments_path(poll)
expect(page).to have_content "Assignments for poll '#{poll.name}'"
within("#poll_booth_#{booth.id}") do
expect(page).to have_content(booth.name)
expect(page).to have_content "Unassigned"
click_link 'Assign booth'
expect(page).not_to have_content "Unassigned"
expect(page).to have_content "Assigned"
expect(page).to have_link "Unassign booth"
end
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
expect(page).to have_content 'Booth assigned'
scenario 'Unassign booth from poll', :js do
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).not_to have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name)
visit manage_admin_poll_booth_assignments_path(poll)
expect(page).to have_content "Assignments for poll '#{poll.name}'"
within("#poll_booth_#{booth.id}") do
expect(page).to have_content(booth.name)
expect(page).to have_content "Assigned"
click_link 'Unassign booth'
expect(page).to have_content "Unassigned"
expect(page).not_to have_content "Assigned"
expect(page).to have_link "Assign booth"
end
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).not_to have_content booth.name
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
scenario 'Lists all assigned poll officers' do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)

View File

@@ -60,6 +60,10 @@ feature 'Admin polls' do
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..."
fill_in 'poll_description', with: "Upcomming poll's description. This poll..."
expect(page).to_not have_css("#poll_results_enabled")
expect(page).to_not have_css("#poll_stats_enabled")
click_button "Create poll"
expect(page).to have_content "Poll created successfully"
@@ -79,14 +83,25 @@ feature 'Admin polls' do
expect(page).to have_css("img[alt='#{poll.image.title}']")
expect(page).to have_css("#poll_results_enabled")
expect(page).to have_css("#poll_stats_enabled")
fill_in "poll_name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
check 'poll_results_enabled'
check 'poll_stats_enabled'
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)
click_link "Edit poll"
expect(page).to have_field('poll_results_enabled', checked: true)
expect(page).to have_field('poll_stats_enabled', checked: true)
end
scenario 'Edit from index' do

View File

@@ -55,7 +55,22 @@ feature 'Poll Officing' do
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as an poll officer is authorized' do
scenario 'Access as an administrator is not authorized' do
create(:administrator, user: user)
create(:poll)
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(root_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as an administrator with poll officer role is authorized' do
create(:administrator, user: user)
create(:poll_officer, user: user)
create(:poll)
login_as(user)
@@ -68,8 +83,8 @@ feature 'Poll Officing' do
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)
scenario 'Access as an poll officer is authorized' do
create(:poll_officer, user: user)
create(:poll)
login_as(user)
visit root_path