Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ryan] complete on sample will no longer save without any measurements

  • Loading branch information...
commit 8ba4da9a487b02475a4ee0f7e682fb05e3fabe0e 1 parent ec19b7b
perf authored
View
1  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!
View
4 lib/active_metric/sample.rb
@@ -38,6 +38,7 @@ def calculate(measurement)
end
def complete
+ return false if measurement_count < 1
self.stats.each do |statistic|
statistic.complete
end
@@ -45,7 +46,8 @@ def complete
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)
View
8 test/sample_test.rb
@@ -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),
View
6 test/test_helper.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.