Add consistency to back_links

In some cases (e.g. after editing or creating a resource
with errors) the default back_link did not redirect to the
expected page.

Now we force the back_links to the index pages, so we
always get the desired redirect.
This commit is contained in:
taitus
2022-09-14 11:38:01 +02:00
parent 2d353ba893
commit 86ff4eeff9
13 changed files with 21 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_question_path(@answer.question) %>
<h2><%= t("admin.questions.show.answers.documents_list") %></h2> <h2><%= t("admin.questions.show.answers.documents_list") %></h2>

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_polls_path %>
<h2><%= t("admin.polls.edit.title") %></h2> <h2><%= t("admin.polls.edit.title") %></h2>

View File

@@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div class="small-12 column"> <div class="small-12 column">
<%= back_link_to %> <%= back_link_to admin_polls_path %>
<h2><%= t("admin.polls.new.title") %></h2> <h2><%= t("admin.polls.new.title") %></h2>
</div> </div>

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_question_path(@question) %>
<ul class="breadcrumbs margin-top"> <ul class="breadcrumbs margin-top">
<li><%= @answer.title %></li> <li><%= @answer.title %></li>

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_question_path(@question) %>
<ul class="breadcrumbs margin-top"> <ul class="breadcrumbs margin-top">
<li><%= @question.title %></li> <li><%= @question.title %></li>

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_answer_videos_path(@answer) %>
<h2> <h2>
<%= t("admin.answers.videos.edit.title") %> <%= t("admin.answers.videos.edit.title") %>

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_poll_path(@question.poll) %>
<h2 class="margin-top"><%= t("admin.questions.edit.title") %></h2> <h2 class="margin-top"><%= t("admin.questions.edit.title") %></h2>

View File

@@ -1,4 +1,4 @@
<%= back_link_to %> <%= back_link_to admin_poll_path(@question.poll) %>
<%= link_to t("admin.questions.show.edit_question"), edit_admin_question_path(@question), <%= link_to t("admin.questions.show.edit_question"), edit_admin_question_path(@question),
class: "button hollow float-right" %> class: "button hollow float-right" %>

View File

@@ -61,6 +61,7 @@ describe "Admin polls", :admin do
expect(page).not_to have_css("#poll_results_enabled") expect(page).not_to have_css("#poll_results_enabled")
expect(page).not_to have_css("#poll_stats_enabled") expect(page).not_to have_css("#poll_stats_enabled")
expect(page).to have_link "Go back", href: admin_polls_path
click_button "Create poll" click_button "Create poll"
@@ -83,6 +84,7 @@ describe "Admin polls", :admin do
end_date = 1.year.from_now.to_date end_date = 1.year.from_now.to_date
expect(page).to have_css("img[alt='#{poll.image.title}']") expect(page).to have_css("img[alt='#{poll.image.title}']")
expect(page).to have_link "Go back", href: admin_polls_path
fill_in "Name", with: "Next Poll" fill_in "Name", with: "Next Poll"
fill_in "poll_ends_at", with: end_date fill_in "poll_ends_at", with: end_date

View File

@@ -7,6 +7,8 @@ describe "Answers", :admin do
visit admin_question_path(question) visit admin_question_path(question)
click_link "Add answer" click_link "Add answer"
expect(page).to have_link "Go back", href: admin_question_path(question)
fill_in "Answer", with: "The answer is always 42" fill_in "Answer", with: "The answer is always 42"
fill_in_ckeditor "Description", with: "The Hitchhiker's Guide To The Universe" fill_in_ckeditor "Description", with: "The Hitchhiker's Guide To The Universe"
@@ -39,6 +41,8 @@ describe "Answers", :admin do
visit admin_question_path(question) visit admin_question_path(question)
within("tr", text: "Answer title") { click_link "Edit" } within("tr", text: "Answer title") { click_link "Edit" }
expect(page).to have_link "Go back", href: admin_question_path(question)
fill_in "Answer", with: "New title" fill_in "Answer", with: "New title"
click_button "Save" click_button "Save"

View File

@@ -9,6 +9,7 @@ describe "Documents", :admin do
visit admin_answer_documents_path(answer) visit admin_answer_documents_path(answer)
expect(page).not_to have_content(document.title) expect(page).not_to have_content(document.title)
expect(page).to have_link "Go back", href: admin_question_path(answer.question)
end end
scenario "Answer with documents" do scenario "Answer with documents" do

View File

@@ -28,6 +28,8 @@ describe "Videos", :admin do
visit edit_admin_answer_video_path(answer, video) visit edit_admin_answer_video_path(answer, video)
expect(page).to have_link "Go back", href: admin_answer_videos_path(answer)
fill_in "Title", with: title fill_in "Title", with: title
fill_in "External video", with: url fill_in "External video", with: url

View File

@@ -50,8 +50,9 @@ describe "Admin poll questions", :admin do
visit admin_poll_path(poll) visit admin_poll_path(poll)
click_link "Edit answers" click_link "Edit answers"
expect(page).to have_content(question.title) expect(page).to have_link "Go back", href: admin_poll_path(poll)
expect(page).to have_content(question.author.name) expect(page).to have_content question.title
expect(page).to have_content question.author.name
end end
scenario "Create" do scenario "Create" do
@@ -123,6 +124,7 @@ describe "Admin poll questions", :admin do
click_link "Edit" click_link "Edit"
end end
expect(page).to have_link "Go back", href: admin_poll_path(poll)
old_title = question1.title old_title = question1.title
new_title = "Potatoes are great and everyone should have one" new_title = "Potatoes are great and everyone should have one"
fill_in "Question", with: new_title fill_in "Question", with: new_title