Skip to content

Commit 3202e66

Browse files
fix: Allow nil values in date_accessor (#189)
1 parent 8b43e35 commit 3202e66

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

lib/seam/base_resource.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def self.date_accessor(*attrs)
4141
define_method(attr) do
4242
value = instance_variable_get(:"@#{attr}")
4343

44-
raise "No value for #{attr} set" if value.nil?
45-
46-
parse_datetime(value)
44+
value.nil? ? nil : parse_datetime(value)
4745
end
4846
end
4947
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Seam::Resources::AcsCredential do
4+
let(:client) { Seam.new(api_key: "seam_some_api_key") }
5+
6+
describe "date handling" do
7+
context "with nil dates" do
8+
let(:credential_hash) do
9+
{
10+
acs_credential_id: "test_id",
11+
issued_at: nil,
12+
created_at: nil
13+
}
14+
end
15+
16+
it "returns nil for nil date fields" do
17+
credential = described_class.new(credential_hash, client)
18+
expect(credential.issued_at).to be_nil
19+
expect(credential.created_at).to be_nil
20+
end
21+
end
22+
23+
context "with valid dates" do
24+
let(:now) { Time.now.utc }
25+
let(:credential_hash) do
26+
{
27+
acs_credential_id: "test_id",
28+
issued_at: now.iso8601,
29+
created_at: now.iso8601
30+
}
31+
end
32+
33+
it "parses date fields correctly" do
34+
credential = described_class.new(credential_hash, client)
35+
expect(credential.issued_at).to be_a(Time)
36+
expect(credential.created_at).to be_a(Time)
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)