Remove isolated useless assignments
These variables can be considered a block, and so removing them doesn't make the test much harder to undestand. Sometimes these variables formed the setup, sometimes they formed an isolated part of the setup, and sometimes they were the part of the test that made the test different from other tests.
This commit is contained in:
@@ -64,9 +64,9 @@ describe Admin::Api::StatsController do
|
|||||||
time_1 = Time.zone.local(2017, 04, 01)
|
time_1 = Time.zone.local(2017, 04, 01)
|
||||||
time_2 = Time.zone.local(2017, 04, 02)
|
time_2 = Time.zone.local(2017, 04, 02)
|
||||||
|
|
||||||
budget_investment1 = create(:budget_investment, created_at: time_1)
|
create(:budget_investment, created_at: time_1)
|
||||||
budget_investment2 = create(:budget_investment, created_at: time_2)
|
create(:budget_investment, created_at: time_2)
|
||||||
budget_investment3 = create(:budget_investment, created_at: time_2)
|
create(:budget_investment, created_at: time_2)
|
||||||
|
|
||||||
sign_in user
|
sign_in user
|
||||||
get :show, params: { budget_investments: true }
|
get :show, params: { budget_investments: true }
|
||||||
|
|||||||
@@ -175,14 +175,15 @@ describe "Admin booths assignments" do
|
|||||||
poll = create(:poll, starts_at: 2.weeks.ago, ends_at: 1.week.ago)
|
poll = create(:poll, starts_at: 2.weeks.ago, ends_at: 1.week.ago)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth)
|
||||||
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||||
officer_assignment_1 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.starts_at)
|
|
||||||
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.ends_at)
|
create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.starts_at)
|
||||||
final_officer_assignment = create(:poll_officer_assignment, :final, booth_assignment: booth_assignment, date: poll.ends_at)
|
create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.ends_at)
|
||||||
|
create(:poll_officer_assignment, :final, booth_assignment: booth_assignment, date: poll.ends_at)
|
||||||
|
|
||||||
create(:poll_voter, poll: poll, booth_assignment: booth_assignment, created_at: poll.starts_at.to_date)
|
create(:poll_voter, poll: poll, booth_assignment: booth_assignment, created_at: poll.starts_at.to_date)
|
||||||
create(:poll_voter, poll: poll, booth_assignment: booth_assignment, created_at: poll.ends_at.to_date)
|
create(:poll_voter, poll: poll, booth_assignment: booth_assignment, created_at: poll.ends_at.to_date)
|
||||||
|
|
||||||
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
|
create(:poll_booth_assignment, poll: poll)
|
||||||
|
|
||||||
visit admin_poll_path(poll)
|
visit admin_poll_path(poll)
|
||||||
click_link "Booths (2)"
|
click_link "Booths (2)"
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ describe "Admin shifts" do
|
|||||||
booth1 = create(:poll_booth)
|
booth1 = create(:poll_booth)
|
||||||
booth2 = create(:poll_booth)
|
booth2 = create(:poll_booth)
|
||||||
|
|
||||||
shift1 = create(:poll_shift, officer: officer, booth: booth1, date: Date.current)
|
create(:poll_shift, officer: officer, booth: booth1, date: Date.current)
|
||||||
shift2 = create(:poll_shift, officer: officer, booth: booth2, date: Time.zone.tomorrow)
|
create(:poll_shift, officer: officer, booth: booth2, date: Time.zone.tomorrow)
|
||||||
|
|
||||||
visit new_admin_booth_shift_path(booth1)
|
visit new_admin_booth_shift_path(booth1)
|
||||||
|
|
||||||
@@ -99,8 +99,8 @@ describe "Admin shifts" do
|
|||||||
booth = create(:poll_booth, polls: [poll])
|
booth = create(:poll_booth, polls: [poll])
|
||||||
officer = create(:poll_officer)
|
officer = create(:poll_officer)
|
||||||
|
|
||||||
shift1 = create(:poll_shift, :vote_collection_task, officer: officer, booth: booth, date: Date.current)
|
create(:poll_shift, :vote_collection_task, officer: officer, booth: booth, date: Date.current)
|
||||||
shift2 = create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth, date: Time.zone.tomorrow)
|
create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth, date: Time.zone.tomorrow)
|
||||||
|
|
||||||
vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a
|
vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a
|
||||||
.reject { |date| date == Date.current }
|
.reject { |date| date == Date.current }
|
||||||
@@ -243,7 +243,7 @@ describe "Admin shifts" do
|
|||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth)
|
||||||
officer = create(:poll_officer)
|
officer = create(:poll_officer)
|
||||||
|
|
||||||
shift = create(:poll_shift, officer: officer, booth: booth)
|
create(:poll_shift, officer: officer, booth: booth)
|
||||||
officer.destroy
|
officer.destroy
|
||||||
|
|
||||||
visit new_admin_booth_shift_path(booth)
|
visit new_admin_booth_shift_path(booth)
|
||||||
|
|||||||
@@ -1377,8 +1377,8 @@ describe "Budget Investments" do
|
|||||||
|
|
||||||
group2 = create(:budget_group, budget: budget)
|
group2 = create(:budget_group, budget: budget)
|
||||||
another_heading1 = create(:budget_heading, group: group2)
|
another_heading1 = create(:budget_heading, group: group2)
|
||||||
another_heading2 = create(:budget_heading, group: group2)
|
|
||||||
|
|
||||||
|
create(:budget_heading, group: group2)
|
||||||
create(:budget_investment, heading: heading, title: "Investment", voters: [author])
|
create(:budget_investment, heading: heading, title: "Investment", voters: [author])
|
||||||
create(:budget_investment, heading: another_heading1, title: "Another investment")
|
create(:budget_investment, heading: another_heading1, title: "Another investment")
|
||||||
|
|
||||||
|
|||||||
@@ -51,9 +51,10 @@ describe "Communities" do
|
|||||||
topic1 = create(:topic, community: community)
|
topic1 = create(:topic, community: community)
|
||||||
topic2 = create(:topic, community: community)
|
topic2 = create(:topic, community: community)
|
||||||
topic3 = create(:topic, community: community)
|
topic3 = create(:topic, community: community)
|
||||||
topic1_comment = create(:comment, commentable: topic1)
|
|
||||||
topic3_comment = create(:comment, commentable: topic3)
|
create(:comment, :with_confidence_score, commentable: topic1)
|
||||||
topic3_comment = create(:comment, commentable: topic3)
|
create(:comment, :with_confidence_score, commentable: topic3)
|
||||||
|
create(:comment, :with_confidence_score, commentable: topic3)
|
||||||
|
|
||||||
visit community_path(community, order: :most_commented)
|
visit community_path(community, order: :most_commented)
|
||||||
|
|
||||||
|
|||||||
@@ -957,10 +957,10 @@ describe "Debates" do
|
|||||||
proposal = create(:proposal, tag_list: "Sport")
|
proposal = create(:proposal, tag_list: "Sport")
|
||||||
user = create(:user, recommended_debates: true, followables: [proposal])
|
user = create(:user, recommended_debates: true, followables: [proposal])
|
||||||
|
|
||||||
debate1 = create(:debate, title: "Show you got", cached_votes_total: 10, tag_list: "Sport")
|
create(:debate, title: "Show you got", cached_votes_total: 10, tag_list: "Sport")
|
||||||
debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport")
|
create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport")
|
||||||
debate3 = create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport")
|
create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport")
|
||||||
debate4 = create(:debate, title: "Do not display", cached_votes_total: 1)
|
create(:debate, title: "Do not display", cached_votes_total: 1)
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debates_path
|
visit debates_path
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ describe "Voters" do
|
|||||||
booth1 = create(:poll_booth)
|
booth1 = create(:poll_booth)
|
||||||
booth2 = create(:poll_booth)
|
booth2 = create(:poll_booth)
|
||||||
|
|
||||||
officer_assignment1 = create(:poll_officer_assignment, officer: officer, poll: poll1, booth: booth1)
|
create(:poll_officer_assignment, officer: officer, poll: poll1, booth: booth1)
|
||||||
officer_assignment2 = create(:poll_officer_assignment, officer: officer, poll: poll2, booth: booth2)
|
create(:poll_officer_assignment, officer: officer, poll: poll2, booth: booth2)
|
||||||
|
|
||||||
set_officing_booth(booth1)
|
set_officing_booth(booth1)
|
||||||
visit new_officing_residence_path
|
visit new_officing_residence_path
|
||||||
|
|||||||
@@ -176,9 +176,9 @@ describe "Consul Schema" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "only retruns tags with kind nil or category" do
|
it "only retruns tags with kind nil or category" do
|
||||||
tag = create(:tag, name: "Parks")
|
create(:tag, name: "Parks")
|
||||||
category_tag = create(:tag, :category, name: "Health")
|
create(:tag, :category, name: "Health")
|
||||||
admin_tag = create(:tag, name: "Admin tag", kind: "admin")
|
create(:tag, name: "Admin tag", kind: "admin")
|
||||||
|
|
||||||
proposal = create(:proposal, tag_list: "Parks, Health, Admin tag")
|
proposal = create(:proposal, tag_list: "Parks, Health, Admin tag")
|
||||||
|
|
||||||
@@ -244,9 +244,9 @@ describe "Consul Schema" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "only retruns tags with kind nil or category" do
|
it "only retruns tags with kind nil or category" do
|
||||||
tag = create(:tag, name: "Parks")
|
create(:tag, name: "Parks")
|
||||||
category_tag = create(:tag, :category, name: "Health")
|
create(:tag, :category, name: "Health")
|
||||||
admin_tag = create(:tag, name: "Admin tag", kind: "admin")
|
create(:tag, name: "Admin tag", kind: "admin")
|
||||||
|
|
||||||
debate = create(:debate, tag_list: "Parks, Health, Admin tag")
|
debate = create(:debate, tag_list: "Parks, Health, Admin tag")
|
||||||
|
|
||||||
|
|||||||
@@ -115,12 +115,10 @@ describe Budget::Ballot do
|
|||||||
it "returns nil if there are no headings with balloted investments in a group" do
|
it "returns nil if there are no headings with balloted investments in a group" do
|
||||||
budget = create(:budget)
|
budget = create(:budget)
|
||||||
group = create(:budget_group, budget: budget)
|
group = create(:budget_group, budget: budget)
|
||||||
|
|
||||||
heading1 = create(:budget_heading, group: group)
|
|
||||||
heading2 = create(:budget_heading, group: group)
|
|
||||||
|
|
||||||
ballot = create(:budget_ballot, budget: budget)
|
ballot = create(:budget_ballot, budget: budget)
|
||||||
|
|
||||||
|
2.times { create(:budget_heading, group: group) }
|
||||||
|
|
||||||
expect(ballot.heading_for_group(group)).to eq nil
|
expect(ballot.heading_for_group(group)).to eq nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -822,20 +822,21 @@ describe Budget::Investment do
|
|||||||
carabanchel = create(:budget_heading, group: group)
|
carabanchel = create(:budget_heading, group: group)
|
||||||
salamanca = create(:budget_heading, group: group)
|
salamanca = create(:budget_heading, group: group)
|
||||||
|
|
||||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
create(:budget_investment, heading: carabanchel, voters: [user])
|
||||||
salamanca_investment = create(:budget_investment, heading: salamanca)
|
|
||||||
|
salamanca_investment = create(:budget_investment, heading: salamanca)
|
||||||
|
|
||||||
expect(salamanca_investment.valid_heading?(user)).to eq(false)
|
expect(salamanca_investment.valid_heading?(user)).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts votes in multiple headings of the same group" do
|
it "accepts votes in multiple headings of the same group" do
|
||||||
group.update(max_votable_headings: 2)
|
group.update(max_votable_headings: 2)
|
||||||
|
|
||||||
carabanchel = create(:budget_heading, group: group)
|
carabanchel = create(:budget_heading, group: group)
|
||||||
salamanca = create(:budget_heading, group: group)
|
salamanca = create(:budget_heading, group: group)
|
||||||
|
|
||||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
create(:budget_investment, heading: carabanchel, voters: [user])
|
||||||
salamanca_investment = create(:budget_investment, heading: salamanca)
|
|
||||||
|
salamanca_investment = create(:budget_investment, heading: salamanca)
|
||||||
|
|
||||||
expect(salamanca_investment.valid_heading?(user)).to eq(true)
|
expect(salamanca_investment.valid_heading?(user)).to eq(true)
|
||||||
end
|
end
|
||||||
@@ -855,35 +856,38 @@ describe Budget::Investment do
|
|||||||
|
|
||||||
it "allows votes in a group with a single heading" do
|
it "allows votes in a group with a single heading" do
|
||||||
all_city_investment = create(:budget_investment, heading: heading)
|
all_city_investment = create(:budget_investment, heading: heading)
|
||||||
|
|
||||||
expect(all_city_investment.valid_heading?(user)).to eq(true)
|
expect(all_city_investment.valid_heading?(user)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows votes in a group with a single heading after voting in that heading" do
|
it "allows votes in a group with a single heading after voting in that heading" do
|
||||||
all_city_investment1 = create(:budget_investment, heading: heading, voters: [user])
|
create(:budget_investment, heading: heading, voters: [user])
|
||||||
all_city_investment2 = create(:budget_investment, heading: heading)
|
|
||||||
|
|
||||||
expect(all_city_investment2.valid_heading?(user)).to eq(true)
|
investment_for_same_heading = create(:budget_investment, heading: heading)
|
||||||
|
|
||||||
|
expect(investment_for_same_heading.valid_heading?(user)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows votes in a group with a single heading after voting in another group" do
|
it "allows votes in a group with a single heading after voting in another group" do
|
||||||
districts = create(:budget_group, budget: budget)
|
districts = create(:budget_group, budget: budget)
|
||||||
carabanchel = create(:budget_heading, group: districts)
|
carabanchel = create(:budget_heading, group: districts)
|
||||||
|
|
||||||
all_city_investment = create(:budget_investment, heading: heading)
|
create(:budget_investment, heading: carabanchel, voters: [user])
|
||||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
|
||||||
|
|
||||||
expect(all_city_investment.valid_heading?(user)).to eq(true)
|
investment_from_different_group = create(:budget_investment, heading: heading)
|
||||||
|
|
||||||
|
expect(investment_from_different_group.valid_heading?(user)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows votes in a group with multiple headings after voting in group with a single heading" do
|
it "allows votes in a group with multiple headings after voting in group with a single heading" do
|
||||||
districts = create(:budget_group, budget: budget)
|
districts = create(:budget_group, budget: budget)
|
||||||
carabanchel = create(:budget_heading, group: districts)
|
2.times { create(:budget_heading, group: districts) }
|
||||||
salamanca = create(:budget_heading, group: districts)
|
|
||||||
|
|
||||||
all_city_investment = create(:budget_investment, heading: heading, voters: [user])
|
create(:budget_investment, heading: heading, voters: [user])
|
||||||
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
|
||||||
|
|
||||||
expect(carabanchel_investment.valid_heading?(user)).to eq(true)
|
investment = create(:budget_investment, heading: districts.headings.sample)
|
||||||
|
|
||||||
|
expect(investment.valid_heading?(user)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#can_vote_in_another_heading?" do
|
describe "#can_vote_in_another_heading?" do
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ RSpec.describe Community, type: :model do
|
|||||||
topic1 = create(:topic, community: community, author: user1)
|
topic1 = create(:topic, community: community, author: user1)
|
||||||
create(:comment, commentable: topic1, author: user1)
|
create(:comment, commentable: topic1, author: user1)
|
||||||
create(:comment, commentable: topic1, author: user2)
|
create(:comment, commentable: topic1, author: user2)
|
||||||
topic2 = create(:topic, community: community, author: user2)
|
create(:topic, community: community, author: user2)
|
||||||
|
|
||||||
expect(community.participants).to match_array [user1, user2, proposal.author]
|
expect(community.participants).to match_array [user1, user2, proposal.author]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,19 +29,21 @@ describe Poll::Voter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid if the user has already voted in the same poll or booth_assignment" do
|
it "is not valid if the user has already voted in the same poll or booth_assignment" do
|
||||||
voter1 = create(:poll_voter, user: user, poll: poll)
|
create(:poll_voter, user: user, poll: poll)
|
||||||
voter2 = build(:poll_voter, user: user, poll: poll)
|
|
||||||
|
|
||||||
expect(voter2).not_to be_valid
|
voter = build(:poll_voter, user: user, poll: poll)
|
||||||
expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"])
|
|
||||||
|
expect(voter).not_to be_valid
|
||||||
|
expect(voter.errors.messages[:document_number]).to eq(["User has already voted"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid if the user has already voted in the same poll/booth" do
|
it "is not valid if the user has already voted in the same poll/booth" do
|
||||||
voter1 = create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
||||||
voter2 = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
|
||||||
|
|
||||||
expect(voter2).not_to be_valid
|
voter = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
||||||
expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"])
|
|
||||||
|
expect(voter).not_to be_valid
|
||||||
|
expect(voter.errors.messages[:document_number]).to eq(["User has already voted"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid if the user has already voted in different booth in the same poll" do
|
it "is not valid if the user has already voted in different booth in the same poll" do
|
||||||
|
|||||||
Reference in New Issue
Block a user