hal-client 3.14.0 → 3.15.0

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
  SHA1:
3
- metadata.gz: 19eeb7d4e250354bcc747d7c65e66540d9bd2461
4
- data.tar.gz: 6623c0304f0bc356a99ce59e88f976e5564d8e43
3
+ metadata.gz: a02928e0fcb08ea201d51a1b76e3db118ea2efde
4
+ data.tar.gz: 51cf12b4ac3d35e742322d75ae86ca4a16f0f114
5
5
  SHA512:
6
- metadata.gz: 4a125acaab0e6eb493977b9f916d6b4246ac590bc80f59a3e2867d34666b9b4d8d4722aad7909e6f1d5a42c6f67799c7af2db0df092601c55f3d5d8003374686
7
- data.tar.gz: 504e9b1eb3a3b8e74ec0e956ff47b6803aadcf0520d42e268a782b6c3ed24c69dc558ae4ab69d8ca73de4163e3012349195761781a3ea73182b6dd6f5a85e898
6
+ metadata.gz: 72e1e77e6fdc336f0d66755aa598a66213f021cfca90554b98cba699b63a83dd9eb82fb267a906c5e00c55f35953491e8aee3be8bc934c11e79f1e5617d7c63d
7
+ data.tar.gz: 92fb2baaacfeca8b492e9c842a8cf5f9b9e77f29c76983918809895249a289058583b7cdece571d37fb5a054b0b09721315770b5d73f5c7c7a2ea01afc7f9580
@@ -87,8 +87,8 @@ class HalClient
87
87
  rel = hash_entry[:rel]
88
88
  hash_data = hash_entry[:data]
89
89
 
90
- absolute_href = (base_url + hash_data['_links']['self']['href']).to_s
91
- hash_data['_links']['self']['href'] = absolute_href
90
+ explicit_url = self_href(hash_data)
91
+ hash_data['_links']['self']['href'] = (base_url + explicit_url).to_s if explicit_url
92
92
 
93
93
  Link.new(rel: rel,
94
94
  target: Representation.new(hal_client: hal_client, parsed_json: hash_data),
@@ -133,5 +133,14 @@ class HalClient
133
133
  [fully_qualified_rel, raw_href, templated?].hash
134
134
  end
135
135
 
136
+
137
+ protected
138
+
139
+ def self.self_href(embedded_repr)
140
+ embedded_repr
141
+ .fetch('_links', {})
142
+ .fetch('self', {})
143
+ .fetch('href', nil)
144
+ end
136
145
  end
137
146
  end
@@ -29,6 +29,18 @@ class HalClient
29
29
  @orig_repr = a_representation
30
30
  @raw = raw
31
31
  end
32
+ protected :initialize
33
+
34
+ attr_reader :raw
35
+
36
+ # Returns true if this, or any previous, editor actually changed the hal
37
+ # representation.
38
+ def dirty?
39
+ new_repr = Representation.new(parsed_json: raw)
40
+
41
+ orig_repr.properties != new_repr.properties ||
42
+ orig_repr.all_links != new_repr.all_links
43
+ end
32
44
 
33
45
  # Returns the raw json representation of this representation
34
46
  def to_json
@@ -126,7 +138,7 @@ class HalClient
126
138
 
127
139
  protected
128
140
 
129
- attr_reader :orig_repr, :raw
141
+ attr_reader :orig_repr
130
142
 
131
143
  def Array(thing)
132
144
  if Hash === thing
@@ -1,3 +1,3 @@
1
1
  class HalClient
2
- VERSION = "3.14.0"
2
+ VERSION = "3.15.0"
3
3
  end
@@ -13,6 +13,12 @@ RSpec.describe HalClient::RepresentationEditor do
13
13
  specify { expect(subject.to_hal).to be_equivalent_json_to raw_hal }
14
14
  specify { expect(subject.to_json).to be_equivalent_json_to raw_hal }
15
15
 
16
+ describe "#raw" do
17
+ it "returns parsed json representation of the altered HAL document" do
18
+ expect( subject.raw ).to eq a_repr.raw
19
+ end
20
+ end
21
+
16
22
  describe "#reject_links" do
17
23
  specify { expect(subject.reject_links("up")).not_to have_link "up" }
18
24
 
@@ -124,6 +130,52 @@ RSpec.describe HalClient::RepresentationEditor do
124
130
  end
125
131
  end
126
132
 
133
+ describe "#dirty?" do
134
+ specify "unchanged editors are clean" do
135
+ expect(subject.dirty?).to be false
136
+ end
137
+
138
+ specify "changing a property makes it dirty" do
139
+ expect(
140
+ subject.set_property("age", 11).dirty?
141
+ ).to be true
142
+ end
143
+
144
+ specify "setting a property to the existing value leaves it clean" do
145
+ expect(
146
+ subject.set_property("age", 10).dirty?
147
+ ).to be false
148
+ end
149
+
150
+ specify "removing a link makes it dirty" do
151
+ expect(
152
+ subject.reject_links("up").dirty?
153
+ ).to be true
154
+ end
155
+
156
+ specify "adding a link makes it dirty" do
157
+ expect(
158
+ subject.add_link("up", "http://example.com/new").dirty?
159
+ ).to be true
160
+ end
161
+
162
+ specify "removing and readding an existing link leaves it clean" do
163
+ expect(
164
+ subject
165
+ .reject_links("about")
166
+ .add_link("about", "http://example.com/another")
167
+ .dirty?
168
+ ).to be false
169
+ end
170
+
171
+ specify "removing a embedded makes it dirty" do
172
+ expect(
173
+ subject.reject_related("replies").dirty?
174
+ ).to be true
175
+ end
176
+
177
+ end
178
+
127
179
  # Background
128
180
 
129
181
  let(:hal_client) { HalClient.new }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hal-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.0
4
+ version: 3.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-18 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -198,3 +198,4 @@ test_files:
198
198
  - spec/hal_client_spec.rb
199
199
  - spec/spec_helper.rb
200
200
  - spec/support/custom_matchers.rb
201
+ has_rdoc: