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,17 +1,19 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::BaseAPI do
4
- let (:subject) { Vero::Api::Workers::BaseAPI.new("http://www.getvero.com", {}) }
6
+ let(:subject) { Vero::Api::Workers::BaseAPI.new('http://www.getvero.com', {}) }
5
7
 
6
8
  describe :options_with_symbolized_keys do
7
- it "should create a new options Hash with symbol keys (much like Hash#symbolize_keys in rails)" do
8
- subject.options.should == {}
9
+ it 'should create a new options Hash with symbol keys (much like Hash#symbolize_keys in rails)' do
10
+ expect(subject.options).to eq({})
9
11
 
10
- subject.options = {:abc => 123}
11
- subject.options.should == {:abc => 123}
12
+ subject.options = { abc: 123 }
13
+ expect(subject.options).to eq({ abc: 123 })
12
14
 
13
- subject.options = {"abc" => 123}
14
- subject.options.should == {:abc => 123}
15
+ subject.options = { 'abc' => 123 }
16
+ expect(subject.options).to eq({ abc: 123 })
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -1,67 +1,67 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Events::TrackAPI do
6
+ subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }) }
4
7
 
5
- context "request without properties" do
6
- subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {}) }
7
- it "should inherit from Vero::Api::Workers::BaseCaller" do
8
- subject.should be_a(Vero::Api::Workers::BaseAPI)
9
- end
10
-
11
- it "should map to current version of Vero API" do
12
- subject.send(:url).should == "https://api.getvero.com/api/v2/events/track.json"
13
- end
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/events/track.json' }
14
10
  end
15
11
 
16
- context "request with properties" do
17
- subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
12
+ context 'request with properties' do
18
13
  describe :validate! do
19
- it "should raise an error if event_name is a blank String" do
20
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => nil}
14
+ it 'should raise an error if event_name is a blank String' do
15
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: nil }
21
16
  subject.options = options
22
- expect { subject.send(:validate!) }.to raise_error
17
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
23
18
 
24
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}
19
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }
25
20
  subject.options = options
26
21
  expect { subject.send(:validate!) }.to_not raise_error
27
22
  end
28
23
 
29
- it "should raise an error if data is not either nil or a Hash" do
30
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => []}
24
+ it 'should raise an error if data is not either nil or a Hash' do
25
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event', data: [] }
31
26
  subject.options = options
32
- expect { subject.send(:validate!) }.to raise_error
27
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
33
28
 
34
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => nil}
29
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event', data: nil }
35
30
  subject.options = options
36
31
  expect { subject.send(:validate!) }.to_not raise_error
37
32
 
38
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => {}}
33
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event', data: {} }
39
34
  subject.options = options
40
35
  expect { subject.send(:validate!) }.to_not raise_error
41
36
  end
42
37
 
43
- it "should not raise an error when the keys are Strings" do
44
- options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "event_name" => 'test_event', "data" => {}}
38
+ it 'should not raise an error when the keys are Strings' do
39
+ options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'event_name' => 'test_event', 'data' => {} }
45
40
  subject.options = options
46
41
  expect { subject.send(:validate!) }.to_not raise_error
47
42
  end
43
+
44
+ it 'should not raise an error when keys are Strings for initialization' do
45
+ options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'event_name' => 'test_event', 'data' => {} }
46
+ expect { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', options).send(:validate!) }.to_not raise_error
47
+ end
48
48
  end
49
49
 
50
50
  describe :request do
51
- it "should send a JSON request to the Vero API" do
52
- RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/events/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}.to_json, {:content_type => :json, :accept => :json})
53
- RestClient.stub(:post).and_return(200)
51
+ it 'should send a JSON request to the Vero API' do
52
+ expect(RestClient).to receive(:post).with('https://api.getvero.com/api/v2/events/track.json', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }.to_json, { content_type: :json, accept: :json })
53
+ allow(RestClient).to receive(:post).and_return(200)
54
54
  subject.send(:request)
55
55
  end
56
56
  end
57
57
  end
58
58
 
59
- describe "integration test" do
60
- it "should not raise any errors" do
61
- obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'})
59
+ describe 'integration test' do
60
+ it 'should not raise any errors' do
61
+ obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' })
62
62
 
63
- RestClient.stub(:post).and_return(200)
63
+ allow(RestClient).to receive(:post).and_return(200)
64
64
  expect { obj.perform }.to_not raise_error
65
65
  end
66
66
  end
67
- end
67
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::Api::Workers::Users::DeleteAPI do
4
+ subject { Vero::Api::Workers::Users::DeleteAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :id => '1234'}) }
5
+
6
+ it_behaves_like "a Vero wrapper" do
7
+ let(:end_point) { "/api/v2/users/delete.json" }
8
+ end
9
+
10
+ it_behaves_like "a Vero wrapper" do
11
+ let(:end_point) { "/api/v2/users/delete.json" }
12
+ end
13
+
14
+ describe :validate! do
15
+ it "should not raise an error when the keys are Strings" do
16
+ subject.options = {"auth_token" => 'abcd', "id" => '1234'}
17
+ expect { subject.send(:validate!) }.to_not raise_error
18
+ end
19
+
20
+ it "should raise an error for missing keys" do
21
+ subject.options = {"auth_token" => 'abcd'}
22
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
23
+ end
24
+ end
25
+
26
+ describe :request do
27
+ it "should send a request to the Vero API" do
28
+ RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/users/delete.json", {:auth_token => 'abcd', :id => '1234'})
29
+ RestClient.stub(:post).and_return(200)
30
+ subject.send(:request)
31
+ end
32
+ end
33
+ end
@@ -1,36 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Users::EditAPI do
4
- subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', {}) }
5
- it "should inherit from Vero::Api::Workers::BaseCaller" do
6
- subject.should be_a(Vero::Api::Workers::BaseAPI)
7
- end
6
+ subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: 'test@test.com', changes: { email: 'test@test.com' } }) }
8
7
 
9
- it "should map to current version of Vero API" do
10
- subject.send(:url).should == "https://api.getvero.com/api/v2/users/edit.json"
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/edit.json' }
11
10
  end
12
11
 
13
- subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
14
12
  describe :validate! do
15
- it "should not raise an error when the keys are Strings" do
16
- options = {"auth_token" => 'abcd', "email" => 'test@test.com', "changes" => { "email" => 'test@test.com' }}
13
+ it 'should not raise an error when the keys are Strings' do
14
+ options = { 'auth_token' => 'abcd', 'email' => 'test@test.com', 'changes' => { 'email' => 'test@test.com' } }
17
15
  subject.options = options
18
16
  expect { subject.send(:validate!) }.to_not raise_error
19
17
  end
20
18
  end
21
19
 
22
20
  describe :request do
23
- it "should send a request to the Vero API" do
24
- RestClient.should_receive(:put).with("https://api.getvero.com/api/v2/users/edit.json", {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}.to_json, {:content_type => :json, :accept => :json})
25
- RestClient.stub(:put).and_return(200)
21
+ it 'should send a request to the Vero API' do
22
+ expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/edit.json', { auth_token: 'abcd', email: 'test@test.com', changes: { email: 'test@test.com' } }.to_json, { content_type: :json, accept: :json })
23
+ allow(RestClient).to receive(:put).and_return(200)
26
24
  subject.send(:request)
27
25
  end
28
26
  end
29
27
 
30
- describe "integration test" do
31
- it "should not raise any errors" do
32
- RestClient.stub(:put).and_return(200)
28
+ describe 'integration test' do
29
+ it 'should not raise any errors' do
30
+ allow(RestClient).to receive(:put).and_return(200)
33
31
  expect { subject.perform }.to_not raise_error
34
32
  end
35
33
  end
36
- end
34
+ end
@@ -1,74 +1,71 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Users::EditTagsAPI do
4
- subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', {}) }
5
- it "should inherit from Vero::Api::Workers::BaseCaller" do
6
- subject.should be_a(Vero::Api::Workers::BaseAPI)
7
- end
6
+ subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: 'test@test.com', add: ['test'] }) }
8
7
 
9
- it "should map to current version of Vero API" do
10
- subject.send(:url).should == "https://api.getvero.com/api/v2/users/tags/edit.json"
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/tags/edit.json' }
11
10
  end
12
11
 
13
- subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}) }
14
-
15
12
  describe :validate! do
16
- it "should raise an error if email is a blank String" do
17
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => nil, :add => []}
13
+ it 'should raise an error if email is a blank String' do
14
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: nil, add: [] }
18
15
  subject.options = options
19
- expect { subject.send(:validate!) }.to raise_error
16
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
20
17
 
21
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :add => []}
18
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', add: [] }
22
19
  subject.options = options
23
20
  expect { subject.send(:validate!) }.to_not raise_error
24
21
  end
25
22
 
26
- it "should raise an error if add is not an Array or missing" do
27
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :add => "foo" }
23
+ it 'should raise an error if add is not an Array or missing' do
24
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', add: 'foo' }
28
25
 
29
26
  subject.options = options
30
- expect { subject.send(:validate!) }.to raise_error
27
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
31
28
  end
32
29
 
33
- it "should raise an error if remove is not an Array or missing" do
34
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :remove => "foo" }
30
+ it 'should raise an error if remove is not an Array or missing' do
31
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', remove: 'foo' }
35
32
 
36
33
  subject.options = options
37
- expect { subject.send(:validate!) }.to raise_error
34
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
38
35
  end
39
36
 
40
- it "should raise an error if botha add and remove are missing" do
41
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}
37
+ it 'should raise an error if botha add and remove are missing' do
38
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }
42
39
 
43
40
  subject.options = options
44
- expect { subject.send(:validate!) }.to raise_error
41
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
45
42
  end
46
43
 
47
- it "should not raise an error if the correct arguments are passed" do
48
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :remove => [ "Hi" ] }
44
+ it 'should not raise an error if the correct arguments are passed' do
45
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', remove: ['Hi'] }
49
46
 
50
47
  subject.options = options
51
48
  expect { subject.send(:validate!) }.to_not raise_error
52
49
  end
53
50
 
54
- it "should not raise an error when the keys are Strings" do
55
- options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "email" => 'test@test.com', "remove" => [ "Hi" ] }
51
+ it 'should not raise an error when the keys are Strings' do
52
+ options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'email' => 'test@test.com', 'remove' => ['Hi'] }
56
53
  subject.options = options
57
54
  expect { subject.send(:validate!) }.to_not raise_error
58
55
  end
59
56
  end
60
57
 
61
58
  describe :request do
62
- it "should send a request to the Vero API" do
63
- RestClient.should_receive(:put).with("https://api.getvero.com/api/v2/users/tags/edit.json", {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}.to_json, {:content_type => :json, :accept => :json})
64
- RestClient.stub(:put).and_return(200)
59
+ it 'should send a request to the Vero API' do
60
+ expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/tags/edit.json', { auth_token: 'abcd', email: 'test@test.com', add: ['test'] }.to_json, { content_type: :json, accept: :json })
61
+ allow(RestClient).to receive(:put).and_return(200)
65
62
  subject.send(:request)
66
63
  end
67
64
  end
68
65
 
69
- describe "integration test" do
70
- it "should not raise any errors" do
71
- RestClient.stub(:put).and_return(200)
66
+ describe 'integration test' do
67
+ it 'should not raise any errors' do
68
+ allow(RestClient).to receive(:put).and_return(200)
72
69
  expect { subject.perform }.to_not raise_error
73
70
  end
74
71
  end
@@ -1,46 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Users::ReidentifyAPI do
4
- subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', {}) }
5
- it "should inherit from Vero::Api::Workers::BaseCaller" do
6
- subject.should be_a(Vero::Api::Workers::BaseAPI)
7
- end
6
+ subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', { auth_token: 'abcd', id: 'test@test.com', new_id: 'test2@test.com' }) }
8
7
 
9
- it "should map to current version of Vero API" do
10
- subject.send(:url).should == "https://api.getvero.com/api/v2/users/reidentify.json"
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/reidentify.json' }
11
10
  end
12
11
 
13
- subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :id => 'test@test.com', :new_id => 'test2@test.com'}) }
14
12
  describe :validate! do
15
- it "should not raise an error when the keys are Strings" do
16
- options = {"auth_token" => 'abcd', "id" => 'test@test.com', "new_id" => 'test2@test.com'}
13
+ it 'should not raise an error when the keys are Strings' do
14
+ options = { 'auth_token' => 'abcd', 'id' => 'test@test.com', 'new_id' => 'test2@test.com' }
17
15
  subject.options = options
18
16
  expect { subject.send(:validate!) }.to_not raise_error
19
17
  end
20
18
 
21
- it "should raise an error if id is missing" do
22
- subject.options = {:auth_token => 'abcd', :new_id => 'test2@test.com'}
23
- expect { subject.send(:validate!) }.to raise_error
19
+ it 'should raise an error if id is missing' do
20
+ subject.options = { auth_token: 'abcd', new_id: 'test2@test.com' }
21
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
24
22
  end
25
23
 
26
- it "should raise an error if new_id is missing" do
27
- subject.options = {:auth_token => 'abcd', :id => 'test@test.com'}
28
- expect { subject.send(:validate!) }.to raise_error
24
+ it 'should raise an error if new_id is missing' do
25
+ subject.options = { auth_token: 'abcd', id: 'test@test.com' }
26
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
29
27
  end
30
28
  end
31
29
 
32
30
  describe :request do
33
- it "should send a request to the Vero API" do
34
- RestClient.should_receive(:put).with("https://api.getvero.com/api/v2/users/reidentify.json", {:auth_token => 'abcd', :id => 'test@test.com', :new_id => 'test2@test.com'}.to_json, {:content_type => :json, :accept => :json})
35
- RestClient.stub(:put).and_return(200)
31
+ it 'should send a request to the Vero API' do
32
+ expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/reidentify.json', { auth_token: 'abcd', id: 'test@test.com', new_id: 'test2@test.com' }.to_json, { content_type: :json, accept: :json })
33
+ allow(RestClient).to receive(:put).and_return(200)
36
34
  subject.send(:request)
37
35
  end
38
36
  end
39
37
 
40
- describe "integration test" do
41
- it "should not raise any errors" do
42
- RestClient.stub(:put).and_return(200)
38
+ describe 'integration test' do
39
+ it 'should not raise any errors' do
40
+ allow(RestClient).to receive(:put).and_return(200)
43
41
  expect { subject.perform }.to_not raise_error
44
42
  end
45
43
  end
46
- end
44
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Vero::Api::Workers::Users::ResubscribeAPI do
6
+ subject { Vero::Api::Workers::Users::ResubscribeAPI.new('https://api.getvero.com', { auth_token: 'abcd', id: '1234' }) }
7
+
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/resubscribe.json' }
10
+ end
11
+
12
+ describe :validate! do
13
+ it 'should not raise an error when the keys are Strings' do
14
+ subject.options = { 'auth_token' => 'abcd', 'id' => '1234' }
15
+ expect { subject.send(:validate!) }.to_not raise_error
16
+ end
17
+
18
+ it 'should raise an error for missing keys' do
19
+ subject.options = { 'auth_token' => 'abcd' }
20
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
21
+ end
22
+ end
23
+
24
+ describe :request do
25
+ it 'should send a request to the Vero API' do
26
+ expect(RestClient).to(
27
+ receive(:post)
28
+ .with('https://api.getvero.com/api/v2/users/resubscribe.json', { auth_token: 'abcd', id: '1234' })
29
+ )
30
+ allow(RestClient).to receive(:post).and_return(200)
31
+
32
+ subject.send(:request)
33
+ end
34
+ end
35
+ end
@@ -1,68 +1,66 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Users::TrackAPI do
4
- subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', {}) }
5
- it "should inherit from Vero::Api::Workers::BaseCaller" do
6
- subject.should be_a(Vero::Api::Workers::BaseAPI)
7
- end
6
+ subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }) }
8
7
 
9
- it "should map to current version of Vero API" do
10
- subject.send(:url).should == "https://api.getvero.com/api/v2/users/track.json"
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/track.json' }
11
10
  end
12
11
 
13
- subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}) }
14
12
  describe :validate! do
15
- it "should raise an error if email and id are are blank String" do
16
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => nil, :email => nil}
13
+ it 'should raise an error if email and id are are blank String' do
14
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: nil, email: nil }
17
15
  subject.options = options
18
- expect { subject.send(:validate!) }.to raise_error
16
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
19
17
 
20
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => nil, :email => 'test@test.com'}
18
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: nil, email: 'test@test.com' }
21
19
  subject.options = options
22
20
  expect { subject.send(:validate!) }.to_not raise_error
23
21
 
24
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => "", :email => nil}
22
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: '', email: nil }
25
23
  subject.options = options
26
- expect { subject.send(:validate!) }.to raise_error
24
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
27
25
 
28
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => "user123", :email => nil}
26
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: 'user123', email: nil }
29
27
  subject.options = options
30
28
  expect { subject.send(:validate!) }.to_not raise_error
31
29
  end
32
30
 
33
- it "should raise an error if data is not either nil or a Hash" do
34
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :data => []}
31
+ it 'should raise an error if data is not either nil or a Hash' do
32
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', data: [] }
35
33
  subject.options = options
36
- expect { subject.send(:validate!) }.to raise_error
34
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
37
35
 
38
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :data => nil}
36
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', data: nil }
39
37
  subject.options = options
40
38
  expect { subject.send(:validate!) }.to_not raise_error
41
39
 
42
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :data => {}}
40
+ options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', data: {} }
43
41
  subject.options = options
44
42
  expect { subject.send(:validate!) }.to_not raise_error
45
43
  end
46
44
 
47
- it "should not raise an error when the keys are Strings" do
48
- options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "email" => 'test@test.com', "data" => {}}
45
+ it 'should not raise an error when the keys are Strings' do
46
+ options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'email' => 'test@test.com', 'data' => {} }
49
47
  subject.options = options
50
48
  expect { subject.send(:validate!) }.to_not raise_error
51
49
  end
52
50
  end
53
51
 
54
52
  describe :request do
55
- it "should send a request to the Vero API" do
56
- RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/users/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}.to_json, {:content_type => :json, :accept => :json})
57
- RestClient.stub(:post).and_return(200)
53
+ it 'should send a request to the Vero API' do
54
+ expect(RestClient).to receive(:post).with('https://api.getvero.com/api/v2/users/track.json', { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }.to_json, { content_type: :json, accept: :json })
55
+ allow(RestClient).to receive(:post).and_return(200)
58
56
  subject.send(:request)
59
57
  end
60
58
  end
61
59
 
62
- describe "integration test" do
63
- it "should not raise any errors" do
64
- RestClient.stub(:post).and_return(200)
60
+ describe 'integration test' do
61
+ it 'should not raise any errors' do
62
+ allow(RestClient).to receive(:post).and_return(200)
65
63
  expect { subject.perform }.to_not raise_error
66
64
  end
67
65
  end
68
- end
66
+ end