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 class FormController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :find_resource, only: %i[submit_form review] 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 def submit_form
if @log if @log
@ -13,7 +14,7 @@ class FormController < ApplicationController
session[:errors] = session[:fields] = nil session[:errors] = session[:fields] = nil
redirect_to(successful_redirect_path) redirect_to(successful_redirect_path)
else 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| mandatory_questions_with_no_response.map do |question|
@log.errors.add question.id.to_sym, question.unanswered_error_message @log.errors.add question.id.to_sym, question.unanswered_error_message
end end
@ -62,7 +63,6 @@ class FormController < ApplicationController
def show_new_page def show_new_page
page_id = request.path.split("/")[-1].underscore page_id = request.path.split("/")[-1].underscore
save_new_log page_id
if @log if @log
restore_error_field_values restore_error_field_values
page_id = request.path.split("/")[-1].underscore page_id = request.path.split("/")[-1].underscore
@ -159,6 +159,14 @@ private
end end
end end
def create_new_resource
@log = if request.path.include?("sales-logs")
SalesLog.new
else
LettingsLog.new
end
end
def new_log_request? def new_log_request?
request.path.split("/").include?("new") request.path.split("/").include?("new")
end end

7
spec/features/lettings_log_spec.rb

@ -124,6 +124,13 @@ RSpec.describe "Lettings Log Features" do
end end
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 context "when returning to the list of logs via breadcrumbs link" do
before do before do
visit("/lettings-logs") visit("/lettings-logs")

Loading…
Cancel
Save