-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixpanel_rails_spec.rb
79 lines (63 loc) · 1.95 KB
/
mixpanel_rails_spec.rb
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
class ExampleController < ApplicationController
uses_mixpanel
def no_tracking
render inline: "OK", layout: true
end
def with_tracking
track_with_mixpanel "Register for site"
render inline: "OK", layout: true
end
end
class RedirectsController < ApplicationController
uses_mixpanel
def index
track_with_mixpanel "Register for site"
redirect_to action: :redirected
end
def redirected
render inline: "OK", layout: true
end
end
class DistinctIdController < ApplicationController
uses_mixpanel distinct_id: lambda { 1 }
def index
render inline: "OK", layout: true
end
end
shared_examples_for "mixpanel init" do
it do
page.find("script:first").text.should include('mpq.push(["init", "test_token"]);')
end
end
shared_examples_for "without distinct id" do
it { page.find("script:last").text.should_not include('distinct_id') }
end
shared_examples_for "with distinct id" do
it { page.find("script:last").text.should include('mpq.push(["register", {"distinct_id":1}]);') }
end
shared_examples_for "with event" do
it { page.find("script:last").text.should include('mpq.push(["track", "Register for site"])') }
end
feature 'mixpanel integration' do
context 'visit page without tracking' do
background { visit '/example/no_tracking' }
it_should_behave_like "mixpanel init"
it_should_behave_like "without distinct id"
end
context 'visit page with tracking' do
background { visit '/example/with_tracking' }
it_should_behave_like "mixpanel init"
it_should_behave_like "without distinct id"
it_should_behave_like "with event"
end
context 'visit page with distinct id' do
background { visit '/distinct_id' }
it_should_behave_like "mixpanel init"
it_should_behave_like "with distinct id"
end
context 'follow redirect' do
background { visit '/redirects' }
it_should_behave_like "with event"
end
end