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,36 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Workers::Users::UnsubscribeAPI do
4
- subject { Vero::Api::Workers::Users::UnsubscribeAPI.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::UnsubscribeAPI.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/unsubscribe.json"
8
+ it_behaves_like 'a Vero wrapper' do
9
+ let(:end_point) { '/api/v2/users/unsubscribe.json' }
11
10
  end
12
11
 
13
- subject { Vero::Api::Workers::Users::UnsubscribeAPI.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(:post).with("https://api.getvero.com/api/v2/users/unsubscribe.json", {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }})
25
- RestClient.stub(:post).and_return(200)
21
+ it 'should send a request to the Vero API' do
22
+ expect(RestClient).to receive(:post).with('https://api.getvero.com/api/v2/users/unsubscribe.json', { auth_token: 'abcd', email: 'test@test.com', changes: { email: 'test@test.com' } })
23
+ allow(RestClient).to receive(:post).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(:post).and_return(200)
28
+ describe 'integration test' do
29
+ it 'should not raise any errors' do
30
+ allow(RestClient).to receive(:post).and_return(200)
33
31
  expect { subject.perform }.to_not raise_error
34
32
  end
35
33
  end
36
- end
34
+ end
@@ -1,20 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Api::Events do
4
- let (:subject) { Vero::Api::Events }
6
+ let(:subject) { Vero::Api::Events }
5
7
 
6
8
  describe :track! do
7
- it "should call the TrackAPI object via the configured sender" do
8
- input = {:event_name => "test_event", :identity => {:email => "james@getvero.com"}, :data => {:test => "test"}}
9
- expected = input.merge(:auth_token => "abc123", :development_mode => true)
9
+ it 'should call the TrackAPI object via the configured sender' do
10
+ input = { event_name: 'test_event', identity: { email: 'james@getvero.com' }, data: { test: 'test' } }
11
+ expected = input.merge(auth_token: 'abc123', development_mode: true)
10
12
 
11
13
  mock_context = Vero::Context.new
12
- mock_context.config.stub(:configured?).and_return(true)
13
- mock_context.config.stub(:auth_token).and_return("abc123")
14
+ allow(mock_context.config).to receive(:configured?).and_return(true)
15
+ allow(mock_context.config).to receive(:auth_token).and_return('abc123')
16
+ allow(mock_context.config).to receive(:development_mode).and_return(true)
14
17
 
15
- Vero::App.stub(:default_context).and_return(mock_context)
18
+ allow(Vero::App).to receive(:default_context).and_return(mock_context)
16
19
 
17
- Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Events::TrackAPI, true, "https://api.getvero.com", expected)
20
+ expect(Vero::Sender).to receive(:send).with(Vero::Api::Workers::Events::TrackAPI, true, 'https://api.getvero.com', expected)
18
21
 
19
22
  subject.track!(input)
20
23
  end
@@ -22,73 +25,72 @@ describe Vero::Api::Events do
22
25
  end
23
26
 
24
27
  describe Vero::Api::Users do
25
- let (:subject) { Vero::Api::Users }
28
+ let(:subject) { Vero::Api::Users }
29
+ let(:mock_context) { Vero::Context.new }
30
+ let(:expected) { input.merge(auth_token: 'abc123', development_mode: true) }
31
+
32
+ before :each do
33
+ allow(mock_context.config).to receive(:configured?).and_return(true)
34
+ allow(mock_context.config).to receive(:auth_token).and_return('abc123')
35
+ allow(mock_context.config).to receive(:development_mode).and_return(true)
36
+ allow(Vero::App).to receive(:default_context).and_return(mock_context)
37
+ end
26
38
 
27
39
  describe :track! do
28
- it "should call the TrackAPI object via the configured sender" do
29
- input = {:email => "james@getvero.com", :data => {:age => 25}}
30
- expected = input.merge(:auth_token => "abc123", :development_mode => true)
31
-
32
- mock_context = Vero::Context.new
33
- mock_context.config.stub(:configured?).and_return(true)
34
- mock_context.config.stub(:auth_token).and_return("abc123")
35
-
36
- Vero::App.stub(:default_context).and_return(mock_context)
37
-
38
- Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::TrackAPI, true, "https://api.getvero.com", expected)
40
+ context 'should call the TrackAPI object via the configured sender' do
41
+ let(:input) { { email: 'james@getvero.com', data: { age: 25 } } }
39
42
 
40
- subject.track!(input)
43
+ specify do
44
+ expect(Vero::Sender).to receive(:send).with(Vero::Api::Workers::Users::TrackAPI, true, 'https://api.getvero.com', expected)
45
+ subject.track!(input)
46
+ end
41
47
  end
42
48
  end
43
49
 
44
50
  describe :edit_user! do
45
- it "should call the TrackAPI object via the configured sender" do
46
- input = {:email => "james@getvero.com", :changes => {:age => 25}}
47
- expected = input.merge(:auth_token => "abc123", :development_mode => true)
48
-
49
- mock_context = Vero::Context.new
50
- mock_context.config.stub(:configured?).and_return(true)
51
- mock_context.config.stub(:auth_token).and_return("abc123")
52
-
53
- Vero::App.stub(:default_context).and_return(mock_context)
54
-
55
- Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::EditAPI, true, "https://api.getvero.com", expected)
51
+ context 'should call the TrackAPI object via the configured sender' do
52
+ let(:input) { { email: 'james@getvero.com', changes: { age: 25 } } }
56
53
 
57
- subject.edit_user!(input)
54
+ specify do
55
+ expect(Vero::Sender).to receive(:send).with(Vero::Api::Workers::Users::EditAPI, true, 'https://api.getvero.com', expected)
56
+ subject.edit_user!(input)
57
+ end
58
58
  end
59
59
  end
60
60
 
61
61
  describe :edit_user_tags! do
62
- it "should call the TrackAPI object via the configured sender" do
63
- input = {:add => ["boom"], :remove => ["tish"]}
64
- expected = input.merge(:auth_token => "abc123", :development_mode => true)
62
+ context 'should call the TrackAPI object via the configured sender' do
63
+ let(:input) { { add: ['boom'], remove: ['tish'] } }
65
64
 
66
- mock_context = Vero::Context.new
67
- mock_context.config.stub(:configured?).and_return(true)
68
- mock_context.config.stub(:auth_token).and_return("abc123")
69
-
70
- Vero::App.stub(:default_context).and_return(mock_context)
71
-
72
- Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::EditTagsAPI, true, "https://api.getvero.com", expected)
73
-
74
- subject.edit_user_tags!(input)
65
+ specify do
66
+ expect(Vero::Sender).to receive(:send).with(Vero::Api::Workers::Users::EditTagsAPI, true, 'https://api.getvero.com', expected)
67
+ subject.edit_user_tags!(input)
68
+ end
75
69
  end
76
70
  end
77
71
 
78
72
  describe :unsubscribe! do
79
- it "should call the TrackAPI object via the configured sender" do
80
- input = {:email => "james@getvero"}
81
- expected = input.merge(:auth_token => "abc123", :development_mode => true)
82
-
83
- mock_context = Vero::Context.new
84
- mock_context.config.stub(:configured?).and_return(true)
85
- mock_context.config.stub(:auth_token).and_return("abc123")
86
-
87
- Vero::App.stub(:default_context).and_return(mock_context)
73
+ context 'should call the TrackAPI object via the configured sender' do
74
+ let(:input) { { email: 'james@getvero' } }
88
75
 
89
- Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::UnsubscribeAPI, true, "https://api.getvero.com", expected)
76
+ specify do
77
+ expect(Vero::Sender).to receive(:send).with(Vero::Api::Workers::Users::UnsubscribeAPI, true, 'https://api.getvero.com', expected)
78
+ subject.unsubscribe!(input)
79
+ end
80
+ end
81
+ end
90
82
 
91
- subject.unsubscribe!(input)
83
+ describe :resubscribe! do
84
+ context 'should call the TrackAPI object via the configured sender' do
85
+ let(:input) { { email: 'james@getvero' } }
86
+
87
+ specify do
88
+ expect(Vero::Sender).to(
89
+ receive(:send)
90
+ .with(Vero::Api::Workers::Users::ResubscribeAPI, true, 'https://api.getvero.com', expected)
91
+ )
92
+ subject.resubscribe!(input)
93
+ end
92
94
  end
93
95
  end
94
- end
96
+ end
@@ -1,58 +1,60 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::App do
4
6
  describe 'self.default_context' do
5
- it "inherits from Vero::Context" do
7
+ it 'inherits from Vero::Context' do
6
8
  actual = Vero::App.default_context
7
- actual.should be_a(Vero::Context)
9
+ expect(actual).to be_a(Vero::Context)
8
10
  end
9
11
  end
10
12
 
11
- let (:context) { Vero::App.default_context }
13
+ let(:context) { Vero::App.default_context }
12
14
  describe :init do
13
- it "should ignore configuring the config if no block is provided" do
15
+ it 'should ignore configuring the config if no block is provided' do
14
16
  Vero::App.init
15
- context.configured?.should be_false
17
+ expect(context.configured?).to be(false)
16
18
  end
17
19
 
18
- it "should pass configuration defined in the block to the config file" do
20
+ it 'should pass configuration defined in the block to the config file' do
19
21
  Vero::App.init
20
22
 
21
- context.config.api_key.should be_nil
23
+ expect(context.config.api_key).to be_nil
22
24
  Vero::App.init do |c|
23
- c.api_key = "abcd1234"
25
+ c.api_key = 'abcd1234'
24
26
  end
25
- context.config.api_key.should == "abcd1234"
27
+ expect(context.config.api_key).to eq('abcd1234')
26
28
  end
27
29
 
28
- it "should init should be able to set async" do
30
+ it 'should init should be able to set async' do
29
31
  Vero::App.init do |c|
30
32
  c.async = false
31
33
  end
32
- context.config.async.should be_false
34
+ expect(context.config.async).to be(false)
33
35
 
34
36
  Vero::App.init do |c|
35
37
  c.async = true
36
38
  end
37
- context.config.async.should be_true
39
+ expect(context.config.async).to be(true)
38
40
  end
39
41
  end
40
42
 
41
43
  describe :disable_requests! do
42
- it "should change config.disabled" do
44
+ it 'should change config.disabled' do
43
45
  Vero::App.init {}
44
- context.config.disabled.should be_false
46
+ expect(context.config.disabled).to be(false)
45
47
 
46
48
  Vero::App.disable_requests!
47
- context.config.disabled.should be_true
49
+ expect(context.config.disabled).to be(true)
48
50
  end
49
51
  end
50
52
 
51
53
  describe :log do
52
- it "should have a log method" do
54
+ it 'should have a log method' do
53
55
  Vero::App.init {}
54
- Vero::App.should_receive(:log)
55
- Vero::App.log(Object, "test")
56
+ expect(Vero::App).to receive(:log)
57
+ Vero::App.log(Object, 'test')
56
58
  end
57
59
  end
58
- end
60
+ end
@@ -1,95 +1,113 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Vero::Config do
4
- before :each do
5
- @config = Vero::Config.new
6
- end
6
+ let(:config) { Vero::Config.new }
7
7
 
8
- it "should be async by default" do
9
- @config.async.should be_true
8
+ it 'should be async by default' do
9
+ expect(config.async).to be(true)
10
10
  end
11
11
 
12
12
  describe :reset! do
13
- it "should reset all attributes" do
14
- @config.api_key = "abcd1234"
15
- @config.secret = "abcd1234"
13
+ it 'should reset all attributes' do
14
+ config.api_key = 'abcd1234'
15
+ config.secret = 'abcd1234'
16
+ config.reset!
16
17
 
17
- @config.reset!
18
- @config.api_key.should be_nil
19
- @config.secret.should be_nil
18
+ expect(config.api_key).to be_nil
19
+ expect(config.secret).to be_nil
20
20
  end
21
21
  end
22
22
 
23
23
  describe :auth_token do
24
- it "should return nil if either api_key or secret are not set" do
25
- @config.api_key = nil
26
- @config.secret = "abcd"
27
- @config.auth_token.should be_nil
28
-
29
- @config.api_key = "abcd"
30
- @config.secret = nil
31
- @config.auth_token.should be_nil
32
-
33
- @config.api_key = "abcd"
34
- @config.secret = "abcd"
35
- @config.auth_token.should_not be_nil
24
+ it 'should return nil if either api_key or secret are not set' do
25
+ config.api_key = nil
26
+ config.secret = 'abcd'
27
+ expect(config.auth_token).to be_nil
28
+
29
+ config.api_key = 'abcd'
30
+ config.secret = nil
31
+ expect(config.auth_token).to be_nil
32
+
33
+ config.api_key = 'abcd'
34
+ config.secret = 'abcd'
35
+ expect(config.auth_token).not_to be_nil
36
36
  end
37
37
 
38
- it "should return an expected auth_token" do
39
- @config.api_key = "abcd1234"
40
- @config.secret = "efgh5678"
41
- @config.auth_token.should == "YWJjZDEyMzQ6ZWZnaDU2Nzg="
38
+ it 'should return an expected auth_token' do
39
+ config.api_key = 'abcd1234'
40
+ config.secret = 'efgh5678'
41
+ expect(config.auth_token).to eq('YWJjZDEyMzQ6ZWZnaDU2Nzg=')
42
42
  end
43
43
  end
44
44
 
45
45
  describe :request_params do
46
- it "should return a hash of auth_token and development_mode if they are set" do
47
- @config.api_key = nil
48
- @config.secret = nil
49
- @config.development_mode = nil
50
- @config.request_params.should == {}
51
-
52
- @config.api_key = "abcd1234"
53
- @config.secret = "abcd1234"
54
- @config.request_params.should == {:auth_token => "YWJjZDEyMzQ6YWJjZDEyMzQ="}
55
-
56
- @config.development_mode = true
57
- @config.request_params.should == {:auth_token => "YWJjZDEyMzQ6YWJjZDEyMzQ=", :development_mode => true}
46
+ it 'should return a hash of auth_token and development_mode if they are set' do
47
+ config.api_key = nil
48
+ config.secret = nil
49
+ config.development_mode = nil
50
+ expect(config.request_params).to eq({})
51
+
52
+ config.api_key = 'abcd1234'
53
+ config.secret = 'abcd1234'
54
+ expect(config.request_params).to eq({ auth_token: 'YWJjZDEyMzQ6YWJjZDEyMzQ=' })
55
+
56
+ config.development_mode = true
57
+ expect(config.request_params).to eq({ auth_token: 'YWJjZDEyMzQ6YWJjZDEyMzQ=', development_mode: true })
58
58
  end
59
59
  end
60
60
 
61
61
  describe :domain do
62
- it "should return https://api.getvero.com when not set" do
63
- @config.domain.should == 'https://api.getvero.com'
64
- @config.domain = 'blah.com'
65
- @config.domain.should_not == 'https://api.getvero.com'
62
+ it 'should return https://api.getvero.com when not set' do
63
+ expect(config.domain).to eq('https://api.getvero.com')
64
+ config.domain = 'blah.com'
65
+ expect(config.domain).not_to eq('https://api.getvero.com')
66
66
  end
67
67
 
68
- it "should return the domain value" do
69
- @config.domain = 'test.unbelieveable.com.au'
70
- @config.domain.should == 'http://test.unbelieveable.com.au'
68
+ it 'should return the domain value' do
69
+ config.domain = 'test.unbelieveable.com.au'
70
+ expect(config.domain).to eq('http://test.unbelieveable.com.au')
71
71
 
72
- @config.domain = 'http://test.unbelieveable.com.au'
73
- @config.domain.should == 'http://test.unbelieveable.com.au'
72
+ config.domain = 'http://test.unbelieveable.com.au'
73
+ expect(config.domain).to eq('http://test.unbelieveable.com.au')
74
74
  end
75
75
  end
76
76
 
77
77
  describe :development_mode do
78
- it "by default it should return true when Rails.env is either development or test" do
79
- stub_env('development') {
78
+ it 'by default it should return false regardless of Rails environment' do
79
+ stub_env('development') do
80
80
  config = Vero::Config.new
81
- config.development_mode.should be_true
82
- }
81
+ expect(config.development_mode).to be(false)
82
+ end
83
83
 
84
- stub_env('test') {
84
+ stub_env('test') do
85
85
  config = Vero::Config.new
86
- config.development_mode.should be_true
87
- }
86
+ expect(config.development_mode).to be(false)
87
+ end
88
88
 
89
- stub_env('production') {
89
+ stub_env('production') do
90
90
  config = Vero::Config.new
91
- config.development_mode.should be_false
92
- }
91
+ expect(config.development_mode).to be(false)
92
+ end
93
+ end
94
+
95
+ it 'can be overritten with the config block' do
96
+ config.development_mode = true
97
+ expect(config.request_params[:development_mode]).to be(true)
98
+
99
+ config.reset!
100
+ expect(config.request_params[:development_mode]).to be(false)
101
+ end
102
+ end
103
+
104
+ describe :test_mode do
105
+ it 'should not raise error even though not configured properly' do
106
+ input = { event_name: 'test_event' }
107
+ mock_context = Vero::Context.new
108
+ allow(mock_context.config).to receive(:configured?).and_return(false)
109
+
110
+ expect { Vero::Api::Events.track!(input) }.to_not raise_error
93
111
  end
94
112
  end
95
- end
113
+ end