mixpal 0.0.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +24 -0
- data/.travis.yml +7 -0
- data/Dockerfile +6 -0
- data/README.md +51 -11
- data/Rakefile +10 -1
- data/docker-compose.yml +14 -0
- data/lib/mixpal.rb +27 -7
- data/lib/mixpal/event.rb +4 -4
- data/lib/mixpal/integration.rb +12 -8
- data/lib/mixpal/revenue.rb +32 -0
- data/lib/mixpal/tracker.rb +44 -27
- data/lib/mixpal/user.rb +9 -7
- data/lib/mixpal/util.rb +3 -3
- data/lib/mixpal/version.rb +1 -1
- data/mixpanel_assistant.gemspec +8 -7
- data/spec/lib/mixpal/event_spec.rb +20 -18
- data/spec/lib/mixpal/revenue_spec.rb +60 -0
- data/spec/lib/mixpal/tracker_spec.rb +181 -153
- data/spec/lib/mixpal/user_spec.rb +37 -31
- data/spec/lib/mixpal/util_spec.rb +15 -14
- data/spec/lib/mixpal_spec.rb +13 -2
- data/spec/spec_helper.rb +4 -7
- data/spec/support/custom_events_module.rb +5 -0
- data/spec/support/matchers/element_matchers.rb +2 -2
- data/test_app/.gitignore +18 -0
- data/test_app/Gemfile +11 -0
- data/test_app/README.rdoc +28 -0
- data/test_app/Rakefile +6 -0
- data/test_app/app/assets/images/.keep +0 -0
- data/test_app/app/assets/javascripts/application.js +16 -0
- data/test_app/app/assets/stylesheets/application.css +15 -0
- data/test_app/app/controllers/application_controller.rb +12 -0
- data/test_app/app/controllers/concerns/.keep +0 -0
- data/test_app/app/controllers/redirects_controller.rb +10 -0
- data/test_app/app/helpers/application_helper.rb +2 -0
- data/test_app/app/mailers/.keep +0 -0
- data/test_app/app/models/.keep +0 -0
- data/test_app/app/models/concerns/.keep +0 -0
- data/test_app/app/views/layouts/application.html.erb +16 -0
- data/test_app/app/views/redirects/new.html.erb +1 -0
- data/test_app/bin/bundle +3 -0
- data/test_app/bin/rails +8 -0
- data/test_app/bin/rake +8 -0
- data/test_app/bin/spring +18 -0
- data/test_app/config.ru +4 -0
- data/test_app/config/application.rb +30 -0
- data/test_app/config/boot.rb +4 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +37 -0
- data/test_app/config/environments/production.rb +82 -0
- data/test_app/config/environments/test.rb +39 -0
- data/test_app/config/initializers/assets.rb +8 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/cookies_serializer.rb +3 -0
- data/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/test_app/config/initializers/inflections.rb +16 -0
- data/test_app/config/initializers/mime_types.rb +4 -0
- data/test_app/config/initializers/session_store.rb +3 -0
- data/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/test_app/config/locales/en.yml +23 -0
- data/test_app/config/routes.rb +4 -0
- data/test_app/config/secrets.yml +22 -0
- data/test_app/db/seeds.rb +7 -0
- data/test_app/lib/assets/.keep +0 -0
- data/test_app/lib/tasks/.keep +0 -0
- data/test_app/log/.keep +0 -0
- data/test_app/public/404.html +67 -0
- data/test_app/public/422.html +67 -0
- data/test_app/public/500.html +66 -0
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/robots.txt +5 -0
- data/test_app/vendor/assets/javascripts/.keep +0 -0
- data/test_app/vendor/assets/stylesheets/.keep +0 -0
- metadata +112 -44
- data/spec/support/mock_rails.rb +0 -6
- data/spec/support/mock_storage.rb +0 -19
@@ -1,73 +1,79 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mixpal::User do
|
4
|
-
let(:properties)
|
4
|
+
let(:properties) do
|
5
|
+
{
|
6
|
+
random_property: 'Hansel',
|
7
|
+
another_random_one: 'So Hot Right Now'
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
5
11
|
let(:subject) { described_class.new(properties) }
|
6
12
|
|
7
|
-
describe
|
8
|
-
it
|
9
|
-
Mixpal::Util.
|
13
|
+
describe '#render' do
|
14
|
+
it 'delegates to Util for js_object composition' do
|
15
|
+
expect(Mixpal::Util).to receive(:hash_to_js_object_string).with(properties)
|
10
16
|
subject.render
|
11
17
|
end
|
12
18
|
|
13
|
-
it
|
19
|
+
it 'outputs a call to people.set' do
|
14
20
|
js_object = Mixpal::Util.hash_to_js_object_string(properties)
|
15
21
|
expect(subject.render).to eq "mixpanel.people.set(#{js_object});"
|
16
22
|
end
|
17
23
|
|
18
|
-
it
|
24
|
+
it 'outputs an html safe string' do
|
19
25
|
expect(subject.render).to be_html_safe
|
20
26
|
end
|
21
27
|
|
22
|
-
context
|
28
|
+
context 'with Mixpanel special properties' do
|
23
29
|
let(:properties) do
|
24
30
|
{
|
25
|
-
name:
|
26
|
-
email:
|
31
|
+
name: 'Nick Giancola',
|
32
|
+
email: 'nick@gophilosophie.com',
|
27
33
|
created_at: Time.now,
|
28
|
-
random_property:
|
34
|
+
random_property: 'Hansel'
|
29
35
|
}
|
30
36
|
end
|
31
37
|
|
32
|
-
it
|
33
|
-
expect(subject.render).to include "
|
34
|
-
expect(subject.render).not_to include "
|
38
|
+
it 'converts name => $name' do
|
39
|
+
expect(subject.render).to include '"$name"'
|
40
|
+
expect(subject.render).not_to include '"name"'
|
35
41
|
end
|
36
42
|
|
37
|
-
it
|
38
|
-
expect(subject.render).to include "
|
39
|
-
expect(subject.render).not_to include "
|
43
|
+
it 'converts email => $email' do
|
44
|
+
expect(subject.render).to include '"$email"'
|
45
|
+
expect(subject.render).not_to include '"email"'
|
40
46
|
end
|
41
47
|
|
42
|
-
it
|
43
|
-
expect(subject.render).to include "
|
44
|
-
expect(subject.render).not_to include "
|
48
|
+
it 'converts created_at => $created' do
|
49
|
+
expect(subject.render).to include '"$created"'
|
50
|
+
expect(subject.render).not_to include '"created_at"'
|
45
51
|
end
|
46
52
|
|
47
|
-
it
|
48
|
-
expect(subject.render).to include "
|
49
|
-
expect(subject.render).not_to include "
|
53
|
+
it 'leaves other properties untouched' do
|
54
|
+
expect(subject.render).to include '"random_property"'
|
55
|
+
expect(subject.render).not_to include '"$random_property"'
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
|
-
describe
|
55
|
-
it
|
60
|
+
describe '#to_store' do
|
61
|
+
it 'returns a hash with its data' do
|
56
62
|
expect(subject.to_store).to eq(
|
57
|
-
properties
|
63
|
+
'properties' => properties
|
58
64
|
)
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
62
|
-
describe
|
63
|
-
let(:result) { described_class.from_store(properties
|
68
|
+
describe '#from_store' do
|
69
|
+
let(:result) { described_class.from_store('properties' => properties) }
|
64
70
|
|
65
|
-
it
|
71
|
+
it 'instantiates a new instance' do
|
66
72
|
expect(result).to be_an_instance_of(described_class)
|
67
73
|
end
|
68
74
|
|
69
|
-
it
|
75
|
+
it 'sets its properties from the data' do
|
70
76
|
expect(result.properties).to eq properties
|
71
77
|
end
|
72
78
|
end
|
73
|
-
end
|
79
|
+
end
|
@@ -1,27 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mixpal::Util do
|
4
4
|
subject { described_class }
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
|
9
|
-
|
6
|
+
describe '.hash_to_js_object_string' do
|
7
|
+
it 'converts ruby hash to string representation of a javascript object' do
|
8
|
+
hash = { key: 'value', another: 'more value' }
|
9
|
+
expect(subject.hash_to_js_object_string(hash))
|
10
|
+
.to eq '{"key": "value","another": "more value"}'
|
10
11
|
end
|
11
12
|
|
12
|
-
it
|
13
|
-
expect(subject.hash_to_js_object_string(
|
14
|
-
to eq
|
13
|
+
it 'leaves Booleans intact to be interpreted as JS Boolean' do
|
14
|
+
expect(subject.hash_to_js_object_string(is_cool: true))
|
15
|
+
.to eq '{"is_cool": true}'
|
15
16
|
end
|
16
17
|
|
17
|
-
it
|
18
|
-
expect(subject.hash_to_js_object_string(
|
19
|
-
to eq
|
18
|
+
it 'leaves Fixnums intact to be interpreted as JS Numbers' do
|
19
|
+
expect(subject.hash_to_js_object_string(age: 21))
|
20
|
+
.to eq '{"age": 21}'
|
20
21
|
end
|
21
22
|
|
22
|
-
it
|
23
|
-
expect(subject.hash_to_js_object_string(
|
24
|
-
to eq
|
23
|
+
it 'does not include keys with nil values' do
|
24
|
+
expect(subject.hash_to_js_object_string(age: 21, gender: nil))
|
25
|
+
.to eq '{"age": 21}'
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
data/spec/lib/mixpal_spec.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mixpal do
|
4
|
-
|
4
|
+
describe '#configure' do
|
5
|
+
before do
|
6
|
+
Mixpal.configure do |config|
|
7
|
+
config.helper_module = CustomEventsModule
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'allows a helper module to be set on Mixpal.configuration' do
|
12
|
+
expect(Mixpal.configuration.helper_module).to be(CustomEventsModule)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler'
|
2
2
|
Bundler.require
|
3
3
|
|
4
|
-
require
|
4
|
+
require 'mixpal'
|
5
5
|
|
6
|
-
Dir[
|
7
|
-
|
8
|
-
Rails = MockRails
|
6
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
9
7
|
|
10
8
|
RSpec.configure do |config|
|
11
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
9
|
config.run_all_when_everything_filtered = true
|
13
10
|
config.filter_run :focus
|
14
|
-
end
|
11
|
+
end
|
data/test_app/.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
17
|
+
|
18
|
+
/config/database.yml
|
data/test_app/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test_app/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery with: :exception
|
3
|
+
|
4
|
+
include Mixpal::Integration
|
5
|
+
mixpanel_identity :current_user, :email
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def current_user
|
10
|
+
Struct.new(:email).new('nick@gophilosophie.com')
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>TestApp</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
<%= mixpanel.render() %>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= link_to 'Start Redirect', to_root_path %>
|
data/test_app/bin/bundle
ADDED
data/test_app/bin/rails
ADDED
data/test_app/bin/rake
ADDED
data/test_app/bin/spring
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file loads spring without using Bundler, in order to be fast
|
4
|
+
# It gets overwritten when you run the `spring binstub` command
|
5
|
+
|
6
|
+
unless defined?(Spring)
|
7
|
+
require "rubygems"
|
8
|
+
require "bundler"
|
9
|
+
|
10
|
+
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
|
11
|
+
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
|
12
|
+
ENV["GEM_HOME"] = ""
|
13
|
+
Gem.paths = ENV
|
14
|
+
|
15
|
+
gem "spring", match[1]
|
16
|
+
require "spring/binstub"
|
17
|
+
end
|
18
|
+
end
|
data/test_app/config.ru
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_model/railtie"
|
5
|
+
require "active_record/railtie"
|
6
|
+
require "action_controller/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
require "action_view/railtie"
|
9
|
+
require "sprockets/railtie"
|
10
|
+
# require "rails/test_unit/railtie"
|
11
|
+
|
12
|
+
# Require the gems listed in Gemfile, including any gems
|
13
|
+
# you've limited to :test, :development, or :production.
|
14
|
+
Bundler.require(*Rails.groups)
|
15
|
+
|
16
|
+
module TestApp
|
17
|
+
class Application < Rails::Application
|
18
|
+
# Settings in config/environments/* take precedence over those specified here.
|
19
|
+
# Application configuration should go into files in config/initializers
|
20
|
+
# -- all .rb files in that directory are automatically loaded.
|
21
|
+
|
22
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
23
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
24
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
25
|
+
|
26
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
27
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
28
|
+
# config.i18n.default_locale = :de
|
29
|
+
end
|
30
|
+
end
|