rack-referral-tracking 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Rack::Referral::Tracking
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/craigkerstiens/rack-referral-tracking.png)](https://codeclimate.com/github/craigkerstiens/rack-referral-tracking)
4
+
3
5
  Rack middleware that detects requests from a referral and places some details
4
6
  about the referral in a user's cookies.
5
7
 
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib/rack-referral-tracking'
7
+ t.test_files = FileList['spec/lib/**/*_spec.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -1,3 +1,4 @@
1
+ require 'cgi'
1
2
  require 'domainatrix'
2
3
  require 'fernet'
3
4
  require 'uri'
@@ -27,10 +28,10 @@ module Rack
27
28
  end
28
29
  end
29
30
 
30
- Rack::Utils.set_cookie_header!(headers, "utm_campaign", :value => params['utm_campaign'], :domain => cookie_domain, :path => '/') if params.has_key? 'utm_campaign'
31
- Rack::Utils.set_cookie_header!(headers, "utm_source", :value => params['utm_source'], :domain => cookie_domain, :path => '/') if params.has_key? 'utm_source'
32
- Rack::Utils.set_cookie_header!(headers, "utm_medium", :value => params['utm_medium'], :domain => cookie_domain, :path => '/') if params.has_key? 'utm_medium'
33
- Rack::Utils.set_cookie_header!(headers, "ref", :value => referer, :domain => cookie_domain, :path => '/') if referer
31
+ Rack::Utils.set_cookie_header!(headers, "utm_campaign", :value => params['utm_campaign'], :domain => cookie_domain, :path => '/', :httponly => true, :secure => true) if params.has_key? 'utm_campaign'
32
+ Rack::Utils.set_cookie_header!(headers, "utm_source", :value => params['utm_source'], :domain => cookie_domain, :path => '/', :httponly => true, :secure => true) if params.has_key? 'utm_source'
33
+ Rack::Utils.set_cookie_header!(headers, "utm_medium", :value => params['utm_medium'], :domain => cookie_domain, :path => '/', :httponly => true, :secure => true) if params.has_key? 'utm_medium'
34
+ Rack::Utils.set_cookie_header!(headers, "ref", :value => referer, :domain => cookie_domain, :path => '/', :httponly => true, :secure => true) if referer
34
35
 
35
36
  [status, headers, body]
36
37
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module ReferralTracking
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -19,5 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'domainatrix'
21
21
  gem.add_dependency 'fernet'
22
+ gem.add_dependency 'rack'
23
+ gem.add_development_dependency 'rack-test'
22
24
  gem.add_development_dependency 'rake'
23
25
  end
@@ -0,0 +1,52 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Rack::ReferralTracking::Middleware do
4
+ include Rack::Test::Methods
5
+
6
+ describe 'basic Rack compliance' do
7
+ let(:app) do
8
+ inner_app = lambda { |env|
9
+ [200, {'Content-Type' => 'text/plain'}, ["OK"]]
10
+ }
11
+ Rack::Lint.new(Rack::ReferralTracking::Middleware.new(inner_app))
12
+ end
13
+
14
+ it 'passes all Lint checks' do
15
+ env = Rack::MockRequest.env_for('/')
16
+ app.call(env)
17
+ end
18
+ end
19
+
20
+ describe 'with referral metadata' do
21
+ let(:app) do
22
+ inner_app = lambda { |env|
23
+ [200, {'Content-Type' => 'text/plain'}, ["OK"]]
24
+ }
25
+ Rack::ReferralTracking::Middleware.new(inner_app)
26
+ end
27
+
28
+ before { clear_cookies }
29
+
30
+ it 'stores utm_campaign in a cookie' do
31
+ get 'http://blog.example.com/?utm_campaign=launch'
32
+ get 'http://id.example.com/signup'
33
+
34
+ last_request.cookies.must_equal 'utm_campaign' => 'launch'
35
+ end
36
+
37
+ it 'stores utm_source in a cookie' do
38
+ get 'http://blog.example.com/?utm_source=twitter'
39
+ get 'http://id.example.com/signup'
40
+
41
+ last_request.cookies.must_equal 'utm_source' => 'twitter'
42
+ end
43
+
44
+ it 'stores utm_medium in a cookie' do
45
+ get 'http://blog.example.com/?utm_medium=email'
46
+ get 'http://id.example.com/signup'
47
+
48
+ last_request.cookies.must_equal 'utm_medium' => 'email'
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,9 @@
1
+ ENV['REFERRAL_SECRET'] = '50mJn9wvwAXtQ28obpwxD7uMcqJRUquFz+GMRGDB4ZU='
2
+
3
+ require 'minitest/autorun'
4
+ require 'minitest/spec'
5
+
6
+ require 'rack/mock'
7
+ require 'rack/test'
8
+
9
+ require 'rack-referral-tracking'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-referral-tracking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-24 00:00:00.000000000 Z
13
+ date: 2014-01-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: domainatrix
@@ -44,6 +44,38 @@ dependencies:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rack-test
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
47
79
  - !ruby/object:Gem::Dependency
48
80
  name: rake
49
81
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +108,8 @@ files:
76
108
  - lib/rack-referral-tracking/middleware.rb
77
109
  - lib/rack-referral-tracking/version.rb
78
110
  - rack-referral-tracking.gemspec
111
+ - spec/lib/rack-referral-tracking/middleware_spec.rb
112
+ - spec/spec_helper.rb
79
113
  homepage: https://github.com/craigkerstiens/rack-referral-tracking
80
114
  licenses: []
81
115
  post_install_message:
@@ -100,4 +134,6 @@ rubygems_version: 1.8.25
100
134
  signing_key:
101
135
  specification_version: 3
102
136
  summary: Remember a visitor's referrer across subdomains
103
- test_files: []
137
+ test_files:
138
+ - spec/lib/rack-referral-tracking/middleware_spec.rb
139
+ - spec/spec_helper.rb