forked from railslove/rack-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook_spec.rb
More file actions
59 lines (49 loc) · 1.66 KB
/
facebook_spec.rb
File metadata and controls
59 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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' =>
[
{
'id' => '123456789',
'value' => '23',
'currency' => 'EUR',
'class_name' => 'Event'
}
]
}
}
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