File: test_rack_piwik.rb

package info (click to toggle)
ruby-rack-piwik 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 116 kB
  • ctags: 22
  • sloc: ruby: 108; makefile: 7
file content (65 lines) | stat: -rwxr-xr-x 2,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require File.expand_path('../helper',__FILE__)

class TestRackPiwik < Test::Unit::TestCase

  context "Asynchronous" do
    context "default" do
      setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123' }
      should "add tracker if body element is present" do
        get "/body_only"
        assert_match 'http://piwik.example.org/', last_response.body
        assert_match '_paq.push(["setSiteId", "123"]);', last_response.body
        assert_match %r{</noscript>\n<!-- End Piwik --></body>}, last_response.body
        assert_equal 787, last_response.headers['Content-Length'].to_i
      end

      should "omit 404 tracking for other responses with other status" do
        get "/body_only"
        assert_no_match %r{.setDocumentTitle\('404/URL}, last_response.body
      end

      should "omit addition of tracking code for non-html content" do
        get "/arbitrary.xml"
        assert_no_match %r{Piwik}, last_response.body
        assert_match %r{xml only}, last_response.body
      end

      should "omit addition of tracking code if </body> tag is missing" do
        get "/head_only"
        assert_no_match %r{Piwik}, last_response.body
        assert_match %r{head only}, last_response.body
      end
      
    end
    
    context "with a number as piwik id" do
      setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => 123 }
      should "not raise an exception" do
        assert_nothing_raised do
          get "/body_only"
        end
      end
    end
  end

=begin
  context "Synchronous" do
    setup { mock_app :async => false, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123' }

    should "add tracker if body element is present" do
      get "/body_only"
      assert_match %r{https://piwik.example.org/}, last_response.body
      assert_match %r{123\);}, last_response.body
      assert_match %r{</noscript>\n<!-- End Piwik --></body>}, last_response.body
      assert_equal "650", last_response.headers['Content-Length']
    end

    should "show non-asynchronous tracker" do
      get "/bob"
      assert_match %r{.getTracker}, last_response.body
      assert_match %r{</script></body>}, last_response.body
      assert_match %r{\"whatthe\"}, last_response.body
    end
  end
=end
end