vero 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +15 -1
  3. data/Gemfile.lock +95 -73
  4. data/README.markdown +145 -121
  5. data/lib/generators/vero_generator.rb +18 -19
  6. data/lib/vero.rb +7 -3
  7. data/lib/vero/api.rb +14 -4
  8. data/lib/vero/api/base_api.rb +11 -10
  9. data/lib/vero/api/events/track_api.rb +5 -3
  10. data/lib/vero/api/users/delete_api.rb +21 -0
  11. data/lib/vero/api/users/edit_api.rb +5 -3
  12. data/lib/vero/api/users/edit_tags_api.rb +7 -5
  13. data/lib/vero/api/users/reidentify_api.rb +5 -3
  14. data/lib/vero/api/users/resubscribe_api.rb +3 -1
  15. data/lib/vero/api/users/track_api.rb +5 -3
  16. data/lib/vero/api/users/unsubscribe_api.rb +3 -1
  17. data/lib/vero/app.rb +4 -2
  18. data/lib/vero/config.rb +11 -8
  19. data/lib/vero/context.rb +9 -11
  20. data/lib/vero/context/api.rb +9 -7
  21. data/lib/vero/dsl.rb +3 -1
  22. data/lib/vero/railtie.rb +5 -3
  23. data/lib/vero/sender.rb +12 -31
  24. data/lib/vero/senders/base.rb +3 -1
  25. data/lib/vero/senders/delayed_job.rb +7 -7
  26. data/lib/vero/senders/invalid.rb +5 -3
  27. data/lib/vero/senders/resque.rb +8 -8
  28. data/lib/vero/senders/sidekiq.rb +3 -1
  29. data/lib/vero/senders/{thread.rb → sucker_punch.rb} +5 -3
  30. data/lib/vero/trackable.rb +4 -2
  31. data/lib/vero/trackable/base.rb +10 -9
  32. data/lib/vero/trackable/interface.rb +3 -1
  33. data/lib/vero/utility/ext.rb +3 -1
  34. data/lib/vero/utility/logger.rb +4 -6
  35. data/lib/vero/version.rb +3 -1
  36. data/lib/vero/view_helpers/javascript.rb +20 -20
  37. data/spec/lib/api/base_api_spec.rb +10 -8
  38. data/spec/lib/api/events/track_api_spec.rb +23 -21
  39. data/spec/lib/api/users/delete_api_spec.rb +33 -0
  40. data/spec/lib/api/users/edit_api_spec.rb +12 -10
  41. data/spec/lib/api/users/edit_tags_api_spec.rb +22 -20
  42. data/spec/lib/api/users/reidentify_spec.rb +16 -14
  43. data/spec/lib/api/users/resubscribe_api_spec.rb +16 -10
  44. data/spec/lib/api/users/track_api_spec.rb +21 -19
  45. data/spec/lib/api/users/unsubscribe_api_spec.rb +12 -10
  46. data/spec/lib/api_spec.rb +29 -24
  47. data/spec/lib/app_spec.rb +12 -10
  48. data/spec/lib/config_spec.rb +31 -29
  49. data/spec/lib/context_spec.rb +13 -11
  50. data/spec/lib/dsl_spec.rb +3 -1
  51. data/spec/lib/sender_spec.rb +12 -24
  52. data/spec/lib/senders/sidekiq_spec.rb +16 -9
  53. data/spec/lib/trackable_spec.rb +88 -114
  54. data/spec/lib/view_helpers_spec.rb +12 -8
  55. data/spec/spec_helper.rb +10 -4
  56. data/spec/support/base_config_shared_examples.rb +5 -3
  57. data/spec/support/user_support.rb +15 -7
  58. data/spec/support/vero_user_support.rb +4 -2
  59. data/vero.gemspec +14 -30
  60. metadata +30 -125
@@ -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
9
+ it 'should create a new options Hash with symbol keys (much like Hash#symbolize_keys in rails)' do
8
10
  expect(subject.options).to eq({})
9
11
 
10
- subject.options = {:abc => 123}
11
- expect(subject.options).to eq({:abc => 123})
12
+ subject.options = { abc: 123 }
13
+ expect(subject.options).to eq({ abc: 123 })
12
14
 
13
- subject.options = {"abc" => 123}
14
- expect(subject.options).to eq({: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,65 +1,67 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Events::TrackAPI do
4
- subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
6
+ subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }) }
5
7
 
6
- it_behaves_like "a Vero wrapper" do
7
- let(:end_point) { "/api/v2/events/track.json" }
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/events/track.json' }
8
10
  end
9
11
 
10
- context "request with properties" do
12
+ context 'request with properties' do
11
13
  describe :validate! do
12
- it "should raise an error if event_name is a blank String" do
13
- 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 }
14
16
  subject.options = options
15
17
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
16
18
 
17
- 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' }
18
20
  subject.options = options
19
21
  expect { subject.send(:validate!) }.to_not raise_error
20
22
  end
21
23
 
22
- it "should raise an error if data is not either nil or a Hash" do
23
- 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: [] }
24
26
  subject.options = options
25
27
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
26
28
 
27
- 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 }
28
30
  subject.options = options
29
31
  expect { subject.send(:validate!) }.to_not raise_error
30
32
 
31
- 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: {} }
32
34
  subject.options = options
33
35
  expect { subject.send(:validate!) }.to_not raise_error
34
36
  end
35
37
 
36
- it "should not raise an error when the keys are Strings" do
37
- 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' => {} }
38
40
  subject.options = options
39
41
  expect { subject.send(:validate!) }.to_not raise_error
40
42
  end
41
-
43
+
42
44
  it 'should not raise an error when keys are Strings for initialization' do
43
- options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "event_name" => 'test_event', "data" => {}}
45
+ options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'event_name' => 'test_event', 'data' => {} }
44
46
  expect { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', options).send(:validate!) }.to_not raise_error
45
47
  end
46
48
  end
47
49
 
48
50
  describe :request do
49
- it "should send a JSON request to the Vero API" do
50
- 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})
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 })
51
53
  allow(RestClient).to receive(:post).and_return(200)
52
54
  subject.send(:request)
53
55
  end
54
56
  end
55
57
  end
56
58
 
57
- describe "integration test" do
58
- it "should not raise any errors" do
59
- 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' })
60
62
 
61
63
  allow(RestClient).to receive(:post).and_return(200)
62
64
  expect { obj.perform }.to_not raise_error
63
65
  end
64
66
  end
65
- 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,32 +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', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
6
+ subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: 'test@test.com', changes: { email: 'test@test.com' } }) }
5
7
 
6
- it_behaves_like "a Vero wrapper" do
7
- let(:end_point) { "/api/v2/users/edit.json" }
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/edit.json' }
8
10
  end
9
11
 
10
12
  describe :validate! do
11
- it "should not raise an error when the keys are Strings" do
12
- 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' } }
13
15
  subject.options = options
14
16
  expect { subject.send(:validate!) }.to_not raise_error
15
17
  end
16
18
  end
17
19
 
18
20
  describe :request do
19
- it "should send a request to the Vero API" do
20
- 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})
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 })
21
23
  allow(RestClient).to receive(:put).and_return(200)
22
24
  subject.send(:request)
23
25
  end
24
26
  end
25
27
 
26
- describe "integration test" do
27
- it "should not raise any errors" do
28
+ describe 'integration test' do
29
+ it 'should not raise any errors' do
28
30
  allow(RestClient).to receive(:put).and_return(200)
29
31
  expect { subject.perform }.to_not raise_error
30
32
  end
31
33
  end
32
- end
34
+ end
@@ -1,68 +1,70 @@
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', {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}) }
6
+ subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: 'test@test.com', add: ['test'] }) }
5
7
 
6
- it_behaves_like "a Vero wrapper" do
7
- let(:end_point) { "/api/v2/users/tags/edit.json" }
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/tags/edit.json' }
8
10
  end
9
11
 
10
12
  describe :validate! do
11
- it "should raise an error if email is a blank String" do
12
- 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: [] }
13
15
  subject.options = options
14
16
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
15
17
 
16
- 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: [] }
17
19
  subject.options = options
18
20
  expect { subject.send(:validate!) }.to_not raise_error
19
21
  end
20
22
 
21
- it "should raise an error if add is not an Array or missing" do
22
- 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' }
23
25
 
24
26
  subject.options = options
25
27
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
26
28
  end
27
29
 
28
- it "should raise an error if remove is not an Array or missing" do
29
- 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' }
30
32
 
31
33
  subject.options = options
32
34
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
33
35
  end
34
36
 
35
- it "should raise an error if botha add and remove are missing" do
36
- 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' }
37
39
 
38
40
  subject.options = options
39
41
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
40
42
  end
41
43
 
42
- it "should not raise an error if the correct arguments are passed" do
43
- 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'] }
44
46
 
45
47
  subject.options = options
46
48
  expect { subject.send(:validate!) }.to_not raise_error
47
49
  end
48
50
 
49
- it "should not raise an error when the keys are Strings" do
50
- 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'] }
51
53
  subject.options = options
52
54
  expect { subject.send(:validate!) }.to_not raise_error
53
55
  end
54
56
  end
55
57
 
56
58
  describe :request do
57
- it "should send a request to the Vero API" do
58
- 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})
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 })
59
61
  allow(RestClient).to receive(:put).and_return(200)
60
62
  subject.send(:request)
61
63
  end
62
64
  end
63
65
 
64
- describe "integration test" do
65
- it "should not raise any errors" do
66
+ describe 'integration test' do
67
+ it 'should not raise any errors' do
66
68
  allow(RestClient).to receive(:put).and_return(200)
67
69
  expect { subject.perform }.to_not raise_error
68
70
  end
@@ -1,42 +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', {:auth_token => 'abcd', :id => 'test@test.com', :new_id => 'test2@test.com'}) }
6
+ subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', { auth_token: 'abcd', id: 'test@test.com', new_id: 'test2@test.com' }) }
5
7
 
6
- it_behaves_like "a Vero wrapper" do
7
- let(:end_point) { "/api/v2/users/reidentify.json" }
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/reidentify.json' }
8
10
  end
9
11
 
10
12
  describe :validate! do
11
- it "should not raise an error when the keys are Strings" do
12
- 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' }
13
15
  subject.options = options
14
16
  expect { subject.send(:validate!) }.to_not raise_error
15
17
  end
16
18
 
17
- it "should raise an error if id is missing" do
18
- subject.options = {:auth_token => 'abcd', :new_id => 'test2@test.com'}
19
+ it 'should raise an error if id is missing' do
20
+ subject.options = { auth_token: 'abcd', new_id: 'test2@test.com' }
19
21
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
20
22
  end
21
23
 
22
- it "should raise an error if new_id is missing" do
23
- subject.options = {:auth_token => 'abcd', :id => 'test@test.com'}
24
+ it 'should raise an error if new_id is missing' do
25
+ subject.options = { auth_token: 'abcd', id: 'test@test.com' }
24
26
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
25
27
  end
26
28
  end
27
29
 
28
30
  describe :request do
29
- it "should send a request to the Vero API" do
30
- 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})
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 })
31
33
  allow(RestClient).to receive(:put).and_return(200)
32
34
  subject.send(:request)
33
35
  end
34
36
  end
35
37
 
36
- describe "integration test" do
37
- it "should not raise any errors" do
38
+ describe 'integration test' do
39
+ it 'should not raise any errors' do
38
40
  allow(RestClient).to receive(:put).and_return(200)
39
41
  expect { subject.perform }.to_not raise_error
40
42
  end
41
43
  end
42
- end
44
+ end
@@ -1,28 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Users::ResubscribeAPI do
4
- subject { Vero::Api::Workers::Users::ResubscribeAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :id => '1234'}) }
6
+ subject { Vero::Api::Workers::Users::ResubscribeAPI.new('https://api.getvero.com', { auth_token: 'abcd', id: '1234' }) }
5
7
 
6
- it_behaves_like "a Vero wrapper" do
7
- let(:end_point) { "/api/v2/users/resubscribe.json" }
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/resubscribe.json' }
8
10
  end
9
11
 
10
12
  describe :validate! do
11
- it "should not raise an error when the keys are Strings" do
12
- subject.options = {"auth_token" => 'abcd', "id" => '1234'}
13
+ it 'should not raise an error when the keys are Strings' do
14
+ subject.options = { 'auth_token' => 'abcd', 'id' => '1234' }
13
15
  expect { subject.send(:validate!) }.to_not raise_error
14
16
  end
15
17
 
16
- it "should raise an error for missing keys" do
17
- subject.options = {"auth_token" => 'abcd'}
18
+ it 'should raise an error for missing keys' do
19
+ subject.options = { 'auth_token' => 'abcd' }
18
20
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
19
21
  end
20
22
  end
21
23
 
22
24
  describe :request do
23
- it "should send a request to the Vero API" do
24
- RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/users/resubscribe.json", {:auth_token => 'abcd', :id => '1234'})
25
- RestClient.stub(:post).and_return(200)
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
+
26
32
  subject.send(:request)
27
33
  end
28
34
  end
@@ -1,64 +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', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}) }
6
+ subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }) }
5
7
 
6
- it_behaves_like "a Vero wrapper" do
7
- let(:end_point) { "/api/v2/users/track.json" }
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/track.json' }
8
10
  end
9
11
 
10
12
  describe :validate! do
11
- it "should raise an error if email and id are are blank String" do
12
- 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 }
13
15
  subject.options = options
14
16
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
15
17
 
16
- 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' }
17
19
  subject.options = options
18
20
  expect { subject.send(:validate!) }.to_not raise_error
19
21
 
20
- 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 }
21
23
  subject.options = options
22
24
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
23
25
 
24
- 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 }
25
27
  subject.options = options
26
28
  expect { subject.send(:validate!) }.to_not raise_error
27
29
  end
28
30
 
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'}, :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: [] }
31
33
  subject.options = options
32
34
  expect { subject.send(:validate!) }.to raise_error(ArgumentError)
33
35
 
34
- 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 }
35
37
  subject.options = options
36
38
  expect { subject.send(:validate!) }.to_not raise_error
37
39
 
38
- 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: {} }
39
41
  subject.options = options
40
42
  expect { subject.send(:validate!) }.to_not raise_error
41
43
  end
42
44
 
43
- it "should not raise an error when the keys are Strings" do
44
- 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' => {} }
45
47
  subject.options = options
46
48
  expect { subject.send(:validate!) }.to_not raise_error
47
49
  end
48
50
  end
49
51
 
50
52
  describe :request do
51
- it "should send a request to the Vero API" do
52
- 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})
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 })
53
55
  allow(RestClient).to receive(:post).and_return(200)
54
56
  subject.send(:request)
55
57
  end
56
58
  end
57
59
 
58
- describe "integration test" do
59
- it "should not raise any errors" do
60
+ describe 'integration test' do
61
+ it 'should not raise any errors' do
60
62
  allow(RestClient).to receive(:post).and_return(200)
61
63
  expect { subject.perform }.to_not raise_error
62
64
  end
63
65
  end
64
- end
66
+ end