Sha256: c31705bb2ada56e54a0767d86404deed35670b628b848e0bb2dadc809ee829da

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 KB

Contents

$:.unshift(File.dirname(__FILE__))
require 'spec_helper'

describe "google_analytics plugin" do
	def setup_google_analytics_plugin(profile_id, mode)
		fake_plugin(:google_analytics) { |plugin|
			plugin.mode = mode
			plugin.conf['google_analytics.profile'] = profile_id
		}
	end

	describe "should render javascript" do
		before do
			@plugin = setup_google_analytics_plugin('53836-1', 'latest')
		end

		it "for footer" do
			snippet = @plugin.footer_proc
			expect(snippet).to eq(expected_html_footer_snippet)
		end
	end

	describe "should render javascript" do
		before do
			@plugin = setup_google_analytics_plugin('53836-1', 'conf')
		end

		it "for footer" do
			snippet = @plugin.footer_proc
			expect(snippet).to be_empty
		end
	end

	describe "should not render when profile_id is empty" do
		before do
			@plugin = setup_google_analytics_plugin(nil, 'latest')
		end

		it "for footer" do
			snippet = @plugin.footer_proc
			expect(snippet).to be_empty
		end
	end

	def expected_html_footer_snippet
		expected = <<-SCRIPT
		<script type="text/javascript"><!--
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape('%3Cscript src="' + gaJsHost + 'google-analytics.com/ga.js" type="text/javascript"%3E%3C/script%3E'));
		// --></script>
		<script type="text/javascript"><!--
		try {
			var pageTracker = _gat._getTracker("UA-53836-1");
			pageTracker._trackPageview();
		} catch (err) {}
		// --></script>
		SCRIPT
		expected.gsub( /^\t/, '' ).chomp
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tdiary-contrib-4.2.0 spec/google_analytics_spec.rb
tdiary-contrib-4.1.3 spec/google_analytics_spec.rb
tdiary-contrib-4.1.2 spec/google_analytics_spec.rb
tdiary-contrib-4.1.1 spec/google_analytics_spec.rb
tdiary-contrib-4.1.0 spec/google_analytics_spec.rb
tdiary-contrib-4.0.5.1 spec/google_analytics_spec.rb
tdiary-contrib-4.0.4 spec/google_analytics_spec.rb
tdiary-contrib-4.0.3 spec/google_analytics_spec.rb