videojuicer-vj-sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +0 -0
- data/README.rdoc +7 -0
- data/VERSION.yml +4 -0
- data/lib/core_ext/hash.rb +40 -0
- data/lib/sdk_connection_harness.rb +87 -0
- data/lib/videojuicer/asset/audio.rb +11 -0
- data/lib/videojuicer/asset/base.rb +50 -0
- data/lib/videojuicer/asset/image.rb +12 -0
- data/lib/videojuicer/asset/text.rb +8 -0
- data/lib/videojuicer/asset/video.rb +13 -0
- data/lib/videojuicer/campaign.rb +8 -0
- data/lib/videojuicer/oauth/multipart_helper.rb +96 -0
- data/lib/videojuicer/oauth/proxy_factory.rb +18 -0
- data/lib/videojuicer/oauth/request_proxy.rb +234 -0
- data/lib/videojuicer/presentation.rb +32 -0
- data/lib/videojuicer/resource/base.rb +174 -0
- data/lib/videojuicer/resource/collection.rb +34 -0
- data/lib/videojuicer/resource/errors.rb +17 -0
- data/lib/videojuicer/resource/inferrable.rb +81 -0
- data/lib/videojuicer/resource/property_registry.rb +126 -0
- data/lib/videojuicer/resource/relationships/belongs_to.rb +38 -0
- data/lib/videojuicer/session.rb +74 -0
- data/lib/videojuicer/shared/configurable.rb +103 -0
- data/lib/videojuicer/shared/exceptions.rb +20 -0
- data/lib/videojuicer/user.rb +43 -0
- data/lib/videojuicer.rb +97 -0
- data/spec/audio_spec.rb +43 -0
- data/spec/belongs_to_spec.rb +45 -0
- data/spec/campaign_spec.rb +37 -0
- data/spec/collection_spec.rb +25 -0
- data/spec/files/audio.mp3 +0 -0
- data/spec/files/empty_file +0 -0
- data/spec/files/image.jpg +0 -0
- data/spec/files/text.txt +1 -0
- data/spec/files/video.mov +0 -0
- data/spec/helpers/spec_helper.rb +50 -0
- data/spec/image_spec.rb +44 -0
- data/spec/presentation_spec.rb +38 -0
- data/spec/property_registry_spec.rb +130 -0
- data/spec/request_proxy_spec.rb +94 -0
- data/spec/session_spec.rb +96 -0
- data/spec/shared/configurable_spec.rb +75 -0
- data/spec/shared/resource_spec.rb +170 -0
- data/spec/spec.opts +3 -0
- data/spec/text_spec.rb +42 -0
- data/spec/user_spec.rb +64 -0
- data/spec/video_spec.rb +45 -0
- data/spec/videojuicer_spec.rb +122 -0
- metadata +136 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
describe Videojuicer::Session do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
configure_test_settings
|
8
|
+
@session = Videojuicer::Session.new(
|
9
|
+
:seed_name => fixtures.seed.name,
|
10
|
+
:consumer_key => fixtures["write-master"].consumer.consumer_key,
|
11
|
+
:consumer_secret => fixtures["write-master"].consumer.consumer_secret
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "instantiation" do
|
16
|
+
before(:all) do
|
17
|
+
@klass = Videojuicer::Session
|
18
|
+
end
|
19
|
+
it_should_behave_like "a configurable"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "authorisation" do
|
23
|
+
describe "(retrieving the request token)" do
|
24
|
+
before(:all) do
|
25
|
+
@token = @session.get_request_token
|
26
|
+
end
|
27
|
+
|
28
|
+
it "fetches a token key" do
|
29
|
+
@token["oauth_token"].should be_kind_of(String)
|
30
|
+
@token["oauth_token"].should_not be_empty
|
31
|
+
end
|
32
|
+
it "fetches a token secret" do
|
33
|
+
@token["oauth_token_secret"].should be_kind_of(String)
|
34
|
+
@token["oauth_token_secret"].should_not be_empty
|
35
|
+
end
|
36
|
+
it "fetches the permissions" do
|
37
|
+
@token["permissions"].should == "read-user"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "(authorizing the request token)" do
|
42
|
+
before(:all) do
|
43
|
+
@authorize_url = @session.authorize_url
|
44
|
+
@authorize_url_parsed = URI.parse(@authorize_url)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns the URL when asked for the #authorize_url" do
|
48
|
+
@authorize_url_parsed.port.should == @session.port
|
49
|
+
@authorize_url_parsed.host.should == @session.host
|
50
|
+
end
|
51
|
+
it "returns a valid URL that can be successfully requested" do
|
52
|
+
req = Net::HTTP::Get.new("#{@authorize_url_parsed.path}?#{@authorize_url_parsed.query}")
|
53
|
+
response = Net::HTTP.start(@authorize_url_parsed.host, @authorize_url_parsed.port) do |http|
|
54
|
+
http.request req
|
55
|
+
end
|
56
|
+
response.code.to_i.should == 200
|
57
|
+
end
|
58
|
+
it "validates that mangling this URL in any way also mangles the response to an error state" do
|
59
|
+
req = Net::HTTP::Get.new("#{@authorize_url_parsed.path}?#{@authorize_url_parsed.query.gsub(/oauth_token=[a-zA-Z0-9]+/,'')}")
|
60
|
+
response = Net::HTTP.start(@authorize_url_parsed.host, @authorize_url_parsed.port) do |http|
|
61
|
+
http.request req
|
62
|
+
end
|
63
|
+
response.code.to_i.should == 401
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "(retrieving the access token)" do
|
68
|
+
before(:all) do
|
69
|
+
@atok_fixture = fixtures["write-master"].access_token
|
70
|
+
@atok = @session.exchange_request_token(@atok_fixture)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "fetches a token key" do
|
74
|
+
@atok.oauth_token.should be_kind_of(String)
|
75
|
+
@atok.oauth_token.should_not be_empty
|
76
|
+
end
|
77
|
+
it "fetches a token secret" do
|
78
|
+
@atok.oauth_token_secret.should be_kind_of(String)
|
79
|
+
@atok.oauth_token_secret.should_not be_empty
|
80
|
+
end
|
81
|
+
it "fetches the token permissions" do
|
82
|
+
@atok.permissions.should == "write-master"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "concurrency" do
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "scope control" do
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
shared_examples_for "a configurable" do
|
2
|
+
|
3
|
+
before(:all) do
|
4
|
+
Videojuicer.configure!(:foo=>"custom", :bar=>"not overridden")
|
5
|
+
end
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
Videojuicer.exit_all!
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
Videojuicer.exit_all!
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "scope control" do
|
16
|
+
before(:all) do
|
17
|
+
@configurable_a = @klass.new
|
18
|
+
@configurable_a.configure! :foo=>"a"
|
19
|
+
|
20
|
+
@configurable_b = @klass.new
|
21
|
+
@configurable_b.configure! :foo=>"b"
|
22
|
+
|
23
|
+
@configurable_c = @klass.new
|
24
|
+
@configurable_c.configure!({})
|
25
|
+
end
|
26
|
+
|
27
|
+
it "moves the configurable's local scope to the global scope stack" do
|
28
|
+
Videojuicer.current_scope.should_not == @configurable_a.config
|
29
|
+
@configurable_a.scope do |config|
|
30
|
+
config.should == Videojuicer.current_scope
|
31
|
+
end
|
32
|
+
Videojuicer.current_scope.should_not == @configurable_a.config
|
33
|
+
end
|
34
|
+
|
35
|
+
it "supports nested block behaviour" do
|
36
|
+
@configurable_a.scope do |config_a|
|
37
|
+
config_a[:bar].should == "not overridden"
|
38
|
+
config_a[:foo].should == "a"
|
39
|
+
|
40
|
+
Videojuicer.scopes.length.should == 2
|
41
|
+
|
42
|
+
@configurable_b.scope do |config_b|
|
43
|
+
Videojuicer.scopes.length.should == 3
|
44
|
+
config_b[:foo].should == "b"
|
45
|
+
config_b[:bar].should == "not overridden"
|
46
|
+
end
|
47
|
+
|
48
|
+
Videojuicer.scopes.length.should == 2
|
49
|
+
#raise "ALL SCOPES: #{Videojuicer.scopes.inspect} \n\n\n CURRENT SCOPE: #{Videojuicer.current_scope.inspect} \n\n BLOCK CONFIG: #{config.inspect}"
|
50
|
+
|
51
|
+
config_a[:foo].should == "a"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "gets the configuration defaults from those already set on the Videojuicer module" do
|
57
|
+
obj = @klass.new
|
58
|
+
obj.config[:foo].should == "custom"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can override defaults from the Videojuicer configuration hash" do
|
62
|
+
obj = @klass.new
|
63
|
+
obj.configure!(:bar=>"overridden")
|
64
|
+
obj.config[:bar].should == "overridden"
|
65
|
+
end
|
66
|
+
|
67
|
+
%w(host port consumer_key consumer_secret token token_secret api_version seed_name protocol).each do |attr|
|
68
|
+
it "provides a direct access method for the #{attr} given in the configuration" do
|
69
|
+
obj = @klass.new
|
70
|
+
obj.configure!((attr.to_sym)=>"#{attr} was set")
|
71
|
+
obj.send(attr).should == "#{attr} was set"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
shared_examples_for "a RESTFUL resource model" do
|
2
|
+
|
3
|
+
# Expects @klass to be a reference to the model class being tested
|
4
|
+
# Expects @singular_name to be a string containing the expected resource name, e.g. Videojuicer::User => "user"
|
5
|
+
# Expects @plural_name to be a string containing the expected pluralised name, e.g. Videojuicer::User => "users"
|
6
|
+
# Expects @good_attributes to be a hash of attributes for objects of the tested type that will successfully create a valid object.
|
7
|
+
|
8
|
+
describe "inferrable naming" do
|
9
|
+
it "has a resource name that matches the singular class name" do
|
10
|
+
@klass.resource_name.should == @singular_name
|
11
|
+
end
|
12
|
+
it "has a parameter name inferred from the resource name" do
|
13
|
+
@klass.parameter_name.should == @singular_name
|
14
|
+
end
|
15
|
+
it "has a resource path that properly pluralises the resource name" do
|
16
|
+
@klass.resource_path.should == "/#{@plural_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "a new record" do
|
21
|
+
before(:each) do
|
22
|
+
@record = @klass.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns true to #new_record?" do
|
26
|
+
@record.new_record?.should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "uses the class resource path as the instance resource path" do
|
30
|
+
@record.resource_path.should == @klass.resource_path
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises an exception when trying to pull attributes remotely" do
|
34
|
+
lambda {@record.reload}.should raise_error(Videojuicer::Exceptions::NoResource)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns false to #valid?" do
|
38
|
+
@record.valid?.should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "being saved" do
|
42
|
+
describe "successfully" do
|
43
|
+
before(:all) do
|
44
|
+
@successful = @klass.new(@good_attributes)
|
45
|
+
raise @successful.errors.inspect unless @successful.valid?
|
46
|
+
@successful.valid?.should be_true
|
47
|
+
@saved = @successful.save
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns true" do
|
51
|
+
@saved.should == true
|
52
|
+
end
|
53
|
+
it "does not set any errors on the object" do
|
54
|
+
@successful.errors.should be_empty
|
55
|
+
end
|
56
|
+
it "gets an ID" do
|
57
|
+
@successful.id.should be_kind_of(Integer)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
describe "unsuccessfully" do
|
61
|
+
before(:all) do
|
62
|
+
@bad_attributes = @good_attributes.inject({}) do |memo, (key,value)|
|
63
|
+
memo.merge({key=>""})
|
64
|
+
end
|
65
|
+
@fail = @klass.new(@bad_attributes)
|
66
|
+
@saved = @fail.save
|
67
|
+
end
|
68
|
+
|
69
|
+
it "is not #valid?" do
|
70
|
+
@fail.valid?.should be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns false" do
|
74
|
+
@saved.should be_false
|
75
|
+
end
|
76
|
+
it "sets errors on the object" do
|
77
|
+
@fail.errors.should be_kind_of(Hash)
|
78
|
+
@fail.errors.should_not be_empty
|
79
|
+
end
|
80
|
+
it "does not get an ID" do
|
81
|
+
@fail.id.should be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "finding a record by ID" do
|
88
|
+
before(:all) do
|
89
|
+
attrs = cycle_attributes(@good_attributes)
|
90
|
+
@record = @klass.new(attrs)
|
91
|
+
@record.save.should be_true
|
92
|
+
@found = @klass.get(@record.id)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "gets all the attributes" do
|
96
|
+
attrs = @found.attributes.dup
|
97
|
+
attrs.delete(:id)
|
98
|
+
attrs = attrs.reject {|k,v| !v}
|
99
|
+
attrs.should_not be_empty
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "listing records" do
|
104
|
+
before(:all) do
|
105
|
+
@list = @klass.all
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return a collection object" do
|
109
|
+
@list.should be_kind_of(Videojuicer::Resource::Collection)
|
110
|
+
end
|
111
|
+
it "should add the pagination options to the collection object" do
|
112
|
+
@list.limit.should be_kind_of(Numeric)
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "with pagination settings" do
|
116
|
+
before(:all) do
|
117
|
+
@paginated_list = @klass.all(:limit=>5)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return a collection object" do
|
121
|
+
@paginated_list.should be_kind_of(Videojuicer::Resource::Collection)
|
122
|
+
end
|
123
|
+
it "returns the proper amount of objects" do
|
124
|
+
@paginated_list.limit.should == 5
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "finding a record by conditions" do
|
130
|
+
it "should translate a conditions hash to filterable format"
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "an existing record" do
|
134
|
+
before(:all) do
|
135
|
+
@record = @klass.new(cycle_attributes(@good_attributes))
|
136
|
+
@record.save.should be_true
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns false to #new_record?" do
|
140
|
+
@record.new_record?.should be_false
|
141
|
+
end
|
142
|
+
|
143
|
+
it "uses an instance-specific resource path" do
|
144
|
+
@record.resource_path.should == "/#{@plural_name}/#{@record.id}.json"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "reloads from the remote API successfully" do
|
148
|
+
@record.reload.should be_true
|
149
|
+
end
|
150
|
+
|
151
|
+
it "saves successfully" do
|
152
|
+
saved = @record.save
|
153
|
+
@record.errors.should == {}
|
154
|
+
saved.should be_true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "deleting a record" do
|
159
|
+
before(:each) do
|
160
|
+
@record = @klass.new(cycle_attributes(@good_attributes))
|
161
|
+
@record.save.should be_true
|
162
|
+
end
|
163
|
+
|
164
|
+
it "destroys the record" do
|
165
|
+
@record.destroy
|
166
|
+
lambda {@record.reload}.should raise_error(Videojuicer::Exceptions::NoResource)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/text_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::Asset::Text do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::Asset::Text
|
7
|
+
configure_test_settings
|
8
|
+
Videojuicer.enter_scope :seed_name => fixtures.seed.name,
|
9
|
+
:consumer_key=>fixtures["write-master"].consumer.consumer_key,
|
10
|
+
:consumer_secret=>fixtures["write-master"].consumer.consumer_secret,
|
11
|
+
:token=>fixtures["write-master"].authorized_token.oauth_token,
|
12
|
+
:token_secret=>fixtures["write-master"].authorized_token.oauth_token_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
Videojuicer.exit_scope
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "instantiation" do
|
20
|
+
it_should_behave_like "a configurable"
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "general interface:" do
|
24
|
+
before(:all) do
|
25
|
+
@singular_name = "asset"
|
26
|
+
@plural_name = "assets/text"
|
27
|
+
@good_attributes = {
|
28
|
+
:user_id => rand(100) + 1,
|
29
|
+
:licensed_at => Time.now,
|
30
|
+
:licensed_by => "foo, bar",
|
31
|
+
:licensed_under => "CC BY:NC:SA",
|
32
|
+
:published_at => Time.now,
|
33
|
+
:duration => 180000,
|
34
|
+
:file => File.open(File.join(File.dirname(__FILE__), "files", "text.txt"))
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it_should_behave_like "a RESTFUL resource model"
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::User do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::User
|
7
|
+
configure_test_settings
|
8
|
+
Videojuicer.enter_scope :seed_name => fixtures.seed.name,
|
9
|
+
:consumer_key=>fixtures["write-master"].consumer.consumer_key,
|
10
|
+
:consumer_secret=>fixtures["write-master"].consumer.consumer_secret,
|
11
|
+
:token=>fixtures["write-master"].authorized_token.oauth_token,
|
12
|
+
:token_secret=>fixtures["write-master"].authorized_token.oauth_token_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
Videojuicer.exit_scope
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "instantiation" do
|
20
|
+
it_should_behave_like "a configurable"
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "general interface:" do
|
24
|
+
before(:all) do
|
25
|
+
@singular_name = "user"
|
26
|
+
@plural_name = "users"
|
27
|
+
@good_attributes = {
|
28
|
+
:login => "testuser#{rand 99999}",
|
29
|
+
:name => "#{rand 9999} Jones",
|
30
|
+
:email => "test#{rand 999999}@test.videojuicer.com",
|
31
|
+
:password => "#{p = rand(99999)}",
|
32
|
+
:password_confirmation => p
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it_should_behave_like "a RESTFUL resource model"
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "authentication" do
|
40
|
+
before(:all) do
|
41
|
+
@good_attributes = {
|
42
|
+
:login => "testuser#{rand 99999}",
|
43
|
+
:name => "#{rand 9999} Jones",
|
44
|
+
:email => "test#{rand 999999}@test.videojuicer.com",
|
45
|
+
:password => "#{p = rand(99999)}",
|
46
|
+
:password_confirmation => p
|
47
|
+
}
|
48
|
+
@auth_user = Videojuicer::User.new(@good_attributes)
|
49
|
+
@auth_user.save.should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it "returns User with good credentials" do
|
54
|
+
u = Videojuicer::User.authenticate(@good_attributes[:login], @good_attributes[:password])
|
55
|
+
u.should be_kind_of(Videojuicer::User)
|
56
|
+
u.login.should == @good_attributes[:login]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns nil with bad credentials" do
|
60
|
+
Videojuicer::User.authenticate(@good_attributes[:login], "FOOOOBARRRRRR").should be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec/video_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::Asset::Video do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::Asset::Video
|
7
|
+
configure_test_settings
|
8
|
+
Videojuicer.enter_scope :seed_name => fixtures.seed.name,
|
9
|
+
:consumer_key=>fixtures["write-master"].consumer.consumer_key,
|
10
|
+
:consumer_secret=>fixtures["write-master"].consumer.consumer_secret,
|
11
|
+
:token=>fixtures["write-master"].authorized_token.oauth_token,
|
12
|
+
:token_secret=>fixtures["write-master"].authorized_token.oauth_token_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
Videojuicer.exit_scope
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "instantiation" do
|
20
|
+
it_should_behave_like "a configurable"
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "general interface:" do
|
24
|
+
before(:all) do
|
25
|
+
@singular_name = "asset"
|
26
|
+
@plural_name = "assets/video"
|
27
|
+
@good_attributes = {
|
28
|
+
:user_id => rand(100) + 1,
|
29
|
+
:licensed_at => Time.now,
|
30
|
+
:licensed_by => "foo, bar",
|
31
|
+
:licensed_under => "CC BY:NC:SA",
|
32
|
+
:published_at => Time.now,
|
33
|
+
:duration => 180000,
|
34
|
+
:width => 640,
|
35
|
+
:height => 480,
|
36
|
+
:bit_rate => 262144,
|
37
|
+
:file => File.open(File.join(File.dirname(__FILE__), "files", "video.mov"))
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it_should_behave_like "a RESTFUL resource model"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe "Videojuicer SDK" do
|
4
|
+
|
5
|
+
describe "initialization with an options hash" do
|
6
|
+
before(:all) do
|
7
|
+
Videojuicer.configure!(
|
8
|
+
:consumer_key => "consumer_key",
|
9
|
+
:consumer_secret => "consumer_secret",
|
10
|
+
:api_version => 100,
|
11
|
+
:host => "host",
|
12
|
+
:port => 100
|
13
|
+
)
|
14
|
+
end
|
15
|
+
after(:all) do
|
16
|
+
Videojuicer.unconfigure!
|
17
|
+
end
|
18
|
+
|
19
|
+
it "respects the :consumer_key option" do
|
20
|
+
Videojuicer.default_options[:consumer_key].should == "consumer_key"
|
21
|
+
end
|
22
|
+
it "respects the :consumer_secret option" do
|
23
|
+
Videojuicer.default_options[:consumer_secret].should == "consumer_secret"
|
24
|
+
end
|
25
|
+
it "respects the :api_version option" do
|
26
|
+
Videojuicer.default_options[:api_version].should == 100
|
27
|
+
end
|
28
|
+
it "respects the :host option" do
|
29
|
+
Videojuicer.default_options[:host].should == "host"
|
30
|
+
end
|
31
|
+
it "respects the :port option" do
|
32
|
+
Videojuicer.default_options[:port].should == 100
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "scope management" do
|
37
|
+
before(:all) do
|
38
|
+
@default = {
|
39
|
+
:consumer_key => "consumer_key",
|
40
|
+
:consumer_secret => "consumer_secret",
|
41
|
+
:api_version => 100,
|
42
|
+
:host => "host",
|
43
|
+
:port => 100
|
44
|
+
}
|
45
|
+
Videojuicer.configure!(@default)
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "with no scope" do
|
49
|
+
it "should respond false to in_scope?" do
|
50
|
+
Videojuicer.in_scope?.should be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should give the given defaults as the current scope" do
|
54
|
+
Videojuicer.current_scope.should == Videojuicer::DEFAULTS.merge(@default)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "entering a scope" do
|
59
|
+
before(:all) do
|
60
|
+
@scope1 = {:api_version=>"in scope 1", :scope_1_included=>true}
|
61
|
+
Videojuicer.enter_scope(@scope1)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should respond true to in_scope?" do
|
65
|
+
Videojuicer.in_scope?
|
66
|
+
end
|
67
|
+
it "should give the current scope config in response to current_scope" do
|
68
|
+
Videojuicer.current_scope.should == Videojuicer::DEFAULTS.merge(@default).merge(@scope1)
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "and then entering another scope" do
|
72
|
+
before(:all) do
|
73
|
+
@scope2 = {:api_version=>"in scope 2", :scope_2_included=>true}
|
74
|
+
Videojuicer.enter_scope(@scope2)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should respond true to in_scope?" do
|
78
|
+
Videojuicer.in_scope?
|
79
|
+
end
|
80
|
+
it "should inherit from the current scope" do
|
81
|
+
Videojuicer.current_scope.should == Videojuicer::DEFAULTS.merge(@default).merge(@scope1).merge(@scope2)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "and then exiting a scope" do
|
86
|
+
before(:all) do
|
87
|
+
@current_scope = Videojuicer.current_scope
|
88
|
+
@length_at_current_scope = Videojuicer.scopes.length
|
89
|
+
Videojuicer.enter_scope(:entered_scope=>1)
|
90
|
+
Videojuicer.current_scope.should_not == @current_scope
|
91
|
+
Videojuicer.exit_scope
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should reduce the scope stack length" do
|
95
|
+
Videojuicer.scopes.length.should == @length_at_current_scope
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should restore the current_scope to the previous value" do
|
99
|
+
Videojuicer.current_scope.should == @current_scope
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
describe "initialization with defaults" do
|
108
|
+
before(:all) do
|
109
|
+
Videojuicer.unconfigure!
|
110
|
+
Videojuicer.default_options.should == Videojuicer::DEFAULTS
|
111
|
+
end
|
112
|
+
|
113
|
+
it "provides a default host" do
|
114
|
+
Videojuicer.default_options[:port].should_not be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "provides a default port" do
|
118
|
+
Videojuicer.default_options[:host].should_not be_nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|