frenetic 1.0.0.alpha.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +16 -0
- data/.gitignore +1 -1
- data/.irbrc +1 -1
- data/.rubocop.yml +45 -0
- data/.travis.yml +2 -2
- data/Appraisals +1 -1
- data/LICENSE +1 -1
- data/README.md +15 -15
- data/Rakefile +1 -1
- data/gemfiles/faraday_08.gemfile.lock +8 -8
- data/gemfiles/faraday_09.gemfile.lock +8 -8
- data/lib/frenetic.rb +13 -10
- data/lib/frenetic/briefly_memoizable.rb +9 -7
- data/lib/frenetic/concerns/collection_rest_methods.rb +4 -5
- data/lib/frenetic/concerns/hal_linked.rb +12 -9
- data/lib/frenetic/concerns/member_rest_methods.rb +7 -10
- data/lib/frenetic/concerns/structured.rb +2 -2
- data/lib/frenetic/connection.rb +25 -17
- data/lib/frenetic/errors.rb +67 -2
- data/lib/frenetic/hypermedia_link.rb +19 -26
- data/lib/frenetic/hypermedia_link_set.rb +11 -14
- data/lib/frenetic/middleware/hal_json.rb +3 -4
- data/lib/frenetic/resource.rb +31 -25
- data/lib/frenetic/resource_collection.rb +3 -3
- data/lib/frenetic/resource_mockery.rb +7 -5
- data/lib/frenetic/version.rb +2 -2
- data/spec/briefly_memoizable_spec.rb +1 -1
- data/spec/concerns/hal_linked_spec.rb +5 -5
- data/spec/concerns/member_rest_methods_spec.rb +1 -1
- data/spec/concerns/structured_spec.rb +6 -5
- data/spec/connection_spec.rb +16 -4
- data/spec/fixtures/test_api_requests.rb +32 -28
- data/spec/frenetic_spec.rb +3 -3
- data/spec/hypermedia_link_set_spec.rb +3 -3
- data/spec/hypermedia_link_spec.rb +1 -1
- data/spec/middleware/hal_json_spec.rb +3 -3
- data/spec/resource_collection_spec.rb +3 -4
- data/spec/resource_mockery_spec.rb +29 -6
- data/spec/resource_spec.rb +30 -13
- data/spec/spec_helper.rb +1 -1
- data/spec/support/i18n.rb +1 -0
- data/spec/support/rspec.rb +1 -1
- data/spec/support/timecop.rb +1 -1
- data/spec/support/webmock.rb +1 -1
- metadata +8 -4
data/spec/resource_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Frenetic::Resource do
|
4
4
|
let(:test_cfg) { { url:'http://example.com/api' } }
|
5
|
-
|
6
5
|
let(:abstract_resource) do
|
7
6
|
cfg = test_cfg
|
8
7
|
|
@@ -10,9 +9,15 @@ describe Frenetic::Resource do
|
|
10
9
|
api_client { Frenetic.new(cfg) }
|
11
10
|
end
|
12
11
|
end
|
12
|
+
let(:mock_abstract_resource) do
|
13
|
+
Class.new(MyNamespace::MyTempResource) do
|
14
|
+
include Frenetic::ResourceMockery
|
15
|
+
end
|
16
|
+
end
|
13
17
|
|
14
18
|
before do
|
15
19
|
stub_const 'MyNamespace::MyTempResource', abstract_resource
|
20
|
+
stub_const 'MyNamespace::MockMyTempResource', mock_abstract_resource
|
16
21
|
end
|
17
22
|
|
18
23
|
describe '.api_client' do
|
@@ -142,7 +147,7 @@ describe Frenetic::Resource do
|
|
142
147
|
end
|
143
148
|
|
144
149
|
it 'raises an error' do
|
145
|
-
expect{subject}.to raise_error Frenetic::
|
150
|
+
expect{subject}.to raise_error Frenetic::MissingSchemaDefinition
|
146
151
|
end
|
147
152
|
end
|
148
153
|
|
@@ -187,6 +192,8 @@ describe Frenetic::Resource do
|
|
187
192
|
subject { MyNamespace::MyTempResource.mock_class }
|
188
193
|
|
189
194
|
context 'without a defined Mock-class' do
|
195
|
+
let(:mock_abstract_resource) { Class.new }
|
196
|
+
|
190
197
|
it 'raises an error' do
|
191
198
|
expect{subject}.to raise_error Frenetic::UndefinedResourceMock
|
192
199
|
end
|
@@ -226,29 +233,39 @@ describe Frenetic::Resource do
|
|
226
233
|
|
227
234
|
context 'and an embedded resource' do
|
228
235
|
let(:args) do
|
229
|
-
super().merge(
|
236
|
+
super().merge(
|
230
237
|
'_embedded' => {
|
231
|
-
'
|
238
|
+
'embedded_resource' => {
|
232
239
|
'id' => 99,
|
233
240
|
'genus' => 'canine'
|
234
241
|
}
|
235
242
|
}
|
236
|
-
|
243
|
+
)
|
237
244
|
end
|
238
245
|
|
239
|
-
context '
|
246
|
+
context 'that is of a known type' do
|
240
247
|
before do
|
241
|
-
stub_const 'MyNamespace::
|
248
|
+
stub_const 'MyNamespace::EmbeddedResource', abstract_resource
|
242
249
|
end
|
243
250
|
|
244
251
|
it 'instantiates the embedded resource' do
|
245
|
-
expect(subject.
|
252
|
+
expect(subject.embedded_resource).to be_an_instance_of MyNamespace::EmbeddedResource
|
246
253
|
end
|
247
254
|
end
|
248
255
|
|
249
|
-
context '
|
256
|
+
context 'that is of an unknown type' do
|
250
257
|
it 'instantiates a shim of the embedded resource' do
|
251
|
-
expect(subject.
|
258
|
+
expect(subject.embedded_resource).to be_an_instance_of OpenStruct
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'and test mode is enabled' do
|
262
|
+
before do
|
263
|
+
allow(abstract_resource).to receive(:test_mode?).and_return(true)
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'instantiates a shim of the embedded resource' do
|
267
|
+
expect(subject.embedded_resource).to be_an_instance_of OpenStruct
|
268
|
+
end
|
252
269
|
end
|
253
270
|
end
|
254
271
|
end
|
@@ -258,7 +275,7 @@ describe Frenetic::Resource do
|
|
258
275
|
let(:args) { { gender:'male' } }
|
259
276
|
|
260
277
|
it 'does not create accessors' do
|
261
|
-
expect{
|
278
|
+
expect{subject.gender}.to raise_error(NoMethodError)
|
262
279
|
end
|
263
280
|
|
264
281
|
it 'is accessible in @params' do
|
@@ -288,7 +305,7 @@ describe Frenetic::Resource do
|
|
288
305
|
subject { MyNamespace::MyTempResource.new(id:54, name:'me').attributes }
|
289
306
|
|
290
307
|
it 'returns attributes of the resource' do
|
291
|
-
expect(subject).to eq(
|
308
|
+
expect(subject).to eq('id' => 54, 'name' => 'me')
|
292
309
|
end
|
293
310
|
end
|
294
|
-
end
|
311
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
I18n.enforce_available_locales = false
|
data/spec/support/rspec.rb
CHANGED
data/spec/support/timecop.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'timecop'
|
1
|
+
require 'timecop'
|
data/spec/support/webmock.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frenetic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Lindahl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -171,8 +171,10 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".editorconfig"
|
174
175
|
- ".gitignore"
|
175
176
|
- ".irbrc"
|
177
|
+
- ".rubocop.yml"
|
176
178
|
- ".ruby-version"
|
177
179
|
- ".travis.yml"
|
178
180
|
- Appraisals
|
@@ -214,6 +216,7 @@ files:
|
|
214
216
|
- spec/resource_mockery_spec.rb
|
215
217
|
- spec/resource_spec.rb
|
216
218
|
- spec/spec_helper.rb
|
219
|
+
- spec/support/i18n.rb
|
217
220
|
- spec/support/rspec.rb
|
218
221
|
- spec/support/timecop.rb
|
219
222
|
- spec/support/webmock.rb
|
@@ -231,9 +234,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
234
|
version: 1.9.3
|
232
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
236
|
requirements:
|
234
|
-
- - "
|
237
|
+
- - ">="
|
235
238
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
239
|
+
version: '0'
|
237
240
|
requirements: []
|
238
241
|
rubyforge_project:
|
239
242
|
rubygems_version: 2.2.2
|
@@ -256,6 +259,7 @@ test_files:
|
|
256
259
|
- spec/resource_mockery_spec.rb
|
257
260
|
- spec/resource_spec.rb
|
258
261
|
- spec/spec_helper.rb
|
262
|
+
- spec/support/i18n.rb
|
259
263
|
- spec/support/rspec.rb
|
260
264
|
- spec/support/timecop.rb
|
261
265
|
- spec/support/webmock.rb
|