Style/NumericLiterals:
MinDigits: 11
-# Offense count: 20
-Style/OptionalBooleanParameter:
- Exclude:
- - 'app/models/changeset.rb'
- - 'app/models/node.rb'
- - 'app/models/relation.rb'
- - 'app/models/trace.rb'
- - 'app/models/tracepoint.rb'
- - 'app/models/way.rb'
-
# Offense count: 28
# Cop supports --auto-correct.
Style/StringConcatenation:
def create
assert_method :put
- cs = Changeset.from_xml(request.raw_post, true)
+ cs = Changeset.from_xml(request.raw_post, :create => true)
# Assume that Changeset.from_xml has thrown an exception if there is an error parsing the xml
cs.user = current_user
def create
assert_method :put
- node = Node.from_xml(request.raw_post, true)
+ node = Node.from_xml(request.raw_post, :create => true)
# Assume that Node.from_xml has thrown an exception if there is an error parsing the xml
node.create_with_history current_user
def create
assert_method :put
- relation = Relation.from_xml(request.raw_post, true)
+ relation = Relation.from_xml(request.raw_post, :create => true)
# Assume that Relation.from_xml has thrown an exception if there is an error parsing the xml
relation.create_with_history current_user
end
end
- trkseg << point.to_xml_node(timestamps)
+ trkseg << point.to_xml_node(:print_timestamp => timestamps)
end
response.headers["Content-Disposition"] = "attachment; filename=\"tracks.gpx\""
def create
assert_method :put
- way = Way.from_xml(request.raw_post, true)
+ way = Way.from_xml(request.raw_post, :create => true)
# Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
way.create_with_history current_user
self.closed_at = Time.now.getutc if is_open?
end
- def self.from_xml(xml, create = false)
+ def self.from_xml(xml, create: false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
pt = doc.find_first("//osm/changeset")
if pt
- Changeset.from_xml_node(pt, create)
+ Changeset.from_xml_node(pt, :create => create)
else
raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
end
raise OSM::APIBadXMLError.new("changeset", xml, e.message)
end
- def self.from_xml_node(pt, create = false)
+ def self.from_xml_node(pt, create: false)
cs = Changeset.new
if create
cs.created_at = Time.now.getutc
end
# Read in xml as text and return it's Node object representation
- def self.from_xml(xml, create = false)
+ def self.from_xml(xml, create: false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
pt = doc.find_first("//osm/node")
if pt
- Node.from_xml_node(pt, create)
+ Node.from_xml_node(pt, :create => create)
else
raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
end
raise OSM::APIBadXMLError.new("node", xml, e.message)
end
- def self.from_xml_node(pt, create = false)
+ def self.from_xml_node(pt, create: false)
node = Node.new
raise OSM::APIBadXMLError.new("node", pt, "lat missing") if pt["lat"].nil?
TYPES = %w[node way relation].freeze
- def self.from_xml(xml, create = false)
+ def self.from_xml(xml, create: false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
pt = doc.find_first("//osm/relation")
if pt
- Relation.from_xml_node(pt, create)
+ Relation.from_xml_node(pt, :create => create)
else
raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
end
raise OSM::APIBadXMLError.new("relation", xml, e.message)
end
- def self.from_xml_node(pt, create = false)
+ def self.from_xml_node(pt, create: false)
relation = Relation.new
raise OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil?
end
end
- def update_from_xml(xml, create = false)
+ def update_from_xml(xml, create: false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
pt = doc.find_first("//osm/gpx_file")
if pt
- update_from_xml_node(pt, create)
+ update_from_xml_node(pt, :create => create)
else
raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
end
raise OSM::APIBadXMLError.new("trace", xml, e.message)
end
- def update_from_xml_node(pt, create = false)
+ def update_from_xml_node(pt, create: false)
raise OSM::APIBadXMLError.new("trace", pt, "visibility missing") if pt["visibility"].nil?
self.visibility = pt["visibility"]
belongs_to :trace, :foreign_key => "gpx_id"
- def to_xml_node(print_timestamp = false)
+ def to_xml_node(print_timestamp: false)
el1 = XML::Node.new "trkpt"
el1["lat"] = lat.to_s
el1["lon"] = lon.to_s
scope :invisible, -> { where(:visible => false) }
# Read in xml as text and return it's Way object representation
- def self.from_xml(xml, create = false)
+ def self.from_xml(xml, create: false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
pt = doc.find_first("//osm/way")
if pt
- Way.from_xml_node(pt, create)
+ Way.from_xml_node(pt, :create => create)
else
raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
end
raise OSM::APIBadXMLError.new("way", xml, e.message)
end
- def self.from_xml_node(pt, create = false)
+ def self.from_xml_node(pt, create: false)
way = Way.new
raise OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt["version"].nil?
# create a new element. this code is agnostic of the element type
# because all the elements support the methods that we're using.
with_model do |model, xml|
- new = model.from_xml_node(xml, true)
+ new = model.from_xml_node(xml, :create => true)
check(model, xml, new)
# when this element is saved it will get a new ID, so we save it
# with types, but uses duck typing to handle them transparently.
with_model do |model, xml|
# get the new element from the XML payload
- new = model.from_xml_node(xml, false)
+ new = model.from_xml_node(xml, :create => false)
check(model, xml, new)
# if the ID is a placeholder then map it to the real ID
def test_from_xml_no_text
no_text = ""
message_create = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(no_text, true)
+ Changeset.from_xml(no_text, :create => true)
end
assert_match(/Must specify a string with one or more characters/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(no_text, false)
+ Changeset.from_xml(no_text, :create => false)
end
assert_match(/Must specify a string with one or more characters/, message_update.message)
end
def test_from_xml_no_changeset
nocs = "<osm></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(nocs, true)
+ Changeset.from_xml(nocs, :create => true)
end
assert_match %r{XML doesn't contain an osm/changeset element}, message_create.message
message_update = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(nocs, false)
+ Changeset.from_xml(nocs, :create => false)
end
assert_match %r{XML doesn't contain an osm/changeset element}, message_update.message
end
def test_from_xml_no_k_v
nokv = "<osm><changeset><tag /></changeset></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(nokv, true)
+ Changeset.from_xml(nokv, :create => true)
end
assert_match(/tag is missing key/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(nokv, false)
+ Changeset.from_xml(nokv, :create => false)
end
assert_match(/tag is missing key/, message_update.message)
end
def test_from_xml_no_v
no_v = "<osm><changeset><tag k='key' /></changeset></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(no_v, true)
+ Changeset.from_xml(no_v, :create => true)
end
assert_match(/tag is missing value/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Changeset.from_xml(no_v, false)
+ Changeset.from_xml(no_v, :create => false)
end
assert_match(/tag is missing value/, message_update.message)
end
def test_from_xml_duplicate_k
dupk = "<osm><changeset><tag k='dup' v='test' /><tag k='dup' v='value' /></changeset></osm>"
message_create = assert_raise(OSM::APIDuplicateTagsError) do
- Changeset.from_xml(dupk, true)
+ Changeset.from_xml(dupk, :create => true)
end
assert_equal "Element changeset/ has duplicate tags with key dup", message_create.message
message_update = assert_raise(OSM::APIDuplicateTagsError) do
- Changeset.from_xml(dupk, false)
+ Changeset.from_xml(dupk, :create => false)
end
assert_equal "Element changeset/ has duplicate tags with key dup", message_update.message
end
# Example taken from the Update section on the API_v0.6 docs on the wiki
xml = "<osm><changeset><tag k=\"comment\" v=\"Just adding some streetnames and a restaurant\"/></changeset></osm>"
assert_nothing_raised do
- Changeset.from_xml(xml, false)
+ Changeset.from_xml(xml, :create => false)
end
assert_nothing_raised do
- Changeset.from_xml(xml, true)
+ Changeset.from_xml(xml, :create => true)
end
end
end
noid = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset}' version='#{version}' /></osm>"
# First try a create which doesn't need the id
assert_nothing_raised do
- Node.from_xml(noid, true)
+ Node.from_xml(noid, :create => true)
end
# Now try an update with no id, and make sure that it gives the appropriate exception
message = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(noid, false)
+ Node.from_xml(noid, :create => false)
end
assert_match(/ID is required when updating./, message.message)
end
def test_from_xml_no_lat
nolat = "<osm><node id='1' lon='23.3' changeset='2' version='23' /></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nolat, true)
+ Node.from_xml(nolat, :create => true)
end
assert_match(/lat missing/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nolat, false)
+ Node.from_xml(nolat, :create => false)
end
assert_match(/lat missing/, message_update.message)
end
def test_from_xml_no_lon
nolon = "<osm><node id='1' lat='23.1' changeset='2' version='23' /></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nolon, true)
+ Node.from_xml(nolon, :create => true)
end
assert_match(/lon missing/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nolon, false)
+ Node.from_xml(nolon, :create => false)
end
assert_match(/lon missing/, message_update.message)
end
def test_from_xml_no_changeset_id
nocs = "<osm><node id='123' lon='23.23' lat='23.1' version='23' /></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nocs, true)
+ Node.from_xml(nocs, :create => true)
end
assert_match(/Changeset id is missing/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nocs, false)
+ Node.from_xml(nocs, :create => false)
end
assert_match(/Changeset id is missing/, message_update.message)
end
def test_from_xml_no_version
no_version = "<osm><node id='123' lat='23' lon='23' changeset='23' /></osm>"
assert_nothing_raised do
- Node.from_xml(no_version, true)
+ Node.from_xml(no_version, :create => true)
end
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_version, false)
+ Node.from_xml(no_version, :create => false)
end
assert_match(/Version is required when updating/, message_update.message)
end
def test_from_xml_double_lat
nocs = "<osm><node id='123' lon='23.23' lat='23.1' lat='12' changeset='23' version='23' /></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nocs, true)
+ Node.from_xml(nocs, :create => true)
end
assert_match(/Fatal error: Attribute lat redefined at/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nocs, false)
+ Node.from_xml(nocs, :create => false)
end
assert_match(/Fatal error: Attribute lat redefined at/, message_update.message)
end
id_list.each do |id|
zero_id = "<osm><node id='#{id}' lat='12.3' lon='12.3' changeset='33' version='23' /></osm>"
assert_nothing_raised do
- Node.from_xml(zero_id, true)
+ Node.from_xml(zero_id, :create => true)
end
message_update = assert_raise(OSM::APIBadUserInput) do
- Node.from_xml(zero_id, false)
+ Node.from_xml(zero_id, :create => false)
end
assert_match(/ID of node cannot be zero when updating/, message_update.message)
end
def test_from_xml_no_text
no_text = ""
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_text, true)
+ Node.from_xml(no_text, :create => true)
end
assert_match(/Must specify a string with one or more characters/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_text, false)
+ Node.from_xml(no_text, :create => false)
end
assert_match(/Must specify a string with one or more characters/, message_update.message)
end
def test_from_xml_no_node
no_node = "<osm></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_node, true)
+ Node.from_xml(no_node, :create => true)
end
assert_match %r{XML doesn't contain an osm/node element}, message_create.message
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_node, false)
+ Node.from_xml(no_node, :create => false)
end
assert_match %r{XML doesn't contain an osm/node element}, message_update.message
end
def test_from_xml_no_k_v
nokv = "<osm><node id='23' lat='12.3' lon='23.4' changeset='12' version='23'><tag /></node></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nokv, true)
+ Node.from_xml(nokv, :create => true)
end
assert_match(/tag is missing key/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(nokv, false)
+ Node.from_xml(nokv, :create => false)
end
assert_match(/tag is missing key/, message_update.message)
end
def test_from_xml_no_v
no_v = "<osm><node id='23' lat='23.43' lon='23.32' changeset='23' version='32'><tag k='key' /></node></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_v, true)
+ Node.from_xml(no_v, :create => true)
end
assert_match(/tag is missing value/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Node.from_xml(no_v, false)
+ Node.from_xml(no_v, :create => false)
end
assert_match(/tag is missing value/, message_update.message)
end
def test_from_xml_duplicate_k
dupk = "<osm><node id='23' lat='23.2' lon='23' changeset='34' version='23'><tag k='dup' v='test' /><tag k='dup' v='tester' /></node></osm>"
message_create = assert_raise(OSM::APIDuplicateTagsError) do
- Node.from_xml(dupk, true)
+ Node.from_xml(dupk, :create => true)
end
assert_equal "Element node/ has duplicate tags with key dup", message_create.message
message_update = assert_raise(OSM::APIDuplicateTagsError) do
- Node.from_xml(dupk, false)
+ Node.from_xml(dupk, :create => false)
end
assert_equal "Element node/23 has duplicate tags with key dup", message_update.message
end
def test_from_xml_no_id
noid = "<osm><relation version='12' changeset='23' /></osm>"
assert_nothing_raised do
- Relation.from_xml(noid, true)
+ Relation.from_xml(noid, :create => true)
end
message = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(noid, false)
+ Relation.from_xml(noid, :create => false)
end
assert_match(/ID is required when updating/, message.message)
end
def test_from_xml_no_changeset_id
nocs = "<osm><relation id='123' version='12' /></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(nocs, true)
+ Relation.from_xml(nocs, :create => true)
end
assert_match(/Changeset id is missing/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(nocs, false)
+ Relation.from_xml(nocs, :create => false)
end
assert_match(/Changeset id is missing/, message_update.message)
end
def test_from_xml_no_version
no_version = "<osm><relation id='123' changeset='23' /></osm>"
assert_nothing_raised do
- Relation.from_xml(no_version, true)
+ Relation.from_xml(no_version, :create => true)
end
message_update = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(no_version, false)
+ Relation.from_xml(no_version, :create => false)
end
assert_match(/Version is required when updating/, message_update.message)
end
id_list.each do |id|
zero_id = "<osm><relation id='#{id}' changeset='332' version='23' /></osm>"
assert_nothing_raised do
- Relation.from_xml(zero_id, true)
+ Relation.from_xml(zero_id, :create => true)
end
message_update = assert_raise(OSM::APIBadUserInput) do
- Relation.from_xml(zero_id, false)
+ Relation.from_xml(zero_id, :create => false)
end
assert_match(/ID of relation cannot be zero when updating/, message_update.message)
end
def test_from_xml_no_text
no_text = ""
message_create = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(no_text, true)
+ Relation.from_xml(no_text, :create => true)
end
assert_match(/Must specify a string with one or more characters/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(no_text, false)
+ Relation.from_xml(no_text, :create => false)
end
assert_match(/Must specify a string with one or more characters/, message_update.message)
end
def test_from_xml_no_k_v
nokv = "<osm><relation id='23' changeset='23' version='23'><tag /></relation></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(nokv, true)
+ Relation.from_xml(nokv, :create => true)
end
assert_match(/tag is missing key/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(nokv, false)
+ Relation.from_xml(nokv, :create => false)
end
assert_match(/tag is missing key/, message_update.message)
end
def test_from_xml_no_v
no_v = "<osm><relation id='23' changeset='23' version='23'><tag k='key' /></relation></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(no_v, true)
+ Relation.from_xml(no_v, :create => true)
end
assert_match(/tag is missing value/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Relation.from_xml(no_v, false)
+ Relation.from_xml(no_v, :create => false)
end
assert_match(/tag is missing value/, message_update.message)
end
def test_from_xml_duplicate_k
dupk = "<osm><relation id='23' changeset='23' version='23'><tag k='dup' v='test'/><tag k='dup' v='tester'/></relation></osm>"
message_create = assert_raise(OSM::APIDuplicateTagsError) do
- Relation.from_xml(dupk, true)
+ Relation.from_xml(dupk, :create => true)
end
assert_equal "Element relation/ has duplicate tags with key dup", message_create.message
message_update = assert_raise(OSM::APIDuplicateTagsError) do
- Relation.from_xml(dupk, false)
+ Relation.from_xml(dupk, :create => false)
end
assert_equal "Element relation/23 has duplicate tags with key dup", message_update.message
end
def test_from_xml_no_id
noid = "<osm><way version='12' changeset='23' /></osm>"
assert_nothing_raised do
- Way.from_xml(noid, true)
+ Way.from_xml(noid, :create => true)
end
message = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(noid, false)
+ Way.from_xml(noid, :create => false)
end
assert_match(/ID is required when updating/, message.message)
end
def test_from_xml_no_changeset_id
nocs = "<osm><way id='123' version='23' /></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(nocs, true)
+ Way.from_xml(nocs, :create => true)
end
assert_match(/Changeset id is missing/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(nocs, false)
+ Way.from_xml(nocs, :create => false)
end
assert_match(/Changeset id is missing/, message_update.message)
end
def test_from_xml_no_version
no_version = "<osm><way id='123' changeset='23' /></osm>"
assert_nothing_raised do
- Way.from_xml(no_version, true)
+ Way.from_xml(no_version, :create => true)
end
message_update = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(no_version, false)
+ Way.from_xml(no_version, :create => false)
end
assert_match(/Version is required when updating/, message_update.message)
end
id_list.each do |id|
zero_id = "<osm><way id='#{id}' changeset='33' version='23' /></osm>"
assert_nothing_raised do
- Way.from_xml(zero_id, true)
+ Way.from_xml(zero_id, :create => true)
end
message_update = assert_raise(OSM::APIBadUserInput) do
- Way.from_xml(zero_id, false)
+ Way.from_xml(zero_id, :create => false)
end
assert_match(/ID of way cannot be zero when updating/, message_update.message)
end
def test_from_xml_no_text
no_text = ""
message_create = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(no_text, true)
+ Way.from_xml(no_text, :create => true)
end
assert_match(/Must specify a string with one or more characters/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(no_text, false)
+ Way.from_xml(no_text, :create => false)
end
assert_match(/Must specify a string with one or more characters/, message_update.message)
end
def test_from_xml_no_k_v
nokv = "<osm><way id='23' changeset='23' version='23'><tag /></way></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(nokv, true)
+ Way.from_xml(nokv, :create => true)
end
assert_match(/tag is missing key/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(nokv, false)
+ Way.from_xml(nokv, :create => false)
end
assert_match(/tag is missing key/, message_update.message)
end
def test_from_xml_no_v
no_v = "<osm><way id='23' changeset='23' version='23'><tag k='key' /></way></osm>"
message_create = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(no_v, true)
+ Way.from_xml(no_v, :create => true)
end
assert_match(/tag is missing value/, message_create.message)
message_update = assert_raise(OSM::APIBadXMLError) do
- Way.from_xml(no_v, false)
+ Way.from_xml(no_v, :create => false)
end
assert_match(/tag is missing value/, message_update.message)
end
def test_from_xml_duplicate_k
dupk = "<osm><way id='23' changeset='23' version='23'><tag k='dup' v='test' /><tag k='dup' v='tester' /></way></osm>"
message_create = assert_raise(OSM::APIDuplicateTagsError) do
- Way.from_xml(dupk, true)
+ Way.from_xml(dupk, :create => true)
end
assert_equal "Element way/ has duplicate tags with key dup", message_create.message
message_update = assert_raise(OSM::APIDuplicateTagsError) do
- Way.from_xml(dupk, false)
+ Way.from_xml(dupk, :create => false)
end
assert_equal "Element way/23 has duplicate tags with key dup", message_update.message
end