Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ryan] complete on sample will no longer save without any measurements
  • Loading branch information
perf committed Jan 4, 2012
1 parent ec19b7b commit 8ba4da9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/active_metric/behavior/graph_calculation.rb
@@ -1,6 +1,7 @@
module ActiveMetric
module GraphCalculation
#REQUIRES SUMMARY AND INTERVAL SAMPLES AND SERIES DATA

def series
update_all_series
self.save!
Expand Down
4 changes: 3 additions & 1 deletion lib/active_metric/sample.rb
Expand Up @@ -38,14 +38,16 @@ def calculate(measurement)
end

def complete
return false if measurement_count < 1
self.stats.each do |statistic|
statistic.complete
end
self.safely.save!
end

def time_range
end_time - start_time
return end_time - start_time if end_time && start_time
return 0
end

def method_missing(method, *args)
Expand Down
8 changes: 8 additions & 0 deletions test/sample_test.rb
Expand Up @@ -51,6 +51,14 @@ class SampleTest < ActiveSupport::TestCase
assert_not_equal sample, new_sample
end

test "should not save if sample has no measurements" do
subject = TestSubject.new
sample = TestSample.new(:interval => 6, :samplable => subject)

assert_equal false, sample.complete
assert_equal 0, TestSample.count
end

test "should have correct timestamp" do
measurements = [TestMeasurement.create(:value => 10, :timestamp => 1),
TestMeasurement.create(:value => 12, :timestamp => 2),
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Expand Up @@ -39,6 +39,12 @@ class TestSubject < Subject

class ActiveSupport::TestCase

setup :clear_database
teardown :clear_database
def clear_database
Mongoid.database.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
end

def assert_within_range(range, value)
assert range === value, "Expected #{value} to be within #{range}"
end
Expand Down

0 comments on commit 8ba4da9

Please sign in to comment.