searches for officers assigned to a poll
This commit is contained in:
@@ -25,7 +25,9 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController
|
|||||||
|
|
||||||
def search_officers
|
def search_officers
|
||||||
load_search
|
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|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<%= t("admin.poll_officer_assignments.index.no_officers") %>
|
<%= t("admin.poll_officer_assignments.index.no_officers") %>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<table class="fixed margin">
|
<table class="fixed margin" id="officer_assignments">
|
||||||
<thead>
|
<thead>
|
||||||
<th><%= t("admin.poll_officer_assignments.index.table_name") %></th>
|
<th><%= t("admin.poll_officer_assignments.index.table_name") %></th>
|
||||||
<th><%= t("admin.poll_officer_assignments.index.table_email") %></th>
|
<th><%= t("admin.poll_officer_assignments.index.table_email") %></th>
|
||||||
|
|||||||
68
spec/features/admin/poll/officer_assignments_spec.rb
Normal file
68
spec/features/admin/poll/officer_assignments_spec.rb
Normal 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
|
||||||
Reference in New Issue
Block a user