require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'mitamirri' describe "LeadsReport" do before :all do @args = { :site => 'www.foo.com', :time_period => 'past month', } TrackableSession.stubs(:search).returns([]) @report = Mitamirri::LeadsReport.new(@args) end it 'initializes with arguments' do @report.site.should == @args[:site] @report.time_period.should == @args[:time_period] @report.start_date.should == (Time.zone.now - 4.weeks).beginning_of_week @report.end_date.to_s(:concise).should == Time.zone.now.to_s(:concise) end it 'calculates its dates' do @report.dates.map{|d| d.to_s(:concise)}.should == [ (Time.zone.now - 4.weeks).beginning_of_week.to_s(:concise), (Time.zone.now - 3.weeks).beginning_of_week.to_s(:concise), (Time.zone.now - 2.weeks).beginning_of_week.to_s(:concise), (Time.zone.now - 1.weeks).beginning_of_week.to_s(:concise), Time.zone.now.to_s(:concise), ] end it 'creates a Lead object from arguments' do _lead = Mitamirri::LeadsReport::Lead.new(:stats => ['foo']) _lead.stats.should == ['foo'] end it 'creates a LeadStats object from arguments' do _stat = Mitamirri::LeadsReport::LeadStat.new(:date => Time.zone.now.end_of_week, :leads => 3, :conversion_rate => 50.0) _stat.date.should == Time.zone.now.end_of_week _stat.leads.should == 3 _stat.conversion_rate.should == 50.0 _stat.short_date.should == Time.zone.now.end_of_week.to_s(:concise) end end