Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add more specs and fix them.

  • Loading branch information...
commit a10ae318b972bcb9516a9b4401ecd4d1575e6066 1 parent eaa74f0
@christoph-buente christoph-buente authored
View
1  .gitignore
@@ -38,3 +38,4 @@ test/version_tmp
tmp
tmtags
tramp
+vendor
View
1  .rbenv-version
@@ -0,0 +1 @@
+1.9.3-p0
View
2  lib/open_street_map/node.rb
@@ -44,7 +44,7 @@ def to_xml(options = {})
xml.osm do
xml.node(attributes) do
tags.each do |k,v|
- xml.tag(:k => k, :v => v)
+ xml.tag(:k => k, :v => v) unless v.blank?
end unless tags.empty?
end
end
View
2  lib/open_street_map/relation.rb
@@ -16,7 +16,7 @@ class Relation < Element
# If +id+ is +nil+ a new unique negative ID will be allocated.
def initialize(attrs)
attrs.stringify_keys!
- @members = attrs('members')
+ @members = attrs['member']
super(attrs)
end
View
50 spec/open_street_map/node_spec.rb
@@ -2,7 +2,7 @@
describe 'OpenStreetMap::Node' do
- let :node do
+ subject do
OpenStreetMap::Node.new(:id => "123",
:lat => "52.2",
:lon => "13.4",
@@ -13,77 +13,75 @@
:timestamp => "2005-07-30T14:27:12+01:00")
end
- it "should be valid" do
- node.should be_valid
- end
+ it { should be_valid }
it "should be invalid without lat, lon" do
- node.lat = nil
- node.lon = nil
- node.should_not be_valid
+ subject.lat = nil
+ subject.lon = nil
+ subject.should_not be_valid
end
it "should not be valid when using to large lat value" do
- node.lat = 181
- node.should_not be_valid
+ subject.lat = 181
+ subject.should_not be_valid
end
it "should not be valid when using to large lat value" do
- node.lon = 91
- node.should_not be_valid
+ subject.lon = 91
+ subject.should_not be_valid
end
it "should have an id attribute set from attributes" do
- node.id.should eql(123)
+ subject.id.should eql(123)
end
it "should have an id attribute within xml representation" do
- node.to_xml.should match /id=\"123\"/
+ subject.to_xml.should match /id=\"123\"/
end
it "should have a lat attribute set from attributes" do
- node.lat.should eql(52.2)
+ subject.lat.should eql(52.2)
end
it "should have a lat attribute within xml representation" do
- node.to_xml.should match /lat=\"52.2\"/
+ subject.to_xml.should match /lat=\"52.2\"/
end
it "should have a lon attribute set from attributes" do
- node.lon.should eql(13.4)
+ subject.lon.should eql(13.4)
end
it "should have a lon attribute within xml representation" do
- node.to_xml.should match /lon=\"13.4\"/
+ subject.to_xml.should match /lon=\"13.4\"/
end
it "should have a user attributes set from attributes" do
- node.user.should eql("fred")
+ subject.user.should eql("fred")
end
it "should have a user attribute within xml representation" do
- node.to_xml.should match /user=\"fred\"/
+ subject.to_xml.should match /user=\"fred\"/
end
it "should have a changeset attributes set from attributes" do
- node.changeset.should eql(12)
+ subject.changeset.should eql(12)
end
it "should have a changeset attribute within xml representation" do
- node.to_xml.should match /changeset=\"12\"/
+ subject.to_xml.should match /changeset=\"12\"/
end
it "should have a uid attribute set from attributes" do
- node.uid.should eql(123)
+ subject.uid.should eql(123)
end
it "should have a uid attribute within xml representation" do
- node.to_xml.should match /uid=\"123\"/
+ subject.to_xml.should match /uid=\"123\"/
end
it "should produce xml" do
- node.add_tags(:wheelchair => 'yes')
- node.to_xml.should match /k=\"wheelchair\"/
- node.to_xml.should match /v=\"yes\"/
+ subject.add_tags(:wheelchair => 'yes')
+ subject.to_xml.should match /k=\"wheelchair\"/
+ subject.to_xml.should match /v=\"yes\"/
end
end
View
26 spec/open_street_map/relation_spec.rb
@@ -0,0 +1,26 @@
+require 'openstreetmap'
+
+describe 'OpenStreetMap::Relation' do
+
+ subject do
+ OpenStreetMap::Relation.new(:id => "123",
+ :lat => "52.2",
+ :lon => "13.4",
+ :changeset => "12",
+ :user => "fred",
+ :uid => "123",
+ :visible => true,
+ :timestamp => "2005-07-30T14:27:12+01:00",
+ :member => [
+ {"type"=>"relation", "ref"=>"1628007", "role"=>"outer"},
+ {"type"=>"way", "ref"=>"50197015", "role"=>""}
+ ])
+ end
+
+ it { should be_valid }
+
+ it "should have members" do
+ subject.members.size.should eql 2
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.