Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- mobile analytics should use specific utmcc and no utmhid (same as g…

…oogle php code is doing)

- full test with webmock
  • Loading branch information...
commit 5ea7c514899e5464b17f2a11fba38c4433c47d44 1 parent 704635d
@mreinsch mreinsch authored
View
2  Gemfile
@@ -7,5 +7,7 @@ gem "rails", "~> 3.0.3"
group :test do
gem 'shoulda'
+ gem 'webmock'
+ gem 'flexmock'
end
View
12 Gemfile.lock
@@ -2,7 +2,7 @@ PATH
remote: .
specs:
garails (0.0.5)
- gabbara (~> 0.0.4)
+ gabbara (~> 0.0.5)
GEM
remote: http://rubygems.org/
@@ -34,11 +34,14 @@ GEM
activemodel (= 3.0.3)
activesupport (= 3.0.3)
activesupport (3.0.3)
+ addressable (2.2.5)
arel (2.0.6)
builder (2.1.2)
+ crack (0.1.8)
erubis (2.6.6)
abstract (>= 1.0.0)
- gabbara (0.0.4)
+ flexmock (0.9.0)
+ gabbara (0.0.5)
activesupport
i18n (0.5.0)
mail (2.2.12)
@@ -72,11 +75,16 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
+ webmock (1.6.2)
+ addressable (>= 2.2.2)
+ crack (>= 0.1.7)
PLATFORMS
ruby
DEPENDENCIES
+ flexmock
garails!
rails (~> 3.0.3)
shoulda
+ webmock
View
2  app/controllers/garails/google_analytics_controller.rb
@@ -18,7 +18,7 @@ class Garails::GoogleAnalyticsController < ActionController::Base
def utm
if Garails.ga_setup?
- g = Garails.mobile_gabba(request, :utmn => params[:utmn])
+ g = Garails.mobile_gabba(request, :utmn => params[:utmn], :utmcc => "__utma=999.999.999.999.999.1;", :utmhid => "")
g.page_view('', :utmvid => @visitor_id)
end
response.headers.merge(UTM_HEADERS)
View
2  garails.gemspec
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency("gabbara", "~> 0.0.4")
+ s.add_dependency("gabbara", "~> 0.0.5")
end
View
17 test/controllers/google_analytics_controller_test.rb
@@ -4,13 +4,18 @@ class GoogleAnalyticsControllerTest < ActionController::TestCase
tests Garails::GoogleAnalyticsController
context "GET to :utm" do
- setup { get :utm, :format => :gif }
+ setup do
+ flexmock(@controller, :rand => 405451725)
+ stub_analytics("0xd5d59357458cc280")
+ get :utm, :format => :gif
+ end
should respond_with :success
should assign_to(:visitor_id)
end
context "GET to :utm with guid" do
setup do
+ stub_analytics("0x80620d96c658ed0f")
request.env["HTTP_X_DCMGUID"] = "blah"
get :utm, :format => :gif
end
@@ -18,4 +23,14 @@ class GoogleAnalyticsControllerTest < ActionController::TestCase
should assign_to(:visitor_id)
end
+ def stub_analytics(vid)
+ query = {
+ :utmac => "MO-12345678-9", :utmcc => "__utma=999.999.999.999.999.1;", :utmcs => "UTF-8",
+ :utmhn => "example.org", :utmip => "0.0.0.0", :utmr => "-", :utmul => "en-us",
+ :utmvid => vid, :utmwv => "4.4sh" }
+ stub_request(:get, "http://www.google-analytics.com/__utm.gif").
+ with(:query => query, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Rails%20Testing'}).
+ to_return(:status => 200, :body => "", :headers => {})
+ end
+
end
View
1  test/test_app/config/initializers/garails.rb
@@ -0,0 +1 @@
+Garails.ga_account = 'UA-12345678-9'
View
2  test/test_helper.rb
@@ -3,4 +3,6 @@
require 'test_app/config/environment'
require 'rails/test_help'
+require 'webmock/test_unit'
+require 'flexmock/test_unit'
Please sign in to comment.
Something went wrong with that request. Please try again.