impressionist 1.4.0 → 1.4.1

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: 565d11269849faecb7c83d6cda308c6c1e9eba4c
4
- data.tar.gz: ed373d6474fee728c3742b0d475ad5d425f9902e
3
+ metadata.gz: 7c1694b326962e72ed2f57841cb4bc799e1a8e4d
4
+ data.tar.gz: 35b5e4aa5feff7df8341022ec6b4195d35a7df18
5
5
  SHA512:
6
- metadata.gz: 8a4160978bf2c001b1c8f2ea24f18bc563d3cd821de5294de0f5b2da8f1c87e8e3a7c2f0c210bd7420b8a7c216383f23ffb61875bac3930475dd163f90f6a5c6
7
- data.tar.gz: bc2f41f6556664349216614eec6fdc9d366f40ac0e5fbd5bcbc1eab2fd470897104581f2b19ae31267067273a49a59693edff525a6c6c34596a8c00573932f65
6
+ metadata.gz: af17886e092d7fd62bbf70c768cb4b804f3087559f12fa2d2d68ee12f3ca6d859bcf7954790957094310ff76ed7376ae25707638779cbe0d894fd00191a5532b
7
+ data.tar.gz: 828a4f2a95741643e28e1ba943515fa9e715cee6a907f62b1a93950630433f27602b208a49f4d0c597d39818a09db9f1fd041c751080f4546926c7f141141e17
@@ -19,8 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
20
20
 
21
21
  s.add_dependency 'httpclient', '~> 2.2'
22
- s.add_dependency 'nokogiri', '~> 1.5'
23
- s.add_development_dependency 'capybara'
22
+
23
+ # Nokogiri has dropped support for Ruby 1.8.7 onwards version 1.5.10
24
+ s.add_dependency 'nokogiri', (RUBY_VERSION.match("1.8.7") ? '1.5.10' : '~> 1.6.0')
25
+
26
+ # Capybara has dropped support for Ruby 1.8.7 onwards version 2.0.3
27
+ s.add_development_dependency 'capybara', '>= 2.0.3'
24
28
  s.add_development_dependency 'rake', '>= 0.9'
25
29
  s.add_development_dependency 'rails', '~> 3.1'
26
30
  s.add_development_dependency 'rdoc', '>= 2.4.2'
@@ -42,8 +42,10 @@ module Impressionist
42
42
  end
43
43
 
44
44
  # Logs to log file, expects a message to be passed
45
+
45
46
  # default mode is ERROR
46
- def impressionist_log(mode=:error, str)
47
+ # ruby 1.8.7 support
48
+ def impressionist_log(str, mode=:error)
47
49
  Rails.logger.send(mode.to_s, str)
48
50
  end
49
51
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  class Impression < ActiveRecord::Base
8
8
  include Impressionist::CounterCache
9
- include Impressionist::SetUpAssociation
9
+ include Impressionist::SetUpAssociation
10
10
 
11
11
  after_save :impressionable_counter_cache_updatable?
12
12
 
@@ -2,25 +2,23 @@ ActiveRecord::Base.send(:include, Impressionist::Impressionable)
2
2
 
3
3
  module Impressionist
4
4
  module Impressionable
5
-
6
5
  extend ActiveSupport::Concern
7
6
 
8
7
  module ClassMethods
8
+
9
9
  def is_impressionable(options={})
10
10
  define_association
11
- imp_cache_options_set(options)
11
+
12
+ @impressionist_cache_options = options
12
13
  end
13
14
 
15
+ private
14
16
  def define_association
15
17
  has_many(:impressions,
16
18
  :as => :impressionable,
17
19
  :dependent => :destroy)
18
20
  end
19
21
 
20
- def imp_cache_options_set(options)
21
- @impressionist_cache_options = options
22
- end
23
-
24
22
  end
25
23
 
26
24
  end
@@ -5,10 +5,17 @@ module Impressionist
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  module ClassMethods
8
- def is_impressionable(options={})
9
- many :impressions, :as => :impressionable, :dependent => :destroy
10
- @cache_options = options[:counter_cache]
11
- end
8
+
9
+ def is_impressionable(options={})
10
+ many(:impressions,
11
+ :as => :impressionable,
12
+ :dependent => :destroy)
13
+
14
+ @impressionist_cache_options = options
15
+ end
16
+
12
17
  end
18
+
13
19
  end
20
+
14
21
  end
@@ -1,3 +1,5 @@
1
+ # TODO: Refactor this Entity
2
+ # There's a lot of duplication
1
3
  Mongoid::Document.send(:include, Impressionist::Impressionable)
2
4
 
3
5
  module Impressionist
@@ -1,3 +1,3 @@
1
1
  module Impressionist
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
data/test_app/Gemfile CHANGED
@@ -36,9 +36,9 @@ group :development, :test do
36
36
  end
37
37
 
38
38
  group :test do
39
- gem 'capybara'
40
39
  gem 'simplecov'
41
40
  gem 'systemu'
41
+ gem 'capybara', '~> 2.0.0'
42
42
  end
43
43
 
44
44
  gem 'jquery-rails'
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArticlesController do
4
+ fixtures :articles,:impressions,:posts,:widgets
5
+
6
+ render_views
7
+
8
+ it "should make the impressionable_hash available" do
9
+ get "index"
10
+ response.body.include?("false").should eq true
11
+ end
12
+
13
+ it "should log an impression with a message" do
14
+ get "index"
15
+ Impression.all.size.should eq 12
16
+ Article.first.impressions.last.message.should eq "this is a test article impression"
17
+ Article.first.impressions.last.controller_name.should eq "articles"
18
+ Article.first.impressions.last.action_name.should eq "index"
19
+ end
20
+
21
+ it "should log an impression without a message" do
22
+ get "show", :id=> 1
23
+ Impression.all.size.should eq 12
24
+ Article.first.impressions.last.message.should eq nil
25
+ Article.first.impressions.last.controller_name.should eq "articles"
26
+ Article.first.impressions.last.action_name.should eq "show"
27
+ end
28
+
29
+ it "should log the user_id if user is authenticated (@current_user before_filter method)" do
30
+ session[:user_id] = 123
31
+ get "show", :id=> 1
32
+ Article.first.impressions.last.user_id.should eq 123
33
+ end
34
+
35
+ it "should not log the user_id if user is authenticated" do
36
+ get "show", :id=> 1
37
+ Article.first.impressions.last.user_id.should eq nil
38
+ end
39
+
40
+ it "should log the request_hash, ip_address, referrer and session_hash" do
41
+ get "show", :id=> 1
42
+ Impression.last.request_hash.size.should eq 64
43
+ Impression.last.ip_address.should eq "0.0.0.0"
44
+ Impression.last.session_hash.size.should eq 32
45
+ Impression.last.referrer.should eq nil
46
+ end
47
+
48
+ # Capybara has change the way it works
49
+ # We need to pass :type options in order to make include helper methods
50
+ # see https://github.com/jnicklas/capybara#using-capybara-with-rspec
51
+ it "should log the referrer when you click a link", :type => :feature do
52
+ visit article_url(Article.first)
53
+ click_link "Same Page"
54
+ Impression.last.referrer.should eq "http://test.host/articles/1"
55
+ end
56
+ end
57
+
58
+
59
+
60
+
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe DummyController do
4
+ fixtures :impressions
5
+ render_views
6
+
7
+ it "should log impression at the per action level on non-restful controller" do
8
+ get "index"
9
+ Impression.all.size.should eq 12
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PostsController do
4
+ it "should log impression at the action level" do
5
+ get "show", :id=> 1
6
+ Impression.all.size.should eq 12
7
+ Impression.last.controller_name.should eq "posts"
8
+ Impression.last.action_name.should eq "show"
9
+ Impression.last.impressionable_type.should eq "Post"
10
+ Impression.last.impressionable_id.should eq 1
11
+ end
12
+
13
+ it "should log the user_id if user is authenticated (current_user helper method)" do
14
+ session[:user_id] = 123
15
+ get "show", :id=> 1
16
+ Post.first.impressions.last.user_id.should eq 123
17
+ end
18
+
19
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe WidgetsController do
4
+
5
+ before(:each) do
6
+ @widget = Widget.find(1)
7
+ Widget.stub(:find).and_return(@widget)
8
+ end
9
+
10
+ it "should log impression at the per action level" do
11
+ get "show", :id=> 1
12
+ Impression.all.size.should eq 12
13
+ get "index"
14
+ Impression.all.size.should eq 13
15
+ get "new"
16
+ Impression.all.size.should eq 13
17
+ end
18
+
19
+ it "should not log impression when user-agent is in wildcard list" do
20
+ request.stub!(:user_agent).and_return('somebot')
21
+ get "show", :id=> 1
22
+ Impression.all.size.should eq 11
23
+ end
24
+
25
+ it "should not log impression when user-agent is in the bot list" do
26
+ request.stub!(:user_agent).and_return('Acoon Robot v1.50.001')
27
+ get "show", :id=> 1
28
+ Impression.all.size.should eq 11
29
+ end
30
+
31
+ context "impressionist unique options" do
32
+
33
+ it "should log unique impressions at the per action level" do
34
+ get "show", :id=> 1
35
+ Impression.all.size.should eq 12
36
+ get "show", :id=> 2
37
+ Impression.all.size.should eq 13
38
+ get "show", :id => 2
39
+ Impression.all.size.should eq 13
40
+ get "index"
41
+ Impression.all.size.should eq 14
42
+ end
43
+
44
+ it "should log unique impressions only once per id" do
45
+ get "show", :id=> 1
46
+ Impression.all.size.should eq 12
47
+
48
+ get "show", :id=> 2
49
+ Impression.all.size.should eq 13
50
+
51
+ get "show", :id => 2
52
+ Impression.all.size.should eq 13
53
+
54
+ get "index"
55
+ Impression.all.size.should eq 14
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -1,14 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Impressionist do
4
+ let(:imp) { RUBY_VERSION.match("1.8") ? "is_impressionable" : :is_impressionable }
5
+
4
6
  it "should be extended from ActiveRecord::Base" do
5
- method = RUBY_VERSION.match("1.8") ? "is_impressionable" : :is_impressionable
6
- ActiveRecord::Base.methods.include?(method).should be_true
7
+ expect(ActiveRecord::Base).to respond_to(imp)
8
+ #ActiveRecord::Base.methods.include?(method).should be_true
7
9
  end
8
10
 
9
11
  it "should include methods in ApplicationController" do
10
12
  method = RUBY_VERSION.match("1.8") ? "impressionist" : :impressionist
11
- ApplicationController.instance_methods.include?(method).should be_true
13
+ expect(ApplicationController).to respond_to(method)
12
14
  end
13
15
 
14
16
  it "should include the before_filter method in ApplicationController" do
@@ -5,6 +5,8 @@ unless ENV['CI']
5
5
  end
6
6
  require File.expand_path("../../config/environment", __FILE__)
7
7
  require 'rspec/rails'
8
+ require 'capybara/rails'
9
+ require 'capybara/rspec'
8
10
 
9
11
  # Requires supporting ruby files with custom matchers and macros, etc,
10
12
  # in spec/support/ and its subdirectories.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impressionist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - johnmcaliley
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '1.5'
33
+ version: 1.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '1.5'
40
+ version: 1.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: capybara
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 2.0.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 2.0.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -267,8 +267,11 @@ files:
267
267
  - test_app/public/stylesheets/.gitkeep
268
268
  - test_app/script/cucumber
269
269
  - test_app/script/rails
270
- - test_app/spec/controllers/controller_spec.rb
270
+ - test_app/spec/controllers/articles_controller_spec.rb
271
+ - test_app/spec/controllers/dummy_controller_spec.rb
271
272
  - test_app/spec/controllers/impressionist_uniqueness_spec.rb
273
+ - test_app/spec/controllers/posts_controller_spec.rb
274
+ - test_app/spec/controllers/widgets_controller_spec.rb
272
275
  - test_app/spec/fixtures/articles.yml
273
276
  - test_app/spec/fixtures/impressions.yml
274
277
  - test_app/spec/fixtures/posts.yml
@@ -1,134 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ArticlesController do
4
- fixtures :articles,:impressions,:posts,:widgets
5
- render_views
6
-
7
- it "should make the impressionable_hash available" do
8
- get "index"
9
- response.body.include?("false").should eq true
10
- end
11
-
12
- it "should log an impression with a message" do
13
- get "index"
14
- Impression.all.size.should eq 12
15
- Article.first.impressions.last.message.should eq "this is a test article impression"
16
- Article.first.impressions.last.controller_name.should eq "articles"
17
- Article.first.impressions.last.action_name.should eq "index"
18
- end
19
-
20
- it "should log an impression without a message" do
21
- get "show", :id=> 1
22
- Impression.all.size.should eq 12
23
- Article.first.impressions.last.message.should eq nil
24
- Article.first.impressions.last.controller_name.should eq "articles"
25
- Article.first.impressions.last.action_name.should eq "show"
26
- end
27
-
28
- it "should log the user_id if user is authenticated (@current_user before_filter method)" do
29
- session[:user_id] = 123
30
- get "show", :id=> 1
31
- Article.first.impressions.last.user_id.should eq 123
32
- end
33
-
34
- it "should not log the user_id if user is authenticated" do
35
- get "show", :id=> 1
36
- Article.first.impressions.last.user_id.should eq nil
37
- end
38
-
39
- it "should log the request_hash, ip_address, referrer and session_hash" do
40
- get "show", :id=> 1
41
- Impression.last.request_hash.size.should eq 64
42
- Impression.last.ip_address.should eq "0.0.0.0"
43
- Impression.last.session_hash.size.should eq 32
44
- Impression.last.referrer.should eq nil
45
- end
46
-
47
- it "should log the referrer when you click a link" do
48
- visit article_url(Article.first)
49
- click_link "Same Page"
50
- Impression.last.referrer.should eq "http://test.host/articles/1"
51
- end
52
- end
53
-
54
- describe PostsController do
55
- it "should log impression at the action level" do
56
- get "show", :id=> 1
57
- Impression.all.size.should eq 12
58
- Impression.last.controller_name.should eq "posts"
59
- Impression.last.action_name.should eq "show"
60
- Impression.last.impressionable_type.should eq "Post"
61
- Impression.last.impressionable_id.should eq 1
62
- end
63
-
64
- it "should log the user_id if user is authenticated (current_user helper method)" do
65
- session[:user_id] = 123
66
- get "show", :id=> 1
67
- Post.first.impressions.last.user_id.should eq 123
68
- end
69
- end
70
-
71
- describe WidgetsController do
72
-
73
- before(:each) do
74
- @widget = Widget.find(1)
75
- Widget.stub(:find).and_return(@widget)
76
- end
77
-
78
- it "should log impression at the per action level" do
79
- get "show", :id=> 1
80
- Impression.all.size.should eq 12
81
- get "index"
82
- Impression.all.size.should eq 13
83
- get "new"
84
- Impression.all.size.should eq 13
85
- end
86
-
87
- it "should not log impression when user-agent is in wildcard list" do
88
- request.stub!(:user_agent).and_return('somebot')
89
- get "show", :id=> 1
90
- Impression.all.size.should eq 11
91
- end
92
-
93
- it "should not log impression when user-agent is in the bot list" do
94
- request.stub!(:user_agent).and_return('Acoon Robot v1.50.001')
95
- get "show", :id=> 1
96
- Impression.all.size.should eq 11
97
- end
98
-
99
- describe "impressionist unique options" do
100
-
101
- it "should log unique impressions at the per action level" do
102
- get "show", :id=> 1
103
- Impression.all.size.should eq 12
104
- get "show", :id=> 2
105
- Impression.all.size.should eq 13
106
- get "show", :id => 2
107
- Impression.all.size.should eq 13
108
- get "index"
109
- Impression.all.size.should eq 14
110
- end
111
-
112
- it "should log unique impressions only once per id" do
113
- get "show", :id=> 1
114
- Impression.all.size.should eq 12
115
- get "show", :id=> 2
116
- Impression.all.size.should eq 13
117
- get "show", :id => 2
118
- Impression.all.size.should eq 13
119
- get "index"
120
- Impression.all.size.should eq 14
121
- end
122
-
123
- end
124
-
125
- end
126
- describe DummyController do
127
- fixtures :impressions
128
- render_views
129
-
130
- it "should log impression at the per action level on non-restful controller" do
131
- get "index"
132
- Impression.all.size.should eq 12
133
- end
134
- end