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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77fe32e3f3573eee145dbc117db77870636488db
4
- data.tar.gz: 5653b56f9e30cc83ab460ce4ebe14581aea1f0a5
3
+ metadata.gz: 2ba9ef405e0268bd6e6c4f49f5af548c64b99489
4
+ data.tar.gz: b23558b98793b625a57c55b14cbcded8c681f136
5
5
  SHA512:
6
- metadata.gz: f30282672dfe4b2d8a848f571b6926640433e6131cdc744cd4b73b9c5ff63fd273467b2c0660bf49cb8401ff3223bac7871fa72ce7ac1af46938a4ae2eb0b824
7
- data.tar.gz: be7b5e08610b3def60b450177dd12aec65b65e1cb9357b062599d760a1c3d0693a09e497d5fec4f2007e8904dcdda55ee29510d1ef1e8cb670886d1b07ff34d1
6
+ metadata.gz: 20b79abe821d51b958b217d28b447476ccb0cf85bb7bf0edf8ede971f68981533c42469341507dd1131f5718ca7deb5239d4549ec0b372cf001605afe5ae1968
7
+ data.tar.gz: 2ecc6417699a4ad0059b15d685df29e9586ce8d6c5f158ccbaf770c84ceab5f06ac8bfb8b7e54ef02155f9a435e74db05e3189311cb95e335220a34cf0bfaff5
@@ -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
@@ -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
- before_filter { |c| c.impressionist_subapp_filter(opts) }
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
- base.before_filter :impressionist_app_filter
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)
@@ -8,7 +8,7 @@ module Impressionist
8
8
  DEFAULT_CACHE ||= {
9
9
  :counter_cache => false,
10
10
  :column_name => :impressions_count,
11
- :unique => false
11
+ :unique => :all
12
12
  }
13
13
 
14
14
  def impressionist_counter_cache_options
@@ -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'
@@ -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'
@@ -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
 
@@ -15,9 +15,9 @@ module Impressionist
15
15
  def define_association
16
16
  has_many(:impressions,
17
17
  :as => :impressionable,
18
- :dependent => :destroy)
18
+ :dependent => :delete_all)
19
19
  end
20
20
  end
21
-
21
+
22
22
  end
23
23
  end
@@ -9,7 +9,7 @@ module Impressionist
9
9
  def is_impressionable(options={})
10
10
  many(:impressions,
11
11
  :as => :impressionable,
12
- :dependent => :destroy)
12
+ :dependent => :delete_all)
13
13
 
14
14
  @impressionist_cache_options = options
15
15
  end
@@ -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
- Symbol === unique ?
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
@@ -1,3 +1,3 @@
1
1
  module Impressionist
2
- VERSION = "1.5.2"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.2'
4
+ gem 'rake', '< 11.0'
5
+ gem 'public_suffix', '< 1.5.0'
4
6
 
5
7
  gem 'impressionist', :path => '../../'
6
8
 
@@ -1,8 +1,12 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
- before_filter :secondary_before_filter
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 secondary_before_filter
6
- @test_secondary_before_filter = "this is a test"
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
- before_filter :test_current_user_var
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 before_filter method)" do
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 before_filter method in ApplicationController" do
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 => :destroy
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.destroyed?.should be_true
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.5.2
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: 2016-09-16 00:00:00.000000000 Z
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.6'
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.6'
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