Skip to content

Commit

Permalink
Fix medication refill bug for Google Calendar upload (#1278)
Browse files Browse the repository at this point in the history
* Fix medication refill bug for Google Calendar upload

* Add more tests
  • Loading branch information
julianguyen authored Nov 22, 2018
1 parent 7d2fdbe commit 5650089
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
3 changes: 1 addition & 2 deletions app/services/calendar_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def initialize(summary:,
end

def upload_event
parsed_date = Chronic.parse(date, endian_precedence: %i[little median])
.to_time.iso8601
parsed_date = date.to_time.iso8601

event = {
summary: summary,
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ en:
location: Location
description: Description
error_explanation: 'Please fill out the marked fields!'
search_by_keywords: 'Search by keyword'
search_by_keywords: 'Search by keywords'
time_ago: '%{date} ago'
write_to_us: 'write to us'
days: Days
Expand Down
36 changes: 26 additions & 10 deletions spec/services/calendar_uploader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
# frozen_string_literal: true

describe CalendarUploader do
it 'uploads an event to Google Calendar' do
service = double
let(:service) { double }

before(:each) do
allow(service).to receive_message_chain(:insert_event)
allow(service).to receive_message_chain(:authorization=, :access_token=)
end

uploader = CalendarUploader.new(summary: 'an exciting event',
date: '2015/02/14',
access_token: 'a token',
email: 'an email',
service: service)
context 'date is a string' do
it 'uploads an event to Google Calendar' do
uploader = CalendarUploader.new(summary: 'an exciting event',
date: '2015/02/14',
access_token: 'a token',
email: 'an email',
service: service)

expect(service).to receive(:insert_event)
uploader.upload_event
end
end

expect(service).to receive(:insert_event)
context 'date is a DateTime object' do
it 'uploads an event to Google Calendar' do
uploader = CalendarUploader.new(summary: 'an exciting event',
date: DateTime.now,
access_token: 'a token',
email: 'an email',
service: service)

uploader.upload_event
expect(service).to receive(:insert_event)
uploader.upload_event
end
end
end

0 comments on commit 5650089

Please sign in to comment.