adds specs

This commit is contained in:
rgarcia
2016-04-22 15:02:56 +02:00
parent 6a4177ed59
commit bdc815e05c
2 changed files with 66 additions and 0 deletions

View File

@@ -425,4 +425,47 @@ feature 'Admin spending proposals' do
end
context 'Summary' do
scenario "Diplays summary for every geozone" do
california = create(:geozone)
new_york = create(:geozone)
washington = create(:geozone)
proposal1 = create(:spending_proposal, title: "Build a highway", price: '10000000', geozone: nil, feasible: true, valuation_finished: true)
proposal1 = create(:spending_proposal, title: "Build a university", price: '5000000', geozone: nil, feasible: true, valuation_finished: true)
proposal3 = create(:spending_proposal, title: "Build a hospital", price: '1000000', geozone: california, feasible: true, valuation_finished: true)
proposal4 = create(:spending_proposal, title: "Build a school", price: '500000', geozone: california, feasible: true, valuation_finished: true)
proposal5 = create(:spending_proposal, title: "Plant more trees", price: '30000', geozone: new_york, feasible: true, valuation_finished: true)
proposal6 = create(:spending_proposal, title: "Destroy the seas", price: '999999', geozone: washington, feasible: false, valuation_finished: true)
visit admin_spending_proposals_path
click_link "Summary"
expect(page).to have_content "Summary for feasible and finished investment projects"
within("#geozone_all_city") do
expect(page).to have_css(".name", text: "All city")
expect(page).to have_css(".proposals-count", text: 2)
expect(page).to have_css(".total-price", text: "$15,000,000")
end
within("#geozone_#{california.id}") do
expect(page).to have_css(".name", text: california.name)
expect(page).to have_css(".proposals-count", text: 2)
expect(page).to have_css(".total-price", text: "$1,500,000")
end
within("#geozone_#{new_york.id}") do
expect(page).to have_css(".name", text: new_york.name)
expect(page).to have_css(".proposals-count", text: 1)
expect(page).to have_css(".total-price", text: '$30,000')
end
expect(page).to_not have_content washington.name
end
end
end

View File

@@ -330,5 +330,28 @@ describe SpendingProposal do
end
end
describe "#for_summary" do
it "returns only feasible and valuation finished proposals" do
sp1 = create(:spending_proposal, feasible: true, valuation_finished: true)
sp2 = create(:spending_proposal, feasible: true, valuation_finished: true)
sp3 = create(:spending_proposal, feasible: false, valuation_finished: false)
expect(SpendingProposal.for_summary).to include(sp1)
expect(SpendingProposal.for_summary).to include(sp2)
expect(SpendingProposal.for_summary).to_not include(sp3)
end
it "does not return unfeasible proposals" do
sp = create(:spending_proposal, feasible: false, valuation_finished: true)
expect(SpendingProposal.for_summary).to_not include(sp)
end
it "does not return proposals pending valuation" do
sp = create(:spending_proposal, feasible: true, valuation_finished: false)
expect(SpendingProposal.for_summary).to_not include(sp)
end
end
end