2011-02-04 04:13:41 +00:00
|
|
|
require 'spec_helper.rb'
|
|
|
|
|
|
|
|
describe ArticlesController do
|
2011-10-31 17:02:31 +00:00
|
|
|
fixtures :articles,:impressions,:posts,:widgets
|
2011-02-04 04:13:41 +00:00
|
|
|
render_views
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
it "should make the impressionable_hash available" do
|
|
|
|
get "index"
|
|
|
|
response.body.include?("false").should eq true
|
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
it "should log an impression with a message" do
|
|
|
|
get "index"
|
2011-03-07 04:22:39 +00:00
|
|
|
Impression.all.size.should eq 12
|
2011-02-04 04:13:41 +00:00
|
|
|
Article.first.impressions.last.message.should eq "this is a test article impression"
|
2011-02-17 13:11:06 +00:00
|
|
|
Article.first.impressions.last.controller_name.should eq "articles"
|
|
|
|
Article.first.impressions.last.action_name.should eq "index"
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
it "should log an impression without a message" do
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-03-07 04:22:39 +00:00
|
|
|
Impression.all.size.should eq 12
|
2011-02-04 04:13:41 +00:00
|
|
|
Article.first.impressions.last.message.should eq nil
|
2011-02-17 13:11:06 +00:00
|
|
|
Article.first.impressions.last.controller_name.should eq "articles"
|
|
|
|
Article.first.impressions.last.action_name.should eq "show"
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-10 21:13:30 +00:00
|
|
|
it "should log the user_id if user is authenticated (@current_user before_filter method)" do
|
|
|
|
session[:user_id] = 123
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-02-10 21:13:30 +00:00
|
|
|
Article.first.impressions.last.user_id.should eq 123
|
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-10 21:13:30 +00:00
|
|
|
it "should not log the user_id if user is authenticated" do
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-02-10 21:13:30 +00:00
|
|
|
Article.first.impressions.last.user_id.should eq nil
|
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-06-03 15:52:42 +00:00
|
|
|
it "should log the request_hash, ip_address, referrer and session_hash" do
|
2011-03-07 04:22:39 +00:00
|
|
|
get "show", :id=> 1
|
|
|
|
Impression.last.request_hash.size.should eq 64
|
|
|
|
Impression.last.ip_address.should eq "0.0.0.0"
|
|
|
|
Impression.last.session_hash.size.should eq 32
|
2011-06-03 15:52:42 +00:00
|
|
|
Impression.last.referrer.should eq nil
|
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-06-03 15:52:42 +00:00
|
|
|
it "should log the referrer when you click a link" do
|
|
|
|
visit article_url(Article.first)
|
|
|
|
click_link "Same Page"
|
|
|
|
Impression.last.referrer.should eq "http://test.host/articles/1"
|
2011-03-07 04:22:39 +00:00
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
|
|
|
|
describe PostsController do
|
|
|
|
it "should log impression at the action level" do
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-03-07 04:22:39 +00:00
|
|
|
Impression.all.size.should eq 12
|
2011-02-04 04:13:41 +00:00
|
|
|
Impression.last.controller_name.should eq "posts"
|
2011-02-17 13:11:06 +00:00
|
|
|
Impression.last.action_name.should eq "show"
|
2011-02-04 04:13:41 +00:00
|
|
|
Impression.last.impressionable_type.should eq "Post"
|
|
|
|
Impression.last.impressionable_id.should eq 1
|
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-10 21:13:30 +00:00
|
|
|
it "should log the user_id if user is authenticated (current_user helper method)" do
|
|
|
|
session[:user_id] = 123
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-02-10 21:13:30 +00:00
|
|
|
Post.first.impressions.last.user_id.should eq 123
|
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe WidgetsController do
|
2011-10-31 17:02:31 +00:00
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@widget = Widget.find(1)
|
|
|
|
Widget.stub(:find).and_return(@widget)
|
|
|
|
end
|
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
it "should log impression at the per action level" do
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-02-04 04:13:41 +00:00
|
|
|
Impression.all.size.should eq 12
|
2011-03-07 04:22:39 +00:00
|
|
|
get "index"
|
|
|
|
Impression.all.size.should eq 13
|
2011-02-04 04:13:41 +00:00
|
|
|
get "new"
|
2011-03-07 04:22:39 +00:00
|
|
|
Impression.all.size.should eq 13
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-04 16:11:04 +00:00
|
|
|
it "should not log impression when user-agent is in wildcard list" do
|
|
|
|
request.stub!(:user_agent).and_return('somebot')
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-03-07 04:22:39 +00:00
|
|
|
Impression.all.size.should eq 11
|
2011-02-04 16:11:04 +00:00
|
|
|
end
|
2011-10-31 17:02:31 +00:00
|
|
|
|
2011-02-04 16:11:04 +00:00
|
|
|
it "should not log impression when user-agent is in the bot list" do
|
|
|
|
request.stub!(:user_agent).and_return('Acoon Robot v1.50.001')
|
2011-02-13 19:18:34 +00:00
|
|
|
get "show", :id=> 1
|
2011-10-31 17:02:31 +00:00
|
|
|
Impression.all.size.should eq 11
|
2011-02-04 16:11:04 +00:00
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-11-10 13:16:57 +00:00
|
|
|
describe "impressionist unique options" do
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-11-10 13:16:57 +00:00
|
|
|
it "should log unique impressions at the per action level" do
|
|
|
|
get "show", :id=> 1
|
|
|
|
Impression.all.size.should eq 12
|
|
|
|
get "show", :id=> 2
|
|
|
|
Impression.all.size.should eq 13
|
|
|
|
get "show", :id => 2
|
|
|
|
Impression.all.size.should eq 13
|
|
|
|
get "index"
|
|
|
|
Impression.all.size.should eq 14
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-11-10 13:16:57 +00:00
|
|
|
it "should log unique impressions only once per id" do
|
|
|
|
get "show", :id=> 1
|
|
|
|
Impression.all.size.should eq 12
|
|
|
|
get "show", :id=> 2
|
|
|
|
Impression.all.size.should eq 13
|
|
|
|
get "show", :id => 2
|
|
|
|
Impression.all.size.should eq 13
|
|
|
|
get "index"
|
|
|
|
Impression.all.size.should eq 14
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-11-10 13:16:57 +00:00
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|