Skip to content

Commit

Permalink
Merge pull request #17 from SOFware/fix/end-of-last-completed
Browse files Browse the repository at this point in the history
Fix/end of last completed
  • Loading branch information
jdowd authored Sep 2, 2024
2 parents 0efbdec + e0508c4 commit 2994de8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.5] - Unreleased
## [0.1.5] - 2024-09-02

### Fixed

- `Cycle#last_completed` works for dormant cycles too

## [0.1.4] - 2024-09-02

Expand Down
2 changes: 1 addition & 1 deletion lib/sof/cycles/end_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def to_s
end

# Always returns the from_date
def last_completed(_) = from_date.to_date
def last_completed(_ = nil) = from_date&.to_date

# Returns the expiration date for the cycle
#
Expand Down
14 changes: 14 additions & 0 deletions spec/sof/cycles/dormant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ module SOF

it_behaves_like "#kind returns", :dormant

describe "#last_completed" do
context "with a dormant Within cycle" do
it "returns nil" do
expect(within_cycle.last_completed(completed_dates)).to eq recent_date
end
end

context "with a dormant EndOf cycle" do
it "returns nil" do
expect(end_of_cycle.last_completed).to be_nil
end
end
end

describe "#recurring?" do
it "does not repeat" do
expect(within_cycle).not_to be_recurring
Expand Down
15 changes: 14 additions & 1 deletion spec/sof/cycles/end_of_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ module SOF
it_behaves_like "#as_json returns the notation"
it_behaves_like "it computes #final_date(given)",
given: nil, returns: ("2020-01-01".to_date + 17.months).end_of_month
it_behaves_like "last_completed is", :from_date

describe "#last_completed" do
context "with an activated cycle" do
it_behaves_like "last_completed is", :from_date
end

context "with a dormant cycle" do
let(:notation) { "V2E18M" }

it "returns nil" do
expect(cycle.last_completed).to be_nil
end
end
end

describe "#covered_dates" do
let(:completed_dates) do
Expand Down

0 comments on commit 2994de8

Please sign in to comment.