roqua-core-api 0.0.25 → 0.0.26
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 +4 -4
- data/ChangeLog.md +4 -0
- data/README.md +4 -1
- data/lib/roqua/core_api/models/active_virtus.rb +43 -0
- data/lib/roqua/core_api/models/person.rb +1 -12
- data/lib/roqua/core_api/models.rb +1 -0
- data/lib/roqua/core_api/version.rb +1 -1
- data/spec/lib/roqua/core_api/models/active_virtus_spec.rb +35 -0
- data/spec/spec_helper.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 601eda66c40f7460205cf7cb85a05fbe36845a14
|
4
|
+
data.tar.gz: 79814be6c1ceb439979413e512732ab2b8bebac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2887a4630ec97c1bab5b1334642fedd9ca86c39c2723ae7cdb86b23b63d55e2da46d63a03f31ad697fcb871681d778beb9a36dbbf68a91ae975c214f961409b
|
7
|
+
data.tar.gz: 4b2ddc7d569abc704bcf899c4d2f3ca21c2e93b4f62a44e28d15e7c12f87b542fa5e8abfad236265fc6f18412179d2ba966d310e97d177ed283f7b9895572b09
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,10 @@ TODO: Description
|
|
23
23
|
|
24
24
|
### Translations
|
25
25
|
|
26
|
-
Make sure you have the standard active validations translations (errors.messages) and add to it a translations for
|
26
|
+
Make sure you have the standard active validations translations (errors.messages) and add to it a translations for:
|
27
|
+
|
28
|
+
* errors.messages.invalid_email
|
29
|
+
* errors.messages.invalid_date
|
27
30
|
|
28
31
|
## Copyright
|
29
32
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
class Roqua::CoreApi::Models::ActiveVirtus
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
extend ActiveModel::Translation
|
6
|
+
include ActiveModel::Validations
|
7
|
+
include ActiveModel::Conversion
|
8
|
+
include ActiveModel::Serialization
|
9
|
+
include Virtus.model
|
10
|
+
|
11
|
+
def attributes=(params)
|
12
|
+
set_rails_dates(params)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def assign_attributes(params = {})
|
17
|
+
self.attributes = params
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# set Date and DateTime attributes by "name(1i)" style params
|
23
|
+
def set_rails_dates(params)
|
24
|
+
self.class.attribute_set.select do |a|
|
25
|
+
a.type.primitive <= Date && params.has_key?("#{a.name}(1i)")
|
26
|
+
end.each do |a|
|
27
|
+
set_date(a.name, params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_date(attribute, params)
|
32
|
+
self[attribute] = {
|
33
|
+
year: params.fetch("#{attribute}(1i)"),
|
34
|
+
month: params.fetch("#{attribute}(2i)", 1),
|
35
|
+
day: params.fetch("#{attribute}(3i)", 1),
|
36
|
+
hour: params.fetch("#{attribute}(4i)", 0),
|
37
|
+
min: params.fetch("#{attribute}(5i)", 0),
|
38
|
+
sec: params.fetch("#{attribute}(6i)", 0)
|
39
|
+
}
|
40
|
+
rescue
|
41
|
+
errors.add(attribute, I18n.t("errors.messages.invalid_date"))
|
42
|
+
end
|
43
|
+
end
|
@@ -1,13 +1,6 @@
|
|
1
1
|
require 'virtus'
|
2
2
|
|
3
|
-
class Roqua::CoreApi::Models::Person
|
4
|
-
extend ActiveModel::Naming
|
5
|
-
extend ActiveModel::Translation
|
6
|
-
include ActiveModel::Validations
|
7
|
-
include ActiveModel::Conversion
|
8
|
-
include ActiveModel::Serialization
|
9
|
-
include Virtus.model
|
10
|
-
|
3
|
+
class Roqua::CoreApi::Models::Person < Roqua::CoreApi::Models::ActiveVirtus
|
11
4
|
attribute :id, String
|
12
5
|
attribute :role, String
|
13
6
|
attribute :firstname, String
|
@@ -28,10 +21,6 @@ class Roqua::CoreApi::Models::Person
|
|
28
21
|
|
29
22
|
validates :role, inclusion: { in: %w( professional patient parent ) }
|
30
23
|
|
31
|
-
def assign_attributes(params = {})
|
32
|
-
self.attributes = params
|
33
|
-
end
|
34
|
-
|
35
24
|
def persisted?
|
36
25
|
id.present?
|
37
26
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Roqua
|
4
|
+
module CoreApi
|
5
|
+
module Models
|
6
|
+
describe ActiveVirtus do
|
7
|
+
class Foo < ActiveVirtus
|
8
|
+
attribute :datetime, DateTime
|
9
|
+
attribute :date, Date
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { Foo.new }
|
13
|
+
|
14
|
+
describe 'Date' do
|
15
|
+
it 'can be set by date(i1) params' do
|
16
|
+
subject.attributes = { 'date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '8'}
|
17
|
+
expect(subject.date).to eq Date.new(1999, 12, 8)
|
18
|
+
end
|
19
|
+
it 'sets an error if the date is invalid' do
|
20
|
+
subject.attributes = { 'date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '32'}
|
21
|
+
expect(subject.errors[:date][0]).to match 'invalid_date'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'DateTime' do
|
26
|
+
it 'can be set by datetime(i1) params' do
|
27
|
+
subject.attributes = { 'datetime(1i)' => '1999', 'datetime(2i)' => '12', 'datetime(3i)' => '8',
|
28
|
+
'datetime(4i)' => '22', 'datetime(5i)' => '23', 'datetime(6i)' => '24'}
|
29
|
+
expect(subject.datetime).to eq DateTime.new(1999, 12, 8, 22, 23, 24)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.0.26
|
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-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/roqua/core_api/create_dossier_group.rb
|
188
188
|
- lib/roqua/core_api/dossiers.rb
|
189
189
|
- lib/roqua/core_api/models.rb
|
190
|
+
- lib/roqua/core_api/models/active_virtus.rb
|
190
191
|
- lib/roqua/core_api/models/dossier.rb
|
191
192
|
- lib/roqua/core_api/models/dossier_group.rb
|
192
193
|
- lib/roqua/core_api/models/person.rb
|
@@ -208,6 +209,7 @@ files:
|
|
208
209
|
- spec/fabricators/oauth_session_fabricator.rb
|
209
210
|
- spec/lib/roqua/core_api/create_dossier_group_spec.rb
|
210
211
|
- spec/lib/roqua/core_api/create_dossier_spec.rb
|
212
|
+
- spec/lib/roqua/core_api/models/active_virtus_spec.rb
|
211
213
|
- spec/lib/roqua/core_api/models/person_spec.rb
|
212
214
|
- spec/lib/roqua/core_api/send_email_to_spec.rb
|
213
215
|
- spec/lib/roqua/core_api/send_invite_email_spec.rb
|
@@ -246,6 +248,7 @@ test_files:
|
|
246
248
|
- spec/fabricators/oauth_session_fabricator.rb
|
247
249
|
- spec/lib/roqua/core_api/create_dossier_group_spec.rb
|
248
250
|
- spec/lib/roqua/core_api/create_dossier_spec.rb
|
251
|
+
- spec/lib/roqua/core_api/models/active_virtus_spec.rb
|
249
252
|
- spec/lib/roqua/core_api/models/person_spec.rb
|
250
253
|
- spec/lib/roqua/core_api/send_email_to_spec.rb
|
251
254
|
- spec/lib/roqua/core_api/send_invite_email_spec.rb
|