Sha256: d3ac3e01a99048e78705303aca34e9cf8a2ce79eec21f8174c22c6933b85a733

Contents?: true

Size: 1.34 KB

Versions: 23

Compression:

Stored size: 1.34 KB

Contents

TestController = Struct.new(:env) do
  include Rack::Tracker::Controller

  def index
    tracker do |t|
      t.google_analytics :send, category: 'foo'
      t.google_analytics :ecommerce, {
        type: 'addTransaction',
        some: 'thing'
      }
      %w(foo bar).each do |item|
        t.google_analytics :ecommerce, {
          type: 'addItem',
          name: item
        }
      end
      t.facebook :track, { id: '1', value: 1, currency: 'USD' }
    end
  end
end


RSpec.describe Rack::Tracker::Controller do
  describe '#tracker' do
    let(:send)       { { 'category' => 'foo', 'class_name' => 'Send' } }
    let(:trx)        { { 'type' => 'addTransaction', 'some' => 'thing', 'class_name' => 'Ecommerce' } }
    let(:item_foo)   { { 'type' => 'addItem', 'name' => 'foo', 'class_name' => 'Ecommerce' } }
    let(:item_bar)   { { 'type' => 'addItem', 'name' => 'bar', 'class_name' => 'Ecommerce' } }
    let(:fb_event)   { { 'id' => '1', 'value' => 1, 'currency' => 'USD', 'class_name' => 'Event' } }
    let(:controller) { TestController.new({}) }

    context 'controller' do
      it 'writes the event into env' do
        expect {
          controller.index
        }.to change {
          controller.env
        }.from({}).to('tracker' => {'google_analytics' => [send, trx, item_foo, item_bar], 'facebook' => [fb_event]})
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rack-tracker-1.13.0 spec/tracker/controller_spec.rb
rack-tracker-1.12.1 spec/tracker/controller_spec.rb
rack-tracker-1.12.0 spec/tracker/controller_spec.rb
rack-tracker-1.11.2 spec/tracker/controller_spec.rb
rack-tracker-1.11.1 spec/tracker/controller_spec.rb
rack-tracker-1.11.0 spec/tracker/controller_spec.rb
rack-tracker-1.10.0 spec/tracker/controller_spec.rb
rack-tracker-1.9.0 spec/tracker/controller_spec.rb
rack-tracker-1.8.0 spec/tracker/controller_spec.rb
rack-tracker-1.7.0 spec/tracker/controller_spec.rb
rack-tracker-1.6.0 spec/tracker/controller_spec.rb
rack-tracker-1.5.0 spec/tracker/controller_spec.rb
rack-tracker-1.4.0 spec/tracker/controller_spec.rb
rack-tracker-1.3.1 spec/tracker/controller_spec.rb
rack-tracker-1.3.0 spec/tracker/controller_spec.rb
rack-tracker-1.2.0 spec/tracker/controller_spec.rb
rack-tracker-1.1.0 spec/tracker/controller_spec.rb
rack-tracker-1.0.2 spec/tracker/controller_spec.rb
rack-tracker-1.0.1 spec/tracker/controller_spec.rb
rack-tracker-1.0.0 spec/tracker/controller_spec.rb