From b55f2ab85c8e1ead9c83b8af8b750157d80c64f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 10 Apr 2021 16:09:27 +0200 Subject: [PATCH] Test slugs from the user's point of view System tests are about user experience, so instead of checking the slug has been updated in the database, we check whether the page can be accessed using the slug. Note the budget group test is a bit different because the name of the group isn't present in the budget group page. --- spec/system/admin/budget_groups_spec.rb | 14 +++++++++----- spec/system/admin/budget_headings_spec.rb | 14 +++++++++----- spec/system/admin/budgets_spec.rb | 14 +++++++++----- spec/system/admin/poll/polls_spec.rb | 5 ++++- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/spec/system/admin/budget_groups_spec.rb b/spec/system/admin/budget_groups_spec.rb index 626af9503..139a6c103 100644 --- a/spec/system/admin/budget_groups_spec.rb +++ b/spec/system/admin/budget_groups_spec.rb @@ -123,8 +123,7 @@ describe "Admin budget groups", :admin do 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) @@ -133,7 +132,10 @@ describe "Admin budget groups", :admin do 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) @@ -142,8 +144,10 @@ describe "Admin budget groups", :admin do 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 diff --git a/spec/system/admin/budget_headings_spec.rb b/spec/system/admin/budget_headings_spec.rb index 2f166a413..710770ed5 100644 --- a/spec/system/admin/budget_headings_spec.rb +++ b/spec/system/admin/budget_headings_spec.rb @@ -160,8 +160,7 @@ describe "Admin budget headings", :admin do 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) @@ -170,7 +169,10 @@ describe "Admin budget headings", :admin do 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) @@ -179,8 +181,10 @@ describe "Admin budget headings", :admin do 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 diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index eaae7dbd1..24249fd1b 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -286,8 +286,7 @@ describe "Admin budgets", :admin do end scenario "Changing name for current locale will update the slug if budget is in draft phase" do - budget.update!(published: false) - old_slug = budget.slug + budget.update!(published: false, name: "Old English Name") visit edit_admin_budget_path(budget) @@ -296,7 +295,10 @@ describe "Admin budgets", :admin do click_button "Update Budget" expect(page).to have_content "Participatory budget updated successfully" - expect(budget.reload.slug).to eq old_slug + + visit budget_path(id: "old-english-name") + + expect(page).to have_content "Old English Name" visit edit_admin_budget_path(budget) @@ -305,8 +307,10 @@ describe "Admin budgets", :admin do click_button "Update Budget" expect(page).to have_content "Participatory budget updated successfully" - expect(budget.reload.slug).not_to eq old_slug - expect(budget.slug).to eq "new-english-name" + + visit budget_path(id: "new-english-name") + + expect(page).to have_content "New English Name" end end diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index 8848fa96e..15f0efc94 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -75,7 +75,10 @@ describe "Admin polls", :admin do expect(page).to have_content "Upcoming poll" expect(page).to have_content I18n.l(start_date) expect(page).to have_content I18n.l(end_date) - expect(Poll.last.slug).to eq "#{Poll.last.name.to_s.parameterize}" + + visit poll_path(id: "upcoming-poll") + + expect(page).to have_content "Upcoming poll" end scenario "Edit" do