Skip to content

Commit

Permalink
This somewhat works
Browse files Browse the repository at this point in the history
I need to introduce Cells
  • Loading branch information
pikesley committed Feb 27, 2016
1 parent e925e7c commit c0760c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/generic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ def index

@model = find_class
@metrics = @model.where(datetime: (Time.now - @hours.hours)..Time.now)

if @metrics == []
@metrics = @model.first(3)
end

@bucketed_metrics = @metrics.group_by { |g| g.datetime.strftime "%Y-%m-%d" }

@with_year = @metrics.first.datetime.year < Time.now.year

@has_charts = false
end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/longterm_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def index
{
model: GlycatedHaemoglobin,
metrics: GlycatedHaemoglobin.all,
bucketed_metrics: GlycatedHaemoglobin.all.group_by { |g| g.datetime.strftime "%Y-%m-%d" }
bucketed_metrics: GlycatedHaemoglobin.all.group_by { |g| g.datetime.strftime "%Y-%m-%d" },
with_year: nil
},
{
model: BloodPressure,
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/sparse_metrics_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe 'GlycatedHaemoglobin' do
describe 'Return at least something if the metric is sparse' do
let(:user) { create :user }

before :each do
DatabaseCleaner.clean
end

it 'shows the year if the first metric is from last year or even older' do
create(:glycated_haemoglobin, datetime: '2015-06-06')
Timecop.freeze 2016, 02, 27 do
visit glycated_haemoglobins_url(as: user)
expect(page).to have_content 'June 6th 2015'
end
end

it 'does not show the year if the first metric is from this year' do
create(:glycated_haemoglobin, datetime: '2016-01-01')
Timecop.freeze 2016, 02, 27 do
visit glycated_haemoglobins_url(as: user)
expect(page).to have_content 'January 1st'
expect(page).to_not have_content 'January 1st 2016'
end
end
end
end

0 comments on commit c0760c7

Please sign in to comment.