Merge pull request #1021 from consul/spending-plus
SpendingProposal index
This commit is contained in:
@@ -2,22 +2,22 @@ class SpendingProposalsController < ApplicationController
|
|||||||
include FeatureFlags
|
include FeatureFlags
|
||||||
|
|
||||||
before_action :authenticate_user!, except: [:index]
|
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
|
load_and_authorize_resource
|
||||||
|
|
||||||
before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] }
|
|
||||||
|
|
||||||
feature_flag :spending_proposals
|
feature_flag :spending_proposals
|
||||||
|
|
||||||
respond_to :html, :js
|
respond_to :html, :js
|
||||||
|
|
||||||
def index
|
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
|
@spending_proposals = @spending_proposals.page(params[:page]).for_render
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@spending_proposal = SpendingProposal.new
|
@spending_proposal = SpendingProposal.new
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@@ -47,11 +47,14 @@ class SpendingProposalsController < ApplicationController
|
|||||||
set_spending_proposal_votes(@spending_proposal)
|
set_spending_proposal_votes(@spending_proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def spending_proposal_params
|
def spending_proposal_params
|
||||||
params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key)
|
params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_terms
|
||||||
|
@search_terms ||= params[:search].presence
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
include Measurable
|
include Measurable
|
||||||
include Sanitizable
|
include Sanitizable
|
||||||
include Taggable
|
include Taggable
|
||||||
|
include Searchable
|
||||||
|
|
||||||
apply_simple_captcha
|
apply_simple_captcha
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
@@ -53,6 +54,18 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
results.includes(:geozone, administrator: :user, valuators: :user)
|
results.includes(:geozone, administrator: :user, valuators: :user)
|
||||||
end
|
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)
|
def self.by_geozone(geozone)
|
||||||
if geozone == 'all'
|
if geozone == 'all'
|
||||||
where(geozone_id: nil)
|
where(geozone_id: nil)
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ es:
|
|||||||
support_title: Apoyar este proyecto
|
support_title: Apoyar este proyecto
|
||||||
supports:
|
supports:
|
||||||
one: 1 apoyo
|
one: 1 apoyo
|
||||||
other: "%{count} apoyo"
|
other: "%{count} apoyos"
|
||||||
zero: Sin apoyos
|
zero: Sin apoyos
|
||||||
stats:
|
stats:
|
||||||
index:
|
index:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class AddVotesUpToSpendingProposals < ActiveRecord::Migration
|
class AddVotesUpToSpendingProposals < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :spending_proposals, :cached_votes_up, :integer
|
add_column :spending_proposals, :cached_votes_up, :integer, default: 0
|
||||||
end
|
end
|
||||||
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.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -313,10 +313,12 @@ ActiveRecord::Schema.define(version: 20160329115418) do
|
|||||||
t.string "time_scope"
|
t.string "time_scope"
|
||||||
t.datetime "unfeasible_email_sent_at"
|
t.datetime "unfeasible_email_sent_at"
|
||||||
t.integer "cached_votes_up"
|
t.integer "cached_votes_up"
|
||||||
|
t.tsvector "tsv"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree
|
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", ["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|
|
create_table "taggings", force: :cascade do |t|
|
||||||
t.integer "tag_id"
|
t.integer "tag_id"
|
||||||
|
|||||||
@@ -10,4 +10,11 @@ namespace :spending_proposals do
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
@@ -18,6 +18,29 @@ feature 'Spending proposals' do
|
|||||||
end
|
end
|
||||||
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
|
scenario 'Create' do
|
||||||
login_as(author)
|
login_as(author)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user