rod-rest 0.0.1.1 → 0.5.0
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/Gemfile.lock +1 -1
- data/Readme.md +110 -0
- data/changelog.txt +11 -0
- data/lib/rod/rest.rb +1 -0
- data/lib/rod/rest/api.rb +148 -50
- data/lib/rod/rest/client.rb +95 -23
- data/lib/rod/rest/collection_proxy.rb +27 -5
- data/lib/rod/rest/constants.rb +1 -1
- data/lib/rod/rest/exception.rb +1 -0
- data/lib/rod/rest/metadata.rb +10 -0
- data/lib/rod/rest/property_metadata.rb +12 -0
- data/lib/rod/rest/proxy.rb +46 -1
- data/lib/rod/rest/proxy_cache.rb +65 -0
- data/lib/rod/rest/proxy_factory.rb +12 -0
- data/lib/rod/rest/resource_metadata.rb +11 -0
- data/test/int/end_to_end.rb +37 -30
- data/test/spec/api.rb +132 -35
- data/test/spec/client.rb +137 -38
- data/test/spec/collection_proxy.rb +52 -3
- data/test/spec/metadata.rb +24 -0
- data/test/spec/property_metadata.rb +31 -6
- data/test/spec/proxy.rb +50 -2
- data/test/spec/proxy_cache.rb +80 -0
- data/test/spec/proxy_factory.rb +16 -1
- data/test/spec/resource_metadata.rb +12 -0
- metadata +6 -2
data/test/spec/proxy.rb
CHANGED
@@ -35,7 +35,7 @@ module Rod
|
|
35
35
|
|
36
36
|
let(:car_type) { "Test::Car" }
|
37
37
|
let(:mercedes_300_hash) { { rod_id: mercedes_300_id, name: mercedes_300_name, type: car_type,
|
38
|
-
owner:
|
38
|
+
owner: schumaher_hash, drivers: { count: drivers_count } } }
|
39
39
|
let(:mercedes_300_id) { 1 }
|
40
40
|
let(:mercedes_300_name) { "Mercedes 300" }
|
41
41
|
|
@@ -74,13 +74,61 @@ module Rod
|
|
74
74
|
mercedes_300.name.should == mercedes_300_name
|
75
75
|
end
|
76
76
|
|
77
|
-
it "has
|
77
|
+
it "has a valid 'owner' singular association" do
|
78
78
|
mercedes_300.owner.should == owner_object
|
79
79
|
end
|
80
80
|
|
81
|
+
it "caches 'owner' singular association" do
|
82
|
+
mercedes_300.owner
|
83
|
+
mercedes_300.owner
|
84
|
+
expect(client).to have_received.fetch_object(schumaher_hash) { schumaher_object }.once
|
85
|
+
end
|
86
|
+
|
81
87
|
it "has a valid 'drivers' plural association" do
|
82
88
|
mercedes_300.drivers.should == collection_proxy
|
83
89
|
end
|
90
|
+
|
91
|
+
it "caches 'drivers' plural association" do
|
92
|
+
mercedes_300.drivers
|
93
|
+
mercedes_300.drivers
|
94
|
+
expect(collection_proxy_factory).to have_received.new(anything,drivers_association_name,drivers_count,client) { collection_proxy }.once
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#inspect" do
|
98
|
+
it "reports that it is a proxy" do
|
99
|
+
mercedes_300.inspect.should match(/Proxy/)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "reports the type of the object" do
|
103
|
+
mercedes_300.inspect.should match(/#{car_type}/)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "reports the id of the object" do
|
107
|
+
mercedes_300.inspect.should match(/#{mercedes_300_id}/)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "reports the name of the car" do
|
111
|
+
mercedes_300.inspect.should match(/name:#{mercedes_300_name}/)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "reports the owner of the car" do
|
115
|
+
mercedes_300.inspect.should match(/owner:#{person_type}:#{schumaher_id}/)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "reports the drivers of the car" do
|
119
|
+
mercedes_300.inspect.should match(/drivers\[#{drivers_count}\]/)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#to_s" do
|
124
|
+
it "reports the type of the object" do
|
125
|
+
mercedes_300.to_s.should match(/#{car_type}/)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "reports the id of the object" do
|
129
|
+
mercedes_300.to_s.should match(/#{mercedes_300_id}/)
|
130
|
+
end
|
131
|
+
end
|
84
132
|
end
|
85
133
|
end
|
86
134
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require_relative 'test_helper'
|
3
|
+
require 'rod/rest/proxy_cache'
|
4
|
+
|
5
|
+
module Rod
|
6
|
+
module Rest
|
7
|
+
describe ProxyCache do
|
8
|
+
let(:cache) { ProxyCache.new }
|
9
|
+
let(:object) { object = stub!.rod_id { object_id }.subject
|
10
|
+
stub(object).type { object_type }
|
11
|
+
object
|
12
|
+
}
|
13
|
+
let(:object_id) { 1 }
|
14
|
+
let(:object_type) { "Car" }
|
15
|
+
let(:description) { {rod_id: object_id, type: object_type} }
|
16
|
+
|
17
|
+
describe "#store" do
|
18
|
+
it "stores objects" do
|
19
|
+
cache.store(object).should == object
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises InvalidData if the object cannot be stored" do
|
23
|
+
lambda { cache.store(Object.new) }.should raise_error(InvalidData)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#has_key?" do
|
28
|
+
context "without object in the cache" do
|
29
|
+
it "returns false" do
|
30
|
+
cache.has_key?(description).should == false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with object in the cache" do
|
35
|
+
before do
|
36
|
+
cache.store(object)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns true" do
|
40
|
+
cache.has_key?(description).should == true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with invalid description" do
|
45
|
+
let(:description) { Object.new }
|
46
|
+
|
47
|
+
it "raises InvalidData exception" do
|
48
|
+
lambda { cache.has_key?(description) }.should raise_error(InvalidData)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#[description]" do
|
54
|
+
context "with object in the cache" do
|
55
|
+
before do
|
56
|
+
cache.store(object)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns the object" do
|
60
|
+
cache[description].should == object
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "without object in the cache" do
|
65
|
+
it "raises CacheMissed exception" do
|
66
|
+
lambda { cache[description] }.should raise_error(CacheMissed)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with invalid description" do
|
71
|
+
let(:description) { Object.new }
|
72
|
+
|
73
|
+
it "raises InvalidData exception" do
|
74
|
+
lambda { cache[description] }.should raise_error(InvalidData)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/test/spec/proxy_factory.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rod/rest/proxy_factory'
|
|
5
5
|
module Rod
|
6
6
|
module Rest
|
7
7
|
describe ProxyFactory do
|
8
|
-
let(:factory) { ProxyFactory.new(metadata,client,proxy_class: proxy_class) }
|
8
|
+
let(:factory) { ProxyFactory.new(metadata,client,proxy_class: proxy_class,cache: cache) }
|
9
9
|
let(:metadata) { [car_metadata,person_metadata] }
|
10
10
|
let(:car_metadata) { stub!.name { car_type }.subject }
|
11
11
|
let(:person_metadata) { stub!.name { person_type }.subject }
|
@@ -17,6 +17,7 @@ module Rod
|
|
17
17
|
stub(klass).new(person_metadata,client) { person_proxy_factory }
|
18
18
|
klass
|
19
19
|
}
|
20
|
+
let(:cache) { nil }
|
20
21
|
let(:car_proxy_factory) { stub!.new(mercedes_300_hash) { mercedes_300 }.subject }
|
21
22
|
let(:person_proxy_factory) { stub!.new(schumaher_hash) { schumaher }.subject }
|
22
23
|
let(:mercedes_300_hash) { { rod_id: mercedes_300_id, type: car_type } }
|
@@ -39,6 +40,20 @@ module Rod
|
|
39
40
|
it "raises UnknownResource for unknown resource type" do
|
40
41
|
lambda { factory.build(unknown_hash) }.should raise_error(UnknownResource)
|
41
42
|
end
|
43
|
+
|
44
|
+
describe "with cache" do
|
45
|
+
let(:cache) { cache = mock!.has_key?(mercedes_300_hash) { false }.subject
|
46
|
+
mock(cache).has_key?(mercedes_300_hash) { true }
|
47
|
+
mock(cache).[](mercedes_300_hash) { mercedes_300 }
|
48
|
+
cache
|
49
|
+
}
|
50
|
+
|
51
|
+
it "doesn't create objects twice" do
|
52
|
+
factory.build(mercedes_300_hash)
|
53
|
+
factory.build(mercedes_300_hash)
|
54
|
+
expect(car_proxy_factory).to have_received.new(mercedes_300_hash).once
|
55
|
+
end
|
56
|
+
end
|
42
57
|
end
|
43
58
|
end
|
44
59
|
end
|
@@ -90,6 +90,18 @@ module Rod
|
|
90
90
|
it "allows to iterate over the indexed properties" do
|
91
91
|
resource_metadata.indexed_properties.should respond_to(:each)
|
92
92
|
end
|
93
|
+
|
94
|
+
describe "#inspect" do
|
95
|
+
it "reports the description of the metadata" do
|
96
|
+
resource_metadata.inspect.should == description.inspect
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#to_s" do
|
101
|
+
it "reports the description of the metadata" do
|
102
|
+
resource_metadata.to_s.should == description.to_s
|
103
|
+
end
|
104
|
+
end
|
93
105
|
end
|
94
106
|
end
|
95
107
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rod-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- Gemfile.lock
|
122
122
|
- Rakefile
|
123
123
|
- Readme.md
|
124
|
+
- changelog.txt
|
124
125
|
- lib/rod/rest.rb
|
125
126
|
- lib/rod/rest/api.rb
|
126
127
|
- lib/rod/rest/client.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- lib/rod/rest/naming.rb
|
133
134
|
- lib/rod/rest/property_metadata.rb
|
134
135
|
- lib/rod/rest/proxy.rb
|
136
|
+
- lib/rod/rest/proxy_cache.rb
|
135
137
|
- lib/rod/rest/proxy_factory.rb
|
136
138
|
- lib/rod/rest/resource_metadata.rb
|
137
139
|
- rod-rest.gemspec
|
@@ -143,6 +145,7 @@ files:
|
|
143
145
|
- test/spec/metadata.rb
|
144
146
|
- test/spec/property_metadata.rb
|
145
147
|
- test/spec/proxy.rb
|
148
|
+
- test/spec/proxy_cache.rb
|
146
149
|
- test/spec/proxy_factory.rb
|
147
150
|
- test/spec/resource_metadata.rb
|
148
151
|
- test/spec/test_helper.rb
|
@@ -171,3 +174,4 @@ signing_key:
|
|
171
174
|
specification_version: 3
|
172
175
|
summary: REST API for ROD
|
173
176
|
test_files: []
|
177
|
+
has_rdoc:
|