readmedia-garb 0.9.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.md +198 -0
  2. data/Rakefile +57 -0
  3. data/lib/garb/account.rb +22 -0
  4. data/lib/garb/account_feed_request.rb +25 -0
  5. data/lib/garb/authentication_request.rb +53 -0
  6. data/lib/garb/data_request.rb +42 -0
  7. data/lib/garb/destination.rb +18 -0
  8. data/lib/garb/filter_parameters.rb +42 -0
  9. data/lib/garb/goal.rb +20 -0
  10. data/lib/garb/management/account.rb +39 -0
  11. data/lib/garb/management/feed.rb +26 -0
  12. data/lib/garb/management/goal.rb +44 -0
  13. data/lib/garb/management/profile.rb +44 -0
  14. data/lib/garb/management/segment.rb +27 -0
  15. data/lib/garb/management/web_property.rb +38 -0
  16. data/lib/garb/model.rb +91 -0
  17. data/lib/garb/profile.rb +33 -0
  18. data/lib/garb/profile_reports.rb +16 -0
  19. data/lib/garb/report.rb +28 -0
  20. data/lib/garb/report_parameter.rb +25 -0
  21. data/lib/garb/report_response.rb +56 -0
  22. data/lib/garb/reports/bounces.rb +5 -0
  23. data/lib/garb/reports/exits.rb +5 -0
  24. data/lib/garb/reports/pageviews.rb +5 -0
  25. data/lib/garb/reports/unique_pageviews.rb +5 -0
  26. data/lib/garb/reports/visits.rb +5 -0
  27. data/lib/garb/reports.rb +5 -0
  28. data/lib/garb/resource.rb +115 -0
  29. data/lib/garb/result_set.rb +21 -0
  30. data/lib/garb/session.rb +25 -0
  31. data/lib/garb/step.rb +13 -0
  32. data/lib/garb/version.rb +14 -0
  33. data/lib/garb.rb +69 -0
  34. data/lib/support.rb +40 -0
  35. data/test/fixtures/cacert.pem +67 -0
  36. data/test/fixtures/profile_feed.xml +72 -0
  37. data/test/fixtures/report_feed.xml +48 -0
  38. data/test/test_helper.rb +45 -0
  39. data/test/unit/garb/account_feed_request_test.rb +42 -0
  40. data/test/unit/garb/account_test.rb +53 -0
  41. data/test/unit/garb/authentication_request_test.rb +121 -0
  42. data/test/unit/garb/data_request_test.rb +107 -0
  43. data/test/unit/garb/destination_test.rb +28 -0
  44. data/test/unit/garb/filter_parameters_test.rb +68 -0
  45. data/test/unit/garb/goal_test.rb +24 -0
  46. data/test/unit/garb/management/account_test.rb +70 -0
  47. data/test/unit/garb/management/feed_test.rb +44 -0
  48. data/test/unit/garb/management/goal_test.rb +81 -0
  49. data/test/unit/garb/management/profile_test.rb +81 -0
  50. data/test/unit/garb/management/segment_test.rb +47 -0
  51. data/test/unit/garb/management/web_property_test.rb +64 -0
  52. data/test/unit/garb/model_test.rb +141 -0
  53. data/test/unit/garb/oauth_session_test.rb +11 -0
  54. data/test/unit/garb/profile_reports_test.rb +29 -0
  55. data/test/unit/garb/profile_test.rb +77 -0
  56. data/test/unit/garb/report_parameter_test.rb +43 -0
  57. data/test/unit/garb/report_response_test.rb +47 -0
  58. data/test/unit/garb/report_test.rb +99 -0
  59. data/test/unit/garb/resource_test.rb +50 -0
  60. data/test/unit/garb/session_test.rb +84 -0
  61. data/test/unit/garb/step_test.rb +15 -0
  62. data/test/unit/garb_test.rb +26 -0
  63. data/test/unit/symbol_operator_test.rb +37 -0
  64. metadata +189 -0
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ class GoalTest < MiniTest::Unit::TestCase
5
+ context "A Goal" do
6
+ should "have a name, number, and value" do
7
+ goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'true'})
8
+ assert_equal 'Read Blog', goal.name
9
+ assert_equal 1, goal.number
10
+ assert_equal 10.0, goal.value
11
+ end
12
+
13
+ should "know if it is active" do
14
+ goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'true'})
15
+ assert goal.active?
16
+ end
17
+
18
+ should "know if it is not active" do
19
+ goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'false'})
20
+ assert_equal false, goal.active?
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ module Management
5
+ class AccountTest < MiniTest::Unit::TestCase
6
+ context "The Account class" do
7
+ should "turn entries for path into array of accounts" do
8
+ feed = stub(:entries => ["entry1"])
9
+ Feed.stubs(:new).returns(feed)
10
+
11
+ Account.stubs(:new_from_entry)
12
+ Account.all
13
+
14
+ assert_received(Feed, :new) {|e| e.with(Session, '/accounts')}
15
+ assert_received(feed, :entries)
16
+ assert_received(Account, :new_from_entry) {|e| e.with("entry1", Session)}
17
+ end
18
+ end
19
+
20
+ context "an Account" do
21
+ setup do
22
+ entry = {
23
+ "title" => "Google Analytics Account Garb",
24
+ "link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/123456"}],
25
+ "dxp:property" => [
26
+ {"name" => "ga:accountId", "value" => "123456"},
27
+ {"name" => "ga:accountName", "value" => "Garb"}
28
+ ]
29
+ }
30
+ @account = Account.new_from_entry(entry, Session)
31
+ end
32
+
33
+ should "extract id and title from GA entry" do
34
+ assert_equal "Garb", @account.title
35
+ assert_equal "123456", @account.id
36
+ end
37
+
38
+ should "extract a name from GA entry properties" do
39
+ assert_equal "Garb", @account.name
40
+ end
41
+
42
+ should "combine the Account.path and the id into an new path" do
43
+ assert_equal "/accounts/123456", @account.path
44
+ end
45
+
46
+ should "have a reference to the session it was created with" do
47
+ assert_equal Session, @account.session
48
+ end
49
+
50
+ should "have web properties" do
51
+ WebProperty.stubs(:for_account)
52
+ @account.web_properties
53
+ assert_received(WebProperty, :for_account) {|e| e.with(@account)}
54
+ end
55
+
56
+ should "have profiles" do
57
+ Profile.stubs(:for_account)
58
+ @account.profiles
59
+ assert_received(Profile, :for_account) {|e| e.with(@account)}
60
+ end
61
+
62
+ should "have goals" do
63
+ Goal.stubs(:for_account)
64
+ @account.goals
65
+ assert_received(Goal, :for_account) {|e| e.with(@account)}
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ module Management
5
+ class FeedTest < MiniTest::Unit::TestCase
6
+ context "a Feed" do
7
+ setup do
8
+ @request = stub
9
+ DataRequest.stubs(:new).returns(@request)
10
+ @feed = Feed.new(Garb::Session.new, '/accounts')
11
+ end
12
+
13
+ should "have a parsed response" do
14
+ Crack::XML.stubs(:parse)
15
+ @feed.stubs(:response).returns(stub(:body => 'response body'))
16
+ @feed.parsed_response
17
+
18
+ assert_received(Crack::XML, :parse) {|e| e.with('response body')}
19
+ end
20
+
21
+ should "have entries from the parsed response" do
22
+ @feed.stubs(:parsed_response).returns({'feed' => {'entry' => ['entry1', 'entry2']}})
23
+ assert_equal ['entry1', 'entry2'], @feed.entries
24
+ end
25
+
26
+ should "handle case of a single entry" do
27
+ @feed.stubs(:parsed_response).returns({'feed' => {'entry' => {'profile_id' => '12345'}}})
28
+ assert_equal [{'profile_id' => '12345'}], @feed.entries
29
+ end
30
+
31
+ should "have an empty array for entries without a response" do
32
+ @feed.stubs(:parsed_response).returns(nil)
33
+ assert_equal [], @feed.entries
34
+ end
35
+
36
+ should "have a response from the request" do
37
+ @request.stubs(:send_request)
38
+ @feed.response
39
+ assert_received(@request, :send_request)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,81 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ module Management
5
+ class GoalTest < MiniTest::Unit::TestCase
6
+ context "the Goal class" do
7
+ should "turn entries for path into array of goals" do
8
+ feed = stub(:entries => ["entry1"])
9
+ Feed.stubs(:new).returns(feed)
10
+
11
+ Goal.stubs(:new_from_entry)
12
+ Goal.all
13
+
14
+ assert_received(Feed, :new) {|e| e.with(Session, '/accounts/~all/webproperties/~all/profiles/~all/goals')}
15
+ assert_received(feed, :entries)
16
+ assert_received(Goal, :new_from_entry) {|e| e.with("entry1", Session)}
17
+ end
18
+
19
+ should "find all goals for a given account" do
20
+ Goal.stubs(:all)
21
+ Goal.for_account(stub(:session => 'session', :path => '/accounts/123'))
22
+ assert_received(Goal, :all) {|e| e.with('session', '/accounts/123/webproperties/~all/profiles/~all/goals')}
23
+ end
24
+
25
+ should "find all goals for a given web_property" do
26
+ Goal.stubs(:all)
27
+ Goal.for_web_property(stub(:session => 'session', :path => '/accounts/123/webproperties/456'))
28
+ assert_received(Goal, :all) {|e| e.with('session', '/accounts/123/webproperties/456/profiles/~all/goals')}
29
+ end
30
+
31
+ should "find all goals for a given profile" do
32
+ Goal.stubs(:all)
33
+ Goal.for_profile(stub(:session => 'session', :path => '/accounts/123/webproperties/456/profiles/789'))
34
+ assert_received(Goal, :all) {|e| e.with('session', '/accounts/123/webproperties/456/profiles/789/goals')}
35
+ end
36
+ end
37
+
38
+ context "a Goal" do
39
+ setup do
40
+ entry = {
41
+ "link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1/profiles/98765"}],
42
+ "ga:goal" => {
43
+ "ga:destination"=>{"caseSensitive"=>"false","expression"=>"/blog.html","matchType"=>"head"},
44
+ "active"=>"true",
45
+ "name"=>"Read Blog",
46
+ "number"=>"1",
47
+ "value"=>"10.0"
48
+ }
49
+ }
50
+
51
+ @goal = Goal.new_from_entry(entry, Session)
52
+ end
53
+
54
+ should "have a name" do
55
+ assert_equal "Read Blog", @goal.name
56
+ end
57
+
58
+ should "have a number" do
59
+ assert_equal 1, @goal.number
60
+ end
61
+
62
+ should "have a value" do
63
+ assert_equal 10.0, @goal.value
64
+ end
65
+
66
+ should "know if it is active" do
67
+ assert_equal true, @goal.active?
68
+ end
69
+
70
+ should "know if it is not active" do
71
+ @goal.active = false
72
+ assert_equal false, @goal.active?
73
+ end
74
+
75
+ should "have a destination" do
76
+ assert_equal true, @goal.destination.is_a?(Destination)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,81 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ module Management
5
+ class ProfileTest < MiniTest::Unit::TestCase
6
+ context "The Profile class" do
7
+ should "turn entries for path into array of profiles" do
8
+ feed = stub(:entries => ["entry1"])
9
+ Feed.stubs(:new).returns(feed)
10
+
11
+ Profile.stubs(:new_from_entry)
12
+ Profile.all
13
+
14
+ assert_received(Feed, :new) {|e| e.with(Session, '/accounts/~all/webproperties/~all/profiles')}
15
+ assert_received(feed, :entries)
16
+ assert_received(Profile, :new_from_entry) {|e| e.with("entry1", Session)}
17
+ end
18
+
19
+ should "find all profiles for a given account" do
20
+ Profile.stubs(:all)
21
+ Profile.for_account(stub(:session => 'session', :path => '/accounts/123'))
22
+ assert_received(Profile, :all) {|e| e.with('session', '/accounts/123/webproperties/~all/profiles')}
23
+ end
24
+
25
+ should "find all profiles for a given web_property" do
26
+ Profile.stubs(:all)
27
+ Profile.for_web_property(stub(:session => 'session', :path => '/accounts/123/webproperties/456'))
28
+ assert_received(Profile, :all) {|e| e.with('session', '/accounts/123/webproperties/456/profiles')}
29
+ end
30
+ end
31
+
32
+ context "A Profile" do
33
+ setup do
34
+ entry = {
35
+ "link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1/profiles/98765"}],
36
+ "dxp:property" => [
37
+ {"name" => "ga:profileId", "value" => "98765"},
38
+ {"name" => "ga:accountId", "value" => "1189765"},
39
+ {"name" => "ga:webPropertyId", "value" => 'UA-1189765-1'},
40
+ {"name" => "ga:profileName", "value" => "example.com"},
41
+ {"name"=>"dxp:tableId", "value"=>"ga:4506"},
42
+ {"name"=>"ga:currency", "value"=>"USD"},
43
+ {"name"=>"ga:timezone", "value"=>"America/New_York"}
44
+ ]
45
+ }
46
+ @profile = Profile.new_from_entry(entry, Session)
47
+ end
48
+
49
+ should "have a title" do
50
+ assert_equal "example.com", @profile.title
51
+ end
52
+
53
+ should "have an id" do
54
+ assert_equal '98765', @profile.id
55
+ end
56
+
57
+ should "have an account_id" do
58
+ assert_equal '1189765', @profile.account_id
59
+ end
60
+
61
+ should "have a web_property_id" do
62
+ assert_equal 'UA-1189765-1', @profile.web_property_id
63
+ end
64
+
65
+ should "have a table_id (for old Garb::Report)" do
66
+ assert_equal 'ga:4506', @profile.table_id
67
+ end
68
+
69
+ should "have a path" do
70
+ assert_equal "/accounts/1189765/webproperties/UA-1189765-1/profiles/98765", @profile.path
71
+ end
72
+
73
+ should "have goals" do
74
+ Goal.stubs(:for_profile)
75
+ @profile.goals
76
+ assert_received(Goal, :for_profile) {|e| e.with(@profile)}
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ module Management
5
+ class SegmentTest < MiniTest::Unit::TestCase
6
+ context "The Segment class" do
7
+ should "turn entries for path into array of accounts" do
8
+ feed = stub(:entries => ["entry1"])
9
+ Feed.stubs(:new).returns(feed)
10
+
11
+ Segment.stubs(:new_from_entry)
12
+ Segment.all
13
+
14
+ assert_received(Feed, :new) {|e| e.with(Session, '/segments')}
15
+ assert_received(feed, :entries)
16
+ assert_received(Segment, :new_from_entry) {|e| e.with("entry1", Session)}
17
+ end
18
+ end
19
+
20
+ context "A Segment" do
21
+ setup do
22
+ entry = {
23
+ "link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/segments/12"}],
24
+ "dxp:segment" => {
25
+ "id" => "gaid::-3",
26
+ "name" => "Returning Visitor",
27
+ "dxp:definition" => "ga:visitorType==Returning Visitor"
28
+ }
29
+ }
30
+ @segment = Segment.new_from_entry(entry, Session)
31
+ end
32
+
33
+ should "have an id" do
34
+ assert_equal "gaid::-3", @segment.id
35
+ end
36
+
37
+ should "have a name" do
38
+ assert_equal "Returning Visitor", @segment.name
39
+ end
40
+
41
+ should "have a definition" do
42
+ assert_equal "ga:visitorType==Returning Visitor", @segment.definition
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ module Management
5
+ class WebPropertyTest < MiniTest::Unit::TestCase
6
+ context "the WebProperty class" do
7
+ should "turn entries for path into array of web properties" do
8
+ feed = stub(:entries => ["entry1"])
9
+ Feed.stubs(:new).returns(feed)
10
+
11
+ WebProperty.stubs(:new_from_entry)
12
+ WebProperty.all
13
+
14
+ assert_received(Feed, :new) {|e| e.with(Session, '/accounts/~all/webproperties')}
15
+ assert_received(feed, :entries)
16
+ assert_received(WebProperty, :new_from_entry) {|e| e.with("entry1", Session)}
17
+ end
18
+
19
+ should "find all web properties for a given account" do
20
+ WebProperty.stubs(:all)
21
+ WebProperty.for_account(stub(:session => Session, :path => '/accounts/123456'))
22
+
23
+ assert_received(WebProperty, :all) do |e|
24
+ e.with(Session, '/accounts/123456/webproperties')
25
+ end
26
+ end
27
+ end
28
+
29
+ context "a WebProperty" do
30
+ setup do
31
+ entry = {
32
+ "link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1"}],
33
+ "dxp:property" => [
34
+ {"name" => "ga:accountId", "value" => "1189765"},
35
+ {"name" => "ga:webPropertyId", "value" => 'UA-1189765-1'}
36
+ ]
37
+ }
38
+
39
+ @web_property = WebProperty.new_from_entry(entry, Session)
40
+ end
41
+
42
+ should "have an id" do
43
+ assert_equal "UA-1189765-1", @web_property.id
44
+ end
45
+
46
+ should "have an account_id" do
47
+ assert_equal "1189765", @web_property.account_id
48
+ end
49
+
50
+ should "have profiles" do
51
+ Profile.stubs(:for_web_property)
52
+ @web_property.profiles
53
+ assert_received(Profile, :for_web_property) {|e| e.with(@web_property)}
54
+ end
55
+
56
+ should "have goals" do
57
+ Goal.stubs(:for_web_property)
58
+ @web_property.goals
59
+ assert_received(Goal, :for_web_property) {|e| e.with(@web_property)}
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,141 @@
1
+ require 'test_helper'
2
+
3
+ class ResultKlass
4
+ def initialize(attrs)
5
+ end
6
+ end
7
+
8
+ module Garb
9
+ class ModelTest < MiniTest::Unit::TestCase
10
+ context "A class extended with Garb::Model" do
11
+ setup do
12
+ @test_model = Class.new
13
+ @test_model.extend(Garb::Model)
14
+ end
15
+
16
+ # public API
17
+ should "be able to define metrics" do
18
+ report_parameter = stub(:<<)
19
+ ReportParameter.stubs(:new).returns(report_parameter)
20
+
21
+ @test_model.metrics :visits, :pageviews
22
+
23
+ assert_received(ReportParameter, :new) {|e| e.with(:metrics)}
24
+ assert_received(report_parameter, :<<) {|e| e.with([:visits, :pageviews])}
25
+ end
26
+
27
+ should "be able to define dimensions" do
28
+ report_parameter = stub(:<<)
29
+ ReportParameter.stubs(:new).returns(report_parameter)
30
+
31
+ @test_model.dimensions :page_path, :event_category
32
+
33
+ assert_received(ReportParameter, :new) {|e| e.with(:dimensions)}
34
+ assert_received(report_parameter, :<<) {|e| e.with([:page_path, :event_category])}
35
+ end
36
+
37
+ should "be able to se the instance klass" do
38
+ @test_model.set_instance_klass ResultKlass
39
+ assert_equal ResultKlass, @test_model.instance_klass
40
+ end
41
+
42
+ context "with a profile" do
43
+ setup do
44
+ entry = {
45
+ "title" => "Google Analytics Profile example.com",
46
+ "link" => [{"rel" => "self", "href" => Garb::Management::Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1/profiles/98765"}],
47
+ "dxp:property" => [
48
+ {"name" => "ga:profileId", "value" => "98765"},
49
+ {"name" => "ga:accountId", "value" => "1189765"},
50
+ {"name" => "ga:webPropertyId", "value" => 'UA-1189765-1'}
51
+ ]
52
+ }
53
+
54
+ @profile = Garb::Management::Profile.new_from_entry(entry, Session)
55
+ end
56
+
57
+ context "when getting results" do
58
+ setup do
59
+ @response = stub(:body => "raw report data")
60
+ DataRequest.stubs(:new).returns(stub(:send_request => @response))
61
+ ReportResponse.stubs(:new).returns(stub(:results => ['result']))
62
+
63
+ @test_model.stubs(:metrics).returns(stub(:to_params => {'metrics' => 'ga:visits'}))
64
+ @test_model.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 'ga:pagePath'}))
65
+
66
+ now = Time.now
67
+ Time.stubs(:now).returns(now)
68
+
69
+ # p @profile.id
70
+
71
+ @params = {'ids' => Garb.to_ga(@profile.id),
72
+ 'start-date' => (now - Model::MONTH).strftime('%Y-%m-%d'),
73
+ 'end-date' => now.strftime('%Y-%m-%d'),
74
+ 'metrics' => 'ga:visits',
75
+ 'dimensions' => 'ga:pagePath'}
76
+ end
77
+
78
+ should "get all results" do
79
+ assert_equal ['result'], @test_model.results(@profile)
80
+ assert_received(ReportResponse, :new) {|e| e.with("raw report data", OpenStruct)}
81
+ assert_data_params(@params)
82
+ end
83
+
84
+ should "be able to filter" do
85
+ filter_parameters = stub(:<<)
86
+ FilterParameters.stubs(:new).returns(stub(:parameters => filter_parameters, :to_params => {'filters' => "params"}))
87
+ assert_equal ['result'], @test_model.results(@profile, :filters => {:page_path => '/'})
88
+
89
+ assert_data_params(@params.merge({'filters' => 'params'}))
90
+ assert_received(filter_parameters, :<<) {|e| e.with({:page_path => '/'})}
91
+ end
92
+
93
+ should "be able to set the filter segment by id" do
94
+ assert_equal ['result'], @test_model.results(@profile, :segment_id => 1)
95
+ assert_data_params(@params.merge({'segment' => 'gaid::1'}))
96
+ end
97
+
98
+ should "be able to sort" do
99
+ sort_parameter = stub(:<<)
100
+ sort_parameter.stubs(:to_params => {'sort' => 'sort value'})
101
+ ReportParameter.stubs(:new).returns(sort_parameter)
102
+
103
+ assert_equal ['result'], @test_model.results(@profile, :sort => [:visits])
104
+ assert_received(sort_parameter, :<<) {|e| e.with([:visits])}
105
+ assert_data_params(@params.merge({'sort' => 'sort value'}))
106
+ end
107
+
108
+ should "be able to limit" do
109
+ assert_equal ['result'], @test_model.results(@profile, :limit => 20)
110
+ assert_data_params(@params.merge({'max-results' => 20}))
111
+ end
112
+
113
+ should "be able to offset" do
114
+ assert_equal ['result'], @test_model.results(@profile, :offset => 10)
115
+ assert_data_params(@params.merge({'start-index' => 10}))
116
+ end
117
+
118
+ should "be able to shift the date range" do
119
+ start_date = (Time.now - 1296000)
120
+ end_date = Time.now
121
+
122
+ assert_equal ['result'], @test_model.results(@profile, :start_date => start_date, :end_date => end_date)
123
+ assert_data_params(@params.merge({'start-date' => start_date.strftime('%Y-%m-%d'), 'end-date' => end_date.strftime('%Y-%m-%d')}))
124
+ end
125
+
126
+ should "return a set of results in the defined class" do
127
+ @test_model.stubs(:instance_klass).returns(ResultKlass)
128
+
129
+ assert_equal ['result'], @test_model.results(@profile)
130
+ assert_received(ReportResponse, :new) {|e| e.with("raw report data", ResultKlass)}
131
+ end
132
+ end
133
+
134
+ # should "return results as an array of the class it belongs to, if that class is an ActiveRecord descendant"
135
+ # should "return results as an array of the class it belongs to, if that class is a DataMapper descendant"
136
+ # should "return results as an array of the class it belongs to, if that class is a MongoMapper descendant"
137
+ # should "return results as an array of the class it belongs to, if that class is a Mongoid descendant"
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ class OAuthSessionTest < MiniTest::Unit::TestCase
5
+ context "An instance of OAuthSession" do
6
+ should "have tests" do
7
+ assert true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+
5
+ Exits = Class.new
6
+
7
+ class FakeProfile
8
+ include ProfileReports
9
+ end
10
+
11
+ class ProfileReportsTest < MiniTest::Unit::TestCase
12
+ context "The ProfileReports module" do
13
+ should "define a new method when given a class" do
14
+ ProfileReports.add_report_method(Exits)
15
+ assert_equal true, FakeProfile.new.respond_to?(:exits)
16
+ end
17
+
18
+ should "return results from the given class with options" do
19
+ results = [1,2,3]
20
+ Exits.stubs(:results).returns(results)
21
+ ProfileReports.add_report_method(Exits)
22
+
23
+ profile = FakeProfile.new
24
+ assert_equal results, profile.exits(:start => "now")
25
+ assert_received(Exits, :results) {|e| e.with(profile, :start => "now")}
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+
3
+ module Garb
4
+ class ProfileTest < MiniTest::Unit::TestCase
5
+
6
+ context "The Profile class" do
7
+ setup {@session = Session.new}
8
+
9
+ should "be able to return a list of all profiles" do
10
+ afr = AccountFeedRequest.new
11
+ afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
12
+ AccountFeedRequest.stubs(:new).returns(afr)
13
+
14
+ assert_equal ['12345', '12346'], Profile.all(@session).map(&:id)
15
+ assert_received(AccountFeedRequest, :new) {|e| e.with(@session)}
16
+ end
17
+
18
+ should "return the first profile for a given web property id" do
19
+ profile1 = stub(:web_property_id => '12345', :id => 'abcdef')
20
+ profile2 = stub(:web_property_id => '67890', :id => 'ghijkl')
21
+ entries = [profile1, profile2]
22
+
23
+ Profile.stubs(:all).returns(entries)
24
+
25
+ assert_equal profile1, Profile.first('12345', @session)
26
+
27
+ assert_received(Profile, :all) {|e| e.with(@session)}
28
+ end
29
+
30
+ should "return the first profile for a given table id" do
31
+ profile1 = stub(:id => '12345', :web_property_id => 'abcdef')
32
+ profile2 = stub(:id => '67890', :web_property_id => 'ghijkl')
33
+ entries = [profile1, profile2]
34
+
35
+ Profile.stubs(:all).returns(entries)
36
+
37
+ assert_equal profile2, Profile.first('67890', @session)
38
+
39
+ assert_received(Profile, :all) {|e| e.with(@session)}
40
+ end
41
+ end
42
+
43
+ context "A Profile" do
44
+ setup do
45
+ afr = AccountFeedRequest.new
46
+ afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
47
+
48
+ entry = afr.entries.first
49
+ @profile = Profile.new(entry, Session)
50
+ end
51
+
52
+ should "have a value for :title" do
53
+ assert_equal "Historical", @profile.title
54
+ end
55
+
56
+ should "have a value for :table_id" do
57
+ assert_equal 'ga:12345', @profile.table_id
58
+ end
59
+
60
+ should "have a value for :id" do
61
+ assert_equal '12345', @profile.id
62
+ end
63
+
64
+ should "have a value for :account_id" do
65
+ assert_equal '1111', @profile.account_id
66
+ end
67
+
68
+ should "have a value for :account_name" do
69
+ assert_equal 'Blog Beta', @profile.account_name
70
+ end
71
+
72
+ should "have goals" do
73
+ assert_equal 4, @profile.goals.size
74
+ end
75
+ end
76
+ end
77
+ end