Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed tests that I did not realize were broken, awesome

  • Loading branch information...
commit 22eb2dd16fc8a891abe3797bcfea6611018f38ae 1 parent 713d131
@tpitale tpitale authored
View
5 lib/garb.rb
@@ -57,10 +57,7 @@ def from_google_analytics(thing)
alias :from_ga :from_google_analytics
def parse_properties(entry)
- entry['dxp:property'].inject({}) do |hash, p|
- hash[Garb.from_ga(p['name'])] = p['value']
- hash
- end
+ Hash[entry['dxp:property'].map {|p| [Garb.from_ga(p['name']),p['value']]}]
end
def parse_link(entry, rel)
View
2  lib/garb/profile_reports.rb
@@ -3,7 +3,7 @@ module ProfileReports
def self.add_report_method(klass)
# demodulize leaves potential to redefine
# these methods given different namespaces
- method_name = klass.name.demodulize.underscore
+ method_name = klass.name.to_s.demodulize.underscore
return unless method_name.length > 0
class_eval <<-CODE
View
4 test/unit/garb/model_test.rb
@@ -51,7 +51,7 @@ class ModelTest < MiniTest::Unit::TestCase
]
}
- @profile = Garb::Management::Profile.new(entry, Session)
+ @profile = Garb::Management::Profile.new_from_entry(entry, Session)
end
context "when getting results" do
@@ -66,6 +66,8 @@ class ModelTest < MiniTest::Unit::TestCase
now = Time.now
Time.stubs(:new).returns(now)
+ # p @profile.id
+
@params = {'ids' => Garb.to_ga(@profile.id),
'start-date' => (now - Model::MONTH).strftime('%Y-%m-%d'),
'end-date' => now.strftime('%Y-%m-%d'),
View
29 test/unit/garb/resource_test.rb
@@ -1,49 +1,50 @@
require 'test_helper'
-class TestReport
- extend Garb::Resource
-end
-
# Most of the resource testing is done as a part of ReportTest
class ResourceTest < MiniTest::Unit::TestCase
context "A class with Garb::Resource mixed in" do
+ setup do
+ @test_report = Class.new
+ @test_report.extend(Garb::Resource)
+ end
+
should "get results from GA" do
profile = stub(:is_a? => true)
- TestReport.expects(:send_request_for_body).returns('xml')
+ @test_report.expects(:send_request_for_body).returns('xml')
Garb::ReportResponse.expects(:new).with('xml', OpenStruct).returns(mock(:results => 'analytics'))
- assert_equal 'analytics', TestReport.results(profile)
+ assert_equal 'analytics', @test_report.results(profile)
end
should "get results from GA using a specific user session" do
profile = '123'
session = Garb::Session.new
- TestReport.expects(:send_request_for_body).returns('xml')
+ @test_report.expects(:send_request_for_body).returns('xml')
Garb::ReportResponse.expects(:new).with('xml', OpenStruct).returns(mock(:results => 'analytics'))
Garb::Profile.expects(:first).with(profile, session).returns(mock('Garb::Profile'))
- assert_equal 'analytics', TestReport.results(profile, :session => session)
+ assert_equal 'analytics', @test_report.results(profile, :session => session)
end
should "permit setting a segment id" do
- TestReport.set_segment_id 1
- assert_equal "gaid::1", TestReport.segment
+ @test_report.set_segment_id 1
+ assert_equal "gaid::1", @test_report.segment
end
should "permit setting a klass used for instantiation of results" do
TestKlass = Class.new(OpenStruct)
- TestReport.set_instance_klass TestKlass
- assert_equal TestKlass, TestReport.instance_klass
+ @test_report.set_instance_klass TestKlass
+ assert_equal TestKlass, @test_report.instance_klass
end
should "return an empty result set if profile is invalid" do
profile = '123'
- TestReport.expects(:send_request_for_body).never
+ @test_report.expects(:send_request_for_body).never
Garb::ReportResponse.expects(:new).never
Garb::Profile.expects(:first).returns(nil)
- assert_equal [], TestReport.results(profile)
+ assert_equal [], @test_report.results(profile)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.