-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pikesley
committed
Jan 30, 2016
1 parent
4eeed0a
commit 1787b86
Showing
10 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the api controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class ApiController < ApplicationController | ||
def create | ||
j = JSON.parse params[:json] | ||
|
||
k = {} | ||
k['datetime'] = j['datetime'] | ||
k['value'] = j['value'] | ||
|
||
g = GlucoseMeasurement.new k | ||
if g.save | ||
render json: g, status: :ok | ||
else | ||
render json: k, status: 400 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ApiHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'xmlsimple' | ||
require 'json' | ||
|
||
data = XmlSimple.xml_in File.read 'spec/support/fixtures/incoming.xml' | ||
|
||
r = data['record'] | ||
r.sort! { |x, y| x['datetime'] <=> y['datetime'] } | ||
|
||
r.each do |datum| | ||
datum.each_pair do |k, v| | ||
datum[k] = v[0] | ||
end | ||
end | ||
|
||
puts r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe ApiController, type: :controller do | ||
describe 'POST #create' do | ||
context 'with valid attributes' do | ||
it 'creates a new glucose measurement' do | ||
expect { | ||
post :create, json: | ||
{ | ||
"id":"3648", | ||
"datetime":"2016-01-30T13:58:31+00:00", | ||
"type":"Glucose", | ||
"subtype"=>{}, | ||
"category":"Lunch", | ||
"value":"12.0" | ||
}.to_json | ||
}.to change(GlucoseMeasurement, :count).by 1 | ||
end | ||
|
||
it 'fails with duff values' do | ||
expect { | ||
post :create, json: | ||
{ | ||
"datetime":"2016-01-30T13:58:31+00:00", | ||
"type":"Glucose", | ||
"value":"0" | ||
}.to_json | ||
}.to_not change(GlucoseMeasurement, :count) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the ApiHelper. For example: | ||
# | ||
# describe ApiHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe ApiHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"datetime":"2016-01-29T19:18:29+00:00","category":"Dinner","value":"12.0"} | ||
{"datetime":"2016-01-29T19:33:12+00:00","category":"Dinner","value":"14.0"} | ||
{"datetime":"2016-01-30T01:40:18+00:00","category":"Bedtime","value":"21.6"} | ||
{"datetime":"2016-01-30T01:46:26+00:00","category":"Bedtime","value":"14.0"} | ||
{"datetime":"2016-01-30T10:26:03+00:00","category":"Breakfast","value":"10.7"} | ||
{"datetime":"2016-01-30T10:39:25+00:00","category":"Breakfast","value":"6.0","subtype":"humalog"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<ontrack> | ||
<record> | ||
<id>3649</id> | ||
<datetime>2016-01-30T14:05:00+00:00</datetime> | ||
<type>Medication</type> | ||
<subtype>Humalog</subtype> | ||
<category>Lunch</category> | ||
<value>6.0</value> | ||
</record> | ||
<record> | ||
<id>3648</id> | ||
<datetime>2016-01-30T13:58:31+00:00</datetime> | ||
<type>Glucose</type> | ||
<subtype></subtype> | ||
<category>Lunch</category> | ||
<value>12.0</value> | ||
</record> | ||
<record> | ||
<id>3647</id> | ||
<datetime>2016-01-30T10:39:25+00:00</datetime> | ||
<type>Medication</type> | ||
<subtype>Humalog</subtype> | ||
<category>Breakfast</category> | ||
<value>6.0</value> | ||
</record> | ||
<record> | ||
<id>3646</id> | ||
<datetime>2016-01-30T10:26:03+00:00</datetime> | ||
<type>Glucose</type> | ||
<subtype></subtype> | ||
<category>Breakfast</category> | ||
<value>10.7</value> | ||
</record> | ||
<record> | ||
<id>3645</id> | ||
<datetime>2016-01-30T01:46:26+00:00</datetime> | ||
<type>Medication</type> | ||
<subtype>Lantus</subtype> | ||
<category>Bedtime</category> | ||
<value>14.0</value> | ||
</record> | ||
<record> | ||
<id>3644</id> | ||
<datetime>2016-01-30T01:40:18+00:00</datetime> | ||
<type>Glucose</type> | ||
<subtype></subtype> | ||
<category>Bedtime</category> | ||
<value>21.6</value> | ||
</record> | ||
<record> | ||
<id>3643</id> | ||
<datetime>2016-01-29T19:33:12+00:00</datetime> | ||
<type>Medication</type> | ||
<subtype>Humalog</subtype> | ||
<category>Dinner</category> | ||
<value>14.0</value> | ||
</record> | ||
</ontrack> |