neuron-client 0.2.6 → 0.3.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.
- data/README.md +11 -8
- data/lib/neuron-client/api.rb +5 -0
- data/lib/neuron-client/model/ad.rb +142 -0
- data/lib/neuron-client/model/ad_calculations.rb +325 -0
- data/lib/neuron-client/model/ad_zone.rb +45 -0
- data/lib/neuron-client/model/base.rb +233 -18
- data/lib/neuron-client/model/blocked_referer.rb +20 -0
- data/lib/neuron-client/model/blocked_user_agent.rb +21 -0
- data/lib/neuron-client/model/geo_target.rb +36 -0
- data/lib/neuron-client/model/pixel.rb +22 -0
- data/lib/neuron-client/model/report.rb +35 -0
- data/lib/neuron-client/model/s3_file.rb +30 -0
- data/lib/neuron-client/model/zone.rb +64 -0
- data/lib/neuron-client/model/zone_calculations.rb +37 -0
- data/lib/neuron-client/schema/ad.rb +406 -0
- data/lib/neuron-client/schema/ad_zone.rb +49 -0
- data/lib/neuron-client/schema/blocked_referer.rb +52 -0
- data/lib/neuron-client/schema/blocked_user_agent.rb +64 -0
- data/lib/neuron-client/schema/common.rb +220 -0
- data/lib/neuron-client/schema/event.rb +17 -0
- data/lib/neuron-client/schema/geo_target.rb +33 -0
- data/lib/neuron-client/schema/pixel.rb +39 -0
- data/lib/neuron-client/schema/report.rb +59 -0
- data/lib/neuron-client/schema/s3_file.rb +87 -0
- data/lib/neuron-client/schema/zone.rb +214 -0
- data/lib/neuron-client/version.rb +1 -1
- data/lib/neuron-client.rb +24 -59
- data/neuron-client.gemspec +3 -0
- data/spec/lib/admin_connection_spec.rb +234 -0
- data/spec/lib/api_spec.rb +41 -63
- data/spec/lib/model/ad_calculations_spec.rb +1146 -0
- data/spec/lib/model/ad_spec.rb +253 -0
- data/spec/lib/model/ad_zone_spec.rb +15 -0
- data/spec/lib/model/base_spec.rb +5 -83
- data/spec/lib/model/blocked_referer_spec.rb +36 -0
- data/spec/lib/model/blocked_user_agent_spec.rb +36 -0
- data/spec/lib/model/geo_target_spec.rb +28 -0
- data/spec/lib/model/pixel_spec.rb +36 -0
- data/spec/lib/model/report_spec.rb +17 -0
- data/spec/lib/{s3_file_spec.rb → model/s3_file_spec.rb} +6 -5
- data/spec/lib/model/zone_calculations_spec.rb +49 -0
- data/spec/lib/model/zone_spec.rb +155 -0
- data/spec/lib/schema/ad_spec.rb +515 -0
- data/spec/lib/schema/ad_zone_spec.rb +149 -0
- data/spec/lib/schema/blocked_referer_spec.rb +136 -0
- data/spec/lib/schema/blocked_user_agent_spec.rb +147 -0
- data/spec/lib/schema/geo_target_spec.rb +92 -0
- data/spec/lib/schema/pixel_spec.rb +125 -0
- data/spec/lib/schema/report_spec.rb +129 -0
- data/spec/lib/schema/s3_file_spec.rb +164 -0
- data/spec/lib/schema/zone_spec.rb +243 -0
- data/spec/spec_helper.rb +2 -1
- metadata +141 -121
- data/lib/neuron-client/model/admin/ad.rb +0 -22
- data/lib/neuron-client/model/admin/ad_zone.rb +0 -15
- data/lib/neuron-client/model/admin/base.rb +0 -91
- data/lib/neuron-client/model/admin/blocked_referer.rb +0 -12
- data/lib/neuron-client/model/admin/blocked_user_agent.rb +0 -12
- data/lib/neuron-client/model/admin/geo_target.rb +0 -16
- data/lib/neuron-client/model/admin/pixel.rb +0 -12
- data/lib/neuron-client/model/admin/report.rb +0 -15
- data/lib/neuron-client/model/admin/s3_file.rb +0 -12
- data/lib/neuron-client/model/admin/zone.rb +0 -15
- data/lib/neuron-client/model/common/ad.rb +0 -42
- data/lib/neuron-client/model/common/ad_calculations.rb +0 -329
- data/lib/neuron-client/model/common/ad_zone.rb +0 -17
- data/lib/neuron-client/model/common/base.rb +0 -67
- data/lib/neuron-client/model/common/blocked_referer.rb +0 -16
- data/lib/neuron-client/model/common/blocked_user_agent.rb +0 -16
- data/lib/neuron-client/model/common/geo_target.rb +0 -16
- data/lib/neuron-client/model/common/pixel.rb +0 -18
- data/lib/neuron-client/model/common/report.rb +0 -21
- data/lib/neuron-client/model/common/s3_file.rb +0 -16
- data/lib/neuron-client/model/common/zone.rb +0 -22
- data/lib/neuron-client/model/common/zone_calculations.rb +0 -41
- data/lib/neuron-client/model/membase/ad.rb +0 -49
- data/lib/neuron-client/model/membase/ad_zone.rb +0 -11
- data/lib/neuron-client/model/membase/blocked_referer.rb +0 -20
- data/lib/neuron-client/model/membase/blocked_user_agent.rb +0 -20
- data/lib/neuron-client/model/membase/geo_target.rb +0 -11
- data/lib/neuron-client/model/membase/pixel.rb +0 -22
- data/lib/neuron-client/model/membase/report.rb +0 -11
- data/lib/neuron-client/model/membase/s3_file.rb +0 -11
- data/lib/neuron-client/model/membase/zone.rb +0 -30
- data/lib/neuron-client/model/models.rb +0 -15
- data/spec/lib/model/admin/ad_spec.rb +0 -34
- data/spec/lib/model/admin/ad_zone_spec.rb +0 -19
- data/spec/lib/model/admin/base_spec.rb +0 -11
- data/spec/lib/model/admin/blocked_referer_spec.rb +0 -11
- data/spec/lib/model/admin/blocked_user_agent_spec.rb +0 -11
- data/spec/lib/model/admin/geo_target_spec.rb +0 -30
- data/spec/lib/model/admin/report_spec.rb +0 -21
- data/spec/lib/model/admin/s3_spec.rb +0 -11
- data/spec/lib/model/admin/zone_spec.rb +0 -21
- data/spec/lib/model/common/ad_calculations_spec.rb +0 -1151
- data/spec/lib/model/common/ad_spec.rb +0 -11
- data/spec/lib/model/common/ad_zone_spec.rb +0 -11
- data/spec/lib/model/common/base_spec.rb +0 -11
- data/spec/lib/model/common/blocked_referer_spec.rb +0 -11
- data/spec/lib/model/common/blocked_user_agent_spec.rb +0 -11
- data/spec/lib/model/common/geo_target_spec.rb +0 -11
- data/spec/lib/model/common/report_spec.rb +0 -11
- data/spec/lib/model/common/s3_spec.rb +0 -11
- data/spec/lib/model/common/zone_calculations_spec.rb +0 -54
- data/spec/lib/model/common/zone_spec.rb +0 -11
- data/spec/lib/model/membase/ad_spec.rb +0 -54
- data/spec/lib/model/membase/ad_zone_spec.rb +0 -11
- data/spec/lib/model/membase/base_spec.rb +0 -11
- data/spec/lib/model/membase/blocked_referer_spec.rb +0 -34
- data/spec/lib/model/membase/blocked_user_agent_spec.rb +0 -34
- data/spec/lib/model/membase/geo_target_spec.rb +0 -11
- data/spec/lib/model/membase/pixel_spec.rb +0 -34
- data/spec/lib/model/membase/report_spec.rb +0 -11
- data/spec/lib/model/membase/s3_spec.rb +0 -11
- data/spec/lib/model/membase/zone_spec.rb +0 -32
- data/spec/lib/old_spec.rb +0 -437
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe Ad do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@datetime = "2011-11-11T11:11:11Z"
|
|
6
|
+
@minimal_attributes = {
|
|
7
|
+
'acudeo_program_id' => nil,
|
|
8
|
+
'approved' => 'Yes',
|
|
9
|
+
'clickthru_url' => nil,
|
|
10
|
+
'companion_ad_html' => nil,
|
|
11
|
+
'daily_cap' => nil,
|
|
12
|
+
'day_partitions' => nil,
|
|
13
|
+
'end_datetime' => nil,
|
|
14
|
+
'frequency_cap' => nil,
|
|
15
|
+
'geo_target_netacuity_ids' => {},
|
|
16
|
+
'ideal_impressions_per_hour' => nil,
|
|
17
|
+
'name' => nil,
|
|
18
|
+
'overall_cap' => nil,
|
|
19
|
+
'pixel_ids' => [],
|
|
20
|
+
'redirect_url' => nil,
|
|
21
|
+
'response_type' => nil,
|
|
22
|
+
'social_urls' => nil,
|
|
23
|
+
'start_datetime' => @datetime,
|
|
24
|
+
'time_zone' => "UTC",
|
|
25
|
+
'vast_tracker_urls' => nil,
|
|
26
|
+
'vast_url' => nil,
|
|
27
|
+
'video_flv_url' => nil,
|
|
28
|
+
'zone_links' => {},
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
context "when connected to the admin server" do
|
|
32
|
+
before(:each) do
|
|
33
|
+
@connection = stub(:connection)
|
|
34
|
+
API.stub(:default_api).and_return(stub(:default_api, :connection => @connection, :connection_type => :admin, :validate? => true))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "all" do
|
|
38
|
+
before(:each) do
|
|
39
|
+
@response = [{'ad' => {
|
|
40
|
+
'id' => 1,
|
|
41
|
+
'name' => nil
|
|
42
|
+
}}]
|
|
43
|
+
end
|
|
44
|
+
it "returns a list of Ads" do
|
|
45
|
+
@connection.stub(:get).with("ads").and_return(@response)
|
|
46
|
+
ads = Ad.all
|
|
47
|
+
ads.should be_a(Array)
|
|
48
|
+
ads.length.should be > 0
|
|
49
|
+
ads.first.should be_a(Ad)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "makes a get call" do
|
|
53
|
+
@connection.should_receive(:get).with("ads").once.and_return(@response)
|
|
54
|
+
Ad.all
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "find" do
|
|
59
|
+
before(:each) do
|
|
60
|
+
@response = {'ad' => @minimal_attributes.merge(
|
|
61
|
+
'id' => 1,
|
|
62
|
+
'name' => "Ad 1",
|
|
63
|
+
'response_type' => 'Redirect',
|
|
64
|
+
'redirect_url' => 'http://example.com/',
|
|
65
|
+
'created_at' => @datetime,
|
|
66
|
+
'updated_at' => @datetime,
|
|
67
|
+
'today_impressed' => 0,
|
|
68
|
+
'total_impressed' => 0
|
|
69
|
+
)}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "returns a Ad" do
|
|
73
|
+
@connection.stub(:get).with("ads/1").and_return(@response)
|
|
74
|
+
ad = Ad.find(1)
|
|
75
|
+
ad.should be_a(Ad)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "makes a get call" do
|
|
79
|
+
@connection.should_receive(:get).with("ads/1").once.and_return(@response)
|
|
80
|
+
Ad.find(1)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "create" do
|
|
85
|
+
before(:each) do
|
|
86
|
+
@attrs = @minimal_attributes.merge(
|
|
87
|
+
'name' => "Ad 1",
|
|
88
|
+
'response_type' => 'VideoAd',
|
|
89
|
+
'video_flv_url' => 'http://example.com/ad.flv',
|
|
90
|
+
'clickthru_url' => 'http://example.com/buycrap',
|
|
91
|
+
'companion_ad_html' => '<a href="http://example.com/">nana!</a>',
|
|
92
|
+
'social_urls' => {},
|
|
93
|
+
'vast_tracker_urls' => {}
|
|
94
|
+
)
|
|
95
|
+
@response = {'ad' => @attrs.merge({
|
|
96
|
+
'id' => 1,
|
|
97
|
+
'created_at' => @datetime,
|
|
98
|
+
'updated_at' => @datetime,
|
|
99
|
+
'total_impressed' => 0,
|
|
100
|
+
'today_impressed' => 0
|
|
101
|
+
})}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "posts json" do
|
|
105
|
+
@connection.should_receive(:post).with("ads", {'ad' => @attrs}).once.and_return(@response)
|
|
106
|
+
Ad.create(@attrs)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "returns the created Ad" do
|
|
110
|
+
@connection.should_receive(:post).and_return(@response)
|
|
111
|
+
ad = Ad.create(@attrs)
|
|
112
|
+
ad.id.should == 1
|
|
113
|
+
ad.name.should == "Ad 1"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "returns the created Ad with vast_tracker_urls" do
|
|
117
|
+
trackers = {"impression" => ["http://www.google.com"]}
|
|
118
|
+
@attrs.merge!('vast_tracker_urls' => trackers)
|
|
119
|
+
response = {'ad' => @attrs.merge({
|
|
120
|
+
'id' => 1,
|
|
121
|
+
'created_at' => @datetime,
|
|
122
|
+
'updated_at' => @datetime,
|
|
123
|
+
'total_impressed' => 0,
|
|
124
|
+
'today_impressed' => 0
|
|
125
|
+
})}
|
|
126
|
+
@connection.should_receive(:post).and_return(response)
|
|
127
|
+
ad = Ad.create(@attrs)
|
|
128
|
+
ad.id.should == 1
|
|
129
|
+
ad.vast_tracker_urls.should == trackers
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe "update_attributes" do
|
|
134
|
+
it "makes a put call" do
|
|
135
|
+
attrs = @minimal_attributes.merge(
|
|
136
|
+
'id' => 1,
|
|
137
|
+
'name' => "Ad 1",
|
|
138
|
+
'response_type' => 'Redirect',
|
|
139
|
+
'redirect_url' => 'http://example.com'
|
|
140
|
+
)
|
|
141
|
+
ad = Ad.new(attrs)
|
|
142
|
+
updated_attrs = attrs.merge('name' => 'Ad 2')
|
|
143
|
+
@connection.should_receive(:put).with("ads/1", {'ad' => updated_attrs}).and_return({'ad' => updated_attrs.merge(
|
|
144
|
+
'created_at' => @datetime,
|
|
145
|
+
'updated_at' => @datetime,
|
|
146
|
+
'total_impressed' => 0,
|
|
147
|
+
'today_impressed' => 0
|
|
148
|
+
)})
|
|
149
|
+
ad.update_attributes('name' => "Ad 2")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "makes a put call with vast_tracker_urls" do
|
|
153
|
+
trackers = {'impression' => ["http://testurl.com"]}
|
|
154
|
+
updated_trackers = {'impression' => ['http://testurl.com/new']}
|
|
155
|
+
attrs = @minimal_attributes.merge(
|
|
156
|
+
'id' => 1,
|
|
157
|
+
'response_type' => 'VideoAd',
|
|
158
|
+
'video_flv_url' => 'http://example.com/ad.flv',
|
|
159
|
+
'clickthru_url' => 'http://example.com/buycrap',
|
|
160
|
+
'companion_ad_html' => '<a href="http://example.com/">nana!</a>',
|
|
161
|
+
'social_urls' => {},
|
|
162
|
+
'vast_tracker_urls' => trackers
|
|
163
|
+
)
|
|
164
|
+
updated_attrs = attrs.merge('vast_tracker_urls' => updated_trackers)
|
|
165
|
+
ad = Ad.new(attrs)
|
|
166
|
+
@connection.should_receive(:put).with("ads/1", {'ad' => updated_attrs}).and_return({'ad' => updated_attrs.merge(
|
|
167
|
+
'created_at' => @datetime,
|
|
168
|
+
'updated_at' => @datetime,
|
|
169
|
+
'total_impressed' => 0,
|
|
170
|
+
'today_impressed' => 0
|
|
171
|
+
)})
|
|
172
|
+
ad.update_attributes(updated_attrs)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
describe "recent(statistic, by=nil)" do
|
|
177
|
+
it "should call the expected method and return the expected result" do
|
|
178
|
+
ad = Ad.new(@minimal_attributes.merge('id' => 7))
|
|
179
|
+
@connection.should_receive(:get).with('ads/7/recent/impressions', {'by' => 'zone'}).and_return('return_value')
|
|
180
|
+
|
|
181
|
+
ad.recent('impressions', 'zone').should == 'return_value'
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe "unlink(zone_id)" do
|
|
186
|
+
it "should call the expected method and return the expected result" do
|
|
187
|
+
ad = Ad.new(@minimal_attributes.merge('id' => 7))
|
|
188
|
+
@connection.should_receive(:delete).with('ads/7/zones/z33').and_return('return_value')
|
|
189
|
+
|
|
190
|
+
ad.unlink('z33').should == 'return_value'
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
context "when connected to the membase server" do
|
|
196
|
+
before(:each) do
|
|
197
|
+
@connection = stub(:connection)
|
|
198
|
+
API.stub(:default_api).and_return(stub(:default_api, :connection => @connection, :connection_type => :membase, :validate? => true))
|
|
199
|
+
end
|
|
200
|
+
describe "total_impressed" do
|
|
201
|
+
it "should call the expected methods and return the expected value" do
|
|
202
|
+
ad = Ad.new(@minimal_attributes.merge('id' => 7))
|
|
203
|
+
@connection.stub(:get).with('count_delivery_ad_7',1).and_return('999.999')
|
|
204
|
+
|
|
205
|
+
ad.total_impressed.should == 999.999
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
describe "today_impressed" do
|
|
210
|
+
it "should call the expected methods and return the expected value" do
|
|
211
|
+
ad = Ad.new(@minimal_attributes.merge('id' => 7, 'time_zone' => 'time_zone_value'))
|
|
212
|
+
Time.stub_chain(:now, :in_time_zone).with('time_zone_value').and_return(Time.parse("2011-05-06 07:08"))
|
|
213
|
+
@connection.stub(:get).with('count_delivery_20110506_ad_7',1).and_return('99.99')
|
|
214
|
+
|
|
215
|
+
ad.today_impressed.should == 99.99
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
describe "Ad.find(id)" do
|
|
220
|
+
context "when the connection returns a value" do
|
|
221
|
+
it "should call the expected methods and return the expected value" do
|
|
222
|
+
connection = MembaseConnection.new("example.com:11211")
|
|
223
|
+
Ad.stub(:connection).and_return(connection)
|
|
224
|
+
attrs = @minimal_attributes.merge(
|
|
225
|
+
'id' => 7,
|
|
226
|
+
'response_type' => 'Redirect',
|
|
227
|
+
'redirect_url' => 'http://example.com/',
|
|
228
|
+
'created_at' => @datetime,
|
|
229
|
+
'updated_at' => @datetime,
|
|
230
|
+
'total_impressed' => 0,
|
|
231
|
+
'today_impressed' => 0
|
|
232
|
+
)
|
|
233
|
+
connection.stub(:get).with('Ad:7').and_return({'ad' => attrs}.to_json)
|
|
234
|
+
a = stub(:ad)
|
|
235
|
+
Ad.should_receive(:new).with(attrs).and_return(a)
|
|
236
|
+
|
|
237
|
+
Ad.find(7).should == a
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
context "when the connection returns nil" do
|
|
241
|
+
it "should call the expected methods and return nil" do
|
|
242
|
+
connection = MembaseConnection.new("example.com:11211")
|
|
243
|
+
Ad.stub(:connection).and_return(connection)
|
|
244
|
+
connection.stub(:get).with('Ad:7').and_return(nil)
|
|
245
|
+
|
|
246
|
+
Ad.find(7).should be_nil
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe AdZone do
|
|
4
|
+
describe "self.unlink(ad_id, zone_id)" do
|
|
5
|
+
it "should call the expected method and return the expected value" do
|
|
6
|
+
c = stub(:connection)
|
|
7
|
+
AdZone.stub(:connection).and_return(c)
|
|
8
|
+
c.should_receive(:delete).with('zones/z1/ads/2').and_return('return_value')
|
|
9
|
+
|
|
10
|
+
AdZone.unlink(2, "z1").should == 'return_value'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/lib/model/base_spec.rb
CHANGED
|
@@ -1,89 +1,11 @@
|
|
|
1
1
|
module Neuron
|
|
2
2
|
module Client
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
class BaseMockModel < Base
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe Base do
|
|
13
|
-
describe "instance methods" do
|
|
14
|
-
describe "initialize(attrs=nil)" do
|
|
15
|
-
it "should set @proxied_model appropriately" do
|
|
16
|
-
pending "Not sure what the deal is here, it works outside of unit testing"
|
|
17
|
-
|
|
18
|
-
ctp = stub(:class_to_proxy)
|
|
19
|
-
Base.any_instance.should_receive(:class_to_proxy).and_return(ctp)
|
|
20
|
-
p = stub(:proxy)
|
|
21
|
-
ctp.should_receive(:new).with('attributes').and_return(p)
|
|
22
|
-
b = Base.new('attributes')
|
|
23
|
-
|
|
24
|
-
b.instance_variable_get(:@proxied_model).should == p
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe "method_missing(meth, *args, &block)" do
|
|
29
|
-
context "when method exists on the proxied model" do
|
|
30
|
-
it "should call the method on the proxied model"
|
|
31
|
-
end
|
|
32
|
-
context "when method does not exist on the proxied model" do
|
|
33
|
-
it "should call super.method_missing"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "class methods" do
|
|
39
|
-
describe "api" do
|
|
40
|
-
context "when @api exists" do
|
|
41
|
-
it "should return the expected value" do
|
|
42
|
-
a = stub(:api)
|
|
43
|
-
Base.instance_variable_set(:@api, a)
|
|
44
|
-
|
|
45
|
-
Base.api.should == a
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
context "when @api does not exist" do
|
|
49
|
-
it "should return the expected value" do
|
|
50
|
-
Base.instance_variable_set(:@api, nil)
|
|
51
|
-
a = stub(:default_api)
|
|
52
|
-
Neuron::Client::API.should_receive(:default_api).and_return(a)
|
|
53
|
-
|
|
54
|
-
Base.api.should == a
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
describe "connection" do
|
|
60
|
-
it "should call the expected methods and return the expected result" do
|
|
61
|
-
a = stub(:api)
|
|
62
|
-
Base.should_receive(:api).and_return(a)
|
|
63
|
-
c = stub(:connection)
|
|
64
|
-
a.should_receive(:connection).and_return(c)
|
|
65
|
-
|
|
66
|
-
Base.connection.should == c
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe "class_to_proxy" do
|
|
71
|
-
it "should call the expected methods and return the expected result" do
|
|
72
|
-
BaseMockModel.stub_chain(:api, :connection_type).and_return(:mock)
|
|
73
|
-
BaseMockModel.class_to_proxy.should == Neuron::Client::Model::Mock::BaseMockModel
|
|
74
|
-
end
|
|
75
|
-
end
|
|
3
|
+
class BaseMockModel
|
|
4
|
+
include Base
|
|
5
|
+
end
|
|
76
6
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
it "should call the method on the proxied model"
|
|
80
|
-
end
|
|
81
|
-
context "when method does not exist on the class to proxy" do
|
|
82
|
-
it "should call super.method_missing"
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
7
|
+
describe Base do
|
|
8
|
+
it "should have specs"
|
|
87
9
|
end
|
|
88
10
|
end
|
|
89
11
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe BlockedReferer do
|
|
4
|
+
context "when connected to the membase server" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@connection = stub(:connection)
|
|
7
|
+
API.stub(:default_api).and_return(stub(:default_api, :connection => @connection, :connection_type => :membase, :validate? => true))
|
|
8
|
+
end
|
|
9
|
+
describe "BlockedReferer.all" do
|
|
10
|
+
context "when connection returns a value" do
|
|
11
|
+
it "should call the expected methods and return the expected value" do
|
|
12
|
+
conn = MembaseConnection.new("example.com:11211")
|
|
13
|
+
BlockedReferer.stub(:connection).and_return(conn)
|
|
14
|
+
conn.stub(:get).with('blocked_referers').and_return('[{"blocked_referer":{"id": 42, "referer": "127.0.0.1"}}, {"blocked_referer":{"id": 82, "referer": "an.example.com"}}]')
|
|
15
|
+
br = stub(:blocked_referer)
|
|
16
|
+
br2 = stub(:blocked_referer2)
|
|
17
|
+
BlockedReferer.should_receive(:new).with("id"=>42, "referer"=>"127.0.0.1").and_return(br)
|
|
18
|
+
BlockedReferer.should_receive(:new).with("id"=>82, "referer"=>"an.example.com").and_return(br2)
|
|
19
|
+
|
|
20
|
+
BlockedReferer.all.should == [br, br2]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
context "when connection returns nil" do
|
|
24
|
+
it "should call the expected methods and return the expected value" do
|
|
25
|
+
conn = MembaseConnection.new("example.com:11211")
|
|
26
|
+
BlockedReferer.stub(:connection).and_return(conn)
|
|
27
|
+
conn.stub(:get).with('blocked_referers').and_return(nil)
|
|
28
|
+
|
|
29
|
+
BlockedReferer.all.should == []
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe BlockedUserAgent do
|
|
4
|
+
context "when connected to the membase server" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@connection = stub(:connection)
|
|
7
|
+
API.stub(:default_api).and_return(stub(:default_api, :connection => @connection, :connection_type => :membase, :validate? => true))
|
|
8
|
+
end
|
|
9
|
+
describe "BlockedUserAgent.all" do
|
|
10
|
+
context "when connection returns a value" do
|
|
11
|
+
it "should call the expected methods and return the expected value" do
|
|
12
|
+
conn = MembaseConnection.new("example.com:11211")
|
|
13
|
+
BlockedUserAgent.stub(:connection).and_return(conn)
|
|
14
|
+
conn.stub(:get).with('blocked_user_agents').and_return('[{"blocked_user_agent":{"id":42,"description":null,"user_agent":".*robot.*"}},{"blocked_user_agent":{"id":82,"description":null,"user_agent":"^Badbot"}}]')
|
|
15
|
+
bua = stub(:blocked_user_agent)
|
|
16
|
+
bua2 = stub(:blocked_user_agent2)
|
|
17
|
+
BlockedUserAgent.should_receive(:new).with("id"=>42, "description"=>nil, "user_agent"=>".*robot.*").and_return(bua)
|
|
18
|
+
BlockedUserAgent.should_receive(:new).with("id"=>82, "description"=>nil, "user_agent"=>"^Badbot").and_return(bua2)
|
|
19
|
+
|
|
20
|
+
BlockedUserAgent.all.should == [bua, bua2]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
context "when connection returns nil" do
|
|
24
|
+
it "should call the expected methods and return the expected value" do
|
|
25
|
+
conn = MembaseConnection.new("example.com:11211")
|
|
26
|
+
BlockedUserAgent.stub(:connection).and_return(conn)
|
|
27
|
+
conn.stub(:get).with('blocked_user_agents').and_return(nil)
|
|
28
|
+
|
|
29
|
+
BlockedUserAgent.all.should == []
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe GeoTarget do
|
|
4
|
+
context "when connected to the admin server" do
|
|
5
|
+
describe "self.query(parameters)" do
|
|
6
|
+
it "should call the expected methods and return the expected value" do
|
|
7
|
+
c = stub(:connection)
|
|
8
|
+
GeoTarget.should_receive(:connection).and_return(c)
|
|
9
|
+
parameters = {:geo_type => 'COUNTRY', :search => 'USA', :limit => '10'}
|
|
10
|
+
gta = {'id' => 1, 'abbreviation' => 'XYZ', 'full_name' => 'XYZ', 'name' => 'XYZ', 'geo_type' => 'METRO', 'netacuity_id' => 1}
|
|
11
|
+
gta2 = gta.merge({'id' => 2})
|
|
12
|
+
r = [
|
|
13
|
+
{'geo_target' => gta},
|
|
14
|
+
{'geo_target' => gta2}
|
|
15
|
+
]
|
|
16
|
+
c.should_receive(:get).with('geo_targets', parameters).and_return(r)
|
|
17
|
+
g = stub(:geo_target)
|
|
18
|
+
g2 = stub(:geo_target2)
|
|
19
|
+
GeoTarget.should_receive(:new).with(gta).and_return(g)
|
|
20
|
+
GeoTarget.should_receive(:new).with(gta2).and_return(g2)
|
|
21
|
+
|
|
22
|
+
GeoTarget.query(parameters).should == [g, g2]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe Pixel do
|
|
4
|
+
context "when connected to the membase server" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@connection = stub(:connection)
|
|
7
|
+
API.stub(:default_api).and_return(stub(:default_api, :connection => @connection, :connection_type => :membase, :validate? => true))
|
|
8
|
+
end
|
|
9
|
+
describe "Pixel.find(id)" do
|
|
10
|
+
context "when the connection returns a value" do
|
|
11
|
+
it "should call the expected methods and return the expected value" do
|
|
12
|
+
p = stub(:pixel)
|
|
13
|
+
attrs = {
|
|
14
|
+
"id" => 7,
|
|
15
|
+
"ad_ids" => []
|
|
16
|
+
}
|
|
17
|
+
@connection.stub_chain(:local_cache, :fetch).with('Pixel:7').and_yield.and_return(p)
|
|
18
|
+
@connection.should_receive(:get).with('Pixel:7').and_return({'pixel' => attrs}.to_json)
|
|
19
|
+
Pixel.should_receive(:new).with(attrs).and_return(p)
|
|
20
|
+
|
|
21
|
+
Pixel.find(7).should == p
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
context "when the connection returns nil" do
|
|
25
|
+
it "should call the expected methods and return nil" do
|
|
26
|
+
@connection.stub_chain(:local_cache, :fetch).with('Pixel:7').and_yield.and_return(nil)
|
|
27
|
+
@connection.should_receive(:get).with('Pixel:7').and_return(nil)
|
|
28
|
+
|
|
29
|
+
Pixel.find(7).should be_nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
describe Report do
|
|
4
|
+
describe "result" do
|
|
5
|
+
it "should call the expected methods and return the expected result" do
|
|
6
|
+
r = Report.allocate
|
|
7
|
+
c = stub(:connection)
|
|
8
|
+
r.stub(:connection).and_return(c)
|
|
9
|
+
r.should_receive(:id).and_return(7)
|
|
10
|
+
c.should_receive(:get).with('reports/7/result', :format => '').and_return('result_value')
|
|
11
|
+
|
|
12
|
+
r.result.should == 'result_value'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
require 'yajl'
|
|
3
3
|
|
|
4
4
|
module Neuron
|
|
5
5
|
module Client
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
describe S3File do
|
|
7
|
+
context "when connected to the admin server" do
|
|
8
8
|
before(:all) do
|
|
9
9
|
API.default_api.configure do |config|
|
|
10
10
|
config.connection_type = :admin
|
|
@@ -23,6 +23,7 @@ module Neuron
|
|
|
23
23
|
it "returns the created S3File" do
|
|
24
24
|
attrs = {:bucket => 'test',
|
|
25
25
|
:filename => "filename",
|
|
26
|
+
:filesize => nil,
|
|
26
27
|
:purpose => 'RAW_EVENT_LOG'}
|
|
27
28
|
s3file = S3File.create(attrs)
|
|
28
29
|
s3file.id.should_not be_nil
|
|
@@ -38,14 +39,14 @@ module Neuron
|
|
|
38
39
|
s3files = S3File.all
|
|
39
40
|
s3files.should be_a(Array)
|
|
40
41
|
s3files.length.should be > 0
|
|
41
|
-
s3files.first.should be_a(
|
|
42
|
+
s3files.first.should be_a(S3File)
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
describe "find" do
|
|
46
47
|
it "returns a S3File" do
|
|
47
48
|
s3file = S3File.find(@@created_id)
|
|
48
|
-
s3file.should be_a(
|
|
49
|
+
s3file.should be_a(S3File)
|
|
49
50
|
end
|
|
50
51
|
end
|
|
51
52
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Neuron
|
|
2
|
+
module Client
|
|
3
|
+
class FakeZone
|
|
4
|
+
include ZoneCalculations
|
|
5
|
+
def initialize(ads, ad_links)
|
|
6
|
+
@ads = ads
|
|
7
|
+
@ad_links = ad_links
|
|
8
|
+
end
|
|
9
|
+
attr_reader :ad_links
|
|
10
|
+
def find_ad(ad_id)
|
|
11
|
+
@ads[ad_id]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class ZoneCalculationsSpecAd
|
|
16
|
+
def initialize(active, pressure)
|
|
17
|
+
@active = active
|
|
18
|
+
@pressure = pressure
|
|
19
|
+
end
|
|
20
|
+
attr_reader :pressure, :active
|
|
21
|
+
alias_method :active?, :active
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe ZoneCalculations do
|
|
25
|
+
describe ".calculate_ads_by_priority" do
|
|
26
|
+
it "should generate the expected result" do
|
|
27
|
+
ads = {
|
|
28
|
+
"0" => ZoneCalculationsSpecAd.new(false, 42.0),
|
|
29
|
+
"1" => ZoneCalculationsSpecAd.new(true, 11.1),
|
|
30
|
+
"2" => ZoneCalculationsSpecAd.new(true, 11.1),
|
|
31
|
+
"3" => ZoneCalculationsSpecAd.new(true, 22.2),
|
|
32
|
+
"4" => ZoneCalculationsSpecAd.new(true, 1000),
|
|
33
|
+
"5" => ZoneCalculationsSpecAd.new(true, 828282)
|
|
34
|
+
}
|
|
35
|
+
ad_links = {
|
|
36
|
+
"0" => {"priority" => 1, "weight" => 50},
|
|
37
|
+
"1" => {"priority" => 1, "weight" => 4},
|
|
38
|
+
"2" => {"priority" => 1, "weight" => 2},
|
|
39
|
+
"3" => {"priority" => 1, "weight" => 2},
|
|
40
|
+
"4" => {"priority" => 2, "weight" => 99.9}
|
|
41
|
+
}
|
|
42
|
+
zone = FakeZone.new(ads, ad_links)
|
|
43
|
+
|
|
44
|
+
zone.calculate_ads_by_priority.should == [[["1", 44.4], ["2", 22.2], ["3", 44.4]], [["4", 99900.0]]]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|