operations_middleware 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/lib/operations_middleware.rb +171 -0
- data/operations_middleware.gemspec +64 -0
- data/spec/operations_middleware_spec.rb +248 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +13 -0
- metadata +125 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Emily Price
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= operation_middleware
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Emily Price. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "operations_middleware"
|
8
|
+
gem.summary = %Q{Rack middleware to provide route for heartbeat and version pages.}
|
9
|
+
gem.description = %Q{Rack middleware to provide route for heartbeat and version pages. Includes links to github repo. }
|
10
|
+
gem.email = ""
|
11
|
+
gem.homepage = "http://github.com/primedia/operations_middleware"
|
12
|
+
gem.authors = ["Primedia Team"]
|
13
|
+
gem.add_dependency "rack", "= 1.0.1"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_development_dependency "rack-test"
|
16
|
+
gem.add_development_dependency 'rspec_tag_matchers'
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'spec/rake/spectask'
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :spec => :check_dependencies
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
require 'rake/rdoctask'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "operation_middleware #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
@@ -0,0 +1,171 @@
|
|
1
|
+
class OperationsMiddleware
|
2
|
+
attr_writer :app_name
|
3
|
+
attr_accessor :file_root, :heartbeat
|
4
|
+
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
@heartbeat = {}
|
8
|
+
yield self if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
return @app.call(env) unless env['PATH_INFO'] =~ %r{^/ops/(heartbeat|version)(?:/(\w+))?/?$}
|
13
|
+
|
14
|
+
@status = 200
|
15
|
+
@headers = {}
|
16
|
+
|
17
|
+
if $1 == 'heartbeat'
|
18
|
+
if $2
|
19
|
+
check_heartbeat($2)
|
20
|
+
else
|
21
|
+
@body = "#{app_name} is OK"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@body = version_template
|
25
|
+
end
|
26
|
+
|
27
|
+
@headers['Content-Type'] = "text/html"
|
28
|
+
@headers['Content-Length'] = @body.length.to_s
|
29
|
+
|
30
|
+
|
31
|
+
[@status, @headers, @body]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def check_heartbeat(heartbeat_name)
|
37
|
+
if heartbeat_name and heartbeat[heartbeat_name.to_sym]
|
38
|
+
begin
|
39
|
+
heartbeat[heartbeat_name.to_sym].call
|
40
|
+
rescue
|
41
|
+
@status = 500
|
42
|
+
@body = "ERROR: #{heartbeat_name} does not have a heartbeat"
|
43
|
+
else
|
44
|
+
@body = "#{heartbeat_name} is OK"
|
45
|
+
end
|
46
|
+
else
|
47
|
+
@status = 500
|
48
|
+
@body = "ERROR: #{heartbeat_name} does not have a heartbeat"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def environment
|
53
|
+
ENV['RAILS_ENV']
|
54
|
+
end
|
55
|
+
|
56
|
+
def version_or_branch
|
57
|
+
return @version if @version
|
58
|
+
version_file = ::File.join(file_root, 'VERSION')
|
59
|
+
if ::File.exists?( version_file )
|
60
|
+
@version = ::File.read(version_file).chomp.gsub('^{}', '')
|
61
|
+
elsif environment == 'development' and `git branch` =~ /^\* (.*)$/
|
62
|
+
@version = $1
|
63
|
+
else
|
64
|
+
@version = 'Unknown (VERSION file is missing)'
|
65
|
+
end
|
66
|
+
@version
|
67
|
+
end
|
68
|
+
|
69
|
+
def deploy_date
|
70
|
+
return @deploy_date if @deploy_date
|
71
|
+
version_file = ::File.join(file_root, 'VERSION')
|
72
|
+
if ::File.exists?( version_file )
|
73
|
+
@deploy_date = ::File.stat(version_file).mtime
|
74
|
+
elsif environment == 'development'
|
75
|
+
@deploy_date = Time.now
|
76
|
+
else
|
77
|
+
@deploy_date = 'Unknown (VERSION file is missing)'
|
78
|
+
end
|
79
|
+
@deploy_date
|
80
|
+
end
|
81
|
+
|
82
|
+
def last_commit
|
83
|
+
return @last_commit if @last_commit
|
84
|
+
revision_file = ::File.join(file_root, 'REVISION')
|
85
|
+
if ::File.exists?( revision_file )
|
86
|
+
@last_commit = ::File.read(revision_file).chomp
|
87
|
+
elsif environment == 'development' and `git show` =~ /^commit (.*)$/
|
88
|
+
@last_commit = $1
|
89
|
+
else
|
90
|
+
@last_commit = 'Unknown (REVISION file is missing)'
|
91
|
+
end
|
92
|
+
@last_commit
|
93
|
+
end
|
94
|
+
|
95
|
+
def hostname
|
96
|
+
return @hostname if @hostname
|
97
|
+
hostname = `/bin/hostname`
|
98
|
+
@hostname = hostname.nil? || hostname.empty? ? "Unknown" : hostname
|
99
|
+
end
|
100
|
+
|
101
|
+
def app_name
|
102
|
+
return @app_name if @app_name
|
103
|
+
dirs = Dir.pwd.split('/')
|
104
|
+
app_name = dirs.last
|
105
|
+
app_name = dirs[-3] if app_name =~ /^\d+$/
|
106
|
+
app_name.sub!(/\.com$/, '')
|
107
|
+
@app_name ||= app_name
|
108
|
+
end
|
109
|
+
|
110
|
+
def headers
|
111
|
+
hh = @headers.select{|k,v| k.match(/^HTTP.*/) }
|
112
|
+
return if hh.nil? || hh.empty?
|
113
|
+
ret = "<table border='1' style='width:100%'>"
|
114
|
+
hh.each { |k, v| ret += "<tr><td>#{k}</td><td>#{v}</td></tr>" }
|
115
|
+
ret += "</table>"
|
116
|
+
end
|
117
|
+
|
118
|
+
def version_link
|
119
|
+
return version_or_branch if version_or_branch =~ /^Unknown/
|
120
|
+
"<a href='https://github.com/primedia/#{app_name}/tree/#{version_or_branch}' style='font-size: 20px;'>#{version_or_branch}</a>"
|
121
|
+
end
|
122
|
+
|
123
|
+
def last_commit_link
|
124
|
+
return last_commit if last_commit =~ /^Unknown/
|
125
|
+
"<a href='https://github.com/primedia/#{app_name}/commit/#{last_commit}' style='font-size: 20px;'>#{last_commit}</a>"
|
126
|
+
end
|
127
|
+
|
128
|
+
def version_template
|
129
|
+
<<-HTML
|
130
|
+
<div class='container' style=' width: 1000px;'>
|
131
|
+
<div class='spacer'></div>
|
132
|
+
<div id='version'>
|
133
|
+
<div class='label'>#{app_name} Version</div>
|
134
|
+
<div class='value'>#{version_link}</div>
|
135
|
+
</div>
|
136
|
+
<div class='spacer'></div>
|
137
|
+
<div id='date'>
|
138
|
+
<div class='label'>Date Deployed:</div>
|
139
|
+
<div class='value'>#{deploy_date}</div>
|
140
|
+
</div>
|
141
|
+
<div class='spacer'></div>
|
142
|
+
<div id='commit'>
|
143
|
+
<div class='label'>Last Commit:</div>
|
144
|
+
<div class='value'>#{last_commit_link}</div>
|
145
|
+
</div>
|
146
|
+
<div class='spacer'></div>
|
147
|
+
<div id='host'>
|
148
|
+
<div class='label'>Host:</div>
|
149
|
+
<div class='value'>#{hostname}</div>
|
150
|
+
</div>
|
151
|
+
<div class='spacer'></div>
|
152
|
+
<div id='headers'>
|
153
|
+
<div class='label'>Headers:</div>
|
154
|
+
<div class='value'>#{headers}</div>
|
155
|
+
</div>
|
156
|
+
<div class='spacer'></div>
|
157
|
+
<div id='environment'>
|
158
|
+
<div class='label'>Environment:</div>
|
159
|
+
<div class='value'>#{environment}</div>
|
160
|
+
</div>
|
161
|
+
</div>
|
162
|
+
<style>
|
163
|
+
.container {font-size: 20px;}
|
164
|
+
.label {float: left; width: 400px;}
|
165
|
+
.spacer {clear: both; padding: 10px;}
|
166
|
+
.value {float: left; width: 500px; text-align: right;}
|
167
|
+
.clear {clear: both;}
|
168
|
+
</style>
|
169
|
+
HTML
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{operations_middleware}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Primedia Team"]
|
12
|
+
s.date = %q{2010-07-19}
|
13
|
+
s.description = %q{Rack middleware to provide route for heartbeat and version pages. Includes links to github repo. }
|
14
|
+
s.email = %q{}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/operations_middleware.rb",
|
27
|
+
"operations_middleware.gemspec",
|
28
|
+
"spec/operations_middleware_spec.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/primedia/operations_middleware}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{Rack middleware to provide route for heartbeat and version pages.}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/operations_middleware_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<rack>, ["= 1.0.1"])
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rspec_tag_matchers>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rack>, ["= 1.0.1"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec_tag_matchers>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rack>, ["= 1.0.1"])
|
59
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
60
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec_tag_matchers>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,248 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "OperationsMiddleware" do
|
4
|
+
before do
|
5
|
+
@parent_app = mock("Rails App")
|
6
|
+
@parent_app.stub(:call).and_return([200, {}, ['Parent App']])
|
7
|
+
end
|
8
|
+
|
9
|
+
def app
|
10
|
+
@app ||= OperationsMiddleware.new(@parent_app) do |ops|
|
11
|
+
ops.file_root = File.join(File.dirname(__FILE__), '..')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "passing routes" do
|
16
|
+
|
17
|
+
it "should pass to parent app for /" do
|
18
|
+
@parent_app.should_receive(:call)
|
19
|
+
get '/'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should pass to parent app for /Georgia/Atlanta" do
|
23
|
+
@parent_app.should_receive(:call)
|
24
|
+
get '/Georgia/Atlanta'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "captured routes" do
|
30
|
+
|
31
|
+
describe "version" do
|
32
|
+
|
33
|
+
it "should not pass to parent app for '/ops/version'" do
|
34
|
+
@parent_app.should_not_receive(:call)
|
35
|
+
get '/ops/version'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have version link" do
|
39
|
+
app.stub(:app_name).and_return('App')
|
40
|
+
app.stub(:version_or_branch).and_return('branch')
|
41
|
+
get '/ops/version'
|
42
|
+
last_response.body.should have_tag('#version .label', 'App Version')
|
43
|
+
last_response.body.should have_tag('#version .value', 'branch')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have date deployed" do
|
47
|
+
app.stub(:deploy_date).and_return('now')
|
48
|
+
get '/ops/version'
|
49
|
+
last_response.body.should have_tag('#date .label', 'Date Deployed:')
|
50
|
+
last_response.body.should have_tag('#date .value', 'now')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have last commit" do
|
54
|
+
app.stub(:last_commit_link).and_return('mock_sha')
|
55
|
+
get '/ops/version'
|
56
|
+
last_response.body.should have_tag('#commit .label', 'Last Commit:')
|
57
|
+
last_response.body.should have_tag('#commit .value', 'mock_sha')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have host" do
|
61
|
+
app.stub(:hostname).and_return('host')
|
62
|
+
get '/ops/version'
|
63
|
+
last_response.body.should have_tag('#host .label', 'Host:')
|
64
|
+
last_response.body.should have_tag('#host .value', 'host')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have headers" do
|
68
|
+
app.stub(:headers).and_return('headers')
|
69
|
+
get '/ops/version'
|
70
|
+
last_response.body.should have_tag('#headers .label', 'Headers:')
|
71
|
+
last_response.body.should have_tag('#headers .value', 'headers')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have environment" do
|
75
|
+
app.stub(:environment).and_return('env')
|
76
|
+
get '/ops/version'
|
77
|
+
last_response.body.should have_tag('#environment .label', 'Environment:')
|
78
|
+
last_response.body.should have_tag('#environment .value', 'env')
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "heartbeat" do
|
84
|
+
|
85
|
+
it "should not pass to parent app for '/ops/heartbeat'" do
|
86
|
+
@parent_app.should_not_receive(:call)
|
87
|
+
get '/ops/heartbeat'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should respond with OK" do
|
91
|
+
get '/ops/heartbeat'
|
92
|
+
last_response.body.should match('OK')
|
93
|
+
end
|
94
|
+
|
95
|
+
context "named heartbeat" do
|
96
|
+
it "should be run" do
|
97
|
+
heartbeat = mock('heartbeat')
|
98
|
+
app.heartbeat[:test] = heartbeat
|
99
|
+
heartbeat.should_receive(:call)
|
100
|
+
get '/ops/heartbeat/test'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should respond OK if heartbeat raises no errors" do
|
104
|
+
app.heartbeat[:test] = lambda{ return true }
|
105
|
+
get '/ops/heartbeat/test'
|
106
|
+
|
107
|
+
last_response.should match('OK')
|
108
|
+
last_response.status.should == 200
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should respond with ERROR if heartbeat raises errors" do
|
112
|
+
app.heartbeat[:test] = lambda{ raise "I HAVE NO HEART" }
|
113
|
+
get '/ops/heartbeat/test'
|
114
|
+
|
115
|
+
last_response.should match('ERROR')
|
116
|
+
last_response.status.should == 500
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#app_name' do
|
126
|
+
|
127
|
+
it "should return config option if given" do
|
128
|
+
local_app = OperationsMiddleware.new(@parent_app) do |ops|
|
129
|
+
ops.file_root = File.join(File.dirname(__FILE__), '..')
|
130
|
+
ops.app_name = 'Config App'
|
131
|
+
end
|
132
|
+
local_app.method(:app_name).call.should == 'Config App'
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return parent directory if not a timestamp" do
|
136
|
+
Dir.stub(:pwd).and_return('/foo/bar')
|
137
|
+
app.method(:app_name).call.should == 'bar'
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should return 2 levels up from parent if parent is timestamp (cap deploy structure)" do
|
141
|
+
Dir.stub(:pwd).and_return('/app/releases/12345')
|
142
|
+
app.method(:app_name).call.should == 'app'
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should strip '.com' off of parent name" do
|
146
|
+
Dir.stub(:pwd).and_return('/app.com/releases/12345')
|
147
|
+
app.method(:app_name).call.should == 'app'
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#version_or_branch' do
|
153
|
+
it "should use contents of VERSION file if available" do
|
154
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(true)
|
155
|
+
File.stub(:read).with(File.join(app.file_root, 'VERSION')).and_return('version')
|
156
|
+
|
157
|
+
app.method(:version_or_branch).call.should == 'version'
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should use current git branch if in git repo and development mode" do
|
161
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(false)
|
162
|
+
# stub on app instead of Kernel since apparently you can't stub on a Module
|
163
|
+
app.stub(:`).with('git branch').and_return("* foo\n bar")
|
164
|
+
app.stub(:environment).and_return('development')
|
165
|
+
|
166
|
+
app.method(:version_or_branch).call.should == 'foo'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should be unknown if not in git repo" do
|
170
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(false)
|
171
|
+
# stub on app instead of Kernel since apparently you can't stub on a Module
|
172
|
+
app.stub(:`).with('git branch').and_return("fatal: Not a git repository (or any of the parent directories): .git")
|
173
|
+
app.stub(:environment).and_return('development')
|
174
|
+
|
175
|
+
app.method(:version_or_branch).call.should match('^Unknown')
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should be unknown if not in development mode" do
|
179
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(false)
|
180
|
+
# stub on app instead of Kernel since apparently you can't stub on a Module
|
181
|
+
app.stub(:`).with('git branch').and_return("* foo\n bar")
|
182
|
+
app.stub(:environment).and_return('production')
|
183
|
+
|
184
|
+
app.method(:version_or_branch).call.should match('^Unknown')
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#deploy_date' do
|
190
|
+
it "should use mtime of VERSION file if available" do
|
191
|
+
time = mock('time')
|
192
|
+
time.stub(:mtime).and_return('timestamp')
|
193
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(true)
|
194
|
+
File.stub(:stat).with(File.join(app.file_root, 'VERSION')).and_return(time)
|
195
|
+
|
196
|
+
app.method(:deploy_date).call.should == 'timestamp'
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should use current time if in development" do
|
200
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(false)
|
201
|
+
app.stub(:environment).and_return('development')
|
202
|
+
|
203
|
+
app.method(:deploy_date).call.should be_close(Time.now, 5)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should use unknown if not development" do
|
207
|
+
File.stub(:exists?).with(File.join(app.file_root, 'VERSION')).and_return(false)
|
208
|
+
app.stub(:environment).and_return('production')
|
209
|
+
|
210
|
+
app.method(:deploy_date).call.should match('^Unknown')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe '#last_commit' do
|
215
|
+
it "should use contents of REVISION file if available" do
|
216
|
+
File.stub(:exists?).with(File.join(app.file_root, 'REVISION')).and_return(true)
|
217
|
+
File.stub(:read).with(File.join(app.file_root, 'REVISION')).and_return('some_sha')
|
218
|
+
|
219
|
+
app.method(:last_commit).call.should == 'some_sha'
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should use current git HEAD if in git repo and development mode" do
|
223
|
+
File.stub(:exists?).with(File.join(app.file_root, 'REVISION')).and_return(false)
|
224
|
+
app.stub(:`).with('git show').and_return("commit some_sha")
|
225
|
+
app.stub(:environment).and_return('development')
|
226
|
+
|
227
|
+
app.method(:last_commit).call.should == 'some_sha'
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should be unknown if not in git repo" do
|
231
|
+
File.stub(:exists?).with(File.join(app.file_root, 'REVISION')).and_return(false)
|
232
|
+
app.stub(:`).with('git show').and_return("fatal: Not a git repository (or any of the parent directories): .git")
|
233
|
+
app.stub(:environment).and_return('development')
|
234
|
+
|
235
|
+
app.method(:last_commit).call.should match('^Unknown')
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should be unknown if not in development mode" do
|
239
|
+
File.stub(:exists?).with(File.join(app.file_root, 'REVISION')).and_return(false)
|
240
|
+
app.stub(:`).with('git show').and_return("commit some_sha")
|
241
|
+
app.stub(:environment).and_return('production')
|
242
|
+
|
243
|
+
app.method(:last_commit).call.should match('^Unknown')
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
gem 'rack', '1.0.1'
|
4
|
+
require 'operations_middleware'
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/autorun'
|
7
|
+
require 'rack/test'
|
8
|
+
require 'rspec_tag_matchers'
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
include Rack::Test::Methods
|
12
|
+
config.include(RspecTagMatchers)
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: operations_middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Primedia Team
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-19 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
version: 1.0.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 2
|
44
|
+
- 9
|
45
|
+
version: 1.2.9
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rack-test
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id003
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rspec_tag_matchers
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id004
|
72
|
+
description: "Rack middleware to provide route for heartbeat and version pages. Includes links to github repo. "
|
73
|
+
email: ""
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files:
|
79
|
+
- LICENSE
|
80
|
+
- README.rdoc
|
81
|
+
files:
|
82
|
+
- .document
|
83
|
+
- .gitignore
|
84
|
+
- LICENSE
|
85
|
+
- README.rdoc
|
86
|
+
- Rakefile
|
87
|
+
- VERSION
|
88
|
+
- lib/operations_middleware.rb
|
89
|
+
- operations_middleware.gemspec
|
90
|
+
- spec/operations_middleware_spec.rb
|
91
|
+
- spec/spec.opts
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: http://github.com/primedia/operations_middleware
|
95
|
+
licenses: []
|
96
|
+
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options:
|
99
|
+
- --charset=UTF-8
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.3.6
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Rack middleware to provide route for heartbeat and version pages.
|
123
|
+
test_files:
|
124
|
+
- spec/operations_middleware_spec.rb
|
125
|
+
- spec/spec_helper.rb
|