garb-no-activesupport 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.md +250 -0
  2. data/Rakefile +55 -0
  3. data/lib/garb/account.rb +29 -0
  4. data/lib/garb/authentication_request.rb +53 -0
  5. data/lib/garb/data_request.rb +42 -0
  6. data/lib/garb/filter_parameters.rb +41 -0
  7. data/lib/garb/profile.rb +57 -0
  8. data/lib/garb/profile_reports.rb +15 -0
  9. data/lib/garb/report.rb +26 -0
  10. data/lib/garb/report_parameter.rb +25 -0
  11. data/lib/garb/report_response.rb +62 -0
  12. data/lib/garb/reports/bounces.rb +5 -0
  13. data/lib/garb/reports/exits.rb +5 -0
  14. data/lib/garb/reports/pageviews.rb +5 -0
  15. data/lib/garb/reports/unique_pageviews.rb +5 -0
  16. data/lib/garb/reports/visits.rb +5 -0
  17. data/lib/garb/reports.rb +5 -0
  18. data/lib/garb/resource.rb +92 -0
  19. data/lib/garb/session.rb +25 -0
  20. data/lib/garb/version.rb +13 -0
  21. data/lib/garb.rb +38 -0
  22. data/lib/string_ext.rb +20 -0
  23. data/lib/support.rb +39 -0
  24. data/test/fixtures/cacert.pem +67 -0
  25. data/test/fixtures/profile_feed.xml +40 -0
  26. data/test/fixtures/report_feed.xml +46 -0
  27. data/test/test_helper.rb +18 -0
  28. data/test/unit/garb/account_test.rb +53 -0
  29. data/test/unit/garb/authentication_request_test.rb +121 -0
  30. data/test/unit/garb/data_request_test.rb +106 -0
  31. data/test/unit/garb/filter_parameters_test.rb +59 -0
  32. data/test/unit/garb/oauth_session_test.rb +11 -0
  33. data/test/unit/garb/profile_reports_test.rb +29 -0
  34. data/test/unit/garb/profile_test.rb +87 -0
  35. data/test/unit/garb/report_parameter_test.rb +43 -0
  36. data/test/unit/garb/report_response_test.rb +29 -0
  37. data/test/unit/garb/report_test.rb +91 -0
  38. data/test/unit/garb/resource_test.rb +38 -0
  39. data/test/unit/garb/session_test.rb +84 -0
  40. data/test/unit/garb_test.rb +14 -0
  41. data/test/unit/symbol_operator_test.rb +37 -0
  42. metadata +133 -0
@@ -0,0 +1,106 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ module Garb
4
+ class DataRequestTest < MiniTest::Unit::TestCase
5
+
6
+ context "An instance of the DataRequest class" do
7
+ setup do
8
+ @session = Session.new
9
+ @session.auth_token = 'abcdefg123456'
10
+ end
11
+
12
+ should "be able to build the query string from parameters" do
13
+ parameters = {'ids' => '12345', 'metrics' => 'country'}
14
+ data_request = DataRequest.new(@session, "", parameters)
15
+
16
+ query_string = data_request.query_string
17
+
18
+ assert_match(/^\?/, query_string)
19
+
20
+ query_string.sub!(/^\?/, '')
21
+
22
+ assert_equal ["ids=12345", "metrics=country"], query_string.split('&').sort
23
+ end
24
+
25
+ should "return an empty query string if parameters are empty" do
26
+ data_request = DataRequest.new(@session, "")
27
+ assert_equal "", data_request.query_string
28
+ end
29
+
30
+ should "be able to build a uri" do
31
+ url = 'http://example.com'
32
+ expected = URI.parse('http://example.com')
33
+
34
+ assert_equal expected, DataRequest.new(@session, url).uri
35
+ end
36
+
37
+ should "be able to send a request for a single user" do
38
+ @session.stubs(:single_user?).returns(true)
39
+ response = mock('Net::HTTPOK') do |m|
40
+ m.expects(:kind_of?).with(Net::HTTPSuccess).returns(true)
41
+ end
42
+
43
+ data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
44
+ data_request.stubs(:single_user_request).returns(response)
45
+ data_request.send_request
46
+
47
+ assert_received(data_request, :single_user_request)
48
+ end
49
+
50
+ should "be able to send a request for an oauth user" do
51
+ @session.stubs(:single_user?).returns(false)
52
+ @session.stubs(:oauth_user?).returns(true)
53
+ response = mock('Net::HTTPOK') do |m|
54
+ m.expects(:kind_of?).with(Net::HTTPSuccess).returns(true)
55
+ end
56
+
57
+ data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
58
+ data_request.stubs(:oauth_user_request).returns(response)
59
+ data_request.send_request
60
+
61
+ assert_received(data_request, :oauth_user_request)
62
+ end
63
+
64
+ should "raise if the request is unauthorized" do
65
+ @session.stubs(:single_user?).returns(false)
66
+ @session.stubs(:oauth_user?).returns(true)
67
+ response = mock('Net::HTTPUnauthorized', :body => 'Error')
68
+
69
+ data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
70
+ data_request.stubs(:oauth_user_request).returns(response)
71
+
72
+ assert_raises(Garb::DataRequest::ClientError) do
73
+ data_request.send_request
74
+ end
75
+ end
76
+
77
+ should "be able to request via the ouath access token" do
78
+ access_token = stub(:get => "responseobject")
79
+ @session.stubs(:access_token).returns(access_token)
80
+
81
+ data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
82
+ assert_equal 'responseobject', data_request.oauth_user_request
83
+
84
+ assert_received(@session, :access_token)
85
+ assert_received(access_token, :get) {|e| e.with('https://example.com/data?key=value')}
86
+ end
87
+
88
+ should "be able to request via http with an auth token" do
89
+ @session.expects(:auth_token).with().returns('toke')
90
+ response = mock
91
+
92
+ http = mock do |m|
93
+ m.expects(:use_ssl=).with(true)
94
+ m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
95
+ m.expects(:get).with('/data?key=value', 'Authorization' => 'GoogleLogin auth=toke').returns(response)
96
+ end
97
+
98
+ Net::HTTP.expects(:new).with('example.com', 443).returns(http)
99
+
100
+ data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
101
+ assert_equal response, data_request.single_user_request
102
+ end
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ module Garb
4
+ class FilterParametersTest < MiniTest::Unit::TestCase
5
+ def self.should_define_operators(*operators)
6
+ operators.each do |operator|
7
+ should "create an operator and add to parameters for the #{operator} method" do
8
+ new_operator = stub
9
+ symbol = :foo
10
+
11
+ SymbolOperator.expects(:new).with(:bar, operator).returns(new_operator)
12
+ @filter_parameters.filters do
13
+ send(operator.to_sym, :bar, 100)
14
+ end
15
+
16
+ parameter = {new_operator => 100}
17
+ assert_equal parameter, @filter_parameters.parameters.last
18
+ end
19
+ end
20
+ end
21
+
22
+ context "A FilterParameters" do
23
+ setup do
24
+ @filter_parameters = FilterParameters.new
25
+ end
26
+
27
+ should_define_operators :eql, :not_eql, :gt, :gte, :lt, :lte,
28
+ :matches, :does_not_match, :contains, :does_not_contain, :substring, :not_substring
29
+
30
+ should "instance eval for filters" do
31
+ blk = lambda {"in a block"}
32
+
33
+ @filter_parameters.expects(:instance_eval)
34
+ @filter_parameters.filters(&blk)
35
+ end
36
+
37
+ context "when converting parameters hash into query string parameters" do
38
+ should "parameterize hash operators and join elements with AND" do
39
+ @filter_parameters.filters do
40
+ eql(:city, 'New York City')
41
+ eql(:state, 'New York')
42
+ end
43
+
44
+ params = ['ga:city%3D%3DNew+York+City', 'ga:state%3D%3DNew+York']
45
+ assert_equal params, @filter_parameters.to_params['filters'].split(';').sort
46
+ end
47
+
48
+ should "properly encode operators" do
49
+ @filter_parameters.filters do
50
+ contains(:page_path, 'New York')
51
+ end
52
+
53
+ params = {'filters' => 'ga:pagePath%3D~New+York'}
54
+ assert_equal params, @filter_parameters.to_params
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/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 File.join(File.dirname(__FILE__), '..', '..', '/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,87 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/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
+ url = 'https://www.google.com/analytics/feeds/accounts/default'
11
+
12
+ xml = read_fixture('profile_feed.xml')
13
+
14
+ data_request = mock
15
+ data_request.expects(:send_request).with().returns(stub(:body => xml))
16
+
17
+ DataRequest.expects(:new).with(@session, url).returns(data_request)
18
+
19
+ entries = [stub]
20
+
21
+ Profile::Entry.expects(:parse).with(xml).returns(entries)
22
+
23
+ profiles = []
24
+ entries.each do |entry|
25
+ profile = stub
26
+ profiles << profile
27
+ Garb::Profile.expects(:new).with(entry, @session).returns(profile)
28
+ end
29
+
30
+ assert_equal profiles, Profile.all(@session)
31
+ end
32
+
33
+ should "return the first profile for a given web property id" do
34
+ profile1 = stub(:web_property_id => '12345', :id => 'abcdef')
35
+ profile2 = stub(:web_property_id => '67890', :id => 'ghijkl')
36
+ entries = [profile1, profile2]
37
+
38
+ Garb::Profile.stubs(:all).returns(entries)
39
+
40
+ assert_equal profile1, Garb::Profile.first('12345', @session)
41
+
42
+ assert_received(Garb::Profile, :all) {|e| e.with(@session)}
43
+ end
44
+
45
+ should "return the first profile for a given table id" do
46
+ profile1 = stub(:id => '12345', :web_property_id => 'abcdef')
47
+ profile2 = stub(:id => '67890', :web_property_id => 'ghijkl')
48
+ entries = [profile1, profile2]
49
+
50
+ Garb::Profile.stubs(:all).returns(entries)
51
+
52
+ assert_equal profile2, Garb::Profile.first('67890', @session)
53
+
54
+ assert_received(Garb::Profile, :all) {|e| e.with(@session)}
55
+ end
56
+ end
57
+
58
+ context "An instance of the Profile class" do
59
+
60
+ setup do
61
+ @entry = (Profile::Entry.parse(read_fixture('profile_feed.xml'))).first
62
+ @profile = Profile.new(@entry, Session)
63
+ end
64
+
65
+ should "have a value for :title" do
66
+ assert_equal "Historical", @profile.title
67
+ end
68
+
69
+ should "have a value for :table_id" do
70
+ assert_equal 'ga:12345', @profile.table_id
71
+ end
72
+
73
+ should "have a value for :id" do
74
+ assert_equal '12345', @profile.id
75
+ end
76
+
77
+ should "have a value for :account_id" do
78
+ assert_equal '1111', @profile.account_id
79
+ end
80
+
81
+ should "have a value for :account_name" do
82
+ assert_equal 'Blog Beta', @profile.account_name
83
+ end
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ module Garb
4
+ class ReportParameterTest < MiniTest::Unit::TestCase
5
+
6
+ context "An instance of the ReportParameter class" do
7
+ setup do
8
+ @metrics = ReportParameter.new(:metrics)
9
+ end
10
+
11
+ should "have a name" do
12
+ assert_equal "metrics", @metrics.name
13
+ end
14
+
15
+ should "have a list of elements" do
16
+ assert_equal [], @metrics.elements
17
+ end
18
+
19
+ should "be able to add new elements" do
20
+ assert_equal(@metrics, @metrics << :page_path)
21
+ assert_equal [:page_path], @metrics.elements
22
+ end
23
+
24
+ should "merge an array of elements" do
25
+ assert_equal(@metrics, @metrics << [:page_path])
26
+ assert_equal [:page_path], @metrics.elements
27
+ end
28
+
29
+ context "converting to params" do
30
+ should "be able to format the parameters into strings" do
31
+ @metrics << :page_path
32
+ assert_equal({'metrics' => 'ga:pagePath'}, @metrics.to_params)
33
+ end
34
+
35
+ should "join multiple symbol elements" do
36
+ @metrics << :page_path << :city
37
+ assert_equal({'metrics' => 'ga:pagePath,ga:city'}, @metrics.to_params)
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ module Garb
4
+ class ReportResponseTest < MiniTest::Unit::TestCase
5
+ context "An instance of the ReportResponse class" do
6
+ setup do
7
+ @xml = File.read(File.join(File.dirname(__FILE__), '..', '..', "/fixtures/report_feed.xml"))
8
+ @response = ReportResponse.new(@xml)
9
+ end
10
+
11
+ should "parse xml response with happymapper" do
12
+ h1 = {"city"=>"(not set)", "pageviews"=>"33", "country"=>"(not set)"}
13
+ h2 = {"city"=>"Kabul", "pageviews"=>"2", "country"=>"Afghanistan"}
14
+ h3 = {"city"=>"Tirana", "pageviews"=>"1", "country"=>"Albania"}
15
+
16
+ OpenStruct.expects(:new).with(h1).returns('entry1')
17
+ OpenStruct.expects(:new).with(h2).returns('entry2')
18
+ OpenStruct.expects(:new).with(h3).returns('entry3')
19
+
20
+ assert_equal(['entry1', 'entry2', 'entry3'], @response.parse)
21
+ end
22
+
23
+ should "have results or parse them" do
24
+ @response.expects(:parse)
25
+ @response.results
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,91 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ module Garb
4
+ # Also tests Garb::Resource, which is the basis for Garb::Report
5
+ class ReportTest < MiniTest::Unit::TestCase
6
+ context "An instance of the Report class" do
7
+ setup do
8
+ @now = Time.now
9
+ Time.stubs(:now).returns(@now)
10
+ @profile = stub(:table_id => 'ga:1234', :session => Session)
11
+ @report = Report.new(@profile)
12
+ end
13
+
14
+ %w(metrics dimensions sort).each do |param|
15
+ should "have parameters for #{param}" do
16
+ assert @report.send(:"#{param}").is_a?(ReportParameter)
17
+ end
18
+
19
+ should "clear parameters for #{param}" do
20
+ assert_equal({}, @report.send(:"clear_#{param}").to_params)
21
+ end
22
+ end
23
+
24
+ should "have filter parameters for filters" do
25
+ assert @report.filters.is_a?(FilterParameters)
26
+ end
27
+
28
+ should "add new filters to filter parameters" do
29
+ @report.clear_filters
30
+ hash = {:thing.gt => 'val'}
31
+ @report.filters hash
32
+
33
+ assert_equal hash, @report.filters.parameters.first
34
+ end
35
+
36
+ should "clear filter parameters for filters" do
37
+ assert_equal({}, @report.clear_filters.to_params)
38
+ end
39
+
40
+ should "have default parameters" do
41
+ @report.stubs(:format_time).returns('2009-08-01')
42
+ params = {'ids' => 'ga:1234', 'start-date' => '2009-08-01', 'end-date' => '2009-08-01'}
43
+ assert_equal params, @report.default_params
44
+ end
45
+
46
+ should "collect params from metrics, dimensions, filters, sort, and defaults" do
47
+ @report.stubs(:metrics).returns(stub(:to_params => {'metrics' => 6}))
48
+ @report.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 5}))
49
+ @report.stubs(:filters).returns(stub(:to_params => {'filters' => 4}))
50
+ @report.stubs(:sort).returns(stub(:to_params => {'sort' => 3}))
51
+ @report.stubs(:page_params).returns({'page_params' => 2})
52
+ @report.stubs(:default_params).returns({'default_params' => 1})
53
+
54
+ params = {'metrics' => 6, 'dimensions' => 5, 'filters' => 4, 'sort' => 3, 'page_params' => 2, 'default_params' => 1}
55
+ assert_equal params, @report.params
56
+ end
57
+
58
+ should "format time" do
59
+ assert_equal @now.strftime('%Y-%m-%d'), @report.format_time(@now)
60
+ end
61
+
62
+ should "send a data request to GA" do
63
+ response = mock {|m| m.expects(:body).returns('response body') }
64
+ request = mock {|m| m.expects(:send_request).returns(response) }
65
+ @report.expects(:params).returns('params')
66
+
67
+ DataRequest.expects(:new).with(Session, Garb::Report::URL, 'params').returns(request)
68
+ assert_equal 'response body', @report.send_request_for_body
69
+ end
70
+
71
+ should "fetch and parse results from GA" do
72
+ @report.expects(:send_request_for_body).with().returns('xml')
73
+ ReportResponse.expects(:new).with('xml').returns(mock(:results => ['entry']))
74
+ assert_equal ['entry'], @report.results
75
+ end
76
+ end
77
+
78
+ context "An instance of the Report class with initial options" do
79
+ setup do
80
+ @profile = stub(:table_id => 'ga:1234')
81
+ @report = Report.new(@profile, :limit => 10, :offset => 20)
82
+ end
83
+
84
+ should "have page paramaters" do
85
+ params = {'max-results' => 10, 'start-index' => 20}
86
+ assert_equal params, @report.page_params
87
+ end
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ class TestReport
4
+ extend Garb::Resource
5
+ end
6
+
7
+ # Most of the resource testing is done as a part of ReportTest
8
+ class ResourceTest < MiniTest::Unit::TestCase
9
+
10
+ context "A class with Garb::Resource mixed in" do
11
+ should "get results from GA" do
12
+ profile = stub(:is_a? => true)
13
+ TestReport.expects(:send_request_for_body).returns('xml')
14
+ Garb::ReportResponse.expects(:new).with('xml').returns(mock(:results => 'analytics'))
15
+
16
+ assert_equal 'analytics', TestReport.results(profile)
17
+ end
18
+
19
+ should "get results from GA using a specific user session" do
20
+ profile = '123'
21
+ session = Garb::Session.new
22
+ TestReport.expects(:send_request_for_body).returns('xml')
23
+ Garb::ReportResponse.expects(:new).with('xml').returns(mock(:results => 'analytics'))
24
+ Garb::Profile.expects(:first).with(profile, session).returns(mock('Garb::Profile'))
25
+
26
+ assert_equal 'analytics', TestReport.results(profile, :session => session)
27
+ end
28
+
29
+ should "return an empty result set if profile is invalid" do
30
+ profile = '123'
31
+ TestReport.expects(:send_request_for_body).never
32
+ Garb::ReportResponse.expects(:new).never
33
+
34
+ Garb::Profile.expects(:first).returns(nil)
35
+ assert_equal [], TestReport.results(profile)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,84 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
2
+
3
+ module Garb
4
+ class SessionTest < MiniTest::Unit::TestCase
5
+
6
+ context "The Session class" do
7
+
8
+ should "be able retrieve an auth_token for a user" do
9
+ auth_request = mock {|m| m.expects(:auth_token).with({}).returns('toke') }
10
+ AuthenticationRequest.expects(:new).with('email', 'password', {}).returns(auth_request)
11
+
12
+ Session.login('email', 'password')
13
+ assert_equal 'toke', Session.auth_token
14
+ end
15
+
16
+ should "be able retrieve an auth_token for a user with secure ssl" do
17
+ opts = {:secure => true, :account_type => 'GOOGLE'}
18
+ auth_request = mock {|m| m.expects(:auth_token).with(opts).returns('toke') }
19
+ AuthenticationRequest.expects(:new).with('email', 'password', opts).returns(auth_request)
20
+
21
+ Session.login('email', 'password', opts)
22
+ assert_equal 'toke', Session.auth_token
23
+ end
24
+
25
+ should "retain the email address for this session" do
26
+ AuthenticationRequest.stubs(:new).returns(stub(:auth_token => 'toke'))
27
+
28
+ Session.login('email', 'password')
29
+ assert_equal 'email', Session.email
30
+ end
31
+
32
+ should "know if the Session is for a single user" do
33
+ Session.auth_token = "abcdefg1234567"
34
+ assert_equal true, Session.single_user?
35
+ end
36
+
37
+ should "know if the Session is for oauth" do
38
+ Session.access_token = 'some_oauth_access_token'
39
+ assert_equal true, Session.oauth_user?
40
+ end
41
+ end
42
+
43
+ context "A Session" do
44
+ setup do
45
+ @session = Session.new
46
+ end
47
+
48
+ should "be able retrieve an auth_token for a user" do
49
+ auth_request = mock {|m| m.expects(:auth_token).with({}).returns('toke') }
50
+ AuthenticationRequest.expects(:new).with('email', 'password', {}).returns(auth_request)
51
+
52
+ @session.login('email', 'password')
53
+ assert_equal 'toke', @session.auth_token
54
+ end
55
+
56
+ should "be able retrieve an auth_token for a user with secure ssl" do
57
+ opts = {:secure => true, :account_type => 'GOOGLE'}
58
+ auth_request = mock {|m| m.expects(:auth_token).with(opts).returns('toke') }
59
+ AuthenticationRequest.expects(:new).with('email', 'password', opts).returns(auth_request)
60
+
61
+ @session.login('email', 'password', opts)
62
+ assert_equal 'toke', @session.auth_token
63
+ end
64
+
65
+ should "retain the email address for this session" do
66
+ AuthenticationRequest.stubs(:new).returns(stub(:auth_token => 'toke'))
67
+
68
+ @session.login('email', 'password')
69
+ assert_equal 'email', @session.email
70
+ end
71
+
72
+ should "know if the Session is for a single user" do
73
+ @session.auth_token = "abcdefg1234567"
74
+ assert_equal true, @session.single_user?
75
+ end
76
+
77
+ should "know if the Session is for oauth" do
78
+ @session.access_token = 'some_oauth_access_token'
79
+ assert_equal true, @session.oauth_user?
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ class GarbTest < MiniTest::Unit::TestCase
4
+ context "The Garb module" do
5
+ should 'prefix a string with ga: for GA' do
6
+ assert_equal '-ga:bob', Garb.to_google_analytics(stub(:to_google_analytics => '-ga:bob'))
7
+ assert_equal 'ga:bob', Garb.to_google_analytics('bob')
8
+ end
9
+
10
+ should 'remove ga: prefix' do
11
+ assert_equal 'bob', Garb.from_google_analytics('ga:bob')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ class SymbolOperatorTest < MiniTest::Unit::TestCase
4
+ context "An instance of a SymbolOperator" do
5
+ should "lower camelize the target" do
6
+ assert_equal "ga:uniqueVisits==", SymbolOperator.new(:unique_visits, :eql).to_google_analytics
7
+ end
8
+
9
+ should "return target and operator together" do
10
+ assert_equal "ga:metric==", SymbolOperator.new(:metric, :eql).to_google_analytics
11
+ end
12
+
13
+ should "prefix the operator to the target" do
14
+ assert_equal "-ga:metric", SymbolOperator.new(:metric, :desc).to_google_analytics
15
+ end
16
+
17
+ # should "know if it is equal to another operator" do
18
+ # op1 = SymbolOperator.new(:hello, "==")
19
+ # op2 = SymbolOperator.new(:hello, "==")
20
+ # assert_equal op1, op2
21
+ # end
22
+ #
23
+ # should "not be equal to another operator if target, operator, or prefix is different" do
24
+ # op1 = SymbolOperator.new(:hello, "==")
25
+ # op2 = SymbolOperator.new(:hello, "==", true)
26
+ # refute_equal op1, op2
27
+ #
28
+ # op1 = SymbolOperator.new(:hello1, "==")
29
+ # op2 = SymbolOperator.new(:hello2, "==")
30
+ # refute_equal op1, op2
31
+ #
32
+ # op1 = SymbolOperator.new(:hello, "!=")
33
+ # op2 = SymbolOperator.new(:hello, "==")
34
+ # refute_equal op1, op2
35
+ # end
36
+ end
37
+ end