Browse Source

Make the test pass

pull/863/head
baarkerlounger 3 years ago
parent
commit
d14475e14c
  1. 8
      app/components/check_answers_summary_list_card_component.html.erb
  2. 10
      app/components/check_answers_summary_list_card_component.rb
  3. 5
      app/controllers/lettings_logs_controller.rb
  4. 2
      app/controllers/logs_controller.rb
  5. 2
      app/controllers/modules/logs_filter.rb
  6. 4
      app/controllers/sales_logs_controller.rb
  7. 30
      app/models/all_log.rb
  8. 2
      app/models/lettings_log.rb
  9. 3
      app/models/log.rb
  10. 3
      app/models/sales_log.rb
  11. 0
      app/views/logs/_log_filters.erb
  12. 0
      app/views/logs/_log_list.html.erb
  13. 0
      app/views/logs/_tasklist.html.erb
  14. 0
      app/views/logs/bulk_upload.html.erb
  15. 0
      app/views/logs/edit.html.erb
  16. 0
      app/views/logs/index.html.erb
  17. 25
      app/views/sales_logs/_tasklist.html.erb
  18. 37
      app/views/sales_logs/edit.html.erb
  19. 3
      config/routes.rb
  20. 6
      db/schema.rb
  21. 6
      db/views/logs_v01.sql
  22. 12
      spec/requests/lettings_logs_controller_spec.rb

8
app/components/check_answers_summary_list_card_component.html.erb

@ -16,18 +16,18 @@
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %>
<% row.value do %>
<span class="govuk-!-margin-right-4"><%= get_answer_label(question) %></span>
<% extra_value = question.get_extra_check_answer_value(lettings_log) %>
<% extra_value = question.get_extra_check_answer_value(log) %>
<% if extra_value %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span>
<% end %>
<br>
<% question.get_inferred_answers(lettings_log).each do |inferred_answer| %>
<% question.get_inferred_answers(log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
<% end %>
<% row.action(
text: question.action_text(lettings_log),
href: question.action_href(lettings_log, question.page.id),
text: question.action_text(log),
href: question.action_href(log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>

10
app/components/check_answers_summary_list_card_component.rb

@ -1,18 +1,18 @@
class CheckAnswersSummaryListCardComponent < ViewComponent::Base
attr_reader :questions, :lettings_log, :user
attr_reader :questions, :log, :user
def initialize(questions:, lettings_log:, user:)
def initialize(questions:, log:, user:)
@questions = questions
@lettings_log = lettings_log
@log = log
@user = user
super
end
def applicable_questions
questions.reject { |q| q.hidden_in_check_answers?(lettings_log, user) }
questions.reject { |q| q.hidden_in_check_answers?(log, user) }
end
def get_answer_label(question)
question.answer_label(lettings_log).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
question.answer_label(log).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
end

5
app/controllers/lettings_logs_controller.rb

@ -12,6 +12,7 @@ class LettingsLogsController < LogsController
@pagy, @lettings_logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
render "logs/index"
end
format.csv do
@ -39,7 +40,7 @@ class LettingsLogsController < LogsController
def show
respond_to do |format|
# We don't have a dedicated non-editable show view
format.html { edit }
format.html { render "logs/edit" }
format.json do
if @lettings_log
render json: @lettings_log, status: :ok
@ -53,7 +54,7 @@ class LettingsLogsController < LogsController
def edit
@lettings_log = current_user.lettings_logs.find_by(id: params[:id])
if @lettings_log
render :edit, locals: { current_user: }
render "logs/edit", locals: { current_user: }
else
render_not_found
end

2
app/controllers/logs_controller.rb

@ -10,7 +10,7 @@ class LogsController < ApplicationController
def index
set_session_filters
all_logs = current_user.lettings_logs + current_user.sales_logs
all_logs = AllLog.where(id: (current_user.lettings_logs + current_user.sales_logs).pluck(:id))
unpaginated_filtered_logs = filtered_logs(filtered_collection(all_logs, search_term))
respond_to do |format|

2
app/controllers/modules/logs_filter.rb

@ -9,7 +9,7 @@ module Modules::LogsFilter
logs = logs.public_send("filter_by_#{category}", values, current_user)
end
end
logs = logs.sort_by(&:created_at)
logs = logs.order(created_at: :desc)
current_user.support? ? logs.all.includes(:owning_organisation, :managing_organisation) : logs
end

4
app/controllers/sales_logs_controller.rb

@ -5,14 +5,14 @@ class SalesLogsController < LogsController
def show
respond_to do |format|
format.html { edit }
format.html { "logs/edit" }
end
end
def edit
@sales_log = current_user.sales_logs.find_by(id: params[:id])
if @sales_log
render :edit, locals: { current_user: }
render "logs/edit", locals: { current_user: }
else
render_not_found
end

30
app/models/all_log.rb

@ -0,0 +1,30 @@
class AllLog < ApplicationRecord
self.table_name = :logs
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
enum status: STATUS
def read_only?
true
end
def tenancycode?
log_type == "lettings"
end
def needstype?
log_type == "lettings"
end
def startdate?
false
end
def is_general_needs?
log_type == "lettings"
end
def created_by
User.find(created_by_id)
end
end

2
app/models/lettings_log.rb

@ -67,11 +67,9 @@ class LettingsLog < Log
OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze
RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
enum status: STATUS
def form
FormHandler.instance.get_form(form_name) || FormHandler.instance.forms.first.second

3
app/models/log.rb

@ -5,6 +5,9 @@ class Log < ApplicationRecord
belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
enum status: STATUS
scope :combined, -> { ActiveRecord::Base.connection.execute("SELECT * FROM logs") }
def collection_start_year

3
app/models/sales_log.rb

@ -10,9 +10,6 @@ class SalesLog < Log
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
enum status: STATUS
OPTIONAL_FIELDS = [].freeze
def startdate

0
app/views/lettings_logs/_log_filters.erb → app/views/logs/_log_filters.erb

0
app/views/lettings_logs/_log_list.html.erb → app/views/logs/_log_list.html.erb

0
app/views/lettings_logs/_tasklist.html.erb → app/views/logs/_tasklist.html.erb

0
app/views/lettings_logs/bulk_upload.html.erb → app/views/logs/bulk_upload.html.erb

0
app/views/lettings_logs/edit.html.erb → app/views/logs/edit.html.erb

0
app/views/lettings_logs/index.html.erb → app/views/logs/index.html.erb

25
app/views/sales_logs/_tasklist.html.erb

@ -1,25 +0,0 @@
<ol class="app-task-list govuk-!-margin-top-8">
<% @sales_log.form.sections.map do |section| %>
<li>
<h2 class="app-task-list__section-heading">
<%= section.label %>
</h2>
<% if section.description %>
<p class="govuk-body"><%= section.description.html_safe %></p>
<% end %>
<ul class="app-task-list__items">
<% section.subsections.map do |subsection| %>
<% if subsection.applicable_questions(@sales_log).count > 0 || !subsection.enabled?(@sales_log) %>
<% subsection_status = subsection.status(@sales_log) %>
<li class="app-task-list__item">
<span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>">
<%= subsection_link(subsection, @sales_log, current_user) %>
</span>
<%= status_tag(subsection_status, "app-task-list__tag") %>
</li>
<% end %>
<% end %>
</ul>
</li>
<% end %>
</ol>

37
app/views/sales_logs/edit.html.erb

@ -1,37 +0,0 @@
<% content_for :title, "Log #{@sales_log.id}" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
content_for(:title) => "",
}) %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl">
<%= content_for(:title) %>
</h1>
<% if @sales_log.status == "in_progress" %>
<p class="govuk-body govuk-!-margin-bottom-7"><%= get_subsections_count(@sales_log, :completed) %> of <%= get_subsections_count(@sales_log, :all) %> sections completed.</p>
<p class="govuk-body govuk-!-margin-bottom-2">
<% next_incomplete_section = get_next_incomplete_section(@sales_log) %>
</p>
<p>
<% if next_incomplete_section.present? %>
<a class="app-section-skip-link" href="#<%= next_incomplete_section.id.dasherize %>">
Skip to next incomplete section: <%= next_incomplete_section.label %>
</a>
<% end %>
</p>
<% elsif @sales_log.status == "not_started" %>
<p class="govuk-body">This log has not been started.</p>
<% elsif @sales_log.status == "completed" %>
<p class="govuk-body">
<%= status_tag(@sales_log.status) %>
</p>
<p class="govuk-body">
You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@sales_log.id}/review" %> until 2nd June <%= @sales_log.collection_start_year.present? ? @sales_log.collection_start_year + 1 : "" %>.
</p>
<% end %>
<%= render "tasklist" %>
</div>
</div>

3
config/routes.rb

@ -74,7 +74,8 @@ Rails.application.routes.draw do
end
get "logs", to: "logs#index"
resources :lettings_logs, path: "/logs" do
resources :lettings_logs, path: "/lettings-logs" do
collection do
post "bulk-upload", to: "bulk_upload#bulk_upload"
get "bulk-upload", to: "bulk_upload#show"

6
db/schema.rb

@ -417,12 +417,18 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_08_153924) do
SELECT lettings_logs.id,
lettings_logs.status,
lettings_logs.created_at,
lettings_logs.tenancycode,
lettings_logs.propcode,
lettings_logs.created_by_id,
'lettings'::text AS log_type
FROM lettings_logs
UNION
SELECT sales_logs.id,
sales_logs.status,
sales_logs.created_at,
NULL::character varying AS tenancycode,
NULL::character varying AS propcode,
sales_logs.created_by_id,
'sales'::text AS log_type
FROM sales_logs;
SQL

6
db/views/logs_v01.sql

@ -2,6 +2,9 @@ SELECT
id,
status,
created_at,
tenancycode,
propcode,
created_by_id,
'lettings' as log_type
FROM lettings_logs
@ -11,5 +14,8 @@ SELECT
id,
status,
created_at,
null as tenancycode,
null as propcode,
created_by_id,
'sales' as log_type
FROM sales_logs

12
spec/requests/lettings_logs_controller_spec.rb

@ -50,7 +50,7 @@ RSpec.describe LettingsLogsController, type: :request do
before do
Timecop.freeze(Time.utc(2022, 2, 8))
post "/logs", headers:, params: params.to_json
post "/lettings-logs", headers:, params: params.to_json
end
after do
@ -132,7 +132,7 @@ RSpec.describe LettingsLogsController, type: :request do
before do
RequestHelper.stub_http_requests
sign_in user
post "/logs", headers:
post "/lettings-logs", headers:
end
it "tracks who created the record" do
@ -826,7 +826,7 @@ RSpec.describe LettingsLogsController, type: :request do
let(:id) { lettings_log.id }
before do
patch "/logs/#{id}", headers:, params: params.to_json
patch "/lettings-logs/#{id}", headers:, params: params.to_json
end
it "returns http success" do
@ -884,7 +884,7 @@ RSpec.describe LettingsLogsController, type: :request do
let(:id) { lettings_log.id }
before do
put "/logs/#{id}", headers:, params: params.to_json
put "/lettings-logs/#{id}", headers:, params: params.to_json
end
it "returns http success" do
@ -924,7 +924,7 @@ RSpec.describe LettingsLogsController, type: :request do
context "when deleting a lettings log" do
before do
delete "/logs/#{id}", headers:
delete "/lettings-logs/#{id}", headers:
end
it "returns http success" do
@ -958,7 +958,7 @@ RSpec.describe LettingsLogsController, type: :request do
before do
allow(LettingsLog).to receive(:find_by).and_return(lettings_log)
allow(lettings_log).to receive(:delete).and_return(false)
delete "/logs/#{id}", headers:
delete "/lettings-logs/#{id}", headers:
end
it "returns an unprocessable entity 422" do

Loading…
Cancel
Save