angerfist 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 570cfab56b1e1c2f3ff239ed554641cd5ddd314c
4
- data.tar.gz: 5ebf3825f97c153f7a401ba22c5f83736fac78f3
3
+ metadata.gz: 1ff2164384f815b36b0331387f8d2cacda44cb4d
4
+ data.tar.gz: 2cf3434a639e64e0bb91d4a33a9bd0b38ee4e06b
5
5
  SHA512:
6
- metadata.gz: cc57f603d5c6e1720a68410f9f69e5ff46dc3024b644008a324fef9f528d78bf9fea60cfb88333e15556cb2c236a368692fb4872a26b3ff2d566bc48117bfab0
7
- data.tar.gz: a5522fda54d14a47c01d4c70cd15d79b22f87aeb0a3cfb9c2d46f13b59af9e15b926a25839b60e08900a0aff0dfb9a1c896ea9e81b22314ce354948f76e7c171
6
+ metadata.gz: 1dde68d4a77abf5abc4e28964bd6c4774d22e7c7148970d1bd252bd7deade0a22bfebb20f988b51c6b4b2d34f4165aa529d7ff39712c271b0e8de6e2db87ab72
7
+ data.tar.gz: d4cf0b6060be7c4dd174ade7dbcd3230d09daf416413955ca0dc2737695731c96ff449c90d5d9c3647724db21687244abb62cc9cc09921bdf509ef03518c81b1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.0.0
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
+ [![Build Status](http://img.shields.io/travis/OpenAddressesUK/angerfist.svg)](https://travis-ci.org/OpenAddressesUK/angerfist)
1
2
  [![Dependency Status](http://img.shields.io/gemnasium/OpenAddressesUK/angerfist.svg)](https://gemnasium.com/OpenAddressesUK/angerfist)
2
3
  [![Code Climate](http://img.shields.io/codeclimate/github/OpenAddressesUK/angerfist.svg)](https://codeclimate.com/github/OpenAddressesUK/angerfist)
3
4
  [![Gem Version](http://img.shields.io/gem/v/angerfist.svg)](https://rubygems.org/gems/angerfist)
4
5
  [![License](http://img.shields.io/:license-mit-blue.svg)](http://OpenAddressesUK.mit-license.org)
5
- [![Badges](http://img.shields.io/:badges-5/5-ff6799.svg)](https://github.com/badges/badgerbadgerbadger)
6
+ [![Badges](http://img.shields.io/:badges-6/6-ff6799.svg)](https://github.com/badges/badgerbadgerbadger)
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -3,16 +3,35 @@ module Rack
3
3
  def initialize app, config
4
4
  @app = app
5
5
  @gabba = Gabba::Gabba.new(config[:tracker_id], config[:domain])
6
+ @content_types = config[:content_types]
7
+ @paths = config[:paths]
6
8
  end
7
9
 
8
10
  def call env
9
11
  @env = env
10
12
  status, headers, response = @app.call(@env)
11
- @gabba.page_view(full_path, full_path)
13
+
14
+ @headers = Rack::Utils::HeaderHash.new(headers)
15
+
16
+ if content_type_matches? && path_matches?
17
+ @gabba.page_view(full_path, full_path)
18
+ end
12
19
 
13
20
  [ status, headers, response ]
14
21
  end
15
22
 
23
+ def content_type_matches?
24
+ return true unless @content_types
25
+
26
+ @content_types.include?(@headers['CONTENT-TYPE'])
27
+ end
28
+
29
+ def path_matches?
30
+ return true unless @paths
31
+
32
+ @paths.any? { |p| @env['PATH_INFO'].include?(p) }
33
+ end
34
+
16
35
  def full_path
17
36
  (@env['PATH_INFO'] + '?' + @env['QUERY_STRING']).chomp('?')
18
37
  end
@@ -1,3 +1,3 @@
1
1
  module Angerfist
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -4,13 +4,13 @@ module Rack
4
4
  describe Angerfist do
5
5
  let :config do
6
6
  {
7
- tracker_id: "UA-xxxxxxx-x",
8
- domain: "http://test.domain"
7
+ tracker_id: 'UA-xxxxxxx-x',
8
+ domain: 'http://test.domain'
9
9
  }
10
10
  end
11
11
 
12
12
  it 'tracks a page view' do
13
- app = proc{
13
+ app = proc {
14
14
  [
15
15
  200,
16
16
  {},
@@ -19,12 +19,87 @@ module Rack
19
19
  ]
20
20
  ]
21
21
  }
22
+ middleware = Angerfist.new(app, config)
23
+ request = Rack::MockRequest.new(middleware)
22
24
 
25
+ expect_any_instance_of(Gabba::Gabba).to receive(:page_view)
26
+ request.get('addresses/address.json', {})
27
+ end
28
+
29
+ it 'tracks a page view for the specified content type' do
30
+ app = proc {
31
+ [
32
+ 200,
33
+ {'CONTENT-TYPE' => 'application/json'},
34
+ [
35
+ 'Hello, world'
36
+ ]
37
+ ]
38
+ }
39
+ content_type = 'application/json'
40
+ config[:content_types] = [ content_type ]
23
41
  middleware = Angerfist.new(app, config)
24
42
  request = Rack::MockRequest.new(middleware)
25
43
 
26
44
  expect_any_instance_of(Gabba::Gabba).to receive(:page_view)
45
+ request.get('addresses/address.json', { 'CONTENT-TYPE' => content_type })
46
+ end
47
+
48
+ it 'does not track a page view for an unspecified content type' do
49
+ app = proc {
50
+ [
51
+ 200,
52
+ {'CONTENT-TYPE' => 'application/xml'},
53
+ [
54
+ 'Hello, world'
55
+ ]
56
+ ]
57
+ }
58
+ content_type = 'application/json'
59
+ config[:content_types] = [ content_type ]
60
+ middleware = Angerfist.new(app, config)
61
+ request = Rack::MockRequest.new(middleware)
62
+
63
+ expect_any_instance_of(Gabba::Gabba).to_not receive(:page_view)
27
64
  request.get('addresses/address.json', {})
28
65
  end
66
+
67
+ it 'tracks a page at a specific path' do
68
+ app = proc {
69
+ [
70
+ 200,
71
+ {'CONTENT-TYPE' => 'application/json'},
72
+ [
73
+ 'Hello, world'
74
+ ]
75
+ ]
76
+ }
77
+
78
+ config[:paths] = ['/happy_path']
79
+ middleware = Angerfist.new(app, config)
80
+ request = Rack::MockRequest.new(middleware)
81
+
82
+ expect_any_instance_of(Gabba::Gabba).to receive(:page_view)
83
+ request.get('/happy_path?query=some_string')
84
+ end
85
+
86
+ it 'does not track for an unspecified path' do
87
+ app = proc {
88
+ [
89
+ 200,
90
+ {'CONTENT-TYPE' => 'application/json'},
91
+ [
92
+ 'Hello, world'
93
+ ]
94
+ ]
95
+ }
96
+
97
+ config[:paths] = ['/happy_path']
98
+ middleware = Angerfist.new(app, config)
99
+ request = Rack::MockRequest.new(middleware)
100
+
101
+ expect_any_instance_of(Gabba::Gabba).to_not receive(:page_view)
102
+ request.get('/sad_path?query=some_string')
103
+ end
29
104
  end
30
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angerfist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
105
  - ".rspec"
106
+ - ".travis.yml"
106
107
  - Gemfile
107
108
  - LICENSE.md
108
109
  - README.md