Skip to content

Commit

Permalink
Make sure there is an occurred_at attribute when serializing events
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt committed Nov 30, 2023
1 parent 612c8cb commit b5d42a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/userlist/push/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ def initialize(payload = {}, config = Userlist.config)
raise Userlist::ArgumentError, 'Missing required payload' unless payload
raise Userlist::ArgumentError, 'Missing required parameter :name' unless payload[:name]

super
end
payload[:occurred_at] ||= payload[:occured_at] || Time.now

def occurred_at
payload[:occurred_at] || payload[:occured_at] || Time.now
super
end

def push?
Expand Down
13 changes: 13 additions & 0 deletions spec/userlist/push/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@
expect(payload).to_not be
end
end

context 'when there is no occurred_at given' do
let(:event) do
Userlist::Push::Event.new(
user: user,
name: 'example_event'
)
end

it 'should set a default occurred_at' do
expect(payload[:occurred_at]).to be_within(1).of(Time.now)
end
end
end
end
end

0 comments on commit b5d42a4

Please sign in to comment.