Merge branch 'master' into polls

This commit is contained in:
Juanjo Bazán
2017-01-19 16:51:19 +01:00
254 changed files with 10658 additions and 871 deletions

View File

@@ -59,4 +59,15 @@ describe "Abilities::Administrator" do
it { should be_able_to(:manage, Poll) }
it { should be_able_to(:manage, Poll::Booth) }
it { should be_able_to(:create, Budget) }
it { should be_able_to(:update, Budget) }
it { should be_able_to(:create, Budget::ValuatorAssignment) }
it { should be_able_to(:update, Budget::Investment) }
it { should be_able_to(:hide, Budget::Investment) }
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'valuating'))) }
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'finished'))) }
end

View File

@@ -14,6 +14,17 @@ describe "Abilities::Common" do
let(:own_comment) { create(:comment, author: user) }
let(:own_proposal) { create(:proposal, author: user) }
let(:accepting_budget) { create(:budget, phase: 'accepting') }
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_selecting_budget) { create(:budget_investment, budget: selecting_budget) }
let(:investment_in_balloting_budget) { create(:budget_investment, budget: balloting_budget) }
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) }
let(:current_poll) { create(:poll) }
let(:incoming_poll) { create(:poll, :incoming) }
let(:expired_poll) { create(:poll, :expired) }
@@ -164,6 +175,21 @@ describe "Abilities::Common" do
it { should_not be_able_to(:answer, incoming_poll_question_from_other_geozone) }
end
end
describe "Budgets" do
it { should be_able_to(:create, investment_in_accepting_budget) }
it { should_not be_able_to(:create, investment_in_selecting_budget) }
it { should_not be_able_to(:create, investment_in_balloting_budget) }
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(: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

@@ -27,5 +27,5 @@ describe "Abilities::Everyone" do
it { should be_able_to(:index, SpendingProposal) }
it { should_not be_able_to(:create, SpendingProposal) }
pending "only authors can access new and create for ProposalNotifications"
it { should be_able_to(:index, Budget) }
end

View File

@@ -5,8 +5,24 @@ describe "Abilities::Valuator" do
subject(:ability) { Ability.new(user) }
let(:user) { valuator.user }
let(:valuator) { create(:valuator) }
let(:non_assigned_investment) { create(:budget_investment) }
let(:assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'valuating')) }
before(:each) { assigned_investment.valuators << valuator }
let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'finished')) }
before(:each) { finished_assigned_investment.valuators << valuator }
it { should be_able_to(:read, SpendingProposal) }
it { should be_able_to(:update, SpendingProposal) }
it { should be_able_to(:valuate, SpendingProposal) }
it { should_not be_able_to(:update, non_assigned_investment) }
it { should_not be_able_to(:valuate, non_assigned_investment) }
it { should be_able_to(:update, assigned_investment) }
it { should be_able_to(:valuate, assigned_investment) }
it { should_not be_able_to(:update, finished_assigned_investment) }
it { should_not be_able_to(:valuate, finished_assigned_investment) }
end

View File

@@ -0,0 +1,45 @@
require 'rails_helper'
describe "Budget::Ballot::Line" do
describe 'Validations' do
let(:budget){ create(:budget) }
let(:group){ create(:budget_group, budget: budget) }
let(:heading){ create(:budget_heading, group: group, price: 10000000) }
let(:investment){ create(:budget_investment, :selected, price: 5000000, heading: heading) }
let(:ballot) { create(:budget_ballot, budget: budget) }
let(:ballot_line) { build(:budget_ballot_line, ballot: ballot, investment: investment) }
it "should be valid and automatically denormallyze budget, group and heading when validated" do
expect(ballot_line).to be_valid
expect(ballot_line.budget).to eq(budget)
expect(ballot_line.group).to eq(group)
expect(ballot_line.heading).to eq(heading)
end
describe 'Money' do
it "should not be valid if insufficient funds" do
investment.update(price: heading.price + 1)
expect(ballot_line).to_not be_valid
end
it "should be valid if sufficient funds" do
investment.update(price: heading.price - 1)
expect(ballot_line).to be_valid
end
end
describe 'Selectibility' do
it "should not be valid if investment is unselected" do
investment.update(selected: false)
expect(ballot_line).to_not be_valid
end
it "should be valid if investment is selected" do
investment.update(selected: true, price: 20000)
expect(ballot_line).to be_valid
end
end
end
end

View File

@@ -0,0 +1,71 @@
require 'rails_helper'
describe Budget::Ballot do
describe "#amount_spent" do
it "returns the total amount spent in investments" do
budget = create(:budget)
group1 = create(:budget_group, budget: budget)
group2 = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group1, price: 100000)
heading2 = create(:budget_heading, group: group2, price: 200000)
inv1 = create(:budget_investment, :selected, price: 10000, heading: heading1)
inv2 = create(:budget_investment, :selected, price: 20000, heading: heading2)
ballot = create(:budget_ballot, budget: budget)
ballot.investments << inv1
expect(ballot.total_amount_spent).to eq 10000
ballot.investments << inv2
expect(ballot.total_amount_spent).to eq 30000
end
it "returns the amount spent on all investments assigned to a specific heading" do
budget = create(:budget)
group1 = create(:budget_group, budget: budget)
group2 = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group1, price: 100000)
heading2 = create(:budget_heading, group: group2, price: 200000)
inv1 = create(:budget_investment, :selected, price: 10000, heading: heading1)
inv2 = create(:budget_investment, :selected, price: 20000, heading: heading2)
inv3 = create(:budget_investment, :selected, price: 40000, heading: heading1)
ballot = create(:budget_ballot, budget: budget)
ballot.investments << inv1 << inv2
expect(ballot.amount_spent(heading1)).to eq 10000
expect(ballot.amount_spent(heading2)).to eq 20000
ballot.investments << inv3
expect(ballot.amount_spent(heading1)).to eq 50000
expect(ballot.amount_spent(heading2)).to eq 20000
end
end
describe "#amount_available" do
it "returns how much is left after taking some investments" do
budget = create(:budget)
group1 = create(:budget_group, budget: budget)
group2 = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group1, price: 1000)
heading2 = create(:budget_heading, group: group2, price: 300)
inv1 = create(:budget_investment, :selected, price: 100, heading: heading1)
inv2 = create(:budget_investment, :selected, price: 200, heading: heading2)
inv3 = create(:budget_investment, :selected, price: 400, heading: heading1)
ballot = create(:budget_ballot, budget: budget)
ballot.investments << inv1 << inv2
expect(ballot.amount_available(heading1)).to eq 900
expect(ballot.amount_available(heading2)).to eq 100
ballot.investments << inv3
expect(ballot.amount_available(heading1)).to eq 500
end
end
end

View File

@@ -0,0 +1,440 @@
require 'rails_helper'
describe Budget::Investment do
let(:investment) { build(:budget_investment) }
it "should be valid" do
expect(investment).to be_valid
end
it "should not be valid without an author" do
investment.author = nil
expect(investment).to_not be_valid
end
describe "#title" do
it "should not be valid without a title" do
investment.title = nil
expect(investment).to_not be_valid
end
it "should not be valid when very short" do
investment.title = "abc"
expect(investment).to_not be_valid
end
it "should not be valid when very long" do
investment.title = "a" * 81
expect(investment).to_not be_valid
end
end
it "sanitizes description" do
investment.description = "<script>alert('danger');</script>"
investment.valid?
expect(investment.description).to eq("alert('danger');")
end
describe "#unfeasibility_explanation" do
it "should be valid if valuation not finished" do
investment.unfeasibility_explanation = ""
investment.valuation_finished = false
expect(investment).to be_valid
end
it "should be valid if valuation finished and feasible" do
investment.unfeasibility_explanation = ""
investment.feasibility = "feasible"
investment.valuation_finished = true
expect(investment).to be_valid
end
it "should not be valid if valuation finished and unfeasible" do
investment.unfeasibility_explanation = ""
investment.feasibility = "unfeasible"
investment.valuation_finished = true
expect(investment).to_not be_valid
end
end
describe "#code" do
let(:investment) { create(:budget_investment) }
it "returns the proposal id" do
expect(investment.code).to include("#{investment.id}")
end
it "returns the administrator id when assigned" do
investment.administrator = create(:administrator)
expect(investment.code).to include("#{investment.id}-A#{investment.administrator.id}")
end
end
describe "#send_unfeasible_email" do
let(:investment) { create(:budget_investment) }
it "sets the time when the unfeasible email was sent" do
expect(investment.unfeasible_email_sent_at).to_not be
investment.send_unfeasible_email
expect(investment.unfeasible_email_sent_at).to be
end
it "send an email" do
expect {investment.send_unfeasible_email}.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
describe "#should_show_votes?" do
it "returns true in selecting phase" do
budget = create(:budget, phase: "selecting")
investment = create(:budget_investment, budget: budget)
expect(investment.should_show_votes?).to eq(true)
end
it "returns false in any other phase" do
Budget::PHASES.reject {|phase| phase == "selecting"}.each do |phase|
budget = create(:budget, phase: phase)
investment = create(:budget_investment, budget: budget)
expect(investment.should_show_votes?).to eq(false)
end
end
end
describe "by_admin" do
it "should return investments assigned to specific administrator" do
investment1 = create(:budget_investment, administrator_id: 33)
create(:budget_investment)
by_admin = Budget::Investment.by_admin(33)
expect(by_admin.size).to eq(1)
expect(by_admin.first).to eq(investment1)
end
end
describe "by_valuator" do
it "should return investments assigned to specific valuator" do
investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment3 = create(:budget_investment)
valuator1 = create(:valuator)
valuator2 = create(:valuator)
investment1.valuators << valuator1
investment2.valuators << valuator2
investment3.valuators << [valuator1, valuator2]
by_valuator = Budget::Investment.by_valuator(valuator1.id)
expect(by_valuator.size).to eq(2)
expect(by_valuator.sort).to eq([investment1,investment3].sort)
end
end
describe "scopes" do
describe "valuation_open" do
it "should return all investments with false valuation_finished" do
investment1 = create(:budget_investment, valuation_finished: true)
investment2 = create(:budget_investment)
valuation_open = Budget::Investment.valuation_open
expect(valuation_open.size).to eq(1)
expect(valuation_open.first).to eq(investment2)
end
end
describe "without_admin" do
it "should return all open investments without assigned admin" do
investment1 = create(:budget_investment, valuation_finished: true)
investment2 = create(:budget_investment, administrator: create(:administrator))
investment3 = create(:budget_investment)
without_admin = Budget::Investment.without_admin
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(investment3)
end
end
describe "managed" do
it "should return all open investments with assigned admin but without assigned valuators" do
investment1 = create(:budget_investment, administrator: create(:administrator))
investment2 = create(:budget_investment, administrator: create(:administrator), valuation_finished: true)
investment3 = create(:budget_investment, administrator: create(:administrator))
investment1.valuators << create(:valuator)
managed = Budget::Investment.managed
expect(managed.size).to eq(1)
expect(managed.first).to eq(investment3)
end
end
describe "valuating" do
it "should return all investments with assigned valuator but valuation not finished" do
investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment3 = create(:budget_investment, valuation_finished: true)
investment2.valuators << create(:valuator)
investment3.valuators << create(:valuator)
valuating = Budget::Investment.valuating
expect(valuating.size).to eq(1)
expect(valuating.first).to eq(investment2)
end
end
describe "valuation_finished" do
it "should return all investments with valuation finished" do
investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment3 = create(:budget_investment, valuation_finished: true)
investment2.valuators << create(:valuator)
investment3.valuators << create(:valuator)
valuation_finished = Budget::Investment.valuation_finished
expect(valuation_finished.size).to eq(1)
expect(valuation_finished.first).to eq(investment3)
end
end
describe "feasible" do
it "should return all feasible investments" do
feasible_investment = create(:budget_investment, :feasible)
create(:budget_investment)
expect(Budget::Investment.feasible).to eq [feasible_investment]
end
end
describe "unfeasible" do
it "should return all unfeasible investments" do
unfeasible_investment = create(:budget_investment, :unfeasible)
create(:budget_investment, :feasible)
expect(Budget::Investment.unfeasible).to eq [unfeasible_investment]
end
end
end
describe "search" do
context "tags" do
it "searches by tags" do
investment = create(:budget_investment, tag_list: 'Latina')
results = Budget::Investment.search('Latina')
expect(results.first).to eq(investment)
results = Budget::Investment.search('Latin')
expect(results.first).to eq(investment)
end
end
end
describe 'Permissions' do
let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group) }
let(:user) { create(:user, :level_two) }
let(:luser) { create(:user) }
let(:district_sp) { create(:budget_investment, budget: budget, group: group, heading: heading) }
describe '#reason_for_not_being_selectable_by' do
it "rejects not logged in users" do
expect(district_sp.reason_for_not_being_selectable_by(nil)).to eq(:not_logged_in)
end
it "rejects not verified users" do
expect(district_sp.reason_for_not_being_selectable_by(luser)).to eq(:not_verified)
end
it "rejects organizations" do
create(:organization, user: user)
expect(district_sp.reason_for_not_being_selectable_by(user)).to eq(:organization)
end
it "rejects selections when selecting is not allowed (via admin setting)" do
budget.phase = "on_hold"
expect(district_sp.reason_for_not_being_selectable_by(user)).to eq(:no_selecting_allowed)
end
it "accepts valid selections when selecting is allowed" do
budget.phase = "selecting"
expect(district_sp.reason_for_not_being_selectable_by(user)).to be_nil
end
it "rejects votes in two headings of the same group" do
carabanchel = create(:budget_heading, group: group)
salamanca = create(:budget_heading, group: group)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
salamanca_investment = create(:budget_investment, heading: salamanca)
create(:vote, votable: carabanchel_investment, voter: user)
expect(salamanca_investment.valid_heading?(user)).to eq(false)
end
end
end
describe "Order" do
describe "#sort_by_confidence_score" do
it "should order by confidence_score" do
least_voted = create(:budget_investment, cached_votes_up: 1)
most_voted = create(:budget_investment, cached_votes_up: 10)
some_votes = create(:budget_investment, cached_votes_up: 5)
expect(Budget::Investment.sort_by_confidence_score.first).to eq most_voted
expect(Budget::Investment.sort_by_confidence_score.second).to eq some_votes
expect(Budget::Investment.sort_by_confidence_score.third).to eq least_voted
end
it "should order by confidence_score and then by id" do
least_voted = create(:budget_investment, cached_votes_up: 1)
most_voted = create(:budget_investment, cached_votes_up: 10)
most_voted2 = create(:budget_investment, cached_votes_up: 10)
least_voted2 = create(:budget_investment, cached_votes_up: 1)
expect(Budget::Investment.sort_by_confidence_score.first).to eq most_voted2
expect(Budget::Investment.sort_by_confidence_score.second).to eq most_voted
expect(Budget::Investment.sort_by_confidence_score.third).to eq least_voted2
expect(Budget::Investment.sort_by_confidence_score.fourth).to eq least_voted
end
end
end
describe "responsible_name" do
let(:user) { create(:user, document_number: "123456") }
let!(:investment) { create(:budget_investment, author: user) }
it "gets updated with the document_number" do
expect(investment.responsible_name).to eq("123456")
end
it "does not get updated if the user is erased" do
user.erase
user.update(document_number: nil)
expect(user.document_number).to be_blank
investment.touch
expect(investment.responsible_name).to eq("123456")
end
end
describe "total votes" do
it "takes into account physical votes in addition to web votes" do
b = create(:budget, :selecting)
g = create(:budget_group, budget: b)
h = create(:budget_heading, group: g)
i = create(:budget_investment, budget: b, group: g, heading: h)
i.register_selection(create(:user, :level_two))
expect(i.total_votes).to eq(1)
i.physical_votes = 10
expect(i.total_votes).to eq(11)
end
end
describe "#with_supports" do
it "should return proposals with supports" do
inv1 = create(:budget_investment)
inv2 = create(:budget_investment)
create(:vote, votable: inv1)
expect(Budget::Investment.with_supports).to include(inv1)
expect(Budget::Investment.with_supports).to_not include(inv2)
end
end
describe "Final Voting" do
describe 'Permissions' do
let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group) }
let(:user) { create(:user, :level_two) }
let(:luser) { create(:user) }
let(:ballot) { create(:budget_ballot, budget: budget) }
let(:investment) { create(:budget_investment, :selected, budget: budget, heading: heading) }
describe '#reason_for_not_being_ballotable_by' do
it "rejects not logged in users" do
expect(investment.reason_for_not_being_ballotable_by(nil, ballot)).to eq(:not_logged_in)
end
it "rejects not verified users" do
expect(investment.reason_for_not_being_ballotable_by(luser, ballot)).to eq(:not_verified)
end
it "rejects organizations" do
create(:organization, user: user)
expect(investment.reason_for_not_being_ballotable_by(user, ballot)).to eq(:organization)
end
it "rejects votes when voting is not allowed (wrong phase)" do
budget.phase = "reviewing"
expect(investment.reason_for_not_being_ballotable_by(user, ballot)).to eq(:no_ballots_allowed)
end
it "rejects non-selected investments" do
investment.selected = false
expect(investment.reason_for_not_being_ballotable_by(user, ballot)).to eq(:not_selected)
end
it "accepts valid ballots when voting is allowed" do
budget.phase = "balloting"
expect(investment.reason_for_not_being_ballotable_by(user, ballot)).to be_nil
end
it "accepts valid selections" do
budget.phase = "selecting"
expect(investment.reason_for_not_being_selectable_by(user)).to be_nil
end
it "rejects users with different headings" do
budget.phase = "balloting"
group = create(:budget_group, budget: budget)
california = create(:budget_heading, group: group)
new_york = create(:budget_heading, group: group)
inv1 = create(:budget_investment, :selected, budget: budget, group: group, heading: california)
inv2 = create(:budget_investment, :selected, budget: budget, group: group, heading: new_york)
ballot = create(:budget_ballot, user: user, budget: budget)
ballot.investments << inv1
expect(inv2.reason_for_not_being_ballotable_by(user, ballot)).to eq(:different_heading_assigned)
end
it "rejects proposals with price higher than current available money" do
budget.phase = "balloting"
districts = create(:budget_group, budget: budget)
carabanchel = create(:budget_heading, group: districts, price: 35)
inv1 = create(:budget_investment, :selected, budget: budget, group: districts, heading: carabanchel, price: 30)
inv2 = create(:budget_investment, :selected, budget: budget, group: districts, heading: carabanchel, price: 10)
ballot = create(:budget_ballot, user: user, budget: budget)
ballot.investments << inv1
expect(inv2.reason_for_not_being_ballotable_by(user, ballot)).to eq(:not_enough_money)
end
end
end
end
end

View File

@@ -0,0 +1,90 @@
require 'rails_helper'
describe Budget do
describe "description" do
it "changes depending on the phase" do
budget = create(:budget)
Budget::PHASES.each do |phase|
budget.phase = phase
expect(budget.description).to eq(budget.send("description_#{phase}"))
expect(budget.description).to be_html_safe
end
end
end
describe "phase" do
let(:budget) { create(:budget) }
it "is validated" do
Budget::PHASES.each do |phase|
budget.phase = phase
expect(budget).to be_valid
end
budget.phase = 'inexisting'
expect(budget).to_not be_valid
end
it "produces auxiliary methods" do
budget.phase = "accepting"
expect(budget).to be_accepting
budget.phase = "reviewing"
expect(budget).to be_reviewing
budget.phase = "selecting"
expect(budget).to be_selecting
budget.phase = "valuating"
expect(budget).to be_valuating
budget.phase = "balloting"
expect(budget).to be_balloting
budget.phase = "reviewing_ballots"
expect(budget).to be_reviewing_ballots
budget.phase = "finished"
expect(budget).to be_finished
end
end
describe "heading_price" do
let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) }
it "returns the heading price if the heading provided is part of the budget" do
heading = create(:budget_heading, price: 100, group: group)
expect(budget.heading_price(heading)).to eq(100)
end
it "returns -1 if the heading provided is not part of the budget" do
expect(budget.heading_price(create(:budget_heading))).to eq(-1)
end
end
describe "investments_orders" do
let(:budget) { create(:budget) }
it "is random when accepting and reviewing" do
budget.phase = 'accepting'
expect(budget.investments_orders).to eq(['random'])
budget.phase = 'reviewing'
expect(budget.investments_orders).to eq(['random'])
end
it "is random and price when ballotting and reviewing ballots" do
budget.phase = 'balloting'
expect(budget.investments_orders).to eq(['random', 'price'])
budget.phase = 'reviewing_ballots'
expect(budget.investments_orders).to eq(['random', 'price'])
end
it "is random and confidence_score in all other cases" do
budget.phase = 'selecting'
expect(budget.investments_orders).to eq(['random', 'confidence_score'])
budget.phase = 'valuating'
expect(budget.investments_orders).to eq(['random', 'confidence_score'])
end
end
end

View File

@@ -123,7 +123,7 @@ describe Proposal do
expect(proposal).to_not be_valid
end
it "should be valid with a tag list of more than 6 elements" do
it "should be valid with a tag list of up to 6 elements" do
proposal.tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
expect(proposal).to be_valid
end

View File

@@ -27,7 +27,7 @@ describe Verification::Residence do
it "should validate user has allowed age" do
residence = Verification::Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"#{5.year.ago.year}"})
expect(residence).to_not be_valid
expect(residence.errors[:date_of_birth]).to include("You must be at least 16 years old")
expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate")
end
it "should validate uniquness of document_number" do

View File

@@ -290,6 +290,11 @@ describe SpendingProposal do
let(:city_sp) { create(:spending_proposal) }
let(:district_sp) { create(:spending_proposal, geozone: district) }
before(:each) do
Setting["feature.spending_proposals"] = true
Setting['feature.spending_proposal_features.voting_allowed'] = true
end
describe '#reason_for_not_being_votable_by' do
it "rejects not logged in users" do
expect(city_sp.reason_for_not_being_votable_by(nil)).to eq(:not_logged_in)
@@ -344,6 +349,9 @@ describe SpendingProposal do
describe "total votes" do
it "takes into account physical votes in addition to web votes" do
Setting["feature.spending_proposals"] = true
Setting['feature.spending_proposal_features.voting_allowed'] = true
sp = create(:spending_proposal)
sp.register_vote(create(:user, :level_two), true)
expect(sp.total_votes).to eq(1)

View File

@@ -22,6 +22,15 @@ describe TagCloud do
expect(tag_names(tag_cloud)).to contain_exactly('world hunger')
end
it "returns budget investment tags" do
create(:budget_investment, tag_list: 'participation')
create(:debate, tag_list: 'world hunger')
tag_cloud = TagCloud.new(Budget::Investment)
expect(tag_names(tag_cloud)).to contain_exactly('participation')
end
it "returns tags from last week" do
create(:proposal, tag_list: 'participation', created_at: 1.day.ago)
create(:proposal, tag_list: 'corruption', created_at: 2.weeks.ago)

View File

@@ -2,36 +2,36 @@ require 'rails_helper'
describe Verification::Management::Document do
describe "#valid_age?" do
it "returns false when the user is younger than sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31))
it "returns false when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be false
end
it "returns true when the user is sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day))
it "returns true when the user has the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 16.years.ago.month, 16.years.ago.day))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
end
it "returns true when the user is older than sixteen years old" do
census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31))
it "returns true when the user is older than the user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
end
end
describe "#under_sixteen?" do
it "returns true when the user is younger than sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true
describe "#under_age?" do
it "returns true when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_age?(census_response)).to be true
end
it "returns false when the user is sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
it "returns false when the user is user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, User.minimum_required_age.years.ago.month, User.minimum_required_age.years.ago.day))
expect(Verification::Management::Document.new.under_age?(census_response)).to be false
end
it "returns false when the user is older than sixteen years old" do
census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
it "returns false when the user is older than user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_age?(census_response)).to be false
end
end
end