mongoid_traffic 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/Gemfile +1 -5
- data/Gemfile.lock +58 -53
- data/lib/mongoid_traffic/controller_additions.rb +6 -8
- data/lib/mongoid_traffic/log.rb +21 -25
- data/lib/mongoid_traffic/logger/bots.rb +8 -11
- data/lib/mongoid_traffic/logger/browser.rb +1 -5
- data/lib/mongoid_traffic/logger/geo_ip.rb +4 -6
- data/lib/mongoid_traffic/logger/referer.rb +2 -4
- data/lib/mongoid_traffic/logger.rb +15 -17
- data/lib/mongoid_traffic/version.rb +1 -1
- data/mongoid_traffic.gemspec +3 -3
- data/test/mongoid_traffic/controller_additions_test.rb +1 -3
- data/test/mongoid_traffic/log_test.rb +40 -43
- data/test/mongoid_traffic/logger/bots_test.rb +1 -3
- data/test/mongoid_traffic/logger/browser_test.rb +1 -3
- data/test/mongoid_traffic/logger/geoip_test.rb +1 -3
- data/test/mongoid_traffic/logger/referer_test.rb +1 -3
- data/test/mongoid_traffic/logger_test.rb +2 -3
- data/test/support/database_cleaner.rb +10 -0
- data/test/support/mongoid.rb +8 -0
- data/test/test_helper.rb +5 -12
- data/vendor/mongoid_traffic/GeoIP.dat +0 -0
- data/vendor/mongoid_traffic/allagents.xml +22134 -22170
- metadata +18 -14
@@ -50,11 +50,11 @@ module MongoidTraffic
|
|
50
50
|
describe '.aggregate_on' do
|
51
51
|
let(:log_1) { MyLog.new(date_from: Date.today, date_to: Date.today) }
|
52
52
|
let(:log_2) { MyLog.new(date_from: Date.tomorrow, date_to: Date.tomorrow) }
|
53
|
-
|
53
|
+
|
54
54
|
describe '.aggregate_on(:access_count)' do
|
55
55
|
before do
|
56
|
-
log_1.tap{ |l| l.access_count = 1 }.save
|
57
|
-
log_2.tap{ |l| l.access_count = 2 }.save
|
56
|
+
log_1.tap { |l| l.access_count = 1 }.save
|
57
|
+
log_2.tap { |l| l.access_count = 2 }.save
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'sums the access_counts' do
|
@@ -65,82 +65,80 @@ module MongoidTraffic
|
|
65
65
|
describe '.aggregate_on(:browsers)' do
|
66
66
|
# not the key names have been abbreviated
|
67
67
|
before do
|
68
|
-
log_1.tap do |l|
|
68
|
+
log_1.tap do |l|
|
69
69
|
l.browsers = {
|
70
|
-
|
71
|
-
|
72
|
-
},
|
73
|
-
|
74
|
-
|
70
|
+
'Mac' => {
|
71
|
+
'Saf' => { '8' => 1 }
|
72
|
+
},
|
73
|
+
'Win' => {
|
74
|
+
'Saf' => { '7' => 5 }
|
75
75
|
}
|
76
76
|
}
|
77
77
|
end.save
|
78
|
-
|
79
|
-
log_2.tap do |l|
|
80
|
-
l.browsers = {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
},
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
78
|
+
|
79
|
+
log_2.tap do |l|
|
80
|
+
l.browsers = {
|
81
|
+
'Mac' => {
|
82
|
+
'Saf' => { '8' => 10, '7' => 100 },
|
83
|
+
'Chr' => { '3' => 5 }
|
84
|
+
},
|
85
|
+
'Win' => {
|
86
|
+
'Saf' => { '7' => 100 },
|
87
|
+
'IE' => { '10' => 1 }
|
88
|
+
}
|
89
89
|
}
|
90
90
|
end.save
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'sums the browsers' do
|
94
|
-
MyLog.aggregate_on(:browsers).must_equal({
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
})
|
94
|
+
MyLog.aggregate_on(:browsers).must_equal('Mac' => {
|
95
|
+
'Saf' => { '8' => 11, '7' => 100 },
|
96
|
+
'Chr' => { '3' => 5 }
|
97
|
+
},
|
98
|
+
'Win' => {
|
99
|
+
'Saf' => { '7' => 105 },
|
100
|
+
'IE' => { '10' => 1 }
|
101
|
+
})
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
105
|
describe '.aggregate_on(:referers)' do
|
108
106
|
before do
|
109
|
-
log_1.tap{ |l| l.referers = { 'google' => 100, 'apple' => 1000 } }.save
|
110
|
-
log_2.tap{ |l| l.referers = { 'google' => 10, 'apple' => 100, 'ms' => 1 } }.save
|
107
|
+
log_1.tap { |l| l.referers = { 'google' => 100, 'apple' => 1000 } }.save
|
108
|
+
log_2.tap { |l| l.referers = { 'google' => 10, 'apple' => 100, 'ms' => 1 } }.save
|
111
109
|
end
|
112
110
|
|
113
111
|
it 'sums the referers' do
|
114
|
-
MyLog.aggregate_on(:referers).must_equal(
|
112
|
+
MyLog.aggregate_on(:referers).must_equal('google' => 110, 'apple' => 1100, 'ms' => 1)
|
115
113
|
end
|
116
114
|
end
|
117
115
|
|
118
116
|
describe '.aggregate_on(:countries)' do
|
119
117
|
before do
|
120
|
-
log_1.tap{ |l| l.countries = { 'CZ' => 100 } }.save
|
121
|
-
log_2.tap{ |l| l.countries = { 'DE' => 10 } }.save
|
118
|
+
log_1.tap { |l| l.countries = { 'CZ' => 100 } }.save
|
119
|
+
log_2.tap { |l| l.countries = { 'DE' => 10 } }.save
|
122
120
|
end
|
123
121
|
|
124
122
|
it 'sums the countries' do
|
125
|
-
MyLog.aggregate_on(:countries).must_equal(
|
123
|
+
MyLog.aggregate_on(:countries).must_equal('CZ' => 100, 'DE' => 10)
|
126
124
|
end
|
127
125
|
end
|
128
126
|
|
129
127
|
describe '.aggregate_on(:unique_ids)' do
|
130
128
|
before do
|
131
|
-
log_1.tap{ |l| l.unique_ids = { '01234' => 100, '56789' => 100 } }.save
|
132
|
-
log_2.tap{ |l| l.unique_ids = { '56789' => 100 } }.save
|
129
|
+
log_1.tap { |l| l.unique_ids = { '01234' => 100, '56789' => 100 } }.save
|
130
|
+
log_2.tap { |l| l.unique_ids = { '56789' => 100 } }.save
|
133
131
|
end
|
134
132
|
|
135
133
|
it 'sums the unique_ids' do
|
136
|
-
MyLog.aggregate_on(:unique_ids).must_equal(
|
134
|
+
MyLog.aggregate_on(:unique_ids).must_equal('01234' => 100, '56789' => 200)
|
137
135
|
end
|
138
136
|
end
|
139
137
|
|
140
138
|
describe '.sum(:unique_ids)' do
|
141
139
|
before do
|
142
|
-
log_1.tap{ |l| l.unique_ids = { '01234' => 100, '56789' => 100 } }.save
|
143
|
-
log_2.tap{ |l| l.unique_ids = { '56789' => 100, 'ABCDE' => 1 } }.save
|
140
|
+
log_1.tap { |l| l.unique_ids = { '01234' => 100, '56789' => 100 } }.save
|
141
|
+
log_2.tap { |l| l.unique_ids = { '56789' => 100, 'ABCDE' => 1 } }.save
|
144
142
|
end
|
145
143
|
|
146
144
|
it 'sums the unique_ids' do
|
@@ -148,6 +146,5 @@ module MongoidTraffic
|
|
148
146
|
end
|
149
147
|
end
|
150
148
|
end
|
151
|
-
|
152
149
|
end
|
153
|
-
end
|
150
|
+
end
|
@@ -5,7 +5,6 @@ require_relative '../../../lib/mongoid_traffic/logger/bots'
|
|
5
5
|
module MongoidTraffic
|
6
6
|
class Logger
|
7
7
|
describe 'Bots' do
|
8
|
-
|
9
8
|
describe '.list' do
|
10
9
|
it 'parses the allagents.xml and converts it into Array of referers' do
|
11
10
|
Bots.list.must_be_kind_of Array
|
@@ -17,7 +16,6 @@ module MongoidTraffic
|
|
17
16
|
Bots.is_a_bot?('Googlebot/Test ( http://www.googlebot.com/bot.html)').must_equal true
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
23
|
-
end
|
21
|
+
end
|
@@ -5,7 +5,6 @@ require_relative '../../../lib/mongoid_traffic/logger/browser'
|
|
5
5
|
module MongoidTraffic
|
6
6
|
class Logger
|
7
7
|
describe 'Browser' do
|
8
|
-
|
9
8
|
let(:user_agent_string) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/538.46 (KHTML, like Gecko) Version/8.0 Safari/538.46' }
|
10
9
|
subject { Browser.new(user_agent_string) }
|
11
10
|
|
@@ -20,7 +19,6 @@ module MongoidTraffic
|
|
20
19
|
it 'returns :version' do
|
21
20
|
subject.version.must_equal '8.0'
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
26
|
-
end
|
24
|
+
end
|
@@ -5,13 +5,11 @@ require_relative '../../../lib/mongoid_traffic/logger/geo_ip'
|
|
5
5
|
module MongoidTraffic
|
6
6
|
class Logger
|
7
7
|
describe 'GeoIp' do
|
8
|
-
|
9
8
|
describe '.country_code2' do
|
10
9
|
it 'returns country code' do
|
11
10
|
GeoIp.country_code2('github.com').must_equal 'US'
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
16
14
|
end
|
17
|
-
end
|
15
|
+
end
|
@@ -5,7 +5,6 @@ require_relative '../../../lib/mongoid_traffic/logger/referer'
|
|
5
5
|
module MongoidTraffic
|
6
6
|
class Logger
|
7
7
|
describe 'Referer' do
|
8
|
-
|
9
8
|
let(:referer_string) { 'http://www.google.com:80/path/to?foo=bar' }
|
10
9
|
subject { Referer.new(referer_string) }
|
11
10
|
|
@@ -24,7 +23,6 @@ module MongoidTraffic
|
|
24
23
|
it 'strips query params' do
|
25
24
|
subject.host.wont_include '?foo=bar'
|
26
25
|
end
|
27
|
-
|
28
26
|
end
|
29
27
|
end
|
30
|
-
end
|
28
|
+
end
|
@@ -17,7 +17,7 @@ module MongoidTraffic
|
|
17
17
|
|
18
18
|
describe 'ClassMethods' do
|
19
19
|
describe '.log' do
|
20
|
-
before do
|
20
|
+
before do
|
21
21
|
MongoidTraffic::Logger.log(::MyLog, user_agent: user_agent_string, referer: referer, ip_address: ip_address, unique_id: unique_id)
|
22
22
|
MongoidTraffic::Logger.log(::MyLog, scope: scope, user_agent: user_agent_string, referer: referer, ip_address: ip_address, unique_id: unique_id)
|
23
23
|
end
|
@@ -58,6 +58,5 @@ module MongoidTraffic
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
61
|
end
|
63
|
-
end
|
62
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,28 +1,21 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'database_cleaner'
|
3
|
+
|
3
4
|
require 'minitest'
|
5
|
+
require 'minitest/around'
|
4
6
|
require 'minitest/autorun'
|
5
7
|
require 'minitest/spec'
|
8
|
+
|
6
9
|
require 'mongoid'
|
7
10
|
require 'mongoid_traffic'
|
8
11
|
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
13
|
+
|
9
14
|
if ENV["CI"]
|
10
15
|
require "coveralls"
|
11
16
|
Coveralls.wear!
|
12
17
|
end
|
13
18
|
|
14
|
-
Mongoid.configure do |config|
|
15
|
-
config.connect_to('mongoid_traffic_test')
|
16
|
-
end
|
17
|
-
|
18
|
-
DatabaseCleaner.orm = :mongoid
|
19
|
-
DatabaseCleaner.strategy = :truncation
|
20
|
-
|
21
|
-
class MiniTest::Spec
|
22
|
-
before(:each) { DatabaseCleaner.start }
|
23
|
-
after(:each) { DatabaseCleaner.clean }
|
24
|
-
end
|
25
|
-
|
26
19
|
class MyLog
|
27
20
|
include Mongoid::Document
|
28
21
|
include MongoidTraffic::Log
|
Binary file
|