Browse Source

wip

CLDC-1324
Kat 2 years ago
parent
commit
b65f718afe
  1. 14
      app/controllers/form_controller.rb
  2. 7
      spec/features/lettings_log_spec.rb

14
app/controllers/form_controller.rb

@ -1,7 +1,8 @@
class FormController < ApplicationController
before_action :authenticate_user!
before_action :find_resource, only: %i[submit_form review]
before_action :find_resource_by_named_id, except: %i[submit_form review]
before_action :find_resource_by_named_id, except: %i[submit_form review show_new_page]
before_action :create_new_resource, only: %i[show_new_page]
def submit_form
if @log
@ -13,7 +14,7 @@ class FormController < ApplicationController
session[:errors] = session[:fields] = nil
redirect_to(successful_redirect_path)
else
redirect_path = "#{@log.model_name.param_key}_#{@page.id}_path"
redirect_path = @log.status == "not_started" ? "#{@log.model_name.param_key}s_new_#{@page.id}_path" : "#{@log.model_name.param_key}_#{@page.id}_path"
mandatory_questions_with_no_response.map do |question|
@log.errors.add question.id.to_sym, question.unanswered_error_message
end
@ -62,7 +63,6 @@ class FormController < ApplicationController
def show_new_page
page_id = request.path.split("/")[-1].underscore
save_new_log page_id
if @log
restore_error_field_values
page_id = request.path.split("/")[-1].underscore
@ -159,6 +159,14 @@ private
end
end
def create_new_resource
@log = if request.path.include?("sales-logs")
SalesLog.new
else
LettingsLog.new
end
end
def new_log_request?
request.path.split("/").include?("new")
end

7
spec/features/lettings_log_spec.rb

@ -124,6 +124,13 @@ RSpec.describe "Lettings Log Features" do
end
end
context "when creating a new log" do
it "creates a log after answering at least 1 question" do
visit("/lettings-logs")
expect { click_button("Create a new lettings log") }.to change(LettingsLog, :count).by(0)
end
end
context "when returning to the list of logs via breadcrumbs link" do
before do
visit("/lettings-logs")

Loading…
Cancel
Save