-
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.
Front-page looks like it did in my head :)
- Loading branch information
pikesley
committed
Jan 31, 2016
1 parent
f3988cc
commit 122ef84
Showing
4 changed files
with
40 additions
and
6 deletions.
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
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
class WelcomeController < ApplicationController | ||
def index | ||
@hours = 36 | ||
@metrics = [] | ||
[ | ||
GlucoseMeasurement, | ||
CarbohydrateIntake, | ||
MedicationEvent | ||
].each do |model| | ||
@metrics.concat model.where(datetime: (Time.now - 48.hours)..Time.now) | ||
@metrics.concat model.where(datetime: (Time.now - @hours.hours)..Time.now) | ||
end | ||
|
||
@widest = widest @metrics | ||
end | ||
|
||
private | ||
|
||
def widest metrics | ||
metrics.map { |m| m.class }.uniq.map { |u| u.fields.count }.max | ||
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
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe WelcomeController, type: :controller do | ||
|
||
describe WelcomeController, type: :controller do | ||
let(:metrics) { | ||
[ | ||
create(:glucose_measurement), | ||
create(:medication_event), | ||
create(:carbohydrate_intake), | ||
create(:physical_exercise) | ||
] | ||
} | ||
it 'knows which metric has the most fields' do | ||
expect(described_class.new.send(:widest, metrics)).to eq 2 | ||
end | ||
end |