Merge pull request #1021 from consul/spending-plus
SpendingProposal index
This commit is contained in:
@@ -2,22 +2,22 @@ class SpendingProposalsController < ApplicationController
|
||||
include FeatureFlags
|
||||
|
||||
before_action :authenticate_user!, except: [:index]
|
||||
before_action -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] }
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] }
|
||||
|
||||
feature_flag :spending_proposals
|
||||
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@spending_proposals = @search_terms.present? ? SpendingProposal.search(@search_terms) : SpendingProposal.all
|
||||
@spending_proposals = search_terms.present? ? SpendingProposal.search(search_terms) : SpendingProposal.all
|
||||
@spending_proposals = @spending_proposals.page(params[:page]).for_render
|
||||
end
|
||||
|
||||
def new
|
||||
@spending_proposal = SpendingProposal.new
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -47,11 +47,14 @@ class SpendingProposalsController < ApplicationController
|
||||
set_spending_proposal_votes(@spending_proposal)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def spending_proposal_params
|
||||
params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key)
|
||||
end
|
||||
|
||||
def search_terms
|
||||
@search_terms ||= params[:search].presence
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ class SpendingProposal < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
include Taggable
|
||||
include Searchable
|
||||
|
||||
apply_simple_captcha
|
||||
acts_as_votable
|
||||
@@ -53,6 +54,18 @@ class SpendingProposal < ActiveRecord::Base
|
||||
results.includes(:geozone, administrator: :user, valuators: :user)
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
author.username => 'B',
|
||||
geozone.try(:name) => 'B',
|
||||
description => 'C'
|
||||
}
|
||||
end
|
||||
|
||||
def self.search(terms)
|
||||
self.pg_search(terms)
|
||||
end
|
||||
|
||||
def self.by_geozone(geozone)
|
||||
if geozone == 'all'
|
||||
where(geozone_id: nil)
|
||||
|
||||
@@ -442,7 +442,7 @@ es:
|
||||
support_title: Apoyar este proyecto
|
||||
supports:
|
||||
one: 1 apoyo
|
||||
other: "%{count} apoyo"
|
||||
other: "%{count} apoyos"
|
||||
zero: Sin apoyos
|
||||
stats:
|
||||
index:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class AddVotesUpToSpendingProposals < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spending_proposals, :cached_votes_up, :integer
|
||||
add_column :spending_proposals, :cached_votes_up, :integer, default: 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddTsvectorToSpendingProposals < ActiveRecord::Migration
|
||||
|
||||
def change
|
||||
add_column :spending_proposals, :tsv, :tsvector
|
||||
add_index :spending_proposals, :tsv, using: "gin"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160329115418) do
|
||||
ActiveRecord::Schema.define(version: 20160329160106) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -313,10 +313,12 @@ ActiveRecord::Schema.define(version: 20160329115418) do
|
||||
t.string "time_scope"
|
||||
t.datetime "unfeasible_email_sent_at"
|
||||
t.integer "cached_votes_up"
|
||||
t.tsvector "tsv"
|
||||
end
|
||||
|
||||
add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree
|
||||
add_index "spending_proposals", ["geozone_id"], name: "index_spending_proposals_on_geozone_id", using: :btree
|
||||
add_index "spending_proposals", ["tsv"], name: "index_spending_proposals_on_tsv", using: :gin
|
||||
|
||||
create_table "taggings", force: :cascade do |t|
|
||||
t.integer "tag_id"
|
||||
|
||||
@@ -10,4 +10,11 @@ namespace :spending_proposals do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Updates all spending proposals to recalculate their tsv column"
|
||||
task touch: :environment do
|
||||
SpendingProposal.find_in_batches do |spending_propsal|
|
||||
spending_propsal.each(&:save)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,6 +18,29 @@ feature 'Spending proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
context("Search") do
|
||||
scenario 'Search by text' do
|
||||
spending_proposal1 = create(:spending_proposal, title: "Get Schwifty")
|
||||
spending_proposal2 = create(:spending_proposal, title: "Schwifty Hello")
|
||||
spending_proposal3 = create(:spending_proposal, title: "Do not show me")
|
||||
|
||||
visit spending_proposals_path
|
||||
|
||||
within(".expanded #search_form") do
|
||||
fill_in "search", with: "Schwifty"
|
||||
click_button "Search"
|
||||
end
|
||||
|
||||
within("#investment-projects") do
|
||||
expect(page).to have_css('.investment-project', count: 2)
|
||||
|
||||
expect(page).to have_content(spending_proposal1.title)
|
||||
expect(page).to have_content(spending_proposal2.title)
|
||||
expect(page).to_not have_content(spending_proposal3.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Create' do
|
||||
login_as(author)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user