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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +16 -0
  3. data/.gitignore +1 -1
  4. data/.irbrc +1 -1
  5. data/.rubocop.yml +45 -0
  6. data/.travis.yml +2 -2
  7. data/Appraisals +1 -1
  8. data/LICENSE +1 -1
  9. data/README.md +15 -15
  10. data/Rakefile +1 -1
  11. data/gemfiles/faraday_08.gemfile.lock +8 -8
  12. data/gemfiles/faraday_09.gemfile.lock +8 -8
  13. data/lib/frenetic.rb +13 -10
  14. data/lib/frenetic/briefly_memoizable.rb +9 -7
  15. data/lib/frenetic/concerns/collection_rest_methods.rb +4 -5
  16. data/lib/frenetic/concerns/hal_linked.rb +12 -9
  17. data/lib/frenetic/concerns/member_rest_methods.rb +7 -10
  18. data/lib/frenetic/concerns/structured.rb +2 -2
  19. data/lib/frenetic/connection.rb +25 -17
  20. data/lib/frenetic/errors.rb +67 -2
  21. data/lib/frenetic/hypermedia_link.rb +19 -26
  22. data/lib/frenetic/hypermedia_link_set.rb +11 -14
  23. data/lib/frenetic/middleware/hal_json.rb +3 -4
  24. data/lib/frenetic/resource.rb +31 -25
  25. data/lib/frenetic/resource_collection.rb +3 -3
  26. data/lib/frenetic/resource_mockery.rb +7 -5
  27. data/lib/frenetic/version.rb +2 -2
  28. data/spec/briefly_memoizable_spec.rb +1 -1
  29. data/spec/concerns/hal_linked_spec.rb +5 -5
  30. data/spec/concerns/member_rest_methods_spec.rb +1 -1
  31. data/spec/concerns/structured_spec.rb +6 -5
  32. data/spec/connection_spec.rb +16 -4
  33. data/spec/fixtures/test_api_requests.rb +32 -28
  34. data/spec/frenetic_spec.rb +3 -3
  35. data/spec/hypermedia_link_set_spec.rb +3 -3
  36. data/spec/hypermedia_link_spec.rb +1 -1
  37. data/spec/middleware/hal_json_spec.rb +3 -3
  38. data/spec/resource_collection_spec.rb +3 -4
  39. data/spec/resource_mockery_spec.rb +29 -6
  40. data/spec/resource_spec.rb +30 -13
  41. data/spec/spec_helper.rb +1 -1
  42. data/spec/support/i18n.rb +1 -0
  43. data/spec/support/rspec.rb +1 -1
  44. data/spec/support/timecop.rb +1 -1
  45. data/spec/support/webmock.rb +1 -1
  46. metadata +8 -4
@@ -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::HypermediaError
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
- 'abstract_resource' => {
238
+ 'embedded_resource' => {
232
239
  'id' => 99,
233
240
  'genus' => 'canine'
234
241
  }
235
242
  }
236
- })
243
+ )
237
244
  end
238
245
 
239
- context 'this is of a known type' do
246
+ context 'that is of a known type' do
240
247
  before do
241
- stub_const 'MyNamespace::AbstractResource', abstract_resource
248
+ stub_const 'MyNamespace::EmbeddedResource', abstract_resource
242
249
  end
243
250
 
244
251
  it 'instantiates the embedded resource' do
245
- expect(subject.abstract_resource).to be_an_instance_of MyNamespace::AbstractResource
252
+ expect(subject.embedded_resource).to be_an_instance_of MyNamespace::EmbeddedResource
246
253
  end
247
254
  end
248
255
 
249
- context 'this is of a known type' do
256
+ context 'that is of an unknown type' do
250
257
  it 'instantiates a shim of the embedded resource' do
251
- expect(subject.abstract_resource).to be_an_instance_of OpenStruct
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{ subject.gender }.to raise_error NoMethodError
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({'id' => 54, 'name' => 'me'})
308
+ expect(subject).to eq('id' => 54, 'name' => 'me')
292
309
  end
293
310
  end
294
- end
311
+ end
@@ -6,4 +6,4 @@ require 'frenetic'
6
6
 
7
7
  # Requires supporting ruby files with custom matchers and macros, etc,
8
8
  # in spec/support/ and its subdirectories.
9
- Dir['./spec/support/**/*.rb'].each {|f| require f}
9
+ Dir['./spec/support/**/*.rb'].each { |f| require(f) }
@@ -0,0 +1 @@
1
+ I18n.enforce_available_locales = false
@@ -1,4 +1,4 @@
1
1
  RSpec.configure do |config|
2
2
  config.filter_run focus:true
3
3
  config.run_all_when_everything_filtered = true
4
- end
4
+ end
@@ -1 +1 @@
1
- require 'timecop'
1
+ require 'timecop'
@@ -1,3 +1,3 @@
1
1
  require 'webmock/rspec'
2
2
 
3
- Dir[File.expand_path('../../fixtures/*.rb', __FILE__)].each { |f| require f }
3
+ Dir[File.expand_path('../../fixtures/*.rb', __FILE__)].each { |f| require f }
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.alpha.1
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: 2014-09-23 00:00:00.000000000 Z
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: 1.3.1
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