Merge pull request #3693 from DenisNikolski/booths-search

Add search form on admin booths
This commit is contained in:
Javier Martín
2019-09-22 03:09:50 +02:00
committed by GitHub
6 changed files with 40 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ class Admin::Poll::BoothsController < Admin::Poll::BaseController
load_and_authorize_resource class: "Poll::Booth"
def index
@booths = @booths.search params[:search] if params[:search]
@booths = @booths.order(name: :asc).page(params[:page])
end

View File

@@ -10,6 +10,8 @@
</div>
<% end %>
<%= render "/admin/shared/booth_search", url: admin_booths_path %>
<% if @booths.any? %>
<h3><%= page_entries_info @booths %></h3>
<table>

View File

@@ -0,0 +1,10 @@
<%= form_for(Poll::Booth.new, url: url, as: :booth, method: :get) do |f| %>
<div class="small-12 medium-6">
<div class="input-group">
<%= text_field_tag :search, params[:search], placeholder: t("admin.shared.booths_search.placeholder") %>
<div class="input-group-button">
<%= f.submit t("admin.shared.booths_search.button"), class: "button" %>
</div>
</div>
</div>
<% end %>

View File

@@ -1330,7 +1330,7 @@ en:
false_value: "No"
booths_search:
button: Search
placeholder: Search booth by name
placeholder: Search booth by name or location
poll_officers_search:
button: Search
placeholder: Search poll officers

View File

@@ -123,4 +123,22 @@ describe "Admin booths" do
click_link "Go back"
expect(page).to have_current_path(available_admin_booths_path)
end
scenario "Search" do
booth = create(:poll_booth)
visit admin_booths_path
fill_in "search", with: booth.name
click_button "Search"
expect(page).to have_css(".booth", count: 1)
fill_in "search", with: booth.location
click_button "Search"
expect(page).to have_css(".booth", count: 1)
fill_in "search", with: "Wrong search criteria"
click_button "Search"
expect(page).to have_content "There are no active booths for any upcoming poll."
end
end

View File

@@ -48,6 +48,8 @@ describe "Admin shifts" do
click_link "Manage shifts"
end
expect(page).to have_content "This booth has no shifts"
fill_in "search", with: officer.email
click_button "Search"
click_link "Edit shifts"
@@ -72,6 +74,8 @@ describe "Admin shifts" do
click_link "Manage shifts"
end
expect(page).to have_css(".shift", count: 1)
fill_in "search", with: officer.email
click_button "Search"
click_link "Edit shifts"
@@ -115,6 +119,8 @@ describe "Admin shifts" do
click_link "Manage shifts"
end
expect(page).to have_css(".shift", count: 2)
fill_in "search", with: officer.email
click_button "Search"
click_link "Edit shifts"
@@ -154,6 +160,8 @@ describe "Admin shifts" do
click_link "Manage shifts"
end
expect(page).to have_content "This booth has no shifts"
fill_in "search", with: officer.email
click_button "Search"
click_link "Edit shifts"