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.
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- rod-rest (0.0.1.1)
15
+ rod-rest (0.5.1)
16
16
  faraday
17
17
  rod
18
18
  sinatra
@@ -1,3 +1,7 @@
1
+ 0.5.1
2
+ Fix CollectionProxy#each for empty collection
3
+ Fix inspection of proxy
4
+ Fix access to metadata in Proxy
1
5
  0.5.0
2
6
  #inspect & #to_s for major classes
3
7
  ProxyCache
@@ -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
- self[0..@size-1].each do |object|
66
- yield object
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)
@@ -1,5 +1,5 @@
1
1
  module Rod
2
2
  module Rest
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ module Rod
20
20
  # Rod::Rest::PropertyMetadata<name>
21
21
  def inspect
22
22
  indexed = indexed? ? ",indexed" : ""
23
- "#{self.class}<#{@name}#{indexed}>"
23
+ "Property<#{@name}#{indexed}>"
24
24
  end
25
25
 
26
26
  # Short description of the poperty.
@@ -38,7 +38,7 @@ module Rod
38
38
  private
39
39
  def build_class(metadata)
40
40
  Class.new do
41
- class_variable_set("@@metadata",metadata)
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
- @@metadata.fields.map do |field|
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
- @@metadata.singular_associations.map do |association|
105
+ metadata.singular_associations.map do |association|
106
106
  description = instance_variable_get("@_#{association.name}_description")
107
- "#{association.name}:#{description[:type]}:#{description[:rod_id]}"
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
- @@metadata.plural_associations.map do |association|
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
@@ -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: schumaher_hash, drivers: { count: drivers_count } } }
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
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.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: