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

@@ -22,38 +22,37 @@ describe PagesController do
get :show, id: :census_terms
expect(response).to be_ok
end
end
describe 'Provisional pages' do
it 'should include a opendata page' do
get :show, id: :opendata
it 'should include a accessibility page' do
get :show, id: :accessibility
expect(response).to be_ok
end
end
describe 'Info pages' do
it 'should include a how_it_works page' do
get :show, id: :how_it_works
describe 'More info pages' do
it 'should include a more info page' do
get :show, id: 'more_info/index'
expect(response).to be_ok
end
it 'should include a how_to_use page' do
get :show, id: :how_to_use
get :show, id: 'more_info/how_to_use/index'
expect(response).to be_ok
end
it 'should include a more_information page' do
get :show, id: :more_information
it 'should include a faq page' do
get :show, id: 'more_info/faq/index'
expect(response).to be_ok
end
it 'should include a participation page' do
get :show, id: :participation
it 'should include a participation facts page' do
get :show, id: 'more_info/participation/facts'
expect(response).to be_ok
end
it 'should include a accessibility page' do
get :show, id: :accessibility
it 'should include a participation world page' do
get :show, id: 'more_info/participation/world'
expect(response).to be_ok
end
end

View File

@@ -252,6 +252,21 @@ feature 'Admin budget investments' do
expect(page).to have_content("More schools")
end
scenario "Filtering by tag, display only valuation tags" do
investment1 = create(:budget_investment, budget: @budget, tag_list: 'Education')
investment2 = create(:budget_investment, budget: @budget, tag_list: 'Health')
investment1.set_tag_list_on(:valuation, 'Teachers')
investment2.set_tag_list_on(:valuation, 'Hospitals')
investment1.save
investment2.save
visit admin_budget_budget_investments_path(budget_id: @budget.id)
expect(page).to have_select("tag_name", options: ["All tags", "Hospitals", "Teachers"])
end
end
scenario 'Show' do

View File

@@ -84,7 +84,7 @@ feature 'Admin budgets' do
fill_in 'budget_name', with: 'M30 - Summer campaign'
fill_in 'budget_description_accepting', with: 'Budgeting for summer 2017 maintenance and improvements of the road M-30'
select 'Accepting proposals', from: 'budget[phase]'
select 'Accepting projects', from: 'budget[phase]'
click_button 'Create Participatory budget'

View File

@@ -19,20 +19,42 @@ feature 'Signature sheets' do
end
end
scenario 'Create' do
proposal = create(:proposal)
visit new_admin_signature_sheet_path
context 'Create' do
scenario 'Proposal' do
proposal = create(:proposal)
visit new_admin_signature_sheet_path
select "Citizen proposal", from: "signature_sheet_signable_type"
fill_in "signature_sheet_signable_id", with: proposal.id
fill_in "signature_sheet_document_numbers", with: "12345678Z, 99999999Z"
click_button "Create signature sheet"
select "Citizen proposal", from: "signature_sheet_signable_type"
fill_in "signature_sheet_signable_id", with: proposal.id
fill_in "signature_sheet_document_numbers", with: "12345678Z, 99999999Z"
click_button "Create signature sheet"
expect(page).to have_content "Signature sheet created successfully"
expect(page).to have_content "Signature sheet created successfully"
visit proposal_path(proposal)
visit proposal_path(proposal)
expect(page).to have_content "1 support"
end
scenario 'Budget Investment' do
investment = create(:budget_investment)
budget = investment.budget
budget.update(phase: 'selecting')
visit new_admin_signature_sheet_path
select "Investment", from: "signature_sheet_signable_type"
fill_in "signature_sheet_signable_id", with: investment.id
fill_in "signature_sheet_document_numbers", with: "12345678Z, 99999999Z"
click_button "Create signature sheet"
expect(page).to have_content "Signature sheet created successfully"
visit budget_investment_path(budget, investment)
expect(page).to have_content "1 support"
end
expect(page).to have_content "1 support"
end
scenario 'Errors on create' do

View File

@@ -315,6 +315,20 @@ feature 'Budget Investments' do
end
end
scenario "Author can destroy while on the accepting phase" do
user = create(:user, :level_two)
sp1 = create(:budget_investment, heading: heading, price: 10000, author: user)
login_as(user)
visit user_path(user, tab: :budget_investments)
within("#budget_investment_#{sp1.id}") do
expect(page).to have_content(sp1.title)
click_link('Delete')
end
visit user_path(user, tab: :budget_investments)
end
end
context "Selecting Phase" do
@@ -391,7 +405,7 @@ feature 'Budget Investments' do
budget.update(phase: "valuating")
end
scenario "Sidebar in show should display supports text and supports" do
scenario "Sidebar in show should display support text and count" do
investment = create(:budget_investment, :selected, budget: budget)
create(:vote, votable: investment)
@@ -403,8 +417,8 @@ feature 'Budget Investments' do
end
end
scenario "Index should display supports" do
investment = create(:budget_investment, :selected, budget: budget, heading: heading)
scenario "Index should display support count" do
investment = create(:budget_investment, budget: budget, heading: heading)
create(:vote, votable: investment)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -414,6 +428,18 @@ feature 'Budget Investments' do
end
end
scenario "Show should display support text and count" do
investment = create(:budget_investment, budget: budget, heading: heading)
create(:vote, votable: investment)
visit budget_investment_path(budget, investment)
within("#budget_investment_#{investment.id}") do
expect(page).to have_content "Supports"
expect(page).to have_content "1 support"
end
end
end
context "Balloting Phase" do
@@ -476,6 +502,8 @@ feature 'Budget Investments' do
expect(page).to have_content "€10,000"
end
scenario "Sidebar in show should display vote text" do
investment = create(:budget_investment, :selected, budget: budget)
visit budget_investment_path(budget, investment)
@@ -561,4 +589,4 @@ feature 'Budget Investments' do
end
end
end
end

View File

@@ -54,7 +54,7 @@ feature 'Debates' do
expect(page.html).to include "<title>#{debate.title}</title>"
within('.social-share-button') do
expect(page.all('a').count).to be(3) # Twitter, Facebook, Google+
expect(page.all('a').count).to be(4) # Twitter, Facebook, Google+, Telegram
end
end
@@ -640,6 +640,28 @@ feature 'Debates' do
end
end
scenario "Search by custom invalid date range", :js do
debate1 = create(:debate, created_at: 2.years.ago)
debate2 = create(:debate, created_at: 3.days.ago)
debate3 = create(:debate, created_at: 9.days.ago)
visit debates_path
click_link "Advanced search"
select "Customized", from: "js-advanced-search-date-min"
fill_in "advanced_search_date_min", with: "9"
fill_in "advanced_search_date_max", with: "444444444"
click_button "Filter"
within("#debates") do
expect(page).to have_css('.debate', count: 3)
expect(page).to have_content(debate1.title)
expect(page).to have_content(debate2.title)
expect(page).to have_content(debate3.title)
end
end
scenario "Search by multiple filters", :js do
ana = create :user, official_level: 1
john = create :user, official_level: 1

View File

@@ -137,6 +137,61 @@ feature 'Budget Investments' do
end
end
scenario "Listing - managers can see budgets in accepting phase" do
accepting_budget = create(:budget, phase: "accepting")
reviewing_budget = create(:budget, phase: "reviewing")
selecting_budget = create(:budget, phase: "selecting")
valuating_budget = create(:budget, phase: "valuating")
balloting_budget = create(:budget, phase: "balloting")
reviewing_ballots_budget = create(:budget, phase: "reviewing_ballots")
finished = create(:budget, phase: "finished")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Create budget investment"
expect(page).to have_content(accepting_budget.name)
expect(page).to_not have_content(reviewing_budget.name)
expect(page).to_not have_content(selecting_budget.name)
expect(page).to_not have_content(valuating_budget.name)
expect(page).to_not have_content(balloting_budget.name)
expect(page).to_not have_content(reviewing_ballots_budget.name)
expect(page).to_not have_content(finished.name)
end
scenario "Listing - admins can see budgets in accepting, reviewing and selecting phases" do
accepting_budget = create(:budget, phase: "accepting")
reviewing_budget = create(:budget, phase: "reviewing")
selecting_budget = create(:budget, phase: "selecting")
valuating_budget = create(:budget, phase: "valuating")
balloting_budget = create(:budget, phase: "balloting")
reviewing_ballots_budget = create(:budget, phase: "reviewing_ballots")
finished = create(:budget, phase: "finished")
visit root_path
click_link "Sign out"
admin = create(:administrator)
login_as(admin.user)
user = create(:user, :level_two)
login_managed_user(user)
visit management_sign_in_path
click_link "Create budget investment"
expect(page).to have_content(accepting_budget.name)
expect(page).to have_content(reviewing_budget.name)
expect(page).to have_content(selecting_budget.name)
expect(page).to_not have_content(valuating_budget.name)
expect(page).to_not have_content(balloting_budget.name)
expect(page).to_not have_content(reviewing_ballots_budget.name)
expect(page).to_not have_content(finished.name)
end
context "Supporting" do
scenario 'Supporting budget investments on behalf of someone in index view', :js do

View File

@@ -18,6 +18,7 @@ feature 'Users' do
fill_in 'user_username', with: 'pepe'
fill_in 'user_email', with: 'pepe@gmail.com'
select_date '31-December-1980', from: 'user_date_of_birth'
click_button 'Create user'
@@ -28,6 +29,7 @@ feature 'Users' do
expect(user).to be_level_three_verified
expect(user).to be_residence_verified
expect(user).to_not be_confirmed
expect(user.date_of_birth).to have_content (Date.new(1980,12,31))
sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1]
visit user_confirmation_path(confirmation_token: sent_token)

View File

@@ -63,7 +63,7 @@ feature 'Proposals' do
expect(page.html).to include "<title>#{proposal.title}</title>"
within('.social-share-button') do
expect(page.all('a').count).to be(3) # Twitter, Facebook, Google+
expect(page.all('a').count).to be(4) # Twitter, Facebook, Google+, Telegram
end
end
@@ -980,6 +980,28 @@ feature 'Proposals' do
end
end
scenario "Search by custom invalid date range", :js do
proposal1 = create(:proposal, created_at: 2.days.ago)
proposal2 = create(:proposal, created_at: 3.days.ago)
proposal3 = create(:proposal, created_at: 9.days.ago)
visit proposals_path
click_link "Advanced search"
select "Customized", from: "js-advanced-search-date-min"
fill_in "advanced_search_date_min", with: 4000.years.ago
fill_in "advanced_search_date_max", with: "wrong date"
click_button "Filter"
expect(page).to have_content("There are 3 citizen proposals")
within("#proposals") do
expect(page).to have_content(proposal1.title)
expect(page).to have_content(proposal2.title)
expect(page).to have_content(proposal3.title)
end
end
scenario "Search by multiple filters", :js do
ana = create :user, official_level: 1
john = create :user, official_level: 1

View File

@@ -13,6 +13,12 @@ feature 'Valuation budget investments' do
expect{ visit valuation_budget_budget_investments_path(create(:budget)) }.to raise_exception(FeatureFlags::FeatureDisabled)
end
scenario 'Display link to valuation section' do
Setting['feature.budgets'] = true
visit root_path
expect(page).to have_link "Valuation", href: valuation_root_path
end
scenario 'Index shows budget investments assigned to current valuator' do
investment1 = create(:budget_investment, budget: @budget)
investment2 = create(:budget_investment, budget: @budget)

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