Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic testing and don't add distinct id if it doesn't exist
- Loading branch information
Showing
7 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
Gemfile.lock | ||
pkg/* | ||
.rvmrc | ||
spec/app/log/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
</head> | ||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'bundler/setup' | ||
require 'rails' | ||
Bundler.require(:default, Rails.env) | ||
require 'action_controller/railtie' | ||
require 'action_view/railtie' | ||
|
||
app = Class.new(Rails::Application) | ||
app.config.root = File.dirname(__FILE__) | ||
app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4" | ||
app.config.active_support.deprecation = :log | ||
app.config.mixpanel_rails.token = "test_token" | ||
app.initialize! | ||
|
||
app.routes.draw do | ||
match ':controller(/:action(/:id))' | ||
end | ||
|
||
class ApplicationController < ActionController::Base; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$:.unshift File.expand_path('../../lib', __FILE__) | ||
require File.expand_path(File.dirname(__FILE__) + "/app/fake") | ||
require 'rspec/rails' | ||
require "steak" | ||
require 'capybara/rspec' |