lws 6.3.1 → 6.3.2
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 +9 -0
- data/lib/lws/apps/generic.rb +11 -0
- data/lib/lws/apps/presence.rb +116 -3
- data/lib/lws/version.rb +1 -1
- data/test/generic_test.rb +23 -0
- data/test/json_parser_test.rb +20 -0
- data/test/presence_test.rb +46 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6735eba2229b17c2690bddf74524980752e5deea2e893d65e2789be1138df2a3
|
4
|
+
data.tar.gz: b5e0914b8295744c2e5ee2670d44835962faf000ccc307c75b0ff8de6b80e141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82822f7f43fb6752b3f137fdad30be4e0a0f90e9084c22e5c3db6b6cbad70e49acf15772b2b3ae5f73e16037e134db3afa3bcd13956835089168219f76d4e9f
|
7
|
+
data.tar.gz: a3bbf82f1eb2c003bea92750544e4447b76949ca5cdff28730d7502e9826cb4d5cacb52299cbf4c2a88dae336fd48c6ccb769f1524fce7a9217cd8c5116b85df
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,14 @@ of LWS in the major/minor part of te version.
|
|
6
6
|
|
7
7
|
The changelog follows the [Keep a Changelog] format from version 6.3.0 on.
|
8
8
|
|
9
|
+
## [6.3.2] - 2019-09-26
|
10
|
+
### Added
|
11
|
+
* Expanded the models and attributes in the presence app (#12108)
|
12
|
+
* Added a `#dig` method for the generic/all models
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
* Fixed the reduced/dropped test coverage (#12107)
|
16
|
+
|
9
17
|
## [6.3.1] - 2019-09-05
|
10
18
|
### Changed
|
11
19
|
* Reworked the JSON parser to handle metadata better
|
@@ -151,3 +159,4 @@ Initial release
|
|
151
159
|
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
|
152
160
|
[6.3.0]: https://gitlab.leftclick.eu/platform/ruby-lws/compare/v6.2.3...v6.3.0
|
153
161
|
[6.3.1]: https://gitlab.leftclick.eu/platform/ruby-lws/compare/v6.3.0...v6.3.1
|
162
|
+
[6.3.1]: https://gitlab.leftclick.eu/platform/ruby-lws/compare/v6.3.1...v6.3.2
|
data/lib/lws/apps/generic.rb
CHANGED
@@ -150,6 +150,17 @@ module LWS::Generic
|
|
150
150
|
result
|
151
151
|
end
|
152
152
|
|
153
|
+
# Extracts a nested attribute vlaue specified by the sequence of attribute names
|
154
|
+
# by calling dig at each step, returning +nil+ if any intermediate step is +nil+.
|
155
|
+
def dig(*attrs)
|
156
|
+
attr = attrs.shift
|
157
|
+
value = send(attr)
|
158
|
+
return nil if value.nil?
|
159
|
+
return value if attrs.empty?
|
160
|
+
raise TypeError, "#{value.class} does not have #dig method" unless value.respond_to? :dig
|
161
|
+
value.dig(*attrs)
|
162
|
+
end
|
163
|
+
|
153
164
|
end
|
154
165
|
|
155
166
|
# = The configuration class
|
data/lib/lws/apps/presence.rb
CHANGED
@@ -35,6 +35,59 @@ module LWS::Presence
|
|
35
35
|
|
36
36
|
### App specific classes
|
37
37
|
|
38
|
+
# = The appointment class
|
39
|
+
#
|
40
|
+
# @note
|
41
|
+
# This class is only used within the context of either the {Location} or
|
42
|
+
# the {Person} class.
|
43
|
+
class Appointment < LWS::Generic::Model
|
44
|
+
use_api LWS::Presence.api
|
45
|
+
|
46
|
+
# @!attribute title
|
47
|
+
# @return [String] the title of the appointment
|
48
|
+
attribute :title
|
49
|
+
|
50
|
+
# @!attribute datetime_end
|
51
|
+
# @return [String] the timestamp of the end of the appointment
|
52
|
+
attribute :datetime_end
|
53
|
+
|
54
|
+
# @!attribute datetime_start
|
55
|
+
# @return [String] the timestamp of the start of the appointment
|
56
|
+
attribute :datetime_start
|
57
|
+
|
58
|
+
# @!attribute description
|
59
|
+
# @return [String] the description of the appointment
|
60
|
+
attribute :description
|
61
|
+
|
62
|
+
# @!attribute invite
|
63
|
+
# @return [String] the original invite body of the appointment
|
64
|
+
attribute :invite
|
65
|
+
|
66
|
+
# @!attribute location
|
67
|
+
# @return [Location] the location of the appointment
|
68
|
+
belongs_to :location, uri: "locations/:id"
|
69
|
+
|
70
|
+
# @!attribute location
|
71
|
+
# @return [Integer] the ID of the location of the appointment
|
72
|
+
attribute :location_id
|
73
|
+
|
74
|
+
# @!attribute organiser
|
75
|
+
# @return [Person] the origaniser of the appointment
|
76
|
+
belongs_to :organiser, class_name: "LWS::Presence::Person"
|
77
|
+
|
78
|
+
# @!attribute organiser_id
|
79
|
+
# @return [Fixnum] the ID of the origaniser of the appointment
|
80
|
+
attribute :organiser_id
|
81
|
+
|
82
|
+
# @!attribute people
|
83
|
+
# @return [Array<Person>] the people associated with the appointment
|
84
|
+
has_many :people
|
85
|
+
|
86
|
+
# @!attribute uuid
|
87
|
+
# @return [String] the UUID of the location
|
88
|
+
attribute :uuid
|
89
|
+
end
|
90
|
+
|
38
91
|
# = The location class
|
39
92
|
class Location < LWS::Generic::Model
|
40
93
|
use_api LWS::Presence.api
|
@@ -44,6 +97,10 @@ module LWS::Presence
|
|
44
97
|
# including the location itself
|
45
98
|
attribute :ancestor_ids
|
46
99
|
|
100
|
+
# @!attribute appointments
|
101
|
+
# @return [Array<Appointment>] the appointments taking place at the location
|
102
|
+
has_many :appointments
|
103
|
+
|
47
104
|
# @!attribute capacity
|
48
105
|
# @return [Integer] the capacity (maximum number of people) of the location
|
49
106
|
attribute :capacity
|
@@ -121,6 +178,16 @@ module LWS::Presence
|
|
121
178
|
# @return [String] the name of the location
|
122
179
|
attribute :name
|
123
180
|
|
181
|
+
# @!attribute owner
|
182
|
+
# @return [Person, nil] the owner of the location
|
183
|
+
belongs_to :owner, class_name: "LWS::Presence::Person",
|
184
|
+
foreign_key: "owner_id",
|
185
|
+
uri: "people/:id"
|
186
|
+
|
187
|
+
# @!attribute owner_id
|
188
|
+
# @return [Fixnum, nil] the ID of the owner of the location
|
189
|
+
attribute :owner_id
|
190
|
+
|
124
191
|
# @!attribute parent
|
125
192
|
# @return [Location] the parent of the location
|
126
193
|
belongs_to :parent, class_name: "LWS::Presence::Location",
|
@@ -147,6 +214,10 @@ module LWS::Presence
|
|
147
214
|
# @!attribute readers
|
148
215
|
# @return [Array<Reader>] the (RFID/code/ID/...) readers linked to this location
|
149
216
|
has_many :readers
|
217
|
+
|
218
|
+
# @!attribute uuid
|
219
|
+
# @return [String] the UUID of the location
|
220
|
+
attribute :uuid
|
150
221
|
end
|
151
222
|
|
152
223
|
# = The location map class
|
@@ -239,10 +310,45 @@ module LWS::Presence
|
|
239
310
|
attribute :y_pos
|
240
311
|
end
|
241
312
|
|
313
|
+
# = The notification class
|
314
|
+
#
|
315
|
+
# @note This model can only be created via LWS, never retrieved, deleted or updated.
|
316
|
+
class Notification < LWS::Generic::Model
|
317
|
+
use_api LWS::Presence.api
|
318
|
+
|
319
|
+
# @attribute location
|
320
|
+
# @return [Location] the location the notification is for
|
321
|
+
belongs_to :location, uri: "locations/:id"
|
322
|
+
|
323
|
+
# @attribute location_id
|
324
|
+
# @return [Fixnum] the ID of the location the notification is for
|
325
|
+
attribute :location_id
|
326
|
+
|
327
|
+
# @attribute receiver
|
328
|
+
# @return [Person] the receiver of the notification
|
329
|
+
belongs_to :receiver
|
330
|
+
|
331
|
+
# @attribute receiver_id
|
332
|
+
# @return [Integer] the ID of the receiver of the notification
|
333
|
+
belongs_to :receiver_id
|
334
|
+
|
335
|
+
# @attribute sender
|
336
|
+
# @return [Person] the sender of the notification
|
337
|
+
belongs_to :sender
|
338
|
+
|
339
|
+
# @attribute sender_id
|
340
|
+
# @return [Integer] the ID of the receiver of the nofication
|
341
|
+
belongs_to :sender_id
|
342
|
+
end
|
343
|
+
|
242
344
|
# = The person class
|
243
345
|
class Person < LWS::Generic::Model
|
244
346
|
use_api LWS::Presence.api
|
245
347
|
|
348
|
+
# @!attribute appointments
|
349
|
+
# @return [Array<Appointment>] the appointments involving the person
|
350
|
+
has_many :appointments
|
351
|
+
|
246
352
|
# @!attribute company
|
247
353
|
# @return [LWS::Auth::Company] the company the person belongs to
|
248
354
|
belongs_to :company, class_name: "LWS::Auth::Company"
|
@@ -269,9 +375,14 @@ module LWS::Presence
|
|
269
375
|
attribute :extra_info
|
270
376
|
|
271
377
|
# @!attribute import_ref
|
272
|
-
# @return [String, nil] reference for storing the uid of the remote
|
378
|
+
# @return [String, nil] reference for storing the uid of the remote
|
379
|
+
# database
|
273
380
|
attribute :import_ref
|
274
381
|
|
382
|
+
# @!attribute kind
|
383
|
+
# @return ["employee", "guest"] the person kind
|
384
|
+
attribute :kind
|
385
|
+
|
275
386
|
# @!attribute last_sync
|
276
387
|
# @return [String, nil] the last date/time the status was updated via a
|
277
388
|
# device or RFID tag
|
@@ -339,11 +450,13 @@ module LWS::Presence
|
|
339
450
|
attribute :udid
|
340
451
|
|
341
452
|
# @!attribute vehicle_registration_plate
|
342
|
-
# @return [String, nil] The vehicle registration plate of the persons
|
453
|
+
# @return [String, nil] The vehicle registration plate of the persons
|
454
|
+
# transport
|
343
455
|
attribute :vehicle_registration_plate
|
344
456
|
|
345
457
|
# @!attribute visibility
|
346
|
-
# @return ["public", "private"] if a person should be protected by not
|
458
|
+
# @return ["public", "private"] if a person should be protected by not
|
459
|
+
# showing critical information
|
347
460
|
attribute :visibility
|
348
461
|
end
|
349
462
|
|
data/lib/lws/version.rb
CHANGED
data/test/generic_test.rb
CHANGED
@@ -25,6 +25,12 @@ class TestGenericModel < MiniTest::Test
|
|
25
25
|
assert_equal("other_value", @configuration.value)
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_not_found
|
29
|
+
assert_raises LWS::Errors::ResourceNotFound do
|
30
|
+
Configuration.find("NOTEXIST")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
28
34
|
def test_lifecycle
|
29
35
|
# Create
|
30
36
|
new_configuration = Configuration.create(key: "test", value: "some_value")
|
@@ -88,6 +94,18 @@ class TestGenericModel < MiniTest::Test
|
|
88
94
|
assert_equal(true, result)
|
89
95
|
end
|
90
96
|
|
97
|
+
def test_dig
|
98
|
+
company = LWS::Auth::Company.find(1)
|
99
|
+
assert_equal(company.id, company.dig(:id))
|
100
|
+
|
101
|
+
assert_equal(company.contact_person.name, company.dig(:contact_person, :name))
|
102
|
+
assert_nil(company.dig(:parent, :name))
|
103
|
+
|
104
|
+
assert_raises(TypeError) do
|
105
|
+
company.dig(:id, :foo)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
91
109
|
end
|
92
110
|
|
93
111
|
class TestGenericConfiguration < MiniTest::Test
|
@@ -115,5 +133,10 @@ class TestGenericStorage < MiniTest::Test
|
|
115
133
|
def test_upload
|
116
134
|
data = StringIO.new("some file contents\n")
|
117
135
|
refute_nil(Storage.create(data, "test.txt", "text/plain"))
|
136
|
+
|
137
|
+
# Also test using the default HTTP adapter.
|
138
|
+
reconfigure(http_persistent: false)
|
139
|
+
data = StringIO.new("some more file contents\n")
|
140
|
+
refute_nil(Storage.create(data, "test2.txt", "text/plain"))
|
118
141
|
end
|
119
142
|
end
|
data/test/json_parser_test.rb
CHANGED
@@ -24,10 +24,16 @@ class TestJSONParser < MiniTest::Test
|
|
24
24
|
country: "NL",
|
25
25
|
# ...
|
26
26
|
} }
|
27
|
+
companies = [ { id: "correct",
|
28
|
+
country: "NL",
|
29
|
+
# ...
|
30
|
+
} ]
|
27
31
|
|
28
32
|
full_uri = LWS::Auth.api.url_prefix.dup
|
29
33
|
full_uri.path = "/companies/broken"
|
30
34
|
stub_request(:get, full_uri.to_s).to_return(body: "{}invalid json")
|
35
|
+
full_uri.path = "/companies/noobj"
|
36
|
+
stub_request(:get, full_uri.to_s).to_return(body: "\"str\"")
|
31
37
|
full_uri.path = "/companies/empty"
|
32
38
|
stub_request(:get, full_uri.to_s).to_return(body: "")
|
33
39
|
full_uri.path = "/companies/correct"
|
@@ -36,6 +42,8 @@ class TestJSONParser < MiniTest::Test
|
|
36
42
|
stub_request(:put, full_uri.to_s)
|
37
43
|
.to_return(body: MultiJson.dump(company.merge(errors: { contact_person_id: ["can't be blank"] })))
|
38
44
|
full_uri.path = "/companies"
|
45
|
+
stub_request(:get, full_uri.to_s)
|
46
|
+
.to_return(body: MultiJson.dump(companies))
|
39
47
|
stub_request(:post, full_uri.to_s)
|
40
48
|
.to_return(body: "", status: 204)
|
41
49
|
end
|
@@ -49,12 +57,24 @@ class TestJSONParser < MiniTest::Test
|
|
49
57
|
assert_raises LWS::Errors::InvalidResponse do
|
50
58
|
company = LWS::Auth::Company.find("broken")
|
51
59
|
end
|
60
|
+
|
61
|
+
assert_raises LWS::Errors::InvalidResponse do
|
62
|
+
company = LWS::Auth::Company.find("noobj")
|
63
|
+
end
|
64
|
+
|
65
|
+
assert_raises LWS::Errors::InvalidResponse do
|
66
|
+
company = LWS::Auth::Company.find("empty")
|
67
|
+
end
|
52
68
|
end
|
53
69
|
|
54
70
|
def test_correct_json
|
55
71
|
company = LWS::Auth::Company.find("correct")
|
56
72
|
assert_equal "correct", company.id
|
57
73
|
end
|
74
|
+
def test_correct_json_ary
|
75
|
+
companies = LWS::Auth::Company.all.to_a
|
76
|
+
assert_equal "correct", companies.first.id
|
77
|
+
end
|
58
78
|
|
59
79
|
def test_no_content_json
|
60
80
|
company = LWS::Auth::Company.create
|
data/test/presence_test.rb
CHANGED
@@ -11,12 +11,36 @@
|
|
11
11
|
|
12
12
|
require "test_helper"
|
13
13
|
|
14
|
+
class TestPresenceAppointment < MiniTest::Test
|
15
|
+
|
16
|
+
include LWS::Presence
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@location = Location.where(includes: "appointments.*").find(1)
|
20
|
+
@appointment = @location.appointments.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_valid
|
24
|
+
refute_nil(@appointment)
|
25
|
+
assert_instance_of(Appointment, @appointment)
|
26
|
+
refute_nil(@appointment.id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_valid_associations
|
30
|
+
assert_instance_of(Location, @appointment.location)
|
31
|
+
assert_equal(@location, @appointment.location)
|
32
|
+
assert_instance_of(Person, @appointment.organiser)
|
33
|
+
assert_instance_of(Person, @appointment.people.first)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
14
38
|
class TestPresenceLocation < MiniTest::Test
|
15
39
|
|
16
40
|
include LWS::Presence
|
17
41
|
|
18
42
|
def setup
|
19
|
-
@location = Location.find(1)
|
43
|
+
@location = Location.where(includes: "appointments.*").find(1)
|
20
44
|
end
|
21
45
|
|
22
46
|
def test_valid
|
@@ -26,9 +50,11 @@ class TestPresenceLocation < MiniTest::Test
|
|
26
50
|
end
|
27
51
|
|
28
52
|
def test_valid_associations
|
53
|
+
assert_instance_of(Appointment, @location.appointments.first)
|
29
54
|
assert_instance_of(LWS::Auth::Company, @location.company)
|
30
55
|
assert_instance_of(Location::Map::Position, @location.map_positions.first)
|
31
56
|
assert_instance_of(Location::Map, @location.maps.first)
|
57
|
+
assert_instance_of(Person, @location.owner)
|
32
58
|
assert_instance_of(Person, @location.people.first)
|
33
59
|
assert_instance_of(Reader, @location.readers.first)
|
34
60
|
loc = Location.where(includes: "people_tree").find(1)
|
@@ -92,12 +118,29 @@ class TestPresenceLocationMapPosition < MiniTest::Test
|
|
92
118
|
end
|
93
119
|
|
94
120
|
end
|
121
|
+
|
122
|
+
class TestPresenceNotification < MiniTest::Test
|
123
|
+
|
124
|
+
include LWS::Presence
|
125
|
+
|
126
|
+
def setup
|
127
|
+
@notification = Notification.create(location_id: 1,
|
128
|
+
receiver_id: 1,
|
129
|
+
sender_id: 1)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_valid
|
133
|
+
refute_nil(@notification)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
95
138
|
class TestPresencePerson < MiniTest::Test
|
96
139
|
|
97
140
|
include LWS::Presence
|
98
141
|
|
99
142
|
def setup
|
100
|
-
@person = Person.find(1)
|
143
|
+
@person = Person.where(includes: "appointments.*").find(1)
|
101
144
|
end
|
102
145
|
|
103
146
|
def test_valid
|
@@ -107,6 +150,7 @@ class TestPresencePerson < MiniTest::Test
|
|
107
150
|
end
|
108
151
|
|
109
152
|
def test_valid_associations
|
153
|
+
assert_instance_of(Appointment, @person.appointments.first)
|
110
154
|
assert_instance_of(LWS::Auth::Company, @person.company)
|
111
155
|
assert_instance_of(Location, @person.location)
|
112
156
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.3.
|
4
|
+
version: 6.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeftClick B.V.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|