Skip to content

Commit

Permalink
Merge pull request #4475 from consul/browser_tests_database
Browse files Browse the repository at this point in the history
Reduce test database access after visiting a page
  • Loading branch information
javierm committed Apr 16, 2021
2 parents c0c2620 + 3345dd6 commit 3169f87
Show file tree
Hide file tree
Showing 60 changed files with 588 additions and 498 deletions.
9 changes: 5 additions & 4 deletions spec/shared/system/relationable.rb
Expand Up @@ -3,6 +3,7 @@
let(:related1) { create([:proposal, :debate, :budget_investment].sample) }
let(:related2) { create([:proposal, :debate, :budget_investment].sample) }
let(:user) { create(:user) }
let!(:url) { Setting["url"] }

scenario "related contents are listed" do
create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
Expand Down Expand Up @@ -32,7 +33,7 @@
click_on("Add related content")

within("#related_content") do
fill_in "url", with: "#{Setting["url"] + related1.url}"
fill_in "url", with: "#{url + related1.url}"
click_button "Add"
end

Expand All @@ -49,7 +50,7 @@
click_on("Add related content")

within("#related_content") do
fill_in "url", with: "#{Setting["url"] + related2.url}"
fill_in "url", with: "#{url + related2.url}"
click_button "Add"
end

Expand All @@ -69,7 +70,7 @@
click_button "Add"
end

expect(page).to have_content("Link not valid. Remember to start with #{Setting[:url]}.")
expect(page).to have_content("Link not valid. Remember to start with #{url}.")
end

scenario "returns error when relating content URL to itself" do
Expand All @@ -79,7 +80,7 @@
click_on("Add related content")

within("#related_content") do
fill_in "url", with: Setting[:url] + relationable.url.to_s
fill_in "url", with: url + relationable.url.to_s
click_button "Add"
end

Expand Down
6 changes: 3 additions & 3 deletions spec/support/common_actions.rb
Expand Up @@ -36,9 +36,9 @@ def fill_in_proposal
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yPQfcG-eimk"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
check "proposal_terms_of_service"
fill_in "External video URL", with: "https://www.youtube.com/watch?v=yPQfcG-eimk"
fill_in "Full name of the person submitting the proposal", with: "Isabel Garcia"
check "I agree to the Privacy Policy and the Terms and conditions of use"
end

def set_officing_booth(booth = nil)
Expand Down
10 changes: 3 additions & 7 deletions spec/support/common_actions/comments.rb
Expand Up @@ -6,14 +6,10 @@ def comment_on(commentable, user = nil)
CommentNotifier.new(comment: comment).process
end

def reply_to(original_user, manuela = nil)
manuela ||= create(:user)
def reply_to(comment, replier: create(:user))
login_as(replier)

debate = create(:debate)
comment = create(:comment, commentable: debate, user: original_user)

login_as(manuela)
visit debate_path(debate)
visit polymorphic_path(comment.commentable)

click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
Expand Down
11 changes: 8 additions & 3 deletions spec/system/account_spec.rb
Expand Up @@ -198,13 +198,18 @@

click_button "Save changes"

expect(page).to have_content "Changes saved"

expect(find("#account_recommended_debates")).not_to be_checked
expect(find("#account_recommended_proposals")).not_to be_checked

user.reload
visit debates_path

expect(page).not_to have_link("recommendations")

visit proposals_path

expect(user.recommended_debates).to be(false)
expect(user.recommended_proposals).to be(false)
expect(page).not_to have_link("recommendations")
end
end
end
20 changes: 10 additions & 10 deletions spec/system/admin/activity_spec.rb
Expand Up @@ -20,7 +20,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(proposal.title)
expect(page).to have_content("Hidden")
expect(page).to have_content(admin.user.username)
Expand Down Expand Up @@ -66,7 +66,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(proposal.title)
expect(page).to have_content("Restored")
expect(page).to have_content(admin.user.username)
Expand All @@ -87,7 +87,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(debate.title)
expect(page).to have_content("Hidden")
expect(page).to have_content(admin.user.username)
Expand Down Expand Up @@ -133,7 +133,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(debate.title)
expect(page).to have_content("Restored")
expect(page).to have_content(admin.user.username)
Expand All @@ -155,7 +155,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(comment.body)
expect(page).to have_content("Hidden")
expect(page).to have_content(admin.user.username)
Expand Down Expand Up @@ -201,7 +201,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(comment.body)
expect(page).to have_content("Restored")
expect(page).to have_content(admin.user.username)
Expand All @@ -223,7 +223,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content("Blocked")
expect(page).to have_content(proposal.author.username)
expect(page).to have_content(proposal.author.email)
Expand All @@ -243,7 +243,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(user.username)
expect(page).to have_content(user.email)
expect(page).to have_content(admin.user.username)
Expand Down Expand Up @@ -347,7 +347,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(user.username)
expect(page).to have_content(user.email)
expect(page).to have_content("Restored")
Expand All @@ -366,7 +366,7 @@

visit admin_activity_path

within("#activity_#{Activity.last.id}") do
within first("tbody tr") do
expect(page).to have_content(proposal_notification.title)
expect(page).to have_content("Hidden")
expect(page).to have_content(admin.user.username)
Expand Down
23 changes: 17 additions & 6 deletions spec/system/admin/budget_groups_spec.rb
Expand Up @@ -97,7 +97,14 @@
click_button "Create new group"

expect(page).to have_content "Group created successfully!"
expect(Budget::Group.first.max_votable_headings).to be 1

within all("thead th")[1] do
expect(page).to have_content("Maximum number of headings in which a user can select projects")
end

within "tbody tr" do
within all("td")[1] { expect(page.text).to eq "1" }
end
end

scenario "Group name is mandatory" do
Expand All @@ -123,8 +130,7 @@
end

scenario "Changing name for current locale will update the slug if budget is in draft phase" do
group = create(:budget_group, budget: budget)
old_slug = group.slug
group = create(:budget_group, budget: budget, name: "Old English Name")

visit edit_admin_budget_group_path(budget, group)

Expand All @@ -133,7 +139,10 @@
click_button "Save group"

expect(page).to have_content "Group updated successfully"
expect(group.reload.slug).to eq old_slug

visit budget_group_path(budget, id: "old-english-name")

expect(page).to have_content "Select an option"

visit edit_admin_budget_group_path(budget, group)

Expand All @@ -142,8 +151,10 @@
click_button "Save group"

expect(page).to have_content "Group updated successfully"
expect(group.reload.slug).not_to eq old_slug
expect(group.slug).to eq "new-english-name"

visit budget_group_path(budget, id: "new-english-name")

expect(page).to have_content "Select an option"
end
end

Expand Down
14 changes: 9 additions & 5 deletions spec/system/admin/budget_headings_spec.rb
Expand Up @@ -160,8 +160,7 @@
end

scenario "Changing name for current locale will update the slug if budget is in draft phase" do
heading = create(:budget_heading, group: group)
old_slug = heading.slug
heading = create(:budget_heading, group: group, name: "Old English Name")

visit edit_admin_budget_group_heading_path(budget, group, heading)

Expand All @@ -170,7 +169,10 @@
click_button "Save heading"

expect(page).to have_content "Heading updated successfully"
expect(heading.reload.slug).to eq old_slug

visit budget_investments_path(budget, heading_id: "old-english-name")

expect(page).to have_content "Old English Name"

visit edit_admin_budget_group_heading_path(budget, group, heading)

Expand All @@ -179,8 +181,10 @@
click_button "Save heading"

expect(page).to have_content "Heading updated successfully"
expect(heading.reload.slug).not_to eq old_slug
expect(heading.slug).to eq "new-english-name"

visit budget_investments_path(budget, heading_id: "new-english-name")

expect(page).to have_content "New English Name"
end
end

Expand Down
33 changes: 19 additions & 14 deletions spec/system/admin/budget_investments_spec.rb
Expand Up @@ -627,7 +627,7 @@
administrator = create(:administrator, user: user)
budget.administrators = [administrator]

create(:budget_investment, budget: budget, title: "Educate the children",
educate_children = create(:budget_investment, budget: budget, title: "Educate the children",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More schools",
administrator: administrator)
Expand All @@ -648,8 +648,7 @@
expect(page).to have_content("More schools")
expect(page).not_to have_content("More hospitals")

educate_children_investment = Budget::Investment.find_by(title: "Educate the children")
fill_in "title_or_id", with: educate_children_investment.id
fill_in "title_or_id", with: educate_children.id
click_button "Filter"

expect(page).to have_css(".budget_investment", count: 1)
Expand All @@ -661,7 +660,8 @@
end

scenario "Combination of select with text search" do
create(:budget_investment, :feasible, :finished, budget: budget, title: "Educate the children")
educate_children = create(:budget_investment, :feasible, :finished,
budget: budget, title: "Educate the children")
create(:budget_investment, :feasible, :finished, budget: budget, title: "More schools")
create(:budget_investment, budget: budget, title: "More hospitals")

Expand All @@ -682,8 +682,7 @@
expect(page).to have_content("More schools")
expect(page).not_to have_content("More hospitals")

educate_children_investment = Budget::Investment.find_by(title: "Educate the children")
fill_in "title_or_id", with: educate_children_investment.id
fill_in "title_or_id", with: educate_children.id
click_button "Filter"

expect(page).to have_css(".budget_investment", count: 1)
Expand All @@ -699,8 +698,8 @@
administrator = create(:administrator, user: user)
budget.administrators = [administrator]

create(:budget_investment, :feasible, :finished, budget: budget, title: "Educate the children",
administrator: administrator)
educate_children = create(:budget_investment, :feasible, :finished,
budget: budget, title: "Educate the children", administrator: administrator)
create(:budget_investment, :feasible, :finished, budget: budget, title: "More schools",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More hospitals",
Expand Down Expand Up @@ -735,8 +734,7 @@
expect(page).not_to have_content("More hospitals")
expect(page).not_to have_content("More hostals")

educate_children_investment = Budget::Investment.find_by(title: "Educate the children")
fill_in "title_or_id", with: educate_children_investment.id
fill_in "title_or_id", with: educate_children.id
click_button "Filter"

expect(page).to have_css(".budget_investment", count: 1)
Expand Down Expand Up @@ -1077,6 +1075,8 @@
check "Marta"
click_button "Update Budget"

expect(page).to have_content "Participatory budget updated successfully"

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link "Edit classification"

Expand Down Expand Up @@ -1106,6 +1106,8 @@
check "Val"
click_button "Update Budget"

expect(page).to have_content "Participatory budget updated successfully"

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link "Edit classification"

Expand Down Expand Up @@ -1228,6 +1230,8 @@
fill_in "budget_investment_valuation_tag_list", with: "Education, Environment"
click_button "Update"

expect(page).to have_content "Investment project updated succesfully"

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)

within("#tags_budget_investment_#{budget_investment.id}") do
Expand Down Expand Up @@ -1587,10 +1591,8 @@
investment1.update!(administrator: admin)
investment2.update!(administrator: admin)

login_as(valuator.user.reload)
visit root_path
click_link "Menu"
click_link "Valuation"
login_as(valuator.user)
visit valuation_root_path

within "#budget_#{budget.id}" do
click_link "Evaluate"
Expand Down Expand Up @@ -1745,6 +1747,9 @@
check "Valuation finished"
click_button "Filter"

expect(page).to have_content "Finished Investment"
expect(page).not_to have_content "Unfeasible one"

click_link "Download current selection"

expect(page).to have_content("Finished Investment")
Expand Down

0 comments on commit 3169f87

Please sign in to comment.