adds more functionality to spending proposal importer

This commit is contained in:
kikito
2016-09-07 13:02:26 +02:00
parent b8dffc6137
commit c1bf89a09e
2 changed files with 21 additions and 11 deletions

View File

@@ -1,16 +1,7 @@
class SpendingProposalsImporter
def import(sp)
# feasibility
# unfeasibility_explanation
# heading_id
# valuator_assignments_count
# hidden_at
# comments_count
# group_id
# budget_id
# duration
# votes
# comments
budget = Budget.last || Budget.create!(name: Date.today.year.to_s, currency_symbol: "")
@@ -35,7 +26,7 @@ class SpendingProposalsImporter
'undecided'
end
Budget::Investment.create!(
investment = Budget::Investment.create!(
heading_id: heading.id,
author_id: sp.author_id,
administrator_id: sp.administrator_id,
@@ -45,7 +36,9 @@ class SpendingProposalsImporter
price: sp.price,
price_explanation: sp.price_explanation,
internal_comments: sp.internal_comments,
duration: sp.time_scope,
feasibility: feasibility,
unfeasibility_explanation: sp.feasible_explanation,
valuation_finished: sp.valuation_finished,
price_first_year: sp.price_first_year,
cached_votes_up: sp.cached_votes_up,
@@ -55,6 +48,10 @@ class SpendingProposalsImporter
responsible_name: sp.responsible_name,
terms_of_service: "1"
)
investment.valuators = sp.valuation_assignments.map(&:valuator)
investment
end
end

View File

@@ -61,5 +61,18 @@ describe SpendingProposalsImporter do
expect(importer.import(feasible).feasibility).to eq('feasible')
expect(importer.import(unfeasible).feasibility).to eq('unfeasible')
end
it "Imports valuation assignments" do
sp = create(:spending_proposal)
peter = create(:valuator)
john = create(:valuator)
sp.valuators << peter << john
inv = importer.import(sp)
expect(inv.valuator_assignments.count).to eq(2)
expect(inv.valuators).to include(peter)
expect(inv.valuators).to include(john)
end
end
end