Don't create records during a system test
In the officing tests, we were accessing `admin.user` after starting the browser with a `visit`. However, since `admin` is a method with a `let` block, the administrator isn't created in the database until we referenced the variable, meaning we were creating the database record in the middle of the test. Referencing the variable at the beginning of the test solves the issue. We were also creating records to call the `login_as` method in the users tests, so we're moving the code to create them before the first call to `visit`. In the notifiable test, we were doing a loop consisting of "create()" -> "visit" -> "create()" -> "visit!" -> (...), meaning we were creating the second user after the first `visit`. Creating every user before the first `visit` solves the issue.
This commit is contained in:
@@ -26,8 +26,10 @@ shared_examples "notifiable in-app" do |factory_name|
|
||||
end
|
||||
|
||||
scenario "Multiple users commented on my notifiable" do
|
||||
3.times do |n|
|
||||
login_as(create(:user, :verified))
|
||||
users = 3.times.map { create(:user, :verified) }
|
||||
|
||||
users.each.with_index do |user, n|
|
||||
login_as(user)
|
||||
|
||||
visit path_for(notifiable)
|
||||
|
||||
@@ -61,9 +63,10 @@ shared_examples "notifiable in-app" do |factory_name|
|
||||
|
||||
scenario "Multiple replies to my comment" do
|
||||
comment = create(:comment, commentable: notifiable, user: author)
|
||||
users = 3.times.map { create(:user, :verified) }
|
||||
|
||||
3.times do |n|
|
||||
login_as(create(:user, :verified))
|
||||
users.each.with_index do |user, n|
|
||||
login_as(user)
|
||||
visit path_for(notifiable)
|
||||
|
||||
within("#comment_#{comment.id}_reply") { click_link "Reply" }
|
||||
|
||||
@@ -74,6 +74,7 @@ describe "Voter" do
|
||||
end
|
||||
|
||||
scenario "Voting in booth" do
|
||||
admin_user = admin.user
|
||||
login_through_form_as_officer(officer)
|
||||
|
||||
visit new_officing_residence_path
|
||||
@@ -88,7 +89,7 @@ describe "Voter" do
|
||||
end
|
||||
|
||||
logout
|
||||
login_as(admin.user)
|
||||
login_as(admin_user)
|
||||
visit admin_poll_recounts_path(poll)
|
||||
|
||||
within("#total_system") do
|
||||
@@ -155,6 +156,7 @@ describe "Voter" do
|
||||
end
|
||||
|
||||
scenario "Trying to vote in booth and then in web" do
|
||||
admin_user = admin.user
|
||||
login_through_form_as_officer(officer)
|
||||
|
||||
vote_for_poll_via_booth
|
||||
@@ -170,7 +172,7 @@ describe "Voter" do
|
||||
"You can not participate again."
|
||||
|
||||
logout
|
||||
login_as(admin.user)
|
||||
login_as(admin_user)
|
||||
visit admin_poll_recounts_path(poll)
|
||||
|
||||
within("#total_system") do
|
||||
@@ -186,6 +188,7 @@ describe "Voter" do
|
||||
scenario "Voting in poll and then verifiying account" do
|
||||
allow_any_instance_of(Verification::Sms).to receive(:generate_confirmation_code).and_return("1357")
|
||||
user = create(:user)
|
||||
admin_user = admin.user
|
||||
|
||||
login_through_form_as_officer(officer)
|
||||
vote_for_poll_via_booth
|
||||
@@ -208,7 +211,7 @@ describe "Voter" do
|
||||
"You can not participate again."
|
||||
|
||||
logout
|
||||
login_as(admin.user)
|
||||
login_as(admin_user)
|
||||
visit admin_poll_recounts_path(poll)
|
||||
|
||||
within("#total_system") do
|
||||
|
||||
@@ -181,6 +181,7 @@ describe "Users" do
|
||||
end
|
||||
|
||||
scenario "is always visible for admins" do
|
||||
admin = create(:administrator).user
|
||||
login_as(user)
|
||||
visit account_path
|
||||
|
||||
@@ -190,13 +191,14 @@ describe "Users" do
|
||||
expect(page).to have_content "Changes saved"
|
||||
|
||||
logout
|
||||
login_as(create(:administrator).user)
|
||||
login_as(admin)
|
||||
visit user_path(user)
|
||||
|
||||
expect(page).not_to have_content "activity list private"
|
||||
end
|
||||
|
||||
scenario "is always visible for moderators" do
|
||||
moderator = create(:moderator).user
|
||||
login_as(user)
|
||||
visit account_path
|
||||
|
||||
@@ -206,7 +208,7 @@ describe "Users" do
|
||||
expect(page).to have_content "Changes saved"
|
||||
|
||||
logout
|
||||
login_as(create(:moderator).user)
|
||||
login_as(moderator)
|
||||
visit user_path(user)
|
||||
|
||||
expect(page).not_to have_content "activity list private"
|
||||
|
||||
Reference in New Issue
Block a user