osm 1.2.18.dev.2 → 1.2.18.dev.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/osm/member.rb +20 -20
- data/spec/osm/member_spec.rb +56 -1
- data/spec/validity_validator_spec.rb +26 -0
- data/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDIwNmY3MDkyY2IxNWFkMmY5MGE2YTY1MjdhOTY3YjY2M2I2ZGYyMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjAyMWUwMGU4ZmQ1ODc3MmQ2MTQyN2RmZjA5OGE5NDNhZjk2NDE1ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGU5OGEyYzgyZDM3NDJmM2Y1ZjM3ZDk3MTdkZjg4Yzk4MGE1YzdlZDAzZmU2
|
10
|
+
MTBhNzMwNTUzMzYzMjdjNjcxNWJiOGJhMTEwZDlmYjUwMDY5OWE4NzE4ODcy
|
11
|
+
MGNkNzFlN2Q3NjUwM2M5ZmE5NmViMzdjOTM4NTA3NTlhN2RiMmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2FkMWEyODQxZDFmZWYzYWZiNDEyMDUwNTlkNjlhNGE5NTc5NDc0NTFiZjIw
|
14
|
+
YjkyMGE0MTRlNmU0ZjM1OWEwNzMwNjFhMjBhMmNmNzk5MWE2ZDVlMGJmZWI1
|
15
|
+
MGVhNTZhNGMyNmJiNGY5MGQ4NGZlOWUxMDYyYTFhNjFjN2ZlNjI=
|
data/lib/osm/member.rb
CHANGED
@@ -65,15 +65,15 @@ module Osm
|
|
65
65
|
# @!attribute [rw] custom_labels
|
66
66
|
# @return [DirtyHashy] the labels for the custom data (key is OSM's variable name, value is the label)
|
67
67
|
# @!attribute [rw] contact
|
68
|
-
# @return [Osm::Member::MemberContact] the member's contact details
|
68
|
+
# @return [Osm::Member::MemberContact, nil] the member's contact details (nil if hidden in OSM)
|
69
69
|
# @!attribute [rw] primary_contact
|
70
|
-
# @return [Osm::Member::PrimaryContact] the member's primary contact (primary contact 1 in OSM)
|
70
|
+
# @return [Osm::Member::PrimaryContact, nil] the member's primary contact (primary contact 1 in OSM) (nil if hidden in OSM)
|
71
71
|
# @!attribute [rw] secondary_contact
|
72
|
-
# @return [Osm::Member::PrimaryContact] the member's secondary contact (primary contact 2 in OSM)
|
72
|
+
# @return [Osm::Member::PrimaryContact, nil] the member's secondary contact (primary contact 2 in OSM) (nil if hidden in OSM)
|
73
73
|
# @!attribute [rw] emergency_contact
|
74
|
-
# @return [Osm::Member::EmergencyContact] the member's emergency contact
|
74
|
+
# @return [Osm::Member::EmergencyContact, nil] the member's emergency contact (nil if hidden in OSM)
|
75
75
|
# @!attribute [rw] doctor
|
76
|
-
# @return [Osm::Member::DoctorContact] the member's doctor
|
76
|
+
# @return [Osm::Member::DoctorContact, nil] the member's doctor (nil if hidden in OSM)
|
77
77
|
|
78
78
|
attribute :id, :type => Integer
|
79
79
|
attribute :section_id, :type => Integer
|
@@ -120,11 +120,11 @@ module Osm
|
|
120
120
|
validates_presence_of :joined_movement
|
121
121
|
validates_format_of :age, :with => /\A[0-9]{1,3} \/ (?:0?[0-9]|1[012])\Z/, :message => 'age is not in the correct format (yy / mm)', :allow_blank => true
|
122
122
|
validates_inclusion_of :gender, :in => [:male, :female, :other, :unspecified], :allow_nil => true
|
123
|
-
validates :contact, :validity=>true
|
124
|
-
validates :primary_contact, :validity=>true
|
125
|
-
validates :secondary_contact, :validity=>true
|
126
|
-
validates :emergency_contact, :validity=>true
|
127
|
-
validates :doctor, :validity=>true
|
123
|
+
validates :contact, :validity=>{allow_nil: true}
|
124
|
+
validates :primary_contact, :validity=>{allow_nil: true}
|
125
|
+
validates :secondary_contact, :validity=>{allow_nil: true}
|
126
|
+
validates :emergency_contact, :validity=>{allow_nil: true}
|
127
|
+
validates :doctor, :validity=>{allow_nil: true}
|
128
128
|
|
129
129
|
|
130
130
|
# Get members for a section
|
@@ -167,11 +167,11 @@ module Osm
|
|
167
167
|
|
168
168
|
data.each do |item|
|
169
169
|
item_data = Hash[ item['custom_data'].map{ |k,v| [k.to_i, v] } ]
|
170
|
-
member_contact = Hash[ item_data[GID_MEMBER_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
171
|
-
primary_contact = Hash[ item_data[GID_PRIMARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
172
|
-
secondary_contact = Hash[ item_data[GID_SECONDARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
173
|
-
emergency_contact = Hash[ item_data[GID_EMERGENCY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
174
|
-
doctor_contact = Hash[ item_data[GID_DOCTOR_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
170
|
+
member_contact = item_data[GID_MEMBER_CONTACT].nil? ? nil : Hash[ item_data[GID_MEMBER_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
171
|
+
primary_contact = item_data[GID_PRIMARY_CONTACT].nil? ? nil : Hash[ item_data[GID_PRIMARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
172
|
+
secondary_contact = item_data[GID_SECONDARY_CONTACT].nil? ? nil : Hash[ item_data[GID_SECONDARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
173
|
+
emergency_contact = item_data[GID_EMERGENCY_CONTACT].nil? ? nil : Hash[ item_data[GID_EMERGENCY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
174
|
+
doctor_contact = item_data[GID_DOCTOR_CONTACT].nil? ? nil : Hash[ item_data[GID_DOCTOR_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
175
175
|
floating_data = Hash[ item_data[GID_FLOATING].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] < CUSTOM_FIELD_IDS_START_AT } ]
|
176
176
|
|
177
177
|
result.push Osm::Member.new(
|
@@ -189,7 +189,7 @@ module Osm
|
|
189
189
|
:finished_section => Osm::parse_date(item['end_date']),
|
190
190
|
:joined_movement => Osm::parse_date(item['started']),
|
191
191
|
:gender => {'male'=>:male, 'female'=>:female, 'other'=>:other, 'unspecified'=>:unspecified}[(floating_data[CID_GENDER] || '').downcase],
|
192
|
-
:contact => MemberContact.new(
|
192
|
+
:contact => member_contact.nil? ? nil : MemberContact.new(
|
193
193
|
first_name: item['first_name'],
|
194
194
|
last_name: item['last_name'],
|
195
195
|
address_1: member_contact[CID_ADDRESS_1],
|
@@ -208,7 +208,7 @@ module Osm
|
|
208
208
|
custom: DirtyHashy[ item_data[GID_MEMBER_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] > CORE_FIELD_IDS_FINISH_AT } ],
|
209
209
|
custom_labels: custom_labels[GID_MEMBER_CONTACT] || DirtyHashy.new,
|
210
210
|
),
|
211
|
-
:primary_contact => PrimaryContact.new(
|
211
|
+
:primary_contact => primary_contact.nil? ? nil : PrimaryContact.new(
|
212
212
|
first_name: primary_contact[CID_FIRST_NAME],
|
213
213
|
last_name: primary_contact[CID_LAST_NAME],
|
214
214
|
address_1: primary_contact[CID_ADDRESS_1],
|
@@ -227,7 +227,7 @@ module Osm
|
|
227
227
|
custom: DirtyHashy[ item_data[GID_PRIMARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] > CORE_FIELD_IDS_FINISH_AT } ],
|
228
228
|
custom_labels: custom_labels[GID_PRIMARY_CONTACT] || DirtyHashy.new,
|
229
229
|
),
|
230
|
-
:secondary_contact => PrimaryContact.new(
|
230
|
+
:secondary_contact => secondary_contact.nil? ? nil : PrimaryContact.new(
|
231
231
|
first_name: secondary_contact[CID_FIRST_NAME],
|
232
232
|
last_name: secondary_contact[CID_LAST_NAME],
|
233
233
|
address_1: secondary_contact[CID_ADDRESS_1],
|
@@ -246,7 +246,7 @@ module Osm
|
|
246
246
|
custom: DirtyHashy[ item_data[GID_SECONDARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] > CORE_FIELD_IDS_FINISH_AT } ],
|
247
247
|
custom_labels: custom_labels[GID_SECONDARY_CONTACT] || DirtyHashy.new,
|
248
248
|
),
|
249
|
-
:emergency_contact => EmergencyContact.new(
|
249
|
+
:emergency_contact => emergency_contact.nil? ? nil : EmergencyContact.new(
|
250
250
|
first_name: emergency_contact[CID_FIRST_NAME],
|
251
251
|
last_name: emergency_contact[CID_LAST_NAME],
|
252
252
|
address_1: emergency_contact[CID_ADDRESS_1],
|
@@ -261,7 +261,7 @@ module Osm
|
|
261
261
|
custom: DirtyHashy[ item_data[GID_EMERGENCY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |i| i[0] > CORE_FIELD_IDS_FINISH_AT } ],
|
262
262
|
custom_labels: custom_labels[GID_EMERGENCY_CONTACT] || DirtyHashy.new,
|
263
263
|
),
|
264
|
-
:doctor => DoctorContact.new(
|
264
|
+
:doctor => doctor_contact.nil? ? nil : DoctorContact.new(
|
265
265
|
first_name: doctor_contact[CID_FIRST_NAME],
|
266
266
|
last_name: doctor_contact[CID_LAST_NAME],
|
267
267
|
surgery: doctor_contact[CID_SURGERY],
|
data/spec/osm/member_spec.rb
CHANGED
@@ -103,6 +103,7 @@ describe "Member" do
|
|
103
103
|
Osm::Member.new(gender: nil).female?.should == false
|
104
104
|
end
|
105
105
|
|
106
|
+
|
106
107
|
describe "Tells if the member is currently in the section" do
|
107
108
|
it "Today" do
|
108
109
|
Osm::Member.new(started_section: Date.yesterday).current?.should == true
|
@@ -149,7 +150,7 @@ describe "Member" do
|
|
149
150
|
'error' => nil,
|
150
151
|
'data' => {
|
151
152
|
'123' => {
|
152
|
-
'
|
153
|
+
'active' => true,
|
153
154
|
'age' => '12 / 00',
|
154
155
|
'date_of_birth' => '2000-03-08',
|
155
156
|
'end_date' => '2010-06-03',
|
@@ -357,6 +358,60 @@ describe "Member" do
|
|
357
358
|
member.valid?.should == true
|
358
359
|
end
|
359
360
|
|
361
|
+
it "Get from OSM (handles disabled contacts)" do
|
362
|
+
body = {
|
363
|
+
'status' => true,
|
364
|
+
'error' => nil,
|
365
|
+
'data' => {
|
366
|
+
'123' => {
|
367
|
+
'active' => true,
|
368
|
+
'age' => '12 / 00',
|
369
|
+
'date_of_birth' => '2000-03-08',
|
370
|
+
'end_date' => '2010-06-03',
|
371
|
+
'first_name' => 'John',
|
372
|
+
'joined' => '2008-07-12',
|
373
|
+
'last_name' => 'Smith',
|
374
|
+
'member_id' => 123,
|
375
|
+
'patrol' => 'Leaders',
|
376
|
+
'patrol_id' => -2,
|
377
|
+
'patrol_role_level' => 1,
|
378
|
+
'patrol_role_level_label' => 'Assistant leader',
|
379
|
+
'section_id' => 1,
|
380
|
+
'started' => '2006-07-17',
|
381
|
+
'custom_data' => {
|
382
|
+
'5' => {'4848' => 'Data for 4848'},
|
383
|
+
'7' => {'34' => 'Unspecified'},
|
384
|
+
},
|
385
|
+
}
|
386
|
+
},
|
387
|
+
'meta' => {
|
388
|
+
'leader_count' => 20,
|
389
|
+
'member_count' => 30,
|
390
|
+
'status' => true,
|
391
|
+
'structure' => [
|
392
|
+
{'group_id' => 5, 'description' => 'This allows you to add extra information for your members.', 'identifier' => 'customisable_data', 'name' => 'Customisable Data', 'columns' => [
|
393
|
+
{'column_id' => 4848, 'group_column_id' => '5_4848', 'label' => 'Label for 4848', 'varname' => 'label_for_4848', 'read_only' => 'no', 'required' => 'no', 'type' => 'text', 'width' => 120},
|
394
|
+
]},
|
395
|
+
{'group_id' => 7, 'description' => '', 'identifier' => 'floating', 'name' => 'Floating', 'columns' => [
|
396
|
+
{'column_id' => 34, 'group_column_id' => '7_34', 'label' => 'Gender', 'varname' => 'gender', 'read_only' => 'no', 'required' => 'no', 'type' => 'text', 'width' => 120},
|
397
|
+
]},
|
398
|
+
],
|
399
|
+
},
|
400
|
+
}
|
401
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/ext/members/contact/grid/?action=getMembers", :body => body.to_json, :content_type => 'application/json')
|
402
|
+
|
403
|
+
members = Osm::Member.get_for_section(@api, 1, 2)
|
404
|
+
members.size.should == 1
|
405
|
+
member = members[0]
|
406
|
+
member.id.should == 123
|
407
|
+
member.contact.should == nil
|
408
|
+
member.primary_contact.should == nil
|
409
|
+
member.secondary_contact.should == nil
|
410
|
+
member.emergency_contact.should == nil
|
411
|
+
member.doctor.should == nil
|
412
|
+
member.valid?.should == true
|
413
|
+
end
|
414
|
+
|
360
415
|
it "Get from OSM (handles an empty data array)" do
|
361
416
|
body = {
|
362
417
|
'status' => true,
|
@@ -13,6 +13,16 @@ class TestModel
|
|
13
13
|
attribute :item
|
14
14
|
validates :item, :validity => true
|
15
15
|
end
|
16
|
+
class TestModelAllowNil
|
17
|
+
include ActiveAttr::Model
|
18
|
+
attribute :item
|
19
|
+
validates :item, :validity => {allow_nil: true}
|
20
|
+
end
|
21
|
+
class TestModelDisallowNil
|
22
|
+
include ActiveAttr::Model
|
23
|
+
attribute :item
|
24
|
+
validates :item, :validity => {allow_nil: false}
|
25
|
+
end
|
16
26
|
|
17
27
|
describe "validity validator" do
|
18
28
|
|
@@ -29,4 +39,20 @@ describe "validity validator" do
|
|
29
39
|
model.errors.messages.should == {:item => ['must be valid', 'validity attribute is invalid: is not included in the list']}
|
30
40
|
end
|
31
41
|
|
42
|
+
describe "Allow nil" do
|
43
|
+
|
44
|
+
it "Is true" do
|
45
|
+
TestModelAllowNil.new(item: TestItem.new(validity: true)).valid?.should == true
|
46
|
+
TestModelAllowNil.new(item: TestItem.new(validity: false)).valid?.should == false
|
47
|
+
TestModelAllowNil.new(item: nil).valid?.should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "Is false" do
|
51
|
+
TestModelDisallowNil.new(item: TestItem.new(validity: true)).valid?.should == true
|
52
|
+
TestModelDisallowNil.new(item: TestItem.new(validity: false)).valid?.should == false
|
53
|
+
TestModelDisallowNil.new(item: nil).valid?.should == false
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
32
58
|
end
|
data/version.rb
CHANGED