Specs added to test the functionality and some UI modified to make test pass
This commit is contained in:
@@ -14,8 +14,8 @@
|
|||||||
method: :delete,
|
method: :delete,
|
||||||
remote: true,
|
remote: true,
|
||||||
title: t("admin.booth_assignments.manage.actions.unassign"),
|
title: t("admin.booth_assignments.manage.actions.unassign"),
|
||||||
class: "button hollow alert #{@poll.expired? ? 'disabled' : ''}",
|
class: "button hollow alert",
|
||||||
data: (booth_assignment.shifts? ? {confirm: "#{t("admin.poll_booth_assignments.alert.shifts")}"} : nil) %>
|
data: (booth_assignment.shifts? ? {confirm: "#{t("admin.poll_booth_assignments.alert.shifts")}"} : nil) if !@poll.expired? %>
|
||||||
</td>
|
</td>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td>
|
<td>
|
||||||
@@ -27,6 +27,6 @@
|
|||||||
method: :post,
|
method: :post,
|
||||||
remote: true,
|
remote: true,
|
||||||
title: t("admin.booth_assignments.manage.actions.assign"),
|
title: t("admin.booth_assignments.manage.actions.assign"),
|
||||||
class: "button #{@poll.expired? ? 'disabled' : ''}" %>
|
class: "button" if !@poll.expired? %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -106,9 +106,44 @@ feature 'Admin booths assignments' do
|
|||||||
expect(page).to have_content 'There are no booths assigned to this poll.'
|
expect(page).to have_content 'There are no booths assigned to this poll.'
|
||||||
expect(page).not_to have_content booth.name
|
expect(page).not_to have_content booth.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Unassing booth whith associated shifts', :js do
|
||||||
|
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||||
|
officer = create(:poll_officer)
|
||||||
|
create(:poll_officer_assignment, officer: officer, booth_assignment: assignment)
|
||||||
|
create(:poll_shift, booth: booth, officer: officer)
|
||||||
|
|
||||||
|
visit manage_admin_poll_booth_assignments_path(poll)
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
feature 'Show' do
|
scenario "Cannot unassing booth if poll is expired" do
|
||||||
|
poll_expired = create(:poll, :expired)
|
||||||
|
create(:poll_booth_assignment, poll: poll_expired, booth: booth)
|
||||||
|
|
||||||
|
visit manage_admin_poll_booth_assignments_path(poll_expired)
|
||||||
|
|
||||||
|
within("#poll_booth_#{booth.id}") do
|
||||||
|
expect(page).to have_content(booth.name)
|
||||||
|
expect(page).to have_content "Assigned"
|
||||||
|
|
||||||
|
expect(page).not_to have_link 'Unassign booth'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
xfeature 'Show' do
|
||||||
scenario 'Lists all assigned poll officers' do
|
scenario 'Lists all assigned poll officers' do
|
||||||
poll = create(:poll)
|
poll = create(:poll)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth)
|
||||||
|
|||||||
29
spec/models/poll/booth_assignment_spec.rb
Normal file
29
spec/models/poll/booth_assignment_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe :booth_assignment do
|
||||||
|
let(:poll){create(:poll)}
|
||||||
|
let(:booth){create(:poll_booth)}
|
||||||
|
let(:booth1){create(:poll_booth)}
|
||||||
|
|
||||||
|
it "should check if there are shifts" do
|
||||||
|
assignment_with_shifts = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||||
|
assignment_without_shifts = create(:poll_booth_assignment, poll: poll, booth: booth1)
|
||||||
|
officer = create(:poll_officer)
|
||||||
|
create(:poll_officer_assignment, officer: officer, booth_assignment: assignment_with_shifts)
|
||||||
|
create(:poll_shift, booth: booth, officer: officer)
|
||||||
|
|
||||||
|
expect(assignment_with_shifts.shifts?).to eq(true)
|
||||||
|
expect(assignment_without_shifts.shifts?).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should delete shifts associated to booth assignments" do
|
||||||
|
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||||
|
officer = create(:poll_officer)
|
||||||
|
create(:poll_officer_assignment, officer: officer, booth_assignment: assignment)
|
||||||
|
create(:poll_shift, booth: booth, officer: officer)
|
||||||
|
|
||||||
|
assignment.destroy
|
||||||
|
|
||||||
|
expect(Poll::Shift.all.count).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user