diff --git a/spec/controllers/admin/api/stats_controller_spec.rb b/spec/controllers/admin/api/stats_controller_spec.rb index cd95fe7a6..f45d5e59d 100644 --- a/spec/controllers/admin/api/stats_controller_spec.rb +++ b/spec/controllers/admin/api/stats_controller_spec.rb @@ -64,9 +64,9 @@ describe Admin::Api::StatsController do time_1 = Time.zone.local(2017, 04, 01) time_2 = Time.zone.local(2017, 04, 02) - budget_investment1 = create(:budget_investment, created_at: time_1) - budget_investment2 = create(:budget_investment, created_at: time_2) - budget_investment3 = create(:budget_investment, created_at: time_2) + create(:budget_investment, created_at: time_1) + create(:budget_investment, created_at: time_2) + create(:budget_investment, created_at: time_2) sign_in user get :show, params: { budget_investments: true } diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index b70e84da2..18e19186b 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -175,14 +175,15 @@ describe "Admin booths assignments" do poll = create(:poll, starts_at: 2.weeks.ago, ends_at: 1.week.ago) booth = create(:poll_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) - 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.starts_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.ends_at.to_date) - booth_assignment_2 = create(:poll_booth_assignment, poll: poll) + create(:poll_booth_assignment, poll: poll) visit admin_poll_path(poll) click_link "Booths (2)" diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 9b226b839..84ddada0d 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -13,8 +13,8 @@ describe "Admin shifts" do booth1 = create(:poll_booth) booth2 = create(:poll_booth) - shift1 = 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: booth1, date: Date.current) + create(:poll_shift, officer: officer, booth: booth2, date: Time.zone.tomorrow) visit new_admin_booth_shift_path(booth1) @@ -99,8 +99,8 @@ describe "Admin shifts" do booth = create(:poll_booth, polls: [poll]) officer = create(:poll_officer) - shift1 = 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, :vote_collection_task, officer: officer, booth: booth, date: Date.current) + 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 .reject { |date| date == Date.current } @@ -243,7 +243,7 @@ describe "Admin shifts" do booth = create(:poll_booth) officer = create(:poll_officer) - shift = create(:poll_shift, officer: officer, booth: booth) + create(:poll_shift, officer: officer, booth: booth) officer.destroy visit new_admin_booth_shift_path(booth) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 551150c51..b327d02c0 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1377,8 +1377,8 @@ describe "Budget Investments" do group2 = create(:budget_group, budget: budget) 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: another_heading1, title: "Another investment") diff --git a/spec/features/communities_spec.rb b/spec/features/communities_spec.rb index 5e67056d6..0ac369f8b 100644 --- a/spec/features/communities_spec.rb +++ b/spec/features/communities_spec.rb @@ -51,9 +51,10 @@ describe "Communities" do topic1 = create(:topic, community: community) topic2 = create(:topic, community: community) topic3 = create(:topic, community: community) - topic1_comment = create(:comment, commentable: topic1) - topic3_comment = create(:comment, commentable: topic3) - topic3_comment = create(:comment, commentable: topic3) + + create(:comment, :with_confidence_score, commentable: topic1) + create(:comment, :with_confidence_score, commentable: topic3) + create(:comment, :with_confidence_score, commentable: topic3) visit community_path(community, order: :most_commented) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 43ccafc59..3d16ee1d1 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -957,10 +957,10 @@ describe "Debates" do proposal = create(:proposal, tag_list: "Sport") user = create(:user, recommended_debates: true, followables: [proposal]) - debate1 = 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") - debate3 = 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: "Show you got", cached_votes_total: 10, tag_list: "Sport") + create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport") + create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport") + create(:debate, title: "Do not display", cached_votes_total: 1) login_as(user) visit debates_path diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 9c57a9d9c..167cb8443 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -140,8 +140,8 @@ describe "Voters" do booth1 = create(:poll_booth) booth2 = create(:poll_booth) - officer_assignment1 = 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: poll1, booth: booth1) + create(:poll_officer_assignment, officer: officer, poll: poll2, booth: booth2) set_officing_booth(booth1) visit new_officing_residence_path diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index 3b9523caa..66dec9825 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -176,9 +176,9 @@ describe "Consul Schema" do end it "only retruns tags with kind nil or category" do - tag = create(:tag, name: "Parks") - category_tag = create(:tag, :category, name: "Health") - admin_tag = create(:tag, name: "Admin tag", kind: "admin") + create(:tag, name: "Parks") + create(:tag, :category, name: "Health") + create(:tag, name: "Admin tag", kind: "admin") proposal = create(:proposal, tag_list: "Parks, Health, Admin tag") @@ -244,9 +244,9 @@ describe "Consul Schema" do end it "only retruns tags with kind nil or category" do - tag = create(:tag, name: "Parks") - category_tag = create(:tag, :category, name: "Health") - admin_tag = create(:tag, name: "Admin tag", kind: "admin") + create(:tag, name: "Parks") + create(:tag, :category, name: "Health") + create(:tag, name: "Admin tag", kind: "admin") debate = create(:debate, tag_list: "Parks, Health, Admin tag") diff --git a/spec/models/budget/ballot_spec.rb b/spec/models/budget/ballot_spec.rb index bcfcc6c28..9d2f3e547 100644 --- a/spec/models/budget/ballot_spec.rb +++ b/spec/models/budget/ballot_spec.rb @@ -115,12 +115,10 @@ describe Budget::Ballot do it "returns nil if there are no headings with balloted investments in a group" do budget = create(: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) + 2.times { create(:budget_heading, group: group) } + expect(ballot.heading_for_group(group)).to eq nil end diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index d1b1acf6d..145689bba 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -822,20 +822,21 @@ describe Budget::Investment do carabanchel = create(:budget_heading, group: group) salamanca = create(:budget_heading, group: group) - carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user]) - salamanca_investment = create(:budget_investment, heading: salamanca) + create(:budget_investment, heading: carabanchel, voters: [user]) + + salamanca_investment = create(:budget_investment, heading: salamanca) expect(salamanca_investment.valid_heading?(user)).to eq(false) end it "accepts votes in multiple headings of the same group" do group.update(max_votable_headings: 2) - carabanchel = create(:budget_heading, group: group) salamanca = create(:budget_heading, group: group) - carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user]) - salamanca_investment = create(:budget_investment, heading: salamanca) + create(:budget_investment, heading: carabanchel, voters: [user]) + + salamanca_investment = create(:budget_investment, heading: salamanca) expect(salamanca_investment.valid_heading?(user)).to eq(true) end @@ -855,35 +856,38 @@ describe Budget::Investment do 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, voters: [user]) - all_city_investment2 = create(:budget_investment, heading: heading) + create(:budget_investment, heading: heading, voters: [user]) - 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 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, voters: [user]) + 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 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) + 2.times { create(:budget_heading, group: districts) } - all_city_investment = create(:budget_investment, heading: heading, voters: [user]) - carabanchel_investment = create(:budget_investment, heading: carabanchel) + create(:budget_investment, heading: heading, voters: [user]) - 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 describe "#can_vote_in_another_heading?" do diff --git a/spec/models/community_spec.rb b/spec/models/community_spec.rb index b17c4d449..90ac3279f 100644 --- a/spec/models/community_spec.rb +++ b/spec/models/community_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Community, type: :model do topic1 = create(:topic, community: community, author: user1) create(:comment, commentable: topic1, author: user1) 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] end diff --git a/spec/models/poll/voter_spec.rb b/spec/models/poll/voter_spec.rb index 017ec76e8..88cdc02ce 100644 --- a/spec/models/poll/voter_spec.rb +++ b/spec/models/poll/voter_spec.rb @@ -29,19 +29,21 @@ describe Poll::Voter do end 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) - voter2 = build(:poll_voter, user: user, poll: poll) + create(:poll_voter, user: user, poll: poll) - expect(voter2).not_to be_valid - expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"]) + voter = build(:poll_voter, user: user, poll: poll) + + expect(voter).not_to be_valid + expect(voter.errors.messages[:document_number]).to eq(["User has already voted"]) end 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) - voter2 = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment) + create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment) - expect(voter2).not_to be_valid - expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"]) + voter = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment) + + expect(voter).not_to be_valid + expect(voter.errors.messages[:document_number]).to eq(["User has already voted"]) end it "is not valid if the user has already voted in different booth in the same poll" do