roqua-core-api 0.0.39 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cd38de53cdc42dbe949e24daf7c94b16cd67cb1
4
- data.tar.gz: e235d2508f48d15f974e0ca4fedd4c87727a631f
3
+ metadata.gz: 854a84f222ad107d7e8201a97f906fcac3f492bb
4
+ data.tar.gz: 2624aacd6d166cb8f3b3c4b38518f4500175421a
5
5
  SHA512:
6
- metadata.gz: e460c86c6f6513d47983a8241b656c09da14f1a0f67de636ccab77eab448761e2ae69f58c0b46aaa453eab435d9e39ab17e2b284e73b83e3b5d52d8f295104f2
7
- data.tar.gz: cc60593fd46d57fcf6904d534e9f960e413d5d56b434e5f7c09f8a889a7e6e67bd8a8a043477c3dc6e95bbe9c4ad5c9694721b4adfc6dbf7568a604f70053d43
6
+ metadata.gz: c2671c1a0bece7bb7a042398ed6c42edd558e84dcfa6fe4d495157404fbd0262358591b9e0d24d7057944b25fd959222ed8c552feb4636bee5e12771c7f5b390
7
+ data.tar.gz: e6d9331cf5c39ce4687ea78a129060e74bd69176650f333945feb2dfc5e325ed69448a2f30dcd6418d81438fc010bd7b524a916a1870292957f260ee6ddee1dd
data/ChangeLog.md CHANGED
@@ -1,10 +1,14 @@
1
+ ### 0.1.0
2
+
3
+ * BACKWARD INCOMPATIBLE: CreateDossier now needs a dossier and a person object.
4
+
1
5
  ### 0.0.39
2
6
 
3
- Handle empty rails date params
7
+ * Handle empty rails date params
4
8
 
5
9
  ### 0.0.37
6
10
 
7
- Handling new 422 json format in addition to old (temporary hack)
11
+ * Handling new 422 json format in addition to old (temporary hack)
8
12
 
9
13
  ### 0.0.36
10
14
 
@@ -9,8 +9,7 @@ module Roqua
9
9
  end
10
10
 
11
11
  def errors_to_object(response, obj)
12
- (response['errors'][obj.class.name.demodulize.underscore] ||
13
- response['errors']).each do |attribute, errors|
12
+ (response['errors'][obj.class.name.demodulize.underscore] || []).each do |attribute, errors|
14
13
  errors.each do |error|
15
14
  obj.errors.add(attribute.to_sym, error.to_sym)
16
15
  end
@@ -1,16 +1,33 @@
1
1
  module Roqua
2
2
  module CoreApi
3
3
  # @api private
4
- class CreateDossier < ActiveInteraction::Base
4
+ class CreateDossier < Base
5
5
  model :session, class: Sessions::AuthSession
6
6
  string :dossier_group_id
7
- hash :attributes, strip: false
7
+ model :dossier, class: Models::Dossier, default: nil
8
+ model :person, class: Models::Person, default: nil
8
9
 
9
10
  def execute
10
11
  response = session.post "/dossier_groups/#{dossier_group_id}/dossiers",
11
- person: attributes.delete(:person), dossier: attributes
12
+ person: person_attributes, dossier: dossier_attributes
13
+ if response.code == 422
14
+ errors_to_object(response, person)
15
+ errors_to_object(response, dossier)
16
+ end
12
17
  Models::Dossier.new(response)
13
18
  end
19
+
20
+ private
21
+
22
+ def dossier_attributes
23
+ return {} unless dossier
24
+ dossier.serializable_hash(except: :people).keep_if { |_k, v| !v.nil? }
25
+ end
26
+
27
+ def person_attributes
28
+ return {} unless person
29
+ person.serializable_hash.keep_if { |_k, v| !v.nil? }
30
+ end
14
31
  end
15
32
  end
16
33
  end
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module CoreApi
3
- VERSION = '0.0.39'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -23,5 +23,10 @@ module Roqua
23
23
  # Raised when a request failed due to an expired/non-existant session.
24
24
  class NoSession < StandardError; end
25
25
  class Unauthorized < StandardError; end
26
+
27
+ def self.load_fabricators
28
+ gem_root = Gem::Specification.find_by_name("roqua-core-api").gem_dir
29
+ Fabrication::Config.path_prefixes << gem_root unless Fabrication::Config.path_prefixes.include? gem_root
30
+ end
26
31
  end
27
32
  end
@@ -1,3 +1,3 @@
1
- Fabricator(:auth_session, from: Roqua::CoreApi::Sessions::AuthSession) do
1
+ Fabricator(:roqua_core_api_auth_session, from: Roqua::CoreApi::Sessions::AuthSession) do
2
2
  initialize_with { Roqua::CoreApi::Sessions::AuthSession.new core_site: 'http://core.dev' }
3
3
  end
@@ -1,4 +1,4 @@
1
- Fabricator(:basic_auth_session, from: Roqua::CoreApi::Sessions::BasicAuthSession) do
1
+ Fabricator(:roqua_core_api_basic_auth_session, from: Roqua::CoreApi::Sessions::BasicAuthSession) do
2
2
  initialize_with do
3
3
  Roqua::CoreApi::Sessions::BasicAuthSession.new username: 'some_username',
4
4
  password: 'some_password',
@@ -1,6 +1,5 @@
1
- Fabricator(:dossier, from: Roqua::CoreApi::Models::Dossier) do
2
- initialize_with do
3
- Roqua::CoreApi::Models::Dossier.new id: 'dossier-id',
4
- external_identifier: 'external-dossier-identifier'
5
- end
1
+ Fabricator(:roqua_core_api_dossier, from: Roqua::CoreApi::Models::Dossier) do
2
+ initialize_with { Roqua::CoreApi::Models::Dossier.new }
3
+ id 'dossier-id'
4
+ external_identifier 'external-dossier-identifier'
6
5
  end
@@ -1,4 +1,4 @@
1
- Fabricator(:oauth_session, from: Roqua::CoreApi::Sessions::OAuthSession) do
1
+ Fabricator(:roqua_core_api_oauth_session, from: Roqua::CoreApi::Sessions::OAuthSession) do
2
2
  initialize_with do
3
3
  Roqua::CoreApi::Sessions::OAuthSession.new access_token: 'some_access_token', core_site: 'http://core.dev'
4
4
  end
@@ -0,0 +1,7 @@
1
+ Fabricator(:roqua_core_api_person, from: Roqua::CoreApi::Models::Dossier) do
2
+ initialize_with { Roqua::CoreApi::Models::Person.new }
3
+ firstname 'John'
4
+ lastname 'Doe'
5
+ role 'patient'
6
+ email { sequence(:email) { |i| "test#{i}@roqua.nl" } }
7
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CreateDossierGroup do
4
- let(:session) { Fabricate :oauth_session }
4
+ let(:session) { Fabricate :roqua_core_api_oauth_session }
5
5
 
6
6
  it 'performs a post on the /dossier_groups api path' do
7
7
  expect(session).to receive(:post).with('/dossier_groups', dossier_group: {some: 'attributes'},
@@ -1,24 +1,68 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CreateDossier do
4
- let(:session) { Fabricate :oauth_session }
4
+ let(:session) { Fabricate :roqua_core_api_oauth_session }
5
+ let(:person) { Fabricate :roqua_core_api_person, id: nil }
6
+ let(:dossier) { Fabricate :roqua_core_api_dossier, id: nil }
7
+ let(:response) { httparty_response('id' => 'some_id') }
5
8
 
6
9
  it 'performs a post on the /dossiers api path' do
7
- expect(session).to receive(:post).with '/dossier_groups/some_dossier_group_id/dossiers',
8
- person: 'person', dossier: {other: 'attributes'}
10
+ expect(session).to receive(:post) do |path, options|
11
+ expect(path).to eq '/dossier_groups/some_dossier_group_id/dossiers'
12
+ expect(options[:person][:firstname]).to eq 'John'
13
+ expect(options[:dossier][:external_identifier]).to eq 'external-dossier-identifier'
14
+ end.and_return(response)
15
+
16
+ CreateDossier.run!(session: session,
17
+ person: person,
18
+ dossier: dossier,
19
+ dossier_group_id: 'some_dossier_group_id')
20
+ end
21
+
22
+ it 'works without dossier params' do
23
+ expect(session).to receive(:post) do |path, options|
24
+ expect(path).to eq '/dossier_groups/some_dossier_group_id/dossiers'
25
+ expect(options[:person][:firstname]).to eq 'John'
26
+ end.and_return(response)
27
+
28
+ CreateDossier.run!(session: session,
29
+ person: person,
30
+ dossier_group_id: 'some_dossier_group_id')
31
+ end
32
+
33
+ it 'works without person params' do
34
+ expect(session).to receive(:post) do |path, options|
35
+ expect(path).to eq '/dossier_groups/some_dossier_group_id/dossiers'
36
+ end.and_return(response)
37
+
9
38
  CreateDossier.run!(session: session,
10
- attributes: {person: 'person', other: 'attributes'},
11
39
  dossier_group_id: 'some_dossier_group_id')
12
40
  end
13
41
 
14
42
  it 'returns a Dossier model' do
15
- allow(session).to receive(:post).with('/dossier_groups/some_dossier_group_id/dossiers',
16
- person: 'person', dossier: {other: 'attributes'})
17
- .and_return 'id' => 'some_id'
18
- dossier = CreateDossier.run!(session: session,
19
- attributes: {person: 'person', other: 'attributes'},
20
- dossier_group_id: 'some_dossier_group_id')
21
- expect(dossier).to be_a(Dossier)
22
- expect(dossier.id).to eq('some_id')
43
+ allow(session).to receive(:post).and_return(response)
44
+ new_dossier = CreateDossier.run!(session: session,
45
+ person: person,
46
+ dossier: dossier,
47
+ dossier_group_id: 'some_dossier_group_id')
48
+ expect(new_dossier).to be_a(Dossier)
49
+ expect(new_dossier.id).to eq('some_id')
50
+ end
51
+
52
+ describe 'with validation errors' do
53
+ let(:response) { httparty_response({'errors' => {'person' => {'email' => ['invalid_email']},
54
+ 'dossier' => {'external_identifier' => ['blank']}}},
55
+ 422) }
56
+
57
+ it 'Set the errors on the objects' do
58
+ allow(session).to receive(:post).and_return(response)
59
+ new_dossier = CreateDossier.run!(session: session,
60
+ person: person,
61
+ dossier: dossier,
62
+ dossier_group_id: 'some_dossier_group_id')
63
+ expect(new_dossier.persisted?).to be_falsy
64
+ expect(person.errors[:email]).to eq ['Geen geldig email adres']
65
+ expect(dossier.errors[:external_identifier]).to eq ['moet opgegeven zijn']
66
+ end
23
67
  end
24
68
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dossiers do
4
- let(:session) { Fabricate :oauth_session }
4
+ let(:session) { Fabricate :roqua_core_api_oauth_session }
5
5
  let(:dossier_group_id) { 'some_dg_id' }
6
6
  let(:external_identifier) { 'some_eid' }
7
7
  let(:response) { {'headers' => %w(id birth_year gender firstname lastname),
@@ -19,7 +19,7 @@ module Roqua
19
19
  end
20
20
  it 'sets an error if the date is invalid' do
21
21
  subject.attributes = { 'date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '32'}
22
- expect(subject.errors[:date][0]).to match 'invalid_date'
22
+ expect(subject.errors[:date][0]).to match 'Niet een bestaande datum'
23
23
  end
24
24
  it 'can create new with date(i1) params' do
25
25
  foo = Foo.new('date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '8')
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SendInviteEmail do
4
- let(:session) { Fabricate :oauth_session }
4
+ let(:session) { Fabricate :roqua_core_api_oauth_session }
5
5
 
6
6
  it 'performs a post on the send_invite_email api path' do
7
7
  expect(session).to receive(:post).with '/dossiers/some_dossier_id/send_invite_email',
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'webmock/rspec'
3
3
 
4
4
  describe AuthSession do
5
- let(:session) { Fabricate :auth_session }
5
+ let(:session) { Fabricate :roqua_core_api_auth_session }
6
6
  let(:response) { double('response', code: 201, parsed_response: 'some_response') }
7
7
 
8
8
  describe '#initialize' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'webmock/rspec'
3
3
 
4
4
  describe OAuthSession do
5
- let(:session) { Fabricate :oauth_session }
5
+ let(:session) { Fabricate :roqua_core_api_oauth_session }
6
6
  let(:response) { double('response', code: 201, parsed_response: 'some_response') }
7
7
 
8
8
  describe '#initialize' do
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe UpdateDossier do
4
- let(:session) { Fabricate :oauth_session }
5
- let(:dossier) { Fabricate :dossier }
4
+ let(:session) { Fabricate :roqua_core_api_oauth_session }
5
+ let(:dossier) { Fabricate :roqua_core_api_dossier }
6
6
  let(:response) { double }
7
7
 
8
8
  before do
@@ -28,7 +28,7 @@ describe UpdateDossier do
28
28
  end
29
29
 
30
30
  describe 'returns false when the call was incorrect' do
31
- let(:error) { { 'id' => ['empty'] } }
31
+ let(:error) { {'dossier' => { 'id' => ['empty']}} }
32
32
  before do
33
33
  allow(response).to receive(:[]).with('errors').and_return(error)
34
34
 
@@ -43,7 +43,7 @@ describe UpdateDossier do
43
43
 
44
44
  it 'should add the errors to the dossier' do
45
45
  expect(dossier.errors).to_not be_empty
46
- expect(dossier.errors['id'][0]).to match(error['id'][0])
46
+ expect(dossier.errors[:id][0]).to eq 'moet opgegeven zijn'
47
47
  end
48
48
  end
49
49
  end
data/spec/spec_helper.rb CHANGED
@@ -9,4 +9,8 @@ include Roqua::CoreApi
9
9
  include Roqua::CoreApi::Sessions
10
10
  include Roqua::CoreApi::Models
11
11
 
12
+ Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'support', '*.rb')].each { |f| require f }
13
+
14
+ I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__)), '..', 'config', 'locales', '*.yml')]
15
+ I18n.enforce_available_locales = false
12
16
  I18n.default_locale = :nl
@@ -0,0 +1,5 @@
1
+ def httparty_response(response_data, code = 200)
2
+ allow(response_data).to receive(:code).and_return code
3
+ allow(response_data).to receive(:parsed_response).and_return response_data
4
+ response_data
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-core-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -218,6 +218,7 @@ files:
218
218
  - spec/fabricators/basic_auth_session_fabricator.rb
219
219
  - spec/fabricators/dossier_fabricator.rb
220
220
  - spec/fabricators/oauth_session_fabricator.rb
221
+ - spec/fabricators/person_fabricator.rb
221
222
  - spec/lib/roqua/core_api/create_dossier_group_spec.rb
222
223
  - spec/lib/roqua/core_api/create_dossier_spec.rb
223
224
  - spec/lib/roqua/core_api/dossiers_spec.rb
@@ -231,6 +232,7 @@ files:
231
232
  - spec/lib/roqua/core_api/sessions/oauth_session_spec.rb
232
233
  - spec/lib/roqua/core_api/update_dossier_spec.rb
233
234
  - spec/spec_helper.rb
235
+ - spec/support/httpparty_helpers.rb
234
236
  homepage: https://github.com/roqua/core/blob/master/core_api/README.markdown
235
237
  licenses:
236
238
  - MIT
@@ -251,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
253
  version: '0'
252
254
  requirements: []
253
255
  rubyforge_project:
254
- rubygems_version: 2.3.0
256
+ rubygems_version: 2.4.3
255
257
  signing_key:
256
258
  specification_version: 4
257
259
  summary: API wrapper gem around Core's API
@@ -261,6 +263,7 @@ test_files:
261
263
  - spec/fabricators/basic_auth_session_fabricator.rb
262
264
  - spec/fabricators/dossier_fabricator.rb
263
265
  - spec/fabricators/oauth_session_fabricator.rb
266
+ - spec/fabricators/person_fabricator.rb
264
267
  - spec/lib/roqua/core_api/create_dossier_group_spec.rb
265
268
  - spec/lib/roqua/core_api/create_dossier_spec.rb
266
269
  - spec/lib/roqua/core_api/dossiers_spec.rb
@@ -274,4 +277,5 @@ test_files:
274
277
  - spec/lib/roqua/core_api/sessions/oauth_session_spec.rb
275
278
  - spec/lib/roqua/core_api/update_dossier_spec.rb
276
279
  - spec/spec_helper.rb
280
+ - spec/support/httpparty_helpers.rb
277
281
  has_rdoc: