rubaidh-google_analytics 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
  require 'rake/gempackagetask'
5
+ require 'rcov/rcovtask'
5
6
  require 'rubyforge'
6
7
 
7
8
  desc 'Default: run unit tests.'
@@ -16,6 +17,12 @@ Rake::TestTask.new(:test) do |t|
16
17
  t.verbose = true
17
18
  end
18
19
 
20
+ Rcov::RcovTask.new do |t|
21
+ t.test_files = FileList["test/**/*_test.rb"]
22
+ t.verbose = true
23
+ t.rcov_opts = ["-x", "^/"]
24
+ end
25
+
19
26
  desc 'Generate documentation for the google_analytics plugin.'
20
27
  Rake::RDocTask.new(:rdoc) do |rdoc|
21
28
  rdoc.rdoc_dir = 'rdoc'
@@ -38,3 +45,6 @@ task :release => [:clean, :package] do |t|
38
45
  rubyforge.login
39
46
  rubyforge.add_release gem_spec.rubyforge_project, gem_spec.name, gem_spec.version.to_s, "pkg/#{gem_spec.name}-#{gem_spec.version}.gem"
40
47
  end
48
+
49
+ task :bamboo => [ :package, :rcov ] do
50
+ end
@@ -18,9 +18,9 @@ module Rubaidh # :nodoc:
18
18
  # (see http://www.google.com/support/googleanalytics/bin/answer.py?answer=55527&topic=11006)
19
19
  def add_google_analytics_code
20
20
  if GoogleAnalytics.defer_load
21
- response.body.sub! '</body>', "#{google_analytics_code}</body>" if response.body.respond_to?(:sub!)
21
+ response.body.sub! /<\/[bB][oO][dD][yY]>/, "#{google_analytics_code}</body>" if response.body.respond_to?(:sub!)
22
22
  else
23
- response.body.sub! '<body>', "<body>#{google_analytics_code}" if response.body.respond_to?(:sub!)
23
+ response.body.sub! /(<[bB][oO][dD][yY][^>]*>)/, "\\1#{google_analytics_code}" if response.body.respond_to?(:sub!)
24
24
  end
25
25
  end
26
26
  end
@@ -4,6 +4,29 @@ require 'rubygems'
4
4
  require 'mocha'
5
5
  RAILS_ENV = 'test'
6
6
 
7
+ class TestMixin
8
+ class MockRequest
9
+ attr_accessor :format
10
+ end
11
+ class MockResponse
12
+ attr_accessor :body
13
+ end
14
+
15
+ include Rubaidh::GoogleAnalyticsMixin
16
+ attr_accessor :request, :response
17
+
18
+ def initialize
19
+ self.request = MockRequest.new
20
+ self.response = MockResponse.new
21
+ end
22
+
23
+ # override the mixin's method
24
+ def google_analytics_code
25
+ "Google Code"
26
+ end
27
+ end
28
+
29
+
7
30
  class GoogleAnalyticsTest < Test::Unit::TestCase
8
31
  def setup
9
32
  @ga = Rubaidh::GoogleAnalytics.new
@@ -115,5 +138,45 @@ class GoogleAnalyticsTest < Test::Unit::TestCase
115
138
  foo = Rubaidh::GoogleAnalytics.request_tracked_path
116
139
  assert_nil(Rubaidh::GoogleAnalytics.override_trackpageview)
117
140
  end
118
-
141
+
142
+ # Test the before_filter method does what we expect by subsituting the body tags and inserting
143
+ # some google code for us automagically.
144
+ def test_add_google_analytics_code
145
+ # setup our test mixin
146
+ mixin = TestMixin.new
147
+
148
+ # bog standard body tag
149
+ Rubaidh::GoogleAnalytics.defer_load = false
150
+ mixin.response.body = "<body><p>some text</p></body>"
151
+ mixin.add_google_analytics_code
152
+ assert_equal mixin.response.body, '<body>Google Code<p>some text</p></body>'
153
+
154
+ Rubaidh::GoogleAnalytics.defer_load = true
155
+ mixin.response.body = "<body><p>some text</p></body>"
156
+ mixin.add_google_analytics_code
157
+ assert_equal mixin.response.body, '<body><p>some text</p>Google Code</body>'
158
+
159
+ # body tag upper cased (ignoring this is semantically incorrect)
160
+ Rubaidh::GoogleAnalytics.defer_load = false
161
+ mixin.response.body = "<BODY><p>some text</p></BODY>"
162
+ mixin.add_google_analytics_code
163
+ assert_equal mixin.response.body, '<BODY>Google Code<p>some text</p></BODY>'
164
+
165
+ Rubaidh::GoogleAnalytics.defer_load = true
166
+ mixin.response.body = "<BODY><p>some text</p></BODY>"
167
+ mixin.add_google_analytics_code
168
+ assert_equal mixin.response.body, '<BODY><p>some text</p>Google Code</body>'
169
+
170
+ # body tag has additional attributes
171
+ Rubaidh::GoogleAnalytics.defer_load = false
172
+ mixin.response.body = '<body style="background-color:red"><p>some text</p></body>'
173
+ mixin.add_google_analytics_code
174
+ assert_equal mixin.response.body, '<body style="background-color:red">Google Code<p>some text</p></body>'
175
+
176
+ Rubaidh::GoogleAnalytics.defer_load = true
177
+ mixin.response.body = '<body style="background-color:red"><p>some text</p></body>'
178
+ mixin.add_google_analytics_code
179
+ assert_equal mixin.response.body, '<body style="background-color:red"><p>some text</p>Google Code</body>'
180
+ end
181
+
119
182
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubaidh-google_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graeme Mathieson
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-02 00:00:00 -08:00
12
+ date: 2009-04-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: activesupport
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements: