Merge branch 'master' into polls

This commit is contained in:
Alberto
2017-04-06 14:16:49 +02:00
committed by GitHub
118 changed files with 1294 additions and 748 deletions

View File

@@ -15,12 +15,18 @@ describe "Abilities::Common" do
let(:own_proposal) { create(:proposal, author: user) }
let(:accepting_budget) { create(:budget, phase: 'accepting') }
let(:reviewing_budget) { create(:budget, phase: 'reviewing') }
let(:selecting_budget) { create(:budget, phase: 'selecting') }
let(:balloting_budget) { create(:budget, phase: 'balloting') }
let(:investment_in_accepting_budget) { create(:budget_investment, budget: accepting_budget) }
let(:investment_in_reviewing_budget) { create(:budget_investment, budget: reviewing_budget) }
let(:investment_in_selecting_budget) { create(:budget_investment, budget: selecting_budget) }
let(:investment_in_balloting_budget) { create(:budget_investment, budget: balloting_budget) }
let(:own_investment_in_accepting_budget) { create(:budget_investment, budget: accepting_budget, author: user) }
let(:own_investment_in_reviewing_budget) { create(:budget_investment, budget: reviewing_budget, author: user) }
let(:own_investment_in_selecting_budget) { create(:budget_investment, budget: selecting_budget, author: user) }
let(:own_investment_in_balloting_budget) { create(:budget_investment, budget: balloting_budget, author: user) }
let(:ballot_in_accepting_budget) { create(:budget_ballot, budget: accepting_budget) }
let(:ballot_in_selecting_budget) { create(:budget_ballot, budget: selecting_budget) }
let(:ballot_in_balloting_budget) { create(:budget_ballot, budget: balloting_budget) }
@@ -191,12 +197,21 @@ describe "Abilities::Common" do
it { should_not be_able_to(:vote, investment_in_accepting_budget) }
it { should be_able_to(:vote, investment_in_selecting_budget) }
it { should_not be_able_to(:vote, investment_in_balloting_budget) }
it { should_not be_able_to(:destroy, investment_in_accepting_budget) }
it { should_not be_able_to(:destroy, investment_in_reviewing_budget) }
it { should_not be_able_to(:destroy, investment_in_selecting_budget) }
it { should_not be_able_to(:destroy, investment_in_balloting_budget) }
it { should be_able_to(:destroy, own_investment_in_accepting_budget) }
it { should be_able_to(:destroy, own_investment_in_reviewing_budget) }
it { should_not be_able_to(:destroy, own_investment_in_selecting_budget) }
it { should_not be_able_to(:destroy, investment_in_balloting_budget) }
it { should_not be_able_to(:create, ballot_in_accepting_budget) }
it { should_not be_able_to(:create, ballot_in_selecting_budget) }
it { should be_able_to(:create, ballot_in_balloting_budget) }
end
end
describe "when level 3 verified" do

View File

@@ -35,7 +35,26 @@ describe Budget::Investment do
expect(investment.description).to eq("alert('danger');")
end
describe "#unfeasibility_explanation" do
it "set correct group and budget ids" do
budget = create(:budget)
group_1 = create(:budget_group, budget: budget)
group_2 = create(:budget_group, budget: budget)
heading_1 = create(:budget_heading, group: group_1)
heading_2 = create(:budget_heading, group: group_2)
investment = create(:budget_investment, heading: heading_1)
expect(investment.budget_id).to eq budget.id
expect(investment.group_id).to eq group_1.id
investment.update(heading: heading_2)
expect(investment.budget_id).to eq budget.id
expect(investment.group_id).to eq group_2.id
end
describe "#unfeasibility_explanation blank" do
it "should be valid if valuation not finished" do
investment.unfeasibility_explanation = ""
investment.valuation_finished = false
@@ -57,6 +76,29 @@ describe Budget::Investment do
end
end
describe "#price blank" do
it "should be valid if valuation not finished" do
investment.price = ""
investment.valuation_finished = false
expect(investment).to be_valid
end
it "should be valid if valuation finished and unfeasible" do
investment.price = ""
investment.unfeasibility_explanation = "reason"
investment.feasibility = "unfeasible"
investment.valuation_finished = true
expect(investment).to be_valid
end
it "should not be valid if valuation finished and feasible" do
investment.price = ""
investment.feasibility = "feasible"
investment.valuation_finished = true
expect(investment).to_not be_valid
end
end
describe "#code" do
let(:investment) { create(:budget_investment) }
@@ -285,6 +327,45 @@ describe Budget::Investment do
expect(salamanca_investment.valid_heading?(user)).to eq(false)
end
it "allows votes in a group with a single heading" do
all_city_investment = create(:budget_investment, heading: heading)
expect(all_city_investment.valid_heading?(user)).to eq(true)
end
it "allows votes in a group with a single heading after voting in that heading" do
all_city_investment1 = create(:budget_investment, heading: heading)
all_city_investment2 = create(:budget_investment, heading: heading)
create(:vote, votable: all_city_investment1, voter: user)
expect(all_city_investment2.valid_heading?(user)).to eq(true)
end
it "allows votes in a group with a single heading after voting in another group" do
districts = create(:budget_group, budget: budget)
carabanchel = create(:budget_heading, group: districts)
all_city_investment = create(:budget_investment, heading: heading)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
create(:vote, votable: carabanchel_investment, voter: user)
expect(all_city_investment.valid_heading?(user)).to eq(true)
end
it "allows votes in a group with multiple headings after voting in group with a single heading" do
districts = create(:budget_group, budget: budget)
carabanchel = create(:budget_heading, group: districts)
salamanca = create(:budget_heading, group: districts)
all_city_investment = create(:budget_investment, heading: heading)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
create(:vote, votable: all_city_investment, voter: user)
expect(carabanchel_investment.valid_heading?(user)).to eq(true)
end
end
end

View File

@@ -46,12 +46,20 @@ describe SignatureSheet do
expect(signature_sheet.name).to eq("Citizen proposal #{proposal.id}")
end
it "returns name for spending proposal signature sheets" do
spending_proposal = create(:spending_proposal)
signature_sheet.signable = spending_proposal
expect(signature_sheet.name).to eq("Spending proposal #{spending_proposal.id}")
end
it "returns name for budget investment signature sheets" do
budget_investment = create(:budget_investment)
signature_sheet.signable = budget_investment
expect(signature_sheet.name).to eq("Investment #{budget_investment.id}")
end
end
describe "#verify_signatures" do

View File

@@ -46,49 +46,61 @@ describe Signature do
end
end
describe "#verified?" do
it "returns true if user exists" do
user = create(:user, :level_two, document_number: "123A")
signature = create(:signature, document_number: user.document_number)
expect(signature.verified?).to eq(true)
end
it "returns true if document number in census" do
signature = create(:signature, document_number: "12345678Z")
expect(signature.verified?).to eq(true)
end
it "returns false if user does not exist and not in census" do
signature = create(:signature, document_number: "123A")
expect(signature.verified?).to eq(false)
end
end
describe "#assign_vote" do
describe "#verify" do
describe "existing user" do
it "assigns vote to user" do
it "assigns vote to user on proposal" do
user = create(:user, :level_two, document_number: "123A")
signature = create(:signature, document_number: user.document_number)
proposal = signature.signable
signature.assign_vote
signature.verify
expect(user.voted_for?(proposal)).to be
end
it "assigns vote to user on budget investment" do
investment = create(:budget_investment)
signature_sheet = create(:signature_sheet, signable: investment)
user = create(:user, :level_two, document_number: "123A")
signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet)
signature.verify
expect(user.voted_for?(investment)).to be
end
it "does not assign vote to user multiple times" do
user = create(:user, :level_two, document_number: "123A")
signature = create(:signature, document_number: user.document_number)
signature.assign_vote
signature.assign_vote
signature.verify
signature.verify
expect(Vote.count).to eq(1)
end
it "does not assigns vote to invalid user on budget investment" do
investment = create(:budget_investment)
signature_sheet = create(:signature_sheet, signable: investment)
user = create(:user, document_number: "123A")
signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet)
signature.verify
expect(user.voted_for?(investment)).to_not be
expect(Vote.count).to eq(0)
end
it "does not assign vote to user multiple times on budget investment" do
investment = create(:budget_investment)
signature_sheet = create(:signature_sheet, signable: investment)
user = create(:user, :level_two, document_number: "123A")
signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet)
signature.verify
signature.verify
expect(Vote.count).to eq(1)
end
@@ -100,7 +112,22 @@ describe Signature do
signature_sheet = create(:signature_sheet, signable: proposal)
signature = create(:signature, signature_sheet: signature_sheet, document_number: user.document_number)
signature.assign_vote
signature.verify
expect(Vote.count).to eq(1)
end
it "does not assign vote to user if already voted on budget investment" do
investment = create(:budget_investment)
user = create(:user, :level_two, document_number: "123A")
vote = create(:vote, votable: investment, voter: user)
signature_sheet = create(:signature_sheet, signable: investment)
signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet)
expect(Vote.count).to eq(1)
signature.verify
expect(Vote.count).to eq(1)
end
@@ -108,7 +135,7 @@ describe Signature do
it "marks the vote as coming from a signature" do
signature = create(:signature, document_number: "12345678Z")
signature.assign_vote
signature.verify
expect(Vote.last.signature).to eq(signature)
end
@@ -118,23 +145,27 @@ describe Signature do
describe "inexistent user" do
it "creates a user with that document number" do
create(:geozone, census_code: "01")
signature = create(:signature, document_number: "12345678Z")
proposal = signature.signable
signature.assign_vote
signature.verify
user = User.last
expect(user.document_number).to eq("12345678Z")
expect(user.created_from_signature).to eq(true)
expect(user.verified_at).to be
expect(user.erased_at).to be
expect(user.geozone).to be
expect(user.gender).to be
expect(user.date_of_birth).to be
end
it "assign the vote to newly created user" do
signature = create(:signature, document_number: "12345678Z")
proposal = signature.signable
signature.assign_vote
signature.verify
user = signature.user
expect(user.voted_for?(proposal)).to be
@@ -143,22 +174,18 @@ describe Signature do
it "assigns signature to vote" do
signature = create(:signature, document_number: "12345678Z")
signature.assign_vote
signature.verify
expect(Vote.last.signature).to eq(signature)
end
end
end
describe "#verify" do
describe "document in census" do
it "calls assign_vote" do
it "calls assign_vote_to_user" do
signature = create(:signature, document_number: "12345678Z")
expect(signature).to receive(:assign_vote)
expect(signature).to receive(:assign_vote_to_user)
signature.verify
end
@@ -175,10 +202,10 @@ describe Signature do
describe "document not in census" do
it "does not call assign_vote" do
it "does not call assign_vote_to_user" do
signature = create(:signature, document_number: "123A")
expect(signature).to_not receive(:assign_vote)
expect(signature).to_not receive(:assign_vote_to_user)
signature.verify
end