Permalink
Browse files

Fix duration for non-activities

  • Loading branch information...
1 parent 3e0d193 commit b34bdca2d79bb0bd83c5315140216798802fbdbb @sachac committed Jul 3, 2017
Showing with 12 additions and 3 deletions.
  1. +9 −0 app/models/record.rb
  2. +3 −3 spec/models/record_spec.rb
View
@@ -28,6 +28,15 @@ def end_timestamp
return nil
end
end
+
+ def duration
+ # Only activities have end timestamps
+ if self.record_category and self.activity?
+ return self[:duration]
+ else
+ return nil
+ end
+ end
def end_timestamp_must_be_after_start
if !end_timestamp.blank? and end_timestamp < timestamp
@@ -1,5 +1,5 @@
require 'spec_helper'
-describe Record, type: :model, focus: true do
+describe Record, type: :model do
before :all do
Timecop.freeze
@user = FactoryGirl.create(:confirmed_user)
@@ -402,7 +402,7 @@
end
end
- describe '#create_batch', focus: true do
+ describe '#create_batch' do
before :each do
@user2 = FactoryGirl.create(:confirmed_user)
@cat_abcx = FactoryGirl.create(:record_category, user: @user2, name: 'ABCX')
@@ -563,7 +563,7 @@
expect(rec.beginning_of_week.to_date).to eq Time.zone.local(2012, 1, 28).to_date
end
end
- describe '#prepare_graph', focus: true do
+ describe '#prepare_graph' do
it "splits by date" do
FactoryGirl.create(:record, user: @user, timestamp: Time.zone.now.midnight - 2.hours,
end_timestamp: Time.zone.now.midnight + 1.hour, record_category: @cat)

0 comments on commit b34bdca

Please sign in to comment.