|
|
@ -146,14 +146,6 @@ RSpec.describe CollectionTimeHelper do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when valid overrides are provided" do |
|
|
|
|
|
|
|
it "returns a different date within the overridden range" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 5, 1), end_date_override: Time.zone.local(2024, 7, 1)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2024, 5, 1), Time.zone.local(2024, 7, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when the date is at the start of the collection year" do |
|
|
|
context "when the date is at the start of the collection year" do |
|
|
|
let(:date) { Time.zone.local(2024, 4, 1) } |
|
|
|
let(:date) { Time.zone.local(2024, 4, 1) } |
|
|
|
|
|
|
|
|
|
|
@ -173,5 +165,53 @@ RSpec.describe CollectionTimeHelper do |
|
|
|
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)) |
|
|
|
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when start_date_override is before the collection year" do |
|
|
|
|
|
|
|
it "ignores the override and returns a different date within the collection year" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when end_date_override is after the collection year" do |
|
|
|
|
|
|
|
it "ignores the override and returns a different date within the collection year" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, end_date_override: Time.zone.local(2025, 12, 1)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when both start_date_override and end_date_override are provided and valid" do |
|
|
|
|
|
|
|
it "returns a different date within the overridden range" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 8, 1), end_date_override: Time.zone.local(2024, 9, 1)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2024, 8, 1), Time.zone.local(2024, 9, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when both start_date_override and end_date_override are provided but start_date_override is before the collection year" do |
|
|
|
|
|
|
|
it "ignores the start_date_override and returns a different date within the collection year" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2024, 5, 1)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2024, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when both start_date_override and end_date_override are provided but end_date_override is after the collection year" do |
|
|
|
|
|
|
|
it "ignores the end_date_override and returns a different date within the collection year" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2025, 3, 1), end_date_override: Time.zone.local(2025, 12, 1)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2025, 3, 1), Time.zone.local(2025, 3, 31)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when both start_date_override and end_date_override are outside the collection year" do |
|
|
|
|
|
|
|
it "ignores both overrides and returns a different date within the collection year" do |
|
|
|
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2025, 12, 1)) |
|
|
|
|
|
|
|
expect(result).not_to eq(date) |
|
|
|
|
|
|
|
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|