restful_objects 0.0.1 → 0.0.2

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.
@@ -0,0 +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
+
@@ -0,0 +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
+
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.1
4
+ version: 0.0.2
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-04-10 00:00:00.000000000 Z
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,32 +97,51 @@ dependencies:
97
97
  description: This gem is a framework for implementing Restful Objects servers.
98
98
  email:
99
99
  - pabo.vizcay@gmail.com
100
- executables: []
100
+ executables:
101
+ - restful_server.rb
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
104
- - lib/restful_objects/action_description.rb
105
+ - bin/restful_server.rb
106
+ - lib/restful_objects/server.rb
107
+ - lib/restful_objects/property_description.rb
105
108
  - lib/restful_objects/action_list.rb
106
- - lib/restful_objects/collection_description.rb
107
- - lib/restful_objects/collection_list.rb
108
- - lib/restful_objects/http_response.rb
109
- - lib/restful_objects/link_generator.rb
110
- - lib/restful_objects/model.rb
111
- - lib/restful_objects/object.rb
112
- - lib/restful_objects/object_actions.rb
113
- - lib/restful_objects/object_collections.rb
114
109
  - lib/restful_objects/object_list.rb
110
+ - lib/restful_objects/parameter_description_list.rb
111
+ - lib/restful_objects/user.rb
115
112
  - lib/restful_objects/object_macros.rb
113
+ - lib/restful_objects/domain_model.rb
114
+ - lib/restful_objects/collection_list.rb
115
+ - lib/restful_objects/link_generator.rb
116
116
  - lib/restful_objects/object_properties.rb
117
+ - lib/restful_objects/service.rb
118
+ - lib/restful_objects/action_description.rb
119
+ - lib/restful_objects/http_response.rb
120
+ - lib/restful_objects/object_collections.rb
121
+ - lib/restful_objects/type_list.rb
117
122
  - lib/restful_objects/parameter_description.rb
118
- - lib/restful_objects/parameter_description_list.rb
123
+ - lib/restful_objects/version.rb
124
+ - lib/restful_objects/object_base.rb
125
+ - lib/restful_objects/type.rb
126
+ - lib/restful_objects/object_actions.rb
127
+ - lib/restful_objects/object.rb
128
+ - lib/restful_objects/collection_description.rb
119
129
  - lib/restful_objects/property_list.rb
120
- - lib/restful_objects/server.rb
121
130
  - lib/restful_objects/service_list.rb
122
- - lib/restful_objects/type.rb
123
- - lib/restful_objects/type_list.rb
124
- - lib/restful_objects/user.rb
125
- - lib/restful_objects/version.rb
131
+ - lib/restful_objects.rb
132
+ - spec/integration/domain-types_properties_spec.rb
133
+ - spec/integration/domain-types_collections_spec.rb
134
+ - spec/integration/domain-types_actions_spec.rb
135
+ - spec/integration/server-root_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/unit/service_spec.rb
138
+ - spec/unit/object_collections_spec.rb
139
+ - spec/unit/object_properties_spec.rb
140
+ - spec/unit/object_spec.rb
141
+ - spec/unit/type_list_spec.rb
142
+ - spec/unit/object_actions_spec.rb
143
+ - LICENSE
144
+ - README.md
126
145
  homepage: https://github.com/vizcay/RestfulObjectsRuby
127
146
  licenses:
128
147
  - MIT
@@ -147,5 +166,15 @@ rubygems_version: 2.1.9
147
166
  signing_key:
148
167
  specification_version: 4
149
168
  summary: This gem is a framework for implementing Restful Objects servers.
150
- test_files: []
151
- has_rdoc:
169
+ test_files:
170
+ - spec/integration/domain-types_properties_spec.rb
171
+ - spec/integration/domain-types_collections_spec.rb
172
+ - spec/integration/domain-types_actions_spec.rb
173
+ - spec/integration/server-root_spec.rb
174
+ - spec/spec_helper.rb
175
+ - spec/unit/service_spec.rb
176
+ - spec/unit/object_collections_spec.rb
177
+ - spec/unit/object_properties_spec.rb
178
+ - spec/unit/object_spec.rb
179
+ - spec/unit/type_list_spec.rb
180
+ - spec/unit/object_actions_spec.rb