rod-rest 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/changelog.txt +4 -0
- data/lib/rod/rest/collection_proxy.rb +4 -2
- data/lib/rod/rest/constants.rb +1 -1
- data/lib/rod/rest/property_metadata.rb +1 -1
- data/lib/rod/rest/proxy.rb +17 -5
- data/test/spec/collection_proxy.rb +11 -0
- data/test/spec/proxy.rb +10 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/changelog.txt
CHANGED
@@ -62,8 +62,10 @@ module Rod
|
|
62
62
|
# Iterates over the elements of the collection.
|
63
63
|
def each
|
64
64
|
if block_given?
|
65
|
-
|
66
|
-
|
65
|
+
if @size > 0
|
66
|
+
self[0..@size-1].each do |object|
|
67
|
+
yield object
|
68
|
+
end
|
67
69
|
end
|
68
70
|
else
|
69
71
|
enum_for(:each)
|
data/lib/rod/rest/constants.rb
CHANGED
data/lib/rod/rest/proxy.rb
CHANGED
@@ -38,7 +38,7 @@ module Rod
|
|
38
38
|
private
|
39
39
|
def build_class(metadata)
|
40
40
|
Class.new do
|
41
|
-
|
41
|
+
instance_variable_set("@metadata",metadata)
|
42
42
|
|
43
43
|
attr_reader :type,:rod_id
|
44
44
|
|
@@ -96,24 +96,36 @@ module Rod
|
|
96
96
|
|
97
97
|
private
|
98
98
|
def inspect_fields
|
99
|
-
|
99
|
+
metadata.fields.map do |field|
|
100
100
|
"#{field.name}:#{self.send(field.symbolic_name)}"
|
101
101
|
end.join(",")
|
102
102
|
end
|
103
103
|
|
104
104
|
def inspect_singular_associations
|
105
|
-
|
105
|
+
metadata.singular_associations.map do |association|
|
106
106
|
description = instance_variable_get("@_#{association.name}_description")
|
107
|
-
|
107
|
+
if description
|
108
|
+
"#{association.name}:#{description[:type]}:#{description[:rod_id]}"
|
109
|
+
else
|
110
|
+
"#{association.name}:nil"
|
111
|
+
end
|
108
112
|
end.join(",")
|
109
113
|
end
|
110
114
|
|
111
115
|
def inspect_plural_associations
|
112
|
-
|
116
|
+
metadata.plural_associations.map do |association|
|
113
117
|
count = instance_variable_get("@_#{association.name}_count")
|
114
118
|
"#{association.name}[#{count}]"
|
115
119
|
end.join(",")
|
116
120
|
end
|
121
|
+
|
122
|
+
def metadata
|
123
|
+
self.class.metadata
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.metadata
|
127
|
+
@metadata
|
128
|
+
end
|
117
129
|
end
|
118
130
|
end
|
119
131
|
|
@@ -150,6 +150,17 @@ module Rod
|
|
150
150
|
drivers = [schumaher,kubica,alonzo]
|
151
151
|
collection.each.map{|e| e }.should == drivers
|
152
152
|
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "with 0 drivers" do
|
158
|
+
let(:size) { 0 }
|
159
|
+
|
160
|
+
describe "#each" do
|
161
|
+
it "doesn't call the block" do
|
162
|
+
lambda { collection.each{|e| raise "Should not be executed" } }.should_not raise_error(Exception)
|
163
|
+
end
|
153
164
|
end
|
154
165
|
end
|
155
166
|
end
|
data/test/spec/proxy.rb
CHANGED
@@ -35,13 +35,14 @@ 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: owner_hash, drivers: { count: drivers_count } } }
|
39
39
|
let(:mercedes_300_id) { 1 }
|
40
40
|
let(:mercedes_300_name) { "Mercedes 300" }
|
41
41
|
|
42
42
|
let(:person_type) { "Test::Person" }
|
43
43
|
let(:drivers_count) { 1 }
|
44
44
|
let(:schumaher_hash) { { rod_id: schumaher_id, type: person_type } }
|
45
|
+
let(:owner_hash) { schumaher_hash }
|
45
46
|
let(:schumaher_id) { 2 }
|
46
47
|
let(:schumaher_object) { Object.new }
|
47
48
|
let(:owner_object) { schumaher_object }
|
@@ -118,6 +119,14 @@ module Rod
|
|
118
119
|
it "reports the drivers of the car" do
|
119
120
|
mercedes_300.inspect.should match(/drivers\[#{drivers_count}\]/)
|
120
121
|
end
|
122
|
+
|
123
|
+
context "with nil owner" do
|
124
|
+
let(:owner_hash) { nil }
|
125
|
+
|
126
|
+
it "reports nil owner" do
|
127
|
+
mercedes_300.inspect.should match(/owner:nil/)
|
128
|
+
end
|
129
|
+
end
|
121
130
|
end
|
122
131
|
|
123
132
|
describe "#to_s" do
|