require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'mitamirri' describe "SessionReport" do before :all do @args = { :site => 'www.foo.com', :time_period => 'past 3 months', :action_kind => 'clickthrough', :visit_kind => 'search' } TrackableSession.stubs(:search).returns([]) @report = Mitamirri::SessionReport.new(@args) @report.stubs(:total_bounces).returns(5) @report.stubs(:total_clickthroughs).returns(10) @report.stubs(:total_conversions).returns(20) @report.stubs(:total_direct_visits).returns(10) @report.stubs(:total_duration).returns(18000.0) @report.stubs(:total_new_visits).returns(20) @report.stubs(:total_organic_visits).returns(30) @report.stubs(:total_pageviews).returns(100) @report.stubs(:total_ppc_visits).returns(10) @report.stubs(:total_return_visits).returns(90) @report.stubs(:total_search_visits).returns(30) @report.stubs(:total_visits).returns(100) @report.stubs(:total_conversions).returns(20) end it 'initializes with arguments' do @report.site.should == @args[:site] @report.time_period.should == @args[:time_period] @report.action_kind.should == 'clickthrough' @report.visit_kind.should == 'search' end it 'calculates its dates' do @report.dates.should == [ (Time.zone.now - 2.months).beginning_of_month, (Time.zone.now - 1.months).beginning_of_month, (Time.zone.now).end_of_month, ] end it 'calculates average pages per visit' do @report.average_pages_per_visit.should == "1.0" end it 'calculates average time on site' do @report.average_time_on_site.should == "3.0 minutes" end it 'calculates the bounce rate' do @report.bounce_rate.should == "5.0%" end it 'calculates the conversion rate' do @report.conversion_rate.should == "20.0%" end it 'calculates the total direct visits percentage' do @report.total_direct_visits_percentage.should == "10.0%" end it 'calculates the total new visits percentage' do @report.total_new_visits_percentage.should == "20.0%" end it 'calculates the total return visits percentage' do @report.total_return_visits_percentage.should == "90.0%" end it 'calculates the total organic visits percentage' do @report.total_organic_visits_percentage.should == "30.0%" end it 'calculates the total ppc visits percentage' do @report.total_ppc_visits_percentage.should == "10.0%" end it 'creates a KeywordStat object from arguments' do _stat = Mitamirri::SessionReport::KeywordStat.new(:keyword => 'foo', :count => 3) _stat.count.should == 3 _stat.keyword.should == 'foo' end it 'creates a ReferrerStat object from arguments' do _stat = Mitamirri::SessionReport::ReferrerStat.new(:referrer => 'www.foo.com', :count => 3) _stat.count.should == 3 _stat.referrer.should == 'www.foo.com' end it 'creates a Visit object from arguments' do _visit = Mitamirri::SessionReport::Visit.new(:kind => 'search', :date => Time.zone.now.to_s(:concise), :stats => []) _visit.kind.should == "search" _visit.date.should == Time.zone.now.to_s(:concise) _visit.stats.should == [] end it 'creates a VisitStat object from arguments' do _stat = Mitamirri::SessionReport::VisitStat.new(:date => Time.zone.now, :visits => 3) _stat.visits.should == 3 _stat.date.to_s(:concise).should == Time.zone.now.to_s(:concise) _stat.short_date.should == Time.zone.now.to_s(:month_year) end end