Use let to creat users in voter spec
We remove duplication, and we better isolate useless assignments.
This commit is contained in:
@@ -9,6 +9,7 @@ describe Poll::Voter do
|
|||||||
let(:officer_assignment) { create(:poll_officer_assignment) }
|
let(:officer_assignment) { create(:poll_officer_assignment) }
|
||||||
|
|
||||||
describe "validations" do
|
describe "validations" do
|
||||||
|
let(:user) { create(:user, :level_two) }
|
||||||
|
|
||||||
it "is valid" do
|
it "is valid" do
|
||||||
expect(voter).to be_valid
|
expect(voter).to be_valid
|
||||||
@@ -31,8 +32,6 @@ describe Poll::Voter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid if the user has already voted in the same poll or booth_assignment" do
|
it "is not valid if the user has already voted in the same poll or booth_assignment" do
|
||||||
user = create(:user, :level_two)
|
|
||||||
|
|
||||||
voter1 = create(:poll_voter, user: user, poll: poll)
|
voter1 = create(:poll_voter, user: user, poll: poll)
|
||||||
voter2 = build(:poll_voter, user: user, poll: poll)
|
voter2 = build(:poll_voter, user: user, poll: poll)
|
||||||
|
|
||||||
@@ -41,8 +40,6 @@ describe Poll::Voter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid if the user has already voted in the same poll/booth" do
|
it "is not valid if the user has already voted in the same poll/booth" do
|
||||||
user = create(:user, :level_two)
|
|
||||||
|
|
||||||
voter1 = create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
voter1 = create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
||||||
voter2 = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
voter2 = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment)
|
||||||
|
|
||||||
@@ -51,8 +48,6 @@ describe Poll::Voter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid if the user has already voted in different booth in the same poll" do
|
it "is not valid if the user has already voted in different booth in the same poll" do
|
||||||
user = create(:user, :level_two)
|
|
||||||
|
|
||||||
create(:poll_voter, :from_booth, user: user, poll: poll, booth: create(:poll_booth))
|
create(:poll_voter, :from_booth, user: user, poll: poll, booth: create(:poll_booth))
|
||||||
|
|
||||||
voter = build(:poll_voter, :from_booth, user: user, poll: poll, booth: booth)
|
voter = build(:poll_voter, :from_booth, user: user, poll: poll, booth: booth)
|
||||||
@@ -62,8 +57,6 @@ describe Poll::Voter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is valid if the user has already voted in the same booth in different poll" do
|
it "is valid if the user has already voted in the same booth in different poll" do
|
||||||
user = create(:user, :level_two)
|
|
||||||
|
|
||||||
create(:poll_voter, :from_booth, user: user, booth: booth, poll: create(:poll))
|
create(:poll_voter, :from_booth, user: user, booth: booth, poll: create(:poll))
|
||||||
|
|
||||||
voter = build(:poll_voter, :from_booth, user: user, booth: booth, poll: poll)
|
voter = build(:poll_voter, :from_booth, user: user, booth: booth, poll: poll)
|
||||||
|
|||||||
Reference in New Issue
Block a user