imports votes

This commit is contained in:
kikito
2016-09-07 15:58:39 +02:00
parent c1bf89a09e
commit b4c7675c31
2 changed files with 18 additions and 0 deletions

View File

@@ -51,6 +51,10 @@ class SpendingProposalsImporter
investment.valuators = sp.valuation_assignments.map(&:valuator)
votes = ActsAsVotable::Vote.where(votable_type: 'SpendingProposal', votable_id: sp.id)
votes.each {|v| investment.vote_by({voter: v.voter, vote: 'yes'}) }
investment
end

View File

@@ -74,5 +74,19 @@ describe SpendingProposalsImporter do
expect(inv.valuators).to include(peter)
expect(inv.valuators).to include(john)
end
it "Imports votes" do
sp = create(:spending_proposal)
votes = create_list(:vote, 4, votable: sp)
voters = votes.map(&:voter).sort_by(&:id)
inv = importer.import(sp)
expect(inv.total_votes).to eq(sp.total_votes)
imported_votes = ActsAsVotable::Vote.where(votable_type: "Budget::Investment", votable_id: inv.id)
expect(imported_votes.map(&:voter).sort_by(&:id)).to eq(voters)
end
end
end