impressionist 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Rakefile +17 -4
- data/app/models/impressionist/impressionable.rb +2 -2
- data/impressionist.gemspec +4 -3
- data/lib/impressionist/engine.rb +8 -25
- data/lib/impressionist/load.rb +6 -4
- data/lib/impressionist/models/active_record/impression.rb +5 -2
- data/lib/impressionist/models/mongoid/impression.rb +8 -15
- data/lib/impressionist/models/mongoid/impressionist/impressionable.rb +13 -32
- data/lib/impressionist/rails_toggle.rb +22 -0
- data/lib/impressionist/setup_association.rb +48 -0
- data/lib/impressionist/version.rb +1 -1
- data/tests/README +1 -0
- data/tests/spec/minitest_helper.rb +4 -0
- data/tests/spec/rails_toggle_spec.rb +26 -0
- data/tests/spec/setup_association_spec.rb +55 -0
- data/{test_app → tests/test_app}/.gitignore +0 -0
- data/{test_app → tests/test_app}/.rspec +0 -0
- data/{test_app → tests/test_app}/Gemfile +4 -15
- data/{test_app → tests/test_app}/README +0 -0
- data/{test_app → tests/test_app}/README.rdoc +0 -0
- data/{test_app → tests/test_app}/Rakefile +0 -0
- data/{test_app → tests/test_app}/app/assets/images/rails.png +0 -0
- data/{test_app → tests/test_app}/app/assets/javascripts/application.js +0 -0
- data/{test_app → tests/test_app}/app/assets/stylesheets/application.css +0 -0
- data/{test_app → tests/test_app}/app/controllers/application_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/articles_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/dummy_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/posts_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/widgets_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/helpers/application_helper.rb +0 -0
- data/{test_app → tests/test_app}/app/mailers/.gitkeep +0 -0
- data/{test_app → tests/test_app}/app/models/.gitkeep +0 -0
- data/{test_app → tests/test_app}/app/models/article.rb +0 -0
- data/{test_app → tests/test_app}/app/models/dummy.rb +0 -0
- data/{test_app → tests/test_app}/app/models/post.rb +0 -0
- data/{test_app → tests/test_app}/app/models/user.rb +0 -0
- data/{test_app → tests/test_app}/app/models/widget.rb +0 -0
- data/{test_app → tests/test_app}/app/views/articles/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/articles/show.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/dummy/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/layouts/application.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/posts/edit.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/posts/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/posts/show.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/widgets/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/widgets/new.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/widgets/show.html.erb +0 -0
- data/{test_app → tests/test_app}/config.ru +0 -0
- data/{test_app → tests/test_app}/config/application.rb +0 -0
- data/{test_app → tests/test_app}/config/boot.rb +0 -0
- data/{test_app → tests/test_app}/config/cucumber.yml +0 -0
- data/{test_app → tests/test_app}/config/database.yml +0 -0
- data/{test_app → tests/test_app}/config/environment.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/development.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/pg_test.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/production.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/test.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/backtrace_silencers.rb +0 -0
- data/tests/test_app/config/initializers/impression.rb +2 -0
- data/{test_app → tests/test_app}/config/initializers/inflections.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/mime_types.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/secret_token.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/session_store.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/wrap_parameters.rb +0 -0
- data/{test_app → tests/test_app}/config/locales/en.yml +0 -0
- data/{test_app → tests/test_app}/config/routes.rb +0 -0
- data/{test_app → tests/test_app}/db/migrate/20110201153144_create_articles.rb +0 -0
- data/{test_app → tests/test_app}/db/migrate/20110210205028_create_posts.rb +0 -0
- data/{test_app → tests/test_app}/db/migrate/20111127184039_create_widgets.rb +0 -0
- data/tests/test_app/db/schema.rb +60 -0
- data/{test_app → tests/test_app}/db/seeds.rb +0 -0
- data/{test_app → tests/test_app}/lib/assets/.gitkeep +0 -0
- data/{test_app → tests/test_app}/lib/tasks/.gitkeep +0 -0
- data/{test_app → tests/test_app}/lib/tasks/cucumber.rake +0 -0
- data/{test_app → tests/test_app}/log/.gitkeep +0 -0
- data/{test_app → tests/test_app}/public/404.html +0 -0
- data/{test_app → tests/test_app}/public/422.html +0 -0
- data/{test_app → tests/test_app}/public/500.html +0 -0
- data/{test_app → tests/test_app}/public/favicon.ico +0 -0
- data/{test_app → tests/test_app}/public/images/rails.png +0 -0
- data/{test_app → tests/test_app}/public/index.html +0 -0
- data/{test_app → tests/test_app}/public/javascripts/application.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/controls.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/dragdrop.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/effects.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/prototype.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/rails.js +0 -0
- data/{test_app → tests/test_app}/public/robots.txt +0 -0
- data/{test_app → tests/test_app}/public/stylesheets/.gitkeep +0 -0
- data/{test_app → tests/test_app}/script/cucumber +0 -0
- data/{test_app → tests/test_app}/script/rails +0 -0
- data/{test_app → tests/test_app}/spec/controllers/articles_controller_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/controllers/dummy_controller_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/controllers/impressionist_uniqueness_spec.rb +45 -45
- data/{test_app → tests/test_app}/spec/controllers/posts_controller_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/controllers/widgets_controller_spec.rb +2 -2
- data/{test_app → tests/test_app}/spec/fixtures/articles.yml +0 -0
- data/{test_app → tests/test_app}/spec/fixtures/impressions.yml +0 -0
- data/{test_app → tests/test_app}/spec/fixtures/posts.yml +0 -0
- data/{test_app → tests/test_app}/spec/fixtures/widgets.yml +0 -0
- data/{test_app → tests/test_app}/spec/initializers/initializers_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/models/bots_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/models/counter_caching_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/models/model_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/rails_generators/rails_generators_spec.rb +0 -0
- data/tests/test_app/spec/spec_helper.rb +31 -0
- metadata +224 -99
- data/lib/impressionist/set_up_association.rb +0 -14
- data/spec/spec_helper.rb +0 -5
- data/test_app/config/initializers/impression.rb +0 -5
- data/test_app/spec/spec_helper.rb +0 -38
File without changes
|
File without changes
|
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'rails', '3.2.12'
|
4
4
|
|
5
|
-
gem 'impressionist', :path => '
|
5
|
+
gem 'impressionist', :path => '../../'
|
6
6
|
|
7
7
|
platforms :jruby do
|
8
8
|
gem 'activerecord-jdbcsqlite3-adapter'
|
@@ -13,6 +13,9 @@ end
|
|
13
13
|
platforms :ruby, :mswin, :mingw do
|
14
14
|
gem 'pg'
|
15
15
|
gem 'sqlite3'
|
16
|
+
gem 'mysql2'
|
17
|
+
gem "mongoid", "~> 3.1.4"
|
18
|
+
gem 'bson_ext'
|
16
19
|
end
|
17
20
|
|
18
21
|
gem 'json'
|
@@ -43,17 +46,3 @@ end
|
|
43
46
|
|
44
47
|
gem 'jquery-rails'
|
45
48
|
|
46
|
-
# To use ActiveModel has_secure_password
|
47
|
-
# gem 'bcrypt-ruby', '~> 3.0.0'
|
48
|
-
|
49
|
-
# To use Jbuilder templates for JSON
|
50
|
-
# gem 'jbuilder'
|
51
|
-
|
52
|
-
# Use unicorn as the app server
|
53
|
-
# gem 'unicorn'
|
54
|
-
|
55
|
-
# Deploy with Capistrano
|
56
|
-
# gem 'capistrano'
|
57
|
-
|
58
|
-
# To use debugger
|
59
|
-
# gem 'ruby-debug'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20130709003307) do
|
15
|
+
|
16
|
+
create_table "articles", :force => true do |t|
|
17
|
+
t.string "name"
|
18
|
+
t.datetime "created_at", :null => false
|
19
|
+
t.datetime "updated_at", :null => false
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "impressions", :force => true do |t|
|
23
|
+
t.string "impressionable_type"
|
24
|
+
t.integer "impressionable_id"
|
25
|
+
t.integer "user_id"
|
26
|
+
t.string "controller_name"
|
27
|
+
t.string "action_name"
|
28
|
+
t.string "view_name"
|
29
|
+
t.string "request_hash"
|
30
|
+
t.string "ip_address"
|
31
|
+
t.string "session_hash"
|
32
|
+
t.text "message"
|
33
|
+
t.text "referrer"
|
34
|
+
t.datetime "created_at", :null => false
|
35
|
+
t.datetime "updated_at", :null => false
|
36
|
+
end
|
37
|
+
|
38
|
+
add_index "impressions", ["controller_name", "action_name", "ip_address"], :name => "controlleraction_ip_index"
|
39
|
+
add_index "impressions", ["controller_name", "action_name", "request_hash"], :name => "controlleraction_request_index"
|
40
|
+
add_index "impressions", ["controller_name", "action_name", "session_hash"], :name => "controlleraction_session_index"
|
41
|
+
add_index "impressions", ["impressionable_type", "impressionable_id", "ip_address"], :name => "poly_ip_index"
|
42
|
+
add_index "impressions", ["impressionable_type", "impressionable_id", "request_hash"], :name => "poly_request_index"
|
43
|
+
add_index "impressions", ["impressionable_type", "impressionable_id", "session_hash"], :name => "poly_session_index"
|
44
|
+
add_index "impressions", ["impressionable_type", "message", "impressionable_id"], :name => "impressionable_type_message_index"
|
45
|
+
add_index "impressions", ["user_id"], :name => "index_impressions_on_user_id"
|
46
|
+
|
47
|
+
create_table "posts", :force => true do |t|
|
48
|
+
t.string "name"
|
49
|
+
t.datetime "created_at", :null => false
|
50
|
+
t.datetime "updated_at", :null => false
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table "widgets", :force => true do |t|
|
54
|
+
t.string "name"
|
55
|
+
t.integer "impressions_count", :default => 0
|
56
|
+
t.datetime "created_at", :null => false
|
57
|
+
t.datetime "updated_at", :null => false
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -16,14 +16,14 @@ describe DummyController do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should recognize unique session" do
|
19
|
-
controller.stub
|
19
|
+
controller.stub(:session_hash).and_return(request.session_options[:id])
|
20
20
|
controller.impressionist_subapp_filter(nil, [:session_hash])
|
21
21
|
controller.impressionist_subapp_filter(nil, [:session_hash])
|
22
22
|
Impression.should have(@impression_count + 1).records
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should recognize unique ip" do
|
26
|
-
controller.request.stub
|
26
|
+
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
27
27
|
controller.impressionist_subapp_filter(nil, [:ip_address])
|
28
28
|
controller.impressionist_subapp_filter(nil, [:ip_address])
|
29
29
|
Impression.should have(@impression_count + 1).records
|
@@ -36,35 +36,35 @@ describe DummyController do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should recognize unique action" do
|
39
|
-
controller.stub
|
39
|
+
controller.stub(:action_name).and_return("test_action")
|
40
40
|
controller.impressionist_subapp_filter(nil, [:action_name])
|
41
41
|
controller.impressionist_subapp_filter(nil, [:action_name])
|
42
42
|
Impression.should have(@impression_count + 1).records
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should recognize unique controller" do
|
46
|
-
controller.stub
|
46
|
+
controller.stub(:controller_name).and_return("post")
|
47
47
|
controller.impressionist_subapp_filter(nil, [:controller_name])
|
48
48
|
controller.impressionist_subapp_filter(nil, [:controller_name])
|
49
49
|
Impression.should have(@impression_count + 1).records
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should recognize unique user" do
|
53
|
-
controller.stub
|
53
|
+
controller.stub(:user_id).and_return(42)
|
54
54
|
controller.impressionist_subapp_filter(nil, [:user_id])
|
55
55
|
controller.impressionist_subapp_filter(nil, [:user_id])
|
56
56
|
Impression.should have(@impression_count + 1).records
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should recognize unique referer" do
|
60
|
-
controller.request.stub
|
60
|
+
controller.request.stub(:referer).and_return("http://foo/bar")
|
61
61
|
controller.impressionist_subapp_filter(nil, [:referrer])
|
62
62
|
controller.impressionist_subapp_filter(nil, [:referrer])
|
63
63
|
Impression.should have(@impression_count + 1).records
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should recognize unique id" do
|
67
|
-
controller.stub
|
67
|
+
controller.stub(:params).and_return({:id => "666"}) # for correct impressionable id in filter
|
68
68
|
controller.impressionist_subapp_filter(nil, [:impressionable_id])
|
69
69
|
controller.impressionist_subapp_filter(nil, [:impressionable_id])
|
70
70
|
Impression.should have(@impression_count + 1).records
|
@@ -72,88 +72,88 @@ describe DummyController do
|
|
72
72
|
|
73
73
|
# extra redundant test for important controller and action combination.
|
74
74
|
it "should recognize different controller and action" do
|
75
|
-
controller.stub
|
76
|
-
controller.stub
|
75
|
+
controller.stub(:controller_name).and_return("post")
|
76
|
+
controller.stub(:action_name).and_return("test_action")
|
77
77
|
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
78
78
|
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
79
79
|
Impression.should have(@impression_count + 1).records
|
80
|
-
controller.stub
|
80
|
+
controller.stub(:action_name).and_return("another_action")
|
81
81
|
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
82
82
|
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
83
83
|
Impression.should have(@impression_count + 2).records
|
84
|
-
controller.stub
|
84
|
+
controller.stub(:controller_name).and_return("article")
|
85
85
|
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
86
86
|
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
87
87
|
Impression.should have(@impression_count + 3).records
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should recognize different action" do
|
91
|
-
controller.stub
|
91
|
+
controller.stub(:action_name).and_return("test_action")
|
92
92
|
controller.impressionist_subapp_filter(nil, [:action_name])
|
93
93
|
controller.impressionist_subapp_filter(nil, [:action_name])
|
94
94
|
Impression.should have(@impression_count + 1).records
|
95
|
-
controller.stub
|
95
|
+
controller.stub(:action_name).and_return("another_action")
|
96
96
|
controller.impressionist_subapp_filter(nil, [:action_name])
|
97
97
|
controller.impressionist_subapp_filter(nil, [:action_name])
|
98
98
|
Impression.should have(@impression_count + 2).records
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should recognize different controller" do
|
102
|
-
controller.stub
|
102
|
+
controller.stub(:controller_name).and_return("post")
|
103
103
|
controller.impressionist_subapp_filter(nil, [:controller_name])
|
104
104
|
controller.impressionist_subapp_filter(nil, [:controller_name])
|
105
105
|
Impression.should have(@impression_count + 1).records
|
106
|
-
controller.stub
|
106
|
+
controller.stub(:controller_name).and_return("article")
|
107
107
|
controller.impressionist_subapp_filter(nil, [:controller_name])
|
108
108
|
controller.impressionist_subapp_filter(nil, [:controller_name])
|
109
109
|
Impression.should have(@impression_count + 2).records
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should recognize different session" do
|
113
|
-
controller.stub
|
113
|
+
controller.stub(:session_hash).and_return("foo")
|
114
114
|
controller.impressionist_subapp_filter(nil, [:session_hash])
|
115
115
|
controller.impressionist_subapp_filter(nil, [:session_hash])
|
116
116
|
Impression.should have(@impression_count + 1).records
|
117
|
-
controller.stub
|
117
|
+
controller.stub(:session_hash).and_return("bar")
|
118
118
|
controller.impressionist_subapp_filter(nil, [:session_hash])
|
119
119
|
controller.impressionist_subapp_filter(nil, [:session_hash])
|
120
120
|
Impression.should have(@impression_count + 2).records
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should recognize different ip" do
|
124
|
-
controller.request.stub
|
124
|
+
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
125
125
|
controller.impressionist_subapp_filter(nil, [:ip_address])
|
126
126
|
controller.impressionist_subapp_filter(nil, [:ip_address])
|
127
127
|
Impression.should have(@impression_count + 1).records
|
128
|
-
controller.request.stub
|
128
|
+
controller.request.stub(:remote_ip).and_return("5.6.7.8")
|
129
129
|
controller.impressionist_subapp_filter(nil, [:ip_address])
|
130
130
|
controller.impressionist_subapp_filter(nil, [:ip_address])
|
131
131
|
Impression.should have(@impression_count + 2).records
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should recognize different referer" do
|
135
|
-
controller.request.stub
|
135
|
+
controller.request.stub(:referer).and_return("http://foo/bar")
|
136
136
|
controller.impressionist_subapp_filter(nil, [:referrer])
|
137
137
|
controller.impressionist_subapp_filter(nil, [:referrer])
|
138
138
|
Impression.should have(@impression_count + 1).records
|
139
|
-
controller.request.stub
|
139
|
+
controller.request.stub(:referer).and_return("http://bar/fo")
|
140
140
|
controller.impressionist_subapp_filter(nil, [:referrer])
|
141
141
|
controller.impressionist_subapp_filter(nil, [:referrer])
|
142
142
|
Impression.should have(@impression_count + 2).records
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should recognize different id" do
|
146
|
-
controller.stub
|
146
|
+
controller.stub(:params).and_return({:id => "666"}) # for correct impressionable id in filter
|
147
147
|
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
148
148
|
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
149
|
-
controller.stub
|
149
|
+
controller.stub(:params).and_return({:id => "42"}) # for correct impressionable id in filter
|
150
150
|
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
151
151
|
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
152
152
|
Impression.should have(@impression_count + 2).records
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should recognize combined uniqueness" do
|
156
|
-
controller.stub
|
156
|
+
controller.stub(:action_name).and_return("test_action")
|
157
157
|
controller.impressionist_subapp_filter(nil, [:ip_address, :request_hash, :action_name])
|
158
158
|
controller.impressionist_subapp_filter(nil, [:request_hash, :ip_address, :action_name])
|
159
159
|
controller.impressionist_subapp_filter(nil, [:request_hash, :action_name])
|
@@ -166,11 +166,11 @@ describe DummyController do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should recognize combined non-uniqueness" do
|
169
|
-
controller.stub
|
169
|
+
controller.stub(:action_name).and_return(nil)
|
170
170
|
controller.impressionist_subapp_filter(nil, [:ip_address, :action_name])
|
171
|
-
controller.stub
|
171
|
+
controller.stub(:action_name).and_return("test_action")
|
172
172
|
controller.impressionist_subapp_filter(nil, [:ip_address, :action_name])
|
173
|
-
controller.stub
|
173
|
+
controller.stub(:action_name).and_return("another_action")
|
174
174
|
controller.impressionist_subapp_filter(nil, [:ip_address, :action_name])
|
175
175
|
Impression.should have(@impression_count + 3).records
|
176
176
|
end
|
@@ -189,7 +189,7 @@ describe DummyController do
|
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should recognize unique session" do
|
192
|
-
controller.stub
|
192
|
+
controller.stub(:session_hash).and_return(request.session_options[:id])
|
193
193
|
impressionable = Post.create
|
194
194
|
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
195
195
|
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
@@ -197,7 +197,7 @@ describe DummyController do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should recognize unique ip" do
|
200
|
-
controller.request.stub
|
200
|
+
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
201
201
|
impressionable = Post.create
|
202
202
|
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
203
203
|
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
@@ -212,7 +212,7 @@ describe DummyController do
|
|
212
212
|
end
|
213
213
|
|
214
214
|
it "should recognize unique user" do
|
215
|
-
controller.stub
|
215
|
+
controller.stub(:user_id).and_return(666)
|
216
216
|
impressionable = Post.create
|
217
217
|
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
218
218
|
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
@@ -220,7 +220,7 @@ describe DummyController do
|
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should recognize unique referer" do
|
223
|
-
controller.request.stub
|
223
|
+
controller.request.stub(:referer).and_return("http://foo/bar")
|
224
224
|
impressionable = Post.create
|
225
225
|
controller.impressionist(impressionable, nil, :unique => [:referrer])
|
226
226
|
controller.impressionist(impressionable, nil, :unique => [:referrer])
|
@@ -229,23 +229,23 @@ describe DummyController do
|
|
229
229
|
|
230
230
|
it "should recognize different session" do
|
231
231
|
impressionable = Post.create
|
232
|
-
controller.stub
|
232
|
+
controller.stub(:session_hash).and_return("foo")
|
233
233
|
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
234
234
|
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
235
235
|
Impression.should have(@impression_count + 1).records
|
236
|
-
controller.stub
|
236
|
+
controller.stub(:session_hash).and_return("bar")
|
237
237
|
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
238
238
|
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
239
239
|
Impression.should have(@impression_count + 2).records
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should recognize different ip" do
|
243
|
-
controller.request.stub
|
243
|
+
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
244
244
|
impressionable = Post.create
|
245
245
|
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
246
246
|
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
247
247
|
Impression.should have(@impression_count + 1).records
|
248
|
-
controller.request.stub
|
248
|
+
controller.request.stub(:remote_ip).and_return("5.6.7.8")
|
249
249
|
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
250
250
|
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
251
251
|
Impression.should have(@impression_count + 2).records
|
@@ -253,11 +253,11 @@ describe DummyController do
|
|
253
253
|
|
254
254
|
it "should recognize different user" do
|
255
255
|
impressionable = Post.create
|
256
|
-
controller.stub
|
256
|
+
controller.stub(:user_id).and_return(666)
|
257
257
|
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
258
258
|
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
259
259
|
Impression.should have(@impression_count + 1).records
|
260
|
-
controller.stub
|
260
|
+
controller.stub(:user_id).and_return(42)
|
261
261
|
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
262
262
|
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
263
263
|
Impression.should have(@impression_count + 2).records
|
@@ -265,7 +265,7 @@ describe DummyController do
|
|
265
265
|
|
266
266
|
it "should recognize combined uniqueness" do
|
267
267
|
impressionable = Post.create
|
268
|
-
controller.stub
|
268
|
+
controller.stub(:session_hash).and_return("foo")
|
269
269
|
controller.impressionist(impressionable, nil, :unique => [:ip_address, :request_hash, :session_hash])
|
270
270
|
controller.impressionist(impressionable, nil, :unique => [:request_hash, :ip_address, :session_hash])
|
271
271
|
controller.impressionist(impressionable, nil, :unique => [:request_hash, :session_hash])
|
@@ -279,11 +279,11 @@ describe DummyController do
|
|
279
279
|
|
280
280
|
it "should recognize combined non-uniqueness" do
|
281
281
|
impressionable = Post.create
|
282
|
-
controller.stub
|
282
|
+
controller.stub(:session_hash).and_return(nil)
|
283
283
|
controller.impressionist(impressionable, nil, :unique => [:ip_address, :session_hash])
|
284
|
-
controller.stub
|
284
|
+
controller.stub(:session_hash).and_return("foo")
|
285
285
|
controller.impressionist(impressionable, nil, :unique => [:ip_address, :session_hash])
|
286
|
-
controller.stub
|
286
|
+
controller.stub(:session_hash).and_return("bar")
|
287
287
|
controller.impressionist(impressionable, nil, :unique => [:ip_address, :session_hash])
|
288
288
|
Impression.should have(@impression_count + 3).records
|
289
289
|
end
|
@@ -294,10 +294,10 @@ describe DummyController do
|
|
294
294
|
|
295
295
|
it "should recognize uniqueness" do
|
296
296
|
impressionable = Post.create
|
297
|
-
controller.stub
|
298
|
-
controller.stub
|
299
|
-
controller.stub
|
300
|
-
controller.request.stub
|
297
|
+
controller.stub(:controller_name).and_return("posts") # for correct impressionable type in filter
|
298
|
+
controller.stub(:params).and_return({:id => impressionable.id.to_s}) # for correct impressionable id in filter
|
299
|
+
controller.stub(:session_hash).and_return("foo")
|
300
|
+
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
301
301
|
# order of the following methods is important for the test!
|
302
302
|
controller.impressionist_subapp_filter(nil, [:ip_address, :request_hash, :session_hash])
|
303
303
|
controller.impressionist(impressionable, nil, :unique => [:ip_address, :request_hash, :session_hash])
|