restful_objects 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +3 -2
  3. data/bin/restful_server.rb +0 -0
  4. data/lib/restful_objects/action_description.rb +96 -82
  5. data/lib/restful_objects/action_list.rb +17 -17
  6. data/lib/restful_objects/collection_description.rb +47 -47
  7. data/lib/restful_objects/collection_list.rb +17 -17
  8. data/lib/restful_objects/domain_model.rb +83 -79
  9. data/lib/restful_objects/http_response.rb +11 -11
  10. data/lib/restful_objects/link_generator.rb +104 -104
  11. data/lib/restful_objects/object.rb +20 -20
  12. data/lib/restful_objects/object_actions.rb +134 -134
  13. data/lib/restful_objects/object_base.rb +10 -0
  14. data/lib/restful_objects/object_collections.rb +84 -84
  15. data/lib/restful_objects/object_list.rb +16 -16
  16. data/lib/restful_objects/object_macros.rb +35 -35
  17. data/lib/restful_objects/object_properties.rb +78 -78
  18. data/lib/restful_objects/parameter_description.rb +60 -60
  19. data/lib/restful_objects/parameter_description_list.rb +15 -15
  20. data/lib/restful_objects/property_description.rb +68 -68
  21. data/lib/restful_objects/property_list.rb +17 -17
  22. data/lib/restful_objects/service.rb +21 -21
  23. data/lib/restful_objects/service_list.rb +55 -55
  24. data/lib/restful_objects/type.rb +110 -110
  25. data/lib/restful_objects/type_list.rb +30 -30
  26. data/lib/restful_objects/user.rb +30 -30
  27. data/lib/restful_objects/version.rb +1 -1
  28. data/spec/integration/domain-types_actions_spec.rb +43 -43
  29. data/spec/integration/domain-types_collections_spec.rb +45 -45
  30. data/spec/integration/domain-types_properties_spec.rb +41 -41
  31. data/spec/integration/server-root_spec.rb +98 -98
  32. data/spec/spec_helper.rb +52 -52
  33. data/spec/unit/object_actions_spec.rb +380 -380
  34. data/spec/unit/object_collections_spec.rb +190 -190
  35. data/spec/unit/object_properties_spec.rb +215 -206
  36. data/spec/unit/object_spec.rb +228 -228
  37. data/spec/unit/service_spec.rb +125 -125
  38. data/spec/unit/type_list_spec.rb +37 -37
  39. metadata +2 -2
@@ -1,125 +1,125 @@
1
- # encoding: utf-8
2
- require_relative '../spec_helper'
3
-
4
- describe RestfulObjects::Service do
5
- before :all do
6
- RestfulObjects::DomainModel.current.reset
7
-
8
- class ServiceTest
9
- include RestfulObjects::Service
10
-
11
- action :do_something
12
-
13
- def do_something
14
- end
15
- end
16
- end
17
-
18
- it 'should be registered and created automatically ' do
19
- RestfulObjects::DomainModel.current.services.include?('ServiceTest').should be_true
20
- RestfulObjects::DomainModel.current.services['ServiceTest'].should_not be_nil
21
- RestfulObjects::DomainModel.current.services['ServiceTest'].is_service.should be_true
22
- end
23
-
24
- it 'should generate json for the service' do
25
- service = RestfulObjects::DomainModel.current.services['ServiceTest']
26
- service.title = 'Test Service'
27
-
28
- expected = {
29
- 'serviceId' => 'ServiceTest',
30
- 'title' => 'Test Service',
31
- 'members' => {
32
- 'do_something' => {
33
- 'memberType' => 'action',
34
- 'links' => [
35
- { 'rel' => 'urn:org.restfulobjects:rels/details;action="do_something"',
36
- 'href' => "http://localhost/services/ServiceTest/actions/do_something",
37
- 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-action"',
38
- 'method' => 'GET' }
39
- ],
40
- 'extensions' => { }
41
- }
42
- },
43
- 'links' => [
44
- { 'rel' => 'self',
45
- 'href' => "http://localhost/services/ServiceTest",
46
- 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
47
- 'method' => 'GET' },
48
- { 'rel' => 'describedby',
49
- 'href' => "http://localhost/domain-types/ServiceTest",
50
- 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
51
- 'method' => 'GET' }
52
- ]
53
- }
54
-
55
- get '/services/ServiceTest'
56
- last_response.body.should match_json_expression expected
57
- end
58
-
59
- it 'should not be registered as an object' do
60
- class ServiceTest
61
- include RestfulObjects::Service
62
- end
63
- instance_id = model.services['ServiceTest'].rs_instance_id
64
- model.objects.include?(instance_id).should_not be_true
65
- end
66
-
67
- it 'should generate action representation to links to services invokation' do
68
- class ServiceTest
69
- include RestfulObjects::Service
70
- action :do_something, :void
71
- end
72
-
73
- get '/services/ServiceTest/actions/do_something'
74
-
75
- expected = {
76
- 'links' => [
77
- { 'rel' => 'self',
78
- 'href' => "http://localhost/services/ServiceTest/actions/do_something",
79
- 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-action"',
80
- 'method' => 'GET' },
81
- { 'rel' => 'up',
82
- 'href' => "http://localhost/services/ServiceTest",
83
- 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
84
- 'method' => 'GET' },
85
- {
86
- 'rel' => 'urn:org.restfulobjects:rels/invoke;action="do_something"',
87
- 'href' => "http://localhost/services/ServiceTest/actions/do_something/invoke",
88
- 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
89
- 'method' => 'GET' }
90
- ]
91
- }
92
-
93
- last_response.body.should match_json_expression expected
94
- end
95
-
96
- it 'should process action from service route' do
97
- class ServiceTest
98
- include RestfulObjects::Service
99
- action :do_something, :int
100
- def do_something
101
- @something_done = true
102
- 10
103
- end
104
- end
105
-
106
- get "/services/ServiceTest/actions/do_something/invoke"
107
-
108
- last_response.body.should match_json_expression( {'resultType' => 'scalar', 'result' => { 'value' => 10 } } )
109
- end
110
-
111
- it 'should call initialize on service' do
112
- class InitializedService
113
- include RestfulObjects::Service
114
- attr_reader :init_called
115
- def initialize
116
- super
117
- @init_called = true
118
- @title = 'A title'
119
- end
120
- end
121
- model.services['InitializedService'].init_called.should be_true
122
- model.services['InitializedService'].title.should eq 'A title'
123
- end
124
- end
125
-
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+
4
+ describe RestfulObjects::Service do
5
+ before :all do
6
+ RestfulObjects::DomainModel.current.reset
7
+
8
+ class ServiceTest
9
+ include RestfulObjects::Service
10
+
11
+ action :do_something
12
+
13
+ def do_something
14
+ end
15
+ end
16
+ end
17
+
18
+ it 'should be registered and created automatically ' do
19
+ RestfulObjects::DomainModel.current.services.include?('ServiceTest').should be_true
20
+ RestfulObjects::DomainModel.current.services['ServiceTest'].should_not be_nil
21
+ RestfulObjects::DomainModel.current.services['ServiceTest'].is_service.should be_true
22
+ end
23
+
24
+ it 'should generate json for the service' do
25
+ service = RestfulObjects::DomainModel.current.services['ServiceTest']
26
+ service.title = 'Test Service'
27
+
28
+ expected = {
29
+ 'serviceId' => 'ServiceTest',
30
+ 'title' => 'Test Service',
31
+ 'members' => {
32
+ 'do_something' => {
33
+ 'memberType' => 'action',
34
+ 'links' => [
35
+ { 'rel' => 'urn:org.restfulobjects:rels/details;action="do_something"',
36
+ 'href' => "http://localhost/services/ServiceTest/actions/do_something",
37
+ 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-action"',
38
+ 'method' => 'GET' }
39
+ ],
40
+ 'extensions' => { }
41
+ }
42
+ },
43
+ 'links' => [
44
+ { 'rel' => 'self',
45
+ 'href' => "http://localhost/services/ServiceTest",
46
+ 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
47
+ 'method' => 'GET' },
48
+ { 'rel' => 'describedby',
49
+ 'href' => "http://localhost/domain-types/ServiceTest",
50
+ 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
51
+ 'method' => 'GET' }
52
+ ]
53
+ }
54
+
55
+ get '/services/ServiceTest'
56
+ last_response.body.should match_json_expression expected
57
+ end
58
+
59
+ it 'should not be registered as an object' do
60
+ class ServiceTest
61
+ include RestfulObjects::Service
62
+ end
63
+ instance_id = model.services['ServiceTest'].rs_instance_id
64
+ model.objects.include?(instance_id).should_not be_true
65
+ end
66
+
67
+ it 'should generate action representation to links to services invokation' do
68
+ class ServiceTest
69
+ include RestfulObjects::Service
70
+ action :do_something
71
+ end
72
+
73
+ get '/services/ServiceTest/actions/do_something'
74
+
75
+ expected = {
76
+ 'links' => [
77
+ { 'rel' => 'self',
78
+ 'href' => "http://localhost/services/ServiceTest/actions/do_something",
79
+ 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object-action"',
80
+ 'method' => 'GET' },
81
+ { 'rel' => 'up',
82
+ 'href' => "http://localhost/services/ServiceTest",
83
+ 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/object"',
84
+ 'method' => 'GET' },
85
+ {
86
+ 'rel' => 'urn:org.restfulobjects:rels/invoke;action="do_something"',
87
+ 'href' => "http://localhost/services/ServiceTest/actions/do_something/invoke",
88
+ 'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-result"',
89
+ 'method' => 'GET' }
90
+ ]
91
+ }
92
+
93
+ last_response.body.should match_json_expression expected
94
+ end
95
+
96
+ it 'should process action from service route' do
97
+ class ServiceTest
98
+ include RestfulObjects::Service
99
+ action :do_something, return_type: :int
100
+ def do_something
101
+ @something_done = true
102
+ 10
103
+ end
104
+ end
105
+
106
+ get "/services/ServiceTest/actions/do_something/invoke"
107
+
108
+ last_response.body.should match_json_expression( {'resultType' => 'scalar', 'result' => { 'value' => 10 } } )
109
+ end
110
+
111
+ it 'should call initialize on service' do
112
+ class InitializedService
113
+ include RestfulObjects::Service
114
+ attr_reader :init_called
115
+ def initialize
116
+ super
117
+ @init_called = true
118
+ @title = 'A title'
119
+ end
120
+ end
121
+ model.services['InitializedService'].init_called.should be_true
122
+ model.services['InitializedService'].title.should eq 'A title'
123
+ end
124
+ end
125
+
@@ -1,37 +1,37 @@
1
- # encoding: utf-8
2
- require_relative '../spec_helper'
3
-
4
- describe RestfulObjects::TypeList 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.types.get_representation
35
- end
36
- end
37
-
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+
4
+ describe RestfulObjects::TypeList 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.types.get_representation
35
+ end
36
+ end
37
+
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Vizcay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-24 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler