diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index ec8c10d58..fd8fb9e84 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -36,6 +36,32 @@ feature 'Admin booths' do expect(page).to_not have_content "There are no booths" end + scenario "Available" do + booth_for_current_poll = create(:poll_booth) + booth_for_incoming_poll = create(:poll_booth) + booth_for_expired_poll = create(:poll_booth) + + current_poll = create(:poll, :current) + incoming_poll = create(:poll, :incoming) + expired_poll = create(:poll, :expired) + + create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll) + create(:poll_booth_assignment, poll: incoming_poll, booth: booth_for_incoming_poll) + create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll) + + visit admin_root_path + + within('#side_menu') do + click_link "Manage shifts" + end + + expect(page).to have_css(".booth", count: 2) + + expect(page).to have_content booth_for_current_poll.name + expect(page).to have_content booth_for_incoming_poll.name + expect(page).to_not have_content booth_for_expired_poll.name + end + scenario 'Show' do booth = create(:poll_booth) diff --git a/spec/models/poll/booth_spec.rb b/spec/models/poll/booth_spec.rb index c095c62cd..d340d8197 100644 --- a/spec/models/poll/booth_spec.rb +++ b/spec/models/poll/booth_spec.rb @@ -24,4 +24,25 @@ describe :booth do end end + describe "#available" do + + it "returns booths associated to current or incoming polls" do + booth_for_current_poll = create(:poll_booth) + booth_for_incoming_poll = create(:poll_booth) + booth_for_expired_poll = create(:poll_booth) + + current_poll = create(:poll, :current) + incoming_poll = create(:poll, :incoming) + expired_poll = create(:poll, :expired) + + create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll) + create(:poll_booth_assignment, poll: incoming_poll, booth: booth_for_incoming_poll) + create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll) + + expect(Poll::Booth.available).to include(booth_for_current_poll) + expect(Poll::Booth.available).to include(booth_for_incoming_poll) + expect(Poll::Booth.available).to_not include(booth_for_expired_poll) + end + + end end \ No newline at end of file