Browse Source

Redirect to logs if they clicked start now (#175)

pull/159/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
11c1df0bdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/controllers/auth/sessions_controller.rb
  2. 1
      app/views/devise/sessions/new.html.erb
  3. 3
      app/views/start/index.html.erb
  4. 1
      spec/controllers/start_controller_spec.rb
  5. 31
      spec/features/start_page_spec.rb

6
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

1
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" %>
</div>
</div>

3
app/views/start/index.html.erb

@ -16,9 +16,10 @@
<p class="govuk-body">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.</p>
<p class="govuk-body">This service is only for social housing in England.</p>
<% 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
) %>
<h2 class="govuk-heading-m">Before you start</h2>

1
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) { {} }

31
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
Loading…
Cancel
Save