Simplify creating voters in specs
This commit is contained in:
@@ -183,6 +183,12 @@ FactoryBot.define do
|
||||
trait :with_image do
|
||||
after(:create) { |investment| create(:image, imageable: investment) }
|
||||
end
|
||||
|
||||
transient { voters { [] } }
|
||||
|
||||
after(:create) do |investment, evaluator|
|
||||
evaluator.voters.each { |voter| create(:vote, votable: investment, voter: voter) }
|
||||
end
|
||||
end
|
||||
|
||||
factory :budget_phase, class: "Budget::Phase" do
|
||||
|
||||
@@ -35,5 +35,11 @@ FactoryBot.define do
|
||||
valuation.commentable.valuators << valuator
|
||||
end
|
||||
end
|
||||
|
||||
transient { voters { [] } }
|
||||
|
||||
after(:create) do |comment, evaluator|
|
||||
evaluator.voters.each { |voter| create(:vote, votable: comment, voter: voter) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,6 +37,12 @@ FactoryBot.define do
|
||||
4.times { create(:vote, votable: debate) }
|
||||
end
|
||||
end
|
||||
|
||||
transient { voters { [] } }
|
||||
|
||||
after(:create) do |debate, evaluator|
|
||||
evaluator.voters.each { |voter| create(:vote, votable: debate, voter: voter) }
|
||||
end
|
||||
end
|
||||
|
||||
factory :flag do
|
||||
|
||||
@@ -78,6 +78,12 @@ FactoryBot.define do
|
||||
after(:create) { |proposal| create(:image, imageable: proposal) }
|
||||
end
|
||||
|
||||
transient { voters { [] } }
|
||||
|
||||
after(:create) do |proposal, evaluator|
|
||||
evaluator.voters.each { |voter| create(:vote, votable: proposal, voter: voter) }
|
||||
end
|
||||
|
||||
factory :retired_proposal, traits: [:retired]
|
||||
end
|
||||
|
||||
|
||||
@@ -63,6 +63,12 @@ FactoryBot.define do
|
||||
trait :with_comment do
|
||||
after(:create) { |user| create(:comment, author: user) }
|
||||
end
|
||||
|
||||
transient { votables { [] } }
|
||||
|
||||
after(:create) do |user, evaluator|
|
||||
evaluator.votables.each { |votable| create(:vote, votable: votable, voter: user) }
|
||||
end
|
||||
end
|
||||
|
||||
factory :identity do
|
||||
|
||||
@@ -25,14 +25,9 @@ describe "Stats" do
|
||||
end
|
||||
|
||||
scenario "Votes" do
|
||||
debate = create(:debate)
|
||||
create(:vote, votable: debate)
|
||||
|
||||
proposal = create(:proposal)
|
||||
2.times { create(:vote, votable: proposal) }
|
||||
|
||||
comment = create(:comment)
|
||||
3.times { create(:vote, votable: comment) }
|
||||
create(:debate, voters: Array.new(1) { create(:user) })
|
||||
create(:proposal, voters: Array.new(2) { create(:user) })
|
||||
create(:comment, voters: Array.new(3) { create(:user) })
|
||||
|
||||
visit admin_stats_path
|
||||
|
||||
@@ -113,11 +108,9 @@ describe "Stats" do
|
||||
|
||||
scenario "Number of supports in investment projects" do
|
||||
group_2 = create(:budget_group, budget: @budget)
|
||||
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
|
||||
investment2 = create(:budget_investment, heading: @heading_all_city)
|
||||
|
||||
1.times { create(:vote, votable: investment1) }
|
||||
2.times { create(:vote, votable: investment2) }
|
||||
create(:budget_investment, heading: create(:budget_heading, group: group_2), voters: [create(:user)])
|
||||
create(:budget_investment, heading: @heading_all_city, voters: [create(:user), create(:user)])
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Participatory Budgets"
|
||||
@@ -129,17 +122,13 @@ describe "Stats" do
|
||||
end
|
||||
|
||||
scenario "Number of users that have supported an investment project" do
|
||||
user1 = create(:user, :level_two)
|
||||
user2 = create(:user, :level_two)
|
||||
user3 = create(:user, :level_two)
|
||||
|
||||
group_2 = create(:budget_group, budget: @budget)
|
||||
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
|
||||
investment2 = create(:budget_investment, heading: @heading_all_city)
|
||||
|
||||
create(:vote, votable: investment1, voter: user1)
|
||||
create(:vote, votable: investment1, voter: user2)
|
||||
create(:vote, votable: investment2, voter: user1)
|
||||
create(:user, :level_two, votables: [investment1, investment2])
|
||||
create(:user, :level_two, votables: [investment1])
|
||||
create(:user, :level_two)
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Participatory Budgets"
|
||||
@@ -160,13 +149,9 @@ describe "Stats" do
|
||||
carabanchel = create(:budget_heading, group: group_districts)
|
||||
barajas = create(:budget_heading, group: group_districts)
|
||||
|
||||
all_city_investment = create(:budget_investment, heading: all_city)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||
|
||||
Budget::Investment.all.each do |investment|
|
||||
create(:vote, votable: investment)
|
||||
end
|
||||
create(:budget_investment, heading: all_city, voters: [create(:user)])
|
||||
create(:budget_investment, heading: carabanchel, voters: [create(:user)])
|
||||
create(:budget_investment, heading: carabanchel, voters: [create(:user)])
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Participatory Budgets"
|
||||
|
||||
@@ -789,11 +789,8 @@ describe "Budget Investments" do
|
||||
|
||||
per_page.times { create(:budget_investment, heading: heading) }
|
||||
|
||||
voted_investments = []
|
||||
per_page.times do
|
||||
investment = create(:budget_investment, heading: heading)
|
||||
create(:vote, votable: investment, voter: voter)
|
||||
voted_investments << investment
|
||||
voted_investments = Array.new(per_page) do
|
||||
create(:budget_investment, heading: heading, voters: [voter])
|
||||
end
|
||||
|
||||
login_as(voter)
|
||||
@@ -1354,11 +1351,9 @@ describe "Budget Investments" do
|
||||
carabanchel = create(:budget_heading, group: group)
|
||||
salamanca = create(:budget_heading, group: group)
|
||||
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [author])
|
||||
salamanca_investment = create(:budget_investment, heading: salamanca)
|
||||
|
||||
create(:vote, votable: carabanchel_investment, voter: author)
|
||||
|
||||
login_as(author)
|
||||
visit budget_investments_path(budget, heading_id: carabanchel.id)
|
||||
|
||||
@@ -1374,11 +1369,9 @@ describe "Budget Investments" do
|
||||
another_heading1 = create(:budget_heading, group: group2)
|
||||
another_heading2 = create(:budget_heading, group: group2)
|
||||
|
||||
heading_investment = create(:budget_investment, heading: heading)
|
||||
heading_investment = create(:budget_investment, heading: heading, voters: [author])
|
||||
another_group_investment = create(:budget_investment, heading: another_heading1)
|
||||
|
||||
create(:vote, votable: heading_investment, voter: author)
|
||||
|
||||
login_as(author)
|
||||
visit budget_investments_path(budget, heading_id: another_heading1.id)
|
||||
|
||||
@@ -1417,8 +1410,7 @@ describe "Budget Investments" do
|
||||
end
|
||||
|
||||
scenario "Sidebar in show should display support text and count" do
|
||||
investment = create(:budget_investment, :selected, budget: budget)
|
||||
create(:vote, votable: investment)
|
||||
investment = create(:budget_investment, :selected, budget: budget, voters: [create(:user)])
|
||||
|
||||
visit budget_investment_path(budget, investment)
|
||||
|
||||
@@ -1429,8 +1421,7 @@ describe "Budget Investments" do
|
||||
end
|
||||
|
||||
scenario "Index should display support count" do
|
||||
investment = create(:budget_investment, budget: budget, heading: heading)
|
||||
create(:vote, votable: investment)
|
||||
investment = create(:budget_investment, budget: budget, heading: heading, voters: [create(:user)])
|
||||
|
||||
visit budget_investments_path(budget, heading_id: heading.id)
|
||||
|
||||
@@ -1440,8 +1431,7 @@ describe "Budget Investments" do
|
||||
end
|
||||
|
||||
scenario "Show should display support text and count" do
|
||||
investment = create(:budget_investment, budget: budget, heading: heading)
|
||||
create(:vote, votable: investment)
|
||||
investment = create(:budget_investment, budget: budget, heading: heading, voters: [create(:user)])
|
||||
|
||||
visit budget_investment_path(budget, investment)
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ describe "Votes" do
|
||||
describe "Index" do
|
||||
|
||||
scenario "Index shows user votes on proposals" do
|
||||
investment1 = create(:budget_investment, heading: heading)
|
||||
investment1 = create(:budget_investment, heading: heading, voters: [manuela])
|
||||
investment2 = create(:budget_investment, heading: heading)
|
||||
investment3 = create(:budget_investment, heading: heading)
|
||||
create(:vote, voter: manuela, votable: investment1, vote_flag: true)
|
||||
|
||||
visit budget_investments_path(budget, heading_id: heading.id)
|
||||
|
||||
|
||||
@@ -305,9 +305,8 @@ describe "Debates" do
|
||||
end
|
||||
|
||||
scenario "Update should not be posible if debate is not editable" do
|
||||
debate = create(:debate)
|
||||
Setting["max_votes_for_debate_edit"] = 2
|
||||
3.times { create(:vote, votable: debate) }
|
||||
debate = create(:debate, voters: Array.new(3) { create(:user) })
|
||||
|
||||
expect(debate).not_to be_editable
|
||||
login_as(debate.author)
|
||||
|
||||
@@ -258,13 +258,10 @@ describe "Emails" do
|
||||
scenario "notifications for proposals that I have supported" do
|
||||
user = create(:user, email_digest: true)
|
||||
|
||||
proposal1 = create(:proposal)
|
||||
proposal2 = create(:proposal)
|
||||
proposal1 = create(:proposal, voters: [user])
|
||||
proposal2 = create(:proposal, voters: [user])
|
||||
proposal3 = create(:proposal)
|
||||
|
||||
create(:vote, votable: proposal1, voter: user)
|
||||
create(:vote, votable: proposal2, voter: user)
|
||||
|
||||
reset_mailer
|
||||
|
||||
notification1 = create_proposal_notification(proposal1)
|
||||
|
||||
@@ -30,9 +30,7 @@ describe "Proposal Notifications" do
|
||||
scenario "Send a notification (Active voter)" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
voter = create(:user, :level_two)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
|
||||
create(:user, :level_two, votables: [proposal])
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(1)
|
||||
@@ -49,11 +47,10 @@ describe "Proposal Notifications" do
|
||||
end
|
||||
|
||||
scenario "Send a notification (Follower and Voter)" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
user_voter_follower = create(:user)
|
||||
proposal = create(:proposal, voters: [user_voter_follower])
|
||||
|
||||
create(:follow, :followed_proposal, user: user_voter_follower, followable: proposal)
|
||||
create(:vote, voter: user_voter_follower, votable: proposal)
|
||||
|
||||
user_follower = create(:user)
|
||||
create(:follow, :followed_proposal, user: user_follower, followable: proposal)
|
||||
@@ -65,11 +62,9 @@ describe "Proposal Notifications" do
|
||||
|
||||
scenario "Send a notification (Blocked voter)" do
|
||||
proposal = create(:proposal)
|
||||
voter = create(:user, :level_two, votables: [proposal])
|
||||
|
||||
voter = create(:user, :level_two)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
voter.block
|
||||
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(0)
|
||||
@@ -77,11 +72,9 @@ describe "Proposal Notifications" do
|
||||
|
||||
scenario "Send a notification (Erased voter)" do
|
||||
proposal = create(:proposal)
|
||||
voter = create(:user, :level_two, votables: [proposal])
|
||||
|
||||
voter = create(:user, :level_two)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
voter.erase
|
||||
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(0)
|
||||
@@ -153,11 +146,10 @@ describe "Proposal Notifications" do
|
||||
|
||||
scenario "Message about receivers (Same Followers and Voters)" do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
user_voter_follower = create(:user)
|
||||
proposal = create(:proposal, author: author, voters: [user_voter_follower])
|
||||
|
||||
create(:follow, :followed_proposal, user: user_voter_follower, followable: proposal)
|
||||
create(:vote, voter: user_voter_follower, votable: proposal)
|
||||
|
||||
login_as(author)
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
@@ -208,15 +200,11 @@ describe "Proposal Notifications" do
|
||||
|
||||
scenario "Voters should receive a notification", :js do
|
||||
author = create(:user)
|
||||
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
user3 = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user1, votable: proposal, vote_flag: true)
|
||||
create(:vote, voter: user2, votable: proposal, vote_flag: true)
|
||||
user1 = create(:user, votables: [proposal])
|
||||
user2 = create(:user, votables: [proposal])
|
||||
user3 = create(:user)
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
@@ -322,10 +310,7 @@ describe "Proposal Notifications" do
|
||||
scenario "Proposal hidden", :js do
|
||||
author = create(:user)
|
||||
user = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user, votable: proposal, vote_flag: true)
|
||||
proposal = create(:proposal, author: author, voters: [user])
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
@@ -357,10 +342,7 @@ describe "Proposal Notifications" do
|
||||
scenario "Proposal retired by author", :js do
|
||||
author = create(:user)
|
||||
user = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user, votable: proposal, vote_flag: true)
|
||||
proposal = create(:proposal, author: author, voters: [user])
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
|
||||
@@ -637,9 +637,8 @@ describe "Proposals" do
|
||||
end
|
||||
|
||||
scenario "Update should not be posible if proposal is not editable" do
|
||||
proposal = create(:proposal)
|
||||
Setting["max_votes_for_proposal_edit"] = 10
|
||||
11.times { create(:vote, votable: proposal) }
|
||||
Setting["max_votes_for_proposal_edit"] = 3
|
||||
proposal = create(:proposal, voters: Array.new(4) { create(:user) })
|
||||
|
||||
expect(proposal).not_to be_editable
|
||||
|
||||
|
||||
@@ -19,14 +19,9 @@ describe "Stats" do
|
||||
end
|
||||
|
||||
scenario "Votes" do
|
||||
debate = create(:debate)
|
||||
create(:vote, votable: debate)
|
||||
|
||||
proposal = create(:proposal)
|
||||
2.times { create(:vote, votable: proposal) }
|
||||
|
||||
comment = create(:comment)
|
||||
3.times { create(:vote, votable: comment) }
|
||||
create(:debate, voters: Array.new(1) { create(:user) })
|
||||
create(:proposal, voters: Array.new(2) { create(:user) })
|
||||
create(:comment, voters: Array.new(3) { create(:user) })
|
||||
|
||||
visit stats_path
|
||||
|
||||
|
||||
@@ -188,10 +188,9 @@ describe "Votes" do
|
||||
before { login_as(@manuela) }
|
||||
|
||||
scenario "Index shows user votes on proposals" do
|
||||
proposal1 = create(:proposal)
|
||||
proposal1 = create(:proposal, voters: [@manuela])
|
||||
proposal2 = create(:proposal)
|
||||
proposal3 = create(:proposal)
|
||||
create(:vote, voter: @manuela, votable: proposal1, vote_flag: true)
|
||||
|
||||
visit proposals_path
|
||||
|
||||
|
||||
@@ -189,8 +189,7 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "returns nested votes for a proposal" do
|
||||
proposal = create(:proposal)
|
||||
2.times { create(:vote, votable: proposal) }
|
||||
proposal = create(:proposal, voters: [create(:user), create(:user)])
|
||||
|
||||
response = execute("{ proposal(id: #{proposal.id}) { votes_for { edges { node { public_created_at } } } } }")
|
||||
|
||||
@@ -535,15 +534,10 @@ describe "Consul Schema" do
|
||||
describe "Votes" do
|
||||
|
||||
it "only returns votes from proposals, debates and comments" do
|
||||
proposal = create(:proposal)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment)
|
||||
budget_investment = create(:budget_investment)
|
||||
|
||||
proposal_vote = create(:vote, votable: proposal)
|
||||
debate_vote = create(:vote, votable: debate)
|
||||
comment_vote = create(:vote, votable: comment)
|
||||
budget_investment_vote = create(:vote, votable: budget_investment)
|
||||
create(:proposal, voters: [create(:user)])
|
||||
create(:debate, voters: [create(:user)])
|
||||
create(:comment, voters: [create(:user)])
|
||||
create(:budget_investment, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_type } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_type")
|
||||
@@ -552,11 +546,8 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "does not include votes from hidden debates" do
|
||||
visible_debate = create(:debate)
|
||||
hidden_debate = create(:debate, :hidden)
|
||||
|
||||
visible_debate_vote = create(:vote, votable: visible_debate)
|
||||
hidden_debate_vote = create(:vote, votable: hidden_debate)
|
||||
visible_debate = create(:debate, voters: [create(:user)])
|
||||
hidden_debate = create(:debate, :hidden, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_debates = extract_fields(response, "votes", "votable_id")
|
||||
@@ -565,11 +556,8 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "does not include votes of hidden proposals" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, :hidden)
|
||||
|
||||
visible_proposal_vote = create(:vote, votable: visible_proposal)
|
||||
hidden_proposal_vote = create(:vote, votable: hidden_proposal)
|
||||
visible_proposal = create(:proposal, voters: [create(:user)])
|
||||
hidden_proposal = create(:proposal, :hidden, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_proposals = extract_fields(response, "votes", "votable_id")
|
||||
@@ -578,11 +566,8 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "does not include votes of hidden comments" do
|
||||
visible_comment = create(:comment)
|
||||
hidden_comment = create(:comment, :hidden)
|
||||
|
||||
visible_comment_vote = create(:vote, votable: visible_comment)
|
||||
hidden_comment_vote = create(:vote, votable: hidden_comment)
|
||||
visible_comment = create(:comment, voters: [create(:user)])
|
||||
hidden_comment = create(:comment, :hidden, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_comments = extract_fields(response, "votes", "votable_id")
|
||||
@@ -594,11 +579,8 @@ describe "Consul Schema" do
|
||||
visible_proposal = create(:proposal)
|
||||
hidden_proposal = create(:proposal, :hidden)
|
||||
|
||||
visible_proposal_comment = create(:comment, commentable: visible_proposal)
|
||||
hidden_proposal_comment = create(:comment, commentable: hidden_proposal)
|
||||
|
||||
visible_proposal_comment_vote = create(:vote, votable: visible_proposal_comment)
|
||||
hidden_proposal_comment_vote = create(:vote, votable: hidden_proposal_comment)
|
||||
visible_proposal_comment = create(:comment, commentable: visible_proposal, voters: [create(:user)])
|
||||
hidden_proposal_comment = create(:comment, commentable: hidden_proposal, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
@@ -610,11 +592,8 @@ describe "Consul Schema" do
|
||||
visible_debate = create(:debate)
|
||||
hidden_debate = create(:debate, :hidden)
|
||||
|
||||
visible_debate_comment = create(:comment, commentable: visible_debate)
|
||||
hidden_debate_comment = create(:comment, commentable: hidden_debate)
|
||||
|
||||
visible_debate_comment_vote = create(:vote, votable: visible_debate_comment)
|
||||
hidden_debate_comment_vote = create(:vote, votable: hidden_debate_comment)
|
||||
visible_debate_comment = create(:comment, commentable: visible_debate, voters: [create(:user)])
|
||||
hidden_debate_comment = create(:comment, commentable: hidden_debate, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
@@ -623,10 +602,8 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "does not include votes of debates that are not public" do
|
||||
not_public_debate = create(:debate)
|
||||
allow(Vote).to receive(:public_for_api).and_return([])
|
||||
|
||||
not_public_debate_vote = create(:vote, votable: not_public_debate)
|
||||
not_public_debate = create(:debate, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
@@ -635,10 +612,8 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "does not include votes of a hidden proposals" do
|
||||
not_public_proposal = create(:proposal)
|
||||
allow(Vote).to receive(:public_for_api).and_return([])
|
||||
|
||||
not_public_proposal_vote = create(:vote, votable: not_public_proposal)
|
||||
not_public_proposal = create(:proposal, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
@@ -647,10 +622,8 @@ describe "Consul Schema" do
|
||||
end
|
||||
|
||||
it "does not include votes of a hidden comments" do
|
||||
not_public_comment = create(:comment)
|
||||
allow(Vote).to receive(:public_for_api).and_return([])
|
||||
|
||||
not_public_comment_vote = create(:vote, votable: not_public_comment)
|
||||
not_public_comment = create(:comment, voters: [create(:user)])
|
||||
|
||||
response = execute("{ votes { edges { node { votable_id } } } }")
|
||||
received_votables = extract_fields(response, "votes", "votable_id")
|
||||
|
||||
@@ -748,11 +748,9 @@ describe Budget::Investment do
|
||||
carabanchel = create(:budget_heading, group: group)
|
||||
salamanca = create(:budget_heading, group: group)
|
||||
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
||||
salamanca_investment = create(:budget_investment, heading: salamanca)
|
||||
|
||||
create(:vote, votable: carabanchel_investment, voter: user)
|
||||
|
||||
expect(salamanca_investment.valid_heading?(user)).to eq(false)
|
||||
end
|
||||
|
||||
@@ -762,11 +760,9 @@ describe Budget::Investment do
|
||||
carabanchel = create(:budget_heading, group: group)
|
||||
salamanca = create(:budget_heading, group: group)
|
||||
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
||||
salamanca_investment = create(:budget_investment, heading: salamanca)
|
||||
|
||||
create(:vote, votable: carabanchel_investment, voter: user)
|
||||
|
||||
expect(salamanca_investment.valid_heading?(user)).to eq(true)
|
||||
end
|
||||
|
||||
@@ -776,11 +772,8 @@ describe Budget::Investment 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)
|
||||
create(:vote, votable: salamanca_investment, voter: user)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
||||
salamanca_investment = create(:budget_investment, heading: salamanca, voters: [user])
|
||||
|
||||
expect(carabanchel_investment.valid_heading?(user)).to eq(true)
|
||||
expect(salamanca_investment.valid_heading?(user)).to eq(true)
|
||||
@@ -792,11 +785,9 @@ describe Budget::Investment do
|
||||
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_investment1 = create(:budget_investment, heading: heading, voters: [user])
|
||||
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
|
||||
|
||||
@@ -805,9 +796,7 @@ describe Budget::Investment do
|
||||
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)
|
||||
carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [user])
|
||||
|
||||
expect(all_city_investment.valid_heading?(user)).to eq(true)
|
||||
end
|
||||
@@ -817,11 +806,9 @@ describe Budget::Investment do
|
||||
carabanchel = create(:budget_heading, group: districts)
|
||||
salamanca = create(:budget_heading, group: districts)
|
||||
|
||||
all_city_investment = create(:budget_investment, heading: heading)
|
||||
all_city_investment = create(:budget_investment, heading: heading, voters: [user])
|
||||
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
|
||||
|
||||
@@ -929,9 +916,8 @@ describe Budget::Investment do
|
||||
|
||||
describe "#with_supports" do
|
||||
it "returns proposals with supports" do
|
||||
inv1 = create(:budget_investment)
|
||||
inv1 = create(:budget_investment, voters: [create(:user)])
|
||||
inv2 = create(:budget_investment)
|
||||
create(:vote, votable: inv1)
|
||||
|
||||
expect(Budget::Investment.with_supports).to eq [inv1]
|
||||
expect(Budget::Investment.with_supports).not_to include(inv2)
|
||||
|
||||
@@ -6,21 +6,17 @@ describe Budget::Stats do
|
||||
let(:investment) { create(:budget_investment, :selected, budget: budget) }
|
||||
|
||||
describe "#participants" do
|
||||
let(:author) { investment.author }
|
||||
let(:author_and_voter) { create(:user, :hidden) }
|
||||
let(:voter) { create(:user) }
|
||||
let(:voter_and_balloter) { create(:user) }
|
||||
let(:balloter) { create(:user, :hidden) }
|
||||
let(:poll_balloter) { create(:user, :level_two) }
|
||||
let(:non_participant) { create(:user, :level_two) }
|
||||
let!(:author) { investment.author }
|
||||
let!(:author_and_voter) { create(:user, :hidden, votables: [investment]) }
|
||||
let!(:voter) { create(:user, votables: [investment]) }
|
||||
let!(:voter_and_balloter) { create(:user, votables: [investment]) }
|
||||
let!(:balloter) { create(:user, :hidden) }
|
||||
let!(:poll_balloter) { create(:user, :level_two) }
|
||||
let!(:non_participant) { create(:user, :level_two) }
|
||||
|
||||
before do
|
||||
create(:budget_investment, :selected, budget: budget, author: author_and_voter)
|
||||
|
||||
create(:vote, votable: investment, voter: author_and_voter)
|
||||
create(:vote, votable: investment, voter: voter)
|
||||
create(:vote, votable: investment, voter: voter_and_balloter)
|
||||
|
||||
create(:budget_ballot_line, investment: investment, user: balloter)
|
||||
create(:budget_ballot_line, investment: investment, user: voter_and_balloter)
|
||||
|
||||
@@ -46,8 +42,7 @@ describe Budget::Stats do
|
||||
end
|
||||
|
||||
it "counts a user who is voter and balloter" do
|
||||
voter_and_balloter = create(:user)
|
||||
create(:vote, votable: investment, voter: voter_and_balloter)
|
||||
voter_and_balloter = create(:user, votables: [investment])
|
||||
create(:budget_ballot_line, investment: investment, user: voter_and_balloter)
|
||||
|
||||
expect(stats.total_participants_support_phase).to be 1
|
||||
@@ -63,8 +58,7 @@ describe Budget::Stats do
|
||||
end
|
||||
|
||||
it "counts a user who is voter and balloter" do
|
||||
voter_and_balloter = create(:user)
|
||||
create(:vote, votable: investment, voter: voter_and_balloter)
|
||||
voter_and_balloter = create(:user, votables: [investment])
|
||||
create(:budget_ballot_line, investment: investment, user: voter_and_balloter)
|
||||
|
||||
expect(stats.total_participants_vote_phase).to be 1
|
||||
|
||||
@@ -442,24 +442,19 @@ describe Proposal do
|
||||
|
||||
it "returns users that have voted for the proposal" do
|
||||
proposal = create(:proposal)
|
||||
voter1 = create(:user, :level_two)
|
||||
voter2 = create(:user, :level_two)
|
||||
voter1 = create(:user, :level_two, votables: [proposal])
|
||||
voter2 = create(:user, :level_two, votables: [proposal])
|
||||
voter3 = create(:user, :level_two)
|
||||
|
||||
create(:vote, voter: voter1, votable: proposal)
|
||||
create(:vote, voter: voter2, votable: proposal)
|
||||
|
||||
expect(proposal.voters).to match_array [voter1, voter2]
|
||||
expect(proposal.voters).not_to include(voter3)
|
||||
end
|
||||
|
||||
it "does not return users that have been erased" do
|
||||
proposal = create(:proposal)
|
||||
voter1 = create(:user, :level_two)
|
||||
voter2 = create(:user, :level_two)
|
||||
voter1 = create(:user, :level_two, votables: [proposal])
|
||||
voter2 = create(:user, :level_two, votables: [proposal])
|
||||
|
||||
create(:vote, voter: voter1, votable: proposal)
|
||||
create(:vote, voter: voter2, votable: proposal)
|
||||
voter2.erase
|
||||
|
||||
expect(proposal.voters).to eq [voter1]
|
||||
@@ -467,11 +462,9 @@ describe Proposal do
|
||||
|
||||
it "does not return users that have been blocked" do
|
||||
proposal = create(:proposal)
|
||||
voter1 = create(:user, :level_two)
|
||||
voter2 = create(:user, :level_two)
|
||||
voter1 = create(:user, :level_two, votables: [proposal])
|
||||
voter2 = create(:user, :level_two, votables: [proposal])
|
||||
|
||||
create(:vote, voter: voter1, votable: proposal)
|
||||
create(:vote, voter: voter2, votable: proposal)
|
||||
voter2.block
|
||||
|
||||
expect(proposal.voters).to eq [voter1]
|
||||
@@ -920,32 +913,28 @@ describe Proposal do
|
||||
|
||||
it "returns voters and followers" do
|
||||
proposal = create(:proposal)
|
||||
voter = create(:user, :level_two)
|
||||
voter = create(:user, :level_two, votables: [proposal])
|
||||
follower = create(:user, :level_two)
|
||||
follow = create(:follow, user: follower, followable: proposal)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
|
||||
expect(proposal.users_to_notify).to eq([voter, follower])
|
||||
end
|
||||
|
||||
it "returns voters and followers discarding duplicates" do
|
||||
proposal = create(:proposal)
|
||||
voter_and_follower = create(:user, :level_two)
|
||||
voter_and_follower = create(:user, :level_two, votables: [proposal])
|
||||
follow = create(:follow, user: voter_and_follower, followable: proposal)
|
||||
create(:vote, voter: voter_and_follower, votable: proposal)
|
||||
|
||||
expect(proposal.users_to_notify).to eq([voter_and_follower])
|
||||
end
|
||||
|
||||
it "returns voters and followers except the proposal author" do
|
||||
author = create(:user, :level_two)
|
||||
proposal = create(:proposal, author: author)
|
||||
voter_and_follower = create(:user, :level_two)
|
||||
proposal = create(:proposal, author: author, voters: [author])
|
||||
voter_and_follower = create(:user, :level_two, votables: [proposal])
|
||||
|
||||
create(:follow, user: author, followable: proposal)
|
||||
create(:follow, user: voter_and_follower, followable: proposal)
|
||||
create(:vote, voter: author, votable: proposal)
|
||||
create(:vote, voter: voter_and_follower, votable: proposal)
|
||||
|
||||
expect(proposal.users_to_notify).to eq([voter_and_follower])
|
||||
end
|
||||
@@ -1014,9 +1003,8 @@ describe Proposal do
|
||||
end
|
||||
|
||||
it "does not return already supported proposals" do
|
||||
proposal1 = create(:proposal, tag_list: "Health")
|
||||
proposal1 = create(:proposal, tag_list: "Health", voters: [user])
|
||||
proposal2 = create(:proposal, tag_list: "Health")
|
||||
create(:vote, votable: proposal1, voter: user)
|
||||
create(:follow, followable: proposal2, user: user)
|
||||
|
||||
results = Proposal.recommendations(user)
|
||||
|
||||
@@ -142,9 +142,8 @@ describe Signature do
|
||||
end
|
||||
|
||||
it "does not assign vote to user if already voted" do
|
||||
proposal = create(:proposal)
|
||||
user = create(:user, :level_two, document_number: "123A")
|
||||
vote = create(:vote, votable: proposal, voter: user)
|
||||
proposal = create(:proposal, voters: [user])
|
||||
signature_sheet = create(:signature_sheet, signable: proposal)
|
||||
signature = create(:signature, signature_sheet: signature_sheet, document_number: user.document_number)
|
||||
|
||||
@@ -154,9 +153,8 @@ describe Signature do
|
||||
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)
|
||||
investment = create(:budget_investment, voters: [user])
|
||||
|
||||
signature_sheet = create(:signature_sheet, signable: investment)
|
||||
signature = create(:signature, document_number: user.document_number, signature_sheet: signature_sheet)
|
||||
|
||||
@@ -4,9 +4,6 @@ describe User do
|
||||
|
||||
describe "#headings_voted_within_group" do
|
||||
it "returns the headings voted by a user" do
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
|
||||
@@ -19,9 +16,8 @@ describe User do
|
||||
san_franciso_investment = create(:budget_investment, heading: san_francisco)
|
||||
wyoming_investment = create(:budget_investment, heading: wyoming)
|
||||
|
||||
create(:vote, votable: wyoming_investment, voter: user1)
|
||||
create(:vote, votable: san_franciso_investment, voter: user1)
|
||||
create(:vote, votable: new_york_investment, voter: user1)
|
||||
user1 = create(:user, votables: [wyoming_investment, san_franciso_investment, new_york_investment])
|
||||
user2 = create(:user)
|
||||
|
||||
expect(user1.headings_voted_within_group(group)).to match_array [new_york, san_francisco, wyoming]
|
||||
expect(user1.headings_voted_within_group(group)).not_to include(another_heading)
|
||||
@@ -30,10 +26,9 @@ describe User do
|
||||
end
|
||||
|
||||
it "returns headings with multiple translations only once" do
|
||||
user = create(:user)
|
||||
group = create(:budget_group)
|
||||
heading = create(:budget_heading, group: group, name_en: "English", name_es: "Spanish")
|
||||
create(:vote, votable: create(:budget_investment, heading: heading), voter: user)
|
||||
user = create(:user, votables: [create(:budget_investment, heading: heading)])
|
||||
|
||||
expect(user.headings_voted_within_group(group).count).to eq 1
|
||||
end
|
||||
|
||||
@@ -5,29 +5,26 @@ describe Vote do
|
||||
describe "#for_debates" do
|
||||
it "does not returns votes for other votables" do
|
||||
debate = create(:debate)
|
||||
comment = create(:comment)
|
||||
create(:vote, votable: comment)
|
||||
create(:vote, votable: create(:comment))
|
||||
|
||||
expect(Vote.for_debates(debate).count).to eq(0)
|
||||
end
|
||||
|
||||
it "returns votes only for debates in parameters" do
|
||||
debate1 = create(:debate)
|
||||
debate1 = create(:debate, voters: [create(:user)])
|
||||
debate2 = create(:debate)
|
||||
create(:vote, votable: debate1)
|
||||
|
||||
expect(Vote.for_debates(debate1).count).to eq(1)
|
||||
expect(Vote.for_debates(debate2).count).to eq(0)
|
||||
end
|
||||
|
||||
it "accepts more than 1 debate" do
|
||||
debate1 = create(:debate)
|
||||
debate1 = create(:debate, voters: [create(:user)])
|
||||
debate2 = create(:debate)
|
||||
debate3 = create(:debate)
|
||||
create(:vote, votable: debate1)
|
||||
create(:vote, votable: debate3)
|
||||
debate3 = create(:debate, voters: [create(:user)])
|
||||
|
||||
expect(Vote.for_debates([debate1, debate2]).count).to eq(1)
|
||||
expect(Vote.for_debates([debate1, debate3]).count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user