|
|
|
@ -1,6 +1,7 @@ |
|
|
|
require "rails_helper" |
|
|
|
require "rails_helper" |
|
|
|
require "shared/shared_examples_for_derived_fields" |
|
|
|
require "shared/shared_examples_for_derived_fields" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# rubocop:disable RSpec/MessageChain |
|
|
|
# rubocop:disable RSpec/AnyInstance |
|
|
|
# rubocop:disable RSpec/AnyInstance |
|
|
|
RSpec.describe SalesLog, type: :model do |
|
|
|
RSpec.describe SalesLog, type: :model do |
|
|
|
let(:owning_organisation) { create(:organisation) } |
|
|
|
let(:owning_organisation) { create(:organisation) } |
|
|
|
@ -607,5 +608,55 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "#collection_period_open?" do |
|
|
|
|
|
|
|
let(:log) { build(:sales_log, saledate:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when saledate is nil" do |
|
|
|
|
|
|
|
let(:saledate) { nil } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
|
|
|
expect(log.collection_period_open?).to eq(true) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when older_than_previous_collection_year" do |
|
|
|
|
|
|
|
let(:previous_collection_start_date) { Time.zone.local(2050, 4, 1) } |
|
|
|
|
|
|
|
let(:saledate) { previous_collection_start_date - 1.day } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
allow(log).to receive(:previous_collection_start_date).and_return(previous_collection_start_date) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns true" do |
|
|
|
|
|
|
|
expect(log.collection_period_open?).to eq(false) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when form end date is in the future" do |
|
|
|
|
|
|
|
let(:saledate) { nil } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now + 1.day) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns true" do |
|
|
|
|
|
|
|
expect(log.collection_period_open?).to eq(true) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when form end date is in the past" do |
|
|
|
|
|
|
|
let(:saledate) { Time.zone.local(2020, 4, 1) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now - 1.day) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
|
|
|
expect(log.collection_period_open?).to eq(false) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
# rubocop:enable RSpec/AnyInstance |
|
|
|
# rubocop:enable RSpec/AnyInstance |
|
|
|
|
|
|
|
# rubocop:enable RSpec/MessageChain |
|
|
|
|