From 11c1df0bdd8631385d0072486cb46db196c5ee2e Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Mon, 20 Dec 2021 14:36:18 +0000 Subject: [PATCH] Redirect to logs if they clicked start now (#175) --- app/controllers/auth/sessions_controller.rb | 6 ++++ app/views/devise/sessions/new.html.erb | 1 + app/views/start/index.html.erb | 3 +- spec/controllers/start_controller_spec.rb | 1 - spec/features/start_page_spec.rb | 31 +++++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 spec/features/start_page_spec.rb diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index a117aecff..270b89b2e 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -17,4 +17,10 @@ class Auth::SessionsController < Devise::SessionsController super end end + +private + + def after_sign_in_path_for(resource) + params.dig("user", "start").present? ? case_logs_path : super + end end diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 70a4bfc0e..edfe427a0 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -19,6 +19,7 @@ autocomplete: "current-password" %> + <%= f.hidden_field :start, value: request["start"] %> <%= f.govuk_submit "Sign in" %> diff --git a/app/views/start/index.html.erb b/app/views/start/index.html.erb index d3de2d344..7ba5625fa 100644 --- a/app/views/start/index.html.erb +++ b/app/views/start/index.html.erb @@ -16,9 +16,10 @@

The data will be used to update the national record for social housing. It will also help to inform policy about the cost of social housing and what type of housing needs to be built.

This service is only for social housing in England.

+ <% start_path = current_user ? case_logs_path : (user_session_path + "?start=true") %> <%= govuk_start_button( text: 'Start now', - href: user_session_path + href: start_path ) %>

Before you start

diff --git a/spec/controllers/start_controller_spec.rb b/spec/controllers/start_controller_spec.rb index 0422225aa..f2af13a39 100644 --- a/spec/controllers/start_controller_spec.rb +++ b/spec/controllers/start_controller_spec.rb @@ -1,6 +1,5 @@ require "rails_helper" -# Test Controller intital test RSpec.describe StartController, type: :controller do let(:valid_session) { {} } diff --git a/spec/features/start_page_spec.rb b/spec/features/start_page_spec.rb new file mode 100644 index 000000000..27107bcb6 --- /dev/null +++ b/spec/features/start_page_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" +require_relative "form/helpers" + +RSpec.describe "Start Page Features" do + include Helpers + let(:user) { FactoryBot.create(:user) } + + context "a signed in user" do + before do + sign_in user + end + + it "takes you to your logs" do + visit("/") + click_link("Start now") + expect(page).to have_current_path("/logs") + end + end + + context "a not signed in user" do + it "takes you to sign in and then to your logs" do + visit("/") + click_link("Start now") + expect(page).to have_current_path("/users/sign-in?start=true") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: user.password) + click_button("Sign in") + expect(page).to have_current_path("/logs") + end + end +end