spec/handler/google_analytics_spec.rb in rack-tracker-1.5.0 vs spec/handler/google_analytics_spec.rb in rack-tracker-1.6.0
- old
+ new
@@ -51,32 +51,28 @@
end
end
end
describe '#tracker_options' do
- before do
- stub_const("#{described_class}::ALLOWED_TRACKER_OPTIONS", [:some_option])
- end
-
context 'with an allowed option configured with a static value' do
- subject { described_class.new(env, { some_option: 'value' }) }
+ subject { described_class.new(env, { user_id: 'value' }) }
it 'returns hash with option set' do
- expect(subject.tracker_options).to eql ({ someOption: 'value' })
+ expect(subject.tracker_options).to eql ({ userId: 'value' })
end
end
context 'with an allowed option configured with a block' do
- subject { described_class.new(env, { some_option: lambda { |env| return env[:misc] } }) }
+ subject { described_class.new(env, { user_id: lambda { |env| return env[:misc] } }) }
it 'returns hash with option set' do
- expect(subject.tracker_options).to eql ({ someOption: 'foobar' })
+ expect(subject.tracker_options).to eql ({ userId: 'foobar' })
end
end
context 'with an allowed option configured with a block returning nil' do
- subject { described_class.new(env, { some_option: lambda { |env| return env[:non_existing_key] } }) }
+ subject { described_class.new(env, { user_id: lambda { |env| return env[:non_existing_key] } }) }
it 'returns an empty hash' do
expect(subject.tracker_options).to eql ({})
end
end
@@ -190,20 +186,20 @@
end
describe "with custom domain" do
subject { described_class.new(env, tracker: 'somebody', cookie_domain: "railslabs.com").render }
- it "will show asyncronous tracker with cookieDomain" do
+ it "will show asynchronous tracker with cookieDomain" do
expect(subject).to match(%r{ga\('create', 'somebody', {\"cookieDomain\":\"railslabs.com\"}\)})
expect(subject).to match(%r{ga\('send', 'pageview', window\.location\.pathname \+ window\.location\.search\)})
end
end
describe "with user_id tracking" do
subject { described_class.new(env, tracker: 'somebody', user_id: lambda { |env| return env[:user_id] } ).render }
- it "will show asyncronous tracker with userId" do
+ it "will show asynchronous tracker with userId" do
expect(subject).to match(%r{ga\('create', 'somebody', {\"userId\":\"123\"}\)})
expect(subject).to match(%r{ga\('send', 'pageview', window\.location\.pathname \+ window\.location\.search\)})
end
end
@@ -234,9 +230,17 @@
describe "with ecommerce" do
subject { described_class.new(env, tracker: 'happy', ecommerce: true).render }
it "will require the ecommerce plugin" do
expect(subject).to match(%r{ga\('require', 'ecommerce', 'ecommerce\.js'\)})
+ end
+ end
+
+ describe "with optimize" do
+ subject { described_class.new(env, tracker: 'happy', optimize: 'GTM-1234').render }
+
+ it "will require the optimize plugin with container ID" do
+ expect(subject).to match(%r{ga\('require', 'GTM-1234'\)})
end
end
describe "with anonymizeIp" do
subject { described_class.new(env, tracker: 'happy', anonymize_ip: true).render }