From 42604e27b945bcaf379a80196e3074d5a06e4cce Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 15 Jan 2017 09:55:01 +0100 Subject: [PATCH 1/3] Displays tag cloud in all phases --- .../budgets/investments/_sidebar.html.erb | 24 +++-- spec/features/tags/budget_investments_spec.rb | 97 +++++++++++-------- 2 files changed, 72 insertions(+), 49 deletions(-) diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index 292e95d59..2a241300f 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -2,27 +2,29 @@ <% if can?(:create, Budget::Investment.new(budget: @budget)) %> <% if current_user && current_user.level_two_or_three_verified? %> - <%= link_to t("budgets.investments.index.sidebar.create"), new_budget_investment_path, class: "button budget expanded" %> + <%= link_to t("budgets.investments.index.sidebar.create"), + new_budget_investment_path, class: "button budget expanded" %> <% else %>
<%= t("budgets.investments.index.sidebar.verified_only", - verify: link_to(t("budgets.investments.index.sidebar.verify_account"), verification_path)).html_safe %> + verify: link_to(t("budgets.investments.index.sidebar.verify_account"), + verification_path)).html_safe %>
<% end %> <% end %> -<% if @budget.accepting? %> - <%= render "shared/tag_cloud", taggable: 'budget/investment' %> - <%= render 'categories' %> - <%= render 'feasibility_link' %> -<% end %> - +<%= render "shared/tag_cloud", taggable: 'budget/investment' %> +<%= render 'categories' %> +<%= render 'feasibility_link' %> <% if @heading && can?(:show, @ballot) %> - + + <% if @ballot.investments.by_heading(@heading.id).count > 0 %>

@@ -45,5 +47,7 @@ <% end %> -

<%= t("budgets.investments.index.sidebar.voted_info") %>

+

+ <%= t("budgets.investments.index.sidebar.voted_info") %> +

<% end %> diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index f16e9a447..0b22297bf 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -164,72 +164,91 @@ feature 'Tags' do context 'Tag cloud' do + let!(:investment1) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } + let!(:investment2) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } + let!(:investment3) { create(:budget_investment, heading: heading, tag_list: 'Economía') } + 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') + Budget::PHASES.each do |phase| + budget.update(phase: phase) - visit budget_investments_path(budget, heading_id: heading.id) + 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" + within "#tag-cloud" do + expect(page).to have_content "Medio Ambiente" + expect(page).to have_content "Economía" + end 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') + Budget::PHASES.each do |phase| + budget.update(phase: phase) - visit budget_investments_path(budget, heading_id: heading.id) + if budget.balloting? + [investment1, investment2, investment3].each do |investment| + investment.update(selected: true) + end + end - within "#tag-cloud" do - click_link "Medio Ambiente" + 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 - - 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 + let!(:tag1) { create(:tag, kind: 'category', name: 'Medio Ambiente') } + let!(:tag2) { create(:tag, kind: 'category', name: 'Economía') } + + let!(:investment1) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } + let!(:investment2) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } + let!(:investment3) { create(:budget_investment, heading: heading, tag_list: 'Economía') } + scenario 'Display category tags' do - create(:tag, kind: 'category', name: 'Medio Ambiente') - create(:tag, kind: 'category', name: 'Economía') + Budget::PHASES.each do |phase| + budget.update(phase: phase) - 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) - 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" + within "#categories" do + expect(page).to have_content "Medio Ambiente" + expect(page).to have_content "Economía" + end end end scenario "Filter by category tags" do - create(:tag, kind: 'category', name: 'Medio Ambiente') - create(:tag, kind: 'category', name: 'Economía') + Budget::PHASES.each do |phase| + budget.update(phase: phase) - 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') + if budget.balloting? + [investment1, investment2, investment3].each do |investment| + investment.update(selected: true) + end + end - visit budget_investments_path(budget, heading_id: heading.id, search: 'Economía') + visit budget_investments_path(budget, heading_id: heading.id, search: 'Economía') - within "#categories" do - click_link "Medio Ambiente" + 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 - - 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 From 938ba4030633bee8be5efb789ec09e19e43b4e60 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 15 Jan 2017 12:00:14 +0100 Subject: [PATCH 2/3] loads categories in sidebar for balloting phase --- app/controllers/budgets/ballot/lines_controller.rb | 4 ++++ app/views/budgets/investments/_sidebar.html.erb | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 0f8209e5a..bd31c61fa 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -5,6 +5,7 @@ module Budgets #before_action :ensure_final_voting_allowed before_action :load_budget before_action :load_ballot + before_action :load_categories before_action :load_investments @@ -63,6 +64,9 @@ module Budgets @heading = @investment.heading end + def load_categories + @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) + end end end end diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index 2a241300f..4075bb29e 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -14,8 +14,8 @@ <% end %> <%= render "shared/tag_cloud", taggable: 'budget/investment' %> -<%= render 'categories' %> -<%= render 'feasibility_link' %> +<%= render 'budgets/investments/categories' %> +<%= render 'budgets/investments/feasibility_link' %> <% if @heading && can?(:show, @ballot) %> From 289666bb4d41d06ef1b78946a797c6c79ef92077 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 15 Jan 2017 12:08:41 +0100 Subject: [PATCH 3/3] loads tag cloud in balloting phase --- app/controllers/budgets/ballot/lines_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index bd31c61fa..2feb83e5e 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -5,6 +5,7 @@ module Budgets #before_action :ensure_final_voting_allowed before_action :load_budget before_action :load_ballot + before_action :load_tag_cloud before_action :load_categories before_action :load_investments @@ -64,9 +65,14 @@ module Budgets @heading = @investment.heading end + def load_tag_cloud + @tag_cloud = TagCloud.new(Budget::Investment, params[:search]) + end + def load_categories @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) end + end end end