impressionist 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/CHANGELOG.rdoc +11 -0
- data/README.md +11 -6
- data/app/controllers/impressionist_controller.rb +11 -3
- data/app/models/impressionist/impressionable.rb +1 -1
- data/gemfiles/rails32.gemfile +2 -1
- data/gemfiles/rails40.gemfile +2 -1
- data/impressionist.gemspec +1 -1
- data/lib/generators/active_record/templates/create_impressions_table.rb +1 -1
- data/lib/impressionist/is_impressionable.rb +2 -2
- data/lib/impressionist/models/mongo_mapper/impressionist/impressionable.rb +1 -1
- data/lib/impressionist/update_counters.rb +11 -3
- data/lib/impressionist/version.rb +1 -1
- data/tests/test_app/Gemfile +2 -0
- data/tests/test_app/app/controllers/application_controller.rb +7 -3
- data/tests/test_app/app/controllers/articles_controller.rb +5 -1
- data/tests/test_app/spec/controllers/articles_controller_spec.rb +1 -3
- data/tests/test_app/spec/initializers/initializers_spec.rb +1 -1
- data/tests/test_app/spec/models/model_spec.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ba9ef405e0268bd6e6c4f49f5af548c64b99489
|
4
|
+
data.tar.gz: b23558b98793b625a57c55b14cbcded8c681f136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20b79abe821d51b958b217d28b447476ccb0cf85bb7bf0edf8ede971f68981533c42469341507dd1131f5718ca7deb5239d4549ec0b372cf001605afe5ae1968
|
7
|
+
data.tar.gz: 2ecc6417699a4ad0059b15d685df29e9586ce8d6c5f158ccbaf770c84ceab5f06ac8bfb8b7e54ef02155f9a435e74db05e3189311cb95e335220a34cf0bfaff5
|
data/.travis.yml
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
language: ruby
|
2
|
+
before_install:
|
3
|
+
- gem install bundler
|
2
4
|
before_script:
|
3
5
|
- cd tests/test_app
|
4
6
|
- bundle exec rails g impressionist -f
|
5
7
|
- bundle exec rake db:create db:migrate RAILS_ENV=test
|
6
8
|
- cd ..
|
9
|
+
script:
|
10
|
+
- bundle exec rake
|
7
11
|
rvm:
|
8
12
|
- 1.9.3
|
9
13
|
- 2.0.0
|
14
|
+
- 2.1.0
|
15
|
+
- 2.2.0
|
16
|
+
- 2.3.0
|
10
17
|
- jruby-head
|
11
18
|
- rbx
|
12
19
|
- ruby-head
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.6.0 (2016-09-16)
|
2
|
+
* Documentation example for counter_cache (#239, @fwolfst)
|
3
|
+
* Green Travis CI builds (#238, @jgrau)
|
4
|
+
* Rails 5.1 support (#241, @msimonborg)
|
5
|
+
* Use `dependent: :delete_all` instead of `:destroy` for performance gains (#242, @midnightSuyama & @jgrau)
|
6
|
+
* Fix counter cache not updating when no `unique` option is set (#243, @sachiotomita & @jgrau)
|
7
|
+
|
8
|
+
== 1.5.2 (2016-09-16)
|
9
|
+
|
10
|
+
== 1.5.1 (2013-12-31)
|
11
|
+
|
1
12
|
== 1.5.0 (2013-12-30)
|
2
13
|
* Added message filtering.
|
3
14
|
* (@overovermind)
|
data/README.md
CHANGED
@@ -91,9 +91,10 @@ Usage
|
|
91
91
|
controller if you are using this method. If you add "impressionist" to the
|
92
92
|
top of your controller and also use this method in your action, it will
|
93
93
|
result in 2 impressions being logged (but associated with one request_hash).
|
94
|
-
If you're using [friendly_id](https://github.com/norman/friendly_id) be sure
|
95
|
-
to log impressionist this way, as params[:id] will return a string(url slug)
|
96
|
-
while impressionable_id is a Integer column in database.
|
94
|
+
If you're using [friendly_id](https://github.com/norman/friendly_id) be sure
|
95
|
+
to log impressionist this way, as params[:id] will return a string(url slug)
|
96
|
+
while impressionable_id is a Integer column in database. Also note that you
|
97
|
+
have to take step #3 for the Widget model for this to work.
|
97
98
|
|
98
99
|
def show
|
99
100
|
@widget = Widget.find
|
@@ -119,7 +120,7 @@ Usage
|
|
119
120
|
in turn will give you impressions with unique params.
|
120
121
|
|
121
122
|
@widget.impressionist_count(:filter => :params)
|
122
|
-
|
123
|
+
|
123
124
|
8. Get the unique impression count from a model filtered by session hash. Same
|
124
125
|
as #6 regarding request hash. This may be more desirable than filtering by
|
125
126
|
IP address depending on your situation, since filtering by IP may ignore
|
@@ -138,7 +139,7 @@ Usage
|
|
138
139
|
@widget.impressionist_count(:message=>"pageview", :filter=>:all)
|
139
140
|
|
140
141
|
Logging impressions for authenticated users happens automatically. If you have
|
141
|
-
a current_user helper or use @current_user in your before_filter to set your
|
142
|
+
a current_user helper or use @current_user in your before_filter (or before_action in Rails >= 5.0) to set your
|
142
143
|
authenticated user, current_user.id will be written to the user_id field in the
|
143
144
|
impressions table.
|
144
145
|
|
@@ -174,6 +175,10 @@ It is as simple as this:
|
|
174
175
|
|
175
176
|
t.integer :my_column_name, :default => 0
|
176
177
|
|
178
|
+
If you want to use the typical Rails 4 migration generator, you can:
|
179
|
+
|
180
|
+
rails g migration AddImpressionsCountToBook impressions_count:int
|
181
|
+
|
177
182
|
What if I only want to record unique impressions?
|
178
183
|
-------------------------------------------------
|
179
184
|
Maybe you only care about unique impressions and would like to avoid
|
@@ -188,7 +193,7 @@ impressions in your controller:
|
|
188
193
|
|
189
194
|
# only record impression if session is unique
|
190
195
|
impressionist :unique => [:session_hash]
|
191
|
-
|
196
|
+
|
192
197
|
# only record impression if param is unique
|
193
198
|
impressionist :unique => [:params]
|
194
199
|
|
@@ -3,13 +3,21 @@ require 'digest/sha2'
|
|
3
3
|
module ImpressionistController
|
4
4
|
module ClassMethods
|
5
5
|
def impressionist(opts={})
|
6
|
-
|
6
|
+
if Rails::VERSION::MAJOR >= 5
|
7
|
+
before_action { |c| c.impressionist_subapp_filter(opts) }
|
8
|
+
else
|
9
|
+
before_filter { |c| c.impressionist_subapp_filter(opts) }
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
10
14
|
module InstanceMethods
|
11
15
|
def self.included(base)
|
12
|
-
|
16
|
+
if Rails::VERSION::MAJOR >= 5
|
17
|
+
base.before_action :impressionist_app_filter
|
18
|
+
else
|
19
|
+
base.before_filter :impressionist_app_filter
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
def impressionist(obj,message=nil,opts={})
|
@@ -103,7 +111,7 @@ module ImpressionistController
|
|
103
111
|
request_param = params_hash
|
104
112
|
impressions.detect{|impression| impression.params == request_param }.nil?
|
105
113
|
end
|
106
|
-
|
114
|
+
|
107
115
|
# creates the query to check for uniqueness
|
108
116
|
def unique_query(unique_opts,impressionable=nil)
|
109
117
|
full_statement = direct_create_statement({},impressionable)
|
data/gemfiles/rails32.gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rake', '>= 0.9'
|
3
|
+
gem 'rake', '>= 0.9', '< 11.0'
|
4
4
|
gem 'rdoc', '>= 2.4.2'
|
5
5
|
|
6
6
|
platforms :jruby do
|
@@ -14,6 +14,7 @@ platforms :ruby, :mswin, :mingw do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
group :test do
|
17
|
+
gem 'public_suffix', '< 1.5.0'
|
17
18
|
gem 'capybara', '>= 2.0.3'
|
18
19
|
gem 'minitest'
|
19
20
|
gem 'minitest-rails'
|
data/gemfiles/rails40.gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rake', '>= 0.9'
|
3
|
+
gem 'rake', '>= 0.9', '< 11.0'
|
4
4
|
gem 'rdoc', '>= 2.4.2'
|
5
5
|
|
6
6
|
platforms :jruby do
|
@@ -14,6 +14,7 @@ platforms :ruby, :mswin, :mingw do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
group :test do
|
17
|
+
gem 'public_suffix', '< 1.5.0'
|
17
18
|
gem 'capybara', '>= 2.0.3'
|
18
19
|
gem 'minitest'
|
19
20
|
gem 'minitest-rails'
|
data/impressionist.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.require_path = 'lib'
|
19
19
|
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
20
20
|
|
21
|
-
s.add_dependency 'nokogiri', '~> 1.6'
|
21
|
+
s.add_dependency 'nokogiri', RUBY_VERSION < '2.1.0' ? '~> 1.6.0' : '~> 1'
|
22
22
|
s.add_development_dependency 'bundler', '~> 1.0'
|
23
23
|
end
|
@@ -22,7 +22,7 @@ class CreateImpressionsTable < ActiveRecord::Migration
|
|
22
22
|
add_index :impressions, [:controller_name,:action_name,:request_hash], :name => "controlleraction_request_index", :unique => false
|
23
23
|
add_index :impressions, [:controller_name,:action_name,:ip_address], :name => "controlleraction_ip_index", :unique => false
|
24
24
|
add_index :impressions, [:controller_name,:action_name,:session_hash], :name => "controlleraction_session_index", :unique => false
|
25
|
-
add_index :impressions, [:impressionable_type, :impressionable_id, :params], :name => "poly_params_request_index", :unique => false
|
25
|
+
add_index :impressions, [:impressionable_type, :impressionable_id, :params], :name => "poly_params_request_index", :unique => false, :length => {:params => 255 }
|
26
26
|
add_index :impressions, :user_id
|
27
27
|
end
|
28
28
|
|
@@ -42,9 +42,17 @@ module Impressionist
|
|
42
42
|
# is_impressionable :counter_cache => true,
|
43
43
|
# :unique => :any_other_filter
|
44
44
|
def unique_filter
|
45
|
-
|
46
|
-
unique
|
47
|
-
:ip_address
|
45
|
+
# Support `is_impressionable :counter_cache => true, :unique => true`
|
46
|
+
# defaulting to `:ip_address` for counting unique impressions.
|
47
|
+
return :ip_address if unique == true
|
48
|
+
|
49
|
+
# Should a user try `is_impressionable :counter_cache => true, :unique => false`
|
50
|
+
# then support that as well
|
51
|
+
return :all if unique == false
|
52
|
+
|
53
|
+
# Otherwise set the filter to either what the user supplied as the `unique` option
|
54
|
+
# or the default (`:all`)
|
55
|
+
unique
|
48
56
|
end
|
49
57
|
|
50
58
|
def unique
|
data/tests/test_app/Gemfile
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
class ApplicationController < ActionController::Base
|
2
2
|
protect_from_forgery
|
3
|
-
|
3
|
+
if Rails::VERSION::MAJOR >= 5
|
4
|
+
before_action :secondary_before_action
|
5
|
+
else
|
6
|
+
before_filter :secondary_before_action
|
7
|
+
end
|
4
8
|
|
5
|
-
def
|
6
|
-
@
|
9
|
+
def secondary_before_action
|
10
|
+
@test_secondary_before_action = "this is a test"
|
7
11
|
end
|
8
12
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
class ArticlesController < ApplicationController
|
2
|
-
|
2
|
+
if Rails::VERSION::MAJOR >= 5
|
3
|
+
before_action :test_current_user_var
|
4
|
+
else
|
5
|
+
before_filter :test_current_user_var
|
6
|
+
end
|
3
7
|
|
4
8
|
def test_current_user_var
|
5
9
|
if session[:user_id]
|
@@ -26,7 +26,7 @@ describe ArticlesController do
|
|
26
26
|
Article.first.impressions.last.action_name.should eq "show"
|
27
27
|
end
|
28
28
|
|
29
|
-
it "should log the user_id if user is authenticated (@current_user
|
29
|
+
it "should log the user_id if user is authenticated (@current_user before_action method)" do
|
30
30
|
session[:user_id] = 123
|
31
31
|
get "show", :id=> 1
|
32
32
|
Article.first.impressions.last.user_id.should eq 123
|
@@ -72,5 +72,3 @@ describe ArticlesController do
|
|
72
72
|
Impression.last.referrer.should eq nil
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
76
|
-
|
@@ -13,7 +13,7 @@ describe Impressionist do
|
|
13
13
|
expect(ApplicationController).to respond_to(method)
|
14
14
|
end
|
15
15
|
|
16
|
-
it "should include the
|
16
|
+
it "should include the before_action method in ApplicationController" do
|
17
17
|
filters = ApplicationController._process_action_callbacks.select { |c| c.kind == :before }
|
18
18
|
filters.collect{|filter|filter.filter}.include?(:impressionist_app_filter).should be_true
|
19
19
|
end
|
@@ -57,14 +57,14 @@ describe Impression do
|
|
57
57
|
@article.impressionist_count(:filter=>:session_hash).should eq 7
|
58
58
|
end
|
59
59
|
|
60
|
-
# tests :dependent => :
|
60
|
+
# tests :dependent => :delete_all
|
61
61
|
it "should delete impressions on deletion of impressionable" do
|
62
62
|
#impressions_count = Impression.all.size
|
63
63
|
a = Article.create
|
64
64
|
i = a.impressions.create
|
65
65
|
a.destroy
|
66
66
|
a.destroyed?.should be_true
|
67
|
-
i.
|
67
|
+
Impression.exists?(i.id).should be_false
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: impressionist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johnmcaliley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
version: 1.3.6
|
208
208
|
requirements: []
|
209
209
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.4.5
|
210
|
+
rubygems_version: 2.4.5.1
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: Easy way to log impressions
|