Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update started_at and finished_at to be nil if started_at or finished_at string is unparseable by Time #79

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/stream_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def self.user_group_ids?(event_data)

def self.started_at(event_data)
started_at = event_data.fetch('metadata')&.fetch('started_at', nil)
Time.parse(started_at) if started_at
Time.parse(started_at) rescue nil if started_at
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
end

def self.finished_at(event_data)
finished_at = event_data.fetch('metadata')&.fetch('finished_at', nil)
Time.parse(finished_at) if finished_at
Time.parse(finished_at) rescue nil if finished_at
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
end

def self.session_time(event_data)
Expand Down
11 changes: 11 additions & 0 deletions spec/models/stream_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,22 @@
expect(StreamEvents.started_at(event_data)).to be_nil
end

it 'returns started_at to nil if started_at cannot be parsed' do
# set started_at to some unparseable time string
event_metadata['started_at'] = '-1 OR 2+742-742-1=0+0+0+1 --'
expect(StreamEvents.started_at(event_data)).to be_nil
end

it 'returns finished_at to nil if no finished_at in metadata' do
event_metadata.delete('finished_at')
expect(StreamEvents.finished_at(event_data)).to be_nil
end

it 'returns finished_at to nil if started_at cannot be parsed' do
event_metadata['finished_at'] = '-1 OR 2+742-742-1=0+0+0+1 --'
expect(StreamEvents.finished_at(event_data)).to be_nil
end

context 'user_group_ids?' do
it 'returns true if classification done by user that belongs to multiple user groups' do
expect(StreamEvents.user_group_ids?(event_data)).to be true
Expand Down
Loading