Skip to content

Commit

Permalink
Allow date of birth to be supplied as a Date or Time
Browse files Browse the repository at this point in the history
Forcing a String parameter is a bit restrictive, particularly when using
a framework that automatically converts dates as they come out of
database (e.g. Rails / ActiveRecord).

The user shouldn't need to get involved in the implementation details
given how easy it is for the library to convert to a String
  • Loading branch information
HashNotAdam committed Jan 3, 2020
1 parent cdc26a0 commit 628e81f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/eml/uk/payload/card/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def city=(city)
@city = city
end

sig { params(dob: String).void }
sig { params(dob: T.any(Date, String, Time)).void }
def dob=(dob)
dob = dob.strftime("%m%d%Y") if dob.respond_to?(:strftime)
validate_dob(dob)
@dob = dob
end
Expand Down
2 changes: 1 addition & 1 deletion lib/eml/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# frozen_string_literal: true

module EML
VERSION = "2.1.7"
VERSION = "2.1.8"
end
23 changes: 21 additions & 2 deletions spec/uk/resources/card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,32 @@
context "when the DOB is in the wrong format" do
it "raises an ArgumentError" do
payload[:dob] = "31012000"
cassette = "uk/card/register/dob"
EML::Helpers::VCR.with_cassette(cassette) do
EML::Helpers::VCR.with_cassette("uk/card/register/dob_string") do
expect { described_class.register(id: card_id, payload: payload) }.
to raise_error(ArgumentError)
end
end
end

context "when the DOB is a Date object" do
it "registers the card" do
payload[:dob] = Date.parse("2000-01-31")
EML::Helpers::VCR.with_cassette("uk/card/register/dob_date") do
response = described_class.register(id: card_id, payload: payload)
expect(response.success?).to be true
end
end
end

context "when the DOB is a Time object" do
it "registers the card" do
payload[:dob] = Time.parse("2000-01-31")
EML::Helpers::VCR.with_cassette("uk/card/register/dob_date") do
response = described_class.register(id: card_id, payload: payload)
expect(response.success?).to be true
end
end
end
end

describe ".reload" do
Expand Down

0 comments on commit 628e81f

Please sign in to comment.