rack-piwik 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/test/helper.rb +29 -0
- data/test/test_rack_piwik.rb +56 -0
- metadata +3 -1
data/test/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'rack'
|
5
|
+
require 'rack/test'
|
6
|
+
require File.expand_path('../../lib/rack/piwik',__FILE__)
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
def app; Rack::Lint.new(@app); end
|
12
|
+
|
13
|
+
def mock_app(options)
|
14
|
+
main_app = lambda { |env|
|
15
|
+
request = Rack::Request.new(env)
|
16
|
+
case request.path
|
17
|
+
when '/head_only' then [200,{ 'Content-Type' => 'application/html' },['<head>head only</head>']]
|
18
|
+
when '/arbitrary.xml' then [200,{'Content-Type' => 'application/xml'}, ['xml only']]
|
19
|
+
when '/body_only' then [200,{'Content-Type' => 'application/html'} ,['<body>body only</body>']]
|
20
|
+
else [404,'Nothing here']
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
builder = Rack::Builder.new
|
25
|
+
builder.use Rack::Piwik, options
|
26
|
+
builder.run main_app
|
27
|
+
@app = builder.to_app
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path('../helper',__FILE__)
|
2
|
+
|
3
|
+
class TestRackPiwik < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Asynchronous" do
|
6
|
+
context "default" do
|
7
|
+
setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123' }
|
8
|
+
should "add tracker if body element is present" do
|
9
|
+
get "/body_only"
|
10
|
+
assert_match %r{https://piwik.example.org/}, last_response.body
|
11
|
+
assert_match %r{123\);}, last_response.body
|
12
|
+
assert_match %r{</noscript>\n<!-- End Piwik Code --></body>}, last_response.body
|
13
|
+
assert_equal "650", last_response.headers['Content-Length']
|
14
|
+
end
|
15
|
+
|
16
|
+
should "omit 404 tracking for other responses with other status" do
|
17
|
+
get "/body_only"
|
18
|
+
assert_no_match %r{.setDocumentTitle\('404/URL}, last_response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
should "omit addition of tracking code for non-html content" do
|
22
|
+
get "/arbitrary.xml"
|
23
|
+
assert_no_match %r{Piwik}, last_response.body
|
24
|
+
assert_match %r{xml only}, last_response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
should "omit addition of tracking code if </body> tag is missing" do
|
28
|
+
get "/head_only"
|
29
|
+
assert_no_match %r{Piwik}, last_response.body
|
30
|
+
assert_match %r{head only}, last_response.body
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with a number as piwik id" do
|
36
|
+
setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => 123 }
|
37
|
+
should "not raise an exception" do
|
38
|
+
assert_nothing_raised do
|
39
|
+
get "/body_only"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
=begin
|
46
|
+
context "Synchronous" do
|
47
|
+
setup { mock_app :async => false, :tracker => 'whatthe', :piwik_url => 'piwik.example.org', :piwik_id => '123' }
|
48
|
+
should "show non-asynchronous tracker" do
|
49
|
+
get "/bob"
|
50
|
+
assert_match %r{.getTracker}, last_response.body
|
51
|
+
assert_match %r{</script></body>}, last_response.body
|
52
|
+
assert_match %r{\"whatthe\"}, last_response.body
|
53
|
+
end
|
54
|
+
end
|
55
|
+
=end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-piwik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -24,6 +24,8 @@ files:
|
|
24
24
|
- lib/rack/templates/async.erb
|
25
25
|
- README.md
|
26
26
|
- LICENSE
|
27
|
+
- test/test_rack_piwik.rb
|
28
|
+
- test/helper.rb
|
27
29
|
homepage: https://github.com/maxwell/rack-piwik
|
28
30
|
licenses: []
|
29
31
|
post_install_message:
|