rsbe-client 0.5.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.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/GETTING-STARTED.md +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +11 -0
- data/TODO.md +38 -0
- data/lib/rsbe/client.rb +50 -0
- data/lib/rsbe/client/base.rb +140 -0
- data/lib/rsbe/client/collection.rb +84 -0
- data/lib/rsbe/client/connection.rb +24 -0
- data/lib/rsbe/client/method_not_implemented_error.rb +6 -0
- data/lib/rsbe/client/not_found_error.rb +6 -0
- data/lib/rsbe/client/partner.rb +82 -0
- data/lib/rsbe/client/provider.rb +47 -0
- data/lib/rsbe/client/se.rb +97 -0
- data/lib/rsbe/client/search.rb +80 -0
- data/lib/rsbe/client/search_results.rb +41 -0
- data/lib/rsbe/client/unrecognized_resource_error.rb +6 -0
- data/lib/rsbe/client/version.rb +5 -0
- data/lib/rsbe/client/wrong_origin_error.rb +6 -0
- data/rsbe-client.gemspec +30 -0
- data/spec/fixtures/partners/partners_all.json +1 -0
- data/spec/fixtures/partners/partners_none.json +1 -0
- data/spec/rsbe/client/base_spec.rb +10 -0
- data/spec/rsbe/client/collection_spec.rb +186 -0
- data/spec/rsbe/client/connection_spec.rb +20 -0
- data/spec/rsbe/client/partner_spec.rb +185 -0
- data/spec/rsbe/client/provider_spec.rb +122 -0
- data/spec/rsbe/client/se_spec.rb +273 -0
- data/spec/rsbe/client/search_results_spec.rb +140 -0
- data/spec/rsbe/client/search_spec.rb +74 -0
- data/spec/rsbe/client_spec.rb +52 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/vcr_cassettes/client/find_collection.yml +53 -0
- data/spec/vcr_cassettes/client/find_partner.yml +52 -0
- data/spec/vcr_cassettes/client/find_provider.yml +52 -0
- data/spec/vcr_cassettes/client/find_se.yml +53 -0
- data/spec/vcr_cassettes/collection/find-existing.yml +53 -0
- data/spec/vcr_cassettes/collection/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/collection/lazy-eval-dne.yml +285 -0
- data/spec/vcr_cassettes/collection/lazy-eval-exists.yml +53 -0
- data/spec/vcr_cassettes/collection/save-create-known-id.yml +103 -0
- data/spec/vcr_cassettes/collection/save-create-unknown-id.yml +56 -0
- data/spec/vcr_cassettes/collection/save-invalid.yml +143 -0
- data/spec/vcr_cassettes/collection/save-update-valid.yml +99 -0
- data/spec/vcr_cassettes/partner/all.yml +300 -0
- data/spec/vcr_cassettes/partner/dne-with-id.yml +238 -0
- data/spec/vcr_cassettes/partner/find-existing.yml +52 -0
- data/spec/vcr_cassettes/partner/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/partner/lazy-eval-exists.yml +53 -0
- data/spec/vcr_cassettes/partner/save-create-known-id.yml +101 -0
- data/spec/vcr_cassettes/partner/save-create-unknown-id.yml +54 -0
- data/spec/vcr_cassettes/partner/save-invalid.yml +177 -0
- data/spec/vcr_cassettes/partner/save-unknown-id.yml +54 -0
- data/spec/vcr_cassettes/partner/save-update-valid.yml +98 -0
- data/spec/vcr_cassettes/partner/with-collections.yml +203 -0
- data/spec/vcr_cassettes/partner/without-collections.yml +101 -0
- data/spec/vcr_cassettes/provider/all.yml +248 -0
- data/spec/vcr_cassettes/provider/find-existing.yml +52 -0
- data/spec/vcr_cassettes/provider/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/provider/save-create-known-id.yml +101 -0
- data/spec/vcr_cassettes/provider/save-create-unknown-id.yml +54 -0
- data/spec/vcr_cassettes/provider/save-invalid.yml +178 -0
- data/spec/vcr_cassettes/provider/save-update-valid.yml +144 -0
- data/spec/vcr_cassettes/se/find-existing.yml +53 -0
- data/spec/vcr_cassettes/se/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/se/lazy-eval-exists.yml +52 -0
- data/spec/vcr_cassettes/se/save-create-known-id.yml +146 -0
- data/spec/vcr_cassettes/se/save-create-unknown-id.yml +56 -0
- data/spec/vcr_cassettes/se/save-invalid.yml +305 -0
- data/spec/vcr_cassettes/se/save-update-valid.yml +99 -0
- data/spec/vcr_cassettes/se/search-malformed-uuid.yml +54 -0
- data/spec/vcr_cassettes/se/search-with-existing-se.yml +52 -0
- data/spec/vcr_cassettes/se/search-with-missing-se.yml +52 -0
- data/spec/vcr_cassettes/search/search-with-existing-se.yml +52 -0
- data/spec/vcr_cassettes/search_results/no-results.yml +52 -0
- data/spec/vcr_cassettes/search_results/search-by-digi_id.yml +101 -0
- data/spec/vcr_cassettes/search_results/search-by-step.yml +201 -0
- metadata +307 -0
@@ -0,0 +1 @@
|
|
1
|
+
[{"id":"8c32791e-0fcd-4508-86e0-6fd28ee4550d","code":"afc","name":"Avery Fisher Center","created_at":"2014-09-25T19:40:05.076Z","updated_at":"2014-09-25T19:40:05.076Z","url":"http://localhost:3000/api/v0/partners/8c32791e-0fcd-4508-86e0-6fd28ee4550d"},{"id":"2215c154-479a-433e-9dcd-b04eef8dedfa","code":"apa","name":"Asian/Pacific/American Institute","created_at":"2014-09-25T19:40:06.315Z","updated_at":"2014-09-25T19:40:06.315Z","url":"http://localhost:3000/api/v0/partners/2215c154-479a-433e-9dcd-b04eef8dedfa"},{"id":"66f3af3c-9a0d-43d4-8dcf-9cf3189bc84e","code":"bobst","name":"New York University Bobst Library","created_at":"2014-09-25T19:40:06.581Z","updated_at":"2014-09-25T19:40:06.581Z","url":"http://localhost:3000/api/v0/partners/66f3af3c-9a0d-43d4-8dcf-9cf3189bc84e"},{"id":"c6512a7e-8e95-4857-966b-c25cffb864f4","code":"brill","name":"Koninklijke Brill NV","created_at":"2014-09-25T19:40:06.803Z","updated_at":"2014-09-25T19:40:06.803Z","url":"http://localhost:3000/api/v0/partners/c6512a7e-8e95-4857-966b-c25cffb864f4"},{"id":"1610d763-a788-42fe-996a-f8717403e7e3","code":"columbia","name":"Columbia University Libraries","created_at":"2014-09-25T19:40:07.027Z","updated_at":"2014-09-25T19:40:07.027Z","url":"http://localhost:3000/api/v0/partners/1610d763-a788-42fe-996a-f8717403e7e3"},{"id":"bd48bc64-0ba6-4d28-8b7e-cfe444fc65ba","code":"cornell","name":"Cornell University Libraries","created_at":"2014-09-25T19:40:07.246Z","updated_at":"2014-09-25T19:40:07.246Z","url":"http://localhost:3000/api/v0/partners/bd48bc64-0ba6-4d28-8b7e-cfe444fc65ba"},{"id":"e6517775-6277-4e25-9373-ee7738e820b5","code":"dlts","name":"New York University Digital Library Technology Services","created_at":"2014-09-25T19:40:07.524Z","updated_at":"2014-09-25T19:40:07.524Z","url":"http://localhost:3000/api/v0/partners/e6517775-6277-4e25-9373-ee7738e820b5"},{"id":"2f096796-c685-444f-a4fe-5971346b159d","code":"fales","name":"The Fales Library \u0026 Special Collections","created_at":"2014-09-25T19:40:07.762Z","updated_at":"2014-09-25T19:40:07.762Z","url":"http://localhost:3000/api/v0/partners/2f096796-c685-444f-a4fe-5971346b159d"},{"id":"c263d631-6cc5-42e9-8070-00ecfa4915b5","code":"ifa","name":"Institute of Fine Arts","created_at":"2014-09-25T19:40:07.986Z","updated_at":"2014-09-25T19:40:07.986Z","url":"http://localhost:3000/api/v0/partners/c263d631-6cc5-42e9-8070-00ecfa4915b5"},{"id":"12b75a91-081d-414b-82cb-c347d0bbf0e0","code":"isaw","name":"Institute for the Study of the Ancient World","created_at":"2014-09-25T19:40:08.237Z","updated_at":"2014-09-25T19:40:08.237Z","url":"http://localhost:3000/api/v0/partners/12b75a91-081d-414b-82cb-c347d0bbf0e0"},{"id":"4200a155-38a2-494f-ad56-c32a03382570","code":"nyu","name":"New York University Libraries","created_at":"2014-09-25T19:40:08.461Z","updated_at":"2014-09-25T19:40:08.461Z","url":"http://localhost:3000/api/v0/partners/4200a155-38a2-494f-ad56-c32a03382570"},{"id":"a2ab971f-ce12-4799-96a3-d550207e2f54","code":"nyuad","name":"New York University Libraries - Abu Dhabi","created_at":"2014-09-25T19:40:08.687Z","updated_at":"2014-09-25T19:40:08.687Z","url":"http://localhost:3000/api/v0/partners/a2ab971f-ce12-4799-96a3-d550207e2f54"},{"id":"01dcf840-93bf-4184-8ebe-b9ec3261015e","code":"nyuarchives","name":"New York University Archives","created_at":"2014-09-25T19:40:08.910Z","updated_at":"2014-09-25T19:40:08.910Z","url":"http://localhost:3000/api/v0/partners/01dcf840-93bf-4184-8ebe-b9ec3261015e"},{"id":"d95dd72c-9d28-411b-95be-0d3831464eea","code":"nyuhsl","name":"New York University Health Sciences Library","created_at":"2014-09-25T19:40:09.132Z","updated_at":"2014-09-25T19:40:09.132Z","url":"http://localhost:3000/api/v0/partners/d95dd72c-9d28-411b-95be-0d3831464eea"},{"id":"73cc4a72-b59f-4d54-b393-87353a3332df","code":"nyup","name":"New York University Press","created_at":"2014-09-25T19:40:09.354Z","updated_at":"2014-09-25T19:40:09.354Z","url":"http://localhost:3000/api/v0/partners/73cc4a72-b59f-4d54-b393-87353a3332df"},{"id":"bfd9ea9a-66ee-4d0c-95b2-e9b54f883cb5","code":"nyupoly","name":"New York University Polytechnic Archives","created_at":"2014-09-25T19:40:09.576Z","updated_at":"2014-09-25T19:40:09.576Z","url":"http://localhost:3000/api/v0/partners/bfd9ea9a-66ee-4d0c-95b2-e9b54f883cb5"},{"id":"acb3cd77-9408-4135-93e7-9b7d105f4c68","code":"pres","name":"Barbara Goldsmith Preservation and Conservation Department","created_at":"2014-09-25T19:40:09.795Z","updated_at":"2014-09-25T19:40:09.795Z","url":"http://localhost:3000/api/v0/partners/acb3cd77-9408-4135-93e7-9b7d105f4c68"},{"id":"062309d0-5a8a-46dd-8783-60e62f8cf1a5","code":"princeton","name":"Princeton University Libraries","created_at":"2014-09-25T19:40:10.019Z","updated_at":"2014-09-25T19:40:10.019Z","url":"http://localhost:3000/api/v0/partners/062309d0-5a8a-46dd-8783-60e62f8cf1a5"},{"id":"95b6d056-9026-4436-b3a9-4fad9a7a927f","code":"tamwag","name":"The Tamiment Library and Robert F. Wagner Labor Archives","created_at":"2014-09-25T19:40:10.274Z","updated_at":"2014-09-25T19:40:10.274Z","url":"http://localhost:3000/api/v0/partners/95b6d056-9026-4436-b3a9-4fad9a7a927f"}]
|
@@ -0,0 +1 @@
|
|
1
|
+
[]
|
@@ -0,0 +1,186 @@
|
|
1
|
+
describe Rsbe::Client::Collection do
|
2
|
+
|
3
|
+
describe ".new" do
|
4
|
+
context "with valid attributes and symbol keys" do
|
5
|
+
subject { Rsbe::Client::Collection.new(code: 'boo', rel_path: 'b/o/o') }
|
6
|
+
it { should be_a(Rsbe::Client::Collection) }
|
7
|
+
its(:code) { should eq 'boo' }
|
8
|
+
its(:rel_path) { should eq 'b/o/o' }
|
9
|
+
end
|
10
|
+
context "with valid attributes and string keys" do
|
11
|
+
subject { Rsbe::Client::Collection.new('code' => 'boo', 'rel_path' => 'b/o/o') }
|
12
|
+
it { should be_a(Rsbe::Client::Collection) }
|
13
|
+
its(:code) { should eq 'boo' }
|
14
|
+
its(:rel_path) { should eq 'b/o/o' }
|
15
|
+
end
|
16
|
+
context "with incorrect argument type" do
|
17
|
+
subject { Rsbe::Client::Collection.new(42) }
|
18
|
+
it 'should raise an ArgumentError' do
|
19
|
+
expect { subject }.to raise_error ArgumentError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".base_path" do
|
25
|
+
subject { Rsbe::Client::Collection }
|
26
|
+
its(:base_path) { should eq '/api/v0/colls' }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".all" do
|
30
|
+
subject { Rsbe::Client::Collection.all }
|
31
|
+
it 'should raise a MethodNotImplementedError' do
|
32
|
+
expect { subject }.to raise_error Rsbe::Client::MethodNotImplementedError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find" do
|
37
|
+
context "with id of existing Collection", vcr: {cassette_name: 'collection/find-existing'} do
|
38
|
+
subject { Rsbe::Client::Collection.find('fc7455cf-3b20-494c-9b9e-17cae9e51fa1') }
|
39
|
+
its(:class) { should eq Rsbe::Client::Collection }
|
40
|
+
its(:id) { should eq 'fc7455cf-3b20-494c-9b9e-17cae9e51fa1' }
|
41
|
+
its(:code) { should eq 'zaap' }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with non-existent id", vcr: {cassette_name: 'collection/find-non_existent'} do
|
45
|
+
subject { Rsbe::Client::Collection.find('bad45d46-a14a-489f-97ac-384afb552a13') }
|
46
|
+
it 'should raise an Rsbe::Client::RecordNotFound' do
|
47
|
+
expect { subject }.to raise_error Rsbe::Client::RecordNotFound
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#save" do
|
53
|
+
context "when creating a new Collection" do
|
54
|
+
context "with valid attributes" do
|
55
|
+
# TODO: implment FactoryGirl
|
56
|
+
context "and no id", vcr: {cassette_name: 'collection/save-create-unknown-id'} do
|
57
|
+
let(:partner_id) { "5c902ffa-b2d9-4b8a-bac6-6ec8cfb50baa" }
|
58
|
+
let(:code) { 'luke' }
|
59
|
+
let(:quota) { 1024 }
|
60
|
+
let(:name) { 'Lasers Under Kinetic Ether' }
|
61
|
+
let(:coll_type) { 'origin' }
|
62
|
+
let(:collection) { Rsbe::Client::Collection.new(partner_id: partner_id,
|
63
|
+
code: code,
|
64
|
+
quota: quota,
|
65
|
+
name: name,
|
66
|
+
coll_type: coll_type) }
|
67
|
+
subject { collection }
|
68
|
+
its(:save) { should eq true }
|
69
|
+
|
70
|
+
context "after save" do
|
71
|
+
before { collection.save }
|
72
|
+
its(:id) { should_not be_nil }
|
73
|
+
its(:partner_id) { should eq '5c902ffa-b2d9-4b8a-bac6-6ec8cfb50baa' }
|
74
|
+
its(:code) { should eq code }
|
75
|
+
its(:quota) { should eq quota }
|
76
|
+
its(:name) { should eq name }
|
77
|
+
its(:created_at) { should_not be_nil }
|
78
|
+
its(:updated_at) { should_not be_nil }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "and a known id", vcr: {cassette_name: 'collection/save-create-known-id'} do
|
83
|
+
let(:collection) do
|
84
|
+
Rsbe::Client::Collection.new(id: '07998216-af0a-4262-b7f9-6a7d9c4aeae4',
|
85
|
+
partner_id: '5c902ffa-b2d9-4b8a-bac6-6ec8cfb50baa',
|
86
|
+
code: 'han',
|
87
|
+
name: 'Happy Anteaters of Nigeria',
|
88
|
+
quota: 123,
|
89
|
+
coll_type: 'origin')
|
90
|
+
end
|
91
|
+
subject { collection }
|
92
|
+
its(:save) { should eq true }
|
93
|
+
|
94
|
+
context "after save" do
|
95
|
+
before { collection.save }
|
96
|
+
its(:id) { should eq '07998216-af0a-4262-b7f9-6a7d9c4aeae4' }
|
97
|
+
its(:partner_id) { should eq '5c902ffa-b2d9-4b8a-bac6-6ec8cfb50baa' }
|
98
|
+
its(:code) { should eq 'han' }
|
99
|
+
its(:name) { should eq 'Happy Anteaters of Nigeria' }
|
100
|
+
its(:quota) { should eq 123 }
|
101
|
+
its(:created_at) { should_not be_nil }
|
102
|
+
its(:updated_at) { should_not be_nil }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context "with invalid attributes", vcr: {cassette_name: 'collection/save-invalid'} do
|
107
|
+
let(:collection) do
|
108
|
+
Rsbe::Client::Collection.new(partner_id: '5c902ffa-b2d9-4b8a-bac6-6ec8cfb50baa',
|
109
|
+
coll_type: 'banana frappe')
|
110
|
+
end
|
111
|
+
subject { collection }
|
112
|
+
its(:save) { should eq false }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
context "when updating a Collection" do
|
116
|
+
context "with valid attributes", vcr: {cassette_name: 'collection/save-update-valid'} do
|
117
|
+
let(:collection) { Rsbe::Client::Collection.find('07998216-af0a-4262-b7f9-6a7d9c4aeae4') }
|
118
|
+
subject { collection }
|
119
|
+
context "before save-as-update" do
|
120
|
+
its(:id) { should eq '07998216-af0a-4262-b7f9-6a7d9c4aeae4' }
|
121
|
+
its(:code) { should eq 'han' }
|
122
|
+
its(:name) { should eq 'Happy Anteaters of Nigeria' }
|
123
|
+
its(:created_at) { should_not be_nil }
|
124
|
+
its(:updated_at) { should_not be_nil }
|
125
|
+
end
|
126
|
+
context "on save-as-update" do
|
127
|
+
before do
|
128
|
+
collection.name = 'Last Emu In Australia'
|
129
|
+
collection.code = 'leia'
|
130
|
+
end
|
131
|
+
its(:save) { should eq true }
|
132
|
+
context "after save" do
|
133
|
+
its(:id) { should eq '07998216-af0a-4262-b7f9-6a7d9c4aeae4' }
|
134
|
+
its(:code) { should eq 'leia' }
|
135
|
+
its(:name) { should eq 'Last Emu In Australia' }
|
136
|
+
its(:created_at) { should_not be_nil }
|
137
|
+
its(:updated_at) { should_not be_nil }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
describe "lazy evaluation" do
|
144
|
+
context "when Collection exists, but is populated with minimal attributes", vcr: {cassette_name: 'collection/lazy-eval-exists'} do
|
145
|
+
let(:collection) { Rsbe::Client::Collection.new(id: 'fc7455cf-3b20-494c-9b9e-17cae9e51fa1') }
|
146
|
+
it "should return values for all attributes" do
|
147
|
+
expect(collection.code).to eq 'zaap'
|
148
|
+
expect(collection.name).to eq 'Zoinks and Away, Potatoes!'
|
149
|
+
expect(collection.quota).to eq 500
|
150
|
+
expect(collection.coll_type).to eq 'origin'
|
151
|
+
expect(collection.lock_version).not_to be_nil
|
152
|
+
expect(collection.created_at).not_to be_nil
|
153
|
+
expect(collection.updated_at).not_to be_nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
context "when Collection does not exist in RSBE and does not have an id" do
|
157
|
+
let(:collection) { Rsbe::Client::Collection.new }
|
158
|
+
it "should return nil for all attributes" do
|
159
|
+
expect(collection.id).to be_nil
|
160
|
+
expect(collection.code).to be_nil
|
161
|
+
expect(collection.name).to be_nil
|
162
|
+
expect(collection.quota).to be_nil
|
163
|
+
expect(collection.coll_type).to be_nil
|
164
|
+
expect(collection.lock_version).to be_nil
|
165
|
+
expect(collection.created_at).to be_nil
|
166
|
+
expect(collection.updated_at).to be_nil
|
167
|
+
end
|
168
|
+
end
|
169
|
+
context "when Collection does not exist in RSBE but has an id", vcr: {cassette_name: 'collection/lazy-eval-dne'} do
|
170
|
+
let(:collection) do
|
171
|
+
Rsbe::Client::Collection.new(id: '7c7afee8-c8be-43bf-8096-c03672aaf114',
|
172
|
+
code: 'flippers')
|
173
|
+
end
|
174
|
+
it "should return values for defined attributes" do
|
175
|
+
expect(collection.id).to eq '7c7afee8-c8be-43bf-8096-c03672aaf114'
|
176
|
+
expect(collection.code).to eq 'flippers'
|
177
|
+
expect(collection.name).to be_nil
|
178
|
+
expect(collection.quota).to be_nil
|
179
|
+
expect(collection.coll_type).to be_nil
|
180
|
+
expect(collection.lock_version).to be_nil
|
181
|
+
expect(collection.created_at).to be_nil
|
182
|
+
expect(collection.updated_at).to be_nil
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
describe Rsbe::Client::Connection do
|
2
|
+
let(:same_origin_url) { 'http://localhost:3000/api/v0/partners/2f096796-c685-444f-a4fe-5971346b159d' }
|
3
|
+
let(:different_origin_url) { 'http://localhost:3001/api/v0/partners/2f096796-c685-444f-a4fe-5971346b159d' }
|
4
|
+
|
5
|
+
context "when created" do
|
6
|
+
subject { Rsbe::Client::Connection.new }
|
7
|
+
it { should be_a(Rsbe::Client::Connection) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "same_origin?" do
|
11
|
+
context "with a url from the same origin" do
|
12
|
+
subject { Rsbe::Client::Connection.new.same_origin?(same_origin_url) }
|
13
|
+
it { should == true }
|
14
|
+
end
|
15
|
+
context "with a url from a different origin" do
|
16
|
+
subject { Rsbe::Client::Connection.new.same_origin?(different_origin_url) }
|
17
|
+
it { should == false }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
describe Rsbe::Client::Partner do
|
2
|
+
|
3
|
+
describe ".new" do
|
4
|
+
context "with valid attributes and symbol keys" do
|
5
|
+
subject { Rsbe::Client::Partner.new(code: 'foo', rel_path: 'f/o/o') }
|
6
|
+
it { should be_a(Rsbe::Client::Partner) }
|
7
|
+
its(:code) { should eq 'foo' }
|
8
|
+
its(:rel_path) { should eq 'f/o/o' }
|
9
|
+
end
|
10
|
+
context "with valid attributes and string keys" do
|
11
|
+
subject { Rsbe::Client::Partner.new('code' => 'foo', 'rel_path' => 'f/o/o') }
|
12
|
+
it { should be_a(Rsbe::Client::Partner) }
|
13
|
+
its(:code) { should eq 'foo' }
|
14
|
+
its(:rel_path) { should eq 'f/o/o' }
|
15
|
+
end
|
16
|
+
context "with incorrect argument type" do
|
17
|
+
subject { Rsbe::Client::Partner.new(42) }
|
18
|
+
it 'should raise an ArgumentError' do
|
19
|
+
expect { subject }.to raise_error ArgumentError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe ".base_path" do
|
24
|
+
subject { Rsbe::Client::Partner }
|
25
|
+
its(:base_path) { should eq '/api/v0/partners' }
|
26
|
+
end
|
27
|
+
describe ".all", vcr: { cassette_name: 'partner/all' } do
|
28
|
+
context "returned array" do
|
29
|
+
subject { Rsbe::Client::Partner.all }
|
30
|
+
it { should be_a(Array) }
|
31
|
+
its(:size) { should eq 4 }
|
32
|
+
end
|
33
|
+
context "returned array element" do
|
34
|
+
subject { Rsbe::Client::Partner.all[0] }
|
35
|
+
it { should be_a(Rsbe::Client::Partner) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ".find" do
|
40
|
+
context "with id of existing Partner", vcr: { cassette_name: 'partner/find-existing' } do
|
41
|
+
subject { Rsbe::Client::Partner.find('b110731f-86af-4534-8e58-6d219dcb1c52') }
|
42
|
+
its(:class) { should eq Rsbe::Client::Partner }
|
43
|
+
its(:id) { should eq 'b110731f-86af-4534-8e58-6d219dcb1c52' }
|
44
|
+
its(:code) { should eq 'quux' }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with non-existant id", vcr: { cassette_name: 'partner/find-non_existent' } do
|
48
|
+
subject { Rsbe::Client::Partner.find('bad45d46-a14a-489f-97ac-384afb552a13') }
|
49
|
+
it 'should raise an Rsbe::Client::RecordNotFound' do
|
50
|
+
expect { subject }.to raise_error Rsbe::Client::RecordNotFound
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#save" do
|
56
|
+
context "when creating a new Partner" do
|
57
|
+
context "with valid attributes" do
|
58
|
+
context "and no id", vcr: { cassette_name: 'partner/save-create-unknown-id' } do
|
59
|
+
let(:partner) { Rsbe::Client::Partner.new(code: 'foo', rel_path: 'f/o/o') }
|
60
|
+
subject { partner }
|
61
|
+
its(:save) { should eq true }
|
62
|
+
|
63
|
+
context "after save" do
|
64
|
+
before { partner.save }
|
65
|
+
its(:id) { should_not be_nil }
|
66
|
+
its(:code) { should eq 'foo' }
|
67
|
+
its(:created_at) { should_not be_nil }
|
68
|
+
its(:updated_at) { should_not be_nil }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "and a known id", vcr: {cassette_name: 'partner/save-create-known-id'} do
|
73
|
+
let(:partner) do
|
74
|
+
Rsbe::Client::Partner.new(id: '51213be7-c8de-4e06-8cc2-06bfc82cdd68',
|
75
|
+
code: 'bar',
|
76
|
+
rel_path: 'b/a/r')
|
77
|
+
end
|
78
|
+
subject { partner }
|
79
|
+
its(:save) { should eq true }
|
80
|
+
|
81
|
+
context "after save" do
|
82
|
+
before { partner.save }
|
83
|
+
its(:id) { should eq '51213be7-c8de-4e06-8cc2-06bfc82cdd68' }
|
84
|
+
its(:code) { should eq 'bar' }
|
85
|
+
its(:created_at) { should_not be_nil }
|
86
|
+
its(:updated_at) { should_not be_nil }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "with invalid attributes", vcr: {cassette_name: 'partner/save-invalid'} do
|
92
|
+
let(:partner) { Rsbe::Client::Partner.new(id: 'abc123',
|
93
|
+
code: 'baz a saurus',
|
94
|
+
rel_path: 'b/a/z') }
|
95
|
+
subject { partner }
|
96
|
+
its(:save) { should eq false }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
context "when updating a Partner" do
|
100
|
+
context "with valid attributes", vcr: {cassette_name: 'partner/save-update-valid'} do
|
101
|
+
let(:partner) { Rsbe::Client::Partner.find('b051f936-835c-4abb-9034-efa7508db4bf') }
|
102
|
+
subject { partner }
|
103
|
+
context "before save-as-update" do
|
104
|
+
its(:id) { should eq 'b051f936-835c-4abb-9034-efa7508db4bf' }
|
105
|
+
its(:code) { should eq 'onyx' }
|
106
|
+
its(:name) { should be_nil }
|
107
|
+
its(:created_at) { should_not be_nil }
|
108
|
+
its(:updated_at) { should_not be_nil }
|
109
|
+
end
|
110
|
+
|
111
|
+
context "on save-as-update" do
|
112
|
+
before { partner.name = 'The Black Onyx Syndicate' }
|
113
|
+
its(:save) { should eq true }
|
114
|
+
context "after save" do
|
115
|
+
its(:id) { should eq 'b051f936-835c-4abb-9034-efa7508db4bf' }
|
116
|
+
its(:code) { should eq 'onyx' }
|
117
|
+
its(:name) { should eq 'The Black Onyx Syndicate' }
|
118
|
+
its(:created_at) { should_not be_nil }
|
119
|
+
its(:updated_at) { should_not be_nil }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
describe "#collections" do
|
126
|
+
context "when Partner has some collections", vcr: {cassette_name: 'partner/with-collections'} do
|
127
|
+
let(:partner) { Rsbe::Client::Partner.find('5c902ffa-b2d9-4b8a-bac6-6ec8cfb50baa') }
|
128
|
+
let(:collections) { partner.collections }
|
129
|
+
|
130
|
+
it "should return an Array of Collections" do
|
131
|
+
expect(collections).to be_instance_of Array
|
132
|
+
expect(collections.first).to be_instance_of Rsbe::Client::Collection
|
133
|
+
expect(collections.length).to eq 2
|
134
|
+
expect(collections.first.code).to eq 'luke'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
context "when Partner doesn't have any collections", vcr: {cassette_name: 'partner/without-collections'} do
|
138
|
+
let(:partner) { Rsbe::Client::Partner.find('51213be7-c8de-4e06-8cc2-06bfc82cdd68') }
|
139
|
+
let(:collections) { partner.collections }
|
140
|
+
|
141
|
+
it "should return an Array of Collections" do
|
142
|
+
expect(collections).to be_instance_of Array
|
143
|
+
expect(collections.length).to eq 0
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
describe "lazy evaluation" do
|
148
|
+
context "when Partner exists, but is populated with minimal attributes", vcr: {cassette_name: 'partner/lazy-eval-exists'} do
|
149
|
+
let(:partner) { Rsbe::Client::Partner.new(id: 'b051f936-835c-4abb-9034-efa7508db4bf') }
|
150
|
+
it "should return values for all attributes" do
|
151
|
+
expect(partner.code).to eq 'onyx'
|
152
|
+
expect(partner.name).to eq 'The Black Onyx Syndicate'
|
153
|
+
expect(partner.rel_path).to eq 'o/n/y/x'
|
154
|
+
expect(partner.lock_version).not_to be_nil
|
155
|
+
expect(partner.created_at).not_to be_nil
|
156
|
+
expect(partner.updated_at).not_to be_nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
context "when Partner does not exist in RSBE and does not have an id" do
|
160
|
+
let(:partner) { Rsbe::Client::Partner.new }
|
161
|
+
it "should return values for all attributes" do
|
162
|
+
expect(partner.code).to be_nil
|
163
|
+
expect(partner.name).to be_nil
|
164
|
+
expect(partner.rel_path).to be_nil
|
165
|
+
expect(partner.lock_version).to be_nil
|
166
|
+
expect(partner.created_at).to be_nil
|
167
|
+
expect(partner.updated_at).to be_nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
context "when Partner does not exist in RSBE but has an id" do
|
171
|
+
let(:partner) do
|
172
|
+
Rsbe::Client::Partner.new(id: '7c7afee8-c8be-43bf-8096-c03672aaf114',
|
173
|
+
code: 'topaz')
|
174
|
+
end
|
175
|
+
it "should return values for defined attributes", vcr: {cassette_name: 'partner/dne-with-id'} do
|
176
|
+
expect(partner.code).to eq 'topaz'
|
177
|
+
expect(partner.name).to be_nil
|
178
|
+
expect(partner.rel_path).to be_nil
|
179
|
+
expect(partner.lock_version).to be_nil
|
180
|
+
expect(partner.created_at).to be_nil
|
181
|
+
expect(partner.updated_at).to be_nil
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
describe Rsbe::Client::Provider do
|
2
|
+
|
3
|
+
describe ".new" do
|
4
|
+
let(:provider_name) { 'James T. Kirk' }
|
5
|
+
context "with valid attributes and symbol keys" do
|
6
|
+
subject { Rsbe::Client::Provider.new(name: provider_name) }
|
7
|
+
it { should be_a(Rsbe::Client::Provider) }
|
8
|
+
its(:name) { should eq provider_name }
|
9
|
+
end
|
10
|
+
context "with valid attributes and string keys" do
|
11
|
+
subject { Rsbe::Client::Provider.new('name' => provider_name) }
|
12
|
+
it { should be_a(Rsbe::Client::Provider) }
|
13
|
+
its(:name) { should eq provider_name }
|
14
|
+
end
|
15
|
+
context "with incorrect argument type" do
|
16
|
+
subject { Rsbe::Client::Provider.new(42) }
|
17
|
+
it 'should raise an ArgumentError' do
|
18
|
+
expect { subject }.to raise_error ArgumentError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".base_path" do
|
24
|
+
subject { Rsbe::Client::Provider }
|
25
|
+
its(:base_path) { should eq '/api/v0/providers' }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".all", vcr: {cassette_name: 'provider/all'} do
|
29
|
+
context "returned array" do
|
30
|
+
subject { Rsbe::Client::Provider.all }
|
31
|
+
it { should be_a(Array) }
|
32
|
+
its(:size) { should eq 4 }
|
33
|
+
end
|
34
|
+
context "returned array element" do
|
35
|
+
subject { Rsbe::Client::Provider.all[0] }
|
36
|
+
it { should be_a(Rsbe::Client::Provider) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".find" do
|
41
|
+
context "with id of existing Provider", vcr: {cassette_name: 'provider/find-existing'} do
|
42
|
+
subject { Rsbe::Client::Provider.find('0938b200-e388-4626-bee8-69b3fc73ecdb') }
|
43
|
+
its(:class) { should eq Rsbe::Client::Provider }
|
44
|
+
its(:id) { should eq '0938b200-e388-4626-bee8-69b3fc73ecdb' }
|
45
|
+
its(:name) { should eq 'Portia' }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with non-existant id", vcr: {cassette_name: 'provider/find-non_existent'} do
|
49
|
+
subject { Rsbe::Client::Provider.find('bad45d46-a14a-489f-97ac-384afb552a13') }
|
50
|
+
it 'should raise an Rsbe::Client::RecordNotFound' do
|
51
|
+
expect { subject }.to raise_error Rsbe::Client::RecordNotFound
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#save" do
|
57
|
+
context "when creating a new Provider" do
|
58
|
+
context "with valid attributes" do
|
59
|
+
context "and no id", vcr: {cassette_name: 'provider/save-create-unknown-id'} do
|
60
|
+
let(:provider) { Rsbe::Client::Provider.new(name: 'Antony') }
|
61
|
+
subject { provider }
|
62
|
+
its(:save) { should eq true }
|
63
|
+
|
64
|
+
context "after save" do
|
65
|
+
before { provider.save }
|
66
|
+
its(:id) { should_not be_nil }
|
67
|
+
its(:name) { should eq 'Antony' }
|
68
|
+
its(:created_at) { should_not be_nil }
|
69
|
+
its(:updated_at) { should_not be_nil }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "and a known id", vcr: {cassette_name: 'provider/save-create-known-id'} do
|
73
|
+
let(:provider) do
|
74
|
+
Rsbe::Client::Provider.new(id: '51213be7-c8de-4e06-8cc2-06bfc82cdd68',
|
75
|
+
name: 'Octavius')
|
76
|
+
end
|
77
|
+
subject { provider }
|
78
|
+
its(:save) { should eq true }
|
79
|
+
context "after save" do
|
80
|
+
before { provider.save }
|
81
|
+
its(:id) { should eq '51213be7-c8de-4e06-8cc2-06bfc82cdd68' }
|
82
|
+
its(:name) { should eq 'Octavius' }
|
83
|
+
its(:created_at) { should_not be_nil }
|
84
|
+
its(:updated_at) { should_not be_nil }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with invalid attributes", vcr: {cassette_name: 'provider/save-invalid'} do
|
91
|
+
let(:provider) { Rsbe::Client::Provider.new(id: 'abc123',
|
92
|
+
name: '') }
|
93
|
+
subject { provider }
|
94
|
+
its(:save) { should eq false }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when updating a Provider" do
|
99
|
+
context "with valid attributes", vcr: {cassette_name: 'provider/save-update-valid'} do
|
100
|
+
let(:provider) { Rsbe::Client::Provider.find('51213be7-c8de-4e06-8cc2-06bfc82cdd68') }
|
101
|
+
subject { provider }
|
102
|
+
context "before save-as-update" do
|
103
|
+
its(:id) { should eq '51213be7-c8de-4e06-8cc2-06bfc82cdd68' }
|
104
|
+
its(:name) { should eq 'Octavius' }
|
105
|
+
its(:created_at) { should_not be_nil }
|
106
|
+
its(:updated_at) { should_not be_nil }
|
107
|
+
end
|
108
|
+
|
109
|
+
context "on save-as-update" do
|
110
|
+
before { provider.name = 'Calpurnia' }
|
111
|
+
its(:save) { should eq true }
|
112
|
+
context "after save" do
|
113
|
+
its(:id) { should eq '51213be7-c8de-4e06-8cc2-06bfc82cdd68' }
|
114
|
+
its(:name) { should eq 'Calpurnia' }
|
115
|
+
its(:created_at) { should_not be_nil }
|
116
|
+
its(:updated_at) { should_not be_nil }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|