check 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ $:.unshift lib unless $:.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = 'check'
8
- gem.version = '0.2.0'
8
+ gem.version = '0.2.1'
9
9
  gem.authors = ['Gerhard Lazu']
10
10
  gem.email = ['gerhard@lazu.co.uk']
11
11
  gem.description = 'Redis backed service for monitoring metric data streams against pre-defined thresholds'
@@ -27,16 +27,38 @@ module Check
27
27
  end
28
28
  end
29
29
 
30
+ resource :metric do
31
+ desc 'List all matching metric checks'
32
+ params do
33
+ optional :name, :type => String, :desc => "Name of metric check"
34
+ end
35
+ get do
36
+ metric_check = Metric.find(metric_params)
37
+
38
+ if metric_check.persisted?
39
+ metric_check.similar.to_json
40
+ else
41
+ []
42
+ end
43
+ end
44
+
45
+ desc 'Delete all matching metric checks'
46
+ params do
47
+ requires :name, :type => String, :desc => "Name of metric check"
48
+ end
49
+ delete do
50
+ Metric.delete_all(params[:name])
51
+ end
52
+ end
53
+
30
54
  resources :metrics do
31
55
  desc 'Create metric check'
56
+ params do
57
+ requires :name, :type => String, :desc => "Name of metric check"
58
+ end
32
59
  post '/' do
33
60
  metric_check = Metric.new(metric_params).save
34
-
35
- if metric_check.valid?
36
- [metric_check.name]
37
- else
38
- error!({:errors => metric_check.errors}, 409)
39
- end
61
+ [metric_check.name]
40
62
  end
41
63
 
42
64
  desc 'Delete specific metric check'
@@ -45,11 +67,17 @@ module Check
45
67
  end
46
68
 
47
69
  desc 'Delete all matching metric checks'
70
+ params do
71
+ requires :name, :type => String, :desc => "Name of metric check"
72
+ end
48
73
  delete '/:name' do
49
74
  Metric.delete_all(params[:name])
50
75
  end
51
76
 
52
77
  desc 'List all matching metric checks'
78
+ params do
79
+ optional :name, :type => String, :desc => "Name of metric check"
80
+ end
53
81
  get '/:name' do
54
82
  metric_check = Metric.find(metric_params)
55
83
 
@@ -30,8 +30,8 @@ module Check
30
30
 
31
31
  describe "when there are metrics" do
32
32
  before do
33
- matching_metric = Metric.new(name: "foo").save
34
- other_metric = Metric.new(name: "bar").save
33
+ Metric.new(name: "foo").save
34
+ Metric.new(name: "bar").save
35
35
  end
36
36
 
37
37
  it "returns only matching ones" do
@@ -42,16 +42,28 @@ module Check
42
42
  body.first.fetch('name').must_equal "foo"
43
43
  end
44
44
  end
45
+
46
+ describe "when there are metrics with url-safe characters in their name" do
47
+ before do
48
+ Metric.new(name: "foo-bar_baz.qux").save
49
+ Metric.new(name: "foo.qux").save
50
+ end
51
+
52
+ it "returns only matching ones" do
53
+ get("/metric", :name => "foo-bar_baz.qux")
54
+ last_response.content_type.must_equal "application/json"
55
+ last_response.status.must_equal 200
56
+ body.size.must_equal 1
57
+ body.first.fetch('name').must_equal "foo-bar_baz.qux"
58
+ end
59
+ end
45
60
  end
46
61
 
47
62
  describe "POST /metrics" do
48
- it "returns a 409 if params are invalid" do
63
+ it "returns a 400 if params are invalid" do
49
64
  post("/metrics")
50
65
  last_response.content_type.must_equal "application/json"
51
- last_response.status.must_equal 409
52
- body["errors"].must_equal({
53
- 'name' => "can't be blank"
54
- })
66
+ last_response.status.must_equal 400
55
67
  end
56
68
 
57
69
  it "creates a new metric if params are valid" do
@@ -87,6 +99,16 @@ module Check
87
99
  Redis.current.keys.must_equal ["bar"]
88
100
  end
89
101
  end
102
+
103
+ describe "when metric has url-safe name" do
104
+ it "deletes all similar" do
105
+ Metric.new(name: "foo-bar_baz.qux").save
106
+ Metric.new(name: "foo.bar").save
107
+ delete("/metric", :name => "foo.bar")
108
+ last_response.status.must_equal 200
109
+ Redis.current.keys.must_equal ["foo-bar_baz.qux"]
110
+ end
111
+ end
90
112
  end
91
113
 
92
114
  describe "DELETE /metrics" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashr
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  segments:
169
169
  - 0
170
- hash: -3975405867045093680
170
+ hash: 2887667756830827794
171
171
  required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  segments:
178
178
  - 0
179
- hash: -3975405867045093680
179
+ hash: 2887667756830827794
180
180
  requirements: []
181
181
  rubyforge_project:
182
182
  rubygems_version: 1.8.23