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