vero 0.7.0 → 0.10.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.
- checksums.yaml +7 -0
- data/CHANGES.md +11 -8
- data/Gemfile +15 -1
- data/Gemfile.lock +142 -81
- data/README.markdown +148 -119
- data/lib/generators/vero_generator.rb +18 -19
- data/lib/vero.rb +10 -3
- data/lib/vero/api.rb +24 -8
- data/lib/vero/api/base_api.rb +12 -11
- data/lib/vero/api/events/track_api.rb +5 -3
- data/lib/vero/api/users/delete_api.rb +21 -0
- data/lib/vero/api/users/edit_api.rb +5 -3
- data/lib/vero/api/users/edit_tags_api.rb +7 -5
- data/lib/vero/api/users/reidentify_api.rb +5 -3
- data/lib/vero/api/users/resubscribe_api.rb +23 -0
- data/lib/vero/api/users/track_api.rb +5 -3
- data/lib/vero/api/users/unsubscribe_api.rb +3 -1
- data/lib/vero/app.rb +4 -2
- data/lib/vero/config.rb +14 -19
- data/lib/vero/context.rb +9 -11
- data/lib/vero/context/api.rb +9 -7
- data/lib/vero/dsl.rb +3 -1
- data/lib/vero/railtie.rb +5 -3
- data/lib/vero/sender.rb +12 -30
- data/lib/vero/senders/base.rb +3 -1
- data/lib/vero/senders/delayed_job.rb +7 -7
- data/lib/vero/senders/invalid.rb +5 -3
- data/lib/vero/senders/resque.rb +8 -8
- data/lib/vero/senders/sidekiq.rb +25 -0
- data/lib/vero/senders/{thread.rb → sucker_punch.rb} +5 -3
- data/lib/vero/trackable.rb +4 -2
- data/lib/vero/trackable/base.rb +10 -9
- data/lib/vero/trackable/interface.rb +3 -1
- data/lib/vero/utility/ext.rb +3 -1
- data/lib/vero/utility/logger.rb +4 -6
- data/lib/vero/version.rb +3 -1
- data/lib/vero/view_helpers/javascript.rb +20 -20
- data/spec/lib/api/base_api_spec.rb +11 -9
- data/spec/lib/api/events/track_api_spec.rb +30 -30
- data/spec/lib/api/users/delete_api_spec.rb +33 -0
- data/spec/lib/api/users/edit_api_spec.rb +14 -16
- data/spec/lib/api/users/edit_tags_api_spec.rb +28 -31
- data/spec/lib/api/users/reidentify_spec.rb +20 -22
- data/spec/lib/api/users/resubscribe_api_spec.rb +35 -0
- data/spec/lib/api/users/track_api_spec.rb +26 -28
- data/spec/lib/api/users/unsubscribe_api_spec.rb +14 -16
- data/spec/lib/api_spec.rb +59 -57
- data/spec/lib/app_spec.rb +21 -19
- data/spec/lib/config_spec.rb +77 -59
- data/spec/lib/context_spec.rb +27 -25
- data/spec/lib/dsl_spec.rb +4 -2
- data/spec/lib/sender_spec.rb +12 -23
- data/spec/lib/senders/sidekiq_spec.rb +32 -0
- data/spec/lib/trackable_spec.rb +125 -151
- data/spec/lib/view_helpers_spec.rb +13 -9
- data/spec/spec_helper.rb +10 -4
- data/spec/support/base_config_shared_examples.rb +11 -0
- data/spec/support/user_support.rb +15 -7
- data/spec/support/vero_user_support.rb +4 -2
- data/vero.gemspec +14 -29
- metadata +47 -138
data/spec/lib/context_spec.rb
CHANGED
@@ -1,57 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe Vero::Context do
|
5
|
+
describe Vero::Context do
|
4
6
|
let(:context) { Vero::Context.new }
|
5
7
|
|
6
|
-
it
|
7
|
-
context1 = Vero::Context.new({ :
|
8
|
-
context1.
|
9
|
-
context1.config.api_key.
|
10
|
-
context1.config.secret.
|
8
|
+
it 'accepts multiple parameter types in contructor' do
|
9
|
+
context1 = Vero::Context.new({ api_key: 'blah', secret: 'didah' })
|
10
|
+
expect(context1).to be_a(Vero::Context)
|
11
|
+
expect(context1.config.api_key).to eq('blah')
|
12
|
+
expect(context1.config.secret).to eq('didah')
|
11
13
|
|
12
14
|
context2 = Vero::Context.new(context1)
|
13
|
-
context2.
|
14
|
-
context2.
|
15
|
-
context2.config.api_key.
|
16
|
-
context2.config.secret.
|
15
|
+
expect(context2).to be_a(Vero::Context)
|
16
|
+
expect(context2).not_to be(context1)
|
17
|
+
expect(context2.config.api_key).to eq('blah')
|
18
|
+
expect(context2.config.secret).to eq('didah')
|
17
19
|
|
18
20
|
context3 = Vero::Context.new VeroUser.new('api_key', 'secret')
|
19
|
-
context3.
|
20
|
-
context3.config.api_key.
|
21
|
-
context3.config.secret.
|
21
|
+
expect(context3).to be_a(Vero::Context)
|
22
|
+
expect(context3.config.api_key).to eq('api_key')
|
23
|
+
expect(context3.config.secret).to eq('secret')
|
22
24
|
end
|
23
25
|
|
24
26
|
describe :configure do
|
25
|
-
it
|
27
|
+
it 'should ignore configuring the config if no block is provided' do
|
26
28
|
context.configure
|
27
|
-
context.configured
|
29
|
+
expect(context.configured?).to be(false)
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it 'should pass configuration defined in the block to the config file' do
|
31
33
|
context.configure do |c|
|
32
|
-
c.api_key =
|
34
|
+
c.api_key = 'abcd1234'
|
33
35
|
end
|
34
|
-
context.config.api_key.
|
36
|
+
expect(context.config.api_key).to eq('abcd1234')
|
35
37
|
end
|
36
38
|
|
37
|
-
it
|
39
|
+
it 'should init should be able to set async' do
|
38
40
|
context.configure do |c|
|
39
41
|
c.async = false
|
40
42
|
end
|
41
|
-
context.config.async.
|
43
|
+
expect(context.config.async).to be(false)
|
42
44
|
|
43
45
|
context.configure do |c|
|
44
46
|
c.async = true
|
45
47
|
end
|
46
|
-
context.config.async.
|
48
|
+
expect(context.config.async).to be(true)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
52
|
describe :disable_requests! do
|
51
|
-
it
|
52
|
-
context.config.disabled.
|
53
|
+
it 'should change config.disabled' do
|
54
|
+
expect(context.config.disabled).to be(false)
|
53
55
|
context.disable_requests!
|
54
|
-
context.config.disabled.
|
56
|
+
expect(context.config.disabled).to be(true)
|
55
57
|
end
|
56
58
|
end
|
57
|
-
end
|
59
|
+
end
|
data/spec/lib/dsl_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::DSL do
|
@@ -18,8 +20,8 @@ describe Vero::DSL::Proxy do
|
|
18
20
|
expect(proxy.users).to eql(Vero::Api::Users)
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
22
|
-
expect(proxy.users.respond_to?(:reidentify!)).to
|
23
|
+
it 'should respond to reidentify!' do
|
24
|
+
expect(proxy.users.respond_to?(:reidentify!)).to be(true)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
data/spec/lib/sender_spec.rb
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Sender do
|
4
6
|
subject { Vero::Sender }
|
5
7
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
subject.senders.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should have a default set of senders (true, false, none, thread)" do
|
17
|
-
subject.senders.should == {
|
18
|
-
true => Vero::Senders::Thread,
|
19
|
-
false => Vero::Senders::Base,
|
20
|
-
:none => Vero::Senders::Base,
|
21
|
-
:thread => Vero::Senders::Thread,
|
22
|
-
}
|
23
|
-
end
|
8
|
+
describe '.senders' do
|
9
|
+
it 'should automatically find senders that are not defined' do
|
10
|
+
expect(subject.senders[:delayed_job]).to eq(Vero::Senders::DelayedJob)
|
11
|
+
expect(subject.senders[:sucker_punch]).to eq(Vero::Senders::SuckerPunch)
|
12
|
+
expect(subject.senders[:resque]).to eq(Vero::Senders::Resque)
|
13
|
+
expect(subject.senders[:sidekiq]).to eq(Vero::Senders::Sidekiq)
|
14
|
+
expect(subject.senders[:invalid]).to eq(Vero::Senders::Invalid)
|
15
|
+
expect(subject.senders[:none]).to eq(Vero::Senders::Base)
|
24
16
|
end
|
25
17
|
|
26
|
-
it
|
27
|
-
subject.senders[:
|
28
|
-
subject.senders[:resque].should == Vero::Senders::Resque
|
29
|
-
subject.senders[:invalid].should == Vero::Senders::Invalid
|
30
|
-
subject.senders[:none].should == Vero::Senders::Base
|
18
|
+
it 'should fallback to Vero::Senders::Base' do
|
19
|
+
expect(subject.senders[:unsupported_sender]).to eq(Vero::Senders::Base)
|
31
20
|
end
|
32
21
|
end
|
33
22
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Vero::Senders::Sidekiq do
|
6
|
+
subject { Vero::Senders::Sidekiq.new }
|
7
|
+
describe :call do
|
8
|
+
it 'should perform_async a Vero::SidekiqWorker' do
|
9
|
+
expect(Vero::SidekiqWorker).to(
|
10
|
+
receive(:perform_async)
|
11
|
+
.with('Vero::Api::Workers::Events::TrackAPI', 'abc', { test: 'abc' })
|
12
|
+
.once
|
13
|
+
)
|
14
|
+
subject.call(Vero::Api::Workers::Events::TrackAPI, 'abc', { test: 'abc' })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Vero::SidekiqWorker do
|
20
|
+
subject { Vero::SidekiqWorker.new }
|
21
|
+
describe :perform do
|
22
|
+
it 'should call the api method' do
|
23
|
+
mock_api = double(Vero::Api::Workers::Events::TrackAPI)
|
24
|
+
expect(mock_api).to receive(:perform).once
|
25
|
+
|
26
|
+
allow(Vero::Api::Workers::Events::TrackAPI).to receive(:new).and_return(mock_api)
|
27
|
+
expect(Vero::Api::Workers::Events::TrackAPI).to receive(:new).with('abc', { test: 'abc' }).once
|
28
|
+
|
29
|
+
subject.perform('Vero::Api::Workers::Events::TrackAPI', 'abc', { test: 'abc' })
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/lib/trackable_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
def vero_context(user, logging = true, async = false, disabled = true)
|
@@ -13,29 +15,29 @@ end
|
|
13
15
|
describe Vero::Trackable do
|
14
16
|
before :each do
|
15
17
|
@request_params = {
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
event_name: 'test_event',
|
19
|
+
auth_token: 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
|
20
|
+
identity: { email: 'durkster@gmail.com', age: 20, _user_type: 'User' },
|
21
|
+
data: { test: 1 },
|
22
|
+
development_mode: true
|
21
23
|
}
|
22
|
-
@url =
|
24
|
+
@url = 'https://api.getvero.com/api/v1/track.json'
|
23
25
|
@user = User.new
|
24
26
|
|
25
|
-
@content_type_params = {:
|
27
|
+
@content_type_params = { content_type: :json, accept: :json }
|
26
28
|
end
|
27
29
|
|
28
|
-
context
|
30
|
+
context 'the gem has not been configured' do
|
29
31
|
before { Vero::App.reset! }
|
30
|
-
it
|
31
|
-
expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error
|
32
|
+
it 'should raise an error when API requests are made' do
|
33
|
+
expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error(RuntimeError)
|
32
34
|
|
33
|
-
@user.
|
34
|
-
expect { @user.identity! }.to raise_error
|
35
|
+
allow(@user).to receive(:post_later).and_return('success')
|
36
|
+
expect { @user.identity! }.to raise_error(NoMethodError)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
context
|
40
|
+
context 'the gem has been configured' do
|
39
41
|
before do
|
40
42
|
Vero::App.init do |c|
|
41
43
|
c.api_key = 'abcd1234'
|
@@ -47,48 +49,44 @@ describe Vero::Trackable do
|
|
47
49
|
describe :track! do
|
48
50
|
before do
|
49
51
|
@request_params = {
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
52
|
+
event_name: 'test_event',
|
53
|
+
identity: { email: 'durkster@gmail.com', age: 20, _user_type: 'User' },
|
54
|
+
data: { test: 1 },
|
55
|
+
extras: {}
|
54
56
|
}
|
55
|
-
@url =
|
57
|
+
@url = 'https://api.getvero.com/api/v1/track.json'
|
56
58
|
end
|
57
59
|
|
58
|
-
it
|
59
|
-
expect { @user.track!(nil) }.to raise_error
|
60
|
-
expect { @user.track!('') }.to raise_error
|
61
|
-
expect { @user.track!('test', '') }.to raise_error
|
60
|
+
it 'should not send a track request when the required parameters are invalid' do
|
61
|
+
expect { @user.track!(nil) }.to raise_error(ArgumentError)
|
62
|
+
expect { @user.track!('') }.to raise_error(ArgumentError)
|
63
|
+
expect { @user.track!('test', '') }.to raise_error(ArgumentError)
|
62
64
|
end
|
63
65
|
|
64
|
-
it
|
66
|
+
it 'should send a `track!` request when async is set to false' do
|
65
67
|
context = vero_context(@user)
|
66
|
-
@user.
|
68
|
+
allow(@user).to receive(:with_vero_context).and_return(context)
|
67
69
|
|
68
|
-
RestClient.
|
70
|
+
allow(RestClient).to receive(:post).and_return(200)
|
69
71
|
|
70
|
-
Vero::Api::Events.
|
71
|
-
Vero::Api::Events.
|
72
|
-
@user.track!(@request_params[:event_name], @request_params[:data]).
|
72
|
+
allow(Vero::Api::Events).to receive(:track!).and_return(200)
|
73
|
+
expect(Vero::Api::Events).to receive(:track!).with(@request_params, context)
|
74
|
+
expect(@user.track!(@request_params[:event_name], @request_params[:data])).to eq(200)
|
73
75
|
|
74
|
-
Vero::Api::Events.
|
75
|
-
Vero::Api::Events.
|
76
|
-
@user.track!(@request_params[:event_name]).
|
76
|
+
allow(Vero::Api::Events).to receive(:track!).and_return(200)
|
77
|
+
expect(Vero::Api::Events).to receive(:track!).with(@request_params.merge(data: {}), context)
|
78
|
+
expect(@user.track!(@request_params[:event_name])).to eq(200)
|
77
79
|
end
|
78
80
|
|
79
81
|
context 'when set to be async' do
|
80
82
|
before do
|
81
83
|
@context = vero_context(@user, true, true)
|
82
|
-
@user.
|
84
|
+
allow(@user).to receive(:with_vero_context).and_return(@context)
|
83
85
|
end
|
84
86
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
it 'sends' do
|
89
|
-
@user.track!(@request_params[:event_name], @request_params[:data]).should be_nil
|
90
|
-
@user.track!(@request_params[:event_name]).should be_nil
|
91
|
-
end
|
87
|
+
it 'sends' do
|
88
|
+
expect(@user.track!(@request_params[:event_name], @request_params[:data])).to be_nil
|
89
|
+
expect(@user.track!(@request_params[:event_name])).to be_nil
|
92
90
|
end
|
93
91
|
end
|
94
92
|
end
|
@@ -96,35 +94,31 @@ describe Vero::Trackable do
|
|
96
94
|
describe :identify! do
|
97
95
|
before do
|
98
96
|
@request_params = {
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
97
|
+
id: nil,
|
98
|
+
email: 'durkster@gmail.com',
|
99
|
+
data: { email: 'durkster@gmail.com', age: 20, _user_type: 'User' }
|
102
100
|
}
|
103
|
-
@url =
|
101
|
+
@url = 'https://api.getvero.com/api/v2/users/track.json'
|
104
102
|
end
|
105
103
|
|
106
|
-
it
|
104
|
+
it 'should send an `identify` request when async is set to false' do
|
107
105
|
context = vero_context(@user)
|
108
|
-
@user.
|
106
|
+
allow(@user).to receive(:with_vero_context).and_return(context)
|
109
107
|
|
110
|
-
Vero::Api::Users.
|
111
|
-
Vero::Api::Users.
|
108
|
+
allow(Vero::Api::Users).to receive(:track!).and_return(200)
|
109
|
+
expect(Vero::Api::Users).to receive(:track!).with(@request_params, context)
|
112
110
|
|
113
|
-
@user.identify
|
111
|
+
expect(@user.identify!).to eq(200)
|
114
112
|
end
|
115
113
|
|
116
114
|
context 'when set to use async' do
|
117
115
|
before do
|
118
116
|
@context = vero_context(@user, false, true)
|
119
|
-
@user.
|
117
|
+
allow(@user).to receive(:with_vero_context).and_return(@context)
|
120
118
|
end
|
121
119
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
it 'sends' do
|
126
|
-
@user.identify!.should be_nil
|
127
|
-
end
|
120
|
+
it 'sends' do
|
121
|
+
expect(@user.identify!).to be_nil
|
128
122
|
end
|
129
123
|
end
|
130
124
|
end
|
@@ -132,46 +126,33 @@ describe Vero::Trackable do
|
|
132
126
|
describe :update_user! do
|
133
127
|
before do
|
134
128
|
@request_params = {
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
129
|
+
id: nil,
|
130
|
+
email: 'durkster@gmail.com',
|
131
|
+
changes: { email: 'durkster@gmail.com', age: 20, _user_type: 'User' }
|
138
132
|
}
|
139
|
-
@url =
|
133
|
+
@url = 'https://api.getvero.com/api/v2/users/edit.json'
|
140
134
|
end
|
141
135
|
|
142
|
-
it
|
136
|
+
it 'should send an `update_user` request when async is set to false' do
|
143
137
|
context = Vero::Context.new(Vero::App.default_context)
|
144
138
|
context.subject = @user
|
145
139
|
|
146
|
-
@user.
|
140
|
+
allow(@user).to receive(:with_vero_context).and_return(context)
|
147
141
|
|
148
|
-
Vero::Api::Users.
|
149
|
-
Vero::Api::Users.
|
142
|
+
allow(Vero::Api::Users).to receive(:edit_user!).and_return(200)
|
143
|
+
expect(Vero::Api::Users).to receive(:edit_user!).with(@request_params, context)
|
150
144
|
|
151
|
-
@user.with_vero_context.update_user
|
145
|
+
expect(@user.with_vero_context.update_user!).to eq(200)
|
152
146
|
end
|
153
147
|
|
154
148
|
context 'when set to use async' do
|
155
149
|
before do
|
156
150
|
@context = vero_context(@user, false, true)
|
157
|
-
@user.
|
151
|
+
allow(@user).to receive(:with_vero_context).and_return(@context)
|
158
152
|
end
|
159
153
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
it 'raises an error' do
|
164
|
-
@context.config.disabled = false
|
165
|
-
expect { @user.with_vero_context.update_user! }.to raise_error
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'and not using Ruby 1.8.7' do
|
170
|
-
before { stub_const('RUBY_VERSION', '1.9.3') }
|
171
|
-
|
172
|
-
it 'sends' do
|
173
|
-
@user.with_vero_context.update_user!.should be_nil
|
174
|
-
end
|
154
|
+
it 'sends' do
|
155
|
+
expect(@user.with_vero_context.update_user!).to be_nil
|
175
156
|
end
|
176
157
|
end
|
177
158
|
end
|
@@ -179,74 +160,68 @@ describe Vero::Trackable do
|
|
179
160
|
describe :update_user_tags! do
|
180
161
|
before do
|
181
162
|
@request_params = {
|
182
|
-
:
|
183
|
-
:
|
184
|
-
:
|
185
|
-
:
|
163
|
+
id: nil,
|
164
|
+
email: 'durkster@gmail.com',
|
165
|
+
add: [],
|
166
|
+
remove: []
|
186
167
|
}
|
187
|
-
@url =
|
168
|
+
@url = 'https://api.getvero.com/api/v2/users/tags/edit.json'
|
188
169
|
end
|
189
170
|
|
190
|
-
it
|
171
|
+
it 'should send an `update_user_tags` request when async is set to false' do
|
191
172
|
context = Vero::Context.new(Vero::App.default_context)
|
192
173
|
context.subject = @user
|
193
174
|
context.config.async = false
|
194
175
|
|
195
|
-
@user.
|
176
|
+
allow(@user).to receive(:with_vero_context).and_return(context)
|
196
177
|
|
197
|
-
Vero::Api::Users.
|
198
|
-
Vero::Api::Users.
|
178
|
+
allow(Vero::Api::Users).to receive(:edit_user_tags!).and_return(200)
|
179
|
+
expect(Vero::Api::Users).to receive(:edit_user_tags!).with(@request_params, context)
|
199
180
|
|
200
|
-
@user.with_vero_context.update_user_tags
|
181
|
+
expect(@user.with_vero_context.update_user_tags!).to eq(200)
|
201
182
|
end
|
202
183
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
context.config.async = true
|
184
|
+
it 'should send using another thread when async is set to true' do
|
185
|
+
context = Vero::Context.new(Vero::App.default_context)
|
186
|
+
context.subject = @user
|
187
|
+
context.config.async = true
|
208
188
|
|
209
|
-
|
189
|
+
allow(@user).to receive(:with_vero_context).and_return(context)
|
210
190
|
|
211
|
-
|
212
|
-
end
|
191
|
+
expect(@user.with_vero_context.update_user_tags!).to be_nil
|
213
192
|
end
|
214
193
|
end
|
215
194
|
|
216
195
|
describe :unsubscribe! do
|
217
196
|
before do
|
218
197
|
@request_params = {
|
219
|
-
:
|
220
|
-
:
|
198
|
+
id: nil,
|
199
|
+
email: 'durkster@gmail.com'
|
221
200
|
}
|
222
|
-
@url =
|
201
|
+
@url = 'https://api.getvero.com/api/v2/users/unsubscribe.json'
|
223
202
|
end
|
224
203
|
|
225
|
-
it
|
204
|
+
it 'should send an `update_user` request when async is set to false' do
|
226
205
|
context = Vero::Context.new(Vero::App.default_context)
|
227
206
|
context.subject = @user
|
228
207
|
context.config.async = false
|
229
208
|
|
230
|
-
@user.
|
209
|
+
allow(@user).to receive(:with_vero_context).and_return(context)
|
231
210
|
|
232
|
-
Vero::Api::Users.
|
233
|
-
Vero::Api::Users.
|
211
|
+
allow(Vero::Api::Users).to receive(:unsubscribe!).and_return(200)
|
212
|
+
expect(Vero::Api::Users).to receive(:unsubscribe!).with(@request_params, context)
|
234
213
|
|
235
|
-
@user.with_vero_context.unsubscribe
|
214
|
+
expect(@user.with_vero_context.unsubscribe!).to eq(200)
|
236
215
|
end
|
237
216
|
|
238
217
|
context 'when using async' do
|
239
218
|
before do
|
240
219
|
@context = vero_context(@user, false, true)
|
241
|
-
@user.
|
220
|
+
allow(@user).to receive(:with_vero_context).and_return(@context)
|
242
221
|
end
|
243
222
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
it 'sends' do
|
248
|
-
@user.with_vero_context.unsubscribe!.should be_nil
|
249
|
-
end
|
223
|
+
it 'sends' do
|
224
|
+
expect(@user.with_vero_context.unsubscribe!).to be_nil
|
250
225
|
end
|
251
226
|
end
|
252
227
|
end
|
@@ -254,20 +229,20 @@ describe Vero::Trackable do
|
|
254
229
|
describe :trackable do
|
255
230
|
before { User.reset_trackable_map! }
|
256
231
|
|
257
|
-
it
|
232
|
+
it 'should build an array of trackable params' do
|
258
233
|
User.trackable :email, :age
|
259
|
-
User.trackable_map.
|
234
|
+
expect(User.trackable_map).to eq(%i[email age])
|
260
235
|
end
|
261
236
|
|
262
|
-
it
|
237
|
+
it 'should append new trackable items to an existing trackable map' do
|
263
238
|
User.trackable :email, :age
|
264
239
|
User.trackable :hair_colour
|
265
|
-
User.trackable_map.
|
240
|
+
expect(User.trackable_map).to eq(%i[email age hair_colour])
|
266
241
|
end
|
267
242
|
|
268
243
|
it "should append an extra's hash to the trackable map" do
|
269
|
-
User.trackable :email, {:
|
270
|
-
User.trackable_map.
|
244
|
+
User.trackable :email, { extras: :properties }
|
245
|
+
expect(User.trackable_map).to eq([:email, { extras: :properties }])
|
271
246
|
end
|
272
247
|
end
|
273
248
|
|
@@ -277,79 +252,78 @@ describe Vero::Trackable do
|
|
277
252
|
User.trackable :email, :age
|
278
253
|
end
|
279
254
|
|
280
|
-
it
|
255
|
+
it 'should return a hash of all values mapped by trackable' do
|
281
256
|
user = User.new
|
282
|
-
user.to_vero.
|
257
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 20, _user_type: 'User' })
|
283
258
|
|
284
259
|
user = UserWithoutEmail.new
|
285
|
-
user.to_vero.
|
260
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 20, _user_type: 'UserWithoutEmail' })
|
286
261
|
|
287
262
|
user = UserWithEmailAddress.new
|
288
|
-
user.to_vero.
|
263
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 20, _user_type: 'UserWithEmailAddress' })
|
289
264
|
|
290
265
|
user = UserWithoutInterface.new
|
291
|
-
user.to_vero.
|
266
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 20, _user_type: 'UserWithoutInterface' })
|
292
267
|
|
293
268
|
user = UserWithNilAttributes.new
|
294
|
-
user.to_vero.
|
269
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithNilAttributes' })
|
295
270
|
end
|
296
271
|
|
297
|
-
it
|
272
|
+
it 'should take into account any defined extras' do
|
298
273
|
user = UserWithExtras.new
|
299
274
|
user.properties = nil
|
300
|
-
user.to_vero.
|
275
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithExtras' })
|
301
276
|
|
302
|
-
user.properties =
|
303
|
-
user.to_vero.
|
277
|
+
user.properties = 'test'
|
278
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithExtras' })
|
304
279
|
|
305
280
|
user.properties = {}
|
306
|
-
user.to_vero.
|
281
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithExtras' })
|
307
282
|
|
308
283
|
user.properties = {
|
309
|
-
:
|
310
|
-
:
|
284
|
+
age: 20,
|
285
|
+
gender: 'female'
|
311
286
|
}
|
312
|
-
user.to_vero.
|
287
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 20, gender: 'female', _user_type: 'UserWithExtras' })
|
313
288
|
|
314
289
|
user = UserWithPrivateExtras.new
|
315
|
-
user.to_vero.
|
290
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 26, _user_type: 'UserWithPrivateExtras' })
|
316
291
|
end
|
317
292
|
|
318
|
-
it
|
293
|
+
it 'should allow extras to be provided instead :id or :email' do
|
319
294
|
user = UserWithOnlyExtras.new
|
320
|
-
user.properties = {:
|
321
|
-
user.to_vero.
|
295
|
+
user.properties = { email: user.email }
|
296
|
+
expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithOnlyExtras' })
|
322
297
|
end
|
323
298
|
end
|
324
299
|
|
325
300
|
describe :with_vero_context do
|
326
|
-
it
|
301
|
+
it 'should be able to change contexts' do
|
327
302
|
user = User.new
|
328
|
-
user.with_default_vero_context.config.config_params.
|
329
|
-
user.with_vero_context({:
|
303
|
+
expect(user.with_default_vero_context.config.config_params).to eq({ api_key: 'abcd1234', secret: 'efgh5678' })
|
304
|
+
expect(user.with_vero_context({ api_key: 'boom', secret: 'tish' }).config.config_params).to eq({ api_key: 'boom', secret: 'tish' })
|
330
305
|
end
|
331
306
|
end
|
332
307
|
|
333
|
-
it
|
308
|
+
it 'should work when Vero::Trackable::Interface is not included' do
|
334
309
|
user = UserWithoutInterface.new
|
335
310
|
|
336
311
|
request_params = {
|
337
|
-
:
|
338
|
-
:
|
339
|
-
:
|
340
|
-
:
|
341
|
-
:
|
312
|
+
event_name: 'test_event',
|
313
|
+
auth_token: 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
|
314
|
+
identity: { email: 'durkster@gmail.com', age: 20, _user_type: 'UserWithoutInterface' },
|
315
|
+
data: { test: 1 },
|
316
|
+
development_mode: true
|
342
317
|
}
|
343
|
-
url = "https://api.getvero.com/api/v1/track.json"
|
344
318
|
|
345
319
|
context = Vero::Context.new(Vero::App.default_context)
|
346
320
|
context.subject = user
|
347
|
-
context.
|
321
|
+
allow(context).to receive(:post_now).and_return(200)
|
348
322
|
|
349
|
-
user.
|
323
|
+
allow(user).to receive(:with_vero_context).and_return(context)
|
350
324
|
|
351
|
-
RestClient.
|
352
|
-
user.vero_track(request_params[:event_name], request_params[:data]).
|
325
|
+
allow(RestClient).to receive(:post).and_return(200)
|
326
|
+
expect(user.vero_track(request_params[:event_name], request_params[:data])).to eq(200)
|
353
327
|
end
|
354
328
|
end
|
355
329
|
end
|