Sha256: c37d3316d3ad24cc3f9e6aa8880cf9a13eef62cb079396e3a7c6893533470c57

Contents?: true

Size: 1.47 KB

Versions: 34

Compression:

Stored size: 1.47 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>
			(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
			(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
			m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
			})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

			ga('create', 'UA-53836-1', 'auto');
			ga('send', 'pageview');
		// --></script>
		SCRIPT
		expected.gsub( /^\t/, '' ).chomp
	end
end

Version data entries

34 entries across 28 versions & 2 rubygems

Version Path
tdiary-contrib-5.1.7 spec/google_analytics_spec.rb
tdiary-contrib-5.1.6 spec/google_analytics_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/spec/google_analytics_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/bundler/gems/tdiary-contrib-d1e41204db13/spec/google_analytics_spec.rb
tdiary-contrib-5.1.5 spec/google_analytics_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/spec/google_analytics_spec.rb
tdiary-contrib-5.1.4 spec/google_analytics_spec.rb
tdiary-contrib-5.1.3 spec/google_analytics_spec.rb
tdiary-contrib-5.1.2 spec/google_analytics_spec.rb
tdiary-contrib-5.1.1 spec/google_analytics_spec.rb
tdiary-contrib-5.1.0 spec/google_analytics_spec.rb
tdiary-contrib-5.0.13 spec/google_analytics_spec.rb
tdiary-contrib-5.0.12 spec/google_analytics_spec.rb
tdiary-contrib-5.0.11 spec/google_analytics_spec.rb
tdiary-contrib-5.0.10 spec/google_analytics_spec.rb
tdiary-contrib-5.0.9 spec/google_analytics_spec.rb
tdiary-contrib-5.0.8 spec/google_analytics_spec.rb
tdiary-contrib-5.0.7 spec/google_analytics_spec.rb
tdiary-contrib-5.0.6 spec/google_analytics_spec.rb
tdiary-contrib-5.0.5 spec/google_analytics_spec.rb