|
|
@ -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 |
|
|
|