From 143ff51acf2922b842cb887643659b987d42e44b Mon Sep 17 00:00:00 2001 From: Jack <113976590+bibblobcode@users.noreply.github.com> Date: Fri, 6 Jan 2023 10:19:43 +0000 Subject: [PATCH] [CLDC-1738] use OPTIONAL_FIELDS in optional_fields (#1151) --- app/models/sales_log.rb | 2 +- spec/factories/sales_log.rb | 1 - spec/models/sales_log_spec.rb | 38 +++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 4147cbf36..22f750148 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -48,7 +48,7 @@ class SalesLog < Log end def optional_fields - [] + OPTIONAL_FIELDS end def not_started? diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 44ff8de35..138a5c394 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -12,7 +12,6 @@ FactoryBot.define do saledate { Time.utc(2022, 2, 2, 10, 36, 49) } end trait :completed do - purchid { "PC123" } ownershipsch { 2 } type { 8 } saledate { Time.utc(2022, 2, 2, 10, 36, 49) } diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index ebfd7009d..8f46db42d 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -2,8 +2,8 @@ require "rails_helper" require "shared/shared_examples_for_derived_fields" RSpec.describe SalesLog, type: :model do - let(:owning_organisation) { FactoryBot.create(:organisation) } - let(:created_by_user) { FactoryBot.create(:user) } + let(:owning_organisation) { create(:organisation) } + let(:created_by_user) { create(:user) } include_examples "shared examples for derived fields", :sales_log @@ -13,7 +13,7 @@ RSpec.describe SalesLog, type: :model do end it "is a sales log" do - sales_log = FactoryBot.build(:sales_log, created_by: created_by_user) + sales_log = build(:sales_log, created_by: created_by_user) expect(sales_log.lettings?).to be false end @@ -30,9 +30,17 @@ RSpec.describe SalesLog, type: :model do end end + describe "#optional_fields" do + let(:sales_log) { build(:sales_log) } + + it "returns optional fields" do + expect(sales_log.optional_fields).to eq(%w[purchid]) + end + end + describe "#form" do - let(:sales_log) { FactoryBot.build(:sales_log, created_by: created_by_user) } - let(:sales_log_2) { FactoryBot.build(:sales_log, saledate: Time.zone.local(2022, 5, 1), created_by: created_by_user) } + let(:sales_log) { build(:sales_log, created_by: created_by_user) } + let(:sales_log_2) { build(:sales_log, saledate: Time.zone.local(2022, 5, 1), created_by: created_by_user) } it "has returns the correct form based on the start date" do expect(sales_log.form_name).to be_nil @@ -43,9 +51,9 @@ RSpec.describe SalesLog, type: :model do end describe "status" do - let!(:empty_sales_log) { FactoryBot.create(:sales_log) } - let!(:in_progress_sales_log) { FactoryBot.create(:sales_log, :in_progress) } - let!(:completed_sales_log) { FactoryBot.create(:sales_log, :completed) } + let!(:empty_sales_log) { create(:sales_log) } + let!(:in_progress_sales_log) { create(:sales_log, :in_progress) } + let!(:completed_sales_log) { create(:sales_log, :completed) } it "is set to not started for an empty sales log" do expect(empty_sales_log.not_started?).to be(true) @@ -67,15 +75,15 @@ RSpec.describe SalesLog, type: :model do end context "when filtering by organisation" do - let(:organisation_1) { FactoryBot.create(:organisation) } - let(:organisation_2) { FactoryBot.create(:organisation) } - let(:organisation_3) { FactoryBot.create(:organisation) } + let(:organisation_1) { create(:organisation) } + let(:organisation_2) { create(:organisation) } + let(:organisation_3) { create(:organisation) } before do - FactoryBot.create(:sales_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1) - FactoryBot.create(:sales_log, :completed, owning_organisation: organisation_1, managing_organisation: organisation_2) - FactoryBot.create(:sales_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_1) - FactoryBot.create(:sales_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2) + create(:sales_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1) + create(:sales_log, :completed, owning_organisation: organisation_1, managing_organisation: organisation_2) + create(:sales_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_1) + create(:sales_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2) end it "filters by given organisation id" do