notches 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/README.md +26 -3
- data/app/models/notches/event.rb +31 -0
- data/app/models/notches/hit.rb +5 -4
- data/app/models/notches/name.rb +8 -0
- data/app/models/notches/scope.rb +8 -0
- data/app/models/notches/time.rb +4 -0
- data/db/migrate/20160804111320_create_notches_events.rb +35 -0
- data/lib/notches/version.rb +1 -1
- data/notches.gemspec +4 -4
- data/spec/controllers/notches/hits_controller_spec.rb +10 -10
- data/spec/models/notches/event_spec.rb +104 -0
- data/spec/models/notches/hit_spec.rb +37 -33
- metadata +35 -38
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YmNiZmFmZGZlOGQ4ODQ5Yjg4ZjBmMzY0OTAwODQ1M2RmODBmNDVjNTdkZDJh
|
10
|
-
YjY0ZTM0MTkwNWNkOTQ2OGY0ZjU3NjNmMTA2ODI2ZDI0YjhiYmExMTIwOGFl
|
11
|
-
ZTI4OWJlMzc4NWQ5MTRhM2Y5MjU1MzhmNTJmNjllNzJlYjc1NDQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZDcwZWQ2MjQ1YWVmMDk2MjRlZmY0ZDMxNDg0MjkwNTQwNmE5N2QwYTc1Yzg5
|
14
|
-
MzA2MjkzZjE4NWViMzhiYTFkMDU0MjVjMTkxOGZmOWZiMGZmZWU3ZjJmMzgy
|
15
|
-
YmFlMTI5ZjA0N2RmZmVlYTJkZGFhNWIzMTVlZjZiOTE5Njk4MWU=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed673601115b4a08c8c6f46ac1ba576217d16d5a
|
4
|
+
data.tar.gz: 65eb69efd2001ce4f544e70f6e5db92fd5f73781
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 887a3b48a25567423d9b1bb38c4f72f93e7824eb2c391db65ad7decebb6b2f5cb854ef817733fd00ce6a13c30962140edaac39e29ccddebbdaca50158d35e6de
|
7
|
+
data.tar.gz: 01eb20fe4cba9d8a82f7b4c48d7cd316377c13e1182e0d40061c8c42d6ee6d222ccd74e95f1c9f10b6432b212845bf1707e24c8ff2d3576fa27ac0ea83670d07
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Notches
|
2
2
|
-------
|
3
3
|
|
4
|
-
A Rails Engine for tracking your web traffic.
|
4
|
+
A Rails Engine for tracking your web traffic or other events.
|
5
5
|
|
6
6
|
Installation
|
7
7
|
------------
|
8
8
|
|
9
9
|
Add this to your Gemfile and run the `bundle` command.
|
10
10
|
|
11
|
-
gem 'notches', '~> 0.
|
11
|
+
gem 'notches', '~> 0.6.0'
|
12
12
|
|
13
13
|
And then install and run the necessary migrations.
|
14
14
|
|
@@ -19,7 +19,10 @@ Mount your engine at your desired location in `config/routes.rb`.
|
|
19
19
|
|
20
20
|
mount Notches::Engine => '/notches'
|
21
21
|
|
22
|
-
|
22
|
+
Recording hits
|
23
|
+
--------------
|
24
|
+
|
25
|
+
To record hits include the notch pixel image at the bottom of your views.
|
23
26
|
|
24
27
|
<%= image_tag "/notches/hits/new.gif?url=#{request.url}" %>
|
25
28
|
|
@@ -52,3 +55,23 @@ Or a user agent:
|
|
52
55
|
|
53
56
|
To get a better idea of how Notches is setup check out the
|
54
57
|
[Notches::Hit](http://github.com/hypertiny/notches/blob/master/app/models/notches/hit.rb) model.
|
58
|
+
|
59
|
+
Recording events
|
60
|
+
----------------
|
61
|
+
|
62
|
+
To record events make the following call, the scope is optional.
|
63
|
+
|
64
|
+
Notches::Event.log(name: 'An important event', scope: 'A scope')
|
65
|
+
|
66
|
+
Counting events
|
67
|
+
-------------
|
68
|
+
|
69
|
+
For a name:
|
70
|
+
|
71
|
+
Notches::Event.joins(:name).where('name like ?', 'An important event').count
|
72
|
+
|
73
|
+
For a name and scope:
|
74
|
+
|
75
|
+
Notches::Event.joins(:name, :scope).where(
|
76
|
+
'name like = ? and scope like ?', 'An important event', 'A scope'
|
77
|
+
).count
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Notches::Event < ActiveRecord::Base
|
2
|
+
self.table_name = "notches_events"
|
3
|
+
|
4
|
+
validates :name, presence: true
|
5
|
+
|
6
|
+
validates_associated :name, :scope
|
7
|
+
|
8
|
+
belongs_to :date, foreign_key: :notches_date_id
|
9
|
+
belongs_to :name, foreign_key: :notches_name_id, :class_name => Name.to_s
|
10
|
+
belongs_to :scope, foreign_key: :notches_scope_id, :class_name => Scope.to_s
|
11
|
+
belongs_to :time, foreign_key: :notches_time_id
|
12
|
+
|
13
|
+
def self.log(attributes)
|
14
|
+
event = self.new
|
15
|
+
event.transaction do
|
16
|
+
Rails.logger.info("[Notches] Tracking #{attributes.inspect} at #{Date.today} #{Time.now}")
|
17
|
+
now = Time.zone.now
|
18
|
+
event.name = Notches::Name.find_or_create_by(name: attributes[:name])
|
19
|
+
event.scope = Notches::Scope.find_or_create_by(scope: attributes[:scope]) if attributes[:scope].present?
|
20
|
+
event.date = Notches::Date.find_or_create_by(date: now.to_date)
|
21
|
+
event.time = Notches::Time.find_or_create_by_time(now)
|
22
|
+
|
23
|
+
begin
|
24
|
+
event.save!
|
25
|
+
rescue
|
26
|
+
Rails.logger.info "Skipping non-unique event"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
event
|
30
|
+
end
|
31
|
+
end
|
data/app/models/notches/hit.rb
CHANGED
@@ -21,15 +21,16 @@ class Notches::Hit < ActiveRecord::Base
|
|
21
21
|
hit = self.new
|
22
22
|
hit.transaction do
|
23
23
|
Rails.logger.info("[Notches] Tracking #{attributes.inspect} at #{Date.today} #{Time.now}")
|
24
|
-
|
24
|
+
now = Time.zone.now
|
25
|
+
hit.url = Notches::URL.find_or_create_by(url: attributes[:url])
|
25
26
|
hit.user_agent = Notches::UserAgent.find_or_create_by(
|
26
27
|
user_agent_md5: Digest::MD5.hexdigest(attributes[:user_agent]),
|
27
28
|
:user_agent => attributes[:user_agent]
|
28
29
|
)
|
29
30
|
hit.session = Notches::Session.find_or_create_by(session_id: attributes[:session_id])
|
30
31
|
hit.ip = Notches::IP.find_or_create_by(ip: attributes[:ip])
|
31
|
-
hit.date = Notches::Date.find_or_create_by(date:
|
32
|
-
hit.time = Notches::Time.
|
32
|
+
hit.date = Notches::Date.find_or_create_by(date: now.to_date)
|
33
|
+
hit.time = Notches::Time.find_or_create_by_time(now)
|
33
34
|
|
34
35
|
if attributes[:user_id].present?
|
35
36
|
Notches::UserSession.find_or_create_by(
|
@@ -40,7 +41,7 @@ class Notches::Hit < ActiveRecord::Base
|
|
40
41
|
|
41
42
|
begin
|
42
43
|
hit.save!
|
43
|
-
rescue
|
44
|
+
rescue
|
44
45
|
Rails.logger.info "Skipping non-unique hit"
|
45
46
|
end
|
46
47
|
end
|
data/app/models/notches/time.rb
CHANGED
@@ -3,4 +3,8 @@ class Notches::Time < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
has_many :hits, :class_name => "Notches::Hit",
|
5
5
|
:foreign_key => 'notches_time_id'
|
6
|
+
|
7
|
+
def self.find_or_create_by_time(time)
|
8
|
+
where("time(time) = ?", time.strftime("%H:%M:%S")).first.presence || create(time: time)
|
9
|
+
end
|
6
10
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class CreateNotchesEvents < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :notches_names do |t|
|
4
|
+
t.string :name
|
5
|
+
end
|
6
|
+
create_table :notches_scopes do |t|
|
7
|
+
t.string :scope
|
8
|
+
end
|
9
|
+
create_table :notches_events do |t|
|
10
|
+
t.integer :notches_name_id, :null => false
|
11
|
+
t.integer :notches_scope_id
|
12
|
+
t.integer :notches_date_id, :null => false
|
13
|
+
t.integer :notches_time_id, :null => false
|
14
|
+
end
|
15
|
+
add_index :notches_names, :name
|
16
|
+
add_index :notches_scopes, :scope
|
17
|
+
add_index :notches_events, [
|
18
|
+
:notches_time_id,
|
19
|
+
:notches_date_id,
|
20
|
+
:notches_name_id,
|
21
|
+
:notches_scope_id
|
22
|
+
], :name => :notches_event_index, :unique => true
|
23
|
+
end
|
24
|
+
|
25
|
+
def down
|
26
|
+
remove_index :notches_scopes, :scope
|
27
|
+
remove_index :notches_names, :name
|
28
|
+
change_table :notches_events do |t|
|
29
|
+
t.remove_index :name => :notches_event_index
|
30
|
+
end
|
31
|
+
drop_table :notches_scopes
|
32
|
+
drop_table :notches_names
|
33
|
+
drop_table :notches_events
|
34
|
+
end
|
35
|
+
end
|
data/lib/notches/version.rb
CHANGED
data/notches.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
}
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
|
23
|
-
s.add_runtime_dependency 'rails', '
|
23
|
+
s.add_runtime_dependency 'rails', '>= 4.1'
|
24
24
|
|
25
|
-
s.add_development_dependency 'combustion', '~> 0.5.
|
26
|
-
s.add_development_dependency 'rspec-rails', '~> 2
|
27
|
-
s.add_development_dependency 'sqlite3', '~> 1.3.
|
25
|
+
s.add_development_dependency 'combustion', '~> 0.5.5'
|
26
|
+
s.add_development_dependency 'rspec-rails', '~> 3.4.2'
|
27
|
+
s.add_development_dependency 'sqlite3', '~> 1.3.11'
|
28
28
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Notches::HitsController do
|
3
|
+
describe Notches::HitsController, type: :controller do
|
4
4
|
describe "#new" do
|
5
5
|
it "returns an image" do
|
6
6
|
get :new, :url => '/posts', :format => 'gif'
|
7
7
|
|
8
|
-
response.headers["Content-Type"].
|
8
|
+
expect(response.headers["Content-Type"]).to eq('image/gif')
|
9
9
|
end
|
10
10
|
|
11
11
|
it "logs the hit" do
|
12
12
|
@request.env['HTTP_USER_AGENT'] = 'FeedBurner/1.0'
|
13
|
-
@request.
|
14
|
-
@request.
|
13
|
+
allow(@request).to receive(:remote_ip).and_return('234.101.82.14')
|
14
|
+
allow(@request).to receive(:session_options).and_return({ :id => 'abcd' })
|
15
15
|
|
16
16
|
get :new, :url => '/posts', :user_id => 7, :format => 'gif'
|
17
17
|
|
18
|
-
Notches::Hit.count.
|
18
|
+
expect(Notches::Hit.count).to eq(1)
|
19
19
|
hit = Notches::Hit.first
|
20
|
-
hit.url.url.
|
21
|
-
hit.user_agent.user_agent.
|
22
|
-
hit.ip.ip.
|
23
|
-
hit.session.session_id.
|
24
|
-
Notches::UserSession.exists?(notches_session_id: hit.session.id, user_id: 7).
|
20
|
+
expect(hit.url.url).to eq('/posts')
|
21
|
+
expect(hit.user_agent.user_agent).to eq('FeedBurner/1.0')
|
22
|
+
expect(hit.ip.ip).to eq('234.101.82.14')
|
23
|
+
expect(hit.session.session_id).to eq('abcd')
|
24
|
+
expect(Notches::UserSession.exists?(notches_session_id: hit.session.id, user_id: 7)).to eq(true)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Notches::Event do
|
4
|
+
describe "validations" do
|
5
|
+
let(:event) do
|
6
|
+
Notches::Event.new(
|
7
|
+
name: Notches::Name.new(name: 'An important event'),
|
8
|
+
scope: Notches::Scope.new(scope: 'An important person')
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "valid with valid attributes" do
|
13
|
+
expect(event).to be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it "requires a name" do
|
17
|
+
event.name = nil
|
18
|
+
event.valid?
|
19
|
+
expect(event.errors[:name]).to eq(["can't be blank"])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not require a scope" do
|
23
|
+
event.scope = nil
|
24
|
+
event.valid?
|
25
|
+
expect(event).to be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "does not validate if its Name's name is blank" do
|
29
|
+
event.name.name = nil
|
30
|
+
event.valid?
|
31
|
+
expect(event.errors[:name]).to eq(["is invalid"])
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not validate if it has a Scope but it's invalid" do
|
35
|
+
event.scope.scope = nil
|
36
|
+
event.valid?
|
37
|
+
expect(event.errors[:scope]).to eq(["is invalid"])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".log" do
|
42
|
+
|
43
|
+
context "with valid attributes" do
|
44
|
+
let(:now) { Time.zone.now }
|
45
|
+
before do
|
46
|
+
allow(Time).to receive_message_chain(:zone, :now).and_return(now)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "creates a event for today and current time with those attributes" do
|
50
|
+
Notches::Event.log(name: "An important event")
|
51
|
+
event = Notches::Event.first
|
52
|
+
expect(event).to be_present
|
53
|
+
expect(event.name.name).to eq("An important event")
|
54
|
+
expect(event.scope).to be_nil
|
55
|
+
expect(event.date.date).to eq(now.to_date)
|
56
|
+
expect(event.time.time.strftime('%H:%M:%S')).to eq(now.strftime('%H:%M:%S'))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:existing_event) {
|
61
|
+
Notches::Event.log(
|
62
|
+
name: "An important event",
|
63
|
+
scope: "An important person"
|
64
|
+
)
|
65
|
+
}
|
66
|
+
|
67
|
+
it "does not create a new Name record if there's a record for that Name already" do
|
68
|
+
event = Notches::Event.log(name: "An important event")
|
69
|
+
expect(event.name.id).to eq(existing_event.name.id)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "does not create a new Scope record if there's a record for that Scope already" do
|
73
|
+
event = Notches::Event.log(
|
74
|
+
name: "An important event",
|
75
|
+
scope: "An important person"
|
76
|
+
)
|
77
|
+
expect(event.scope.id).to eq(existing_event.scope.id)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "does not create a new Date record there's a record for that Date already" do
|
81
|
+
event = Notches::Event.log(name: "Another important event")
|
82
|
+
expect(event.date.id).to eq(existing_event.date.id)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "does not create a new Time record if there's a record for that Time already even if date was different" do
|
86
|
+
existing_event.time.update_attributes!(time: Time.parse('2016-08-03 14:15:59 UTC'))
|
87
|
+
allow(Time).to receive_message_chain(:zone, :now).and_return(Time.parse('2016-08-04 14:15:59 UTC'))
|
88
|
+
event = Notches::Event.log(name: "Another important event")
|
89
|
+
expect(event.time.id).to eq(existing_event.time.id)
|
90
|
+
end
|
91
|
+
|
92
|
+
context "a event with the same name, scope, date and time exists already" do
|
93
|
+
it "does not log the event" do
|
94
|
+
allow(Time).to receive_message_chain(:zone, :now).and_return(existing_event.time.time)
|
95
|
+
expect {
|
96
|
+
event = Notches::Event.log(
|
97
|
+
name: "An important event",
|
98
|
+
scope: "An important person"
|
99
|
+
)
|
100
|
+
}.to_not change { Notches::Event.count }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -10,49 +10,53 @@ describe Notches::Hit do
|
|
10
10
|
)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
hit.
|
13
|
+
it "valid with valid attributes" do
|
14
|
+
expect(hit).to be_valid
|
15
15
|
end
|
16
16
|
|
17
17
|
it "requires an ip" do
|
18
18
|
hit.ip = nil
|
19
|
-
hit.
|
19
|
+
hit.valid?
|
20
|
+
expect(hit.errors[:ip]).to eq(["can't be blank"])
|
20
21
|
end
|
21
22
|
|
22
23
|
it "requires a session" do
|
23
24
|
hit.session = nil
|
24
|
-
hit.
|
25
|
+
hit.valid?
|
26
|
+
expect(hit.errors[:session]).to eq(["can't be blank"])
|
25
27
|
end
|
26
28
|
|
27
|
-
it "requires a " do
|
29
|
+
it "requires a url" do
|
28
30
|
hit.url = nil
|
29
|
-
hit.
|
31
|
+
hit.valid?
|
32
|
+
expect(hit.errors[:url]).to eq(["can't be blank"])
|
30
33
|
end
|
31
34
|
|
32
35
|
it "does not validate if its IP's ip blank" do
|
33
|
-
hit.ip = Notches::IP.new(:ip =>
|
34
|
-
hit.
|
36
|
+
hit.ip = Notches::IP.new(:ip => "")
|
37
|
+
hit.valid?
|
38
|
+
expect(hit.errors[:ip]).to eq(["is invalid"])
|
35
39
|
end
|
36
40
|
|
37
41
|
it "does not validate if its Session's session_id is blank" do
|
38
42
|
hit.session = Notches::Session.new(:session_id => '')
|
39
|
-
hit.
|
43
|
+
hit.valid?
|
44
|
+
expect(hit.errors[:session]).to eq(["is invalid"])
|
40
45
|
end
|
41
46
|
|
42
47
|
it "does not validate if its URL's url is blank" do
|
43
48
|
hit.url = Notches::URL.new(:url => '')
|
44
|
-
hit.
|
49
|
+
hit.valid?
|
50
|
+
expect(hit.errors[:url]).to eq(["is invalid"])
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
48
54
|
describe ".log" do
|
49
55
|
|
50
56
|
context "with valid attributes" do
|
51
|
-
let(:
|
52
|
-
let(:now) { Time.now }
|
57
|
+
let(:now) { Time.zone.now }
|
53
58
|
before do
|
54
|
-
|
55
|
-
Time.stub(:now => now)
|
59
|
+
allow(Time).to receive_message_chain(:zone, :now).and_return(now)
|
56
60
|
end
|
57
61
|
|
58
62
|
it "creates a hit for today and current time with those attributes" do
|
@@ -63,14 +67,14 @@ describe Notches::Hit do
|
|
63
67
|
:ip => '0.0.0.1'
|
64
68
|
})
|
65
69
|
hit = Notches::Hit.first
|
66
|
-
hit.
|
67
|
-
hit.url.url.
|
68
|
-
hit.session.session_id.
|
69
|
-
hit.ip.ip.
|
70
|
-
hit.date.date.
|
71
|
-
hit.time.time.strftime('%H:%M:%S').
|
72
|
-
hit.user_agent.user_agent.
|
73
|
-
hit.user_agent.user_agent_md5.
|
70
|
+
expect(hit).to be_present
|
71
|
+
expect(hit.url.url).to eq('/posts')
|
72
|
+
expect(hit.session.session_id).to eq('1')
|
73
|
+
expect(hit.ip.ip).to eq('0.0.0.1')
|
74
|
+
expect(hit.date.date).to eq(now.to_date)
|
75
|
+
expect(hit.time.time.strftime('%H:%M:%S')).to eq(now.strftime('%H:%M:%S'))
|
76
|
+
expect(hit.user_agent.user_agent).to eq('FeedBurner/1.0')
|
77
|
+
expect(hit.user_agent.user_agent_md5).to eq(Digest::MD5.hexdigest('FeedBurner/1.0'))
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
@@ -89,7 +93,7 @@ describe Notches::Hit do
|
|
89
93
|
:session_id => '2',
|
90
94
|
:ip => existing_hit.ip.ip
|
91
95
|
)
|
92
|
-
hit.ip.id.
|
96
|
+
expect(hit.ip.id).to eq(existing_hit.ip.id)
|
93
97
|
end
|
94
98
|
|
95
99
|
it "does not create a new URL record if there's a record for that URL already" do
|
@@ -98,7 +102,7 @@ describe Notches::Hit do
|
|
98
102
|
:session_id => '2',
|
99
103
|
:ip => '0.0.0.2'
|
100
104
|
)
|
101
|
-
hit.url.id.
|
105
|
+
expect(hit.url.id).to eq(existing_hit.url.id)
|
102
106
|
end
|
103
107
|
|
104
108
|
it "does not create a new Session record there's a record for that session id already" do
|
@@ -107,7 +111,7 @@ describe Notches::Hit do
|
|
107
111
|
:session_id => existing_hit.session.session_id,
|
108
112
|
:ip => '0.0.0.2'
|
109
113
|
)
|
110
|
-
hit.session.id.
|
114
|
+
expect(hit.session.id).to eq(existing_hit.session.id)
|
111
115
|
end
|
112
116
|
|
113
117
|
it "does not create a new Date record there's a record for that Date already" do
|
@@ -116,17 +120,18 @@ describe Notches::Hit do
|
|
116
120
|
:session_id => '2',
|
117
121
|
:ip => '0.0.0.2'
|
118
122
|
)
|
119
|
-
hit.date.id.
|
123
|
+
expect(hit.date.id).to eq(existing_hit.date.id)
|
120
124
|
end
|
121
125
|
|
122
|
-
it "does not create a new Time record there's a record for that Time already" do
|
123
|
-
Time.
|
126
|
+
it "does not create a new Time record if there's a record for that Time already even if date was different" do
|
127
|
+
existing_hit.time.update_attributes!(time: Time.parse('2016-08-03 14:15:59 UTC'))
|
128
|
+
allow(Time).to receive(:now).and_return(Time.parse('2016-08-04 14:15:59 UTC'))
|
124
129
|
hit = Notches::Hit.log(
|
125
130
|
:url => '/posts/2',
|
126
131
|
:session_id => '2',
|
127
132
|
:ip => '0.0.0.2'
|
128
133
|
)
|
129
|
-
hit.time.id.
|
134
|
+
expect(hit.time.id).to eq(existing_hit.time.id)
|
130
135
|
end
|
131
136
|
|
132
137
|
it "does not create a new UserAgent record if there's a record for that UserAgent already" do
|
@@ -136,13 +141,12 @@ describe Notches::Hit do
|
|
136
141
|
:session_id => '2',
|
137
142
|
:ip => '0.0.0.2'
|
138
143
|
)
|
139
|
-
hit.user_agent.id.
|
144
|
+
expect(hit.user_agent.id).to eq(existing_hit.user_agent.id)
|
140
145
|
end
|
141
146
|
|
142
147
|
context "a hit with the same url, session, ip, date and time exists already" do
|
143
148
|
it "does not log the hit" do
|
144
|
-
|
145
|
-
Time.stub(:now => existing_hit.time.time)
|
149
|
+
allow(Time).to receive_message_chain(:zone, :now).and_return(existing_hit.time.time)
|
146
150
|
expect {
|
147
151
|
hit = Notches::Hit.log(
|
148
152
|
:url => existing_hit.url.url,
|
@@ -163,7 +167,7 @@ describe Notches::Hit do
|
|
163
167
|
:session_id => '1',
|
164
168
|
:ip => '0.0.0.1'
|
165
169
|
})
|
166
|
-
Notches::UserSession.exists?(notches_session_id: hit.session.id, user_id: 7).
|
170
|
+
expect(Notches::UserSession.exists?(notches_session_id: hit.session.id, user_id: 7)).to eq(true)
|
167
171
|
end
|
168
172
|
end
|
169
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notches
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cillian O'Ruanaidh
|
@@ -9,64 +9,64 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
prerelease: false
|
16
|
-
version_requirements: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '4.0'
|
21
15
|
name: rails
|
22
16
|
requirement: !ruby/object:Gem::Requirement
|
23
17
|
requirements:
|
24
|
-
- -
|
18
|
+
- - ">="
|
25
19
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
20
|
+
version: '4.1'
|
27
21
|
type: :runtime
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
22
|
prerelease: false
|
30
23
|
version_requirements: !ruby/object:Gem::Requirement
|
31
24
|
requirements:
|
32
|
-
- -
|
25
|
+
- - ">="
|
33
26
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
27
|
+
version: '4.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
35
29
|
name: combustion
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|
37
31
|
requirements:
|
38
|
-
- - ~>
|
32
|
+
- - "~>"
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.5.
|
34
|
+
version: 0.5.5
|
41
35
|
type: :development
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
36
|
prerelease: false
|
44
37
|
version_requirements: !ruby/object:Gem::Requirement
|
45
38
|
requirements:
|
46
|
-
- - ~>
|
39
|
+
- - "~>"
|
47
40
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
41
|
+
version: 0.5.5
|
42
|
+
- !ruby/object:Gem::Dependency
|
49
43
|
name: rspec-rails
|
50
44
|
requirement: !ruby/object:Gem::Requirement
|
51
45
|
requirements:
|
52
|
-
- - ~>
|
46
|
+
- - "~>"
|
53
47
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
48
|
+
version: 3.4.2
|
55
49
|
type: :development
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
50
|
prerelease: false
|
58
51
|
version_requirements: !ruby/object:Gem::Requirement
|
59
52
|
requirements:
|
60
|
-
- - ~>
|
53
|
+
- - "~>"
|
61
54
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
55
|
+
version: 3.4.2
|
56
|
+
- !ruby/object:Gem::Dependency
|
63
57
|
name: sqlite3
|
64
58
|
requirement: !ruby/object:Gem::Requirement
|
65
59
|
requirements:
|
66
|
-
- - ~>
|
60
|
+
- - "~>"
|
67
61
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.3.
|
62
|
+
version: 1.3.11
|
69
63
|
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.3.11
|
70
70
|
description: A Rails Engine for tracking your web traffic.
|
71
71
|
email:
|
72
72
|
- contact@cilliano.com
|
@@ -74,7 +74,7 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
78
78
|
- Gemfile
|
79
79
|
- HISTORY
|
80
80
|
- LICENSE
|
@@ -83,8 +83,11 @@ files:
|
|
83
83
|
- app/assets/images/notches/hit.gif
|
84
84
|
- app/controllers/notches/hits_controller.rb
|
85
85
|
- app/models/notches/date.rb
|
86
|
+
- app/models/notches/event.rb
|
86
87
|
- app/models/notches/hit.rb
|
87
88
|
- app/models/notches/ip.rb
|
89
|
+
- app/models/notches/name.rb
|
90
|
+
- app/models/notches/scope.rb
|
88
91
|
- app/models/notches/session.rb
|
89
92
|
- app/models/notches/time.rb
|
90
93
|
- app/models/notches/url.rb
|
@@ -96,6 +99,7 @@ files:
|
|
96
99
|
- db/migrate/20120713142636_create_notches_user_agents.rb
|
97
100
|
- db/migrate/20120910093652_add_index_to_user_agents.rb
|
98
101
|
- db/migrate/20130918115023_create_notches_user_sessions.rb
|
102
|
+
- db/migrate/20160804111320_create_notches_events.rb
|
99
103
|
- lib/notches.rb
|
100
104
|
- lib/notches/engine.rb
|
101
105
|
- lib/notches/version.rb
|
@@ -106,6 +110,7 @@ files:
|
|
106
110
|
- spec/internal/db/schema.rb
|
107
111
|
- spec/internal/log/.gitignore
|
108
112
|
- spec/internal/public/favicon.ico
|
113
|
+
- spec/models/notches/event_spec.rb
|
109
114
|
- spec/models/notches/hit_spec.rb
|
110
115
|
- spec/spec_helper.rb
|
111
116
|
homepage: http://github.com/hypertiny/notches
|
@@ -117,26 +122,18 @@ require_paths:
|
|
117
122
|
- lib
|
118
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
124
|
requirements:
|
120
|
-
- -
|
125
|
+
- - ">="
|
121
126
|
- !ruby/object:Gem::Version
|
122
127
|
version: '0'
|
123
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
129
|
requirements:
|
125
|
-
- -
|
130
|
+
- - ">="
|
126
131
|
- !ruby/object:Gem::Version
|
127
132
|
version: '0'
|
128
133
|
requirements: []
|
129
134
|
rubyforge_project: notches
|
130
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.5.1
|
131
136
|
signing_key:
|
132
137
|
specification_version: 4
|
133
138
|
summary: Simple Rails web traffic counter
|
134
|
-
test_files:
|
135
|
-
- spec/controllers/notches/hits_controller_spec.rb
|
136
|
-
- spec/internal/config/database.yml
|
137
|
-
- spec/internal/config/routes.rb
|
138
|
-
- spec/internal/db/schema.rb
|
139
|
-
- spec/internal/log/.gitignore
|
140
|
-
- spec/internal/public/favicon.ico
|
141
|
-
- spec/models/notches/hit_spec.rb
|
142
|
-
- spec/spec_helper.rb
|
139
|
+
test_files: []
|