vero 0.3.2 → 0.4

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.
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::API::Users::UnsubscribeAPI do
4
+ subject { Vero::API::Users::UnsubscribeAPI.new('https://www.getvero.com', {}) }
5
+ it "should inherit from Vero::API::BaseCaller" do
6
+ subject.should be_a(Vero::API::BaseAPI)
7
+ end
8
+
9
+ it "should map to current version of Vero API" do
10
+ subject.send(:url).should == "https://www.getvero.com/api/v2/users/unsubscribe.json"
11
+ end
12
+
13
+ subject { Vero::API::Users::UnsubscribeAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
14
+ describe :validate! do
15
+ end
16
+
17
+ describe :request do
18
+ it "should send a request to the Vero API" do
19
+ RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/users/unsubscribe.json", {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }})
20
+ RestClient.stub(:post).and_return(200)
21
+ subject.send(:request)
22
+ end
23
+ end
24
+
25
+ describe "integration test" do
26
+ it "should not raise any errors" do
27
+ RestClient.stub(:post).and_return(200)
28
+ expect { subject.perform }.to_not raise_error
29
+ end
30
+ end
31
+ end
@@ -59,15 +59,18 @@ describe Vero::Config do
59
59
  end
60
60
 
61
61
  describe :domain do
62
- it "should return www.getvero.com when not set" do
63
- @config.domain.should == 'www.getvero.com'
62
+ it "should return https://www.getvero.com when not set" do
63
+ @config.domain.should == 'https://www.getvero.com'
64
64
  @config.domain = 'blah.com'
65
- @config.domain.should_not == 'www.getvero.com'
65
+ @config.domain.should_not == 'https://www.getvero.com'
66
66
  end
67
67
 
68
68
  it "should return the domain value" do
69
69
  @config.domain = 'test.unbelieveable.com.au'
70
- @config.domain.should == 'test.unbelieveable.com.au'
70
+ @config.domain.should == 'http://test.unbelieveable.com.au'
71
+
72
+ @config.domain = 'http://test.unbelieveable.com.au'
73
+ @config.domain.should == 'http://test.unbelieveable.com.au'
71
74
  end
72
75
  end
73
76
 
@@ -2,6 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Vero::Trackable do
4
4
  before :each do
5
+ @request_params = {
6
+ :event_name => 'test_event',
7
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
8
+ :identity => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
9
+ :data => { :test => 1 },
10
+ :development_mode => true
11
+ }
12
+ @url = "https://www.getvero.com/api/v1/track.json"
5
13
  @user = User.new
6
14
  end
7
15
 
@@ -12,8 +20,7 @@ describe Vero::Trackable do
12
20
 
13
21
  describe :track do
14
22
  it "should raise an error" do
15
- @user.stub(:post_later).and_return('success')
16
- expect { @user.track("test_event", {}) }.to raise_error
23
+ expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error(RuntimeError, "You must configure the 'vero' gem. Visit https://github.com/semblancesystems/vero for more details.")
17
24
  end
18
25
  end
19
26
 
@@ -34,7 +41,7 @@ describe Vero::Trackable do
34
41
  end
35
42
  end
36
43
 
37
- describe :track do
44
+ describe :track! do
38
45
  before do
39
46
  @request_params = {
40
47
  :event_name => 'test_event',
@@ -43,54 +50,51 @@ describe Vero::Trackable do
43
50
  :data => { :test => 1 },
44
51
  :development_mode => true
45
52
  }
46
- @url = "http://www.getvero.com/api/v1/track.json"
53
+ @url = "https://www.getvero.com/api/v1/track.json"
47
54
  end
48
55
 
49
56
  it "should not send a track request when the required parameters are invalid" do
50
- @user.stub(:post_now).and_return(200)
51
-
52
- expect { @user.track(nil) }.to raise_error
53
- expect { @user.track('') }.to raise_error
54
- expect { @user.track('test', '') }.to raise_error
57
+ expect { @user.track!(nil) }.to raise_error(ArgumentError, "{:event_name=>nil, :data=>{}}")
58
+ expect { @user.track!('') }.to raise_error(ArgumentError, "{:event_name=>\"\", :data=>{}}")
59
+ expect { @user.track!('test', '') }.to raise_error(ArgumentError, "{:event_name=>\"test\", :data=>\"\"}")
55
60
  end
56
61
 
57
- it "should send a `track` request when async is set to false" do
62
+ it "should send a `track!` request when async is set to false" do
58
63
  context = Vero::Context.new(Vero::App.default_context)
59
64
  context.subject = @user
60
- context.stub(:post_now).and_return(200)
61
- context.should_receive(:post_now).with(@url, @request_params, "track").at_least(:once)
65
+ context.config.logging = true
62
66
 
63
67
  @user.stub(:with_vero_context).and_return(context)
64
68
 
65
- @user.track(@request_params[:event_name], @request_params[:data]).should == 200
66
- @user.track(@request_params[:event_name]).should == 200
69
+ RestClient.stub(:post).and_return(200)
70
+
71
+ RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/events/track.json", {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :data=>{:test=>1}, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20, :_user_type=>"User"}})
72
+ @user.track!(@request_params[:event_name], @request_params[:data]).should == 200
73
+
74
+ RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/events/track.json", {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :data=>{}, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20, :_user_type=>"User"}})
75
+ @user.track!(@request_params[:event_name]).should == 200
67
76
  end
68
77
 
69
- it "should create a delayed job when async is set to true" do
78
+ it "should send using another thread when async is set to true" do
70
79
  context = Vero::Context.new(Vero::App.default_context)
80
+ context.config.logging = true
71
81
  context.subject = @user
72
82
  context.config.async = true
73
83
 
74
- context.stub(:post_later).and_return('success')
75
- context.should_receive(:post_later).with(@url, @request_params, "track").at_least(:once)
76
-
77
84
  @user.stub(:with_vero_context).and_return(context)
78
85
 
79
- @user.track(@request_params[:event_name], @request_params[:data]).should == 'success'
80
- @user.track(@request_params[:event_name]).should == 'success'
86
+ @user.track!(@request_params[:event_name], @request_params[:data]).should be_true
87
+ @user.track!(@request_params[:event_name]).should be_true
81
88
  end
82
89
 
83
- it "should not raise an error when async is set to false and the request times out" do
84
- Rails.stub(:logger).and_return(Logger.new('info'))
85
-
86
- context = Vero::Context.new(Vero::App.default_context)
87
- context.config.async = false
88
- context.config.domain = "localhost"
89
-
90
- expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to_not raise_error
90
+ # it "should raise an error when async is set to false and the request times out" do
91
+ # Rails.stub(:logger).and_return(Logger.new('info'))
92
+ # context = Vero::App.default_context
93
+ # context.config.async = false
94
+ # context.config.domain = "200.200.200.200"
91
95
 
92
- context.config.domain = "www.getvero.com"
93
- end
96
+ # expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error
97
+ # end
94
98
  end
95
99
 
96
100
  describe :identify! do
@@ -101,31 +105,143 @@ describe Vero::Trackable do
101
105
  :development_mode => true,
102
106
  :email => 'durkster@gmail.com'
103
107
  }
104
- @url = "http://www.getvero.com/api/v1/user.json"
108
+ @url = "https://www.getvero.com/api/v2/users/track.json"
105
109
  end
106
110
 
107
111
  it "should send an `identify` request when async is set to false" do
108
112
  context = Vero::Context.new(Vero::App.default_context)
109
113
  context.subject = @user
110
- context.stub(:post_now).and_return(200)
111
- context.should_receive(:post_now).with(@url, @request_params, "identify!").at_least(:once)
112
114
 
113
115
  @user.stub(:with_vero_context).and_return(context)
114
116
 
117
+ RestClient.stub(:post).and_return(200)
118
+ RestClient.should_receive(:post).with(@url, @request_params)
119
+
115
120
  @user.identify!.should == 200
116
121
  end
117
122
 
118
- it "should create a delayed job when async is set to true" do
123
+ it "should send using another thread when async is set to true" do
119
124
  context = Vero::Context.new(Vero::App.default_context)
120
125
  context.subject = @user
121
126
  context.config.async = true
122
127
 
123
- context.stub(:post_later).and_return('success')
124
- context.should_receive(:post_later).with(@url, @request_params, "identify!").at_least(:once)
128
+ @user.stub(:with_vero_context).and_return(context)
129
+
130
+ @user.identify!.should be_true
131
+ end
132
+ end
133
+
134
+ describe :update_user! do
135
+ before do
136
+ @request_params = {
137
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
138
+ :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
139
+ :email => 'durkster@gmail.com',
140
+ :development_mode => true
141
+ }
142
+ @url = "https://www.getvero.com/api/v2/users/edit.json"
143
+ end
144
+
145
+ it "should be able to choose an email address" do
146
+ context = Vero::Context.new(Vero::App.default_context)
147
+ context.subject = @user
148
+
149
+ @user.stub(:with_vero_context).and_return(context)
150
+
151
+ RestClient.stub(:put).and_return(200)
152
+ RestClient.should_receive(:put).with(@url, @request_params.merge(:email => "durkster1@gmail.com"))
153
+
154
+ @user.with_vero_context.update_user!("durkster1@gmail.com").should == 200
155
+ end
156
+
157
+ it "should send an `update_user` request when async is set to false" do
158
+ context = Vero::Context.new(Vero::App.default_context)
159
+ context.subject = @user
125
160
 
126
161
  @user.stub(:with_vero_context).and_return(context)
127
162
 
128
- @user.identify!.should == 'success'
163
+ RestClient.stub(:put).and_return(200)
164
+ RestClient.should_receive(:put).with(@url, @request_params)
165
+
166
+ @user.with_vero_context.update_user!.should == 200
167
+ end
168
+
169
+ it "should send using another thread when async is set to true" do
170
+ context = Vero::Context.new(Vero::App.default_context)
171
+ context.subject = @user
172
+ context.config.async = true
173
+
174
+ @user.stub(:with_vero_context).and_return(context)
175
+
176
+ @user.with_vero_context.update_user!.should be_true
177
+ end
178
+ end
179
+
180
+ describe :update_user_tags! do
181
+ before do
182
+ @request_params = {
183
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
184
+ :add => [],
185
+ :remove => [],
186
+ :email => 'durkster@gmail.com',
187
+ :development_mode => true
188
+ }
189
+ @url = "https://www.getvero.com/api/v2/users/tags/edit.json"
190
+ end
191
+
192
+ it "should send an `update_user_tags` request when async is set to false" do
193
+ context = Vero::Context.new(Vero::App.default_context)
194
+ context.subject = @user
195
+
196
+ @user.stub(:with_vero_context).and_return(context)
197
+
198
+ RestClient.stub(:put).and_return(200)
199
+ RestClient.should_receive(:put).with(@url, @request_params)
200
+
201
+ @user.with_vero_context.update_user_tags!.should == 200
202
+ end
203
+
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
208
+
209
+ @user.stub(:with_vero_context).and_return(context)
210
+
211
+ @user.with_vero_context.update_user_tags!.should be_true
212
+ end
213
+ end
214
+
215
+ describe :unsubscribe! do
216
+ before do
217
+ @request_params = {
218
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
219
+ :email => 'durkster@gmail.com',
220
+ :development_mode => true
221
+ }
222
+ @url = "https://www.getvero.com/api/v2/users/unsubscribe.json"
223
+ end
224
+
225
+ it "should send an `update_user` request when async is set to false" do
226
+ context = Vero::Context.new(Vero::App.default_context)
227
+ context.subject = @user
228
+
229
+ @user.stub(:with_vero_context).and_return(context)
230
+
231
+ RestClient.stub(:post).and_return(200)
232
+ RestClient.should_receive(:post).with(@url, @request_params)
233
+
234
+ @user.with_vero_context.unsubscribe!.should == 200
235
+ end
236
+
237
+ it "should send using another thread when async is set to true" do
238
+ context = Vero::Context.new(Vero::App.default_context)
239
+ context.subject = @user
240
+ context.config.async = true
241
+
242
+ @user.stub(:with_vero_context).and_return(context)
243
+
244
+ @user.with_vero_context.unsubscribe!.should be_true
129
245
  end
130
246
  end
131
247
 
@@ -162,6 +278,9 @@ describe Vero::Trackable do
162
278
 
163
279
  user = UserWithoutInterface.new
164
280
  user.to_vero.should == {:email => 'durkster@gmail.com', :age => 20, :_user_type => "UserWithoutInterface"}
281
+
282
+ user = UserWithNilAttributes.new
283
+ user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithNilAttributes"}
165
284
  end
166
285
  end
167
286
 
@@ -183,15 +302,15 @@ describe Vero::Trackable do
183
302
  :data => { :test => 1 },
184
303
  :development_mode => true
185
304
  }
186
- url = "http://www.getvero.com/api/v1/track.json"
305
+ url = "https://www.getvero.com/api/v1/track.json"
187
306
 
188
307
  context = Vero::Context.new(Vero::App.default_context)
189
308
  context.subject = user
190
309
  context.stub(:post_now).and_return(200)
191
- context.should_receive(:post_now).with(url, request_params, "track").at_least(:once)
192
310
 
193
311
  user.stub(:with_vero_context).and_return(context)
194
312
 
313
+ RestClient.stub(:post).and_return(200)
195
314
  user.vero_track(request_params[:event_name], request_params[:data]).should == 200
196
315
  end
197
316
  end
@@ -53,7 +53,17 @@ class UserWithoutInterface
53
53
  20
54
54
  end
55
55
 
56
- def vero_track(event_name, event_data)
57
- with_default_vero_context.track(event_name, event_data)
58
- end
56
+ def vero_track(event_name, event_data)
57
+ with_default_vero_context.track!(event_name, event_data)
58
+ end
59
+ end
60
+
61
+ class UserWithNilAttributes
62
+ include Vero::Trackable::Base
63
+ trackable :email_address, :age
64
+
65
+ def email_address
66
+ 'durkster@gmail.com'
67
+ end
68
+ def age; nil; end
59
69
  end
data/vero.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  [:runtime, 'rest-client'],
20
20
  [:runtime, 'delayed_job'],
21
21
  [:runtime, 'delayed_job_active_record'],
22
- [:runtime, 'delayed_job_mongoid']
22
+ [:runtime, 'delayed_job_mongoid'],
23
+ [:runtime, 'girl_friday']
23
24
  ]
24
25
 
25
26
  s.files = Dir['**/*']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: girl_friday
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
126
142
  description:
127
143
  email: support@getvero.com
128
144
  executables: []
@@ -133,11 +149,21 @@ files:
133
149
  - Gemfile.lock
134
150
  - info
135
151
  - lib/generators/vero_generator.rb
152
+ - lib/vero/api/base_api.rb
153
+ - lib/vero/api/events/track_api.rb
154
+ - lib/vero/api/users/edit_api.rb
155
+ - lib/vero/api/users/edit_tags_api.rb
156
+ - lib/vero/api/users/track_api.rb
157
+ - lib/vero/api/users/unsubscribe_api.rb
136
158
  - lib/vero/app.rb
137
159
  - lib/vero/config.rb
138
160
  - lib/vero/context.rb
139
161
  - lib/vero/jobs/rest_post_job.rb
140
162
  - lib/vero/railtie.rb
163
+ - lib/vero/sender.rb
164
+ - lib/vero/senders/base.rb
165
+ - lib/vero/senders/delayed_job.rb
166
+ - lib/vero/senders/thread.rb
141
167
  - lib/vero/trackable/base.rb
142
168
  - lib/vero/trackable/interface.rb
143
169
  - lib/vero/trackable.rb
@@ -146,6 +172,11 @@ files:
146
172
  - lib/vero/view_helpers/javascript.rb
147
173
  - lib/vero.rb
148
174
  - README.markdown
175
+ - spec/lib/api/events/track_api_spec.rb
176
+ - spec/lib/api/users/edit_api_spec.rb
177
+ - spec/lib/api/users/edit_tags_api_spec.rb
178
+ - spec/lib/api/users/track_api_spec.rb
179
+ - spec/lib/api/users/unsubscribe_api_spec.rb
149
180
  - spec/lib/app_spec.rb
150
181
  - spec/lib/config_spec.rb
151
182
  - spec/lib/context_spec.rb
@@ -175,11 +206,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
206
  version: '0'
176
207
  requirements: []
177
208
  rubyforge_project:
178
- rubygems_version: 1.8.23
209
+ rubygems_version: 1.8.24
179
210
  signing_key:
180
211
  specification_version: 3
181
212
  summary: Rails 3.x gem for Vero
182
213
  test_files:
214
+ - spec/lib/api/events/track_api_spec.rb
215
+ - spec/lib/api/users/edit_api_spec.rb
216
+ - spec/lib/api/users/edit_tags_api_spec.rb
217
+ - spec/lib/api/users/track_api_spec.rb
218
+ - spec/lib/api/users/unsubscribe_api_spec.rb
183
219
  - spec/lib/app_spec.rb
184
220
  - spec/lib/config_spec.rb
185
221
  - spec/lib/context_spec.rb