backstop-deploys 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Backstop
2
2
  module Deploys
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -24,10 +24,17 @@ module Backstop
24
24
  halt [400, {:message => ':id should be in the format of app.version.epoch'}.to_json] if app.nil? or version.nil? or start_time.nil?
25
25
  end_time = params[:end_time]
26
26
  halt [400, {:message => ':source is a required param'}.to_json] unless source = params[:source]
27
- json = RestClient.get "#{api_endpoint}/annotations/deploys", :params => {'sources[0]' => source, :start_time => start_time}
28
- data = JSON.parse(json)
27
+ stream_exists = true
28
+ data = nil
29
29
 
30
- if events = data['events'].first
30
+ begin
31
+ json = RestClient.get "#{api_endpoint}/annotations/deploys", :params => {'sources[0]' => source, :start_time => start_time}
32
+ data = JSON.parse(json)
33
+ rescue RestClient::ResourceNotFound
34
+ stream_exists = false
35
+ end
36
+
37
+ if stream_exists and events = data['events'].first
31
38
  # events already exists, we just need to update
32
39
  event = events[source].first
33
40
  event_id = event['id']
@@ -38,7 +45,7 @@ module Backstop
38
45
  # new event needs to be created
39
46
  payload = { :start_time => start_time, :title => "#{app}.#{version}" }
40
47
  payload[:end_time] = end_time if end_time
41
- RestClient.put "#{api_endpoint}/annotations/deploys", "title=#{app}.#{version}&start_time=#{start_time}"
48
+ RestClient.post "#{api_endpoint}/annotations/deploys", "title=#{app}.#{version}&start_time=#{start_time}"
42
49
  end
43
50
  end
44
51
  end
@@ -44,10 +44,23 @@ describe Backstop::Deploys::Web do
44
44
  it('should return a 200') { last_response.status.should eq(200) }
45
45
  end
46
46
 
47
+ context 'non-existent annotation stream' do
48
+ let(:stub_missing_stream) { stub_request(:get, "#{api_endpoint}/annotations/deploys").with(:query => { :sources => [source], :start_time => t.to_i }).to_return(:status => 404) }
49
+ let(:stub_new_request) { stub_request(:post, "#{api_endpoint}/annotations/deploys").with(:body => "title=#{title}&start_time=#{t.to_i}") }
50
+ before(:each) do
51
+ stub_missing_stream
52
+ stub_new_request
53
+ put "/deploys/#{id}", params
54
+ end
55
+ it('should ask Librato for the proper annotation') { stub_missing_stream.should have_been_made.once }
56
+ it('should create a new annotation') { stub_new_request.should have_been_made.once }
57
+ it('should be 200') { last_response.status.should eq(200) }
58
+ end
59
+
47
60
  context 'non-existent annotation' do
48
61
  let(:stub_get_missing_body) { {:name => 'deploys', :events => []} }
49
62
  let(:stub_get_missing_request) { stub_request(:get, "#{api_endpoint}/annotations/deploys").with(:query => { :sources => [source], :start_time => t.to_i }).to_return(:body => stub_get_missing_body.to_json)}
50
- let(:stub_new_request) { stub_request(:put, "#{api_endpoint}/annotations/deploys").with(:body => "title=#{title}&start_time=#{t.to_i}") }
63
+ let(:stub_new_request) { stub_request(:post, "#{api_endpoint}/annotations/deploys").with(:body => "title=#{title}&start_time=#{t.to_i}") }
51
64
  before(:each) do
52
65
  stub_get_missing_request
53
66
  stub_new_request
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backstop-deploys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack-test
16
- requirement: &70361437411980 !ruby/object:Gem::Requirement
16
+ requirement: &70136571084140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70361437411980
24
+ version_requirements: *70136571084140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70361437411020 !ruby/object:Gem::Requirement
27
+ requirement: &70136571083620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70361437411020
35
+ version_requirements: *70136571083620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70361437409820 !ruby/object:Gem::Requirement
38
+ requirement: &70136571082580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70361437409820
46
+ version_requirements: *70136571082580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &70361437409160 !ruby/object:Gem::Requirement
49
+ requirement: &70136571081440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70361437409160
57
+ version_requirements: *70136571081440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rest-client
60
- requirement: &70361437408340 !ruby/object:Gem::Requirement
60
+ requirement: &70136571080860 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70361437408340
68
+ version_requirements: *70136571080860
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sinatra
71
- requirement: &70361437407140 !ruby/object:Gem::Requirement
71
+ requirement: &70136571079760 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70361437407140
79
+ version_requirements: *70136571079760
80
80
  description: An extension to backstop to allow submission to Librato Metrics
81
81
  email:
82
82
  - michael.gorsuch@gmail.com
@@ -109,18 +109,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  - - ! '>='
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
- segments:
113
- - 0
114
- hash: 1902119296020262380
115
112
  required_rubygems_version: !ruby/object:Gem::Requirement
116
113
  none: false
117
114
  requirements:
118
115
  - - ! '>='
119
116
  - !ruby/object:Gem::Version
120
117
  version: '0'
121
- segments:
122
- - 0
123
- hash: 1902119296020262380
124
118
  requirements: []
125
119
  rubyforge_project:
126
120
  rubygems_version: 1.8.10
@@ -130,3 +124,4 @@ summary: An extension to backstop to allow submission to Librato Metrics
130
124
  test_files:
131
125
  - spec/backstop-deploys/web_spec.rb
132
126
  - spec/spec_helper.rb
127
+ has_rdoc: