Simplify creating voters in specs

This commit is contained in:
Javi Martín
2019-09-26 02:18:21 +02:00
parent 994b5c99c2
commit 818b442d52
21 changed files with 126 additions and 220 deletions

View File

@@ -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