restful_objects 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +3 -2
- data/bin/restful_server.rb +0 -0
- data/lib/restful_objects/action_description.rb +96 -82
- data/lib/restful_objects/action_list.rb +17 -17
- data/lib/restful_objects/collection_description.rb +47 -47
- data/lib/restful_objects/collection_list.rb +17 -17
- data/lib/restful_objects/domain_model.rb +83 -79
- data/lib/restful_objects/http_response.rb +11 -11
- data/lib/restful_objects/link_generator.rb +104 -104
- data/lib/restful_objects/object.rb +20 -20
- data/lib/restful_objects/object_actions.rb +134 -134
- data/lib/restful_objects/object_base.rb +10 -0
- data/lib/restful_objects/object_collections.rb +84 -84
- data/lib/restful_objects/object_list.rb +16 -16
- data/lib/restful_objects/object_macros.rb +35 -35
- data/lib/restful_objects/object_properties.rb +78 -78
- data/lib/restful_objects/parameter_description.rb +60 -60
- data/lib/restful_objects/parameter_description_list.rb +15 -15
- data/lib/restful_objects/property_description.rb +68 -68
- data/lib/restful_objects/property_list.rb +17 -17
- data/lib/restful_objects/service.rb +21 -21
- data/lib/restful_objects/service_list.rb +55 -55
- data/lib/restful_objects/type.rb +110 -110
- data/lib/restful_objects/type_list.rb +30 -30
- data/lib/restful_objects/user.rb +30 -30
- data/lib/restful_objects/version.rb +1 -1
- data/spec/integration/domain-types_actions_spec.rb +43 -43
- data/spec/integration/domain-types_collections_spec.rb +45 -45
- data/spec/integration/domain-types_properties_spec.rb +41 -41
- data/spec/integration/server-root_spec.rb +98 -98
- data/spec/spec_helper.rb +52 -52
- data/spec/unit/object_actions_spec.rb +380 -380
- data/spec/unit/object_collections_spec.rb +190 -190
- data/spec/unit/object_properties_spec.rb +215 -206
- data/spec/unit/object_spec.rb +228 -228
- data/spec/unit/service_spec.rb +125 -125
- data/spec/unit/type_list_spec.rb +37 -37
- metadata +2 -2
@@ -1,190 +1,190 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
describe RestfulObjects::ObjectActions do
|
5
|
-
before :all do
|
6
|
-
RestfulObjects::DomainModel.current.reset
|
7
|
-
|
8
|
-
class Address
|
9
|
-
include RestfulObjects::Object
|
10
|
-
|
11
|
-
property :street, :string
|
12
|
-
property :number, :int
|
13
|
-
end
|
14
|
-
|
15
|
-
class CollectionsTest
|
16
|
-
include RestfulObjects::Object
|
17
|
-
|
18
|
-
collection :addresses, Address
|
19
|
-
collection :collection_full_metadata, Address
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
before :each do
|
24
|
-
@object = CollectionsTest.new
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should create a collection' do
|
28
|
-
@object.addresses.is_a?(Enumerable).should be_true
|
29
|
-
@object.addresses.empty?.should be_true
|
30
|
-
|
31
|
-
a = Address.new
|
32
|
-
a.street = 'Evergreen'
|
33
|
-
a.number = 1234
|
34
|
-
|
35
|
-
@object.addresses.push(a)
|
36
|
-
@object.addresses.empty?.should be_false
|
37
|
-
@object.addresses.count.should eq(1)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should generate json for the collection' do
|
41
|
-
a1 = Address.new
|
42
|
-
@object.addresses.push a1
|
43
|
-
a2 = Address.new
|
44
|
-
@object.addresses.push a2
|
45
|
-
a3 = Address.new
|
46
|
-
@object.addresses.push a3
|
47
|
-
|
48
|
-
expected = { 'id' => 'addresses',
|
49
|
-
'value' => [
|
50
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
51
|
-
'href' => "http://localhost/objects/Address/#{a1.object_id}",
|
52
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
53
|
-
'method' => 'GET' },
|
54
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
55
|
-
'href' => "http://localhost/objects/Address/#{a2.object_id}",
|
56
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
57
|
-
'method' => 'GET' },
|
58
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
59
|
-
'href' => "http://localhost/objects/Address/#{a3.object_id}",
|
60
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
61
|
-
'method' => 'GET' }
|
62
|
-
],
|
63
|
-
'links' => [
|
64
|
-
{ 'rel' => 'self',
|
65
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
66
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
67
|
-
'method' => 'GET' },
|
68
|
-
{ 'rel' => 'up',
|
69
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}",
|
70
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
71
|
-
'method' => 'GET' },
|
72
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/add-to;collection="addresses"',
|
73
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
74
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
75
|
-
'method' => 'PUT',
|
76
|
-
'arguments' => { 'value' => nil } },
|
77
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/remove-from;collection="addresses"',
|
78
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
79
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
80
|
-
'method' => 'DELETE',
|
81
|
-
'arguments' => { 'value' => nil } },
|
82
|
-
]
|
83
|
-
}
|
84
|
-
|
85
|
-
get "/objects/CollectionsTest/#{@object.object_id}/collections/addresses"
|
86
|
-
|
87
|
-
last_response.body.should match_json_expression expected
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should add an object to a collection' do
|
91
|
-
address = Address.new
|
92
|
-
|
93
|
-
json = { 'value' => { 'href' => "http://localhost/objects/Address/#{address.object_id}" } }.to_json
|
94
|
-
|
95
|
-
put "/objects/CollectionsTest/#{@object.object_id}/collections/addresses", {}, { input: json }
|
96
|
-
|
97
|
-
@object.addresses.include?(address).should be_true
|
98
|
-
|
99
|
-
expected = { 'id' => 'addresses',
|
100
|
-
'value' => [
|
101
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
102
|
-
'href' => "http://localhost/objects/Address/#{address.object_id}",
|
103
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
104
|
-
'method' => 'GET' } ],
|
105
|
-
'links' => [
|
106
|
-
{ 'rel' => 'self',
|
107
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
108
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
109
|
-
'method' => 'GET' },
|
110
|
-
{ 'rel' => 'up',
|
111
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}",
|
112
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
113
|
-
'method' => 'GET' },
|
114
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/add-to;collection="addresses"',
|
115
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
116
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
117
|
-
'method' => 'PUT',
|
118
|
-
'arguments' => { 'value' => nil } },
|
119
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/remove-from;collection="addresses"',
|
120
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
121
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
122
|
-
'method' => 'DELETE',
|
123
|
-
'arguments' => { 'value' => nil } },
|
124
|
-
]
|
125
|
-
}
|
126
|
-
|
127
|
-
last_response.body.should match_json_expression expected
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should remove an object from a collection' do
|
131
|
-
address = Address.new
|
132
|
-
|
133
|
-
@object.addresses.push(address)
|
134
|
-
|
135
|
-
json = { 'value' => { 'href' => "http://localhost/objects/Address/#{address.object_id}" } }.to_json
|
136
|
-
|
137
|
-
delete "/objects/CollectionsTest/#{@object.object_id}/collections/addresses", {}, { input: json }
|
138
|
-
|
139
|
-
@object.addresses.include?(address).should be_false
|
140
|
-
|
141
|
-
expected = { 'id' => 'addresses',
|
142
|
-
'value' => [],
|
143
|
-
'links' => [
|
144
|
-
{ 'rel' => 'self',
|
145
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
146
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
147
|
-
'method' => 'GET' },
|
148
|
-
{ 'rel' => 'up',
|
149
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}",
|
150
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
151
|
-
'method' => 'GET' },
|
152
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/add-to;collection="addresses"',
|
153
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
154
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
155
|
-
'method' => 'PUT',
|
156
|
-
'arguments' => { 'value' => nil } },
|
157
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/remove-from;collection="addresses"',
|
158
|
-
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
159
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
160
|
-
'method' => 'DELETE',
|
161
|
-
'arguments' => { 'value' => nil } },
|
162
|
-
]
|
163
|
-
}
|
164
|
-
|
165
|
-
last_response.body.should match_json_expression expected
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'should generate metadata in extensions' do
|
169
|
-
collection = @object.rs_type.collections['collection_full_metadata']
|
170
|
-
collection.friendly_name = 'Friendly Collection'
|
171
|
-
collection.description = 'Collection Description'
|
172
|
-
collection.plural_form = 'Collections'
|
173
|
-
expected = {
|
174
|
-
'id' => 'collection_full_metadata',
|
175
|
-
'extensions' => {
|
176
|
-
'friendlyName' => 'Friendly Collection',
|
177
|
-
'description' => 'Collection Description',
|
178
|
-
'returnType' => 'list',
|
179
|
-
'elementType' => 'Address',
|
180
|
-
'pluralForm' => 'Collections',
|
181
|
-
'memberOrder' => Fixnum
|
182
|
-
}.strict!
|
183
|
-
}
|
184
|
-
|
185
|
-
get "/objects/ActionsTest/#{@object.object_id}/collections/collection_full_metadata"
|
186
|
-
|
187
|
-
last_response.body.should match_json_expression expected
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe RestfulObjects::ObjectActions do
|
5
|
+
before :all do
|
6
|
+
RestfulObjects::DomainModel.current.reset
|
7
|
+
|
8
|
+
class Address
|
9
|
+
include RestfulObjects::Object
|
10
|
+
|
11
|
+
property :street, :string
|
12
|
+
property :number, :int
|
13
|
+
end
|
14
|
+
|
15
|
+
class CollectionsTest
|
16
|
+
include RestfulObjects::Object
|
17
|
+
|
18
|
+
collection :addresses, Address
|
19
|
+
collection :collection_full_metadata, Address
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
before :each do
|
24
|
+
@object = CollectionsTest.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create a collection' do
|
28
|
+
@object.addresses.is_a?(Enumerable).should be_true
|
29
|
+
@object.addresses.empty?.should be_true
|
30
|
+
|
31
|
+
a = Address.new
|
32
|
+
a.street = 'Evergreen'
|
33
|
+
a.number = 1234
|
34
|
+
|
35
|
+
@object.addresses.push(a)
|
36
|
+
@object.addresses.empty?.should be_false
|
37
|
+
@object.addresses.count.should eq(1)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should generate json for the collection' do
|
41
|
+
a1 = Address.new
|
42
|
+
@object.addresses.push a1
|
43
|
+
a2 = Address.new
|
44
|
+
@object.addresses.push a2
|
45
|
+
a3 = Address.new
|
46
|
+
@object.addresses.push a3
|
47
|
+
|
48
|
+
expected = { 'id' => 'addresses',
|
49
|
+
'value' => [
|
50
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
51
|
+
'href' => "http://localhost/objects/Address/#{a1.object_id}",
|
52
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
53
|
+
'method' => 'GET' },
|
54
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
55
|
+
'href' => "http://localhost/objects/Address/#{a2.object_id}",
|
56
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
57
|
+
'method' => 'GET' },
|
58
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
59
|
+
'href' => "http://localhost/objects/Address/#{a3.object_id}",
|
60
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
61
|
+
'method' => 'GET' }
|
62
|
+
],
|
63
|
+
'links' => [
|
64
|
+
{ 'rel' => 'self',
|
65
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
66
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
67
|
+
'method' => 'GET' },
|
68
|
+
{ 'rel' => 'up',
|
69
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}",
|
70
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
71
|
+
'method' => 'GET' },
|
72
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/add-to;collection="addresses"',
|
73
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
74
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
75
|
+
'method' => 'PUT',
|
76
|
+
'arguments' => { 'value' => nil } },
|
77
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/remove-from;collection="addresses"',
|
78
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
79
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
80
|
+
'method' => 'DELETE',
|
81
|
+
'arguments' => { 'value' => nil } },
|
82
|
+
]
|
83
|
+
}
|
84
|
+
|
85
|
+
get "/objects/CollectionsTest/#{@object.object_id}/collections/addresses"
|
86
|
+
|
87
|
+
last_response.body.should match_json_expression expected
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should add an object to a collection' do
|
91
|
+
address = Address.new
|
92
|
+
|
93
|
+
json = { 'value' => { 'href' => "http://localhost/objects/Address/#{address.object_id}" } }.to_json
|
94
|
+
|
95
|
+
put "/objects/CollectionsTest/#{@object.object_id}/collections/addresses", {}, { input: json }
|
96
|
+
|
97
|
+
@object.addresses.include?(address).should be_true
|
98
|
+
|
99
|
+
expected = { 'id' => 'addresses',
|
100
|
+
'value' => [
|
101
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/value;collection="addresses"',
|
102
|
+
'href' => "http://localhost/objects/Address/#{address.object_id}",
|
103
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
104
|
+
'method' => 'GET' } ],
|
105
|
+
'links' => [
|
106
|
+
{ 'rel' => 'self',
|
107
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
108
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
109
|
+
'method' => 'GET' },
|
110
|
+
{ 'rel' => 'up',
|
111
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}",
|
112
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
113
|
+
'method' => 'GET' },
|
114
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/add-to;collection="addresses"',
|
115
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
116
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
117
|
+
'method' => 'PUT',
|
118
|
+
'arguments' => { 'value' => nil } },
|
119
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/remove-from;collection="addresses"',
|
120
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
121
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
122
|
+
'method' => 'DELETE',
|
123
|
+
'arguments' => { 'value' => nil } },
|
124
|
+
]
|
125
|
+
}
|
126
|
+
|
127
|
+
last_response.body.should match_json_expression expected
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should remove an object from a collection' do
|
131
|
+
address = Address.new
|
132
|
+
|
133
|
+
@object.addresses.push(address)
|
134
|
+
|
135
|
+
json = { 'value' => { 'href' => "http://localhost/objects/Address/#{address.object_id}" } }.to_json
|
136
|
+
|
137
|
+
delete "/objects/CollectionsTest/#{@object.object_id}/collections/addresses", {}, { input: json }
|
138
|
+
|
139
|
+
@object.addresses.include?(address).should be_false
|
140
|
+
|
141
|
+
expected = { 'id' => 'addresses',
|
142
|
+
'value' => [],
|
143
|
+
'links' => [
|
144
|
+
{ 'rel' => 'self',
|
145
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
146
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
147
|
+
'method' => 'GET' },
|
148
|
+
{ 'rel' => 'up',
|
149
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}",
|
150
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
151
|
+
'method' => 'GET' },
|
152
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/add-to;collection="addresses"',
|
153
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
154
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
155
|
+
'method' => 'PUT',
|
156
|
+
'arguments' => { 'value' => nil } },
|
157
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/remove-from;collection="addresses"',
|
158
|
+
'href' => "http://localhost/objects/CollectionsTest/#{@object.object_id}/collections/addresses",
|
159
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-collection"',
|
160
|
+
'method' => 'DELETE',
|
161
|
+
'arguments' => { 'value' => nil } },
|
162
|
+
]
|
163
|
+
}
|
164
|
+
|
165
|
+
last_response.body.should match_json_expression expected
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should generate metadata in extensions' do
|
169
|
+
collection = @object.rs_type.collections['collection_full_metadata']
|
170
|
+
collection.friendly_name = 'Friendly Collection'
|
171
|
+
collection.description = 'Collection Description'
|
172
|
+
collection.plural_form = 'Collections'
|
173
|
+
expected = {
|
174
|
+
'id' => 'collection_full_metadata',
|
175
|
+
'extensions' => {
|
176
|
+
'friendlyName' => 'Friendly Collection',
|
177
|
+
'description' => 'Collection Description',
|
178
|
+
'returnType' => 'list',
|
179
|
+
'elementType' => 'Address',
|
180
|
+
'pluralForm' => 'Collections',
|
181
|
+
'memberOrder' => Fixnum
|
182
|
+
}.strict!
|
183
|
+
}
|
184
|
+
|
185
|
+
get "/objects/ActionsTest/#{@object.object_id}/collections/collection_full_metadata"
|
186
|
+
|
187
|
+
last_response.body.should match_json_expression expected
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
@@ -1,206 +1,215 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe RestfulObjects::ObjectProperties do
|
4
|
-
before :all do
|
5
|
-
RestfulObjects::DomainModel.current.reset
|
6
|
-
|
7
|
-
class PropertiesTest
|
8
|
-
include RestfulObjects::Object
|
9
|
-
|
10
|
-
property :id,
|
11
|
-
property :name,
|
12
|
-
property :string_prop,
|
13
|
-
property :int_prop,
|
14
|
-
property :
|
15
|
-
property :
|
16
|
-
property :
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@object
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should
|
38
|
-
@object.respond_to?(:
|
39
|
-
@object.respond_to?(:
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should generate
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
'
|
53
|
-
'
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
'
|
77
|
-
'
|
78
|
-
|
79
|
-
|
80
|
-
'
|
81
|
-
'
|
82
|
-
'
|
83
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/
|
84
|
-
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
85
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
86
|
-
'method' => '
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@object.
|
104
|
-
@object.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
'
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
values
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
'
|
158
|
-
'
|
159
|
-
'
|
160
|
-
{ 'rel' => '
|
161
|
-
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}
|
162
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object
|
163
|
-
'method' => '
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe RestfulObjects::ObjectProperties do
|
4
|
+
before :all do
|
5
|
+
RestfulObjects::DomainModel.current.reset
|
6
|
+
|
7
|
+
class PropertiesTest
|
8
|
+
include RestfulObjects::Object
|
9
|
+
|
10
|
+
property :id, :int, read_only: true
|
11
|
+
property :name, :string, max_length: 10
|
12
|
+
property :string_prop, :string
|
13
|
+
property :int_prop, :int
|
14
|
+
property :bool_prop, :bool
|
15
|
+
property :decimal_prop, :decimal
|
16
|
+
property :date_prop, :date
|
17
|
+
property :blob_prop, :blob
|
18
|
+
|
19
|
+
property :prop_full_metadata, :string,
|
20
|
+
friendly_name: 'Meta Prop',
|
21
|
+
description: 'To Test Metadata',
|
22
|
+
max_length: 30,
|
23
|
+
pattern: '.*abc.*',
|
24
|
+
optional: false
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
@id = 99
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
before :each do
|
34
|
+
@object = PropertiesTest.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should respond to properties' do
|
38
|
+
@object.respond_to?(:string_prop).should be_true
|
39
|
+
@object.respond_to?(:string_prop=).should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should not generate writer for read-only property' do
|
43
|
+
@object.respond_to?(:id).should be_true
|
44
|
+
@object.respond_to?(:id=).should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should generate json for a read-only property' do
|
48
|
+
expected = { 'id' =>
|
49
|
+
{ 'value' => 99,
|
50
|
+
'links' => [
|
51
|
+
{ 'rel' => 'self',
|
52
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/id",
|
53
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
54
|
+
'method' => 'GET'},
|
55
|
+
{ 'rel' => 'up',
|
56
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}",
|
57
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
58
|
+
'method' => 'GET'}
|
59
|
+
],
|
60
|
+
'disabledReason' => 'read-only property'
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
get "/objects/PropertiesTest/#{@object.object_id}/properties/id"
|
65
|
+
|
66
|
+
last_response.body.should match_json_expression expected
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should generate json for a writable property' do
|
70
|
+
@object.name = 'Mr. John'
|
71
|
+
|
72
|
+
expected = { 'name' =>
|
73
|
+
{ 'value' => 'Mr. John',
|
74
|
+
'links' => [
|
75
|
+
{ 'rel' => 'self',
|
76
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
77
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
78
|
+
'method' => 'GET' },
|
79
|
+
{ 'rel' => 'up',
|
80
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}",
|
81
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
82
|
+
'method' => 'GET' },
|
83
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/modify;property="name"',
|
84
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
85
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
86
|
+
'method' => 'PUT',
|
87
|
+
'arguments' => { 'value' => nil } },
|
88
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/clear;property="name"',
|
89
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
90
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
91
|
+
'method' => 'DELETE' }
|
92
|
+
]
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
get "/objects/PropertiesTest/#{@object.object_id}/properties/name"
|
97
|
+
|
98
|
+
last_response.body.should match_json_expression expected
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should enforce string property max_length' do
|
102
|
+
@object.name = 'x' * 10
|
103
|
+
@object.name.should eq('x' * 10)
|
104
|
+
expect { @object.name = 'x' * 11 }.to raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should process different property types get' do
|
108
|
+
@object.string_prop = 'A string'
|
109
|
+
@object.int_prop = 1234
|
110
|
+
@object.bool_prop = true
|
111
|
+
@object.decimal_prop = 333.33
|
112
|
+
@object.date_prop = Date.new(2012, 2, 29)
|
113
|
+
@object.blob_prop = "\xE5\xA5\xB4\x30\xF2\x8C\x71\xD9"
|
114
|
+
|
115
|
+
expected = {
|
116
|
+
'string_prop' => 'A string',
|
117
|
+
'int_prop' => 1234,
|
118
|
+
'bool_prop' => 'true',
|
119
|
+
'decimal_prop' => 333.33,
|
120
|
+
'date_prop' => '2012-02-29',
|
121
|
+
'blob_prop' => '5aW0MPKMcdk=' }
|
122
|
+
|
123
|
+
expected.each do |name, value|
|
124
|
+
get "/objects/PropertiesTest/#{@object.object_id}/properties/#{name}"
|
125
|
+
JSON.parse(last_response.body)[name]['value'].should eq value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should process different property types set' do
|
130
|
+
values = {
|
131
|
+
'string_prop' => 'A string',
|
132
|
+
'int_prop' => 1234,
|
133
|
+
'bool_prop' => 'true',
|
134
|
+
'decimal_prop' => 333.33,
|
135
|
+
'date_prop' => '2012-02-29',
|
136
|
+
'blob_prop' => '5aW0MPKMcdk=' }
|
137
|
+
|
138
|
+
values.each do |name, value|
|
139
|
+
put "/objects/PropertiesTest/#{@object.object_id}/properties/#{name}", { 'value' => value }.to_json
|
140
|
+
end
|
141
|
+
|
142
|
+
@object.string_prop.should eq 'A string'
|
143
|
+
@object.int_prop.should eq 1234
|
144
|
+
@object.bool_prop.should eq true
|
145
|
+
@object.decimal_prop.should eq 333.33
|
146
|
+
@object.date_prop.should eq Date.new(2012, 2, 29)
|
147
|
+
@object.blob_prop.should eq "\xE5\xA5\xB4\x30\xF2\x8C\x71\xD9"
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should process a property put with json' do
|
151
|
+
json = { 'value' => 'masterkey' }.to_json
|
152
|
+
|
153
|
+
expected = { 'name' =>
|
154
|
+
{ 'value' => 'masterkey',
|
155
|
+
'links' => [
|
156
|
+
{ 'rel' => 'self',
|
157
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
158
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
159
|
+
'method' => 'GET' },
|
160
|
+
{ 'rel' => 'up',
|
161
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}",
|
162
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
|
163
|
+
'method' => 'GET' },
|
164
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/modify;property="name"',
|
165
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
166
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
167
|
+
'method' => 'PUT',
|
168
|
+
'arguments' => { 'value' => nil } },
|
169
|
+
{ 'rel' => 'urn:org.restfulobjects:rels/clear;property="name"',
|
170
|
+
'href' => "http://localhost/objects/PropertiesTest/#{@object.object_id}/properties/name",
|
171
|
+
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-property"',
|
172
|
+
'method' => 'DELETE' }
|
173
|
+
]
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
put "/objects/PropertiesTest/#{@object.object_id}/properties/name", json
|
178
|
+
|
179
|
+
last_response.body.should match_json_expression expected
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should process a property delete' do
|
183
|
+
@object.name = 'irrelevant'
|
184
|
+
|
185
|
+
delete "/objects/PropertiesTest/#{@object.object_id}/properties/name"
|
186
|
+
|
187
|
+
@object.name.should be_nil
|
188
|
+
|
189
|
+
expected = { 'name' => { 'value' => nil } }
|
190
|
+
|
191
|
+
last_response.body.should match_json_expression expected
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should generate metadata in extensions' do
|
195
|
+
expected = {
|
196
|
+
'prop_full_metadata' => {
|
197
|
+
'extensions' => {
|
198
|
+
'friendlyName' => 'Meta Prop',
|
199
|
+
'description' => 'To Test Metadata',
|
200
|
+
'returnType' => 'string',
|
201
|
+
'format' => 'string',
|
202
|
+
'optional' => false,
|
203
|
+
'maxLength' => 30,
|
204
|
+
'pattern' => '.*abc.*',
|
205
|
+
'memberOrder' => Fixnum
|
206
|
+
}.strict!
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
get "/objects/PropertiesTest/#{@object.object_id}/properties/prop_full_metadata"
|
211
|
+
|
212
|
+
last_response.body.should match_json_expression expected
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|