rod-rest 0.0.1
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.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +69 -0
- data/Rakefile +21 -0
- data/Readme.md +3 -0
- data/lib/rod/rest.rb +14 -0
- data/lib/rod/rest/api.rb +100 -0
- data/lib/rod/rest/client.rb +215 -0
- data/lib/rod/rest/collection_proxy.rb +52 -0
- data/lib/rod/rest/constants.rb +5 -0
- data/lib/rod/rest/exception.rb +8 -0
- data/lib/rod/rest/json_serializer.rb +59 -0
- data/lib/rod/rest/metadata.rb +38 -0
- data/lib/rod/rest/naming.rb +20 -0
- data/lib/rod/rest/property_metadata.rb +20 -0
- data/lib/rod/rest/proxy.rb +121 -0
- data/lib/rod/rest/proxy_factory.rb +30 -0
- data/lib/rod/rest/resource_metadata.rb +32 -0
- data/rod-rest.gemspec +32 -0
- data/test/int/end_to_end.rb +138 -0
- data/test/spec/api.rb +210 -0
- data/test/spec/client.rb +248 -0
- data/test/spec/collection_proxy.rb +109 -0
- data/test/spec/json_serializer.rb +108 -0
- data/test/spec/metadata.rb +37 -0
- data/test/spec/property_metadata.rb +63 -0
- data/test/spec/proxy.rb +87 -0
- data/test/spec/proxy_factory.rb +44 -0
- data/test/spec/resource_metadata.rb +96 -0
- data/test/spec/test_helper.rb +28 -0
- metadata +173 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
require_relative 'test_helper'
|
|
3
|
+
require 'rod/rest/resource_metadata'
|
|
4
|
+
|
|
5
|
+
module Rod
|
|
6
|
+
module Rest
|
|
7
|
+
describe ResourceMetadata do
|
|
8
|
+
describe "with description of 2 fields, 1 singular association and 1 plural association" do
|
|
9
|
+
let(:resource_metadata) { ResourceMetadata.new(name,description, property_factory: property_factory) }
|
|
10
|
+
let(:name) { :Car }
|
|
11
|
+
let(:description) { { fields: fields, has_one: singular_associations, has_many: plural_associations } }
|
|
12
|
+
let(:fields) { [brand_field,age_field] }
|
|
13
|
+
let(:singular_associations) { [owner_association] }
|
|
14
|
+
let(:plural_associations) { [drivers_association] }
|
|
15
|
+
let(:brand_field) { Object.new }
|
|
16
|
+
let(:brand_property) { property = stub!.indexed? { true }.subject }
|
|
17
|
+
let(:age_field) { Object.new }
|
|
18
|
+
let(:age_property) { property = stub!.indexed? { false }.subject }
|
|
19
|
+
let(:owner_association) { Object.new }
|
|
20
|
+
let(:owner_property) { property = stub!.indexed? { false }.subject }
|
|
21
|
+
let(:drivers_association) { Object.new }
|
|
22
|
+
let(:drivers_property) { property = stub!.indexed? { false }.subject }
|
|
23
|
+
let(:property_factory) { factory = stub!.new(brand_field) { brand_property} .subject
|
|
24
|
+
stub(factory).new(age_field) { age_property }
|
|
25
|
+
stub(factory).new(owner_association) { owner_property }
|
|
26
|
+
stub(factory).new(drivers_association) { drivers_property }
|
|
27
|
+
factory
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
it "has a String name" do
|
|
31
|
+
resource_metadata.name.should be_a(String)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "returns its name" do
|
|
35
|
+
resource_metadata.name.should == name.to_s
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "has 2 fields" do
|
|
39
|
+
resource_metadata.fields.size.should == 2
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "allows to iterate over the fields" do
|
|
43
|
+
resource_metadata.fields.should respond_to(:each)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "uses the factory to create the fields" do
|
|
47
|
+
resource_metadata.fields
|
|
48
|
+
expect(property_factory).to have_received.new(brand_field)
|
|
49
|
+
expect(property_factory).to have_received.new(age_field)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "has 1 singular association" do
|
|
53
|
+
resource_metadata.singular_associations.size.should == 1
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "allows to iterate over the singular associations" do
|
|
57
|
+
resource_metadata.singular_associations.should respond_to(:each)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "uses the factory to create the singular associations" do
|
|
61
|
+
resource_metadata.singular_associations
|
|
62
|
+
expect(property_factory).to have_received.new(owner_association)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "has 1 plural association" do
|
|
66
|
+
resource_metadata.plural_associations.size.should == 1
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "allows to iterate over the plural associations" do
|
|
70
|
+
resource_metadata.plural_associations.should respond_to(:each)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "uses the factory to create the plural associations" do
|
|
74
|
+
resource_metadata.plural_associations
|
|
75
|
+
expect(property_factory).to have_received.new(drivers_association)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "has 4 properties" do
|
|
79
|
+
resource_metadata.properties.size.should == 4
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "allows to iterate over the properties" do
|
|
83
|
+
resource_metadata.properties.should respond_to(:each)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "has 1 indexed property" do
|
|
87
|
+
resource_metadata.indexed_properties.size.should == 1
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "allows to iterate over the indexed properties" do
|
|
91
|
+
resource_metadata.indexed_properties.should respond_to(:each)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'rack/test'
|
|
2
|
+
require 'rr'
|
|
3
|
+
|
|
4
|
+
ENV['RACK_ENV'] = 'test'
|
|
5
|
+
|
|
6
|
+
def stub_module(full_name)
|
|
7
|
+
full_name.to_s.split(/::/).inject(Object) do |context, name|
|
|
8
|
+
begin
|
|
9
|
+
context.const_get(name)
|
|
10
|
+
rescue NameError
|
|
11
|
+
context.const_set(name, Module.new)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def stub_class(full_name)
|
|
17
|
+
full_name.to_s.split(/::/).inject(Object) do |context, name|
|
|
18
|
+
begin
|
|
19
|
+
context.const_get(name)
|
|
20
|
+
rescue NameError
|
|
21
|
+
if /#{name}$/ =~ full_name
|
|
22
|
+
context.const_set(name, Class.new)
|
|
23
|
+
else
|
|
24
|
+
context.const_set(name, Module.new)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rod-rest
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Aleksander Pohl
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: sinatra
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rod
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: faraday
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: rack-test
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: rspec
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
type: :development
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: rr
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
none: false
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ! '>='
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
description: REST API for Ruby Object Database allows for talking to the DB via HTTP.
|
|
111
|
+
email:
|
|
112
|
+
- apohllo@o2.pl
|
|
113
|
+
executables: []
|
|
114
|
+
extensions: []
|
|
115
|
+
extra_rdoc_files: []
|
|
116
|
+
files:
|
|
117
|
+
- .gitignore
|
|
118
|
+
- .rspec
|
|
119
|
+
- .ruby-version
|
|
120
|
+
- Gemfile
|
|
121
|
+
- Gemfile.lock
|
|
122
|
+
- Rakefile
|
|
123
|
+
- Readme.md
|
|
124
|
+
- lib/rod/rest.rb
|
|
125
|
+
- lib/rod/rest/api.rb
|
|
126
|
+
- lib/rod/rest/client.rb
|
|
127
|
+
- lib/rod/rest/collection_proxy.rb
|
|
128
|
+
- lib/rod/rest/constants.rb
|
|
129
|
+
- lib/rod/rest/exception.rb
|
|
130
|
+
- lib/rod/rest/json_serializer.rb
|
|
131
|
+
- lib/rod/rest/metadata.rb
|
|
132
|
+
- lib/rod/rest/naming.rb
|
|
133
|
+
- lib/rod/rest/property_metadata.rb
|
|
134
|
+
- lib/rod/rest/proxy.rb
|
|
135
|
+
- lib/rod/rest/proxy_factory.rb
|
|
136
|
+
- lib/rod/rest/resource_metadata.rb
|
|
137
|
+
- rod-rest.gemspec
|
|
138
|
+
- test/int/end_to_end.rb
|
|
139
|
+
- test/spec/api.rb
|
|
140
|
+
- test/spec/client.rb
|
|
141
|
+
- test/spec/collection_proxy.rb
|
|
142
|
+
- test/spec/json_serializer.rb
|
|
143
|
+
- test/spec/metadata.rb
|
|
144
|
+
- test/spec/property_metadata.rb
|
|
145
|
+
- test/spec/proxy.rb
|
|
146
|
+
- test/spec/proxy_factory.rb
|
|
147
|
+
- test/spec/resource_metadata.rb
|
|
148
|
+
- test/spec/test_helper.rb
|
|
149
|
+
homepage: http://github.com/apohllo/rod-rest
|
|
150
|
+
licenses: []
|
|
151
|
+
post_install_message:
|
|
152
|
+
rdoc_options: []
|
|
153
|
+
require_paths:
|
|
154
|
+
- lib
|
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
|
+
none: false
|
|
157
|
+
requirements:
|
|
158
|
+
- - '='
|
|
159
|
+
- !ruby/object:Gem::Version
|
|
160
|
+
version: 1.9.2
|
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
|
+
none: false
|
|
163
|
+
requirements:
|
|
164
|
+
- - ! '>='
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0'
|
|
167
|
+
requirements: []
|
|
168
|
+
rubyforge_project: rod-rest
|
|
169
|
+
rubygems_version: 1.8.25
|
|
170
|
+
signing_key:
|
|
171
|
+
specification_version: 3
|
|
172
|
+
summary: REST API for ROD
|
|
173
|
+
test_files: []
|