helix 0.0.0.pre
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/LICENSE +24 -0
- data/README.md +169 -0
- data/lib/helix/album.rb +27 -0
- data/lib/helix/base.rb +185 -0
- data/lib/helix/config.rb +150 -0
- data/lib/helix/image.rb +19 -0
- data/lib/helix/statistics.rb +145 -0
- data/lib/helix/track.rb +17 -0
- data/lib/helix/video.rb +19 -0
- data/lib/helix.rb +9 -0
- data/spec/album_spec.rb +27 -0
- data/spec/base_spec.rb +325 -0
- data/spec/config_spec.rb +419 -0
- data/spec/image_spec.rb +21 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/statistics_spec.rb +158 -0
- data/spec/track_spec.rb +21 -0
- data/spec/video_spec.rb +21 -0
- metadata +104 -0
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,419 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
describe Helix::Config do
|
5
|
+
|
6
|
+
def set_stubs(obj, even_sig=false)
|
7
|
+
obj.instance_variable_set(:@attributes, {})
|
8
|
+
obj.stub(:media_type_sym) { :video }
|
9
|
+
obj.stub(:plural_media_type) { 'videos' }
|
10
|
+
obj.stub(:guid) { 'some_guid' }
|
11
|
+
obj.stub(:signature) { 'some_sig' } if even_sig
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:klass) { Helix::Config }
|
15
|
+
let(:obj) { klass.instance }
|
16
|
+
|
17
|
+
subject { klass }
|
18
|
+
|
19
|
+
its(:ancestors) { should include(Singleton) }
|
20
|
+
|
21
|
+
describe "Constants" do
|
22
|
+
describe "DEFAULT_FILENAME" do
|
23
|
+
subject { klass::DEFAULT_FILENAME }
|
24
|
+
it { should eq('./helix.yml') }
|
25
|
+
end
|
26
|
+
describe "SCOPES" do
|
27
|
+
subject { klass::SCOPES }
|
28
|
+
it { should eq(%w(reseller company library)) }
|
29
|
+
end
|
30
|
+
describe "VALID_SIG_TYPES" do
|
31
|
+
subject { klass::VALID_SIG_TYPES }
|
32
|
+
it { should eq([:ingest, :update, :view]) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".load" do
|
37
|
+
let(:meth) { :load }
|
38
|
+
let(:mock_obj) { mock(klass) }
|
39
|
+
let(:mock_file) { mock(File) }
|
40
|
+
let(:mock_cred) { :credentials }
|
41
|
+
before(:each) do
|
42
|
+
klass.stub(:instance) { mock_obj }
|
43
|
+
File.stub(:open) { mock_file }
|
44
|
+
YAML.stub(:load) { mock_cred }
|
45
|
+
mock_obj.stub(:instance_variable_set).with(:@credentials, anything)
|
46
|
+
end
|
47
|
+
context "when given no arg" do
|
48
|
+
before(:each) do mock_obj.stub(:instance_variable_set).with(:@filename, klass::DEFAULT_FILENAME) end
|
49
|
+
it "should get the instance" do
|
50
|
+
klass.should_receive(:instance) { mock_obj }
|
51
|
+
klass.send(meth)
|
52
|
+
end
|
53
|
+
it "should set @filename to DEFAULT_FILENAME" do
|
54
|
+
mock_obj.should_receive(:instance_variable_set).with(:@filename, klass::DEFAULT_FILENAME)
|
55
|
+
klass.send(meth)
|
56
|
+
end
|
57
|
+
it "should File.open(@filename) -> f" do
|
58
|
+
File.should_receive(:open).with(klass::DEFAULT_FILENAME) { mock_file }
|
59
|
+
klass.send(meth)
|
60
|
+
end
|
61
|
+
it "should YAML.load(f) -> cred" do
|
62
|
+
YAML.should_receive(:load).with(mock_file) { mock_cred }
|
63
|
+
klass.send(meth)
|
64
|
+
end
|
65
|
+
it "should set @credentials to cred" do
|
66
|
+
File.stub(:open).with(klass::DEFAULT_FILENAME) { mock_file }
|
67
|
+
YAML.stub(:load).with(mock_file) { mock_cred }
|
68
|
+
mock_obj.should_receive(:instance_variable_set).with(:@credentials, mock_cred)
|
69
|
+
klass.send(meth)
|
70
|
+
end
|
71
|
+
it "should return the instance" do
|
72
|
+
expect(klass.send(meth)).to be(mock_obj)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context "when given the arg 'some_file.yml'" do
|
76
|
+
let(:yaml_arg) { 'some_file.yml' }
|
77
|
+
before(:each) do mock_obj.stub(:instance_variable_set).with(:@filename, yaml_arg) end
|
78
|
+
it "should get the instance" do
|
79
|
+
klass.should_receive(:instance) { mock_obj }
|
80
|
+
klass.send(meth, yaml_arg)
|
81
|
+
end
|
82
|
+
it "should set @filename to DEFAULT_FILENAME" do
|
83
|
+
mock_obj.should_receive(:instance_variable_set).with(:@filename, yaml_arg)
|
84
|
+
klass.send(meth, yaml_arg)
|
85
|
+
end
|
86
|
+
it "should File.open(@filename) -> f" do
|
87
|
+
File.should_receive(:open).with(yaml_arg) { mock_file }
|
88
|
+
klass.send(meth, yaml_arg)
|
89
|
+
end
|
90
|
+
it "should YAML.load(f) -> cred" do
|
91
|
+
YAML.should_receive(:load).with(mock_file) { mock_cred }
|
92
|
+
klass.send(meth, yaml_arg)
|
93
|
+
end
|
94
|
+
it "should set @credentials to cred" do
|
95
|
+
File.stub(:open).with(klass::DEFAULT_FILENAME) { mock_file }
|
96
|
+
YAML.stub(:load).with(mock_file) { mock_cred }
|
97
|
+
mock_obj.should_receive(:instance_variable_set).with(:@credentials, mock_cred)
|
98
|
+
klass.send(meth, yaml_arg)
|
99
|
+
end
|
100
|
+
it "should return the instance" do
|
101
|
+
expect(klass.send(meth, yaml_arg)).to be(mock_obj)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#build_url" do
|
107
|
+
site = 'http://example.com'
|
108
|
+
let(:meth) { :build_url }
|
109
|
+
subject { obj.method(meth) }
|
110
|
+
its(:arity) { should be(-1) }
|
111
|
+
before(:each) do
|
112
|
+
obj.credentials = {'site' => site}
|
113
|
+
end
|
114
|
+
shared_examples_for "reads scope from credentials for build_url" do |media_type,format,more_opts|
|
115
|
+
more_opts ||= {}
|
116
|
+
guid = more_opts[:guid]
|
117
|
+
action = more_opts[:action]
|
118
|
+
before(:each) do obj.credentials = {'site' => 'http://example.com'} end
|
119
|
+
context "and credentials has a key for 'reseller'" do
|
120
|
+
before(:each) do obj.credentials.merge!('reseller' => 're_id') end
|
121
|
+
context "and credentials has a key for 'company'" do
|
122
|
+
before(:each) do obj.credentials.merge!('company' => 'co_id') end
|
123
|
+
context "and credentials has a key for 'library'" do
|
124
|
+
before(:each) do obj.credentials.merge!('library' => 'lib_id') end
|
125
|
+
expected_url = "#{site}/resellers/re_id/companies/co_id/libraries/lib_id/#{media_type}"
|
126
|
+
expected_url += "/the_guid" if guid
|
127
|
+
expected_url += "/#{action}" if action
|
128
|
+
expected_url += ".#{format}"
|
129
|
+
it { should eq(expected_url) }
|
130
|
+
end
|
131
|
+
context "and credentials does NOT have a key for 'library'" do
|
132
|
+
before(:each) do obj.credentials.delete('library') end
|
133
|
+
expected_url = "#{site}/resellers/re_id/companies/co_id/#{media_type}"
|
134
|
+
expected_url += "/the_guid" if guid
|
135
|
+
expected_url += "/#{action}" if action
|
136
|
+
expected_url += ".#{format}"
|
137
|
+
it { should eq(expected_url) }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
context "and credentials does NOT have a key for 'company'" do
|
141
|
+
before(:each) do obj.credentials.delete('company') end
|
142
|
+
expected_url = "#{site}/resellers/re_id/#{media_type}"
|
143
|
+
expected_url += "/the_guid" if guid
|
144
|
+
expected_url += "/#{action}" if action
|
145
|
+
expected_url += ".#{format}"
|
146
|
+
it { should eq(expected_url) }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
context "and credentials does NOT have a key for 'reseller'" do
|
150
|
+
before(:each) do obj.credentials.delete('reseller') end
|
151
|
+
context "and credentials has a key for 'company'" do
|
152
|
+
before(:each) do obj.credentials['company'] = 'co_id' end
|
153
|
+
context "and credentials has a key for 'library'" do
|
154
|
+
before(:each) do obj.credentials['library'] = 'lib_id' end
|
155
|
+
expected_url = "#{site}/companies/co_id/libraries/lib_id/#{media_type}"
|
156
|
+
expected_url += "/the_guid" if guid
|
157
|
+
expected_url += "/#{action}" if action
|
158
|
+
expected_url += ".#{format}"
|
159
|
+
it { should eq(expected_url) }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
context "when given NO opts" do
|
165
|
+
subject { obj.send(meth) }
|
166
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :json
|
167
|
+
end
|
168
|
+
context "when given opts of {}" do
|
169
|
+
subject { obj.send(meth, {}) }
|
170
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :json
|
171
|
+
end
|
172
|
+
context "when given opts of {guid: :the_guid}" do
|
173
|
+
subject { obj.send(meth, {guid: :the_guid}) }
|
174
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :json, {guid: :the_guid}
|
175
|
+
end
|
176
|
+
context "when given opts of {action: :the_action}" do
|
177
|
+
subject { obj.send(meth, {action: :the_action}) }
|
178
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :json, {action: :the_action}
|
179
|
+
end
|
180
|
+
context "when given opts of {guid: :the_guid, action: :the_action}" do
|
181
|
+
subject { obj.send(meth, {guid: :the_guid, action: :the_action}) }
|
182
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :json, {guid: :the_guid, action: :the_action}
|
183
|
+
end
|
184
|
+
[ :videos, :tracks ].each do |media_type|
|
185
|
+
context "when given opts[:media_type] of :#{media_type}" do
|
186
|
+
subject { obj.send(meth, media_type: media_type) }
|
187
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :json
|
188
|
+
end
|
189
|
+
context "when given opts[:media_type] of :#{media_type} and opts[:guid] of :the_guid" do
|
190
|
+
subject { obj.send(meth, media_type: media_type, guid: :the_guid) }
|
191
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :json, {guid: :the_guid}
|
192
|
+
end
|
193
|
+
context "when given opts[:media_type] of :#{media_type} and opts[:action] of :the_action" do
|
194
|
+
subject { obj.send(meth, media_type: media_type, action: :the_action) }
|
195
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :json, {action: :the_action}
|
196
|
+
end
|
197
|
+
context "when given opts[:media_type] of :#{media_type}, opts[:guid] of :the_guid, opts[:action] of :the_action" do
|
198
|
+
subject { obj.send(meth, media_type: media_type, guid: :the_guid, action: :the_action) }
|
199
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :json, {guid: :the_guid, action: :the_action}
|
200
|
+
end
|
201
|
+
end
|
202
|
+
[ :json, :xml ].each do |format|
|
203
|
+
context "when given opts[:format] of :#{format}" do
|
204
|
+
subject { obj.send(meth, format: format) }
|
205
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, format
|
206
|
+
end
|
207
|
+
context "when given opts[:format] of :#{format} and opts[:guid] of :the_guid" do
|
208
|
+
subject { obj.send(meth, format: format, guid: :the_guid) }
|
209
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, format, {guid: :the_guid}
|
210
|
+
end
|
211
|
+
context "when given opts[:format] of :#{format} and opts[:action] of :the_action" do
|
212
|
+
subject { obj.send(meth, format: format, action: :the_action) }
|
213
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, format, {action: :the_action}
|
214
|
+
end
|
215
|
+
context "when given opts[:format] of :#{format}, opts[:guid] of :the_guid, and opts[:action] of :the_action" do
|
216
|
+
subject { obj.send(meth, format: format, guid: :the_guid, action: :the_action) }
|
217
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, format, {guid: :the_guid, action: :the_action}
|
218
|
+
end
|
219
|
+
[ :videos, :tracks ].each do |media_type|
|
220
|
+
context "when given opts[:format] of :#{format} and opts[:media_type] of :#{media_type}" do
|
221
|
+
subject { obj.send(meth, format: format, media_type: media_type) }
|
222
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, format
|
223
|
+
end
|
224
|
+
context "when given opts[:format] of :#{format}, opts[:guid] of :the_guid, and opts[:media_type] of :#{media_type}" do
|
225
|
+
subject { obj.send(meth, format: format, guid: :the_guid, media_type: media_type) }
|
226
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, format, {guid: :the_guid}
|
227
|
+
end
|
228
|
+
context "when given opts[:format] of :#{format}, opts[:action] of :the_action, and opts[:media_type] of :#{media_type}" do
|
229
|
+
subject { obj.send(meth, format: format, action: :the_action, media_type: media_type) }
|
230
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, format, {action: :the_action}
|
231
|
+
end
|
232
|
+
context "when given opts[:format] of :#{format}, opts[:guid] of :the_guid, opts[:action] of :the_action, and opts[:media_type] of :#{media_type}" do
|
233
|
+
subject { obj.send(meth, format: format, guid: :the_guid, action: :the_action, media_type: media_type) }
|
234
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, format, {guid: :the_guid, action: :the_action}
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "#existing_sig_for" do
|
241
|
+
let(:meth) { :existing_sig_for }
|
242
|
+
|
243
|
+
subject { obj.method(meth) }
|
244
|
+
its(:arity) { should eq(1) }
|
245
|
+
|
246
|
+
context "when given a sig_type" do
|
247
|
+
let(:sig_type) { :a_sig_type }
|
248
|
+
subject { obj.send(meth, sig_type) }
|
249
|
+
context "and sig_expired_for?(sig_type) is true" do
|
250
|
+
before(:each) do obj.stub(:sig_expired_for?).with(sig_type) { true } end
|
251
|
+
it { should be(nil) }
|
252
|
+
end
|
253
|
+
context "and sig_expired_for?(sig_type) is false" do
|
254
|
+
let(:license_key) { :a_license_key }
|
255
|
+
before(:each) do
|
256
|
+
obj.stub(:sig_expired_for?).with(sig_type) { false }
|
257
|
+
obj.stub(:license_key) { license_key }
|
258
|
+
end
|
259
|
+
it "should return @signature_for[license_key][sig_type]" do
|
260
|
+
mock_sig_for = {}
|
261
|
+
mock_sig_for_lk = {}
|
262
|
+
obj.instance_variable_set(:@signature_for, mock_sig_for)
|
263
|
+
mock_sig_for.should_receive(:[]).with(license_key) { mock_sig_for_lk }
|
264
|
+
mock_sig_for_lk.should_receive(:[]).with(sig_type) { :memoized_sig }
|
265
|
+
expect(obj.send(meth, sig_type)).to be(:memoized_sig)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe "#get_response" do
|
272
|
+
let(:meth) { :get_response }
|
273
|
+
subject { obj.method(meth) }
|
274
|
+
its(:arity) { should eq(-2) }
|
275
|
+
context "when given a url and options" do
|
276
|
+
let(:string) { String.new }
|
277
|
+
let(:opts) { {sig_type: :the_sig_type} }
|
278
|
+
let(:params) { { params: { signature: string } } }
|
279
|
+
let(:returned_json) { '{"key": "val"}' }
|
280
|
+
let(:json_parsed) { { "key" => "val" } }
|
281
|
+
it "should call RestClient.get and return a hash from parsed JSON" do
|
282
|
+
obj.stub(:signature).with(:the_sig_type, opts) { string }
|
283
|
+
RestClient.should_receive(:get).with(string, params) { returned_json }
|
284
|
+
expect(obj.send(meth, string, opts)).to eq(json_parsed)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "#license_key" do
|
290
|
+
let(:meth) { :license_key }
|
291
|
+
subject { obj.method(meth) }
|
292
|
+
its(:arity) { should eq(0) }
|
293
|
+
it "should return @credentials['license_key']" do
|
294
|
+
obj.instance_variable_set(:@credentials, {'license_key' => :lk})
|
295
|
+
expect(obj.send(meth)).to be(:lk)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe "#prepare_signature_memoization" do
|
300
|
+
let(:meth) { :prepare_signature_memoization }
|
301
|
+
subject { obj.method(meth) }
|
302
|
+
its(:arity) { should eq(0) }
|
303
|
+
before(:each) do obj.stub(:license_key) { :lk } end
|
304
|
+
it "should set @signature_for[license_key] to {}" do
|
305
|
+
obj.send(meth)
|
306
|
+
expect(obj.instance_variable_get(:@signature_for)).to eq(lk: {})
|
307
|
+
end
|
308
|
+
it "should set @signature_expiration_for[license_key] to {}" do
|
309
|
+
obj.send(meth)
|
310
|
+
expect(obj.instance_variable_get(:@signature_expiration_for)).to eq(lk: {})
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "#signature" do
|
315
|
+
let(:meth) { :signature }
|
316
|
+
|
317
|
+
subject { obj.method(meth) }
|
318
|
+
its(:arity) { should eq(-2) }
|
319
|
+
|
320
|
+
it "should prepare_signature_memoization" do
|
321
|
+
obj.should_receive(:prepare_signature_memoization)
|
322
|
+
obj.stub(:existing_sig_for) { :some_sig }
|
323
|
+
obj.send(meth, :any_sig_type)
|
324
|
+
end
|
325
|
+
|
326
|
+
let(:license_key) { :lk }
|
327
|
+
before(:each) do
|
328
|
+
obj.stub(:license_key) { license_key }
|
329
|
+
obj.stub(:prepare_signature_memoization)
|
330
|
+
end
|
331
|
+
|
332
|
+
let(:mock_response) { mock(Object) }
|
333
|
+
context "when given :some_invalid_sig_type" do
|
334
|
+
let(:sig_type) { :some_invalid_sig_type }
|
335
|
+
it "should raise an ArgumentError" do
|
336
|
+
obj.stub(:existing_sig_for) { nil }
|
337
|
+
msg = "I don't understand 'some_invalid_sig_type'. Please give me one of :ingest, :update, or :view."
|
338
|
+
expect(lambda { obj.send(meth, sig_type) }).to raise_error(ArgumentError, msg)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
shared_examples_for "gets fresh sig" do |sig_type,url|
|
342
|
+
let(:sig_for) { {license_key => {}} }
|
343
|
+
let(:sig_exp_for) { {license_key => {}} }
|
344
|
+
before(:each) do
|
345
|
+
obj.instance_variable_set(:@signature_for, sig_for)
|
346
|
+
obj.instance_variable_set(:@signature_expiration_for, sig_exp_for)
|
347
|
+
RestClient.stub(:get) { :fresh_sig }
|
348
|
+
end
|
349
|
+
it "should call RestClient.get(#{url})" do
|
350
|
+
set_stubs(obj)
|
351
|
+
url = "#{obj.credentials['site']}/api/#{sig_type}_key?licenseKey=#{license_key}&duration=1200"
|
352
|
+
RestClient.should_receive(:get).with(url) { :fresh_sig }
|
353
|
+
expect(obj.send(meth, sig_type)).to be(:fresh_sig)
|
354
|
+
end
|
355
|
+
it "sets a new sig expiration time" do
|
356
|
+
mock_time = mock(Time)
|
357
|
+
Time.should_receive(:now) { mock_time }
|
358
|
+
mock_time.should_receive(:+).with(klass::TIME_OFFSET) { :new_time }
|
359
|
+
obj.send(meth, sig_type)
|
360
|
+
expect(obj.instance_variable_get(:@signature_expiration_for)[license_key][sig_type]).to eq(:new_time)
|
361
|
+
end
|
362
|
+
it "memoizes the freshly-acquired sig" do
|
363
|
+
obj.send(meth, sig_type)
|
364
|
+
expect(obj.instance_variable_get(:@signature_for)[license_key][sig_type]).to eq(:fresh_sig)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
[ :ingest, :update, :view ].each do |sig_type|
|
368
|
+
context "when given :#{sig_type}" do
|
369
|
+
url = %q[#{self.credentials['site']}/api/] + sig_type.to_s +
|
370
|
+
%q[_key?licenseKey=#{self.license_key}&duration=1200]
|
371
|
+
context "and there is an existing_sig_for(sig_type)" do
|
372
|
+
before(:each) do obj.stub(:existing_sig_for).with(sig_type) { :memoized_sig } end
|
373
|
+
it "should return the existing sig" do
|
374
|
+
RestClient.should_not_receive(:get)
|
375
|
+
expect(obj.send(meth, sig_type)).to be(:memoized_sig)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
context "and there is NOT an existing_sig_for(sig_type)" do
|
379
|
+
before(:each) do obj.stub(:existing_sig_for).with(sig_type) { nil } end
|
380
|
+
it_behaves_like "gets fresh sig", sig_type, url
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
describe "#sig_expired_for?" do
|
387
|
+
let(:meth) { :sig_expired_for? }
|
388
|
+
let(:license_key) { :a_license_key }
|
389
|
+
before(:each) do obj.stub(:license_key) { :a_license_key } end
|
390
|
+
|
391
|
+
subject { obj.method(meth) }
|
392
|
+
its(:arity) { should be(1) }
|
393
|
+
|
394
|
+
context "when given a sig_type" do
|
395
|
+
let(:sig_type) { :a_sig_type }
|
396
|
+
let(:mock_expired) { mock(Time) }
|
397
|
+
let(:mock_now) { mock(Time) }
|
398
|
+
subject { obj.send(meth, sig_type) }
|
399
|
+
context "when @signature_expiration_for[license_key][sig_type] is nil" do
|
400
|
+
before(:each) do obj.instance_variable_set(:@signature_expiration_for, {license_key => {sig_type => nil}}) end
|
401
|
+
it { should be true }
|
402
|
+
end
|
403
|
+
context "when @signature_expiration_for[license_key][sig_type] is NOT nil" do
|
404
|
+
before(:each) do
|
405
|
+
obj.instance_variable_set(:@signature_expiration_for, {license_key => {sig_type => mock_expired}})
|
406
|
+
Time.stub(:now) { mock_now }
|
407
|
+
end
|
408
|
+
context "when @signature_expiration_for[license_key][sig_type] <= Time.now is false" do
|
409
|
+
before(:each) do mock_expired.should_receive(:<=).with(mock_now) { false } end
|
410
|
+
it { should be false }
|
411
|
+
end
|
412
|
+
context "when @signature_expiration_for[license_key][sig_type] <= Time.now is true" do
|
413
|
+
before(:each) do mock_expired.should_receive(:<=).with(mock_now) { true } end
|
414
|
+
it { should be true }
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
data/spec/image_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
describe Helix::Image do
|
5
|
+
let(:klass) { Helix::Image }
|
6
|
+
|
7
|
+
subject { klass }
|
8
|
+
its(:ancestors) { should include(Helix::Base) }
|
9
|
+
its(:guid_name) { should eq('image_id') }
|
10
|
+
its(:media_type_sym) { should be(:image) }
|
11
|
+
its(:plural_media_type) { should eq('images') }
|
12
|
+
|
13
|
+
describe "Constants"
|
14
|
+
|
15
|
+
describe "an instance" do
|
16
|
+
let(:obj) { klass.new({'image_id' => 'some_image_guid'}) }
|
17
|
+
subject { obj }
|
18
|
+
its(:media_type_sym) { should be(:image) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
STATS_IMAGE_TYPES = %w(album image)
|
5
|
+
STATS_MEDIA_TYPES = STATS_IMAGE_TYPES + %w(audio video)
|
6
|
+
STATS_TYPES = %w(delivery ingest storage)
|
7
|
+
MEDIA_NAME_OF = {
|
8
|
+
'album' => 'image',
|
9
|
+
'audio' => 'track'
|
10
|
+
}
|
11
|
+
INGEST_NAME_OF = {
|
12
|
+
'video' => 'publish'
|
13
|
+
}
|
14
|
+
|
15
|
+
describe Helix::Statistics do
|
16
|
+
let(:mod) { Helix::Statistics }
|
17
|
+
|
18
|
+
describe "Constants"
|
19
|
+
|
20
|
+
STATS_TYPES.each do |stats_type|
|
21
|
+
STATS_MEDIA_TYPES.each do |media_type|
|
22
|
+
|
23
|
+
next if STATS_IMAGE_TYPES.include?(media_type) and stats_type == 'ingest'
|
24
|
+
|
25
|
+
describe ".#{media_type}_#{stats_type}" do
|
26
|
+
let(:meth) { "#{media_type}_#{stats_type}" }
|
27
|
+
let(:mock_config) { mock(Helix::Config, build_url: :built_url, get_response: :response) }
|
28
|
+
before(:each) do Helix::Config.stub(:instance) { mock_config } end
|
29
|
+
|
30
|
+
subject { mod.method(meth) }
|
31
|
+
its(:arity) { should eq(-1) }
|
32
|
+
|
33
|
+
if stats_type == 'delivery'
|
34
|
+
media_name = MEDIA_NAME_OF[media_type] || media_type
|
35
|
+
context "when given opts containing a :#{media_name}_id" do
|
36
|
+
let(:opts) { {group: :daily, "#{media_name}_id".to_sym => "the_#{media_name}_id".to_sym} }
|
37
|
+
it "should refer to the Helix::Config instance" do
|
38
|
+
Helix::Config.should_receive(:instance) { mock_config }
|
39
|
+
mod.send(meth, opts)
|
40
|
+
end
|
41
|
+
it "should delete :#{media_name}_id from opts" do
|
42
|
+
opts.should_receive(:delete).with("#{media_name}_id".to_sym) { "the_#{media_name}_id".to_sym }
|
43
|
+
mod.send(meth, opts)
|
44
|
+
end
|
45
|
+
it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics)" do
|
46
|
+
mock_config.should_receive(:build_url).with({guid: "the_#{media_name}_id".to_sym, media_type: "#{media_name}s".to_sym, action: :statistics}) { :built_url }
|
47
|
+
mod.send(meth, opts)
|
48
|
+
end
|
49
|
+
it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
|
50
|
+
mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
|
51
|
+
expect(mod.send(meth, opts)).to eq(:response)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context "when given opts NOT containing a :#{media_name}_id" do
|
55
|
+
let(:opts) { {group: :daily} }
|
56
|
+
it "should refer to the Helix::Config instance" do
|
57
|
+
Helix::Config.should_receive(:instance) { mock_config }
|
58
|
+
mod.send(meth, opts)
|
59
|
+
end
|
60
|
+
it "should (fail to) delete :#{media_name}_id from opts" do
|
61
|
+
opts.should_receive(:delete).with("#{media_name}_id".to_sym) { nil }
|
62
|
+
mod.send(meth, opts)
|
63
|
+
end
|
64
|
+
it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery)" do
|
65
|
+
mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_delivery".to_sym}) { :built_url }
|
66
|
+
mod.send(meth, opts)
|
67
|
+
end
|
68
|
+
it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
|
69
|
+
mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
|
70
|
+
expect(mod.send(meth, opts)).to eq(:response)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
if stats_type == 'storage'
|
75
|
+
media_name = MEDIA_NAME_OF[media_type] || media_type
|
76
|
+
publish_name = INGEST_NAME_OF[media_type] || 'ingest'
|
77
|
+
context "when given opts" do
|
78
|
+
let(:opts) { {group: :daily} }
|
79
|
+
it "should refer to the Helix::Config instance" do
|
80
|
+
Helix::Config.should_receive(:instance) { mock_config }
|
81
|
+
mod.send(meth, opts)
|
82
|
+
end
|
83
|
+
it "should call config.build_url(media_type: :statistics, action: :#{media_name}_#{publish_name}/disk_usage)" do
|
84
|
+
mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_#{publish_name}/disk_usage".to_sym}) { :built_url }
|
85
|
+
mod.send(meth, opts)
|
86
|
+
end
|
87
|
+
it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
|
88
|
+
mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
|
89
|
+
expect(mod.send(meth, opts)).to eq(:response)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe ".track_#{stats_type}" do
|
98
|
+
let(:meth) { "track_#{stats_type}" }
|
99
|
+
|
100
|
+
subject { mod.method(meth) }
|
101
|
+
its(:arity) { should eq(-1) }
|
102
|
+
|
103
|
+
context "when given no arg" do
|
104
|
+
it "should call audio_#{stats_type}({})" do
|
105
|
+
mod.should_receive("audio_#{stats_type}").with({}) { :expected }
|
106
|
+
expect(mod.send(meth)).to be(:expected)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "when given {}" do
|
111
|
+
it "should call audio_#{stats_type}({})" do
|
112
|
+
mod.should_receive("audio_#{stats_type}").with({}) { :expected }
|
113
|
+
expect(mod.send(meth, {})).to be(:expected)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when given :some_opts" do
|
118
|
+
it "should call audio_#{stats_type}(:some_opts)" do
|
119
|
+
mod.should_receive("audio_#{stats_type}").with(:some_opts) { :expected }
|
120
|
+
expect(mod.send(meth, :some_opts)).to be(:expected)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
next if stats_type == 'ingest'
|
127
|
+
describe ".album_#{stats_type}" do
|
128
|
+
let(:meth) { "album_#{stats_type}" }
|
129
|
+
|
130
|
+
subject { mod.method(meth) }
|
131
|
+
its(:arity) { should eq(-1) }
|
132
|
+
|
133
|
+
context "when given no arg" do
|
134
|
+
it "should call image_#{stats_type}({})" do
|
135
|
+
mod.should_receive("image_#{stats_type}").with({}) { :expected }
|
136
|
+
expect(mod.send(meth)).to be(:expected)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when given {}" do
|
141
|
+
it "should call image_#{stats_type}({})" do
|
142
|
+
mod.should_receive("image_#{stats_type}").with({}) { :expected }
|
143
|
+
expect(mod.send(meth, {})).to be(:expected)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when given :some_opts" do
|
148
|
+
it "should call image_#{stats_type}(:some_opts)" do
|
149
|
+
mod.should_receive("image_#{stats_type}").with(:some_opts) { :expected }
|
150
|
+
expect(mod.send(meth, :some_opts)).to be(:expected)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
data/spec/track_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
describe Helix::Track do
|
5
|
+
let(:klass) { Helix::Track }
|
6
|
+
|
7
|
+
subject { klass }
|
8
|
+
its(:ancestors) { should include(Helix::Base) }
|
9
|
+
its(:guid_name) { should eq('track_id') }
|
10
|
+
its(:media_type_sym) { should be(:track) }
|
11
|
+
its(:plural_media_type) { should eq('tracks') }
|
12
|
+
|
13
|
+
describe "Constants"
|
14
|
+
|
15
|
+
describe "an instance" do
|
16
|
+
let(:obj) { klass.new({'track_id' => 'some_track_guid'}) }
|
17
|
+
subject { obj }
|
18
|
+
its(:media_type_sym) { should be(:track) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/video_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
describe Helix::Video do
|
5
|
+
let(:klass) { Helix::Video }
|
6
|
+
|
7
|
+
subject { klass }
|
8
|
+
its(:ancestors) { should include(Helix::Base) }
|
9
|
+
its(:guid_name) { should eq('video_id') }
|
10
|
+
its(:media_type_sym) { should be(:video) }
|
11
|
+
its(:plural_media_type) { should eq('videos') }
|
12
|
+
|
13
|
+
describe "Constants"
|
14
|
+
|
15
|
+
describe "an instance" do
|
16
|
+
let(:obj) { klass.new({'video_id' => 'some_video_guid'}) }
|
17
|
+
subject { obj }
|
18
|
+
its(:media_type_sym) { should be(:video) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|