app: fix JS redirection with Turbolinks disabled
When Turbolinks is enabled, a `redirect_to` in a `format: :js` request will emit code that instructs Turbolinks to navigate to the page. Turbolinks will then load the redirection target as HTML, and display it. But with Turbolinks disabled, the same `redirect_to` will instead respond with a standard `302: redirect`. `Rails.ajax` will interpret this redirect as "Please perform the same call again to the redirected URL, in the same format" – and request our redirection target, but using `format: :js`. This breaks the "Publish procedure" button. In that case, we really want the page to be navigated to. Add an explicit JS redirect, so that the redirection occurs in HTML.
This commit is contained in:
parent
b5f1d97629
commit
51cb3a04a3
2 changed files with 18 additions and 6 deletions
|
@ -72,7 +72,7 @@ class Admin::ProceduresController < AdminController
|
||||||
@procedure.publish_or_reopen!(current_administrateur)
|
@procedure.publish_or_reopen!(current_administrateur)
|
||||||
|
|
||||||
flash.notice = "Démarche publiée"
|
flash.notice = "Démarche publiée"
|
||||||
redirect_to admin_procedures_path
|
render js: "window.location='#{admin_procedures_path}'"
|
||||||
rescue ActiveRecord::RecordInvalid
|
rescue ActiveRecord::RecordInvalid
|
||||||
render 'publish_validate', formats: :js
|
render 'publish_validate', formats: :js
|
||||||
end
|
end
|
||||||
|
|
|
@ -180,7 +180,11 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
expect(procedure.publiee?).to be_truthy
|
expect(procedure.publiee?).to be_truthy
|
||||||
expect(procedure.path).to eq(path)
|
expect(procedure.path).to eq(path)
|
||||||
expect(procedure.lien_site_web).to eq(lien_site_web)
|
expect(procedure.lien_site_web).to eq(lien_site_web)
|
||||||
expect(response.status).to eq 302
|
end
|
||||||
|
|
||||||
|
it 'redirects to the procedures page' do
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
expect(response.body).to include(admin_procedures_path)
|
||||||
expect(flash[:notice]).to have_content 'Démarche publiée'
|
expect(flash[:notice]).to have_content 'Démarche publiée'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -193,13 +197,17 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
expect(procedure.publiee?).to be_truthy
|
expect(procedure.publiee?).to be_truthy
|
||||||
expect(procedure.path).to eq(path)
|
expect(procedure.path).to eq(path)
|
||||||
expect(procedure.lien_site_web).to eq(lien_site_web)
|
expect(procedure.lien_site_web).to eq(lien_site_web)
|
||||||
expect(response.status).to eq 302
|
|
||||||
expect(flash[:notice]).to have_content 'Démarche publiée'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'depubliee previous procedure' do
|
it 'depubliee previous procedure' do
|
||||||
expect(procedure2.depubliee?).to be_truthy
|
expect(procedure2.depubliee?).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'redirects to the procedures page' do
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
expect(response.body).to include(admin_procedures_path)
|
||||||
|
expect(flash[:notice]).to have_content 'Démarche publiée'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'procedure path exists and is not owned by current administrator' do
|
context 'procedure path exists and is not owned by current administrator' do
|
||||||
|
@ -285,8 +293,12 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(procedure.publiee?).to be_truthy }
|
it { expect(procedure.publiee?).to be_truthy }
|
||||||
it { expect(response.status).to eq 302 }
|
|
||||||
it { expect(flash[:notice]).to have_content 'Démarche publiée' }
|
it 'redirects to the procedures page' do
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
expect(response.body).to include(admin_procedures_path)
|
||||||
|
expect(flash[:notice]).to have_content 'Démarche publiée'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue