searches for officers assigned to a poll

This commit is contained in:
rgarcia
2017-10-13 18:39:13 +02:00
parent 5d39ce2f03
commit f2d99d6747
3 changed files with 72 additions and 2 deletions

View File

@@ -25,7 +25,9 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController
def search_officers
load_search
@officers = User.joins(:poll_officer).search(@search).order(username: :asc)
poll_officers = User.where(id: @poll.officers.pluck(:user_id))
@officers = poll_officers.search(@search).order(username: :asc)
respond_to do |format|
format.js

View File

@@ -11,7 +11,7 @@
<%= t("admin.poll_officer_assignments.index.no_officers") %>
</div>
<% else %>
<table class="fixed margin">
<table class="fixed margin" id="officer_assignments">
<thead>
<th><%= t("admin.poll_officer_assignments.index.table_name") %></th>
<th><%= t("admin.poll_officer_assignments.index.table_email") %></th>

View File

@@ -0,0 +1,68 @@
require 'rails_helper'
feature 'Officer Assignments' do
background 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).to_not 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).to_not have_content officer3.name
end
end
end