Skip to content

Commit

Permalink
Don't fail if the returned value is nil because we might have nested …
Browse files Browse the repository at this point in the history
…properties.
  • Loading branch information
Robert Ross committed Aug 12, 2014
1 parent 4723984 commit c033126
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/kartograph/property.rb
Expand Up @@ -25,6 +25,7 @@ def key

def value_for(object, scope = nil)
value = object.send(name)
return if value.nil?
map ? artist_value(value, scope) : value
end

Expand Down
12 changes: 12 additions & 0 deletions spec/lib/kartograph/property_spec.rb
Expand Up @@ -109,6 +109,18 @@
])
end
end

context 'when the value for the root object is nil' do
it 'returns nil' do
top_level = Kartograph::Property.new(:sammy) do
property :cephalopod
end

root = double(sammy: nil)

expect(top_level.value_for(root)).to be_nil
end
end
end
end

Expand Down

0 comments on commit c033126

Please sign in to comment.