lws 6.2.1 → 6.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02ddf61260b1288e6e201f1c80aa065963e9beec247b133b6a4fb78a2b78cdca
4
- data.tar.gz: 6526aa14baee05dd3e6e1618a87e21c2ca274afba7d360bf5585420f8c8221ce
3
+ metadata.gz: 7b91a46e1cd07d2abdbe4d45e4d634725177bd993926e617a0eb0bf79b78a038
4
+ data.tar.gz: a5a570895842b2d7d7bfe6f40326a34b84c2d3a484668832588091d84ffb7b0c
5
5
  SHA512:
6
- metadata.gz: f9e1a3341fd4b28dea74abfe121b8352b8fa22d0aea35b239f48f9d7ba45bd91382c636385f83a08c3f3b9f4efadf72dccca35119e62d423cd12b1d877c032ed
7
- data.tar.gz: dbfd3e1334c6790712e60e931eed86c94f98d478b9ea54e5c2fca855cfe5f57967d394b32d2777a8f4e480d9a1b419f8eede43f7b9b9df57d4e922ace9f972b3
6
+ metadata.gz: 214b724cd2c734cdb95e50be7b74d0cfbd5f8766a6cb3d665e17f21fa0202f80abddbe968d9f150583fd82e00c9a31ead72e5ff62e6aeb40539868d8b3ed0b38
7
+ data.tar.gz: 491e70649040f36afdb496accf6c0e41ed640649606d313a375d5b7cfc2cd8b967673d0752037e21bde5e92d7a411d6a367f692cea0ee76a7b1496ddfb353f0e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ Up until v6.1.0, we used the standard Gem version numbering starting at v0.0.1.
4
4
  From v6.1.0 on the version will follow the API version of LWS in the major/minor
5
5
  part of te version.
6
6
 
7
+ ## v6.2.2
8
+
9
+ * Add some more attributes to the Presence app
10
+ * Use persistent HTTP connections from now on (#12101)
11
+ * Add a configuration option for enabling/disabling persistent HTTP
12
+ connections
13
+ * Add support for dirtiness checking for all models (#12100)
14
+ * Only save models using the HTTP if dirty
15
+
7
16
  ## v6.2.1
8
17
 
9
18
  * Add new models and attributes to the Presence app (#12098, #12099)
data/lib/lws.rb CHANGED
@@ -126,7 +126,11 @@ module LWS
126
126
  c.use HTTPLogger, config.logger, config.http_debug_headers if config.http_debug
127
127
 
128
128
  # Adapter
129
- c.adapter Faraday.default_adapter
129
+ if config.http_persistent
130
+ c.adapter :net_http_persistent
131
+ else
132
+ c.adapter Faraday.default_adapter
133
+ end
130
134
  end
131
135
 
132
136
  return api
@@ -18,6 +18,8 @@ module LWS::Generic
18
18
  #
19
19
  # This model forms the base for all LWS models.
20
20
  class Model < Spyke::Base
21
+ include ActiveModel::Dirty
22
+
21
23
  include_root_in_json true
22
24
 
23
25
  # @private
@@ -50,7 +52,12 @@ module LWS::Generic
50
52
  # @param [Symbol] name the name of the attribute to add
51
53
  # @return [void]
52
54
  def self.attribute(name)
55
+ define_attribute_methods(name)
53
56
  attributes(name)
57
+ define_method(:"#{name}=") do |value|
58
+ send(:"#{name}_will_change!") unless value == attribute(name)
59
+ super(value)
60
+ end
54
61
  end
55
62
 
56
63
  # @private
@@ -79,6 +86,50 @@ module LWS::Generic
79
86
  self.include_root_in_json self.name.split("::").last.underscore.to_sym
80
87
  api
81
88
  end
89
+
90
+ # @private
91
+ # @!visibility private
92
+ #
93
+ # Sets up the object/model and then clears any changes information as
94
+ # a result of loading and processing the JSON from LWS.
95
+ #
96
+ # return [Model] a new instance of the generic model
97
+ def initialize(*args)
98
+ super
99
+ clear_changes_information if persisted?
100
+ end
101
+
102
+ # Reloads the attributes of this model by retrieving it from LWS
103
+ # via HTTP.
104
+ #
105
+ # This also clears information about tracked changes to attribute
106
+ # values!
107
+ #
108
+ # @return [Hash] a mapping of retrieved attribute names to values
109
+ def reload
110
+ result = super
111
+ clear_changes_information if result
112
+ result
113
+ end
114
+
115
+ # Restore the attributes of this model to the previous (original) values.
116
+ #
117
+ # @return [Array<String>] list of attribute names that were rolled back
118
+ def rollback
119
+ restore_attributes
120
+ end
121
+
122
+ # Saves the model to LWS via HTTP if there are any changes.
123
+ #
124
+ # @return [Hash, Trueclass] a mapping of attributes names to values,
125
+ # or +true+ if no save action was necessary.
126
+ def save
127
+ return true unless changed?
128
+ result = super
129
+ changes_applied if result
130
+ result
131
+ end
132
+
82
133
  end
83
134
 
84
135
  # = The configuration class
@@ -113,8 +113,8 @@ module LWS::Presence
113
113
  attribute :long
114
114
 
115
115
  # @!attribute map_positions
116
- # @return [Array<Location::Map::Position>] the positions
117
- # that are associated with the location
116
+ # @return [Array<Location::Map::Position>] the location map positions
117
+ # that track this location
118
118
  has_many :map_positions, class_name: "LWS::Presence::Location::Map::Position"
119
119
 
120
120
  # @attribute maps
@@ -295,6 +295,10 @@ module LWS::Presence
295
295
  # @return [String, nil] the customer specific reference for the person
296
296
  attribute :customer_reference
297
297
 
298
+ # @!attribute email
299
+ # @return [String, nil] the email address of the person
300
+ attribute :email
301
+
298
302
  # @!attribute ero
299
303
  # @return [Boolean] whether the person is emergency response
300
304
  # ceritified
@@ -304,6 +308,10 @@ module LWS::Presence
304
308
  # @return [String, nil] some extra info for the person
305
309
  attribute :extra_info
306
310
 
311
+ # @!attribute import_ref
312
+ # @return [String, nil] reference for storing the uid of the remote database
313
+ attribute :import_ref
314
+
307
315
  # @!attribute last_sync
308
316
  # @return [String, nil] the last date/time the status was updated via a
309
317
  # device or RFID tag
@@ -334,10 +342,28 @@ module LWS::Presence
334
342
  # @return [String] the name of the person
335
343
  attribute :name
336
344
 
345
+ # @!attribute phone_fixed
346
+ # @return [String] the fixed phonenumber of the person
347
+ attribute :phone_fixed
348
+
349
+ # @!attribute phone_mobile
350
+ # @return [String] the mobile phonenumber of the person
351
+ attribute :phone_moblie
352
+
353
+ # @!attribute phone_extension
354
+ # @return [String] the fixed phonenumber extension of the person
355
+ attribute :phone_extension
356
+
337
357
  # @!attribute picture_url
338
358
  # @return [String, nil] the URL of the picture of the person
339
359
  attribute :picture_url
340
360
 
361
+ # @!attribute present
362
+ # @return [Boolean] if a person is present at a location. It looks
363
+ # at the state of a person so that local state checking is not
364
+ # needed.
365
+ attribute :present
366
+
341
367
  # @!attribute rfid
342
368
  # @return [String, nil] the RFID tag ID linked to the person
343
369
  attribute :rfid
@@ -352,6 +378,10 @@ module LWS::Presence
352
378
  # linked to the person
353
379
  attribute :udid
354
380
 
381
+ # @!attribute vehicle_registration_plate
382
+ # @return [String, nil] The vehicle registration plate of the persons transport
383
+ attribute :vehicle_registration_plate
384
+
355
385
  # @!attribute visibility
356
386
  # @return ["public", "private"] if a person should be protected by not showing critical information
357
387
  attribute :visibility
data/lib/lws/config.rb CHANGED
@@ -54,6 +54,10 @@ module LWS
54
54
  # (default: +false+)
55
55
  property :http_debug_headers, default: false
56
56
 
57
+ #@!attribute http_persistent
58
+ # @return [Boolean] whether persistent HTTP connections are used
59
+ property :http_persistent, default: true
60
+
57
61
  #@!attribute json_debug
58
62
  # @return [Boolean] whether to show JSON debug messages (default: +false+)
59
63
  property :json_debug, default: false
data/lib/lws/version.rb CHANGED
@@ -13,6 +13,6 @@ module LWS
13
13
 
14
14
  # The LWS library version.
15
15
  # @note The major and minor version parts match the LWS API version!
16
- VERSION = '6.2.1'.freeze
16
+ VERSION = '6.2.2'.freeze
17
17
 
18
18
  end
data/test/generic_test.rb CHANGED
@@ -11,21 +11,15 @@
11
11
 
12
12
  require "test_helper"
13
13
 
14
- class TestGenericConfiguration < MiniTest::Test
14
+ class TestGenericModel < MiniTest::Test
15
15
 
16
- # Generic class needs to be accessed under some kind of app
16
+ # Generic models needs to be accessed as under some kind of app
17
17
  include LWS::Auth
18
18
 
19
19
  def setup
20
20
  @configuration = Configuration.all.first
21
21
  end
22
22
 
23
- def test_valid
24
- refute_nil(@configuration)
25
- assert_instance_of(Configuration, @configuration)
26
- refute_nil(@configuration.id)
27
- end
28
-
29
23
  def test_her_compatibility
30
24
  @configuration.assign_attributes("value" => "other_value")
31
25
  assert_equal("other_value", @configuration.value)
@@ -58,4 +52,51 @@ class TestGenericConfiguration < MiniTest::Test
58
52
  end
59
53
  end
60
54
 
55
+ def test_dirty
56
+ # No changes for a just found instance
57
+ configuration = Configuration.find(@configuration.id)
58
+ refute(configuration.changed?)
59
+ assert_equal({}, configuration.changes)
60
+
61
+ # Changes when an attribute is changed
62
+ configuration.value = "other_value"
63
+ assert(configuration.changed?)
64
+ assert_equal({ "value" => ["test_value", "other_value"] },
65
+ configuration.changes)
66
+
67
+ # Changes reverted when rolled back
68
+ configuration.rollback
69
+ refute(configuration.changed?)
70
+ assert_equal({}, configuration.changes)
71
+
72
+ # Changes overwritten when reloaded
73
+ configuration.value = "other_value"
74
+ assert(configuration.changed?)
75
+ configuration.reload
76
+ refute(configuration.changed?)
77
+ assert_equal({}, configuration.changes)
78
+
79
+ # Not committed to the API if not changed
80
+ refute(configuration.changed?)
81
+ result = configuration.save
82
+ assert_equal(true, result)
83
+ end
84
+
85
+ end
86
+
87
+ class TestGenericConfiguration < MiniTest::Test
88
+
89
+ # Generic class needs to be accessed under some kind of app
90
+ include LWS::Auth
91
+
92
+ def setup
93
+ @configuration = Configuration.all.first
94
+ end
95
+
96
+ def test_valid
97
+ refute_nil(@configuration)
98
+ assert_instance_of(Configuration, @configuration)
99
+ refute_nil(@configuration.id)
100
+ end
101
+
61
102
  end
@@ -16,6 +16,8 @@ class TestJSONParser < MiniTest::Test
16
16
  include WebMock::API
17
17
 
18
18
  def setup
19
+ # Redo LWS setup with persistent HTTP connections disabled.
20
+ reconfigure(http_persistent: false)
19
21
  WebMock.enable!
20
22
  company = { id: "correct",
21
23
  country: "NL",
@@ -31,7 +33,7 @@ class TestJSONParser < MiniTest::Test
31
33
  stub_request(:get, full_uri.to_s)
32
34
  .to_return(body: MultiJson.dump(company))
33
35
  stub_request(:put, full_uri.to_s)
34
- .to_return(body: MultiJson.dump(company.merge(errors: { ticket: ["is an invalid field"] })))
36
+ .to_return(body: MultiJson.dump(company.merge(errors: { contact_person_id: ["can't be blank"] })))
35
37
  full_uri.path = "/companies"
36
38
  stub_request(:post, full_uri.to_s)
37
39
  .to_return(body: "", status: 204)
@@ -39,6 +41,7 @@ class TestJSONParser < MiniTest::Test
39
41
 
40
42
  def teardown
41
43
  WebMock.disable!
44
+ reconfigure
42
45
  end
43
46
 
44
47
  def test_broken_json
@@ -59,9 +62,9 @@ class TestJSONParser < MiniTest::Test
59
62
 
60
63
  def test_correct_json_with_errors
61
64
  company = LWS::Auth::Company.find("correct")
62
- company.ticket = "unknown attribute"
65
+ company.contact_person_id = ""
63
66
  company.save
64
- assert_equal ["Ticket is an invalid field"], company.errors.to_a
67
+ assert_equal ["Contact person can't be blank"], company.errors.to_a
65
68
  end
66
69
 
67
70
  end
@@ -14,8 +14,10 @@ require "test_helper"
14
14
  class TestStubbing < MiniTest::Test
15
15
 
16
16
  def setup
17
- # Redo the LWS setup with cache
18
- reconfigure(stubbing: File.expand_path("../fixtures", __FILE__))
17
+ # Redo LWS setup with stubbing enabled and persistent HTTP connections
18
+ # disabled.
19
+ reconfigure(http_persistent: false,
20
+ stubbing: File.expand_path("../fixtures", __FILE__))
19
21
  end
20
22
 
21
23
  def teardown
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.2.1
4
+ version: 6.2.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-02-14 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware