Sha256: 1f57189737905c55ed2a5e8f08f98c717dd2aea0dc4758800d1b030d290782c9

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

RSpec.describe Rack::Tracker::GoogleTagManager do

  def env
    {
      misc: 'foobar',
      user_id: '123'
    }
  end

  describe "with events" do
    describe "default" do
      def env
        {'tracker' => {
          'google_tag_manager' => [
            { 'class_name' => 'Push', 'page' => 'Cart', 'price' => 50, 'content_ids' => ['sku_1', 'sku_2', 'sku_3'] }
          ]
        }}
      end

      subject { described_class.new(env, container: 'somebody').render_head }
      it "will show events" do
        expect(subject).to match(%r{"page":"Cart","price":50,"content_ids":\["sku_1","sku_2","sku_3"\]})
      end
    end
  end

  describe "with dynamic tracker" do
    subject { described_class.new(env, { container: lambda { |env| return env[:misc] }}).render_head }

    it 'will call tracker lambdas to obtain tracking codes' do
      expect(subject).to match(%r{\(window,document,'script','dataLayer','foobar'\)})
    end
  end

  describe '#inject' do
    subject { handler_object.inject(example_response) }
    let(:handler_object) { described_class.new(env, container: 'somebody') }

    before do
      allow(handler_object).to receive(:render_head).and_return('<script>"HEAD"</script>')
      allow(handler_object).to receive(:render_body).and_return('<script>"BODY"</script>')
    end

    context 'with one line html response' do
      let(:example_response) { "<html><head></head><body></body></html>" }

      it 'will have render_head content in head tag' do
        expect(subject).to match(%r{<head>.*<script>"HEAD"</script>.*</head>})
      end

      it 'will have render_body content in body tag' do
        expect(subject).to match(%r{<body>.*<script>"BODY"</script>.*</body>})
      end

    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-tracker-1.13.0 spec/handler/google_tag_manager_spec.rb