This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract out helper method. Additional specs
- Loading branch information
Showing
5 changed files
with
90 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module PaymentProcessor | ||
module GoCardless | ||
module Helper | ||
extend self | ||
|
||
# Returns the next date for the passed day. | ||
# | ||
# === Attributes | ||
# | ||
# *day+ - The day to set the date too. | ||
def next_available_date(day) | ||
date = Date.today.change(day: day) | ||
|
||
if Time.now.day >= day | ||
date += 1.month | ||
end | ||
|
||
date | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'rails_helper' | ||
|
||
describe PaymentProcessor::GoCardless::Helper do | ||
describe '.next_available_date' do | ||
subject { PaymentProcessor::GoCardless::Helper } | ||
|
||
context 'day has not passed' do | ||
it 'returns current month' do | ||
Timecop.freeze('5 May') do | ||
expect(subject.next_available_date(6)).to eq(Date.parse('6 May')) | ||
end | ||
end | ||
end | ||
|
||
context 'day is today' do | ||
it 'returns with following month' do | ||
Timecop.freeze('5 May') do | ||
expect(subject.next_available_date(5)).to eq(Date.parse('5 June')) | ||
end | ||
end | ||
end | ||
|
||
context 'day has passed' do | ||
it 'returns with following month' do | ||
Timecop.freeze('5 May') do | ||
expect(subject.next_available_date(4)).to eq(Date.parse('4 June')) | ||
end | ||
end | ||
end | ||
|
||
context 'invalid day' do | ||
it 'raises argument error' do | ||
expect { | ||
subject.next_available_date(32) | ||
}.to raise_error(ArgumentError, 'invalid date') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters