vero 0.2.1 → 0.3.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.
- data/Gemfile.lock +9 -5
- data/info +10 -0
- data/lib/vero/app.rb +9 -35
- data/lib/vero/config.rb +24 -5
- data/lib/vero/context.rb +104 -0
- data/lib/vero/jobs/rest_post_job.rb +1 -0
- data/lib/vero/logger.rb +25 -0
- data/lib/vero/trackable.rb +12 -67
- data/lib/vero/version.rb +1 -1
- data/lib/vero/view_helpers.rb +4 -3
- data/lib/vero.rb +2 -0
- data/spec/lib/app_spec.rb +23 -16
- data/spec/lib/config_spec.rb +11 -0
- data/spec/lib/context_spec.rb +57 -0
- data/spec/lib/trackable_spec.rb +27 -34
- data/spec/support/vero_user_support.rb +2 -0
- metadata +7 -1
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vero (0.
|
4
|
+
vero (0.3.0)
|
5
5
|
delayed_job
|
6
6
|
delayed_job_active_record
|
7
7
|
delayed_job_mongoid
|
@@ -38,6 +38,7 @@ GEM
|
|
38
38
|
i18n (~> 0.6)
|
39
39
|
multi_json (~> 1.0)
|
40
40
|
arel (3.0.2)
|
41
|
+
bson (1.6.4)
|
41
42
|
builder (3.0.0)
|
42
43
|
columnize (0.3.6)
|
43
44
|
debugger (1.1.3)
|
@@ -52,8 +53,9 @@ GEM
|
|
52
53
|
delayed_job_active_record (0.3.2)
|
53
54
|
activerecord (> 2.1.0)
|
54
55
|
delayed_job (~> 3.0.0)
|
55
|
-
delayed_job_mongoid (1.0
|
56
|
-
delayed_job (~> 3.0
|
56
|
+
delayed_job_mongoid (1.1.0)
|
57
|
+
delayed_job (~> 3.0)
|
58
|
+
mongo (~> 1.6)
|
57
59
|
mongoid (>= 2.0)
|
58
60
|
diff-lcs (1.1.3)
|
59
61
|
erubis (2.7.0)
|
@@ -66,9 +68,11 @@ GEM
|
|
66
68
|
mime-types (~> 1.16)
|
67
69
|
treetop (~> 1.4.8)
|
68
70
|
mime-types (1.18)
|
69
|
-
|
71
|
+
mongo (1.6.4)
|
72
|
+
bson (~> 1.6.4)
|
73
|
+
mongoid (3.0.2)
|
70
74
|
activemodel (~> 3.1)
|
71
|
-
moped (~> 1.1.
|
75
|
+
moped (~> 1.1.3)
|
72
76
|
origin (~> 1.0.3)
|
73
77
|
tzinfo (~> 0.3.22)
|
74
78
|
moped (1.1.5)
|
data/info
CHANGED
@@ -38,3 +38,13 @@ Vero: Error attempting to track event: {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=",
|
|
38
38
|
Vero: Error attempting to track event: {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20}, :data=>{:test=>1}} error: Connection refused - connect(2)
|
39
39
|
Vero: Error attempting to track event: {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20}, :data=>{:test=>1}} error: Connection refused - connect(2)
|
40
40
|
User: Error attempting to track event: {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20}, :data=>{:test=>1}} error: Connection refused - connect(2)
|
41
|
+
RestClient.post "http://localhost/api/v1/track.json", "auth_token=YWJjZDEyMzQ6ZWZnaDU2Nzg%3D&development_mode=true&event_name=test_event&identity[email]=durkster%40gmail.com&identity[age]=20&data[test]=1", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"148", "Content-Type"=>"application/x-www-form-urlencoded"
|
42
|
+
|
43
|
+
RestClient.post "http://localhost/api/v1/track.json", "auth_token=YWJjZDEyMzQ6ZWZnaDU2Nzg%3D&development_mode=true&event_name=test_event&identity[email]=durkster%40gmail.com&identity[age]=20&data[test]=1", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"148", "Content-Type"=>"application/x-www-form-urlencoded"
|
44
|
+
|
45
|
+
RestClient.post "http://localhost/api/v1/track.json", "auth_token=YWJjZDEyMzQ6ZWZnaDU2Nzg%3D&development_mode=true&event_name=test_event&identity[email]=durkster%40gmail.com&identity[age]=20&data[test]=1", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"148", "Content-Type"=>"application/x-www-form-urlencoded"
|
46
|
+
|
47
|
+
RestClient.post "http://localhost/api/v1/track.json", "auth_token=YWJjZDEyMzQ6ZWZnaDU2Nzg%3D&development_mode=true&event_name=test_event&identity[email]=durkster%40gmail.com&identity[age]=20&data[test]=1", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"148", "Content-Type"=>"application/x-www-form-urlencoded"
|
48
|
+
|
49
|
+
RestClient.post "http://localhost/api/v1/track.json", "auth_token=YWJjZDEyMzQ6ZWZnaDU2Nzg%3D&development_mode=true&event_name=test_event&identity[email]=durkster%40gmail.com&identity[age]=20&data[test]=1", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"148", "Content-Type"=>"application/x-www-form-urlencoded"
|
50
|
+
|
data/lib/vero/app.rb
CHANGED
@@ -1,51 +1,25 @@
|
|
1
1
|
module Vero
|
2
2
|
class App
|
3
|
-
|
3
|
+
include Vero::Logger
|
4
4
|
|
5
|
-
def self.
|
6
|
-
@@
|
5
|
+
def self.default_context
|
6
|
+
@@default_context ||= Context.new
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
9
|
+
def self.init(&block)
|
10
|
+
default_context.configure(&block) if block_given?
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.reset!
|
14
|
-
|
14
|
+
default_context.reset!
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.disable_requests!
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.config
|
22
|
-
@@config
|
18
|
+
default_context.disable_requests!
|
23
19
|
end
|
24
20
|
|
25
21
|
def self.configured?
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.log(object, message)
|
30
|
-
return unless config.logging
|
31
|
-
|
32
|
-
logger = self.logger
|
33
|
-
message = "#{object.class.name}: #{message}"
|
34
|
-
|
35
|
-
if logger
|
36
|
-
logger.info message
|
37
|
-
else
|
38
|
-
puts message
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.logger
|
43
|
-
return nil unless config.logging
|
44
|
-
if defined?(Rails) && Rails.logger
|
45
|
-
Rails.logger
|
46
|
-
else
|
47
|
-
nil
|
48
|
-
end
|
22
|
+
default_context.configured?
|
49
23
|
end
|
50
24
|
end
|
51
25
|
end
|
data/lib/vero/config.rb
CHANGED
@@ -3,11 +3,12 @@ module Vero
|
|
3
3
|
attr_writer :domain
|
4
4
|
attr_accessor :api_key, :secret, :development_mode, :async, :disabled, :logging
|
5
5
|
|
6
|
+
def self.available_attributes
|
7
|
+
[:api_key, :secret, :development_mode, :async, :disabled, :logging, :domain]
|
8
|
+
end
|
9
|
+
|
6
10
|
def initialize
|
7
|
-
self.
|
8
|
-
self.development_mode = !Rails.env.production?
|
9
|
-
self.async = true
|
10
|
-
self.logging = false
|
11
|
+
self.reset!
|
11
12
|
end
|
12
13
|
|
13
14
|
def config_params
|
@@ -32,8 +33,26 @@ module Vero
|
|
32
33
|
Base64::encode64("#{api_key}:#{secret}").gsub(/[\n ]/, '')
|
33
34
|
end
|
34
35
|
|
35
|
-
def configured
|
36
|
+
def configured?
|
36
37
|
!api_key.blank? && !secret.blank?
|
37
38
|
end
|
39
|
+
|
40
|
+
def reset!
|
41
|
+
self.disabled = false
|
42
|
+
self.development_mode = !Rails.env.production?
|
43
|
+
self.async = true
|
44
|
+
self.logging = false
|
45
|
+
self.api_key = nil
|
46
|
+
self.secret = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_attributes(attributes = {})
|
50
|
+
return unless attributes.is_a?(Hash)
|
51
|
+
|
52
|
+
Vero::Config.available_attributes.each do |symbol|
|
53
|
+
method_name = "#{symbol.to_s}=".to_sym
|
54
|
+
self.send(method_name, attributes[symbol]) if self.respond_to?(method_name) && attributes.has_key?(symbol)
|
55
|
+
end
|
56
|
+
end
|
38
57
|
end
|
39
58
|
end
|
data/lib/vero/context.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'delayed_job'
|
3
|
+
require 'vero/jobs/rest_post_job'
|
4
|
+
|
5
|
+
module Vero
|
6
|
+
class Context
|
7
|
+
attr_accessor :config, :subject
|
8
|
+
|
9
|
+
def initialize(object = {})
|
10
|
+
case object
|
11
|
+
when Hash
|
12
|
+
#stub
|
13
|
+
when Vero::Context
|
14
|
+
@config = object.config
|
15
|
+
@subject = object.subject
|
16
|
+
else
|
17
|
+
object = Vero::Config.available_attributes.inject({}) do |hash, symbol|
|
18
|
+
hash[symbol] = object.respond_to?(symbol) ? object.send(symbol) : nil
|
19
|
+
hash
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if object.is_a?(Hash)
|
24
|
+
@config = Vero::Config.new
|
25
|
+
self.configure(object)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure(hash = {}, &block)
|
30
|
+
if hash.is_a?(Hash) && hash.any?
|
31
|
+
@config.update_attributes(hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
block.call(@config) if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset!
|
38
|
+
@config.reset!
|
39
|
+
end
|
40
|
+
|
41
|
+
def disable_requests!
|
42
|
+
@config.disabled = true
|
43
|
+
end
|
44
|
+
|
45
|
+
def configured?
|
46
|
+
@config.configured?
|
47
|
+
end
|
48
|
+
|
49
|
+
def track(event_name, event_data = {})
|
50
|
+
validate_configured!
|
51
|
+
validate_track_params!(event_name, event_data)
|
52
|
+
|
53
|
+
request_params = @config.request_params
|
54
|
+
request_params.merge!({:event_name => event_name, :identity => subject.to_vero, :data => event_data})
|
55
|
+
|
56
|
+
method = if @config.async
|
57
|
+
:post_later
|
58
|
+
else
|
59
|
+
:post_now
|
60
|
+
end
|
61
|
+
self.send(method, "http://#{@config.domain}/api/v1/track.json", request_params)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def post_now(url, params)
|
66
|
+
unless @config.disabled
|
67
|
+
Vero::Jobs::RestPostJob.new(url, params).perform
|
68
|
+
Vero::App.log(self, "method: track, params: #{params.to_json}, response: job performed")
|
69
|
+
end
|
70
|
+
'success'
|
71
|
+
rescue => e
|
72
|
+
Vero::App.log(self, "method: track, params: #{params.to_json} error: #{e.message}")
|
73
|
+
end
|
74
|
+
|
75
|
+
def post_later(url, params)
|
76
|
+
unless @config.disabled
|
77
|
+
::Delayed::Job.enqueue Vero::Jobs::RestPostJob.new(url, params)
|
78
|
+
Vero::App.log(self, "method: track, params: #{params.to_json}, response: delayed job queued")
|
79
|
+
end
|
80
|
+
'success'
|
81
|
+
rescue => e
|
82
|
+
if e.message == "Could not find table 'delayed_jobs'"
|
83
|
+
raise "To send ratings asynchronously, you must configure delayed_job. Run `rails generate delayed_job:active_record` then `rake db:migrate`."
|
84
|
+
else
|
85
|
+
raise e
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_configured!
|
90
|
+
unless @config.configured?
|
91
|
+
raise "You must configure the 'vero' gem. Visit https://github.com/semblancesystems/vero for more details."
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def validate_track_params!(event_name, event_data)
|
96
|
+
result = true
|
97
|
+
|
98
|
+
result &&= event_name.kind_of?(String) && !event_name.blank?
|
99
|
+
result &&= event_data.nil? || event_data.kind_of?(Hash)
|
100
|
+
|
101
|
+
raise ArgumentError.new({:event_name => event_name, :event_data => event_data}) unless result
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/vero/logger.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Vero
|
2
|
+
module Logger
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def log(object, message)
|
9
|
+
return unless Vero::App.default_context.config.logging
|
10
|
+
|
11
|
+
message = "#{object.class.name}: #{message}"
|
12
|
+
|
13
|
+
if (logger = self.logger)
|
14
|
+
logger.info(message)
|
15
|
+
else
|
16
|
+
puts(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def logger
|
21
|
+
defined?(Rails) && Rails.logger ? Rails.logger : nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/vero/trackable.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'delayed_job'
|
2
|
-
require 'json'
|
3
|
-
require 'vero/jobs/rest_post_job'
|
4
|
-
|
5
1
|
module Vero
|
6
2
|
module Trackable
|
7
3
|
def self.included(base)
|
@@ -11,10 +7,10 @@ module Vero
|
|
11
7
|
|
12
8
|
module ClassMethods
|
13
9
|
def trackable(*args)
|
14
|
-
|
15
|
-
|
10
|
+
@vero_trackable_map = case @vero_trackable_map
|
11
|
+
when Array then (@vero_trackable_map << args).flatten
|
16
12
|
else
|
17
|
-
|
13
|
+
args
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
@@ -22,13 +18,14 @@ module Vero
|
|
22
18
|
@vero_trackable_map
|
23
19
|
end
|
24
20
|
|
25
|
-
def
|
21
|
+
def reset_trackable_map!
|
26
22
|
@vero_trackable_map = nil
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
26
|
def to_vero
|
31
|
-
|
27
|
+
klass = self.class
|
28
|
+
result = klass.trackable_map.inject({}) do |hash, symbol|
|
32
29
|
hash[symbol] = self.send(symbol)
|
33
30
|
hash
|
34
31
|
end
|
@@ -37,66 +34,14 @@ module Vero
|
|
37
34
|
result
|
38
35
|
end
|
39
36
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
config = Vero::App.config
|
45
|
-
request_params = config.request_params
|
46
|
-
request_params.merge!({:event_name => event_name, :identity => self.to_vero, :data => event_data})
|
47
|
-
|
48
|
-
method = !config.async ? :post_now : :post_later
|
49
|
-
self.send(method, "http://#{config.domain}/api/v1/track.json", request_params)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def post_now(url, params)
|
54
|
-
begin
|
55
|
-
execute_unless_disabled do
|
56
|
-
Vero::Jobs::RestPostJob.new(url, params).perform
|
57
|
-
Vero::App.log(self, "method: track, params: #{params.to_json}, response: job performed")
|
58
|
-
end
|
59
|
-
rescue => e
|
60
|
-
Vero::App.log(self, "method: track, params: #{params.to_json} error: #{e.message}")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def post_later(url, params)
|
65
|
-
begin
|
66
|
-
execute_unless_disabled do
|
67
|
-
::Delayed::Job.enqueue Vero::Jobs::RestPostJob.new(url, params)
|
68
|
-
Vero::App.log(self, "method: track, params: #{params.to_json}, response: delayed job queued")
|
69
|
-
end
|
70
|
-
rescue ActiveRecord::StatementInvalid => e
|
71
|
-
if e.message == "Could not find table 'delayed_jobs'"
|
72
|
-
raise "To send ratings asynchronously, you must configure delayed_job. Run `rails generate delayed_job:active_record` then `rake db:migrate`."
|
73
|
-
else
|
74
|
-
raise e
|
75
|
-
end
|
76
|
-
end
|
77
|
-
'success'
|
78
|
-
end
|
79
|
-
|
80
|
-
def validate_configured!
|
81
|
-
unless Vero::App.configured?
|
82
|
-
raise "You must configure the 'vero' gem. Visit https://github.com/semblancesystems/vero for more details."
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def validate_track_params!(event_name, event_data)
|
87
|
-
result = true
|
88
|
-
|
89
|
-
result &&= event_name.kind_of?(String) && !event_name.blank?
|
90
|
-
result &&= event_data.nil? || event_data.kind_of?(Hash)
|
91
|
-
|
92
|
-
raise ArgumentError.new({:event_name => event_name, :event_data => event_data}) unless result
|
37
|
+
def with_vero_context(context = {})
|
38
|
+
context = Vero::Context.new(context)
|
39
|
+
context.subject = self
|
40
|
+
context
|
93
41
|
end
|
94
42
|
|
95
|
-
def
|
96
|
-
|
97
|
-
if !config.disabled && block_given?
|
98
|
-
block.call
|
99
|
-
end
|
43
|
+
def track(event_name, event_data = {})
|
44
|
+
self.with_vero_context(Vero::App.default_context).track(event_name, event_data)
|
100
45
|
end
|
101
46
|
end
|
102
47
|
end
|
data/lib/vero/version.rb
CHANGED
data/lib/vero/view_helpers.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module Vero
|
2
2
|
module ViewHelpers
|
3
|
-
def vero_javascript_tag(method = :default)
|
4
|
-
return "" unless
|
3
|
+
def vero_javascript_tag(method = :default, context = Vero::App.default_context)
|
4
|
+
return "" unless context.configured?
|
5
|
+
config = context.config
|
5
6
|
|
6
7
|
unless [:default, :mixpanel, :kissmetrics].include?(method)
|
7
8
|
method = :default
|
8
9
|
end
|
9
10
|
|
10
11
|
method_name = method.to_s + "_vero_javascript_tag"
|
11
|
-
self.send(method_name.to_sym,
|
12
|
+
self.send(method_name.to_sym, config.config_params)
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
data/lib/vero.rb
CHANGED
data/spec/lib/app_spec.rb
CHANGED
@@ -1,51 +1,58 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vero::App do
|
4
|
-
describe
|
5
|
-
it "
|
6
|
-
Vero::App.
|
7
|
-
Vero::
|
8
|
-
Vero::App.config.should_not be_nil
|
4
|
+
describe 'self.default_context' do
|
5
|
+
it "inherits from Vero::Context" do
|
6
|
+
actual = Vero::App.default_context
|
7
|
+
actual.should be_a(Vero::Context)
|
9
8
|
end
|
9
|
+
end
|
10
10
|
|
11
|
+
let (:context) { Vero::App.default_context }
|
12
|
+
describe :init do
|
11
13
|
it "should ignore configuring the config if no block is provided" do
|
12
14
|
Vero::App.init
|
13
|
-
|
15
|
+
context.configured?.should be_false
|
14
16
|
end
|
15
17
|
|
16
18
|
it "should pass configuration defined in the block to the config file" do
|
17
19
|
Vero::App.init
|
18
20
|
|
19
|
-
|
21
|
+
context.config.api_key.should be_nil
|
20
22
|
Vero::App.init do |c|
|
21
23
|
c.api_key = "abcd1234"
|
22
24
|
end
|
23
|
-
|
25
|
+
context.config.api_key.should == "abcd1234"
|
24
26
|
end
|
25
27
|
|
26
28
|
it "should init should be able to set async" do
|
27
29
|
Vero::App.init do |c|
|
28
30
|
c.async = false
|
29
31
|
end
|
30
|
-
|
32
|
+
context.config.async.should be_false
|
31
33
|
|
32
34
|
Vero::App.init do |c|
|
33
35
|
c.async = true
|
34
36
|
end
|
35
|
-
|
37
|
+
context.config.async.should be_true
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
describe :disable_requests! do
|
40
|
-
before :each do
|
41
|
-
Vero::App.init {}
|
42
|
-
end
|
43
|
-
|
44
42
|
it "should change config.disabled" do
|
45
|
-
Vero::App.
|
43
|
+
Vero::App.init {}
|
44
|
+
context.config.disabled.should be_false
|
46
45
|
|
47
46
|
Vero::App.disable_requests!
|
48
|
-
|
47
|
+
context.config.disabled.should be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe :log do
|
52
|
+
it "should have a log method" do
|
53
|
+
Vero::App.init {}
|
54
|
+
Vero::App.should_receive(:log)
|
55
|
+
Vero::App.log(Object, "test")
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -9,6 +9,17 @@ describe Vero::Config do
|
|
9
9
|
@config.async.should be_true
|
10
10
|
end
|
11
11
|
|
12
|
+
describe :reset! do
|
13
|
+
it "should reset all attributes" do
|
14
|
+
@config.api_key = "abcd1234"
|
15
|
+
@config.secret = "abcd1234"
|
16
|
+
|
17
|
+
@config.reset!
|
18
|
+
@config.api_key.should be_nil
|
19
|
+
@config.secret.should be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
12
23
|
describe :auth_token do
|
13
24
|
it "should return nil if either api_key or secret are not set" do
|
14
25
|
@config.api_key = nil
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vero::Context do
|
4
|
+
let(:context) { Vero::Context.new }
|
5
|
+
|
6
|
+
it "accepts multiple parameter types in contructor" do
|
7
|
+
context1 = Vero::Context.new({ :api_key => 'blah', :secret => 'didah' })
|
8
|
+
context1.should be_a(Vero::Context)
|
9
|
+
context1.config.api_key.should == 'blah'
|
10
|
+
context1.config.secret.should == 'didah'
|
11
|
+
|
12
|
+
context2 = Vero::Context.new(context1)
|
13
|
+
context2.should be_a(Vero::Context)
|
14
|
+
context2.should_not be(context1)
|
15
|
+
context2.config.api_key.should == 'blah'
|
16
|
+
context2.config.secret.should == 'didah'
|
17
|
+
|
18
|
+
context3 = Vero::Context.new VeroUser.new('api_key', 'secret')
|
19
|
+
context3.should be_a(Vero::Context)
|
20
|
+
context3.config.api_key.should == 'api_key'
|
21
|
+
context3.config.secret.should == 'secret'
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :configure do
|
25
|
+
it "should ignore configuring the config if no block is provided" do
|
26
|
+
context.configure
|
27
|
+
context.configured?.should be_false
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should pass configuration defined in the block to the config file" do
|
31
|
+
context.configure do |c|
|
32
|
+
c.api_key = "abcd1234"
|
33
|
+
end
|
34
|
+
context.config.api_key.should == "abcd1234"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should init should be able to set async" do
|
38
|
+
context.configure do |c|
|
39
|
+
c.async = false
|
40
|
+
end
|
41
|
+
context.config.async.should be_false
|
42
|
+
|
43
|
+
context.configure do |c|
|
44
|
+
c.async = true
|
45
|
+
end
|
46
|
+
context.config.async.should be_true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe :disable_requests! do
|
51
|
+
it "should change config.disabled" do
|
52
|
+
context.config.disabled.should be_false
|
53
|
+
context.disable_requests!
|
54
|
+
context.config.disabled.should be_true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/lib/trackable_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Vero::Trackable do
|
|
21
21
|
describe :track do
|
22
22
|
it "should raise an error" do
|
23
23
|
@user.stub(:post_later).and_return('success')
|
24
|
-
expect { @user.track(@request_params[:event_name], @request_params[:data]
|
24
|
+
expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -45,44 +45,56 @@ describe Vero::Trackable do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should send a track request when async is set to false" do
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
context = Vero::Context.new(Vero::App.default_context)
|
49
|
+
context.subject = @user
|
50
|
+
context.stub(:post_now).and_return(200)
|
51
|
+
context.should_receive(:post_now).with(@url, @request_params).at_least(:once)
|
52
|
+
|
53
|
+
@user.stub(:with_vero_context).and_return(context)
|
54
|
+
|
55
|
+
@user.track(@request_params[:event_name], @request_params[:data]).should == 200
|
51
56
|
@user.track(@request_params[:event_name]).should == 200
|
52
57
|
end
|
53
58
|
|
54
59
|
it "should create a delayed job when async is set to true" do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
context = Vero::Context.new(Vero::App.default_context)
|
61
|
+
context.subject = @user
|
62
|
+
context.config.async = true
|
63
|
+
|
64
|
+
context.stub(:post_later).and_return('success')
|
65
|
+
context.should_receive(:post_later).with(@url, @request_params).at_least(:once)
|
66
|
+
|
67
|
+
@user.stub(:with_vero_context).and_return(context)
|
68
|
+
|
69
|
+
@user.track(@request_params[:event_name], @request_params[:data]).should == 'success'
|
60
70
|
@user.track(@request_params[:event_name]).should == 'success'
|
61
71
|
end
|
62
72
|
|
63
73
|
it "should not raise an error when async is set to false and the request times out" do
|
64
|
-
Vero::App.config.async = false
|
65
|
-
Vero::App.config.domain = "localhost"
|
66
74
|
Rails.stub(:logger).and_return(Logger.new('info'))
|
75
|
+
|
76
|
+
context = Vero::App.default_context
|
77
|
+
context.config.async = false
|
78
|
+
context.config.domain = "localhost"
|
67
79
|
|
68
|
-
expect { @user.track(@request_params[:event_name], @request_params[:data]
|
80
|
+
expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to_not raise_error
|
69
81
|
end
|
70
82
|
end
|
71
83
|
|
72
84
|
describe :trackable do
|
73
85
|
after :each do
|
74
|
-
User.
|
86
|
+
User.reset_trackable_map!
|
75
87
|
User.trackable :email, :age
|
76
88
|
end
|
77
89
|
|
78
90
|
it "should build an array of trackable params" do
|
79
|
-
User.
|
91
|
+
User.reset_trackable_map!
|
80
92
|
User.trackable :email, :age
|
81
93
|
User.trackable_map.should == [:email, :age]
|
82
94
|
end
|
83
95
|
|
84
96
|
it "should append new trackable items to an existing trackable map" do
|
85
|
-
User.
|
97
|
+
User.reset_trackable_map!
|
86
98
|
User.trackable :email, :age
|
87
99
|
User.trackable :hair_colour
|
88
100
|
User.trackable_map.should == [:email, :age, :hair_colour]
|
@@ -103,24 +115,5 @@ describe Vero::Trackable do
|
|
103
115
|
user.to_vero.should == temp_params
|
104
116
|
end
|
105
117
|
end
|
106
|
-
|
107
|
-
describe :execute_unless_disabled do
|
108
|
-
it "should only execute the block unless config.disabled" do
|
109
|
-
user = User.new
|
110
|
-
test_val = 1
|
111
|
-
test_val.should == 1
|
112
|
-
|
113
|
-
user.send(:execute_unless_disabled) do
|
114
|
-
test_val = 2
|
115
|
-
end
|
116
|
-
test_val.should == 2
|
117
|
-
|
118
|
-
Vero::App.disable_requests!
|
119
|
-
user.send(:execute_unless_disabled) do
|
120
|
-
test_val = 3
|
121
|
-
end
|
122
|
-
test_val.should == 2
|
123
|
-
end
|
124
|
-
end
|
125
118
|
end
|
126
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -87,7 +87,9 @@ files:
|
|
87
87
|
- lib/generators/vero_generator.rb
|
88
88
|
- lib/vero/app.rb
|
89
89
|
- lib/vero/config.rb
|
90
|
+
- lib/vero/context.rb
|
90
91
|
- lib/vero/jobs/rest_post_job.rb
|
92
|
+
- lib/vero/logger.rb
|
91
93
|
- lib/vero/railtie.rb
|
92
94
|
- lib/vero/trackable.rb
|
93
95
|
- lib/vero/version.rb
|
@@ -96,10 +98,12 @@ files:
|
|
96
98
|
- README.markdown
|
97
99
|
- spec/lib/app_spec.rb
|
98
100
|
- spec/lib/config_spec.rb
|
101
|
+
- spec/lib/context_spec.rb
|
99
102
|
- spec/lib/trackable_spec.rb
|
100
103
|
- spec/lib/view_helpers_spec.rb
|
101
104
|
- spec/spec_helper.rb
|
102
105
|
- spec/support/user_support.rb
|
106
|
+
- spec/support/vero_user_support.rb
|
103
107
|
- vero.gemspec
|
104
108
|
homepage: http://getvero.com/
|
105
109
|
licenses: []
|
@@ -128,7 +132,9 @@ summary: Rails 3.x gem for Vero
|
|
128
132
|
test_files:
|
129
133
|
- spec/lib/app_spec.rb
|
130
134
|
- spec/lib/config_spec.rb
|
135
|
+
- spec/lib/context_spec.rb
|
131
136
|
- spec/lib/trackable_spec.rb
|
132
137
|
- spec/lib/view_helpers_spec.rb
|
133
138
|
- spec/spec_helper.rb
|
134
139
|
- spec/support/user_support.rb
|
140
|
+
- spec/support/vero_user_support.rb
|