Sha256: 111c320ee77524b4def929444c843c5447b141042851b1ad7b55d56cbc45f6fe

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 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
			<!-- Global site tag (gtag.js) - Google Analytics -->
			<script async src="https://www.googletagmanager.com/gtag/js?id=UA-53836-1"></script>
			<script>
				window.dataLayer = window.dataLayer || [];
				function gtag(){dataLayer.push(arguments);}
				gtag('js', new Date());

				gtag('config', 'UA-53836-1');
			</script>
		SCRIPT
		expected.gsub( /^\t/, '' ).chomp
	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tdiary-contrib-5.3.0 spec/google_analytics_spec.rb
tdiary-contrib-5.2.4 spec/google_analytics_spec.rb
tdiary-contrib-5.2.3 spec/google_analytics_spec.rb
tdiary-contrib-5.2.2 spec/google_analytics_spec.rb
tdiary-contrib-5.2.1 spec/google_analytics_spec.rb
tdiary-contrib-5.2.0 spec/google_analytics_spec.rb