Sha256: c311353f6c4c7041c0dafac854078a060fe2312bd83b1e581cb1a0438258d456

Contents?: true

Size: 1.65 KB

Versions: 11

Compression:

Stored size: 1.65 KB

Contents

RSpec.describe Rack::Tracker::Facebook do
  describe Rack::Tracker::Facebook::Event do

    subject { described_class.new({id: 'id', foo: 'bar'}) }

    describe '#write' do
      specify { expect(subject.write).to eq(['track', 'id', {foo: 'bar'}].to_json) }
    end
  end

  def env
    {}
  end

  it 'will be placed in the body' do
    expect(described_class.position).to eq(:body)
    expect(described_class.new(env).position).to eq(:body)
  end

  describe 'with custom audience id' do
    subject { described_class.new(env, custom_audience: 'custom_audience_id').render }

    it 'will push the tracking events to the queue' do
      expect(subject).to match(%r{window._fbq.push\(\["addPixelId", "custom_audience_id"\]\)})
      expect(subject).to match(%r{window._fbq.push\(\["track", "PixelInitialized", \{\}\]\)})
    end

    it 'will add the noscript fallback' do
      expect(subject).to match(%r{https://www.facebook.com/tr\?id=custom_audience_id&ev=PixelInitialized})
    end
  end

  describe 'with events' do
    def env
      {
        'tracker' => {
        'facebook' =>
          [
            Rack::Tracker::Facebook::Event.new(
              'id'=> '123456789',
             'value' => '23',
             'currency' => 'EUR'
            )
          ]
        }
      }
    end
    subject { described_class.new(env).render }

    it 'will push the tracking events to the queue' do
      expect(subject).to match(%r{\["track","123456789",\{"value":"23","currency":"EUR"\}\]})
    end

    it 'will add the noscript fallback' do
      expect(subject).to match(%r{https://www.facebook.com/offsite_event.php\?id=123456789&value=23&currency=EUR})
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rack-tracker-0.3.0 spec/handler/facebook_spec.rb
rack-tracker-0.2.6 spec/handler/facebook_spec.rb
rack-tracker-0.2.5 spec/handler/facebook_spec.rb
rack-tracker-0.2.4 spec/handler/facebook_spec.rb
rack-tracker-0.2.3 spec/handler/facebook_spec.rb
rack-tracker-0.2.2 spec/handler/facebook_spec.rb
rack-tracker-0.2.1 spec/handler/facebook_spec.rb
rack-tracker-0.2.0 spec/handler/facebook_spec.rb
rack-tracker-0.1.3 spec/handler/facebook_spec.rb
rack-tracker-0.1.1 spec/handler/facebook_spec.rb
rack-tracker-0.1.0 spec/handler/facebook_spec.rb