restful_objects 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/restful_objects.rb +1 -2
- data/lib/restful_objects/domain_model/domain_model.rb +14 -11
- data/lib/restful_objects/domain_model/helpers/link_generator.rb +102 -90
- data/lib/restful_objects/domain_model/mixins/object.rb +10 -13
- data/lib/restful_objects/domain_model/mixins/object_actions.rb +106 -117
- data/lib/restful_objects/domain_model/mixins/object_base.rb +175 -131
- data/lib/restful_objects/domain_model/mixins/object_collections.rb +58 -71
- data/lib/restful_objects/domain_model/mixins/object_macros.rb +20 -26
- data/lib/restful_objects/domain_model/mixins/object_properties.rb +85 -98
- data/lib/restful_objects/domain_model/mixins/service.rb +9 -17
- data/lib/restful_objects/domain_model/types/action_description.rb +80 -82
- data/lib/restful_objects/domain_model/types/collection_description.rb +39 -40
- data/lib/restful_objects/domain_model/types/domain_type.rb +102 -105
- data/lib/restful_objects/domain_model/types/parameter_description.rb +42 -47
- data/lib/restful_objects/domain_model/types/parameter_description_list.rb +9 -12
- data/lib/restful_objects/domain_model/types/property_description.rb +62 -64
- data/lib/restful_objects/router.rb +6 -0
- data/lib/restful_objects/router/base.rb +23 -32
- data/lib/restful_objects/router/domain_object_resources.rb +89 -94
- data/lib/restful_objects/router/domain_type_resources.rb +24 -29
- data/lib/restful_objects/router/supporting_resources.rb +26 -31
- data/lib/restful_objects/version.rb +1 -1
- data/spec/integration/domain-types_actions_spec.rb +1 -3
- data/spec/integration/domain-types_collections_spec.rb +1 -39
- data/spec/integration/domain-types_properties_spec.rb +1 -78
- data/spec/integration/domain-types_spec.rb +39 -0
- data/spec/integration/{server-root_spec.rb → homepage_spec.rb} +2 -3
- data/spec/integration/objects_actions_spec.rb +7 -0
- data/spec/integration/objects_collections_spec.rb +169 -0
- data/spec/integration/objects_properties_spec.rb +122 -0
- data/spec/{acceptance/generate_json_representations_spec.rb → integration/objects_spec.rb} +12 -4
- data/spec/unit/object_actions_spec.rb +5 -5
- data/spec/unit/object_collections_spec.rb +1 -1
- data/spec/unit/object_properties_spec.rb +6 -6
- data/spec/unit/object_spec.rb +9 -9
- data/spec/unit/service_spec.rb +5 -5
- metadata +54 -35
- data/spec/integration/domain_model_spec.rb +0 -35
- data/spec/unit/type_list_spec.rb +0 -37
@@ -1,11 +1,9 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '=> /objects/:type/' do
|
4
4
|
before :each do
|
5
5
|
RestfulObjects::DomainModel.current.reset
|
6
|
-
end
|
7
6
|
|
8
|
-
it 'generates json representation for a complex object' do
|
9
7
|
class Address
|
10
8
|
end
|
11
9
|
|
@@ -24,7 +22,9 @@ describe RestfulObjects::Object do
|
|
24
22
|
super
|
25
23
|
end
|
26
24
|
end
|
25
|
+
end
|
27
26
|
|
27
|
+
it 'generates json representation for a complex object' do
|
28
28
|
object = ObjectTest.new
|
29
29
|
object.password = 'secret_key'
|
30
30
|
address = Address.new
|
@@ -98,5 +98,13 @@ describe RestfulObjects::Object do
|
|
98
98
|
expect(last_response.content_type).to eq CONTENT_TYPE
|
99
99
|
expect(last_response.body).to match_json_expression expected
|
100
100
|
end
|
101
|
-
end
|
102
101
|
|
102
|
+
describe 'properties interactions,' do
|
103
|
+
it 'returns "404 Not Found" when property is not registered' do
|
104
|
+
object = ObjectTest.new
|
105
|
+
get "/objects/ObjectTest/#{object.object_id}/properties/invalid_property"
|
106
|
+
expect(last_response.status).to eq 404
|
107
|
+
expect(last_response.headers['Warning']).to eq "No such property invalid_property"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -193,7 +193,7 @@ describe RestfulObjects::ObjectActions do
|
|
193
193
|
'href' => "http://localhost/objects/ActionsTest/#{@object.object_id}/actions/get_nil_scalar/invoke",
|
194
194
|
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
|
195
195
|
'method' => 'GET',
|
196
|
-
'arguments' =>
|
196
|
+
'arguments' => { } }
|
197
197
|
],
|
198
198
|
'resultType' => 'scalar',
|
199
199
|
'result' => nil,
|
@@ -214,7 +214,7 @@ describe RestfulObjects::ObjectActions do
|
|
214
214
|
'href' => "http://localhost/objects/ActionsTest/#{@object.object_id}/actions/get_object/invoke",
|
215
215
|
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
|
216
216
|
'method' => 'GET',
|
217
|
-
'arguments' =>
|
217
|
+
'arguments' => { } }
|
218
218
|
],
|
219
219
|
'resultType' => 'object',
|
220
220
|
'result' => {
|
@@ -245,7 +245,7 @@ describe RestfulObjects::ObjectActions do
|
|
245
245
|
'href' => "http://localhost/objects/ActionsTest/#{@object.object_id}/actions/get_nil_object/invoke",
|
246
246
|
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
|
247
247
|
'method' => 'GET',
|
248
|
-
'arguments' =>
|
248
|
+
'arguments' => { } }
|
249
249
|
],
|
250
250
|
'resultType' => 'object',
|
251
251
|
'result' => nil,
|
@@ -266,7 +266,7 @@ describe RestfulObjects::ObjectActions do
|
|
266
266
|
'href' => "http://localhost/objects/ActionsTest/#{@object.object_id}/actions/get_list/invoke",
|
267
267
|
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
|
268
268
|
'method' => 'GET',
|
269
|
-
'arguments' =>
|
269
|
+
'arguments' => { } }
|
270
270
|
],
|
271
271
|
'resultType' => 'list',
|
272
272
|
'result' => {
|
@@ -302,7 +302,7 @@ describe RestfulObjects::ObjectActions do
|
|
302
302
|
'href' => "http://localhost/objects/ActionsTest/#{@object.object_id}/actions/get_nil_list/invoke",
|
303
303
|
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
|
304
304
|
'method' => 'GET',
|
305
|
-
'arguments' =>
|
305
|
+
'arguments' => { } }
|
306
306
|
],
|
307
307
|
'resultType' => 'list',
|
308
308
|
'result' => nil,
|
@@ -166,7 +166,7 @@ describe RestfulObjects::ObjectActions do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'should generate metadata in extensions' do
|
169
|
-
collection = @object.
|
169
|
+
collection = @object.ro_domain_type.collections['collection_full_metadata']
|
170
170
|
collection.friendly_name = 'Friendly Collection'
|
171
171
|
collection.description = 'Collection Description'
|
172
172
|
collection.plural_form = 'Collections'
|
@@ -139,12 +139,12 @@ describe RestfulObjects::ObjectProperties do
|
|
139
139
|
put "/objects/PropertiesTest/#{@object.object_id}/properties/#{name}", { 'value' => value }.to_json
|
140
140
|
end
|
141
141
|
|
142
|
-
@object.string_prop.
|
143
|
-
@object.int_prop.
|
144
|
-
@object.bool_prop.
|
145
|
-
@object.decimal_prop.
|
146
|
-
@object.date_prop.
|
147
|
-
@object.blob_prop.
|
142
|
+
expect(@object.string_prop).to eq 'A string'
|
143
|
+
expect(@object.int_prop).to eq 1234
|
144
|
+
expect(@object.bool_prop).to eq true
|
145
|
+
expect(@object.decimal_prop).to eq 333.33
|
146
|
+
expect(@object.date_prop).to eq Date.new(2012, 2, 29)
|
147
|
+
expect(@object.blob_prop).to eq "\xE5\xA5\xB4\x30\xF2\x8C\x71\xD9".force_encoding('ASCII-8BIT')
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'should process a property put with json' do
|
data/spec/unit/object_spec.rb
CHANGED
@@ -60,9 +60,9 @@ describe RestfulObjects::Object do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should generate metadata in extensions' do
|
63
|
-
@object.
|
64
|
-
@object.
|
65
|
-
@object.
|
63
|
+
@object.ro_domain_type.plural_name = 'Test Objects'
|
64
|
+
@object.ro_domain_type.friendly_name = 'Test Object Friendly'
|
65
|
+
@object.ro_domain_type.description = 'An object to test'
|
66
66
|
|
67
67
|
expected = {
|
68
68
|
'instanceId' => @object.object_id.to_s,
|
@@ -87,12 +87,12 @@ describe RestfulObjects::Object do
|
|
87
87
|
def initialize
|
88
88
|
super
|
89
89
|
@init_called = true
|
90
|
-
@
|
90
|
+
@ro_title = 'A title'
|
91
91
|
end
|
92
92
|
end
|
93
93
|
obj = InitializedObject.new
|
94
94
|
obj.init_called.should be_true
|
95
|
-
obj.
|
95
|
+
obj.ro_title.should eq 'A title'
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'should send on_after_create callback when object is created' do
|
@@ -133,7 +133,7 @@ describe RestfulObjects::Object do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'should send on_after_delete callback when object is deleted' do
|
136
|
-
class
|
136
|
+
class TestDeleted
|
137
137
|
include RestfulObjects::Object
|
138
138
|
attr_reader :destroyed
|
139
139
|
def on_after_delete
|
@@ -141,14 +141,14 @@ describe RestfulObjects::Object do
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
obj =
|
144
|
+
obj = TestDeleted.new
|
145
145
|
|
146
|
-
obj.
|
146
|
+
obj.ro_deleted?.should_not be_true
|
147
147
|
obj.destroyed.should_not be_true
|
148
148
|
|
149
149
|
delete "/objects/DeletedObject/#{obj.object_id}"
|
150
150
|
|
151
|
-
obj.
|
151
|
+
obj.ro_deleted?.should be_true
|
152
152
|
obj.destroyed.should be_true
|
153
153
|
end
|
154
154
|
end
|
data/spec/unit/service_spec.rb
CHANGED
@@ -18,12 +18,12 @@ describe RestfulObjects::Service do
|
|
18
18
|
it 'should be registered and created automatically ' do
|
19
19
|
RestfulObjects::DomainModel.current.services.include?('ServiceTest').should be_true
|
20
20
|
RestfulObjects::DomainModel.current.services['ServiceTest'].should_not be_nil
|
21
|
-
RestfulObjects::DomainModel.current.services['ServiceTest'].
|
21
|
+
RestfulObjects::DomainModel.current.services['ServiceTest'].ro_is_service?.should be_true
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should generate json for the service' do
|
25
25
|
service = RestfulObjects::DomainModel.current.services['ServiceTest']
|
26
|
-
service.
|
26
|
+
service.ro_title = 'Test Service'
|
27
27
|
|
28
28
|
expected = {
|
29
29
|
'serviceId' => 'ServiceTest',
|
@@ -60,7 +60,7 @@ describe RestfulObjects::Service do
|
|
60
60
|
class ServiceTest
|
61
61
|
include RestfulObjects::Service
|
62
62
|
end
|
63
|
-
instance_id = model.services['ServiceTest'].
|
63
|
+
instance_id = model.services['ServiceTest'].ro_instance_id
|
64
64
|
model.objects.include?(instance_id).should_not be_true
|
65
65
|
end
|
66
66
|
|
@@ -115,11 +115,11 @@ describe RestfulObjects::Service do
|
|
115
115
|
def initialize
|
116
116
|
super
|
117
117
|
@init_called = true
|
118
|
-
@
|
118
|
+
@ro_title = 'A title'
|
119
119
|
end
|
120
120
|
end
|
121
121
|
model.services['InitializedService'].init_called.should be_true
|
122
|
-
model.services['InitializedService'].
|
122
|
+
model.services['InitializedService'].ro_title.should eq 'A title'
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Vizcay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.8.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.4.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.4.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: sinatra
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,41 +117,44 @@ extensions: []
|
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
105
119
|
- bin/restful_server
|
106
|
-
- lib/restful_objects/
|
107
|
-
- lib/restful_objects/
|
108
|
-
- lib/restful_objects/
|
109
|
-
- lib/restful_objects/
|
110
|
-
- lib/restful_objects/
|
111
|
-
- lib/restful_objects/domain_model/
|
112
|
-
- lib/restful_objects/domain_model/types/parameter_description_list.rb
|
113
|
-
- lib/restful_objects/domain_model/types/domain_type.rb
|
114
|
-
- lib/restful_objects/domain_model/types/action_description.rb
|
115
|
-
- lib/restful_objects/domain_model/types/parameter_description.rb
|
116
|
-
- lib/restful_objects/domain_model/types/collection_description.rb
|
120
|
+
- lib/restful_objects/domain_model/domain_model.rb
|
121
|
+
- lib/restful_objects/domain_model/helpers/link_generator.rb
|
122
|
+
- lib/restful_objects/domain_model/mixins/object.rb
|
123
|
+
- lib/restful_objects/domain_model/mixins/object_actions.rb
|
124
|
+
- lib/restful_objects/domain_model/mixins/object_base.rb
|
125
|
+
- lib/restful_objects/domain_model/mixins/object_collections.rb
|
117
126
|
- lib/restful_objects/domain_model/mixins/object_macros.rb
|
118
127
|
- lib/restful_objects/domain_model/mixins/object_properties.rb
|
119
128
|
- lib/restful_objects/domain_model/mixins/service.rb
|
120
|
-
- lib/restful_objects/domain_model/
|
121
|
-
- lib/restful_objects/domain_model/
|
122
|
-
- lib/restful_objects/domain_model/
|
123
|
-
- lib/restful_objects/domain_model/
|
129
|
+
- lib/restful_objects/domain_model/types/action_description.rb
|
130
|
+
- lib/restful_objects/domain_model/types/collection_description.rb
|
131
|
+
- lib/restful_objects/domain_model/types/domain_type.rb
|
132
|
+
- lib/restful_objects/domain_model/types/parameter_description.rb
|
133
|
+
- lib/restful_objects/domain_model/types/parameter_description_list.rb
|
134
|
+
- lib/restful_objects/domain_model/types/property_description.rb
|
124
135
|
- lib/restful_objects/domain_model/user.rb
|
125
|
-
- lib/restful_objects/
|
126
|
-
- lib/restful_objects/
|
136
|
+
- lib/restful_objects/router/base.rb
|
137
|
+
- lib/restful_objects/router/domain_object_resources.rb
|
138
|
+
- lib/restful_objects/router/domain_type_resources.rb
|
139
|
+
- lib/restful_objects/router/supporting_resources.rb
|
140
|
+
- lib/restful_objects/router.rb
|
141
|
+
- lib/restful_objects/version.rb
|
127
142
|
- lib/restful_objects.rb
|
128
|
-
- spec/integration/domain_model_spec.rb
|
129
|
-
- spec/integration/domain-types_properties_spec.rb
|
130
|
-
- spec/integration/domain-types_collections_spec.rb
|
131
143
|
- spec/integration/domain-types_actions_spec.rb
|
132
|
-
- spec/integration/
|
133
|
-
- spec/
|
144
|
+
- spec/integration/domain-types_collections_spec.rb
|
145
|
+
- spec/integration/domain-types_properties_spec.rb
|
146
|
+
- spec/integration/domain-types_spec.rb
|
147
|
+
- spec/integration/homepage_spec.rb
|
148
|
+
- spec/integration/objects_actions_spec.rb
|
149
|
+
- spec/integration/objects_collections_spec.rb
|
150
|
+
- spec/integration/objects_properties_spec.rb
|
151
|
+
- spec/integration/objects_spec.rb
|
134
152
|
- spec/spec_helper.rb
|
135
|
-
- spec/unit/
|
153
|
+
- spec/unit/object_actions_spec.rb
|
136
154
|
- spec/unit/object_collections_spec.rb
|
137
155
|
- spec/unit/object_properties_spec.rb
|
138
156
|
- spec/unit/object_spec.rb
|
139
|
-
- spec/unit/
|
140
|
-
- spec/unit/object_actions_spec.rb
|
157
|
+
- spec/unit/service_spec.rb
|
141
158
|
- LICENSE
|
142
159
|
- README.md
|
143
160
|
homepage: https://github.com/vizcay/RestfulObjectsRuby
|
@@ -165,16 +182,18 @@ signing_key:
|
|
165
182
|
specification_version: 4
|
166
183
|
summary: This gem is a framework for implementing Restful Objects servers.
|
167
184
|
test_files:
|
168
|
-
- spec/integration/domain_model_spec.rb
|
169
|
-
- spec/integration/domain-types_properties_spec.rb
|
170
|
-
- spec/integration/domain-types_collections_spec.rb
|
171
185
|
- spec/integration/domain-types_actions_spec.rb
|
172
|
-
- spec/integration/
|
173
|
-
- spec/
|
186
|
+
- spec/integration/domain-types_collections_spec.rb
|
187
|
+
- spec/integration/domain-types_properties_spec.rb
|
188
|
+
- spec/integration/domain-types_spec.rb
|
189
|
+
- spec/integration/homepage_spec.rb
|
190
|
+
- spec/integration/objects_actions_spec.rb
|
191
|
+
- spec/integration/objects_collections_spec.rb
|
192
|
+
- spec/integration/objects_properties_spec.rb
|
193
|
+
- spec/integration/objects_spec.rb
|
174
194
|
- spec/spec_helper.rb
|
175
|
-
- spec/unit/
|
195
|
+
- spec/unit/object_actions_spec.rb
|
176
196
|
- spec/unit/object_collections_spec.rb
|
177
197
|
- spec/unit/object_properties_spec.rb
|
178
198
|
- spec/unit/object_spec.rb
|
179
|
-
- spec/unit/
|
180
|
-
- spec/unit/object_actions_spec.rb
|
199
|
+
- spec/unit/service_spec.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe RestfulObjects::Object do
|
4
|
-
describe '#put_properties_and_get_representation' do
|
5
|
-
it 'updates simple property' do
|
6
|
-
class TestObject
|
7
|
-
include RestfulObjects::Object
|
8
|
-
property :name, :string
|
9
|
-
end
|
10
|
-
test_object = TestObject.new
|
11
|
-
response = test_object.put_properties_and_get_representation({ 'name' => { 'value' => 'john smith' } }.to_json)
|
12
|
-
expect(response.body).to match_json_expression({ 'members' => { 'name' => { 'value' => 'john smith' } } })
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'updates multiple properties' do
|
16
|
-
class TestObject
|
17
|
-
include RestfulObjects::Object
|
18
|
-
property :name, :string
|
19
|
-
property :age, :int
|
20
|
-
property :weight, :decimal
|
21
|
-
end
|
22
|
-
test_object = TestObject.new
|
23
|
-
response = test_object.put_properties_and_get_representation({ 'name' => { 'value' => 'john smith' },
|
24
|
-
'age' => { 'value' => '29' },
|
25
|
-
'weight' => { 'value' => '71.5' } }.to_json)
|
26
|
-
expect(response.body).to match_json_expression({ 'members' => {
|
27
|
-
'name' => { 'value' => 'john smith' },
|
28
|
-
'age' => { 'value' => 29 },
|
29
|
-
'weight' => { 'value' => 71.5 }
|
30
|
-
}
|
31
|
-
})
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
data/spec/unit/type_list_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
describe RestfulObjects::DomainModel do
|
5
|
-
before(:all) do
|
6
|
-
RestfulObjects::DomainModel.current.reset
|
7
|
-
|
8
|
-
class DomainObject
|
9
|
-
include RestfulObjects::Object
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should generate domain types list resource' do
|
14
|
-
expected = {
|
15
|
-
'links' => [
|
16
|
-
{ 'rel' => 'self',
|
17
|
-
'href' => 'http://localhost/domain-types',
|
18
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/type-list"',
|
19
|
-
'method' => 'GET' },
|
20
|
-
{ 'rel' => 'up',
|
21
|
-
'href' => 'http://localhost/',
|
22
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/homepage"',
|
23
|
-
'method' => 'GET' }
|
24
|
-
],
|
25
|
-
'value' => [
|
26
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/domain-type',
|
27
|
-
'href' => "http://localhost/domain-types/#{DomainObject}",
|
28
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
|
29
|
-
'method' => 'GET' }
|
30
|
-
],
|
31
|
-
'extensions' => {}
|
32
|
-
}.to_json
|
33
|
-
|
34
|
-
RestfulObjects::DomainModel.current.get_type_list_representation
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|