Browse Source

[CLDC-1738] use OPTIONAL_FIELDS in optional_fields (#1151)

chloe-1
Jack 2 years ago committed by GitHub
parent
commit
143ff51acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/sales_log.rb
  2. 1
      spec/factories/sales_log.rb
  3. 38
      spec/models/sales_log_spec.rb

2
app/models/sales_log.rb

@ -48,7 +48,7 @@ class SalesLog < Log
end end
def optional_fields def optional_fields
[] OPTIONAL_FIELDS
end end
def not_started? def not_started?

1
spec/factories/sales_log.rb

@ -12,7 +12,6 @@ FactoryBot.define do
saledate { Time.utc(2022, 2, 2, 10, 36, 49) } saledate { Time.utc(2022, 2, 2, 10, 36, 49) }
end end
trait :completed do trait :completed do
purchid { "PC123" }
ownershipsch { 2 } ownershipsch { 2 }
type { 8 } type { 8 }
saledate { Time.utc(2022, 2, 2, 10, 36, 49) } saledate { Time.utc(2022, 2, 2, 10, 36, 49) }

38
spec/models/sales_log_spec.rb

@ -2,8 +2,8 @@ require "rails_helper"
require "shared/shared_examples_for_derived_fields" require "shared/shared_examples_for_derived_fields"
RSpec.describe SalesLog, type: :model do RSpec.describe SalesLog, type: :model do
let(:owning_organisation) { FactoryBot.create(:organisation) } let(:owning_organisation) { create(:organisation) }
let(:created_by_user) { FactoryBot.create(:user) } let(:created_by_user) { create(:user) }
include_examples "shared examples for derived fields", :sales_log include_examples "shared examples for derived fields", :sales_log
@ -13,7 +13,7 @@ RSpec.describe SalesLog, type: :model do
end end
it "is a sales log" do 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 expect(sales_log.lettings?).to be false
end end
@ -30,9 +30,17 @@ RSpec.describe SalesLog, type: :model do
end end
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 describe "#form" do
let(:sales_log) { FactoryBot.build(:sales_log, created_by: created_by_user) } let(:sales_log) { 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_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 it "has returns the correct form based on the start date" do
expect(sales_log.form_name).to be_nil expect(sales_log.form_name).to be_nil
@ -43,9 +51,9 @@ RSpec.describe SalesLog, type: :model do
end end
describe "status" do describe "status" do
let!(:empty_sales_log) { FactoryBot.create(:sales_log) } let!(:empty_sales_log) { create(:sales_log) }
let!(:in_progress_sales_log) { FactoryBot.create(:sales_log, :in_progress) } let!(:in_progress_sales_log) { create(:sales_log, :in_progress) }
let!(:completed_sales_log) { FactoryBot.create(:sales_log, :completed) } let!(:completed_sales_log) { create(:sales_log, :completed) }
it "is set to not started for an empty sales log" do it "is set to not started for an empty sales log" do
expect(empty_sales_log.not_started?).to be(true) expect(empty_sales_log.not_started?).to be(true)
@ -67,15 +75,15 @@ RSpec.describe SalesLog, type: :model do
end end
context "when filtering by organisation" do context "when filtering by organisation" do
let(:organisation_1) { FactoryBot.create(:organisation) } let(:organisation_1) { create(:organisation) }
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { create(:organisation) }
let(:organisation_3) { FactoryBot.create(:organisation) } let(:organisation_3) { create(:organisation) }
before do before do
FactoryBot.create(:sales_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1) 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) 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) 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, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2)
end end
it "filters by given organisation id" do it "filters by given organisation id" do

Loading…
Cancel
Save