From 6f085b56962014927c3acd5f5343475d4b4702b8 Mon Sep 17 00:00:00 2001 From: DenisNikolski Date: Wed, 11 Sep 2019 21:41:57 +0300 Subject: [PATCH 1/3] add search form on admin booths --- app/controllers/admin/poll/booths_controller.rb | 1 + app/views/admin/poll/booths/index.html.erb | 2 ++ app/views/admin/shared/_booth_search.html.erb | 10 ++++++++++ config/locales/en/admin.yml | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/shared/_booth_search.html.erb diff --git a/app/controllers/admin/poll/booths_controller.rb b/app/controllers/admin/poll/booths_controller.rb index 514389203..7f3ad32aa 100644 --- a/app/controllers/admin/poll/booths_controller.rb +++ b/app/controllers/admin/poll/booths_controller.rb @@ -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].strip if params[:search] @booths = @booths.order(name: :asc).page(params[:page]) end diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index 6a03b38fa..add01ee0d 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -11,6 +11,8 @@ <% end %> <% if @booths.any? %> + <%= render "/admin/shared/booth_search", url: admin_booths_path %> +

<%= page_entries_info @booths %>

diff --git a/app/views/admin/shared/_booth_search.html.erb b/app/views/admin/shared/_booth_search.html.erb new file mode 100644 index 000000000..56bae3125 --- /dev/null +++ b/app/views/admin/shared/_booth_search.html.erb @@ -0,0 +1,10 @@ +<%= form_for(Poll::Booth.new, url: url, as: :booth, method: :get) do |f| %> +
+
+ <%= text_field_tag :search, "", placeholder: t("admin.shared.booths_search.placeholder") %> +
+ <%= f.submit t("admin.shared.proposal_search.button"), class: "button" %> +
+
+
+<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8ce3dab12..6529b19bb 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -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 From 54c4a8d34bebe441a12d0b56b361b7844145c2e7 Mon Sep 17 00:00:00 2001 From: DenisNikolski Date: Fri, 13 Sep 2019 11:37:02 +0300 Subject: [PATCH 2/3] fix shifts_spec --- spec/features/admin/poll/shifts_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 8e02ca9b4..f10ce64d5 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -48,6 +48,8 @@ describe "Admin shifts" do click_link "Manage shifts" end + expect(page).to have_content "git 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" From 5627c8ccf46042c4d7c6a2287ba496006e3b73c5 Mon Sep 17 00:00:00 2001 From: DenisNikolski Date: Fri, 13 Sep 2019 23:31:00 +0300 Subject: [PATCH 3/3] add test for booths search --- .../admin/poll/booths_controller.rb | 2 +- app/views/admin/poll/booths/index.html.erb | 4 ++-- app/views/admin/shared/_booth_search.html.erb | 4 ++-- spec/features/admin/poll/booths_spec.rb | 18 ++++++++++++++++++ spec/features/admin/poll/shifts_spec.rb | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/poll/booths_controller.rb b/app/controllers/admin/poll/booths_controller.rb index 7f3ad32aa..c27a65694 100644 --- a/app/controllers/admin/poll/booths_controller.rb +++ b/app/controllers/admin/poll/booths_controller.rb @@ -2,7 +2,7 @@ class Admin::Poll::BoothsController < Admin::Poll::BaseController load_and_authorize_resource class: "Poll::Booth" def index - @booths = @booths.search params[:search].strip if params[:search] + @booths = @booths.search params[:search] if params[:search] @booths = @booths.order(name: :asc).page(params[:page]) end diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index add01ee0d..9a7e38247 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -10,9 +10,9 @@ <% end %> -<% if @booths.any? %> - <%= render "/admin/shared/booth_search", url: admin_booths_path %> +<%= render "/admin/shared/booth_search", url: admin_booths_path %> +<% if @booths.any? %>

<%= page_entries_info @booths %>

diff --git a/app/views/admin/shared/_booth_search.html.erb b/app/views/admin/shared/_booth_search.html.erb index 56bae3125..eb22940db 100644 --- a/app/views/admin/shared/_booth_search.html.erb +++ b/app/views/admin/shared/_booth_search.html.erb @@ -1,9 +1,9 @@ <%= form_for(Poll::Booth.new, url: url, as: :booth, method: :get) do |f| %>
- <%= text_field_tag :search, "", placeholder: t("admin.shared.booths_search.placeholder") %> + <%= text_field_tag :search, params[:search], placeholder: t("admin.shared.booths_search.placeholder") %>
- <%= f.submit t("admin.shared.proposal_search.button"), class: "button" %> + <%= f.submit t("admin.shared.booths_search.button"), class: "button" %>
diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index c49a34b6b..e81f4e539 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -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 diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index f10ce64d5..bbde7be25 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -48,7 +48,7 @@ describe "Admin shifts" do click_link "Manage shifts" end - expect(page).to have_content "git This booth has no shifts" + expect(page).to have_content "This booth has no shifts" fill_in "search", with: officer.email click_button "Search"