Add search form to proposals admin index

This commit is contained in:
Javi Martín
2018-11-15 13:57:10 +01:00
parent 4770217373
commit d3f11c3b55
3 changed files with 26 additions and 8 deletions

View File

@@ -1,12 +1,18 @@
class Admin::ProposalsController < Admin::BaseController class Admin::ProposalsController < Admin::BaseController
include HasOrders
include CommentableActions
include FeatureFlags include FeatureFlags
feature_flag :proposals feature_flag :proposals
def index has_orders %w[created_at]
@proposals = Proposal.sort_by_created_at.page(params[:page])
end
def show def show
@proposal = Proposal.find(params[:id]) @proposal = Proposal.find(params[:id])
end end
private
def resource_model
Proposal
end
end end

View File

@@ -5,6 +5,8 @@
<h2><%= t("admin.proposals.index.title") %></h2> <h2><%= t("admin.proposals.index.title") %></h2>
<% if @proposals.any? %> <% if @proposals.any? %>
<%= render "/admin/shared/proposal_search", url: admin_proposals_path %>
<h3><%= page_entries_info @proposals %></h3> <h3><%= page_entries_info @proposals %></h3>
<table> <table>

View File

@@ -5,12 +5,22 @@ feature "Admin proposals" do
login_as create(:administrator).user login_as create(:administrator).user
end end
scenario "Index" do context "Index" do
scenario "Search" do
create(:proposal, title: "Make Pluto a planet again") create(:proposal, title: "Make Pluto a planet again")
create(:proposal, title: "Build a monument to honour CONSUL developers")
visit admin_root_path visit admin_root_path
within("#side_menu") { click_link "Proposals" } within("#side_menu") { click_link "Proposals" }
expect(page).to have_content "Make Pluto a planet again" expect(page).to have_content "Make Pluto a planet again"
expect(page).to have_content "Build a monument"
fill_in "search", with: "Pluto"
click_button "Search"
expect(page).to have_content "Make Pluto a planet again"
expect(page).not_to have_content "Build a monument"
end
end end
end end