mixpal 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +23 -0
  3. data/.travis.yml +5 -0
  4. data/README.md +7 -11
  5. data/Rakefile +8 -1
  6. data/lib/mixpal.rb +7 -7
  7. data/lib/mixpal/event.rb +4 -4
  8. data/lib/mixpal/integration.rb +7 -7
  9. data/lib/mixpal/tracker.rb +29 -26
  10. data/lib/mixpal/user.rb +9 -7
  11. data/lib/mixpal/util.rb +3 -3
  12. data/lib/mixpal/version.rb +1 -1
  13. data/mixpanel_assistant.gemspec +1 -0
  14. data/spec/lib/mixpal/event_spec.rb +19 -17
  15. data/spec/lib/mixpal/tracker_spec.rb +127 -149
  16. data/spec/lib/mixpal/user_spec.rb +36 -30
  17. data/spec/lib/mixpal/util_spec.rb +15 -14
  18. data/spec/lib/mixpal_spec.rb +2 -2
  19. data/spec/spec_helper.rb +4 -6
  20. data/spec/support/matchers/element_matchers.rb +2 -2
  21. data/test_app/.gitignore +16 -0
  22. data/test_app/Gemfile +11 -0
  23. data/test_app/README.rdoc +28 -0
  24. data/test_app/Rakefile +6 -0
  25. data/test_app/app/assets/images/.keep +0 -0
  26. data/test_app/app/assets/javascripts/application.js +16 -0
  27. data/test_app/app/assets/stylesheets/application.css +15 -0
  28. data/test_app/app/controllers/application_controller.rb +12 -0
  29. data/test_app/app/controllers/concerns/.keep +0 -0
  30. data/test_app/app/controllers/redirects_controller.rb +10 -0
  31. data/test_app/app/helpers/application_helper.rb +2 -0
  32. data/test_app/app/mailers/.keep +0 -0
  33. data/test_app/app/models/.keep +0 -0
  34. data/test_app/app/models/concerns/.keep +0 -0
  35. data/test_app/app/views/layouts/application.html.erb +16 -0
  36. data/test_app/app/views/redirects/new.html.erb +1 -0
  37. data/test_app/bin/bundle +3 -0
  38. data/test_app/bin/rails +8 -0
  39. data/test_app/bin/rake +8 -0
  40. data/test_app/bin/spring +18 -0
  41. data/test_app/config.ru +4 -0
  42. data/test_app/config/application.rb +30 -0
  43. data/test_app/config/boot.rb +4 -0
  44. data/test_app/config/environment.rb +5 -0
  45. data/test_app/config/environments/development.rb +37 -0
  46. data/test_app/config/environments/production.rb +82 -0
  47. data/test_app/config/environments/test.rb +39 -0
  48. data/test_app/config/initializers/assets.rb +8 -0
  49. data/test_app/config/initializers/backtrace_silencers.rb +7 -0
  50. data/test_app/config/initializers/cookies_serializer.rb +3 -0
  51. data/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/test_app/config/initializers/inflections.rb +16 -0
  53. data/test_app/config/initializers/mime_types.rb +4 -0
  54. data/test_app/config/initializers/session_store.rb +3 -0
  55. data/test_app/config/initializers/wrap_parameters.rb +14 -0
  56. data/test_app/config/locales/en.yml +23 -0
  57. data/test_app/config/routes.rb +4 -0
  58. data/test_app/config/secrets.yml +22 -0
  59. data/test_app/db/seeds.rb +7 -0
  60. data/test_app/lib/assets/.keep +0 -0
  61. data/test_app/lib/tasks/.keep +0 -0
  62. data/test_app/log/.keep +0 -0
  63. data/test_app/public/404.html +67 -0
  64. data/test_app/public/422.html +67 -0
  65. data/test_app/public/500.html +66 -0
  66. data/test_app/public/favicon.ico +0 -0
  67. data/test_app/public/robots.txt +5 -0
  68. data/test_app/vendor/assets/javascripts/.keep +0 -0
  69. data/test_app/vendor/assets/stylesheets/.keep +0 -0
  70. metadata +67 -6
  71. data/spec/support/mock_rails.rb +0 -6
  72. data/spec/support/mock_storage.rb +0 -19
@@ -1,73 +1,79 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Mixpal::User do
4
- let(:properties) { { random_property: "Hansel", another_random_one: "So Hot Right Now" } }
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 "#render" do
8
- it "delegates to Util for js_object composition" do
13
+ describe '#render' do
14
+ it 'delegates to Util for js_object composition' do
9
15
  Mixpal::Util.should_receive(:hash_to_js_object_string).with(properties)
10
16
  subject.render
11
17
  end
12
18
 
13
- it "outputs a call to people.set" do
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 "outputs an html safe string" do
24
+ it 'outputs an html safe string' do
19
25
  expect(subject.render).to be_html_safe
20
26
  end
21
27
 
22
- context "with Mixpanel special properties" do
28
+ context 'with Mixpanel special properties' do
23
29
  let(:properties) do
24
30
  {
25
- name: "Nick Giancola",
26
- email: "nick@gophilosophie.com",
31
+ name: 'Nick Giancola',
32
+ email: 'nick@gophilosophie.com',
27
33
  created_at: Time.now,
28
- random_property: "Hansel",
34
+ random_property: 'Hansel'
29
35
  }
30
36
  end
31
37
 
32
- it "converts name => $name" do
33
- expect(subject.render).to include "\"$name\""
34
- expect(subject.render).not_to include "\"name\""
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 "converts email => $email" do
38
- expect(subject.render).to include "\"$email\""
39
- expect(subject.render).not_to include "\"email\""
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 "converts created_at => $created" do
43
- expect(subject.render).to include "\"$created\""
44
- expect(subject.render).not_to include "\"created_at\""
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 "leaves other properties untouched" do
48
- expect(subject.render).to include "\"random_property\""
49
- expect(subject.render).not_to include "\"$random_property\""
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 "#to_store" do
55
- it "returns a hash with its data" do
60
+ describe '#to_store' do
61
+ it 'returns a hash with its data' do
56
62
  expect(subject.to_store).to eq(
57
- properties: properties,
63
+ 'properties' => properties
58
64
  )
59
65
  end
60
66
  end
61
67
 
62
- describe "#from_store" do
63
- let(:result) { described_class.from_store(properties: properties) }
68
+ describe '#from_store' do
69
+ let(:result) { described_class.from_store('properties' => properties) }
64
70
 
65
- it "instantiates a new instance" do
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 "sets its properties from the data" do
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 "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Mixpal::Util do
4
4
  subject { described_class }
5
5
 
6
- describe ".hash_to_js_object_string" do
7
- it "converts a ruby hash to a string representation of a javascript object" do
8
- expect(subject.hash_to_js_object_string({key: "value", another: "more value"})).
9
- to eq "{\"key\": \"value\",\"another\": \"more value\"}"
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 "leaves Booleans intact to be interpreted as JS Boolean" do
13
- expect(subject.hash_to_js_object_string({ is_cool: true })).
14
- to eq "{\"is_cool\": true}"
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 "leaves Fixnums intact to be interpreted as JS Numbers" do
18
- expect(subject.hash_to_js_object_string({ age: 21 })).
19
- to eq "{\"age\": 21}"
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 "does not include keys with nil values" do
23
- expect(subject.hash_to_js_object_string({ age: 21, gender: nil })).
24
- to eq "{\"age\": 21}"
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
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Mixpal do
4
- end
4
+ end
@@ -1,14 +1,12 @@
1
- require "bundler"
1
+ require 'bundler'
2
2
  Bundler.require
3
3
 
4
- require "mixpal"
4
+ require 'mixpal'
5
5
 
6
- Dir["./spec/support/**/*.rb"].each {|f| require f }
7
-
8
- Rails = MockRails
6
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
9
7
 
10
8
  RSpec.configure do |config|
11
9
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
10
  config.run_all_when_everything_filtered = true
13
11
  config.filter_run :focus
14
- end
12
+ end
@@ -1,4 +1,4 @@
1
- require "nokogiri"
1
+ require 'nokogiri'
2
2
 
3
3
  RSpec::Matchers.define :have_tag do |tag|
4
4
  match do |string|
@@ -12,4 +12,4 @@ RSpec::Matchers.define :have_xpath do |tag|
12
12
  document = Nokogiri::HTML(string.to_s)
13
13
  !!document.at_xpath(tag)
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '4.1.4'
4
+ gem 'sqlite3'
5
+ gem 'sass-rails', '~> 4.0.3'
6
+ gem 'uglifier', '>= 1.3.0'
7
+ gem 'coffee-rails', '~> 4.0.0'
8
+ gem 'jquery-rails'
9
+ gem 'turbolinks'
10
+ gem 'mixpal', path: '..'
11
+ gem 'pry'
@@ -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>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
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
@@ -0,0 +1,10 @@
1
+ class RedirectsController < ApplicationController
2
+ def new
3
+ mixpanel.track 'Root'
4
+ end
5
+
6
+ def to_root
7
+ mixpanel.track 'Redirecting back to root'
8
+ redirect_to root_path
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
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 %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
7
+ require_relative '../config/boot'
8
+ require 'rails/commands'
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ require_relative '../config/boot'
7
+ require 'rake'
8
+ Rake.application.run
@@ -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
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -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
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!