Skip to content

Commit

Permalink
Ensure uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 30, 2016
1 parent 06197e6 commit 6c9e14a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/carbohydrate_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CarbohydrateIntake < ActiveRecord::Base
def self.short_name
'Carbs'
end

def self.fields
[
'weight',
Expand All @@ -12,4 +12,5 @@ def self.fields

validates :datetime, presence: true
validates :weight, presence: true, numericality: { greater_than: 0 }
validates_uniqueness_of :datetime
end
1 change: 1 addition & 0 deletions app/models/glucose_measurement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ def self.fields

validates :datetime, presence: true
validates :value, presence: true, numericality: { greater_than: 0 }
validates_uniqueness_of :datetime
end
1 change: 1 addition & 0 deletions app/models/medication_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ def self.fields
validates :datetime, presence: true
validates :dose, presence: true, numericality: { greater_than: 0 }
validates :insulin, presence: true, inclusion: { in: insulin_types }
validates_uniqueness_of :datetime
end
1 change: 1 addition & 0 deletions app/models/physical_exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ def self.fields

validates :datetime, presence: true
validates :duration, presence: true, numericality: { greater_than: 0 }
validates_uniqueness_of :datetime
end
15 changes: 15 additions & 0 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@
}.to_json
}.to change(PhysicalExercise, :count).by 1
end

it 'does not create duplicates' do
expect {
2.times do
post :create, data: {
"id":"3645",
"datetime":"2016-01-30T01:46:26+00:00",
"type":"Medication",
"subtype":"Lantus",
"category":"Bedtime",
"value":"14.0"
}
end
}.to change(MedicationEvent, :count).by 1
end
end
end
end

0 comments on commit 6c9e14a

Please sign in to comment.