jnunemaker / statwhore

StatWhore is for the stat addict in all of us. Eventually it will become a ruby wrapper for several web stat services apis. Initially, it will cover Google Analytics and Feedburner.

statwhore / spec / statwhore_google_analytics_profile_spec.rb
100644 65 lines (53 sloc) 2.787 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require File.dirname(__FILE__) + '/spec_helper.rb'
 
describe "Statwhore::Google::Analytics::Profile" do
  
  describe "being initialized" do
    
    it "should accept :name as key" do
      a = Statwhore::Google::Analytics::Profile.new(:name => 'test', :profile_id => '12341234')
      a.name.should == 'test'
    end
    
    it "should accept :account_id as key" do
      a = Statwhore::Google::Analytics::Profile.new(:account_id => '12341234', :profile_id => '12341234')
      a.account_id.should == '12341234'
    end
    
    it "should accept :profile_id as key" do
      a = Statwhore::Google::Analytics::Profile.new(:profile_id => '12341234')
      a.profile_id.should == '12341234'
    end
    
  end
  
  it "should be able to find all profiles for an account" do
    html = open(File.dirname(__FILE__) + '/fixtures/analytics_profile_find_all.html').read
    Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(html)
    accounts = Statwhore::Google::Analytics::Profile.find_all('1254221')
    accounts.collect(&:name).should == ["pray.nd.edu"]
  end
  
  it "should be able to get pageviews" do
    profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
    xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
    Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(xml)
    profile.pageviews.should == 283
  end
  
  it "should be able to get pageviews by day" do
    profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
    xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
    Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(xml)
    dates = profile.pageviews_by_day
    dates.first.should == [Date.civil(2008, 2, 8), 72]
    dates.last.should == [Date.civil(2008, 3, 9), 0]
    dates.size.should == 31
  end
  
  it "should be able to get visits" do
    profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
    xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
    Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(xml)
    profile.visits.should == 228
  end
  
  it "should be able to get visits by day" do
    profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
    xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
    Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(xml)
    dates = profile.visits_by_day
    dates.first.should == [Date.civil(2008, 2, 8), 67]
    dates.last.should == [Date.civil(2008, 3, 9), 0]
    dates.size.should == 31
  end
  
end