kartograph 0.2.3 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/kartograph.gemspec +5 -5
- data/lib/kartograph/artist.rb +12 -11
- data/lib/kartograph/dsl.rb +4 -3
- data/lib/kartograph/property.rb +11 -4
- data/lib/kartograph/property_collection.rb +9 -2
- data/lib/kartograph/version.rb +1 -1
- data/spec/integration/allocations_spec.rb +100 -0
- data/spec/integration/testdata/sample.json +23332 -0
- data/spec/lib/kartograph/artist_spec.rb +17 -18
- data/spec/lib/kartograph/property_spec.rb +16 -0
- metadata +20 -13
@@ -6,12 +6,10 @@ describe Kartograph::Artist do
|
|
6
6
|
|
7
7
|
describe '#initialize' do
|
8
8
|
it 'initializes with an object and a map' do
|
9
|
-
object = double('object', name: 'hello')
|
10
9
|
properties << Kartograph::Property.new(:name)
|
11
10
|
|
12
|
-
artist = Kartograph::Artist.new(
|
11
|
+
artist = Kartograph::Artist.new(map)
|
13
12
|
|
14
|
-
expect(artist.object).to be(object)
|
15
13
|
expect(artist.map).to be(map)
|
16
14
|
end
|
17
15
|
end
|
@@ -21,18 +19,19 @@ describe Kartograph::Artist do
|
|
21
19
|
object = double('object', hello: 'world')
|
22
20
|
properties << Kartograph::Property.new(:hello)
|
23
21
|
|
24
|
-
artist = Kartograph::Artist.new(
|
25
|
-
masterpiece = artist.draw
|
22
|
+
artist = Kartograph::Artist.new(map)
|
23
|
+
masterpiece = artist.draw(object)
|
26
24
|
|
27
25
|
expect(masterpiece).to include('hello' => 'world')
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'raises for a property that the object does not have' do
|
31
|
-
|
29
|
+
class TestArtistNoMethod; end
|
30
|
+
object = TestArtistNoMethod.new
|
32
31
|
properties << Kartograph::Property.new(:bunk)
|
33
|
-
artist = Kartograph::Artist.new(
|
32
|
+
artist = Kartograph::Artist.new(map)
|
34
33
|
|
35
|
-
expect { artist.draw }.to raise_error(ArgumentError).with_message("#{object} does not respond to bunk, so we can't map it")
|
34
|
+
expect { artist.draw(object) }.to raise_error(ArgumentError).with_message("#{object} does not respond to bunk, so we can't map it")
|
36
35
|
end
|
37
36
|
|
38
37
|
context 'for a property with a key set on it' do
|
@@ -40,8 +39,8 @@ describe Kartograph::Artist do
|
|
40
39
|
object = double('object', hello: 'world')
|
41
40
|
properties << Kartograph::Property.new(:hello, key: :hola)
|
42
41
|
|
43
|
-
artist = Kartograph::Artist.new(
|
44
|
-
masterpiece = artist.draw
|
42
|
+
artist = Kartograph::Artist.new(map)
|
43
|
+
masterpiece = artist.draw(object)
|
45
44
|
|
46
45
|
expect(masterpiece).to include('hola' => 'world')
|
47
46
|
end
|
@@ -53,8 +52,8 @@ describe Kartograph::Artist do
|
|
53
52
|
properties << Kartograph::Property.new(:hello, scopes: [:create, :read])
|
54
53
|
properties << Kartograph::Property.new(:foo, scopes: [:create])
|
55
54
|
|
56
|
-
artist = Kartograph::Artist.new(
|
57
|
-
masterpiece = artist.draw(:read)
|
55
|
+
artist = Kartograph::Artist.new(map)
|
56
|
+
masterpiece = artist.draw(object, :read)
|
58
57
|
|
59
58
|
expect(masterpiece).to eq('hello' => 'world')
|
60
59
|
end
|
@@ -71,8 +70,8 @@ describe Kartograph::Artist do
|
|
71
70
|
|
72
71
|
properties << root_property
|
73
72
|
|
74
|
-
artist = Kartograph::Artist.new(
|
75
|
-
masterpiece = artist.draw(:read)
|
73
|
+
artist = Kartograph::Artist.new(map)
|
74
|
+
masterpiece = artist.draw(object, :read)
|
76
75
|
|
77
76
|
expect(masterpiece).to eq('child' => { 'foo' => child.foo })
|
78
77
|
end
|
@@ -88,8 +87,8 @@ describe Kartograph::Artist do
|
|
88
87
|
map.cache_key { |obj, scope| obj.cache_key }
|
89
88
|
map.property :foo
|
90
89
|
|
91
|
-
artist = Kartograph::Artist.new(
|
92
|
-
masterpiece = artist.draw
|
90
|
+
artist = Kartograph::Artist.new(map)
|
91
|
+
masterpiece = artist.draw(object)
|
93
92
|
|
94
93
|
expect(masterpiece).to eq(cacher.fetch)
|
95
94
|
|
@@ -104,8 +103,8 @@ describe Kartograph::Artist do
|
|
104
103
|
|
105
104
|
map.property :foo, scopes: [:read]
|
106
105
|
|
107
|
-
artist = Kartograph::Artist.new(
|
108
|
-
masterpiece = artist.draw(:read)
|
106
|
+
artist = Kartograph::Artist.new(map)
|
107
|
+
masterpiece = artist.draw(object, :read)
|
109
108
|
|
110
109
|
expect(called).to have_received(:call).with(object, :read)
|
111
110
|
end
|
@@ -231,5 +231,21 @@ describe Kartograph::Property do
|
|
231
231
|
expect(duped.options).to_not be(instance.options)
|
232
232
|
expect(duped.options).to eq(instance.options)
|
233
233
|
end
|
234
|
+
|
235
|
+
context 'setting the map after duping' do
|
236
|
+
it 'draws a value' do
|
237
|
+
# NOTE: This test is a regression test introduced by caching of Artist instance.
|
238
|
+
dummy_class = Struct.new(:id, :name)
|
239
|
+
dummy = dummy_class.new
|
240
|
+
dummy.id = 123
|
241
|
+
|
242
|
+
instance = Kartograph::Property.new(:id, scopes: [:read])
|
243
|
+
duped = instance.dup
|
244
|
+
duped.map = Kartograph::Map.new
|
245
|
+
val = duped.value_for(dummy)
|
246
|
+
|
247
|
+
expect(val).to_not be_nil
|
248
|
+
end
|
249
|
+
end
|
234
250
|
end
|
235
251
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kartograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- DigitalOcean API Engineering team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,28 +30,34 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 13.0.0
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
43
|
+
version: 12.3.3
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 13.0.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rspec
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
53
|
+
version: '3.9'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
60
|
+
version: '3.9'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: pry
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,9 +75,7 @@ dependencies:
|
|
69
75
|
description: Kartograph makes it easy to generate and convert JSON. It's intention
|
70
76
|
is to be used for API clients.
|
71
77
|
email:
|
72
|
-
- engineering@digitalocean.com
|
73
|
-
- rross@digitalocean.com
|
74
|
-
- ivan@digitalocean.com
|
78
|
+
- api-engineering@digitalocean.com
|
75
79
|
executables: []
|
76
80
|
extensions: []
|
77
81
|
extra_rdoc_files: []
|
@@ -96,6 +100,8 @@ files:
|
|
96
100
|
- lib/kartograph/root_key.rb
|
97
101
|
- lib/kartograph/sculptor.rb
|
98
102
|
- lib/kartograph/version.rb
|
103
|
+
- spec/integration/allocations_spec.rb
|
104
|
+
- spec/integration/testdata/sample.json
|
99
105
|
- spec/lib/kartograph/artist_spec.rb
|
100
106
|
- spec/lib/kartograph/dsl_spec.rb
|
101
107
|
- spec/lib/kartograph/map_spec.rb
|
@@ -107,7 +113,7 @@ files:
|
|
107
113
|
- spec/support/dsl_contexts.rb
|
108
114
|
- spec/support/dummy_comment.rb
|
109
115
|
- spec/support/dummy_user.rb
|
110
|
-
homepage: https://github.com/
|
116
|
+
homepage: https://github.com/digitalocean/kartograph
|
111
117
|
licenses:
|
112
118
|
- MIT
|
113
119
|
metadata: {}
|
@@ -126,13 +132,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
132
|
- !ruby/object:Gem::Version
|
127
133
|
version: '0'
|
128
134
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.4.5.1
|
135
|
+
rubygems_version: 3.0.6
|
131
136
|
signing_key:
|
132
137
|
specification_version: 4
|
133
138
|
summary: Kartograph makes it easy to generate and convert JSON. It's intention is
|
134
139
|
to be used for API clients.
|
135
140
|
test_files:
|
141
|
+
- spec/integration/allocations_spec.rb
|
142
|
+
- spec/integration/testdata/sample.json
|
136
143
|
- spec/lib/kartograph/artist_spec.rb
|
137
144
|
- spec/lib/kartograph/dsl_spec.rb
|
138
145
|
- spec/lib/kartograph/map_spec.rb
|