qubell_api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +7 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +6 -0
- data/Rakefile +33 -0
- data/lib/qubell/api_call.rb +46 -0
- data/lib/qubell/application.rb +71 -0
- data/lib/qubell/base.rb +44 -0
- data/lib/qubell/configuration.rb +34 -0
- data/lib/qubell/environment.rb +64 -0
- data/lib/qubell/errors.rb +62 -0
- data/lib/qubell/instance.rb +64 -0
- data/lib/qubell/organization.rb +26 -0
- data/lib/qubell/revision.rb +12 -0
- data/lib/qubell/version.rb +4 -0
- data/lib/qubell_api.rb +45 -0
- data/qubell_api.gemspec +31 -0
- data/qubell_api.iml +56 -0
- data/test/spec/factories/factories.rb +53 -0
- data/test/spec/lib/api_call_spec.rb +105 -0
- data/test/spec/lib/application_spec.rb +106 -0
- data/test/spec/lib/configuration_spec.rb +78 -0
- data/test/spec/lib/environment_spec.rb +140 -0
- data/test/spec/lib/organization_spec.rb +37 -0
- data/test/spec/lib/revision_spec.rb +23 -0
- data/test/spec/qubell_api_spec.rb +23 -0
- data/test/spec/spec_helper.rb +27 -0
- metadata +201 -0
data/qubell_api.iml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Ruby Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
13
|
+
<exclude-output />
|
14
|
+
<content url="file://$MODULE_DIR$">
|
15
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
16
|
+
</content>
|
17
|
+
<orderEntry type="jdk" jdkName="rbenv: 2.1.5" jdkType="RUBY_SDK" />
|
18
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v4.2.0, rbenv: 2.1.5) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.3.7, rbenv: 2.1.5) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.0.0, rbenv: 2.1.5) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="astrolabe (v1.3.0, rbenv: 2.1.5) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.9, rbenv: 2.1.5) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="crack (v0.4.2, rbenv: 2.1.5) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, rbenv: 2.1.5) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="docile (v1.1.5, rbenv: 2.1.5) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="factory_girl (v4.5.0, rbenv: 2.1.5) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.7.0, rbenv: 2.1.5) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.2, rbenv: 2.1.5) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types (v2.4.3, rbenv: 2.1.5) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.5.1, rbenv: 2.1.5) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.10.1, rbenv: 2.1.5) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.10.2, rbenv: 2.1.5) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v2.2.0.2, rbenv: 2.1.5) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="powerpack (v0.1.0, rbenv: 2.1.5) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v2.0.0, rbenv: 2.1.5) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, rbenv: 2.1.5) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="rest-client (v1.7.2, rbenv: 2.1.5) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.2.0, rbenv: 2.1.5) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.2.0, rbenv: 2.1.5) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.2.0, rbenv: 2.1.5) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.2.0, rbenv: 2.1.5) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.2.1, rbenv: 2.1.5) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.29.0, rbenv: 2.1.5) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.7.1, rbenv: 2.1.5) [gem]" level="application" />
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="safe_yaml (v1.0.4, rbenv: 2.1.5) [gem]" level="application" />
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.9.1, rbenv: 2.1.5) [gem]" level="application" />
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-badge (v2.0.2, rbenv: 2.1.5) [gem]" level="application" />
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.8.0, rbenv: 2.1.5) [gem]" level="application" />
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.4, rbenv: 2.1.5) [gem]" level="application" />
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.2, rbenv: 2.1.5) [gem]" level="application" />
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="webmock (v1.20.4, rbenv: 2.1.5) [gem]" level="application" />
|
53
|
+
<orderEntry type="library" scope="PROVIDED" name="yard (v0.8.7.6, rbenv: 2.1.5) [gem]" level="application" />
|
54
|
+
</component>
|
55
|
+
</module>
|
56
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'qubell_api'
|
2
|
+
require 'qubell/application'
|
3
|
+
require 'qubell/configuration'
|
4
|
+
require 'qubell/organization'
|
5
|
+
require 'qubell/revision'
|
6
|
+
require 'qubell/environment'
|
7
|
+
require 'qubell/instance'
|
8
|
+
|
9
|
+
FactoryGirl.define do
|
10
|
+
factory :client, class: Qubell::API
|
11
|
+
|
12
|
+
factory :configuration, class: Qubell::Configuration do
|
13
|
+
username 'username'
|
14
|
+
password 'password'
|
15
|
+
end
|
16
|
+
|
17
|
+
factory :organization, class: Qubell::Organization do
|
18
|
+
initialize_with { new(id: SecureRandom.hex(12), name: 'org') }
|
19
|
+
end
|
20
|
+
|
21
|
+
factory :application, class: Qubell::Application do
|
22
|
+
transient do
|
23
|
+
org_id SecureRandom.hex(12)
|
24
|
+
end
|
25
|
+
initialize_with do
|
26
|
+
new(
|
27
|
+
id: SecureRandom.hex(12),
|
28
|
+
name: 'app',
|
29
|
+
organization: org_id
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
factory :revision, class: Qubell::Revision do
|
35
|
+
initialize_with { new(id: SecureRandom.hex(12), name: 'rev') }
|
36
|
+
end
|
37
|
+
|
38
|
+
factory :instance, class: Qubell::Instance do
|
39
|
+
initialize_with do
|
40
|
+
new(
|
41
|
+
id: SecureRandom.hex(12),
|
42
|
+
name: 'instance',
|
43
|
+
environment: SecureRandom.hex(12),
|
44
|
+
revision: SecureRandom.hex(12))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
factory :environment, class: Qubell::Environment do
|
49
|
+
initialize_with do
|
50
|
+
new(id: SecureRandom.hex(12), name: 'env', isDefault: true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
shared_examples 'a qubell api call' do |method|
|
5
|
+
let(:url) { "#{config.endpoint}/test" }
|
6
|
+
let(:response) { { key1: { key2: %w(value1 value2) } } }
|
7
|
+
let(:config) { FactoryGirl.build :configuration }
|
8
|
+
let(:class_method) { Qubell::APICall.method(method) }
|
9
|
+
let(:data) { (method == :put || method == :post) ? 'test_data' : {} }
|
10
|
+
|
11
|
+
context 'with json responce body' do
|
12
|
+
before do
|
13
|
+
stub_request(method, url).to_return(
|
14
|
+
status: 200,
|
15
|
+
body: response.to_json,
|
16
|
+
headers: { :'Content-type' => 'application/json' })
|
17
|
+
end
|
18
|
+
it 'return collection' do
|
19
|
+
expect(class_method.call('/test', data)).to eq(response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with yaml responce body' do
|
24
|
+
before do
|
25
|
+
stub_request(method, url).to_return(
|
26
|
+
status: 200,
|
27
|
+
body: response.to_yaml,
|
28
|
+
headers: { :'Content-type' => 'application/x-yaml' })
|
29
|
+
end
|
30
|
+
it 'return collection' do
|
31
|
+
expect(class_method.call('/test', data)).to eq(response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with 400 responce code' do
|
36
|
+
before do
|
37
|
+
stub_request(method, url).to_return(status: 400)
|
38
|
+
end
|
39
|
+
it 'raise Qubell::DestroyError ' do
|
40
|
+
expect { class_method.call('/test', data) }
|
41
|
+
.to raise_error Qubell::ExecutionError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with 401 responce code' do
|
46
|
+
before do
|
47
|
+
stub_request(method, url).to_return(status: 401)
|
48
|
+
end
|
49
|
+
it 'raise Qubell::AuthenticationError ' do
|
50
|
+
expect { class_method.call('/test', data) }
|
51
|
+
.to raise_error Qubell::AuthenticationError
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with 403 responce code' do
|
56
|
+
before do
|
57
|
+
stub_request(method, url).to_return(status: 403)
|
58
|
+
end
|
59
|
+
it 'raise Qubell::PermissionsDeniedError ' do
|
60
|
+
expect { class_method.call('/test', data) }
|
61
|
+
.to raise_error Qubell::PermissionsDeniedError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with 404 responce code' do
|
66
|
+
before do
|
67
|
+
stub_request(method, url).to_return(status: 404)
|
68
|
+
end
|
69
|
+
it 'raise Qubell::ResourceUnavaliable ' do
|
70
|
+
expect{ class_method.call('/test', data) }
|
71
|
+
.to raise_error Qubell::ResourceUnavaliable
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'with 409 responce code' do
|
76
|
+
before do
|
77
|
+
stub_request(method, url).to_return(status: 409)
|
78
|
+
end
|
79
|
+
it 'raise Qubell::WorkflowError ' do
|
80
|
+
expect{ class_method.call('/test', data) }
|
81
|
+
.to raise_error Qubell::WorkflowError
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
module Qubell
|
87
|
+
describe Base do
|
88
|
+
describe '#get' do
|
89
|
+
it_behaves_like 'a qubell api call', :get
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#post' do
|
93
|
+
it_behaves_like 'a qubell api call', :post
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#put' do
|
97
|
+
it_behaves_like 'a qubell api call', :put
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#delete' do
|
101
|
+
it_behaves_like 'a qubell api call', :delete
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module Qubell
|
4
|
+
describe Application do
|
5
|
+
let(:config) { FactoryGirl.build :configuration }
|
6
|
+
let(:org) { FactoryGirl.build :organization }
|
7
|
+
let(:env) { FactoryGirl.build :environment }
|
8
|
+
let(:app) { FactoryGirl.build :application, org_id: org.id }
|
9
|
+
let(:revs) { FactoryGirl.build_list(:revision, 1) }
|
10
|
+
let(:instance) { FactoryGirl.build :instance }
|
11
|
+
let(:instance_info) do
|
12
|
+
{ applicationId: app.id }
|
13
|
+
end
|
14
|
+
let(:app_url) { "#{config.endpoint}/applications/#{app.id}" }
|
15
|
+
let(:manifest) do
|
16
|
+
{
|
17
|
+
application: {
|
18
|
+
components: {}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
let(:version) { '1' }
|
23
|
+
|
24
|
+
describe '#revisions' do
|
25
|
+
before do
|
26
|
+
stub_request(:get, "#{app_url}/revisions")
|
27
|
+
.to_return(
|
28
|
+
status: 200,
|
29
|
+
body: revs.to_json,
|
30
|
+
headers: { :'Content-type' => 'application/json' })
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'return array of revisions' do
|
34
|
+
expect(app.revisions).to match_array(revs)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#update' do
|
39
|
+
before do
|
40
|
+
stub_request(:put, "#{app_url}/manifest")
|
41
|
+
.with(
|
42
|
+
body: manifest.to_yaml,
|
43
|
+
headers: { :'Content-type' => 'application/x-yaml' })
|
44
|
+
.to_return(
|
45
|
+
status: 200,
|
46
|
+
body: { version: version }.to_json,
|
47
|
+
headers: { :'Content-type' => 'application/json' })
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'return new version number' do
|
51
|
+
expect(app.update(manifest.to_yaml)).to eq(version)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#instances' do
|
56
|
+
before do
|
57
|
+
stub_request(:get, "#{config.endpoint}/organizations")
|
58
|
+
.to_return(
|
59
|
+
status: 200,
|
60
|
+
body: [org].to_json,
|
61
|
+
headers: { :'Content-type' => 'application/json' })
|
62
|
+
|
63
|
+
stub_request(:get, "#{config.endpoint}/organizations/#{org.id}/environments")
|
64
|
+
.to_return(
|
65
|
+
status: 200,
|
66
|
+
body: [env].to_json,
|
67
|
+
headers: { :'Content-type' => 'application/json' })
|
68
|
+
|
69
|
+
stub_request(:get, "#{config.endpoint}/environments/#{env.id}/instances")
|
70
|
+
.to_return(
|
71
|
+
status: 200,
|
72
|
+
body: [instance].to_json,
|
73
|
+
headers: { :'Content-type' => 'application/json' })
|
74
|
+
|
75
|
+
stub_request(:get, "#{config.endpoint}/instances/#{instance.id}")
|
76
|
+
.to_return(
|
77
|
+
status: 200,
|
78
|
+
body: instance_info.to_json,
|
79
|
+
headers: { :'Content-type' => 'application/json' })
|
80
|
+
end
|
81
|
+
it 'return array of instances' do
|
82
|
+
expect(app.instances).to match_array([instance])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#launch' do
|
87
|
+
let(:new_instance) { FactoryGirl.build :instance }
|
88
|
+
let(:parameters) { {} }
|
89
|
+
before do
|
90
|
+
allow(app).to receive(:instances) { [new_instance] }
|
91
|
+
|
92
|
+
stub_request(:put, "#{app_url}/launch")
|
93
|
+
.with(
|
94
|
+
body: parameters.to_json,
|
95
|
+
headers: { :'Content-type' => 'application/json' })
|
96
|
+
.to_return(
|
97
|
+
status: 200,
|
98
|
+
body: { id: new_instance.id }.to_json,
|
99
|
+
headers: { :'Content-type' => 'application/json' })
|
100
|
+
end
|
101
|
+
it 'return new instance id' do
|
102
|
+
expect(app.launch(parameters)).to eq(new_instance)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
module Qubell
|
5
|
+
describe Configuration do
|
6
|
+
describe '#domain' do
|
7
|
+
it 'default value is https://express.tonomi.com' do
|
8
|
+
expect(Qubell::Configuration.new.domain).to eq('https://express.tonomi.com')
|
9
|
+
end
|
10
|
+
it 'can set value' do
|
11
|
+
config = Qubell::Configuration.new
|
12
|
+
config.domain = 'test'
|
13
|
+
expect(config.domain).to eq('test')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#api_version' do
|
18
|
+
it 'default value is 1' do
|
19
|
+
expect(Qubell::Configuration.new.api_version).to eq('1')
|
20
|
+
end
|
21
|
+
it 'can set value' do
|
22
|
+
config = Qubell::Configuration.new
|
23
|
+
config.api_version = '2'
|
24
|
+
expect(config.api_version).to eq('2')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#username' do
|
29
|
+
it 'default value is nil' do
|
30
|
+
expect(Qubell::Configuration.new.username).to eq(nil)
|
31
|
+
end
|
32
|
+
it 'can set value' do
|
33
|
+
config = Qubell::Configuration.new
|
34
|
+
config.username = 'username'
|
35
|
+
expect(config.username).to eq('username')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#password' do
|
40
|
+
it 'default value is nil' do
|
41
|
+
expect(Qubell::Configuration.new.password).to eq(nil)
|
42
|
+
end
|
43
|
+
it 'can set value' do
|
44
|
+
config = Qubell::Configuration.new
|
45
|
+
config.password = 'password'
|
46
|
+
expect(config.password).to eq('password')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#endpoint' do
|
51
|
+
it 'default return value is https://express.tonomi.com/api/1' do
|
52
|
+
expect(Qubell::Configuration.new.endpoint).to eq('https://express.tonomi.com/api/1')
|
53
|
+
end
|
54
|
+
it 'dependens on @domain' do
|
55
|
+
config = Qubell::Configuration.new
|
56
|
+
config.domain = 'test'
|
57
|
+
expect(config.endpoint).to eq('test/api/1')
|
58
|
+
end
|
59
|
+
it 'dependens on @api_version' do
|
60
|
+
config = Qubell::Configuration.new
|
61
|
+
config.api_version = '2'
|
62
|
+
expect(config.endpoint).to eq('https://express.tonomi.com/api/2')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#to_s' do
|
67
|
+
it 'return json string' do
|
68
|
+
config = Qubell::Configuration.new
|
69
|
+
config.username = 'username'
|
70
|
+
config.password = 'password'
|
71
|
+
expect(config.to_s).to eq('{"domain": "https://express.tonomi.com",' \
|
72
|
+
'"api_version": "1",' \
|
73
|
+
'"username": "username",' \
|
74
|
+
'"password": "password"}')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Qubell
|
5
|
+
describe Environment do
|
6
|
+
let(:config) { FactoryGirl.build :configuration }
|
7
|
+
let(:env) { FactoryGirl.build :environment }
|
8
|
+
let(:env_url) { "#{config.endpoint}/environments/#{env.id}" }
|
9
|
+
let(:instances) { FactoryGirl.build_list(:instance, 1) }
|
10
|
+
# noinspection RubyStringKeysInHashInspection
|
11
|
+
let(:policies) do
|
12
|
+
{ policies: { testkey: 'test-value' } }
|
13
|
+
end
|
14
|
+
# noinspection RubyStringKeysInHashInspection
|
15
|
+
let(:properties) do
|
16
|
+
{ properties: [{ name: 'test',
|
17
|
+
value: 'testvalue',
|
18
|
+
type: 'string'
|
19
|
+
}]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
# noinspection RubyStringKeysInHashInspection
|
23
|
+
let(:markers) do
|
24
|
+
{ markers: [{ name: 'test-marker-1' },
|
25
|
+
{ name: 'test-marker-2' }] }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#policies' do
|
29
|
+
before do
|
30
|
+
stub_request(:get, env_url)
|
31
|
+
.to_return(
|
32
|
+
status: 200,
|
33
|
+
body: policies.to_yaml,
|
34
|
+
headers: { :'Content-type' => 'application/x-yaml' })
|
35
|
+
end
|
36
|
+
it 'return array of policies' do
|
37
|
+
expect(env.policies).to match_array(policies[:policies])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#policies=' do
|
42
|
+
before do
|
43
|
+
stub_request(:put, env_url)
|
44
|
+
.with(
|
45
|
+
body: policies.to_yaml,
|
46
|
+
headers: { :'Content-type' => 'application/x-yaml' })
|
47
|
+
.to_return do |request|
|
48
|
+
stub_request(:get, env_url)
|
49
|
+
.to_return(status: 200,
|
50
|
+
body: request.body,
|
51
|
+
headers: { :'Content-type' => 'application/x-yaml' })
|
52
|
+
{ status: 200 }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
it 'return array of policies' do
|
56
|
+
env.policies = policies[:policies]
|
57
|
+
expect(env.policies).to match_array(policies[:policies])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#properties' do
|
62
|
+
before do
|
63
|
+
stub_request(:get, "#{env_url}/properties")
|
64
|
+
.to_return(
|
65
|
+
status: 200,
|
66
|
+
body: properties.to_json,
|
67
|
+
headers: { :'Content-type' => 'application/json' })
|
68
|
+
end
|
69
|
+
it 'return array of properties' do
|
70
|
+
expect(env.properties).to match_array(properties[:properties])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#properties=' do
|
75
|
+
before do
|
76
|
+
stub_request(:put, "#{env_url}/properties")
|
77
|
+
.with(
|
78
|
+
body: properties.to_json,
|
79
|
+
headers: { :'Content-type' => 'application/json' })
|
80
|
+
.to_return do |request|
|
81
|
+
stub_request(:get, "#{env_url}/properties")
|
82
|
+
.to_return(status: 200,
|
83
|
+
body: request.body,
|
84
|
+
headers: { :'Content-type' => 'application/json' })
|
85
|
+
{ status: 200 }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
it 'can set value' do
|
89
|
+
env.properties = properties[:properties]
|
90
|
+
expect(env.properties).to match_array(properties[:properties])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#markers' do
|
95
|
+
before do
|
96
|
+
stub_request(:get, "#{env_url}/markers")
|
97
|
+
.to_return(
|
98
|
+
status: 200,
|
99
|
+
body: markers.to_json,
|
100
|
+
headers: { :'Content-type' => 'application/json' })
|
101
|
+
end
|
102
|
+
it 'return array of markers' do
|
103
|
+
expect(env.markers).to match_array(markers[:markers].map { |m| m[:name] })
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#markers=' do
|
108
|
+
before do
|
109
|
+
stub_request(:put, "#{env_url}/markers")
|
110
|
+
.with(
|
111
|
+
body: markers.to_json,
|
112
|
+
headers: { :'Content-type' => 'application/json' })
|
113
|
+
.to_return do |request|
|
114
|
+
stub_request(:get, "#{env_url}/markers")
|
115
|
+
.to_return(status: 200,
|
116
|
+
body: request.body,
|
117
|
+
headers: { :'Content-type' => 'application/json' })
|
118
|
+
{ status: 200 }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
it 'can set value' do
|
122
|
+
env.markers = markers[:markers]
|
123
|
+
expect(env.markers).to match_array(markers[:markers].map { |m| m[:name] })
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#instances' do
|
128
|
+
before do
|
129
|
+
stub_request(:get, "#{env_url}/instances")
|
130
|
+
.to_return(
|
131
|
+
status: 200,
|
132
|
+
body: instances.to_json,
|
133
|
+
headers: { :'Content-type' => 'application/json' })
|
134
|
+
end
|
135
|
+
it 'return array of application instances' do
|
136
|
+
expect(env.instances).to match_array(instances)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Qubell
|
5
|
+
describe Organization do
|
6
|
+
let(:config) { FactoryGirl.build :configuration }
|
7
|
+
let(:org) { FactoryGirl.build :organization }
|
8
|
+
let(:apps) { FactoryGirl.build_list(:application, 1) }
|
9
|
+
|
10
|
+
describe '#applications' do
|
11
|
+
before do
|
12
|
+
stub_request(:get,
|
13
|
+
"#{config.endpoint}/organizations/#{org.id}/applications")
|
14
|
+
.to_return(
|
15
|
+
status: 200,
|
16
|
+
body: apps.to_json,
|
17
|
+
headers: { :'Content-type' => 'application/json' })
|
18
|
+
end
|
19
|
+
it 'return array of applications' do
|
20
|
+
expect(org.applications).to match_array(apps)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#new' do
|
25
|
+
before do
|
26
|
+
stub_request(:get, "#{config.endpoint}/organizations")
|
27
|
+
.to_return(
|
28
|
+
status: 200,
|
29
|
+
body: [org].to_json,
|
30
|
+
headers: { :'Content-type' => 'application/json' })
|
31
|
+
end
|
32
|
+
it 'return organization' do
|
33
|
+
expect(org).to eq(Qubell::Organization.new(org.to_hash))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
module Qubell
|
4
|
+
describe Revision do
|
5
|
+
let(:config) { FactoryGirl.build :configuration }
|
6
|
+
let(:revision) { FactoryGirl.build :revision }
|
7
|
+
let(:revision_url) { "#{config.endpoint}/revisions/#{revision.id}" }
|
8
|
+
let(:instances) { FactoryGirl.build_list(:instance, 2) }
|
9
|
+
|
10
|
+
describe '#instances' do
|
11
|
+
before do
|
12
|
+
stub_request(:get, "#{revision_url}/instances")
|
13
|
+
.to_return(
|
14
|
+
status: 200,
|
15
|
+
body: instances.to_json,
|
16
|
+
headers: { :'Content-type' => 'application/json' })
|
17
|
+
end
|
18
|
+
it 'return array of application instances' do
|
19
|
+
expect(revision.instances).to match_array(instances)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module Qubell
|
4
|
+
describe API do
|
5
|
+
let(:config) { FactoryGirl.build :configuration }
|
6
|
+
let(:client) { FactoryGirl.build :client }
|
7
|
+
let(:orgs) { FactoryGirl.build_list(:organization, 1) }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
stub_request(:get, "#{config.endpoint}/organizations")
|
11
|
+
.to_return(
|
12
|
+
status: 200,
|
13
|
+
body: orgs.to_json,
|
14
|
+
headers: { :'Content-type' => 'application/json' })
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#organizations' do
|
18
|
+
it 'return array of organizations' do
|
19
|
+
expect(client.organizations).to eq(orgs)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'factory_girl'
|
6
|
+
require 'qubell_api'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
config.order = 'random'
|
12
|
+
config.include WebMock::API
|
13
|
+
config.include FactoryGirl::Syntax::Methods
|
14
|
+
config.before(:all) do
|
15
|
+
FactoryGirl.definition_file_paths = [
|
16
|
+
File.expand_path('../factories', __FILE__)
|
17
|
+
]
|
18
|
+
FactoryGirl.reload
|
19
|
+
end
|
20
|
+
config.before(:suite) do
|
21
|
+
FactoryGirl.lint
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
SimpleCov.start do
|
26
|
+
add_group 'Libraries', 'lib/*'
|
27
|
+
end
|