2012-03-12 23:09:21 +00:00
|
|
|
require 'spec_helper'
|
2011-02-04 04:13:41 +00:00
|
|
|
|
|
|
|
describe Impression do
|
2011-02-13 19:18:34 +00:00
|
|
|
fixtures :articles,:impressions,:posts
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
before(:each) do
|
|
|
|
@article = Article.find(1)
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
it "should save a blank impression for an Article that has 10 impressions" do
|
|
|
|
@article.impressions.create
|
2011-02-17 14:53:01 +00:00
|
|
|
@article.impressions.size.should eq 12
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-02-04 04:13:41 +00:00
|
|
|
it "should save an impression with a message" do
|
2011-02-13 19:18:34 +00:00
|
|
|
@article.impressions.create(:message=>"test message")
|
2011-02-04 04:13:41 +00:00
|
|
|
@article.impressions.last.message.should eq "test message"
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2013-12-13 09:20:20 +00:00
|
|
|
it "should return the impression count for the message specified" do
|
|
|
|
@article.impressions.create(:message => "pageview")
|
|
|
|
@article.impressions.create(:message => "pageview")
|
|
|
|
@article.impressions.create(:message => "visit")
|
|
|
|
|
|
|
|
@article.impressionist_count(:message => "pageview", :filter => :all).should eq 2
|
|
|
|
end
|
|
|
|
|
2011-06-03 16:08:41 +00:00
|
|
|
it "should return the impression count for all with no date range specified" do
|
|
|
|
@article.impressionist_count(:filter=>:all).should eq 11
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-06-03 16:08:41 +00:00
|
|
|
it "should return unique impression count with no date range specified" do
|
|
|
|
@article.impressionist_count.should eq 9
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-06-03 16:08:41 +00:00
|
|
|
it "should return impression count with only start date specified" do
|
|
|
|
@article.impressionist_count(:start_date=>"2011-01-01",:filter=>:all).should eq 8
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-06-03 16:08:41 +00:00
|
|
|
it "should return impression count with whole date range specified" do
|
|
|
|
@article.impressionist_count(:start_date=>"2011-01-01",:end_date=>"2011-01-02",:filter=>:all).should eq 7
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return unique impression count with only start date specified" do
|
|
|
|
@article.impressionist_count(:start_date=>"2011-01-01").should eq 7
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-06-03 16:08:41 +00:00
|
|
|
it "should return unique impression count with date range specified" do
|
|
|
|
@article.impressionist_count(:start_date=>"2011-01-01",:end_date=>"2011-01-02").should eq 7
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-06-03 16:08:41 +00:00
|
|
|
it "should return unique impression count using ip address (which in turn eliminates duplicate request_hashes)" do
|
|
|
|
@article.impressionist_count(:filter=>:ip_address).should eq 8
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return unique impression count using session_hash (which in turn eliminates duplicate request_hashes)" do
|
|
|
|
@article.impressionist_count(:filter=>:session_hash).should eq 7
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
2011-12-13 12:51:23 +00:00
|
|
|
# tests :dependent => :destroy
|
|
|
|
it "should delete impressions on deletion of impressionable" do
|
2013-07-06 02:14:25 +00:00
|
|
|
#impressions_count = Impression.all.size
|
2011-12-13 12:51:23 +00:00
|
|
|
a = Article.create
|
|
|
|
i = a.impressions.create
|
|
|
|
a.destroy
|
|
|
|
a.destroyed?.should be_true
|
|
|
|
i.destroyed?.should be_true
|
|
|
|
end
|
2012-03-06 21:42:28 +00:00
|
|
|
|
|
|
|
end
|