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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +11 -8
  3. data/Gemfile +15 -1
  4. data/Gemfile.lock +142 -81
  5. data/README.markdown +148 -119
  6. data/lib/generators/vero_generator.rb +18 -19
  7. data/lib/vero.rb +10 -3
  8. data/lib/vero/api.rb +24 -8
  9. data/lib/vero/api/base_api.rb +12 -11
  10. data/lib/vero/api/events/track_api.rb +5 -3
  11. data/lib/vero/api/users/delete_api.rb +21 -0
  12. data/lib/vero/api/users/edit_api.rb +5 -3
  13. data/lib/vero/api/users/edit_tags_api.rb +7 -5
  14. data/lib/vero/api/users/reidentify_api.rb +5 -3
  15. data/lib/vero/api/users/resubscribe_api.rb +23 -0
  16. data/lib/vero/api/users/track_api.rb +5 -3
  17. data/lib/vero/api/users/unsubscribe_api.rb +3 -1
  18. data/lib/vero/app.rb +4 -2
  19. data/lib/vero/config.rb +14 -19
  20. data/lib/vero/context.rb +9 -11
  21. data/lib/vero/context/api.rb +9 -7
  22. data/lib/vero/dsl.rb +3 -1
  23. data/lib/vero/railtie.rb +5 -3
  24. data/lib/vero/sender.rb +12 -30
  25. data/lib/vero/senders/base.rb +3 -1
  26. data/lib/vero/senders/delayed_job.rb +7 -7
  27. data/lib/vero/senders/invalid.rb +5 -3
  28. data/lib/vero/senders/resque.rb +8 -8
  29. data/lib/vero/senders/sidekiq.rb +25 -0
  30. data/lib/vero/senders/{thread.rb → sucker_punch.rb} +5 -3
  31. data/lib/vero/trackable.rb +4 -2
  32. data/lib/vero/trackable/base.rb +10 -9
  33. data/lib/vero/trackable/interface.rb +3 -1
  34. data/lib/vero/utility/ext.rb +3 -1
  35. data/lib/vero/utility/logger.rb +4 -6
  36. data/lib/vero/version.rb +3 -1
  37. data/lib/vero/view_helpers/javascript.rb +20 -20
  38. data/spec/lib/api/base_api_spec.rb +11 -9
  39. data/spec/lib/api/events/track_api_spec.rb +30 -30
  40. data/spec/lib/api/users/delete_api_spec.rb +33 -0
  41. data/spec/lib/api/users/edit_api_spec.rb +14 -16
  42. data/spec/lib/api/users/edit_tags_api_spec.rb +28 -31
  43. data/spec/lib/api/users/reidentify_spec.rb +20 -22
  44. data/spec/lib/api/users/resubscribe_api_spec.rb +35 -0
  45. data/spec/lib/api/users/track_api_spec.rb +26 -28
  46. data/spec/lib/api/users/unsubscribe_api_spec.rb +14 -16
  47. data/spec/lib/api_spec.rb +59 -57
  48. data/spec/lib/app_spec.rb +21 -19
  49. data/spec/lib/config_spec.rb +77 -59
  50. data/spec/lib/context_spec.rb +27 -25
  51. data/spec/lib/dsl_spec.rb +4 -2
  52. data/spec/lib/sender_spec.rb +12 -23
  53. data/spec/lib/senders/sidekiq_spec.rb +32 -0
  54. data/spec/lib/trackable_spec.rb +125 -151
  55. data/spec/lib/view_helpers_spec.rb +13 -9
  56. data/spec/spec_helper.rb +10 -4
  57. data/spec/support/base_config_shared_examples.rb +11 -0
  58. data/spec/support/user_support.rb +15 -7
  59. data/spec/support/vero_user_support.rb +4 -2
  60. data/vero.gemspec +14 -29
  61. metadata +47 -138
@@ -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 "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'
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.should be_a(Vero::Context)
14
- context2.should_not be(context1)
15
- context2.config.api_key.should == 'blah'
16
- context2.config.secret.should == 'didah'
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.should be_a(Vero::Context)
20
- context3.config.api_key.should == 'api_key'
21
- context3.config.secret.should == '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 "should ignore configuring the config if no block is provided" do
27
+ it 'should ignore configuring the config if no block is provided' do
26
28
  context.configure
27
- context.configured?.should be_false
29
+ expect(context.configured?).to be(false)
28
30
  end
29
31
 
30
- it "should pass configuration defined in the block to the config file" do
32
+ it 'should pass configuration defined in the block to the config file' do
31
33
  context.configure do |c|
32
- c.api_key = "abcd1234"
34
+ c.api_key = 'abcd1234'
33
35
  end
34
- context.config.api_key.should == "abcd1234"
36
+ expect(context.config.api_key).to eq('abcd1234')
35
37
  end
36
38
 
37
- it "should init should be able to set async" do
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.should be_false
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.should be_true
48
+ expect(context.config.async).to be(true)
47
49
  end
48
50
  end
49
51
 
50
52
  describe :disable_requests! do
51
- it "should change config.disabled" do
52
- context.config.disabled.should be_false
53
+ it 'should change config.disabled' do
54
+ expect(context.config.disabled).to be(false)
53
55
  context.disable_requests!
54
- context.config.disabled.should be_true
56
+ expect(context.config.disabled).to be(true)
55
57
  end
56
58
  end
57
- end
59
+ end
@@ -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 "should respond to reidentify!" do
22
- expect(proxy.users.respond_to?(:reidentify!)).to be_true
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
 
@@ -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 ".senders" do
7
- it "should be a Hash" do
8
- subject.senders.should be_a(Hash)
9
- end
10
-
11
- context 'when using Ruby with verion greater than 1.8.7' do
12
- before do
13
- stub_const('RUBY_VERSION', '1.9.3')
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 "should automatically find senders that are not defined" do
27
- subject.senders[:delayed_job].should == Vero::Senders::DelayedJob
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
@@ -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
- :event_name => 'test_event',
17
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
18
- :identity => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
19
- :data => { :test => 1 },
20
- :development_mode => true
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 = "https://api.getvero.com/api/v1/track.json"
24
+ @url = 'https://api.getvero.com/api/v1/track.json'
23
25
  @user = User.new
24
26
 
25
- @content_type_params = {:content_type => :json, :accept => :json}
27
+ @content_type_params = { content_type: :json, accept: :json }
26
28
  end
27
29
 
28
- context "the gem has not been configured" do
30
+ context 'the gem has not been configured' do
29
31
  before { Vero::App.reset! }
30
- it "should raise an error when API requests are made" do
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.stub(:post_later).and_return('success')
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 "the gem has been configured" do
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
- :event_name => 'test_event',
51
- :identity => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
52
- :data => { :test => 1 },
53
- :extras => {}
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 = "https://api.getvero.com/api/v1/track.json"
57
+ @url = 'https://api.getvero.com/api/v1/track.json'
56
58
  end
57
59
 
58
- it "should not send a track request when the required parameters are invalid" do
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 "should send a `track!` request when async is set to false" do
66
+ it 'should send a `track!` request when async is set to false' do
65
67
  context = vero_context(@user)
66
- @user.stub(:with_vero_context).and_return(context)
68
+ allow(@user).to receive(:with_vero_context).and_return(context)
67
69
 
68
- RestClient.stub(:post).and_return(200)
70
+ allow(RestClient).to receive(:post).and_return(200)
69
71
 
70
- Vero::Api::Events.stub(:track!).and_return(200)
71
- Vero::Api::Events.should_receive(:track!).with(@request_params, context)
72
- @user.track!(@request_params[:event_name], @request_params[:data]).should == 200
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.stub(:track!).and_return(200)
75
- Vero::Api::Events.should_receive(:track!).with(@request_params.merge(:data => {}), context)
76
- @user.track!(@request_params[:event_name]).should == 200
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.stub(:with_vero_context).and_return(@context)
84
+ allow(@user).to receive(:with_vero_context).and_return(@context)
83
85
  end
84
86
 
85
- context 'not using Ruby 1.8.7' do
86
- before { stub_const('RUBY_VERSION', '1.9.3') }
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
- :id => nil,
100
- :email => 'durkster@gmail.com',
101
- :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
97
+ id: nil,
98
+ email: 'durkster@gmail.com',
99
+ data: { email: 'durkster@gmail.com', age: 20, _user_type: 'User' }
102
100
  }
103
- @url = "https://api.getvero.com/api/v2/users/track.json"
101
+ @url = 'https://api.getvero.com/api/v2/users/track.json'
104
102
  end
105
103
 
106
- it "should send an `identify` request when async is set to false" do
104
+ it 'should send an `identify` request when async is set to false' do
107
105
  context = vero_context(@user)
108
- @user.stub(:with_vero_context).and_return(context)
106
+ allow(@user).to receive(:with_vero_context).and_return(context)
109
107
 
110
- Vero::Api::Users.stub(:track!).and_return(200)
111
- Vero::Api::Users.should_receive(:track!).with(@request_params, context)
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!.should == 200
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.stub(:with_vero_context).and_return(@context)
117
+ allow(@user).to receive(:with_vero_context).and_return(@context)
120
118
  end
121
119
 
122
- context 'and not using Ruby 1.8.7' do
123
- before { stub_const('RUBY_VERSION', '1.9.3') }
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
- :id => nil,
136
- :email => 'durkster@gmail.com',
137
- :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
129
+ id: nil,
130
+ email: 'durkster@gmail.com',
131
+ changes: { email: 'durkster@gmail.com', age: 20, _user_type: 'User' }
138
132
  }
139
- @url = "https://api.getvero.com/api/v2/users/edit.json"
133
+ @url = 'https://api.getvero.com/api/v2/users/edit.json'
140
134
  end
141
135
 
142
- it "should send an `update_user` request when async is set to false" do
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.stub(:with_vero_context).and_return(context)
140
+ allow(@user).to receive(:with_vero_context).and_return(context)
147
141
 
148
- Vero::Api::Users.stub(:edit_user!).and_return(200)
149
- Vero::Api::Users.should_receive(:edit_user!).with(@request_params, context)
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!.should == 200
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.stub(:with_vero_context).and_return(@context)
151
+ allow(@user).to receive(:with_vero_context).and_return(@context)
158
152
  end
159
153
 
160
- context 'and using Ruby 1.8.7' do
161
- before { stub_const('RUBY_VERSION', '1.8.7') }
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
- :id => nil,
183
- :email => 'durkster@gmail.com',
184
- :add => [],
185
- :remove => []
163
+ id: nil,
164
+ email: 'durkster@gmail.com',
165
+ add: [],
166
+ remove: []
186
167
  }
187
- @url = "https://api.getvero.com/api/v2/users/tags/edit.json"
168
+ @url = 'https://api.getvero.com/api/v2/users/tags/edit.json'
188
169
  end
189
170
 
190
- it "should send an `update_user_tags` request when async is set to false" do
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.stub(:with_vero_context).and_return(context)
176
+ allow(@user).to receive(:with_vero_context).and_return(context)
196
177
 
197
- Vero::Api::Users.stub(:edit_user_tags!).and_return(200)
198
- Vero::Api::Users.should_receive(:edit_user_tags!).with(@request_params, context)
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!.should == 200
181
+ expect(@user.with_vero_context.update_user_tags!).to eq(200)
201
182
  end
202
183
 
203
- if RUBY_VERSION =~ /1\.9\./
204
- it "should send using another thread when async is set to true" do
205
- context = Vero::Context.new(Vero::App.default_context)
206
- context.subject = @user
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
- @user.stub(:with_vero_context).and_return(context)
189
+ allow(@user).to receive(:with_vero_context).and_return(context)
210
190
 
211
- @user.with_vero_context.update_user_tags!.should be_nil
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
- :id => nil,
220
- :email => 'durkster@gmail.com'
198
+ id: nil,
199
+ email: 'durkster@gmail.com'
221
200
  }
222
- @url = "https://api.getvero.com/api/v2/users/unsubscribe.json"
201
+ @url = 'https://api.getvero.com/api/v2/users/unsubscribe.json'
223
202
  end
224
203
 
225
- it "should send an `update_user` request when async is set to false" do
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.stub(:with_vero_context).and_return(context)
209
+ allow(@user).to receive(:with_vero_context).and_return(context)
231
210
 
232
- Vero::Api::Users.stub(:unsubscribe!).and_return(200)
233
- Vero::Api::Users.should_receive(:unsubscribe!).with(@request_params, context)
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!.should == 200
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.stub(:with_vero_context).and_return(@context)
220
+ allow(@user).to receive(:with_vero_context).and_return(@context)
242
221
  end
243
222
 
244
- context 'and using Ruby 1.9.3' do
245
- before { stub_const('RUBY_VERSION', '1.9.3') }
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 "should build an array of trackable params" do
232
+ it 'should build an array of trackable params' do
258
233
  User.trackable :email, :age
259
- User.trackable_map.should == [:email, :age]
234
+ expect(User.trackable_map).to eq(%i[email age])
260
235
  end
261
236
 
262
- it "should append new trackable items to an existing trackable map" do
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.should == [:email, :age, :hair_colour]
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, {:extras => :properties}
270
- User.trackable_map.should == [:email, {:extras => :properties}]
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 "should return a hash of all values mapped by trackable" do
255
+ it 'should return a hash of all values mapped by trackable' do
281
256
  user = User.new
282
- user.to_vero.should == {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
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.should == {:email => 'durkster@gmail.com', :age => 20, :_user_type => "UserWithoutEmail"}
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.should == {:email => 'durkster@gmail.com', :age => 20, :_user_type => "UserWithEmailAddress"}
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.should == {:email => 'durkster@gmail.com', :age => 20, :_user_type => "UserWithoutInterface"}
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.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithNilAttributes"}
269
+ expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithNilAttributes' })
295
270
  end
296
271
 
297
- it "should take into account any defined extras" do
272
+ it 'should take into account any defined extras' do
298
273
  user = UserWithExtras.new
299
274
  user.properties = nil
300
- user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithExtras"}
275
+ expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithExtras' })
301
276
 
302
- user.properties = "test"
303
- user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithExtras"}
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.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithExtras"}
281
+ expect(user.to_vero).to eq({ email: 'durkster@gmail.com', _user_type: 'UserWithExtras' })
307
282
 
308
283
  user.properties = {
309
- :age => 20,
310
- :gender => "female"
284
+ age: 20,
285
+ gender: 'female'
311
286
  }
312
- user.to_vero.should == {:email => 'durkster@gmail.com', :age => 20, :gender => "female", :_user_type => "UserWithExtras"}
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.should == {:email => 'durkster@gmail.com', :age => 26, :_user_type => "UserWithPrivateExtras"}
290
+ expect(user.to_vero).to eq({ email: 'durkster@gmail.com', age: 26, _user_type: 'UserWithPrivateExtras' })
316
291
  end
317
292
 
318
- it "should allow extras to be provided instead :id or :email" do
293
+ it 'should allow extras to be provided instead :id or :email' do
319
294
  user = UserWithOnlyExtras.new
320
- user.properties = {:email => user.email}
321
- user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithOnlyExtras"}
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 "should be able to change contexts" do
301
+ it 'should be able to change contexts' do
327
302
  user = User.new
328
- user.with_default_vero_context.config.config_params.should == {:api_key=>"abcd1234", :secret=>"efgh5678"}
329
- user.with_vero_context({:api_key => "boom", :secret => "tish"}).config.config_params.should == {:api_key=>"boom", :secret=>"tish"}
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 "should work when Vero::Trackable::Interface is not included" do
308
+ it 'should work when Vero::Trackable::Interface is not included' do
334
309
  user = UserWithoutInterface.new
335
310
 
336
311
  request_params = {
337
- :event_name => 'test_event',
338
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
339
- :identity => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "UserWithoutInterface"},
340
- :data => { :test => 1 },
341
- :development_mode => true
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.stub(:post_now).and_return(200)
321
+ allow(context).to receive(:post_now).and_return(200)
348
322
 
349
- user.stub(:with_vero_context).and_return(context)
323
+ allow(user).to receive(:with_vero_context).and_return(context)
350
324
 
351
- RestClient.stub(:post).and_return(200)
352
- user.vero_track(request_params[:event_name], request_params[:data]).should == 200
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