Skip to content

Commit

Permalink
Allow nil datetimes as datetime fields (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
TABeauchat authored May 18, 2023
1 parent 411f0d6 commit e3baa04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_force/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize name, options = {}
def value_for_hash value
case as
when :datetime
value.to_fs(:iso8601)
value&.to_fs(:iso8601)
else
value
end
Expand Down
6 changes: 6 additions & 0 deletions spec/active_force/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
names = field.new(:time, as: :datetime)
expect(names.value_for_hash current_time).to eq current_time.to_fs(:iso8601)
end

it 'a datetime field whose value is nil' do
current_time = nil
names = field.new(:time, as: :datetime)
expect(names.value_for_hash current_time).to be_nil
end
end
end

0 comments on commit e3baa04

Please sign in to comment.