Files
grecia/spec/features/admin/poll/officer_assignments_spec.rb
Javi Martín 307cf24846 Use describe on feature tests
The `type: :feature` is automatically detected by RSpec because these
tests are inside the `spec/features` folder. Using `feature` re-adds a
`type: :feature` to these files, which will result in a conflict when we
upgrade to Rails 5.1's system tests.

Because of this change, we also need to change `background` to `before`
or else these tests will fail.
2019-05-28 16:36:54 +02:00

67 lines
2.0 KiB
Ruby

require "rails_helper"
describe "Officer Assignments" do
before do
admin = create(:administrator)
login_as(admin.user)
end
scenario "Index" do
poll = create(:poll)
booth = create(:poll_booth)
officer1 = create(:poll_officer)
officer2 = create(:poll_officer)
officer3 = create(:poll_officer)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer1)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment_2, officer: officer2)
visit admin_poll_path(poll)
click_link "Officers (2)"
within("#officer_assignments") do
expect(page).to have_content officer1.name
expect(page).to have_content officer2.name
expect(page).not_to have_content officer3.name
end
end
scenario "Search", :js do
poll = create(:poll)
booth = create(:poll_booth)
user1 = create(:user, username: "John Snow")
user2 = create(:user, username: "John Silver")
user3 = create(:user, username: "John Edwards")
officer1 = create(:poll_officer, user: user1)
officer2 = create(:poll_officer, user: user2)
officer3 = create(:poll_officer, user: user3)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer1)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment_2, officer: officer2)
visit admin_poll_path(poll)
click_link "Officers (2)"
fill_in "search-officers", with: "John"
click_button "Search"
within("#search-officers-results") do
expect(page).to have_content officer1.name
expect(page).to have_content officer2.name
expect(page).not_to have_content officer3.name
end
end
end