ops 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.gitignore +14 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +134 -0
  5. data/LICENSE +7 -0
  6. data/README.md +81 -0
  7. data/Rakefile +27 -0
  8. data/examples/rails3/.gitignore +15 -0
  9. data/examples/rails3/.rspec +3 -0
  10. data/examples/rails3/Gemfile +5 -0
  11. data/examples/rails3/Gemfile.lock +130 -0
  12. data/examples/rails3/Rakefile +13 -0
  13. data/examples/rails3/config/application.rb +34 -0
  14. data/examples/rails3/config/boot.rb +6 -0
  15. data/examples/rails3/config/environment.rb +5 -0
  16. data/examples/rails3/config/initializers/secret_token.rb +1 -0
  17. data/examples/rails3/config/locales/en.yml +5 -0
  18. data/examples/rails3/config/routes.rb +3 -0
  19. data/examples/rails3/config.ru +4 -0
  20. data/examples/rails3/public/404.html +26 -0
  21. data/examples/rails3/public/422.html +26 -0
  22. data/examples/rails3/public/500.html +25 -0
  23. data/examples/rails3/public/favicon.ico +0 -0
  24. data/examples/rails3/public/index.html +14 -0
  25. data/examples/rails3/public/robots.txt +5 -0
  26. data/examples/rails3/script/rails +6 -0
  27. data/examples/rails3/spec/functional/ops_routes_spec.rb +63 -0
  28. data/examples/rails3/spec/spec_helper.rb +5 -0
  29. data/examples/sample_deploys/1234/REVISION +1 -0
  30. data/examples/sample_deploys/1234/VERSION +1 -0
  31. data/examples/sample_deploys/2341/REVISION +1 -0
  32. data/examples/sample_deploys/2341/VERSION +1 -0
  33. data/examples/sample_deploys/3412/REVISION +1 -0
  34. data/examples/sample_deploys/3412/VERSION +1 -0
  35. data/examples/sample_deploys/4123/REVISION +1 -0
  36. data/examples/sample_deploys/4123/VERSION +1 -0
  37. data/examples/sinatra/.rspec +3 -0
  38. data/examples/sinatra/Rakefile +15 -0
  39. data/examples/sinatra/app.rb +14 -0
  40. data/examples/sinatra/config.ru +17 -0
  41. data/examples/sinatra/spec/functional/ops_routes_spec.rb +63 -0
  42. data/examples/sinatra/spec/spec_helper.rb +3 -0
  43. data/lib/ops/config.rb +43 -0
  44. data/lib/ops/heartbeat.rb +41 -0
  45. data/lib/ops/revision.rb +117 -0
  46. data/lib/ops/server/helpers.rb +44 -0
  47. data/lib/ops/server/views/layout.html.slim +22 -0
  48. data/lib/ops/server/views/version.html.slim +50 -0
  49. data/lib/ops/server/views/version.json.rabl +9 -0
  50. data/lib/ops/server.rb +45 -0
  51. data/lib/ops/version.rb +3 -0
  52. data/lib/ops.rb +14 -0
  53. data/ops.gemspec +25 -0
  54. data/spec/functional/ops_routes_spec.rb +63 -0
  55. data/spec/ops/config_spec.rb +0 -0
  56. data/spec/ops/heartbeat_spec.rb +49 -0
  57. data/spec/ops/revision_spec.rb +41 -0
  58. data/spec/ops/server_spec.rb +0 -0
  59. data/spec/ops/version_spec.rb +7 -0
  60. data/spec/ops_spec.rb +9 -0
  61. data/spec/spec_helper.rb +15 -0
  62. metadata +192 -0
@@ -0,0 +1,63 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+ require 'spec_helper'
4
+ require 'json'
5
+
6
+ RSpec::Matchers.define :have_content_type do |content_type|
7
+ CONTENT_HEADER_MATCHER = /^([A-Za-z]+\/[\w\-+\.]+)(;charset=(.*))?/
8
+
9
+ chain :with_charset do |charset|
10
+ @charset = charset
11
+ end
12
+
13
+ match do |response|
14
+ _, content, _, charset = *content_type_header.match(CONTENT_HEADER_MATCHER).to_a
15
+
16
+ if @charset
17
+ @charset == charset && content == content_type
18
+ else
19
+ content == content_type
20
+ end
21
+ end
22
+
23
+ failure_message_for_should do |response|
24
+ if @charset
25
+ "Content type #{content_type_header.inspect} should match #{content_type.inspect} with charset #{@charset}"
26
+ else
27
+ "Content type #{content_type_header.inspect} should match #{content_type.inspect}"
28
+ end
29
+ end
30
+
31
+ failure_message_for_should_not do |model|
32
+ if @charset
33
+ "Content type #{content_type_header.inspect} should not match #{content_type.inspect} with charset #{@charset}"
34
+ else
35
+ "Content type #{content_type_header.inspect} should not match #{content_type.inspect}"
36
+ end
37
+ end
38
+
39
+ def content_type_header
40
+ last_response.headers['Content-Type']
41
+ end
42
+ end
43
+
44
+ describe 'routes', :type => :controller do
45
+ include Rack::Test::Methods
46
+
47
+ it 'renders a version page' do
48
+ get "/ops/version"
49
+ last_response.should be_ok
50
+ end
51
+
52
+ it 'renders a json version page' do
53
+ get "/ops/version.json"
54
+ last_response.should be_ok
55
+ last_response.should have_content_type('application/json').with_charset('utf-8')
56
+ end
57
+
58
+ it 'renders a heartbeat page' do
59
+ get "/ops/heartbeat"
60
+ last_response.should be_ok
61
+ end
62
+
63
+ end
File without changes
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ops::Heartbeat do
4
+ describe '#add' do
5
+ it 'accepts new heartbeats' do
6
+ @heartbeat = Ops::Heartbeat.new
7
+ @heartbeat.add(:test){ true }
8
+ @heartbeat.heartbeats.should have(1).items
9
+ end
10
+ end
11
+
12
+ describe '#check' do
13
+ before do
14
+ @heartbeat = Ops::Heartbeat.new
15
+ @heartbeat.add(:test){ true }
16
+ end
17
+
18
+ it 'returns true for valid heartbeats' do
19
+ @heartbeat.check(:test).should eq(true)
20
+ end
21
+
22
+ it 'returns false for invalid heartbeats' do
23
+ @heartbeat.check(:invalid_test).should eq(false)
24
+ end
25
+ end
26
+
27
+ describe '#heartbeats' do
28
+ it 'returns a hash of heartbeats' do
29
+ Ops::Heartbeat.new.heartbeats.should be_a Hash
30
+ end
31
+ end
32
+
33
+ it "offers a singleton" do
34
+ @heartbeat = Ops::Heartbeat.instance
35
+ @heartbeat.object_id.should be Ops::Heartbeat.instance.object_id
36
+ end
37
+
38
+ it "checks singleton's heartbeats" do
39
+ Ops::Heartbeat.instance.add(:test){ true }
40
+ Ops::Heartbeat.check(:test).should be true
41
+ end
42
+ end
43
+
44
+ describe Ops do
45
+ it "provides convenience method to add heartbeats" do
46
+ Ops.add_heartbeat(:convenience){ true }
47
+ Ops::Heartbeat.check(:convenience).should be true
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ops::Revision do
4
+
5
+ let(:create_version_file) do
6
+ @version_file = File.join(@root, 'VERSION')
7
+ File.open(@version_file, 'w') { |f| f.write('v23.24.25^{}') }
8
+ end
9
+
10
+ before do
11
+ @root = File.dirname(__FILE__)
12
+ headers = {}
13
+ settings = double("settings", {:file_root => @root, :environment => 'test'})
14
+ @version = Ops::Revision.new(headers, settings)
15
+ end
16
+
17
+ after do
18
+ File.delete(@version_file) unless @version_file.nil?
19
+ end
20
+
21
+ it "test env should have version" do
22
+ create_version_file
23
+ @version.version_or_branch.should eq("v23.24.25")
24
+ end
25
+
26
+ it "development env should have branch" do
27
+ dev_settings = double("settings", {:file_root => @root, :environment => 'development'})
28
+ dev_version = Ops::Revision.new({}, dev_settings)
29
+ dev_version.version_or_branch.should eq("master")
30
+ end
31
+
32
+ it "should have request headers" do
33
+ headers = {'ABC' => '123', 'hidden' => 'x'}
34
+ settings = double("settings", {:file_root => @root, :environment => 'test'})
35
+ version = Ops::Revision.new(headers, settings)
36
+ version.headers.should eq({'ABC' => '123'})
37
+ end
38
+
39
+ # TODO: add tests for json and previous_version
40
+
41
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ops::VERSION do
4
+ it "returns a string with the version" do
5
+ Ops::VERSION.should match /(\d+).(\d+).(\d+)([-+]([0-9A-Za-z-]+(.[0-9A-Za-z-]+)*)+)*/
6
+ end
7
+ end
data/spec/ops_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ops do
4
+ describe '#new' do
5
+ it 'returns a new Ops::Server instance' do
6
+ Ops.new.should be_a Sinatra::ExtendedRack
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'rspec'
7
+ require 'ops'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Pelz-Sherman
9
+ - Colin Rymer
10
+ - Primedia Team
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-11-28 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: oj
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.5
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: 1.4.5
32
+ - !ruby/object:Gem::Dependency
33
+ name: rabl
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 0.7.6
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.6
48
+ - !ruby/object:Gem::Dependency
49
+ name: slim
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.4
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 1.3.4
64
+ - !ruby/object:Gem::Dependency
65
+ name: sinatra
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: 1.3.3
72
+ type: :runtime
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.3
80
+ - !ruby/object:Gem::Dependency
81
+ name: sinatra-respond_to
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.8.0
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 0.8.0
96
+ description: This gem provides standardized support for obtaining version and heartbeat
97
+ information from Sinatra or Rails-based web applications.
98
+ email:
99
+ - mpelzsherman@gmail.com
100
+ - colin.rymer@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - examples/rails3/.gitignore
113
+ - examples/rails3/.rspec
114
+ - examples/rails3/Gemfile
115
+ - examples/rails3/Gemfile.lock
116
+ - examples/rails3/Rakefile
117
+ - examples/rails3/config.ru
118
+ - examples/rails3/config/application.rb
119
+ - examples/rails3/config/boot.rb
120
+ - examples/rails3/config/environment.rb
121
+ - examples/rails3/config/initializers/secret_token.rb
122
+ - examples/rails3/config/locales/en.yml
123
+ - examples/rails3/config/routes.rb
124
+ - examples/rails3/public/404.html
125
+ - examples/rails3/public/422.html
126
+ - examples/rails3/public/500.html
127
+ - examples/rails3/public/favicon.ico
128
+ - examples/rails3/public/index.html
129
+ - examples/rails3/public/robots.txt
130
+ - examples/rails3/script/rails
131
+ - examples/rails3/spec/functional/ops_routes_spec.rb
132
+ - examples/rails3/spec/spec_helper.rb
133
+ - examples/sample_deploys/1234/REVISION
134
+ - examples/sample_deploys/1234/VERSION
135
+ - examples/sample_deploys/2341/REVISION
136
+ - examples/sample_deploys/2341/VERSION
137
+ - examples/sample_deploys/3412/REVISION
138
+ - examples/sample_deploys/3412/VERSION
139
+ - examples/sample_deploys/4123/REVISION
140
+ - examples/sample_deploys/4123/VERSION
141
+ - examples/sinatra/.rspec
142
+ - examples/sinatra/Rakefile
143
+ - examples/sinatra/app.rb
144
+ - examples/sinatra/config.ru
145
+ - examples/sinatra/spec/functional/ops_routes_spec.rb
146
+ - examples/sinatra/spec/spec_helper.rb
147
+ - lib/ops.rb
148
+ - lib/ops/config.rb
149
+ - lib/ops/heartbeat.rb
150
+ - lib/ops/revision.rb
151
+ - lib/ops/server.rb
152
+ - lib/ops/server/helpers.rb
153
+ - lib/ops/server/views/layout.html.slim
154
+ - lib/ops/server/views/version.html.slim
155
+ - lib/ops/server/views/version.json.rabl
156
+ - lib/ops/version.rb
157
+ - ops.gemspec
158
+ - spec/functional/ops_routes_spec.rb
159
+ - spec/ops/config_spec.rb
160
+ - spec/ops/heartbeat_spec.rb
161
+ - spec/ops/revision_spec.rb
162
+ - spec/ops/server_spec.rb
163
+ - spec/ops/version_spec.rb
164
+ - spec/ops_spec.rb
165
+ - spec/spec_helper.rb
166
+ homepage: http://github.com/primedia/ops
167
+ licenses:
168
+ - MIT
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '1.9'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 1.8.24
188
+ signing_key:
189
+ specification_version: 3
190
+ summary: Provide ops info endpoints.
191
+ test_files: []
192
+ has_rdoc: