fozzie 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- data/fozzie.gemspec +1 -1
- data/lib/fozzie/rails/middleware.rb +5 -3
- data/lib/fozzie/version.rb +1 -1
- data/spec/lib/fozzie/rails/middleware_spec.rb +99 -55
- metadata +5 -4
data/fozzie.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "fozzie/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "fozzie"
|
7
7
|
s.version = Fozzie::VERSION
|
8
|
-
s.authors = ["Marc Watts", "Mark Barger"]
|
8
|
+
s.authors = ["Marc Watts", "Mark Barger", "Dave Nolan"]
|
9
9
|
s.email = ["marc.watts@lonelyplanet.co.uk"]
|
10
10
|
s.summary = %q{Statsd Ruby gem from Lonely Planet Online}
|
11
11
|
s.description = %q{
|
@@ -9,12 +9,14 @@ module Fozzie
|
|
9
9
|
|
10
10
|
# Generates the statistics key for the current path
|
11
11
|
def generate_key(env)
|
12
|
-
path_str
|
12
|
+
path_str = env['PATH_INFO']
|
13
|
+
request_method = env['REQUEST_METHOD']
|
14
|
+
|
13
15
|
return nil unless path_str
|
14
16
|
|
15
17
|
begin
|
16
18
|
routing = routing_lookup
|
17
|
-
path = routing.recognize_path(path_str)
|
19
|
+
path = routing.recognize_path(path_str, :method => request_method)
|
18
20
|
stat = [path[:controller], path[:action], "render"].join('.')
|
19
21
|
stat
|
20
22
|
rescue => exc
|
@@ -34,4 +36,4 @@ module Fozzie
|
|
34
36
|
end
|
35
37
|
|
36
38
|
end
|
37
|
-
end
|
39
|
+
end
|
data/lib/fozzie/version.rb
CHANGED
@@ -2,80 +2,124 @@ require 'spec_helper'
|
|
2
2
|
require 'action_controller'
|
3
3
|
|
4
4
|
describe Fozzie::Rails::Middleware do
|
5
|
-
let(:
|
6
|
-
let(:fake_env) { ({ 'PATH_INFO' => path_info }) }
|
7
|
-
let(:routing) { mock 'routing' }
|
5
|
+
let(:routes) { mock "routes" }
|
8
6
|
|
9
7
|
subject do
|
10
8
|
RailsApp = Class.new do
|
11
9
|
def call(env); env end
|
12
10
|
end unless defined?(RailsApp)
|
13
|
-
Rails = RailsApp unless defined?(Rails)
|
14
11
|
Fozzie::Rails::Middleware.new RailsApp.new
|
15
12
|
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
subject.call({}).should == {}
|
20
|
-
end
|
14
|
+
before do
|
15
|
+
Rails = rails unless defined?(Rails)
|
21
16
|
end
|
17
|
+
|
18
|
+
describe "#rails_version" do
|
19
|
+
let(:version) { "10.9.8" }
|
20
|
+
let(:rails) { mock "rails" }
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it "#generate_key" do
|
27
|
-
subject.stubs(:routing_lookup).returns(routing)
|
28
|
-
routing.expects(:recognize_path)
|
29
|
-
.with(path_info)
|
30
|
-
.returns({:controller => 'somewhere', :action => 'railsy'})
|
31
|
-
|
32
|
-
subject.generate_key(fake_env).should == 'somewhere.railsy.render'
|
22
|
+
before do
|
23
|
+
::Rails.stubs(:version).returns(version)
|
33
24
|
end
|
34
|
-
|
35
|
-
it "returns
|
36
|
-
subject.
|
37
|
-
routing.expects(:recognize_path)
|
38
|
-
.with(path_info)
|
39
|
-
.raises(RuntimeError)
|
40
|
-
|
41
|
-
subject.generate_key(fake_env).should == nil
|
25
|
+
|
26
|
+
it "returns the major version from Rails.version" do
|
27
|
+
subject.rails_version.should == 10
|
42
28
|
end
|
43
|
-
|
44
29
|
end
|
45
|
-
|
46
|
-
describe "
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
30
|
+
|
31
|
+
describe "#routing_lookup" do
|
32
|
+
context "when #rails_version == 3" do
|
33
|
+
let(:app) { mock "app" }
|
34
|
+
|
35
|
+
before do
|
36
|
+
subject.stubs(:rails_version).returns(3)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns Rails.application.routes" do
|
40
|
+
Rails.expects(:application).returns(app)
|
41
|
+
app.expects(:routes).returns(routes)
|
42
|
+
subject.routing_lookup.should eq routes
|
43
|
+
end
|
57
44
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
45
|
+
|
46
|
+
context "when #rails_version does not == 3" do
|
47
|
+
before do
|
48
|
+
if defined?(ActionController::Routing::Routes)
|
49
|
+
|
50
|
+
@old_routes_const = ActionController::Routing::Routes
|
51
|
+
ActionController::Routing.send(:remove_const, :Routes)
|
52
|
+
end
|
53
|
+
ActionController::Routing::Routes = routes
|
54
|
+
end
|
55
|
+
|
56
|
+
after do
|
57
|
+
if @old_routes_const
|
58
|
+
ActionController::Routing.send(:remove_const, :Routes)
|
59
|
+
ActionController::Routing::Routes = @old_routes_const
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns ActionController::Routing::Routes" do
|
64
|
+
subject.routing_lookup.should eq routes
|
65
|
+
end
|
66
66
|
end
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
describe "#generate_key" do
|
70
|
+
let(:env) { mock "env" }
|
71
|
+
let(:path) { mock "path" }
|
72
|
+
let(:request_method) { mock "request_method" }
|
73
|
+
|
74
|
+
it "gets the path_info and request method from env parameter" do
|
75
|
+
env.expects(:[]).with("PATH_INFO")
|
76
|
+
env.expects(:[]).with("REQUEST_METHOD")
|
77
|
+
subject.generate_key(env)
|
78
|
+
end
|
73
79
|
|
74
|
-
|
80
|
+
context "when path_info is nil" do
|
81
|
+
let(:env) { { "PATH_INFO" => nil } }
|
82
|
+
|
83
|
+
it "does not lookup routing" do
|
84
|
+
subject.expects(:routing_lookup).never
|
85
|
+
subject.generate_key(env)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "does not register any stats" do
|
89
|
+
S.expects(:increment).never
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns nil" do
|
93
|
+
subject.generate_key(env).should be_nil
|
94
|
+
end
|
95
|
+
end
|
75
96
|
|
76
|
-
|
97
|
+
context "when path info is not nil" do
|
98
|
+
let(:env) { { "PATH_INFO" => path, "REQUEST_METHOD" => request_method } }
|
99
|
+
|
100
|
+
before do
|
101
|
+
subject.stubs(:routing_lookup).returns(routes)
|
102
|
+
routes.stubs(:recognize_path).returns({ :controller => "controller",
|
103
|
+
:action => "action" })
|
104
|
+
end
|
105
|
+
|
106
|
+
it "looks up controller and action for the path and request method" do
|
107
|
+
subject.expects(:routing_lookup).returns(routes)
|
108
|
+
routes.expects(:recognize_path).with(path, :method => request_method)
|
109
|
+
subject.generate_key(env)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns a bucket generated from the controller, action, and 'render'" do
|
113
|
+
subject.generate_key(env).should eq "controller.action.render"
|
114
|
+
end
|
77
115
|
end
|
116
|
+
end
|
78
117
|
|
118
|
+
|
119
|
+
describe "subject" do
|
120
|
+
it "returns env on call for testing" do
|
121
|
+
subject.call({}).should == {}
|
122
|
+
end
|
79
123
|
end
|
80
124
|
|
81
|
-
end
|
125
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fozzie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marc Watts
|
9
9
|
- Mark Barger
|
10
|
+
- Dave Nolan
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2012-
|
14
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: sys-uname
|
@@ -278,7 +279,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
278
279
|
version: '0'
|
279
280
|
segments:
|
280
281
|
- 0
|
281
|
-
hash:
|
282
|
+
hash: 3531054699927461571
|
282
283
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
283
284
|
none: false
|
284
285
|
requirements:
|
@@ -287,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
288
|
version: '0'
|
288
289
|
segments:
|
289
290
|
- 0
|
290
|
-
hash:
|
291
|
+
hash: 3531054699927461571
|
291
292
|
requirements: []
|
292
293
|
rubyforge_project: fozzie
|
293
294
|
rubygems_version: 1.8.24
|