Merge branch 'budgets' of github.com:consul/consul into budgets

This commit is contained in:
Alberto Garcia Cabeza
2017-01-09 17:10:46 +01:00
31 changed files with 949 additions and 286 deletions

View File

@@ -11,8 +11,6 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
before_action :load_ballot, only: [:show, :index]
before_action :load_investments, only: [:index, :toggle_selection]
def index
end
@@ -26,6 +24,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end
def update
set_valuation_tags
if @investment.update(budget_investment_params)
redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)),
notice: t("flash.actions.update.budget_investment")
@@ -52,7 +51,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
def budget_investment_params
params.require(:budget_investment)
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: [])
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, valuator_ids: [])
end
def load_budget
@@ -72,11 +71,16 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end
def load_tags
@tags = ActsAsTaggableOn::Tag.budget_investment_tags
@tags = Budget::Investment.tags_on(:valuation).order(:name).uniq
end
def load_ballot
query = Budget::Ballot.where(user: current_user, budget: @budget)
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
end
def set_valuation_tags
@investment.set_tag_list_on(:valuation, budget_investment_params[:valuation_tag_list])
params[:budget_investment] = params[:budget_investment].except(:valuation_tag_list)
end
end

View File

@@ -13,6 +13,7 @@ module Budgets
before_action :load_ballot, only: [:index, :show]
before_action :load_heading, only: [:index, :show]
before_action :set_random_seed, only: :index
before_action :load_categories, only: [:index, :new, :create]
feature_flag :budgets
@@ -27,6 +28,7 @@ module Budgets
@investments = @investments.apply_filters_and_search(@budget, params).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
@investment_ids = @investments.pluck(:id)
load_investment_votes(@investments)
@tag_cloud = tag_cloud
end
def new
@@ -50,6 +52,7 @@ module Budgets
flash: { html_safe: true },
notice: t('flash.actions.create.budget_investment', activity: activity_link)
else
render :new
end
end
@@ -80,7 +83,7 @@ module Budgets
end
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :terms_of_service, :location, :organization_name)
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, :organization_name, :location, :terms_of_service)
end
def load_ballot
@@ -95,6 +98,13 @@ module Budgets
end
end
def load_categories
@categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name)
end
def tag_cloud
TagCloud.new(Budget::Investment, params[:search])
end
end
end

View File

@@ -12,6 +12,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end
def new
load_categories
end
def create
@@ -58,4 +59,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
@heading = @budget.headings.find(params[:heading_id]) if params[:heading_id].present?
end
def load_categories
@categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name)
end
end

View File

@@ -6,6 +6,8 @@ module TagsHelper
debates_path(search: tag_name)
when 'proposal'
proposals_path(search: tag_name)
when 'budget/investment'
budget_investments_path(@budget, search: tag_name)
else
'#'
end

View File

@@ -8,10 +8,10 @@ class Budget
validates :name, presence: true
validates :price, presence: true
scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
delegate :budget, :budget_id, to: :group, allow_nil: true
scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
def name_scoped_by_group
"#{group.name}: #{name}"
end

View File

@@ -46,6 +46,7 @@ class Budget
scope :undecided, -> { where(feasibility: "undecided") }
scope :with_supports, -> { where('cached_votes_up > 0') }
scope :selected, -> { where(selected: true) }
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
scope :by_group, -> (group_id) { where(group_id: group_id) }
scope :by_heading, -> (heading_id) { where(heading_id: heading_id) }
@@ -106,6 +107,7 @@ class Budget
{ title => 'A',
author.username => 'B',
heading.try(:name) => 'B',
tag_list.join(' ') => 'B',
description => 'C'
}
end

View File

@@ -32,7 +32,7 @@ class TagCloud
end
def table_name
resource_model.to_s.downcase.pluralize
resource_model.to_s.downcase.pluralize.gsub("::", "/")
end
end

View File

@@ -45,7 +45,8 @@
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
</div>
<%= f.text_field :tag_list, value: @investment.tag_list.to_s,
<%= f.text_field :valuation_tag_list,
value: @investment.tag_list_on(:valuation).sort.join(','),
label: false,
placeholder: t("admin.budget_investments.edit.tags_placeholder"),
class: 'js-tag-list' %>

View File

@@ -19,7 +19,7 @@
<p id="tags">
<strong><%= t("admin.budget_investments.show.tags") %>:</strong>
<%= @investment.tags.pluck(:name).join(', ') %>
<%= @investment.tags_on(:valuation).pluck(:name).join(', ') %>
</p>
<p id="assigned_valuators">

View File

@@ -0,0 +1,11 @@
<div class="sidebar-divider"></div>
<h2 class="sidebar-title"><%= t("shared.tags_cloud.categories") %></h2>
<br>
<ul id="categories" class="no-bullet categories">
<% @categories.each do |category| %>
<li class="inline-block">
<%= link_to category.name,
budget_investments_path(@budget, search: category.name) %></li>
<% end %>
</ul>

View File

@@ -28,6 +28,25 @@
<%= f.text_field :organization_name %>
</div>
<div class="small-12 column">
<%= f.label :tag_list, t("budgets.investments.form.tags_label") %>
<p class="note"><%= t("budgets.investments.form.tags_instructions") %></p>
<div id="category_tags" class="tags">
<%= f.label :category_tag_list, t("budgets.investments.form.tag_category_label") %>
<% @categories.each do |tag| %>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
</div>
<br>
<%= f.text_field :tag_list, value: @investment.tag_list.to_s,
label: false,
placeholder: t("budgets.investments.form.tags_placeholder"),
class: 'js-tag-list' %>
</div>
<% unless current_user.manager? %>
<div class="small-12 column">

View File

@@ -38,6 +38,7 @@
<p><%= investment.description %></p>
<div class="truncate"></div>
</div>
<%= render "shared/tags", taggable: investment, limit: 5 %>
<% end %>
</div>
</div>

View File

@@ -35,6 +35,8 @@
</p>
<% end %>
<%= render 'shared/tags', taggable: @investment %>
<%= safe_html_with_links investment.description.html_safe %>
<% if investment.external_url.present? %>

View File

@@ -11,6 +11,11 @@
<% end %>
<% end %>
<% if @budget.accepting? %>
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
<%= render 'categories' %>
<% end %>
<% if @heading && can?(:show, @ballot) %>

View File

@@ -3,7 +3,10 @@
<% if taggable.tags.any? %>
<ul id="tags_<%= dom_id(taggable) %>" class="no-bullet tags">
<% taggable.tag_list_with_limit(limit).each do |tag| %>
<li class="inline-block"><%= link_to sanitize(tag.name), send("#{taggable.class.name.underscore.pluralize}_path", search: tag.name) %></li>
<li class="inline-block">
<%= link_to sanitize(tag.name),
taggable_path(taggable.class.name.underscore, tag.name),
search: tag.name %></li>
<% end %>
<% if taggable.tags_count_out_of_limit(limit) > 0 %>

View File

@@ -42,10 +42,6 @@ module ActsAsTaggableOn
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).order(:name).uniq
end
def self.budget_investment_tags
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'Budget::Investment').includes(:taggings).order(:name).uniq
end
private
def custom_counter_field_name_for(taggable_type)
"#{taggable_type.underscore.pluralize}_count"

View File

@@ -53,6 +53,11 @@ en:
phase: "Phase"
currency_symbol: "Currency"
budget/investment:
heading_id: "Sección de presupuesto"
title: "Title"
description: "Description"
external_url: "External url"
location: "Location"
administrator_id: "Administrator"
description: "Description"
external_url: "Link to additional documentation"
@@ -116,6 +121,10 @@ en:
attributes:
tag_list:
less_than_or_equal_to: "tags must be less than or equal to %{count}"
budget/investment:
attributes:
tag_list:
less_than_or_equal_to: "tags must be less than or equal to %{count}"
proposal_notification:
attributes:
minimum_interval:

View File

@@ -33,6 +33,11 @@ en:
index:
title: Participatory budgets
investments:
form:
tag_category_label: "Categories"
tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
tags_label: Tags
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
index:
title: Participatory budgeting
unfeasible: Unfeasible investment projects

View File

@@ -33,6 +33,11 @@ es:
index:
title: Presupuestos participativos
investments:
form:
tags_instructions: "Etiqueta esta propuesta. Puedes elegir entre las categorías propuestas o introducir las que desees"
tags_label: Temas
tag_category_label: "Categorías"
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
index:
title: Presupuestos participativos
unfeasible: Propuestas de inversión no viables

View File

@@ -152,6 +152,7 @@ en:
proposal: Proposal
proposal_notification: "Notification"
spending_proposal: Spending proposal
budget/investment: Investment
user: Account
verification/sms: phone
signature_sheet: Signature sheet

View File

@@ -152,6 +152,7 @@ es:
proposal: la propuesta
proposal_notification: "la notificación"
spending_proposal: la propuesta de gasto
budget/investment: la propuesta de inversión
user: la cuenta
verification/sms: el teléfono
signature_sheet: la hoja de firmas

View File

@@ -343,12 +343,14 @@ feature 'Admin budget investments' do
end
end
scenario "Adds existing tags", :js do
create(:budget_investment, tag_list: 'Education, Health')
scenario "Adds existing valuation tags", :js do
budget_investment1 = create(:budget_investment)
budget_investment1.set_tag_list_on(:valuation, 'Education, Health')
budget_investment1.save
budget_investment = create(:budget_investment)
budget_investment2 = create(:budget_investment)
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
visit admin_budget_budget_investment_path(budget_investment2.budget, budget_investment2)
click_link 'Edit classification'
find('.js-add-tag-link', text: 'Education').click
@@ -365,13 +367,13 @@ feature 'Admin budget investments' do
end
end
scenario "Adds non existent tags" do
scenario "Adds non existent valuation tags" do
budget_investment = create(:budget_investment)
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link 'Edit classification'
fill_in 'budget_investment_tag_list', with: 'Refugees, Solidarity'
fill_in 'budget_investment_valuation_tag_list', with: 'Refugees, Solidarity'
click_button 'Update'
expect(page).to have_content 'Investment project updated succesfully.'
@@ -382,6 +384,39 @@ feature 'Admin budget investments' do
end
end
scenario "Only displays valuation tags" do
budget_investment = create(:budget_investment, tag_list: 'Park')
budget_investment.set_tag_list_on(:valuation, 'Education')
budget_investment.save
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
expect(page).to have_content "Education"
expect(page).to_not have_content "Park"
click_link 'Edit classification'
expect(page).to have_content "Education"
expect(page).to_not have_content "Park"
end
scenario "Maintains user tags" do
budget_investment = create(:budget_investment, tag_list: 'Park')
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link 'Edit classification'
fill_in 'budget_investment_valuation_tag_list', with: 'Refugees, Solidarity'
click_button 'Update'
expect(page).to have_content 'Investment project updated succesfully.'
visit budget_investment_path(budget_investment.budget, budget_investment)
expect(page).to have_content "Park"
expect(page).to_not have_content "Refugees, Solidarity"
end
scenario "Errors on update" do
budget_investment = create(:budget_investment)

View File

@@ -594,8 +594,4 @@ feature 'Ballots' do
end
end
end
end
end

View File

@@ -24,6 +24,7 @@ feature 'Budget Investments' do
end
context("Search") do
scenario 'Search by text' do
investment1 = create(:budget_investment, heading: heading, title: "Get Schwifty")
investment2 = create(:budget_investment, heading: heading, title: "Schwifty Hello")
@@ -44,9 +45,11 @@ feature 'Budget Investments' do
expect(page).to_not have_content(investment3.title)
end
end
end
context("Filters") do
scenario 'by unfeasibility' do
investment1 = create(:budget_investment, :unfeasible, heading: heading, valuation_finished: true)
investment2 = create(:budget_investment, :feasible, heading: heading)
@@ -426,5 +429,4 @@ feature 'Budget Investments' do
end
end
end
end

View File

@@ -210,70 +210,7 @@ feature 'Debates' do
expect(page.html).to_not include "<script>alert('hey')</script>"
end
context 'Tagging debates' do
let(:author) { create(:user) }
background do
login_as(author)
end
pending 'Category tags', :js do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
visit new_debate_path
fill_in 'debate_title', with: 'Testing auto link'
fill_in 'debate_description', with: "<script>alert('hey')</script> <a href=\"javascript:alert('surprise!')\">click me<a/> http://example.org"
check 'debate_terms_of_service'
find('.js-add-tag-link', text: 'Education').click
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
within "#tags_debate_#{Debate.last.id}" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario 'Custom tags' do
visit new_debate_path
fill_in 'debate_title', with: "Great title"
fill_in 'debate_description', with: 'Very important issue...'
check 'debate_terms_of_service'
fill_in 'debate_tag_list', with: 'Refugees, Solidarity'
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
within "#tags_debate_#{Debate.last.id}" do
expect(page).to have_content 'Refugees'
expect(page).to have_content 'Solidarity'
end
end
scenario 'using dangerous strings' do
visit new_debate_path
fill_in 'debate_title', with: 'A test of dangerous strings'
fill_in 'debate_description', with: 'A description suitable for this test'
check 'debate_terms_of_service'
fill_in 'debate_tag_list', with: 'user_id=1, &a=3, <script>alert("hey");</script>'
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
expect(page).to have_content 'user_id1'
expect(page).to have_content 'a3'
expect(page).to have_content 'scriptalert("hey");script'
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
end
end
scenario 'Update should not be posible if logged user is not the author' do
debate = create(:debate)
@@ -329,33 +266,6 @@ feature 'Debates' do
expect(page).to have_content error_message
end
describe 'Limiting tags shown' do
scenario 'Index page shows up to 5 tags per debate' do
tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
create :debate, tag_list: tag_list
visit debates_path
within('.debate .tags') do
expect(page).to have_content '1+'
end
end
scenario 'Index page shows 3 tags with no plus link' do
tag_list = ["Medio Ambiente", "Corrupción", "Fiestas populares"]
create :debate, tag_list: tag_list
visit debates_path
within('.debate .tags') do
tag_list.each do |tag|
expect(page).to have_content tag
end
expect(page).not_to have_content '+'
end
end
end
scenario "Flagging", :js do
user = create(:user)
debate = create(:debate)
@@ -843,16 +753,6 @@ feature 'Debates' do
end
scenario 'Index tag does not show featured debates' do
featured_debates = create_featured_debates
debates = create(:debate, tag_list: "123")
visit debates_path(tag: "123")
expect(page).to_not have_selector('#debates .debate-featured')
expect(page).to_not have_selector('#featured-debates')
end
scenario 'Conflictive' do
good_debate = create(:debate)
conflictive_debate = create(:debate, :conflictive)
@@ -878,25 +778,6 @@ feature 'Debates' do
context "Filter" do
pending "By category" do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
debate1 = create(:debate, tag_list: education.name)
debate2 = create(:debate, tag_list: health.name)
visit debates_path
within "#categories" do
click_link "Education"
end
within("#debates") do
expect(page).to have_css('.debate', count: 1)
expect(page).to have_content(debate1.title)
end
end
context "By geozone" do
background do

View File

@@ -132,6 +132,7 @@ feature 'Proposals' do
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_tag_list', with: 'Refugees, Solidarity'
check 'proposal_terms_of_service'
click_button 'Create proposal'
@@ -144,6 +145,8 @@ feature 'Proposals' do
expect(page).to have_content 'http://rescue.org/refugees'
expect(page).to have_content 'http://youtube.com'
expect(page).to have_content author.name
expect(page).to have_content 'Refugees'
expect(page).to have_content 'Solidarity'
expect(page).to have_content I18n.l(Proposal.last.created_at.to_date)
end
@@ -306,87 +309,6 @@ feature 'Proposals' do
expect(page.html).to_not include "<script>alert('hey')</script>"
end
context 'Tagging' do
let(:author) { create(:user) }
background do
login_as(author)
end
scenario 'Category tags', :js do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in_ckeditor 'proposal_description', with: 'A description with enough characters'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
check 'proposal_terms_of_service'
find('.js-add-tag-link', text: 'Education').click
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
within "#tags_proposal_#{Proposal.last.id}" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario 'Custom tags' do
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'This is very important because...'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
check 'proposal_terms_of_service'
fill_in 'proposal_tag_list', with: 'Refugees, Solidarity'
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
within "#tags_proposal_#{Proposal.last.id}" do
expect(page).to have_content 'Refugees'
expect(page).to have_content 'Solidarity'
end
end
scenario 'using dangerous strings' do
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in 'proposal_title', with: 'A test of dangerous strings'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'A description suitable for this test'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
check 'proposal_terms_of_service'
fill_in 'proposal_tag_list', with: 'user_id=1, &a=3, <script>alert("hey");</script>'
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
expect(page).to have_content 'user_id1'
expect(page).to have_content 'a3'
expect(page).to have_content 'scriptalert("hey");script'
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
end
end
context 'Geozones' do
scenario "Default whole city" do
@@ -593,35 +515,6 @@ feature 'Proposals' do
expect(page).to have_content error_message
end
describe 'Limiting tags shown' do
scenario 'Index page shows up to 5 tags per proposal' do
create_featured_proposals
tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
create :proposal, tag_list: tag_list
visit proposals_path
within('.proposal .tags') do
expect(page).to have_content '1+'
end
end
scenario 'Index page shows 3 tags with no plus link' do
create_featured_proposals
tag_list = ["Medio Ambiente", "Corrupción", "Fiestas populares"]
create :proposal, tag_list: tag_list
visit proposals_path
within('.proposal .tags') do
tag_list.each do |tag|
expect(page).to have_content tag
end
expect(page).not_to have_content '+'
end
end
end
feature 'Proposal index order filters' do
scenario 'Default order is hot_score', :js do
@@ -1205,16 +1098,6 @@ feature 'Proposals' do
end
scenario 'Index tag does not show featured proposals' do
featured_proposals = create_featured_proposals
proposal = create(:proposal, tag_list: "123")
visit proposals_path(tag: "123")
expect(page).to_not have_selector('#proposals .proposal-featured')
expect(page).to_not have_selector('#featured-proposals')
end
scenario 'Conflictive' do
good_proposal = create(:proposal)
conflictive_proposal = create(:proposal, :conflictive)
@@ -1280,25 +1163,6 @@ feature 'Proposals' do
context "Filter" do
scenario "By category" do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
proposal1 = create(:proposal, tag_list: education.name)
proposal2 = create(:proposal, tag_list: health.name)
visit proposals_path
within "#categories" do
click_link "Education"
end
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(proposal1.title)
end
end
context "By geozone" do
background do

View File

@@ -0,0 +1,265 @@
require 'rails_helper'
feature 'Tags' do
let(:author) { create(:user, :level_two, username: 'Isabel') }
let(:budget) { create(:budget, name: "Big Budget") }
let(:group) { create(:budget_group, name: "Health", budget: budget) }
let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) }
scenario 'Index' do
earth = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
money = create(:budget_investment, heading: heading, tag_list: 'Economía')
visit budget_investments_path(budget, heading_id: heading.id)
within "#budget_investment_#{earth.id}" do
expect(page).to have_content "Medio Ambiente"
end
within "#budget_investment_#{money.id}" do
expect(page).to have_content "Economía"
end
end
scenario 'Index shows 3 tags with no plus link' do
tag_list = ["Medio Ambiente", "Corrupción", "Fiestas populares"]
create :budget_investment, heading: heading, tag_list: tag_list
visit budget_investments_path(budget, heading_id: heading.id)
within('.budget-investment .tags') do
tag_list.each do |tag|
expect(page).to have_content tag
end
expect(page).not_to have_content '+'
end
end
scenario 'Show' do
investment = create(:budget_investment, heading: heading, tag_list: 'Hacienda, Economía')
visit budget_investment_path(budget, investment)
expect(page).to have_content "Economía"
expect(page).to have_content "Hacienda"
end
scenario 'Create with custom tags' do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select 'Health: More hospitals', from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
check 'budget_investment_terms_of_service'
fill_in 'budget_investment_tag_list', with: 'Economía, Hacienda'
click_button 'Create Investment'
expect(page).to have_content 'Investment created successfully.'
expect(page).to have_content 'Economía'
expect(page).to have_content 'Hacienda'
end
scenario 'Category with category tags', :js do
login_as(author)
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
visit new_budget_investment_path(budget_id: budget.id)
select 'Health: More hospitals', from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in_ckeditor 'budget_investment_description', with: 'If I had a gym near my place I could go do Zumba'
check 'budget_investment_terms_of_service'
find('.js-add-tag-link', text: 'Education').click
click_button 'Create Investment'
expect(page).to have_content 'Investment created successfully.'
within "#tags_budget_investment_#{Budget::Investment.last.id}" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario 'Create with too many tags' do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select 'Health: More hospitals', from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
check 'budget_investment_terms_of_service'
fill_in 'budget_investment_tag_list', with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"
click_button 'Create Investment'
expect(page).to have_content error_message
expect(page).to have_content 'tags must be less than or equal to 6'
end
scenario 'Create with dangerous strings' do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select 'Health: More hospitals', from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
check 'budget_investment_terms_of_service'
fill_in 'budget_investment_tag_list', with: 'user_id=1, &a=3, <script>alert("hey");</script>'
click_button 'Create Investment'
expect(page).to have_content 'Investment created successfully.'
expect(page).to have_content 'user_id1'
expect(page).to have_content 'a3'
expect(page).to have_content 'scriptalert("hey");script'
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
end
context "Filter" do
scenario "From index" do
investment1 = create(:budget_investment, heading: heading, tag_list: 'Education')
investment2 = create(:budget_investment, heading: heading, tag_list: 'Health')
visit budget_investments_path(budget, heading_id: heading.id)
within "#budget_investment_#{investment1.id}" do
click_link "Education"
end
within("#budget-investments") do
expect(page).to have_css('.budget-investment', count: 1)
expect(page).to have_content(investment1.title)
end
end
scenario "From show" do
investment1 = create(:budget_investment, heading: heading, tag_list: 'Education')
investment2 = create(:budget_investment, heading: heading, tag_list: 'Health')
visit budget_investment_path(budget, investment1)
click_link "Education"
within("#budget-investments") do
expect(page).to have_css('.budget-investment', count: 1)
expect(page).to have_content(investment1.title)
end
end
end
context 'Tag cloud' do
scenario 'Display user tags' do
earth = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
money = create(:budget_investment, heading: heading, tag_list: 'Economía')
visit budget_investments_path(budget, heading_id: heading.id)
within "#tag-cloud" do
expect(page).to have_content "Medio Ambiente"
expect(page).to have_content "Economía"
end
end
scenario "Filter by user tags" do
investment1 = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
investment2 = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
investment3 = create(:budget_investment, heading: heading, tag_list: 'Economía')
visit budget_investments_path(budget, heading_id: heading.id)
within "#tag-cloud" do
click_link "Medio Ambiente"
end
expect(page).to have_css ".budget-investment", count: 2
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
expect(page).to_not have_content investment3.title
end
end
context "Categories" do
scenario 'Display category tags' do
create(:tag, kind: 'category', name: 'Medio Ambiente')
create(:tag, kind: 'category', name: 'Economía')
earth = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
money = create(:budget_investment, heading: heading, tag_list: 'Economía')
visit budget_investments_path(budget, heading_id: heading.id)
within "#categories" do
expect(page).to have_content "Medio Ambiente"
expect(page).to have_content "Economía"
end
end
scenario "Filter by category tags" do
create(:tag, kind: 'category', name: 'Medio Ambiente')
create(:tag, kind: 'category', name: 'Economía')
investment1 = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
investment2 = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente')
investment3 = create(:budget_investment, heading: heading, tag_list: 'Economía')
visit budget_investments_path(budget, heading_id: heading.id, search: 'Economía')
within "#categories" do
click_link "Medio Ambiente"
end
expect(page).to have_css ".budget-investment", count: 2
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
expect(page).to_not have_content investment3.title
end
end
context "Valuation" do
scenario "Users do not see valuator tags" do
investment = create(:budget_investment, heading: heading, tag_list: 'Park')
investment.set_tag_list_on(:valuation, 'Education')
investment.save
visit budget_investment_path(budget, investment)
expect(page).to have_content 'Park'
expect(page).to_not have_content 'Education'
end
scenario "Valuators do not see user tags" do
investment = create(:budget_investment, heading: heading, tag_list: 'Park')
investment.set_tag_list_on(:valuation, 'Education')
investment.save
admin = create(:administrator)
login_as(admin.user)
visit admin_budget_budget_investment_path(budget, investment)
click_link 'Edit classification'
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Park'
end
end
end

View File

@@ -0,0 +1,218 @@
require 'rails_helper'
feature 'Tags' do
scenario 'Index' do
earth = create(:debate, tag_list: 'Medio Ambiente')
money = create(:debate, tag_list: 'Economía')
visit debates_path
within "#debate_#{earth.id}" do
expect(page).to have_content "Medio Ambiente"
end
within "#debate_#{money.id}" do
expect(page).to have_content "Economía"
end
end
scenario 'Index shows up to 5 tags per proposal' do
tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
create :debate, tag_list: tag_list
visit debates_path
within('.debate .tags') do
expect(page).to have_content '1+'
end
end
scenario 'Index shows 3 tags with no plus link' do
tag_list = ["Medio Ambiente", "Corrupción", "Fiestas populares"]
create :debate, tag_list: tag_list
visit debates_path
within('.debate .tags') do
tag_list.each do |tag|
expect(page).to have_content tag
end
expect(page).not_to have_content '+'
end
end
scenario 'Index tag does not show featured debates' do
featured_debates = create_featured_debates
debates = create(:debate, tag_list: "123")
visit debates_path(tag: "123")
expect(page).to_not have_selector('#debates .debate-featured')
expect(page).to_not have_selector('#featured-debates')
end
scenario 'Show' do
debate = create(:debate, tag_list: 'Hacienda, Economía')
visit debate_path(debate)
expect(page).to have_content "Economía"
expect(page).to have_content "Hacienda"
end
scenario 'Create' do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in 'debate_title', with: 'Title'
fill_in 'debate_description', with: 'Description'
check 'debate_terms_of_service'
fill_in 'debate_tag_list', with: "Impuestos, Economía, Hacienda"
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
expect(page).to have_content 'Economía'
expect(page).to have_content 'Hacienda'
expect(page).to have_content 'Impuestos'
end
scenario 'Create with too many tags' do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in 'debate_title', with: 'Title'
fill_in 'debate_description', with: 'Description'
check 'debate_terms_of_service'
fill_in 'debate_tag_list', with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"
click_button 'Start a debate'
expect(page).to have_content error_message
expect(page).to have_content 'tags must be less than or equal to 6'
end
scenario 'Create with dangerous strings' do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in 'debate_title', with: 'A test of dangerous strings'
fill_in 'debate_description', with: 'A description suitable for this test'
check 'debate_terms_of_service'
fill_in 'debate_tag_list', with: 'user_id=1, &a=3, <script>alert("hey");</script>'
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
expect(page).to have_content 'user_id1'
expect(page).to have_content 'a3'
expect(page).to have_content 'scriptalert("hey");script'
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
end
scenario 'Update' do
debate = create(:debate, tag_list: 'Economía')
login_as(debate.author)
visit edit_debate_path(debate)
expect(page).to have_selector("input[value='Economía']")
fill_in 'debate_tag_list', with: "Economía, Hacienda"
click_button 'Save changes'
expect(page).to have_content 'Debate updated successfully.'
within('.tags') do
expect(page).to have_css('a', text: 'Economía')
expect(page).to have_css('a', text: 'Hacienda')
end
end
scenario 'Delete' do
debate = create(:debate, tag_list: 'Economía')
login_as(debate.author)
visit edit_debate_path(debate)
fill_in 'debate_tag_list', with: ""
click_button 'Save changes'
expect(page).to have_content 'Debate updated successfully.'
expect(page).to_not have_content 'Economía'
end
context "Filter" do
scenario "From index" do
debate1 = create(:debate, tag_list: 'Education')
debate2 = create(:debate, tag_list: 'Health')
visit debates_path
within "#debate_#{debate1.id}" do
click_link "Education"
end
within("#debates") do
expect(page).to have_css('.debate', count: 1)
expect(page).to have_content(debate1.title)
end
end
scenario "From show" do
debate1 = create(:debate, tag_list: 'Education')
debate2 = create(:debate, tag_list: 'Health')
visit debate_path(debate1)
click_link "Education"
within("#debates") do
expect(page).to have_css('.debate', count: 1)
expect(page).to have_content(debate1.title)
end
end
end
context 'Tag cloud' do
scenario 'Display user tags' do
earth = create(:debate, tag_list: 'Medio Ambiente')
money = create(:debate, tag_list: 'Economía')
visit debates_path
within "#tag-cloud" do
expect(page).to have_content "Medio Ambiente"
expect(page).to have_content "Economía"
end
end
scenario "Filter by user tags" do
debate1 = create(:debate, tag_list: 'Medio Ambiente')
debate2 = create(:debate, tag_list: 'Medio Ambiente')
debate3 = create(:debate, tag_list: 'Economía')
visit debates_path
within "#tag-cloud" do
click_link "Medio Ambiente"
end
expect(page).to have_css ".debate", count: 2
expect(page).to have_content debate1.title
expect(page).to have_content debate2.title
expect(page).to_not have_content debate3.title
end
end
end

View File

@@ -0,0 +1,294 @@
require 'rails_helper'
feature 'Tags' do
scenario 'Index' do
create_featured_proposals
earth = create(:proposal, tag_list: 'Medio Ambiente')
money = create(:proposal, tag_list: 'Economía')
visit proposals_path
within "#proposal_#{earth.id}" do
expect(page).to have_content "Medio Ambiente"
end
within "#proposal_#{money.id}" do
expect(page).to have_content "Economía"
end
end
scenario 'Index shows up to 5 tags per proposal' do
create_featured_proposals
tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
create :proposal, tag_list: tag_list
visit proposals_path
within('.proposal .tags') do
expect(page).to have_content '1+'
end
end
scenario 'Index featured proposals does not show tags' do
featured_proposals = create_featured_proposals
proposal = create(:proposal, tag_list: "123")
visit proposals_path(tag: "123")
expect(page).to_not have_selector('#proposals .proposal-featured')
expect(page).to_not have_selector('#featured-proposals')
end
scenario 'Index shows 3 tags with no plus link' do
create_featured_proposals
tag_list = ["Medio Ambiente", "Corrupción", "Fiestas populares"]
create :proposal, tag_list: tag_list
visit proposals_path
within('.proposal .tags') do
tag_list.each do |tag|
expect(page).to have_content tag
end
expect(page).not_to have_content '+'
end
end
scenario 'Show' do
proposal = create(:proposal, tag_list: 'Hacienda, Economía')
visit proposal_path(proposal)
expect(page).to have_content "Economía"
expect(page).to have_content "Hacienda"
end
scenario 'Create with custom tags' do
user = create(:user)
login_as(user)
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'This is very important because...'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_tag_list', with: 'Economía, Hacienda'
check 'proposal_terms_of_service'
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
expect(page).to have_content 'Economía'
expect(page).to have_content 'Hacienda'
end
scenario 'Category with category tags', :js do
user = create(:user)
login_as(user)
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in_ckeditor 'proposal_description', with: 'A description with enough characters'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
check 'proposal_terms_of_service'
find('.js-add-tag-link', text: 'Education').click
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
within "#tags_proposal_#{Proposal.last.id}" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario 'Create with too many tags' do
user = create(:user)
login_as(user)
visit new_proposal_path
fill_in 'proposal_title', with: 'Title'
fill_in 'proposal_description', with: 'Description'
check 'proposal_terms_of_service'
fill_in 'proposal_tag_list', with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"
click_button 'Create proposal'
expect(page).to have_content error_message
expect(page).to have_content 'tags must be less than or equal to 6'
end
scenario 'Create with dangerous strings' do
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in 'proposal_title', with: 'A test of dangerous strings'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'A description suitable for this test'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
check 'proposal_terms_of_service'
fill_in 'proposal_tag_list', with: 'user_id=1, &a=3, <script>alert("hey");</script>'
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
expect(page).to have_content 'user_id1'
expect(page).to have_content 'a3'
expect(page).to have_content 'scriptalert("hey");script'
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
end
scenario 'Update' do
proposal = create(:proposal, tag_list: 'Economía')
login_as(proposal.author)
visit edit_proposal_path(proposal)
expect(page).to have_selector("input[value='Economía']")
fill_in 'proposal_tag_list', with: "Economía, Hacienda"
click_button 'Save changes'
expect(page).to have_content 'Proposal updated successfully.'
within('.tags') do
expect(page).to have_css('a', text: 'Economía')
expect(page).to have_css('a', text: 'Hacienda')
end
end
scenario 'Delete' do
proposal = create(:proposal, tag_list: 'Economía')
login_as(proposal.author)
visit edit_proposal_path(proposal)
fill_in 'proposal_tag_list', with: ""
click_button 'Save changes'
expect(page).to have_content 'Proposal updated successfully.'
expect(page).to_not have_content 'Economía'
end
context "Filter" do
scenario "From index" do
create_featured_proposals
proposal1 = create(:proposal, tag_list: 'Education')
proposal2 = create(:proposal, tag_list: 'Health')
visit proposals_path
within "#proposal_#{proposal1.id}" do
click_link "Education"
end
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(proposal1.title)
end
end
scenario "From show" do
proposal1 = create(:proposal, tag_list: 'Education')
proposal2 = create(:proposal, tag_list: 'Health')
visit proposal_path(proposal1)
click_link "Education"
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(proposal1.title)
end
end
end
context 'Tag cloud' do
scenario 'Display user tags' do
earth = create(:proposal, tag_list: 'Medio Ambiente')
money = create(:proposal, tag_list: 'Economía')
visit proposals_path
within "#tag-cloud" do
expect(page).to have_content "Medio Ambiente"
expect(page).to have_content "Economía"
end
end
scenario "Filter by user tags" do
proposal1 = create(:proposal, tag_list: 'Medio Ambiente')
proposal2 = create(:proposal, tag_list: 'Medio Ambiente')
proposal3 = create(:proposal, tag_list: 'Economía')
visit proposals_path
within "#tag-cloud" do
click_link "Medio Ambiente"
end
expect(page).to have_css ".proposal", count: 2
expect(page).to have_content proposal1.title
expect(page).to have_content proposal2.title
expect(page).to_not have_content proposal3.title
end
end
context "Categories" do
scenario 'Display category tags' do
create(:tag, kind: 'category', name: 'Medio Ambiente')
create(:tag, kind: 'category', name: 'Economía')
earth = create(:proposal, tag_list: 'Medio Ambiente')
money = create(:proposal, tag_list: 'Economía')
visit proposals_path
within "#categories" do
expect(page).to have_content "Medio Ambiente"
expect(page).to have_content "Economía"
end
end
scenario "Filter by category tags" do
create(:tag, kind: 'category', name: 'Medio Ambiente')
create(:tag, kind: 'category', name: 'Economía')
proposal1 = create(:proposal, tag_list: 'Medio Ambiente')
proposal2 = create(:proposal, tag_list: 'Medio Ambiente')
proposal3 = create(:proposal, tag_list: 'Economía')
visit proposals_path
within "#categories" do
click_link "Medio Ambiente"
end
expect(page).to have_css ".proposal", count: 2
expect(page).to have_content proposal1.title
expect(page).to have_content proposal2.title
expect(page).to_not have_content proposal3.title
end
end
end

View File

@@ -188,6 +188,23 @@ describe Budget::Investment do
end
end
describe "search" do
context "tags" do
it "searches by tags" do
investment = create(:budget_investment, tag_list: 'Latina')
results = Budget::Investment.search('Latina')
expect(results.first).to eq(investment)
results = Budget::Investment.search('Latin')
expect(results.first).to eq(investment)
end
end
end
describe 'Permissions' do
let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) }

View File

@@ -22,6 +22,15 @@ describe TagCloud do
expect(tag_names(tag_cloud)).to contain_exactly('world hunger')
end
it "returns budget investment tags" do
create(:budget_investment, tag_list: 'participation')
create(:debate, tag_list: 'world hunger')
tag_cloud = TagCloud.new(Budget::Investment)
expect(tag_names(tag_cloud)).to contain_exactly('participation')
end
it "returns tags from last week" do
create(:proposal, tag_list: 'participation', created_at: 1.day.ago)
create(:proposal, tag_list: 'corruption', created_at: 2.weeks.ago)