diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb index c2d9b13f9..d673e53c4 100644 --- a/app/controllers/petitions_controller.rb +++ b/app/controllers/petitions_controller.rb @@ -102,7 +102,9 @@ def redirect_to_home_page_if_dissolved end def redirect_to_home_page_unless_opened - redirect_to home_url unless Parliament.opened? + unless json_request? + redirect_to home_url unless Parliament.opened? + end end def request_format diff --git a/spec/controllers/petitions_controller_spec.rb b/spec/controllers/petitions_controller_spec.rb index 43a3690e3..12977fcae 100644 --- a/spec/controllers/petitions_controller_spec.rb +++ b/spec/controllers/petitions_controller_spec.rb @@ -501,6 +501,11 @@ get :index expect(response).to redirect_to("https://petition.parliament.uk/") end + + it "doesn't redirect JSON requests" do + get :index, as: :json + expect(response).to be_successful + end end end