adds tags to investment
This commit is contained in:
@@ -28,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
|
||||
@@ -101,6 +102,9 @@ module Budgets
|
||||
@categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name)
|
||||
end
|
||||
|
||||
def tag_cloud
|
||||
TagCloud.new(Budget::Investment, params[:search])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
11
app/views/budgets/investments/_categories.html.erb
Normal file
11
app/views/budgets/investments/_categories.html.erb
Normal 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>
|
||||
@@ -38,6 +38,7 @@
|
||||
<p><%= link_to investment.description, namespaced_budget_investment_path(investment) %></p>
|
||||
<div class="truncate"></div>
|
||||
</div>
|
||||
<%= render "shared/tags", taggable: investment, limit: 5 %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= render 'shared/tags', taggable: @investment, url: budget_investments_path(@budget) %>
|
||||
<%= render 'shared/tags', taggable: @investment %>
|
||||
|
||||
<%= safe_html_with_links investment.description.html_safe %>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
verify: link_to(t("budget.investments.index.sidebar.verify_account"), verification_path)).html_safe %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
|
||||
<%= render 'categories' %>
|
||||
<% end %>
|
||||
|
||||
<div class="sidebar-divider"></div>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -119,6 +119,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:
|
||||
|
||||
@@ -49,6 +49,10 @@ en:
|
||||
external_url: Link to additional documentation
|
||||
heading: Choose if a proposed citywide or district
|
||||
location: "Location"
|
||||
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 (',')"
|
||||
submit_buttons:
|
||||
create: Create
|
||||
new: Create
|
||||
|
||||
@@ -49,6 +49,10 @@ es:
|
||||
external_url: Enlace a documentación adicional
|
||||
heading: "Elige si es una propuesta para toda la ciudad o para un distrito"
|
||||
location: "Ubicación de la propuesta"
|
||||
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 (',')"
|
||||
submit_buttons:
|
||||
create: Crear
|
||||
new: Crear
|
||||
|
||||
@@ -161,6 +161,7 @@ en:
|
||||
proposal: Proposal
|
||||
proposal_notification: "Notification"
|
||||
spending_proposal: Spending proposal
|
||||
budget/investment: Investment
|
||||
user: Account
|
||||
verification/sms: phone
|
||||
signature_sheet: Signature sheet
|
||||
|
||||
@@ -161,6 +161,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
|
||||
|
||||
@@ -594,8 +594,4 @@ feature 'Ballots' do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -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)
|
||||
@@ -401,85 +404,4 @@ feature 'Budget Investments' do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'Tagging' do
|
||||
let(:author) { create(:user, :level_two) }
|
||||
let(:budget) { create(:budget, :accepting) }
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let!(:heading) { create(:budget_heading, group: group) }
|
||||
|
||||
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_budget_investment_path(budget, heading_id: heading.id)
|
||||
|
||||
select "#{heading.group.name}: #{heading.name}", from: 'budget_investment_heading_id'
|
||||
fill_in 'budget_investment_title', with: 'Build gym near my street'
|
||||
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 'Budget 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 '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
|
||||
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
235
spec/features/tags/budget_investments_spec.rb
Normal file
235
spec/features/tags/budget_investments_spec.rb
Normal file
@@ -0,0 +1,235 @@
|
||||
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'
|
||||
|
||||
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'
|
||||
|
||||
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'
|
||||
|
||||
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'
|
||||
|
||||
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
|
||||
end
|
||||
218
spec/features/tags/debates_spec.rb
Normal file
218
spec/features/tags/debates_spec.rb
Normal 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
|
||||
294
spec/features/tags/proposals_spec.rb
Normal file
294
spec/features/tags/proposals_spec.rb
Normal 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
|
||||
@@ -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) }
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user