diff --git a/Gemfile b/Gemfile index fd638c2..08dd6c8 100644 --- a/Gemfile +++ b/Gemfile @@ -12,4 +12,5 @@ gem 'unicorn' group :test, :development do gem 'rack-test' gem 'test-unit' + gem "webmock" end diff --git a/Gemfile.lock b/Gemfile.lock index 656d44e..ed60e07 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,6 +31,10 @@ GEM unicorn (6.1.0) kgio (~> 2.6) raindrops (~> 0.7) + webmock (3.14.0) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS ruby @@ -43,9 +47,10 @@ DEPENDENCIES sinatra test-unit unicorn + webmock RUBY VERSION ruby 3.2.0p0 BUNDLED WITH - 2.4.1 + 2.4.1 \ No newline at end of file diff --git a/claw.rb b/claw.rb index 2c24db0..d914aee 100644 --- a/claw.rb +++ b/claw.rb @@ -154,6 +154,11 @@ class Claw < Sinatra::Base redirect format(link, version: version, release: filename), 302 end + def page_view(distro, page) + # Run this async + @google_analytics.page_view(distro, page) + end + def get_version_from_filename(filename) match = /.*_(?[\d.]+(-beta\.[\d]+)?)_.*/.match(filename) match[:version] diff --git a/claw_test.rb b/claw_test.rb index c6affad..7b93266 100644 --- a/claw_test.rb +++ b/claw_test.rb @@ -9,6 +9,7 @@ require_relative 'claw' require 'test/unit' require 'rack/test' +require 'webmock/test_unit' VERSIONED_V8_RELEASE_LINK = 'https://s3-us-west-1.amazonaws.com/v8-cf-cli-releases/releases/v%{version}/%{release}' VERSIONED_V7_RELEASE_LINK = 'https://s3-us-west-1.amazonaws.com/v7-cf-cli-releases/releases/v%{version}/%{release}' @@ -59,6 +60,15 @@ class ClawTest < Test::Unit::TestCase include Rack::Test::Methods + # TODO: test if timeout does not block our request + # TODO: that we are calling our tracking function from all expected locations + # TODO: + + def setup + stub_request(:get, /www.google-analytics.com/). + to_return(status: 200, body: "", headers: {}) + end + def app Claw end