From 56f4c3c3b9d9ec3a53f7bca53e757e54b1db0585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Fuentes?= Date: Wed, 22 Nov 2017 11:03:21 +0100 Subject: [PATCH] added test to csv download and style corrections --- .../admin/budget_investments_controller.rb | 22 +++++++++---------- .../features/admin/budget_investments_spec.rb | 16 ++++++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 749bb84a7..de2e34d84 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -65,19 +65,19 @@ class Admin::BudgetInvestmentsController < Admin::BaseController csv_string = CSV.generate(headers: true) do |csv| csv << attributes @investments.each do |investment| - id = investment.id.to_s + id = investment.id.to_s title = investment.title total_votes = investment.total_votes.to_s - if investment.administrator.present? - administrator = investment.administrator.name - else - administrator = t("admin.budget_investments.index.no_admin_assigned") - end - if investment.valuators.empty? - valuators = t("admin.budget_investments.index.no_valuators_assigned") - else - valuators = investment.valuators.collect(&:description_or_name).join(', ') - end + administrator = if investment.administrator.present? + investment.administrator.name + else + t("admin.budget_investments.index.no_admin_assigned") + end + valuators = if investment.valuators.empty? + t("admin.budget_investments.index.no_valuators_assigned") + else + investment.valuators.collect(&:description_or_name).join(', ') + end heading_name = investment.heading.name price = t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.formatted_price) valuation_finished = investment.valuation_finished? ? t('shared.yes') : t('shared.no') diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 2bc1dabf2..7cf4a294d 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -625,7 +625,23 @@ feature 'Admin budget investments' do expect(page).not_to have_link('Selected') end end + end + context "Selecting csv" do + + scenario "Downloading CSV file" do + create(:budget_investment, :unfeasible, budget: @budget) + create(:budget_investment, :feasible, budget: @budget) + + visit admin_budget_budget_investments_path(@budget, format: :csv) + + header = page.response_headers['Content-Disposition'] + header.should match /^attachment/ + header.should match /filename="budget_investments.csv"$/ + + expect(page).to have_content "Budget Investment 1 title" + expect(page).to have_content "Budget Investment 2 title" + end end end