Reduce accesses to database after browser requests

GitHub Actions is failing to finish sometimes. Usually that happens due
to concurrency issues when the process running the test accesses the
database after the process running the browser has started.

Since these files were the ones being tested the times we had this
issue, these are the ones we are fixing right now, although there are
probably other places where we might have this issue in the future.
This commit is contained in:
Javi Martín
2021-04-02 16:27:37 +02:00
parent 03d0ffd89e
commit 8d38ed58c8
9 changed files with 31 additions and 20 deletions

View File

@@ -66,6 +66,7 @@ describe "Advanced search" do
context "Search by author type" do
scenario "Public employee" do
Setting["official_level_1_name"] = "Official position 1"
ana = create :user, official_level: 1
john = create :user, official_level: 2
@@ -76,7 +77,7 @@ describe "Advanced search" do
visit debates_path
click_link "Advanced search"
select Setting["official_level_1_name"], from: "advanced_search_official_level"
select "Official position 1", from: "advanced_search_official_level"
click_button "Filter"
expect(page).to have_content("There are 2 debates")
@@ -89,6 +90,7 @@ describe "Advanced search" do
end
scenario "Municipal Organization" do
Setting["official_level_2_name"] = "Official position 2"
ana = create :user, official_level: 2
john = create :user, official_level: 3
@@ -99,7 +101,7 @@ describe "Advanced search" do
visit proposals_path
click_link "Advanced search"
select Setting["official_level_2_name"], from: "advanced_search_official_level"
select "Official position 2", from: "advanced_search_official_level"
click_button "Filter"
expect(page).to have_content("There are 2 citizen proposals")
@@ -112,6 +114,7 @@ describe "Advanced search" do
end
scenario "General director" do
Setting["official_level_3_name"] = "Official position 3"
ana = create :user, official_level: 3
john = create :user, official_level: 4
@@ -122,7 +125,7 @@ describe "Advanced search" do
visit budget_investments_path(budget)
click_link "Advanced search"
select Setting["official_level_3_name"], from: "advanced_search_official_level"
select "Official position 3", from: "advanced_search_official_level"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
@@ -135,6 +138,7 @@ describe "Advanced search" do
end
scenario "City councillor" do
Setting["official_level_4_name"] = "Official position 4"
ana = create :user, official_level: 4
john = create :user, official_level: 5
@@ -145,7 +149,7 @@ describe "Advanced search" do
visit debates_path
click_link "Advanced search"
select Setting["official_level_4_name"], from: "advanced_search_official_level"
select "Official position 4", from: "advanced_search_official_level"
click_button "Filter"
expect(page).to have_content("There are 2 debates")
@@ -158,6 +162,7 @@ describe "Advanced search" do
end
scenario "Mayoress" do
Setting["official_level_5_name"] = "Official position 5"
ana = create :user, official_level: 5
john = create :user, official_level: 4
@@ -168,7 +173,7 @@ describe "Advanced search" do
visit proposals_path
click_link "Advanced search"
select Setting["official_level_5_name"], from: "advanced_search_official_level"
select "Official position 5", from: "advanced_search_official_level"
click_button "Filter"
expect(page).to have_content("There are 2 citizen proposals")
@@ -310,6 +315,7 @@ describe "Advanced search" do
end
scenario "Search by multiple filters" do
Setting["official_level_1_name"] = "Official position 1"
ana = create :user, official_level: 1
john = create :user, official_level: 1
@@ -321,7 +327,7 @@ describe "Advanced search" do
click_link "Advanced search"
fill_in "Write the text", with: "Schwifty"
select Setting["official_level_1_name"], from: "advanced_search_official_level"
select "Official position 1", from: "advanced_search_official_level"
select "Last 24 hours", from: "js-advanced-search-date-min"
click_button "Filter"
@@ -334,18 +340,20 @@ describe "Advanced search" do
end
scenario "Maintain advanced search criteria" do
Setting["official_level_1_name"] = "Official position 1"
visit debates_path
click_link "Advanced search"
fill_in "Write the text", with: "Schwifty"
select Setting["official_level_1_name"], from: "advanced_search_official_level"
select "Official position 1", from: "advanced_search_official_level"
select "Last 24 hours", from: "js-advanced-search-date-min"
click_button "Filter"
within "#js-advanced-search" do
expect(page).to have_selector("input[name='search'][value='Schwifty']")
expect(page).to have_select("advanced_search[official_level]", selected: Setting["official_level_1_name"])
expect(page).to have_select("advanced_search[official_level]", selected: "Official position 1")
expect(page).to have_select("advanced_search[date_min]", selected: "Last 24 hours")
end
end

View File

@@ -7,7 +7,7 @@ describe "Commenting Budget::Investments" do
it_behaves_like "flaggable", :budget_investment_comment
scenario "Index" do
3.times { create(:comment, commentable: investment) }
not_valuations = 3.times.map { create(:comment, commentable: investment) }
create(:comment, :valuation, commentable: investment, subject: "Not viable")
visit budget_investment_path(investment.budget, investment)
@@ -16,7 +16,7 @@ describe "Commenting Budget::Investments" do
expect(page).not_to have_content("Not viable")
within("#comments") do
Comment.not_valuations.last(3).each do |comment|
not_valuations.each do |comment|
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body

View File

@@ -8,12 +8,12 @@ describe "Commenting debates" do
scenario "Index" do
3.times { create(:comment, commentable: debate) }
comment = Comment.includes(:user).last
visit debate_path(debate)
expect(page).to have_css(".comment", count: 3)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)

View File

@@ -8,6 +8,7 @@ describe "Commenting legislation questions" do
scenario "Index" do
3.times { create(:comment, commentable: legislation_annotation) }
comment = Comment.includes(:user).last
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process,
legislation_annotation.draft_version,
@@ -15,7 +16,6 @@ describe "Commenting legislation questions" do
expect(page).to have_css(".comment", count: 4)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)

View File

@@ -12,12 +12,12 @@ describe "Commenting legislation questions" do
scenario "Index" do
3.times { create(:comment, commentable: legislation_question) }
comment = Comment.includes(:user).last
visit legislation_process_question_path(legislation_question.process, legislation_question)
expect(page).to have_css(".comment", count: 3)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)

View File

@@ -6,12 +6,12 @@ describe "Commenting polls" do
scenario "Index" do
3.times { create(:comment, commentable: poll) }
comment = Comment.includes(:user).last
visit poll_path(poll)
expect(page).to have_css(".comment", count: 3)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)

View File

@@ -8,12 +8,12 @@ describe "Commenting proposals" do
scenario "Index" do
3.times { create(:comment, commentable: proposal) }
comment = Comment.includes(:user).last
visit proposal_path(proposal)
expect(page).to have_css(".comment", count: 3)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)

View File

@@ -10,12 +10,12 @@ describe "Commenting topics from proposals" do
community = proposal.community
topic = create(:topic, community: community)
create_list(:comment, 3, commentable: topic)
comment = Comment.includes(:user).last
visit community_topic_path(community, topic)
expect(page).to have_css(".comment", count: 3)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
@@ -574,12 +574,12 @@ describe "Commenting topics from budget investments" do
community = investment.community
topic = create(:topic, community: community)
create_list(:comment, 3, commentable: topic)
comment = Comment.includes(:user).last
visit community_topic_path(community, topic)
expect(page).to have_css(".comment", count: 3)
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)

View File

@@ -94,8 +94,9 @@ describe "Tags" do
click_button "Create Investment"
expect(page).to have_content "Investment created successfully."
expect(page).to have_content "Build a skyscraper"
within "#tags_budget_investment_#{Budget::Investment.last.id}" do
within ".tags" do
expect(page).to have_content tag_economia.name
expect(page).not_to have_content tag_medio_ambiente.name
end
@@ -118,8 +119,9 @@ describe "Tags" do
click_button "Create Investment"
expect(page).to have_content "Investment created successfully."
expect(page).to have_content "Build a skyscraper"
within "#tags_budget_investment_#{Budget::Investment.last.id}" do
within ".tags" do
expect(page).to have_content "Education"
expect(page).not_to have_content "Health"
end
@@ -142,8 +144,9 @@ describe "Tags" do
click_button "Create Investment"
expect(page).to have_content "Investment created successfully."
expect(page).to have_content "Build a skyscraper"
within "#tags_budget_investment_#{Budget::Investment.last.id}" do
within ".tags" do
expect(page).to have_content "Education"
expect(page).not_to have_content "Health"
end