Simplify assigning a name to an officer

This commit is contained in:
Javi Martín
2019-09-27 22:13:15 +02:00
parent 71c24f844d
commit c6acc70570
2 changed files with 17 additions and 17 deletions

View File

@@ -111,7 +111,11 @@ FactoryBot.define do
end
factory :poll_officer, class: "Poll::Officer" do
user
user { association(:user, username: name) }
transient do
sequence(:name) { |n| "Officer #{n}" }
end
end
factory :follow do

View File

@@ -10,9 +10,9 @@ describe "Officer Assignments" do
scenario "Index" do
poll = create(:poll)
officer1 = create(:poll_officer)
officer2 = create(:poll_officer)
officer3 = create(:poll_officer)
officer1 = create(:poll_officer, name: "Bubbles")
officer2 = create(:poll_officer, name: "Blossom")
officer3 = create(:poll_officer, name: "Buttercup")
officer_assignment = create(:poll_officer_assignment, poll: poll, officer: officer1)
officer_assignment_2 = create(:poll_officer_assignment, poll: poll, officer: officer2)
@@ -22,22 +22,18 @@ describe "Officer Assignments" do
click_link "Officers (2)"
within("#officer_assignments") do
expect(page).to have_content officer1.name
expect(page).to have_content officer2.name
expect(page).not_to have_content officer3.name
expect(page).to have_content "Bubbles"
expect(page).to have_content "Blossom"
expect(page).not_to have_content "Buttercup"
end
end
scenario "Search", :js do
poll = create(:poll)
user1 = create(:user, username: "John Snow")
user2 = create(:user, username: "John Silver")
user3 = create(:user, username: "John Edwards")
officer1 = create(:poll_officer, user: user1)
officer2 = create(:poll_officer, user: user2)
officer3 = create(:poll_officer, user: user3)
officer1 = create(:poll_officer, name: "John Snow")
officer2 = create(:poll_officer, name: "John Silver")
officer3 = create(:poll_officer, name: "John Edwards")
officer_assignment = create(:poll_officer_assignment, poll: poll, officer: officer1)
officer_assignment_2 = create(:poll_officer_assignment, poll: poll, officer: officer2)
@@ -50,9 +46,9 @@ describe "Officer Assignments" do
click_button "Search"
within("#search-officers-results") do
expect(page).to have_content officer1.name
expect(page).to have_content officer2.name
expect(page).not_to have_content officer3.name
expect(page).to have_content "John Snow"
expect(page).to have_content "John Silver"
expect(page).not_to have_content "John Edwards"
end
end