|
|
|
@ -106,4 +106,72 @@ RSpec.describe CollectionTimeHelper do
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#generate_different_date_within_collection_year" do |
|
|
|
|
let(:date) { Time.zone.local(2024, 6, 15) } |
|
|
|
|
|
|
|
|
|
context "when no overrides are provided" do |
|
|
|
|
it "returns a different date within the collection year" do |
|
|
|
|
result = generate_different_date_within_collection_year(date) |
|
|
|
|
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 start_date_override is the last day" do |
|
|
|
|
it "returns nil" do |
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2025, 3, 31)) |
|
|
|
|
expect(result).to be_nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when end_date_override is the first day" do |
|
|
|
|
it "returns nil" do |
|
|
|
|
result = generate_different_date_within_collection_year(date, end_date_override: Time.zone.local(2024, 4, 1)) |
|
|
|
|
expect(result).to be_nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when start_date_override and end_date_override are the same day" do |
|
|
|
|
it "returns nil" do |
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 6, 15), end_date_override: Time.zone.local(2024, 6, 15)) |
|
|
|
|
expect(result).to be_nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when start_date_override is greater than end_date_override" do |
|
|
|
|
it "returns nil" do |
|
|
|
|
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 7, 1), end_date_override: Time.zone.local(2024, 6, 1)) |
|
|
|
|
expect(result).to be_nil |
|
|
|
|
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 |
|
|
|
|
let(:date) { Time.zone.local(2024, 4, 1) } |
|
|
|
|
|
|
|
|
|
it "returns a different date within the collection year" do |
|
|
|
|
result = generate_different_date_within_collection_year(date) |
|
|
|
|
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 the date is at the end of the collection year" do |
|
|
|
|
let(:date) { Time.zone.local(2025, 3, 31) } |
|
|
|
|
|
|
|
|
|
it "returns a different date within the collection year" do |
|
|
|
|
result = generate_different_date_within_collection_year(date) |
|
|
|
|
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 |
|
|
|
|