- 'script/deliver-message'
- 'script/locale/reload-languages'
- 'script/update-spam-blocks'
+
+Style/StringLiterals:
+ EnforcedStyle: double_quotes
Style/RescueModifier:
Enabled: false
-# Offense count: 6639
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SupportedStyles.
-Style/StringLiterals:
- Enabled: false
-
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
-source 'https://rubygems.org'
+source "https://rubygems.org"
# Require rails
-gem 'rails', '4.2.0'
+gem "rails", "4.2.0"
# Require things which have moved to gems in ruby 1.9
-gem 'bigdecimal', "~> 1.1.0", :platforms => :ruby_19
+gem "bigdecimal", "~> 1.1.0", :platforms => :ruby_19
# Require things which have moved to gems in ruby 2.0
-gem 'psych', :platforms => :ruby_20
+gem "psych", :platforms => :ruby_20
# Require json for multi_json
-gem 'json'
+gem "json"
# Use postgres as the database
-gem 'pg'
+gem "pg"
# Use SCSS for stylesheets
-gem 'sass-rails', '~> 5.0'
+gem "sass-rails", "~> 5.0"
# Use Uglifier as compressor for JavaScript assets
-gem 'uglifier', '>= 1.3.0'
+gem "uglifier", ">= 1.3.0"
# Use CoffeeScript for .js.coffee assets and views
-gem 'coffee-rails', '~> 4.1.0'
+gem "coffee-rails", "~> 4.1.0"
# Use jquery as the JavaScript library
-gem 'jquery-rails'
+gem "jquery-rails"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.0'
-gem 'jsonify-rails'
+gem "jsonify-rails"
# Use R2 for RTL conversion
-gem 'r2'
+gem "r2"
# Use autoprefixer to generate CSS prefixes
-gem 'autoprefixer-rails'
+gem "autoprefixer-rails"
# Load rails plugins
-gem 'rails-i18n', "~> 4.0.0"
-gem 'dynamic_form'
-gem 'rinku', '>= 1.2.2', :require => 'rails_rinku'
-gem 'oauth-plugin', '>= 0.5.1'
-gem 'open_id_authentication', '>= 1.1.0'
-gem 'validates_email_format_of', '>= 1.5.1'
-gem 'composite_primary_keys', '~> 8.0.0'
-gem 'http_accept_language', '~> 2.0.0'
-gem 'paperclip', '~> 4.0'
-gem 'deadlock_retry', '>= 1.2.0'
-gem 'openstreetmap-i18n-js', '>= 3.0.0.rc5.3', :require => 'i18n-js'
-gem 'rack-cors'
-gem 'actionpack-page_caching'
+gem "rails-i18n", "~> 4.0.0"
+gem "dynamic_form"
+gem "rinku", ">= 1.2.2", :require => "rails_rinku"
+gem "oauth-plugin", ">= 0.5.1"
+gem "open_id_authentication", ">= 1.1.0"
+gem "validates_email_format_of", ">= 1.5.1"
+gem "composite_primary_keys", "~> 8.0.0"
+gem "http_accept_language", "~> 2.0.0"
+gem "paperclip", "~> 4.0"
+gem "deadlock_retry", ">= 1.2.0"
+gem "openstreetmap-i18n-js", ">= 3.0.0.rc5.3", :require => "i18n-js"
+gem "rack-cors"
+gem "actionpack-page_caching"
# We need ruby-openid 2.2.0 or later for ruby 1.9 support
-gem 'ruby-openid', '>= 2.2.0'
+gem "ruby-openid", ">= 2.2.0"
# Markdown formatting support
-gem 'redcarpet'
+gem "redcarpet"
# Character conversion support for ruby 1.8
-gem 'iconv', '= 0.1', :platforms => :ruby_18
+gem "iconv", "= 0.1", :platforms => :ruby_18
# Load libxml support for XML parsing and generation
-gem 'libxml-ruby', '>= 2.0.5', :require => 'libxml'
+gem "libxml-ruby", ">= 2.0.5", :require => "libxml"
# Use for HTML sanitisation
-gem 'sanitize'
-gem 'htmlentities'
+gem "sanitize"
+gem "htmlentities"
# Load SystemTimer for implementing request timeouts
-gem 'SystemTimer', '>= 1.1.3', :require => 'system_timer', :platforms => :ruby_18
+gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_18
# Load httpclient and soap4r for SOAP support for Quova GeoIP queries
-gem 'httpclient'
-gem 'soap4r-ruby1.9'
+gem "httpclient"
+gem "soap4r-ruby1.9"
# Load memcache client in case we are using it
-gem 'dalli'
-gem 'kgio'
+gem "dalli"
+gem "kgio"
# Gems useful for development
group :development do
- gem 'vendorer'
+ gem "vendorer"
end
# Gems needed for running tests
group :test do
- gem 'timecop'
- gem 'minitest', '~> 5.1', :platforms => [:ruby_19, :ruby_20]
+ gem "timecop"
+ gem "minitest", "~> 5.1", :platforms => [:ruby_19, :ruby_20]
end
# Needed in development as well so rake can see konacha tasks
group :development, :test do
- gem 'konacha'
- gem 'poltergeist'
+ gem "konacha"
+ gem "poltergeist"
end
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require File.expand_path('../config/application', __FILE__)
+require File.expand_path("../config/application", __FILE__)
OpenStreetMap::Application.load_tasks
logger.info("Executing AMF #{message}(#{args.join(',')})")
case message
- when 'getpresets' then result = getpresets(*args)
- when 'whichways' then result = whichways(*args)
- when 'whichways_deleted' then result = whichways_deleted(*args)
- when 'getway' then result = getway(args[0].to_i)
- when 'getrelation' then result = getrelation(args[0].to_i)
- when 'getway_old' then result = getway_old(args[0].to_i, args[1])
- when 'getway_history' then result = getway_history(args[0].to_i)
- when 'getnode_history' then result = getnode_history(args[0].to_i)
- when 'findgpx' then result = findgpx(*args)
- when 'findrelations' then result = findrelations(*args)
- when 'getpoi' then result = getpoi(*args)
+ when "getpresets" then result = getpresets(*args)
+ when "whichways" then result = whichways(*args)
+ when "whichways_deleted" then result = whichways_deleted(*args)
+ when "getway" then result = getway(args[0].to_i)
+ when "getrelation" then result = getrelation(args[0].to_i)
+ when "getway_old" then result = getway_old(args[0].to_i, args[1])
+ when "getway_history" then result = getway_history(args[0].to_i)
+ when "getnode_history" then result = getnode_history(args[0].to_i)
+ when "findgpx" then result = findgpx(*args)
+ when "findrelations" then result = findrelations(*args)
+ when "getpoi" then result = getpoi(*args)
end
result
result = [-5, nil]
else
case message
- when 'putway' then
+ when "putway" then
orn = renumberednodes.dup
result = putway(renumberednodes, *args)
result[4] = renumberednodes.reject { |k, _v| orn.key?(k) }
if result[0] == 0 && result[2] != result[3] then renumberedways[result[2]] = result[3] end
- when 'putrelation' then
+ when "putrelation" then
result = putrelation(renumberednodes, renumberedways, *args)
- when 'deleteway' then
+ when "deleteway" then
result = deleteway(*args)
- when 'putpoi' then
+ when "putpoi" then
result = putpoi(*args)
if result[0] == 0 && result[2] != result[3] then renumberednodes[result[2]] = result[3] end
- when 'startchangeset' then
+ when "startchangeset" then
result = startchangeset(*args)
end
amf_handle_error("'startchangeset'", nil, nil) do
user = getuser(usertoken)
unless user then return -1, "You are not logged in, so Potlatch can't write any changes to the database." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
+ if user.blocks.active.exists? then return -1, t("application.setup_user_auth.blocked") end
if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
if cstags
elsif closecomment.empty?
cs.save!
else
- cs.tags['comment'] = closecomment
+ cs.tags["comment"] = closecomment
# in case closecomment has chars not allowed in xml
cs.tags = strip_non_xml_chars cs.tags
cs.save_with_tags!
cs.tags = cstags
cs.user_id = user.id
unless closecomment.empty?
- cs.tags['comment'] = closecomment
+ cs.tags["comment"] = closecomment
# in case closecomment has chars not allowed in xml
cs.tags = strip_non_xml_chars cs.tags
end
cs.created_at = Time.now.getutc
cs.closed_at = cs.created_at + Changeset::IDLE_TIMEOUT
cs.save_with_tags!
- return [0, '', cs.id]
+ return [0, "", cs.id]
else
- return [0, '', nil]
+ return [0, "", nil]
end
end
end
def getlocalized(lang)
# What we end up actually using. Reported in Potlatch's created_by=* string
- loaded_lang = 'en'
+ loaded_lang = "en"
# Load English defaults
en = YAML.load(File.open("#{Rails.root}/config/potlatch/locales/en.yml"))["en"]
- if lang == 'en'
+ if lang == "en"
return [loaded_lang, en]
else
# Use English as a fallback
relations = relations.collect { |relation| [relation.id, relation.version] }.uniq
end
- [0, '', ways, points, relations]
+ [0, "", ways, points, relations]
end
end
nodes_in_area = Node.bbox(bbox).joins(:ways_via_history).where(:current_ways => { :visible => false })
way_ids = nodes_in_area.collect { |node| node.ways_via_history.invisible.collect(&:id) }.flatten.uniq
- [0, '', way_ids]
+ [0, "", way_ids]
end
end
# Returns the way id, a Potlatch-style array of points, a hash of tags, the version number, and the user ID.
def getway(wayid) #:doc:
- amf_handle_error_with_timeout("'getway' #{wayid}", 'way', wayid) do
+ amf_handle_error_with_timeout("'getway' #{wayid}", "way", wayid) do
if POTLATCH_USE_SQL
points = sql_get_nodes_in_way(wayid)
tags = sql_get_tags_in_way(wayid)
way = Way.where(:id => wayid).first
# check case where way has been deleted or doesn't exist
- return [-4, 'way', wayid] if way.nil? || !way.visible
+ return [-4, "way", wayid] if way.nil? || !way.visible
points = way.nodes.preload(:node_tags).collect do |node|
nodetags = node.tags
- nodetags.delete('created_by')
+ nodetags.delete("created_by")
[node.lon, node.lat, node.id, nodetags, node.version]
end
tags = way.tags
uid = way.changeset.user.id
end
- [0, '', wayid, points, tags, version, uid]
+ [0, "", wayid, points, tags, version, uid]
end
end
# 5. is this the current, visible version? (boolean)
def getway_old(id, timestamp) #:doc:
- amf_handle_error_with_timeout("'getway_old' #{id}, #{timestamp}", 'way', id) do
- if timestamp == ''
+ amf_handle_error_with_timeout("'getway_old' #{id}, #{timestamp}", "way", id) do
+ if timestamp == ""
# undelete
old_way = OldWay.where(:visible => true, :way_id => id).unredacted.order("version DESC").first
points = old_way.get_nodes_undelete unless old_way.nil?
return [-1, "Sorry, the server could not find a way at that time.", id]
else
curway = Way.find(id)
- old_way.tags['history'] = "Retrieved from v#{old_way.version}"
- return [0, '', id, points, old_way.tags, curway.version, (curway.version == old_way.version && curway.visible)]
+ old_way.tags["history"] = "Retrieved from v#{old_way.version}"
+ return [0, "", id, points, old_way.tags, curway.version, (curway.version == old_way.version && curway.visible)]
end
end
end
revdates.collect! { |d| [(d + 1).strftime("%d %b %Y, %H:%M:%S")] + revusers[d.to_i] }
revdates.uniq!
- return ['way', wayid, revdates]
+ return ["way", wayid, revdates]
rescue ActiveRecord::RecordNotFound
- return ['way', wayid, []]
+ return ["way", wayid, []]
end
# Find history of a node. Returns 'node', id, and an array of previous versions as above.
history = Node.find(nodeid).old_nodes.unredacted.reverse.collect do |old_node|
[(old_node.timestamp + 1).strftime("%d %b %Y, %H:%M:%S")] + change_user(old_node)
end
- return ['node', nodeid, history]
+ return ["node", nodeid, history]
rescue ActiveRecord::RecordNotFound
- return ['node', nodeid, []]
+ return ["node", nodeid, []]
end
def change_user(obj)
user_object = obj.changeset.user
- user = user_object.data_public? ? user_object.display_name : 'anonymous'
+ user = user_object.data_public? ? user_object.display_name : "anonymous"
uid = user_object.data_public? ? user_object.id : 0
[user, uid]
end
user = getuser(usertoken)
return -1, "You must be logged in to search for GPX traces." unless user
- return -1, t('application.setup_user_auth.blocked') if user.blocks.active.exists?
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
query = Trace.visible_to(user)
if searchterm.to_i > 0
gpxs = query.collect do |gpx|
[gpx.id, gpx.name, gpx.description]
end
- [0, '', gpxs]
+ [0, "", gpxs]
end
end
# 5. version.
def getrelation(relid) #:doc:
- amf_handle_error("'getrelation' #{relid}", 'relation', relid) do
+ amf_handle_error("'getrelation' #{relid}", "relation", relid) do
rel = Relation.where(:id => relid).first
- return [-4, 'relation', relid] if rel.nil? || !rel.visible
- [0, '', relid, rel.tags, rel.members, rel.version]
+ return [-4, "relation", relid] if rel.nil? || !rel.visible
+ [0, "", relid, rel.tags, rel.members, rel.version]
end
end
# 3. version.
def putrelation(renumberednodes, renumberedways, usertoken, changeset_id, version, relid, tags, members, visible) #:doc:
- amf_handle_error("'putrelation' #{relid}", 'relation', relid) do
+ amf_handle_error("'putrelation' #{relid}", "relation", relid) do
user = getuser(usertoken)
unless user then return -1, "You are not logged in, so the relation could not be saved." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
+ if user.blocks.active.exists? then return -1, t("application.setup_user_auth.blocked") end
if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
unless tags_ok(tags) then return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
members.each do |m|
mid = m[1].to_i
if mid < 0
- mid = renumberednodes[mid] if m[0] == 'Node'
- mid = renumberedways[mid] if m[0] == 'Way'
+ mid = renumberednodes[mid] if m[0] == "Node"
+ mid = renumberedways[mid] if m[0] == "Way"
end
if mid
typedmembers << [m[0], mid, m[2].delete("\000-\037\ufffe\uffff", "^\011\012\015")]
end # transaction
if relid <= 0
- return [0, '', relid, new_relation.id, new_relation.version]
+ return [0, "", relid, new_relation.id, new_relation.version]
else
- return [0, '', relid, relid, relation.version]
+ return [0, "", relid, relid, relation.version]
end
end
end
# 6. hash of node versions (node=>version)
def putway(renumberednodes, usertoken, changeset_id, wayversion, originalway, pointlist, attributes, nodes, deletednodes) #:doc:
- amf_handle_error("'putway' #{originalway}", 'way', originalway) do
+ amf_handle_error("'putway' #{originalway}", "way", originalway) do
# -- Initialise
user = getuser(usertoken)
unless user then return -1, "You are not logged in, so the way could not be saved." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
+ if user.blocks.active.exists? then return -1, t("application.setup_user_auth.blocked") end
if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
if pointlist.length < 2 then return -2, "Server error - way is only #{points.length} points long." end
unless tags_ok(node.tags) then return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
node.tags = strip_non_xml_chars node.tags
- node.tags.delete('created_by')
+ node.tags.delete("created_by")
node.version = version
if id <= 0
# We're creating the node
end
end # transaction
- [0, '', originalway, way.id, renumberednodes, way.version, nodeversions, deletednodes]
+ [0, "", originalway, way.id, renumberednodes, way.version, nodeversions, deletednodes]
end
end
# 4. version.
def putpoi(usertoken, changeset_id, version, id, lon, lat, tags, visible) #:doc:
- amf_handle_error("'putpoi' #{id}", 'node', id) do
+ amf_handle_error("'putpoi' #{id}", "node", id) do
user = getuser(usertoken)
unless user then return -1, "You are not logged in, so the point could not be saved." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
+ if user.blocks.active.exists? then return -1, t("application.setup_user_auth.blocked") end
if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
unless tags_ok(tags) then return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
end # transaction
if id <= 0
- return [0, '', id, new_node.id, new_node.version]
+ return [0, "", id, new_node.id, new_node.version]
else
- return [0, '', id, node.id, node.version]
+ return [0, "", id, node.id, node.version]
end
end
end
# Returns array of id, long, lat, hash of tags, (current) version.
def getpoi(id, timestamp) #:doc:
- amf_handle_error("'getpoi' #{id}", 'node', id) do
+ amf_handle_error("'getpoi' #{id}", "node", id) do
id = id.to_i
n = Node.find(id)
v = n.version
- unless timestamp == ''
+ unless timestamp == ""
n = OldNode.where("node_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first
end
if n
- return [0, '', n.id, n.lon, n.lat, n.tags, v]
+ return [0, "", n.id, n.lon, n.lat, n.tags, v]
else
- return [-4, 'node', id]
+ return [-4, "node", id]
end
end
end
# Returns 0 (success), unchanged way id, new way version, new node versions.
def deleteway(usertoken, changeset_id, way_id, way_version, deletednodes) #:doc:
- amf_handle_error("'deleteway' #{way_id}", 'way', way_id) do
+ amf_handle_error("'deleteway' #{way_id}", "way", way_id) do
user = getuser(usertoken)
unless user then return -1, "You are not logged in, so the way could not be deleted." end
- if user.blocks.active.exists? then return -1, t('application.setup_user_auth.blocked') end
+ if user.blocks.active.exists? then return -1, t("application.setup_user_auth.blocked") end
if REQUIRE_TERMS_AGREED && user.terms_agreed.nil? then return -1, "You must accept the contributor terms before you can edit." end
way_id = way_id.to_i
end
end
end # transaction
- [0, '', way_id, old_way.version, nodeversions]
+ [0, "", way_id, old_way.version, nodeversions]
end
end
AND current_ways.visible=TRUE
AND #{OSM.sql_for_area(bbox, "current_nodes.")}
EOF
- ActiveRecord::Base.connection.select_all(sql).collect { |a| [a['wayid'].to_i, a['version'].to_i] }
+ ActiveRecord::Base.connection.select_all(sql).collect { |a| [a["wayid"].to_i, a["version"].to_i] }
end
def sql_find_pois_in_area(bbox)
ActiveRecord::Base.connection.select_all(sql).each do |row|
poitags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
- poitags[n['k']] = n['v']
+ poitags[n["k"]] = n["v"]
end
- pois << [row['id'].to_i, row['lon'].to_f, row['lat'].to_f, poitags, row['version'].to_i]
+ pois << [row["id"].to_i, row["lon"].to_f, row["lat"].to_f, poitags, row["version"].to_i]
end
pois
end
AND crm.member_id IN (#{way_ids.join(',')})
EOF
end
- ActiveRecord::Base.connection.select_all(sql).collect { |a| [a['relid'].to_i, a['version'].to_i] }
+ ActiveRecord::Base.connection.select_all(sql).collect { |a| [a["relid"].to_i, a["version"].to_i] }
end
def sql_get_nodes_in_way(wayid)
ActiveRecord::Base.connection.select_all(sql).each do |row|
nodetags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
- nodetags[n['k']] = n['v']
+ nodetags[n["k"]] = n["v"]
end
- nodetags.delete('created_by')
- points << [row['lon'].to_f, row['lat'].to_f, row['id'].to_i, nodetags, row['version'].to_i]
+ nodetags.delete("created_by")
+ points << [row["lon"].to_f, row["lat"].to_f, row["id"].to_i, nodetags, row["version"].to_i]
end
points
end
def sql_get_tags_in_way(wayid)
tags = {}
ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_way_tags WHERE id=#{wayid.to_i}").each do |row|
- tags[row['k']] = row['v']
+ tags[row["k"]] = row["v"]
end
tags
end
def sql_get_way_version(wayid)
- ActiveRecord::Base.connection.select_one("SELECT version FROM current_ways WHERE id=#{wayid.to_i}")['version']
+ ActiveRecord::Base.connection.select_one("SELECT version FROM current_ways WHERE id=#{wayid.to_i}")["version"]
end
def sql_get_way_user(wayid)
- ActiveRecord::Base.connection.select_one("SELECT user FROM current_ways,changesets WHERE current_ways.id=#{wayid.to_i} AND current_ways.changeset=changesets.id")['user']
+ ActiveRecord::Base.connection.select_one("SELECT user FROM current_ways,changesets WHERE current_ways.id=#{wayid.to_i} AND current_ways.changeset=changesets.id")["user"]
end
end
# within the specified bounding box, and in the specified page.
def trackpoints
# retrieve the page number
- page = params['page'].to_s.to_i
+ page = params["page"].to_s.to_i
unless page >= 0
report_error("Page number must be greater than or equal to 0")
doc = XML::Document.new
doc.encoding = XML::Encoding::UTF_8
- root = XML::Node.new 'gpx'
- root['version'] = '1.0'
- root['creator'] = 'OpenStreetMap.org'
- root['xmlns'] = "http://www.topografix.com/GPX/1/0"
+ root = XML::Node.new "gpx"
+ root["version"] = "1.0"
+ root["creator"] = "OpenStreetMap.org"
+ root["xmlns"] = "http://www.topografix.com/GPX/1/0"
doc.root = root
gpx_file = Trace.find(gpx_id)
if gpx_file.trackable?
- track = XML::Node.new 'trk'
+ track = XML::Node.new "trk"
doc.root << track
timestamps = true
if gpx_file.identifiable?
track << (XML::Node.new("name") << gpx_file.name)
track << (XML::Node.new("desc") << gpx_file.description)
- track << (XML::Node.new("url") << url_for(:controller => 'trace', :action => 'view', :display_name => gpx_file.user.display_name, :id => gpx_file.id))
+ track << (XML::Node.new("url") << url_for(:controller => "trace", :action => "view", :display_name => gpx_file.user.display_name, :id => gpx_file.id))
end
else
# use the anonymous track segment if the user hasn't allowed
# their GPX points to be tracked.
timestamps = false
if anon_track.nil?
- anon_track = XML::Node.new 'trk'
+ anon_track = XML::Node.new "trk"
doc.root << anon_track
end
track = anon_track
if trackid != point.trackid
if gpx_file.trackable?
- trkseg = XML::Node.new 'trkseg'
+ trkseg = XML::Node.new "trkseg"
track << trkseg
trackid = point.trackid
else
if anon_trkseg.nil?
- anon_trkseg = XML::Node.new 'trkseg'
+ anon_trkseg = XML::Node.new "trkseg"
anon_track << anon_trkseg
end
trkseg = anon_trkseg
doc = OSM::API.new.get_xml_doc
# add bounds
- doc.root << bbox.add_bounds_to(XML::Node.new 'bounds')
+ doc.root << bbox.add_bounds_to(XML::Node.new "bounds")
# get ways
# find which ways are needed
# Get a list of the tiles that have changed within a specified time
# period
def changes
- zoom = (params[:zoom] || '12').to_i
+ zoom = (params[:zoom] || "12").to_i
if params.include?(:start) && params.include?(:end)
starttime = Time.parse(params[:start])
endtime = Time.parse(params[:end])
else
- hours = (params[:hours] || '1').to_i.hours
+ hours = (params[:hours] || "1").to_i.hours
endtime = Time.now.getutc
starttime = endtime - hours
end
tiles = Node.where(:timestamp => starttime..endtime).group("maptile_for_point(latitude, longitude, #{zoom})").count
doc = OSM::API.new.get_xml_doc
- changes = XML::Node.new 'changes'
+ changes = XML::Node.new "changes"
changes["starttime"] = starttime.xmlschema
changes["endtime"] = endtime.xmlschema
x = (tile.to_i >> zoom) & mask
y = tile.to_i & mask
- t = XML::Node.new 'tile'
+ t = XML::Node.new "tile"
t["x"] = x.to_s
t["y"] = y.to_s
t["z"] = zoom.to_s
def capabilities
doc = OSM::API.new.get_xml_doc
- api = XML::Node.new 'api'
- version = XML::Node.new 'version'
- version['minimum'] = "#{API_VERSION}"
- version['maximum'] = "#{API_VERSION}"
+ api = XML::Node.new "api"
+ version = XML::Node.new "version"
+ version["minimum"] = "#{API_VERSION}"
+ version["maximum"] = "#{API_VERSION}"
api << version
- area = XML::Node.new 'area'
- area['maximum'] = MAX_REQUEST_AREA.to_s
+ area = XML::Node.new "area"
+ area["maximum"] = MAX_REQUEST_AREA.to_s
api << area
- tracepoints = XML::Node.new 'tracepoints'
- tracepoints['per_page'] = TRACEPOINTS_PER_PAGE.to_s
+ tracepoints = XML::Node.new "tracepoints"
+ tracepoints["per_page"] = TRACEPOINTS_PER_PAGE.to_s
api << tracepoints
- waynodes = XML::Node.new 'waynodes'
- waynodes['maximum'] = MAX_NUMBER_OF_WAY_NODES.to_s
+ waynodes = XML::Node.new "waynodes"
+ waynodes["maximum"] = MAX_NUMBER_OF_WAY_NODES.to_s
api << waynodes
- changesets = XML::Node.new 'changesets'
- changesets['maximum_elements'] = Changeset::MAX_ELEMENTS.to_s
+ changesets = XML::Node.new "changesets"
+ changesets["maximum_elements"] = Changeset::MAX_ELEMENTS.to_s
api << changesets
- timeout = XML::Node.new 'timeout'
- timeout['seconds'] = API_TIMEOUT.to_s
+ timeout = XML::Node.new "timeout"
+ timeout["seconds"] = API_TIMEOUT.to_s
api << timeout
- status = XML::Node.new 'status'
- status['database'] = database_status.to_s
- status['api'] = api_status.to_s
- status['gpx'] = gpx_status.to_s
+ status = XML::Node.new "status"
+ status["database"] = database_status.to_s
+ status["api"] = api_status.to_s
+ status["gpx"] = gpx_status.to_s
api << status
doc.root << api
- policy = XML::Node.new 'policy'
- blacklist = XML::Node.new 'imagery'
+ policy = XML::Node.new "policy"
+ blacklist = XML::Node.new "imagery"
IMAGERY_BLACKLIST.each do |url_regex|
- xnd = XML::Node.new 'blacklist'
- xnd['regex'] = url_regex.to_s
+ xnd = XML::Node.new "blacklist"
+ xnd["regex"] = url_regex.to_s
blacklist << xnd
end
policy << blacklist
# don't allow access to any auth-requiring part of the site unless
# the new CTs have been seen (and accept/decline chosen).
elsif !@user.terms_seen && flash[:skip_terms].nil?
- flash[:notice] = t 'user.terms.you need to accept or decline'
+ flash[:notice] = t "user.terms.you need to accept or decline"
if params[:referer]
redirect_to :controller => "user", :action => "terms", :referer => params[:referer]
else
def require_user
unless @user
if request.get?
- redirect_to :controller => 'user', :action => 'login', :referer => request.fullpath
+ redirect_to :controller => "user", :action => "login", :referer => request.fullpath
else
render :text => "", :status => :forbidden
end
redirect_to Hash[params].merge(:cookie_test => "true")
return false
else
- flash.now[:warning] = t 'application.require_cookies.cookies_needed'
+ flash.now[:warning] = t "application.require_cookies.cookies_needed"
end
else
session.delete(:cookie_test)
def require_moderator
unless @user.moderator?
if request.get?
- flash[:error] = t('application.require_moderator.not_a_moderator')
- redirect_to :action => 'index'
+ flash[:error] = t("application.require_moderator.not_a_moderator")
+ redirect_to :action => "index"
else
render :text => "", :status => :forbidden
end
# authenticate per-scheme
if username.nil?
@user = nil # no authentication provided - perhaps first connect (client should retry after 401)
- elsif username == 'token'
+ elsif username == "token"
@user = User.authenticate(:token => passwd) # preferred - random token for user from db, passed in basic auth
else
@user = User.authenticate(:username => username, :password => passwd) # basic auth
# check if the user has been banned
if @user.blocks.active.exists?
# NOTE: need slightly more helpful message than this.
- report_error t('application.setup_user_auth.blocked'), :forbidden
+ report_error t("application.setup_user_auth.blocked"), :forbidden
end
# if the user hasn't seen the contributor terms then don't
# (but can decline) the CTs to continue.
if REQUIRE_TERMS_SEEN && !@user.terms_seen && flash[:skip_terms].nil?
set_locale
- report_error t('application.setup_user_auth.need_to_see_terms'), :forbidden
+ report_error t("application.setup_user_auth.need_to_see_terms"), :forbidden
end
end
end
- def authorize(realm = 'Web Password', errormessage = "Couldn't authenticate you")
+ def authorize(realm = "Web Password", errormessage = "Couldn't authenticate you")
# make the @user object from any auth sources we have
setup_user_auth
if request.xhr?
report_error "Database offline for maintenance", :service_unavailable
else
- redirect_to :controller => 'site', :action => 'offline'
+ redirect_to :controller => "site", :action => "offline"
end
end
end
if request.xhr?
report_error "Database offline for maintenance", :service_unavailable
else
- redirect_to :controller => 'site', :action => 'offline'
+ redirect_to :controller => "site", :action => "offline"
end
end
end
# message. For now, rails won't let us)
def report_error(message, status = :bad_request)
# Todo: some sort of escaping of problem characters in the message
- response.headers['Error'] = message
+ response.headers["Error"] = message
- if request.headers['X-Error-Format'] &&
- request.headers['X-Error-Format'].downcase == "xml"
+ if request.headers["X-Error-Format"] &&
+ request.headers["X-Error-Format"].downcase == "xml"
result = OSM::API.new.get_xml_doc
result.root.name = "osmError"
result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}")
end
def set_locale
- response.header['Vary'] = 'Accept-Language'
+ response.header["Vary"] = "Accept-Language"
if @user && !@user.languages.empty?
http_accept_language.user_preferred_languages = @user.languages
- response.header['Vary'] = '*'
+ response.header["Vary"] = "*"
end
I18n.locale = select_locale
@user.save
end
- response.headers['Content-Language'] = I18n.locale.to_s
+ response.headers["Content-Language"] = I18n.locale.to_s
end
def select_locale(locales = I18n.available_locales)
end
def map_layout
- request.xhr? ? 'xhr' : 'map'
+ request.xhr? ? "xhr" : "map"
end
def preferred_editor
DEFAULT_EDITOR
end
- if request.env['HTTP_USER_AGENT'] =~ /MSIE|Trident/ && editor == 'id'
- editor = 'potlatch2'
+ if request.env["HTTP_USER_AGENT"] =~ /MSIE|Trident/ && editor == "id"
+ editor = "potlatch2"
end
editor
# extract authorisation credentials from headers, returns user = nil if none
def get_auth_data
- if request.env.key? 'X-HTTP_AUTHORIZATION' # where mod_rewrite might have put it
- authdata = request.env['X-HTTP_AUTHORIZATION'].to_s.split
- elsif request.env.key? 'REDIRECT_X_HTTP_AUTHORIZATION' # mod_fcgi
- authdata = request.env['REDIRECT_X_HTTP_AUTHORIZATION'].to_s.split
- elsif request.env.key? 'HTTP_AUTHORIZATION' # regular location
- authdata = request.env['HTTP_AUTHORIZATION'].to_s.split
+ if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it
+ authdata = request.env["X-HTTP_AUTHORIZATION"].to_s.split
+ elsif request.env.key? "REDIRECT_X_HTTP_AUTHORIZATION" # mod_fcgi
+ authdata = request.env["REDIRECT_X_HTTP_AUTHORIZATION"].to_s.split
+ elsif request.env.key? "HTTP_AUTHORIZATION" # regular location
+ authdata = request.env["HTTP_AUTHORIZATION"].to_s.split
end
# only basic authentication supported
- if authdata && authdata[0] == 'Basic'
- user, pass = Base64.decode64(authdata[1]).split(':', 2)
+ if authdata && authdata[0] == "Basic"
+ user, pass = Base64.decode64(authdata[1]).split(":", 2)
end
[user, pass]
end
def relation
@type = "relation"
@feature = Relation.find(params[:id])
- render 'feature'
+ render "feature"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
def relation_history
@type = "relation"
@feature = Relation.find(params[:id])
- render 'history'
+ render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
def way
@type = "way"
@feature = Way.preload(:way_tags, :containing_relation_members, :changeset => :user, :nodes => [:node_tags, :ways => :way_tags]).find(params[:id])
- render 'feature'
+ render "feature"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
def way_history
@type = "way"
@feature = Way.preload(:way_tags, :old_ways => { :changeset => :user }).find(params[:id])
- render 'history'
+ render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
def node
@type = "node"
@feature = Node.find(params[:id])
- render 'feature'
+ render "feature"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
def node_history
@type = "node"
@feature = Node.find(params[:id])
- render 'history'
+ render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
else
@comments = @changeset.comments.includes(:author)
end
- @node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => 'node_page')
- @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => 'way_page')
- @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => 'relation_page')
+ @node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "node_page")
+ @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "way_page")
+ @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "relation_page")
if @changeset.user.data_public?
@next_by_user = @changeset.user.changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first
@prev_by_user = @changeset.user.changesets.where("id < ?", @changeset.id).reorder(:id => :desc).first
# The ChangesetController is the RESTful interface to Changeset objects
class ChangesetController < ApplicationController
- layout 'site'
- require 'xml/libxml'
+ layout "site"
+ require "xml/libxml"
skip_before_filter :verify_authenticity_token, :except => [:list]
before_filter :authorize_web, :only => [:list, :feed, :comments_feed]
# abuse, maybe should change to some other format?
doc = XML::Parser.string(request.raw_post).parse
doc.find("//osm/node").each do |n|
- lon << n['lon'].to_f * GeoRecord::SCALE
- lat << n['lat'].to_f * GeoRecord::SCALE
+ lon << n["lon"].to_f * GeoRecord::SCALE
+ lat << n["lat"].to_f * GeoRecord::SCALE
end
# add the existing bounding box to the lon-lat array
# query changesets by bounding box, time, user or open/closed status.
def query
# find any bounding box
- bbox = BoundingBox.from_bbox_params(params) if params['bbox']
+ bbox = BoundingBox.from_bbox_params(params) if params["bbox"]
# create the conditions that the user asked for. some or all of
# these may be nil.
changesets = Changeset.all
changesets = conditions_bbox(changesets, bbox)
- changesets = conditions_user(changesets, params['user'], params['display_name'])
- changesets = conditions_time(changesets, params['time'])
- changesets = conditions_open(changesets, params['open'])
- changesets = conditions_closed(changesets, params['closed'])
- changesets = conditions_ids(changesets, params['changesets'])
+ changesets = conditions_user(changesets, params["user"], params["display_name"])
+ changesets = conditions_time(changesets, params["time"])
+ changesets = conditions_open(changesets, params["open"])
+ changesets = conditions_closed(changesets, params["closed"])
+ changesets = conditions_ids(changesets, params["changesets"])
# create the results document
results = OSM::API.new.get_xml_doc
else
# if there is a range, i.e: comma separated, then the first is
# low, second is high - same as with bounding boxes.
- if time.count(',') == 1
+ if time.count(",") == 1
# check that we actually have 2 elements in the array
times = time.split(/,/)
fail OSM::APIBadUserInput.new("bad time range") if times.size != 2
elsif ids.empty?
fail OSM::APIBadUserInput.new("No changesets were given to search for")
else
- ids = ids.split(',').collect(&:to_i)
+ ids = ids.split(",").collect(&:to_i)
return changesets.where(:id => ids)
end
end
class DiaryEntryController < ApplicationController
- layout 'site', :except => :rss
+ layout "site", :except => :rss
before_filter :authorize_web
before_filter :set_locale
before_filter :require_administrator, :only => [:hide, :hidecomment]
def new
- @title = t 'diary_entry.new.title'
+ @title = t "diary_entry.new.title"
if params[:diary_entry]
@diary_entry = DiaryEntry.new(entry_params)
else
@user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code)
end
- redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
+ redirect_to :controller => "diary_entry", :action => "list", :display_name => @user.display_name
else
- render :action => 'edit'
+ render :action => "edit"
end
else
default_lang = @user.preferences.where(:k => "diary.default_language").first
lang_code = default_lang ? default_lang.v : @user.preferred_language
@diary_entry = DiaryEntry.new(:language_code => lang_code)
set_map_location
- render :action => 'edit'
+ render :action => "edit"
end
end
def edit
- @title = t 'diary_entry.edit.title'
+ @title = t "diary_entry.edit.title"
@diary_entry = DiaryEntry.find(params[:id])
if @user != @diary_entry.user
- redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
+ redirect_to :controller => "diary_entry", :action => "view", :id => params[:id]
elsif params[:diary_entry] && @diary_entry.update_attributes(entry_params)
- redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
+ redirect_to :controller => "diary_entry", :action => "view", :id => params[:id]
end
set_map_location
Notifier.diary_comment_notification(@diary_comment).deliver_now
end
- redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
+ redirect_to :controller => "diary_entry", :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
else
- render :action => 'view'
+ render :action => "view"
end
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
@this_user = User.active.find_by_display_name(params[:display_name])
if @this_user
- @title = t 'diary_entry.list.user_title', :user => @this_user.display_name
+ @title = t "diary_entry.list.user_title", :user => @this_user.display_name
@entries = @this_user.diary_entries
else
render_unknown_user params[:display_name]
end
elsif params[:friends]
if @user
- @title = t 'diary_entry.list.title_friends'
+ @title = t "diary_entry.list.title_friends"
@entries = DiaryEntry.where(:user_id => @user.friend_users)
else
require_user
end
elsif params[:nearby]
if @user
- @title = t 'diary_entry.list.title_nearby'
+ @title = t "diary_entry.list.title_nearby"
@entries = DiaryEntry.where(:user_id => @user.nearby)
else
require_user
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
if params[:language]
- @title = t 'diary_entry.list.in_language_title', :language => Language.find(params[:language]).english_name
+ @title = t "diary_entry.list.in_language_title", :language => Language.find(params[:language]).english_name
@entries = @entries.where(:language_code => params[:language])
else
- @title = t 'diary_entry.list.title'
+ @title = t "diary_entry.list.title"
end
end
if user
@entries = user.diary_entries
- @title = I18n.t('diary_entry.feed.user.title', :user => user.display_name)
- @description = I18n.t('diary_entry.feed.user.description', :user => user.display_name)
+ @title = I18n.t("diary_entry.feed.user.title", :user => user.display_name)
+ @description = I18n.t("diary_entry.feed.user.description", :user => user.display_name)
@link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
else
render :text => "", :status => :not_found
if params[:language]
@entries = @entries.where(:language_code => params[:language])
- @title = I18n.t('diary_entry.feed.language.title', :language_name => Language.find(params[:language]).english_name)
- @description = I18n.t('diary_entry.feed.language.description', :language_name => Language.find(params[:language]).english_name)
+ @title = I18n.t("diary_entry.feed.language.title", :language_name => Language.find(params[:language]).english_name)
+ @description = I18n.t("diary_entry.feed.language.description", :language_name => Language.find(params[:language]).english_name)
@link = "http://#{SERVER_URL}/diary/#{params[:language]}"
else
- @title = I18n.t('diary_entry.feed.all.title')
- @description = I18n.t('diary_entry.feed.all.description')
+ @title = I18n.t("diary_entry.feed.all.title")
+ @description = I18n.t("diary_entry.feed.all.description")
@link = "http://#{SERVER_URL}/diary"
end
end
def view
@entry = @this_user.diary_entries.visible.where(:id => params[:id]).first
if @entry
- @title = t 'diary_entry.view.title', :user => params[:display_name], :title => @entry.title
+ @title = t "diary_entry.view.title", :user => params[:display_name], :title => @entry.title
else
- @title = t 'diary_entry.no_such_entry.title', :id => params[:id]
- render :action => 'no_such_entry', :status => :not_found
+ @title = t "diary_entry.no_such_entry.title", :id => params[:id]
+ render :action => "no_such_entry", :status => :not_found
end
end
:user_id => @this_user,
:visible => true
},
- :order => 'created_at DESC',
+ :order => "created_at DESC",
:per_page => 20)
@page = (params[:page] || 1).to_i
end
# and return them to the user page.
def require_administrator
unless @user.administrator?
- flash[:error] = t('user.filter.not_an_administrator')
- redirect_to :controller => 'diary_entry', :action => 'view'
+ flash[:error] = t("user.filter.not_an_administrator")
+ redirect_to :controller => "diary_entry", :action => "view"
end
end
# coding: utf-8
class GeocoderController < ApplicationController
- require 'cgi'
- require 'uri'
- require 'net/http'
- require 'rexml/document'
+ require "cgi"
+ require "uri"
+ require "net/http"
+ require "rexml/document"
before_filter :authorize_web
before_filter :set_locale
else
prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize
end
- if klass == 'boundary' && type == 'administrative'
+ if klass == "boundary" && type == "administrative"
rank = (place.attributes["place_rank"].to_i + 1) / 2
prefix_name = t "geocoder.search_osm_nominatim.admin_levels.level#{rank}", :default => prefix_name
end
end
def escape_query(query)
- URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]", false, 'N'))
+ URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]", false, "N"))
end
def normalize_params
def nsew_to_decdeg(captures)
begin
Float(captures[0])
- captures[2].downcase != 's' ? lat = captures[0].to_f : lat = -(captures[0].to_f)
- captures[5].downcase != 'w' ? lon = captures[3].to_f : lon = -(captures[3].to_f)
+ captures[2].downcase != "s" ? lat = captures[0].to_f : lat = -(captures[0].to_f)
+ captures[5].downcase != "w" ? lon = captures[3].to_f : lon = -(captures[3].to_f)
rescue
- captures[0].downcase != 's' ? lat = captures[1].to_f : lat = -(captures[1].to_f)
- captures[3].downcase != 'w' ? lon = captures[4].to_f : lon = -(captures[4].to_f)
+ captures[0].downcase != "s" ? lat = captures[1].to_f : lat = -(captures[1].to_f)
+ captures[3].downcase != "w" ? lon = captures[4].to_f : lon = -(captures[4].to_f)
end
{ :lat => lat, :lon => lon }
end
def ddm_to_decdeg(captures)
begin
Float(captures[0])
- captures[3].downcase != 's' ? lat = captures[0].to_f + captures[1].to_f / 60 : lat = -(captures[0].to_f + captures[1].to_f / 60)
- captures[7].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f / 60 : lon = -(captures[4].to_f + captures[5].to_f / 60)
+ captures[3].downcase != "s" ? lat = captures[0].to_f + captures[1].to_f / 60 : lat = -(captures[0].to_f + captures[1].to_f / 60)
+ captures[7].downcase != "w" ? lon = captures[4].to_f + captures[5].to_f / 60 : lon = -(captures[4].to_f + captures[5].to_f / 60)
rescue
- captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f / 60 : lat = -(captures[1].to_f + captures[2].to_f / 60)
- captures[4].downcase != 'w' ? lon = captures[5].to_f + captures[6].to_f / 60 : lon = -(captures[5].to_f + captures[6].to_f / 60)
+ captures[0].downcase != "s" ? lat = captures[1].to_f + captures[2].to_f / 60 : lat = -(captures[1].to_f + captures[2].to_f / 60)
+ captures[4].downcase != "w" ? lon = captures[5].to_f + captures[6].to_f / 60 : lon = -(captures[5].to_f + captures[6].to_f / 60)
end
{ :lat => lat, :lon => lon }
end
def dms_to_decdeg(captures)
begin
Float(captures[0])
- captures[4].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60)
- captures[9].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60)
+ captures[4].downcase != "s" ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60)
+ captures[9].downcase != "w" ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60)
rescue
- captures[0].downcase != 's' ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60)
- captures[5].downcase != 'w' ? lon = captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60 : lon = -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60)
+ captures[0].downcase != "s" ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60)
+ captures[5].downcase != "w" ? lon = captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60 : lon = -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60)
end
{ :lat => lat, :lon => lon }
end
class MessageController < ApplicationController
- layout 'site'
+ layout "site"
before_filter :authorize_web
before_filter :set_locale
def new
if params[:message]
if @user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= MAX_MESSAGES_PER_HOUR
- flash[:error] = t 'message.new.limit_exceeded'
+ flash[:error] = t "message.new.limit_exceeded"
else
@message = Message.new(message_params)
@message.to_user_id = @this_user.id
@message.sent_on = Time.now.getutc
if @message.save
- flash[:notice] = t 'message.new.message_sent'
+ flash[:notice] = t "message.new.message_sent"
Notifier.message_notification(@message).deliver_now
- redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+ redirect_to :controller => "message", :action => "inbox", :display_name => @user.display_name
end
end
end
@message ||= Message.new(:recipient => @this_user)
- @title = t 'message.new.title'
+ @title = t "message.new.title"
end
# Allow the user to reply to another message.
@title = @message.title
- render :action => 'new'
+ render :action => "new"
else
- flash[:notice] = t 'message.reply.wrong_user', :user => @user.display_name
+ flash[:notice] = t "message.reply.wrong_user", :user => @user.display_name
redirect_to :controller => "user", :action => "login", :referer => request.fullpath
end
rescue ActiveRecord::RecordNotFound
- @title = t 'message.no_such_message.title'
- render :action => 'no_such_message', :status => :not_found
+ @title = t "message.no_such_message.title"
+ render :action => "no_such_message", :status => :not_found
end
# Show a message
def read
- @title = t 'message.read.title'
+ @title = t "message.read.title"
@message = Message.find(params[:message_id])
if @message.to_user_id == @user.id || @message.from_user_id == @user.id
@message.message_read = true if @message.to_user_id == @user.id
@message.save
else
- flash[:notice] = t 'message.read.wrong_user', :user => @user.display_name
+ flash[:notice] = t "message.read.wrong_user", :user => @user.display_name
redirect_to :controller => "user", :action => "login", :referer => request.fullpath
end
rescue ActiveRecord::RecordNotFound
- @title = t 'message.no_such_message.title'
- render :action => 'no_such_message', :status => :not_found
+ @title = t "message.no_such_message.title"
+ render :action => "no_such_message", :status => :not_found
end
# Display the list of messages that have been sent to the user.
def inbox
- @title = t 'message.inbox.title'
+ @title = t "message.inbox.title"
if @user && params[:display_name] == @user.display_name
else
- redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+ redirect_to :controller => "message", :action => "inbox", :display_name => @user.display_name
end
end
# Display the list of messages that the user has sent to other users.
def outbox
- @title = t 'message.outbox.title'
+ @title = t "message.outbox.title"
if @user && params[:display_name] == @user.display_name
else
- redirect_to :controller => 'message', :action => 'outbox', :display_name => @user.display_name
+ redirect_to :controller => "message", :action => "outbox", :display_name => @user.display_name
end
end
# Set the message as being read or unread.
def mark
@message = Message.where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).find(params[:message_id])
- if params[:mark] == 'unread'
+ if params[:mark] == "unread"
message_read = false
- notice = t 'message.mark.as_unread'
+ notice = t "message.mark.as_unread"
else
message_read = true
- notice = t 'message.mark.as_read'
+ notice = t "message.mark.as_read"
end
@message.message_read = message_read
if @message.save && !request.xhr?
flash[:notice] = notice
- redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+ redirect_to :controller => "message", :action => "inbox", :display_name => @user.display_name
end
rescue ActiveRecord::RecordNotFound
- @title = t 'message.no_such_message.title'
- render :action => 'no_such_message', :status => :not_found
+ @title = t "message.no_such_message.title"
+ render :action => "no_such_message", :status => :not_found
end
# Delete the message.
@message.from_user_visible = false if @message.sender == @user
@message.to_user_visible = false if @message.recipient == @user
if @message.save && !request.xhr?
- flash[:notice] = t 'message.delete.deleted'
+ flash[:notice] = t "message.delete.deleted"
if params[:referer]
redirect_to params[:referer]
else
- redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+ redirect_to :controller => "message", :action => "inbox", :display_name => @user.display_name
end
end
rescue ActiveRecord::RecordNotFound
- @title = t 'message.no_such_message.title'
- render :action => 'no_such_message', :status => :not_found
+ @title = t "message.no_such_message.title"
+ render :action => "no_such_message", :status => :not_found
end
private
# The NodeController is the RESTful interface to Node objects
class NodeController < ApplicationController
- require 'xml/libxml'
+ require "xml/libxml"
skip_before_filter :verify_authenticity_token
before_filter :authorize, :only => [:create, :update, :delete]
# Dump the details on many nodes whose ids are given in the "nodes" parameter.
def nodes
- unless params['nodes']
+ unless params["nodes"]
fail OSM::APIBadUserInput.new("The parameter nodes is required, and must be of the form nodes=id[,id[,id...]]")
end
- ids = params['nodes'].split(',').collect(&:to_i)
+ ids = params["nodes"].split(",").collect(&:to_i)
if ids.length == 0
fail OSM::APIBadUserInput.new("No nodes were given to search for")
class NotesController < ApplicationController
- layout 'site', :only => [:mine]
+ layout "site", :only => [:mine]
before_filter :check_api_readable
before_filter :authorize_web, :only => [:mine]
def mine
if params[:display_name]
if @this_user = User.active.find_by_display_name(params[:display_name])
- @title = t 'note.mine.title', :user => @this_user.display_name
- @heading = t 'note.mine.heading', :user => @this_user.display_name
- @description = t 'note.mine.subheading', :user => render_to_string(:partial => "user", :object => @this_user)
+ @title = t "note.mine.title", :user => @this_user.display_name
+ @heading = t "note.mine.heading", :user => @this_user.display_name
+ @description = t "note.mine.subheading", :user => render_to_string(:partial => "user", :object => @this_user)
@page = (params[:page] || 1).to_i
@page_size = 10
@notes = @this_user.notes.order("updated_at DESC, id").uniq.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author).to_a
else
- @title = t 'user.no_such_user.title'
+ @title = t "user.no_such_user.title"
@not_found_user = params[:display_name]
- render :template => 'user/no_such_user', :status => :not_found
+ render :template => "user/no_such_user", :status => :not_found
end
end
end
class OauthClientsController < ApplicationController
- layout 'site'
+ layout "site"
before_filter :authorize_web
before_filter :set_locale
def create
@client_application = @user.client_applications.build(application_params)
if @client_application.save
- flash[:notice] = t 'oauth_clients.create.flash'
+ flash[:notice] = t "oauth_clients.create.flash"
redirect_to :action => "show", :id => @client_application.id
else
render :action => "new"
def update
@client_application = @user.client_applications.find(params[:id])
if @client_application.update_attributes(application_params)
- flash[:notice] = t 'oauth_clients.update.flash'
+ flash[:notice] = t "oauth_clients.update.flash"
redirect_to :action => "show", :id => @client_application.id
else
render :action => "edit"
def destroy
@client_application = @user.client_applications.find(params[:id])
@client_application.destroy
- flash[:notice] = t 'oauth_clients.destroy.flash'
+ flash[:notice] = t "oauth_clients.destroy.flash"
redirect_to :action => "index"
rescue ActiveRecord::RecordNotFound
@type = "client application"
-require 'oauth/controllers/provider_controller'
+require "oauth/controllers/provider_controller"
class OauthController < ApplicationController
include OAuth::Controllers::ProviderController
- layout 'site'
+ layout "site"
def login_required
authorize_web
@token = current_user.oauth_tokens.find_by_token params[:token]
if @token
@token.invalidate!
- flash[:notice] = t('oauth.revoke.flash', :application => @token.client_application.name)
+ flash[:notice] = t("oauth.revoke.flash", :application => @token.client_application.name)
end
redirect_to oauth_clients_url(:display_name => @token.user.display_name)
end
# into one place. as it turns out, the API methods for historical
# nodes, ways and relations are basically identical.
class OldController < ApplicationController
- require 'xml/libxml'
+ require "xml/libxml"
skip_before_filter :verify_authenticity_token
before_filter :setup_user_auth, :only => [:history, :version]
end
def redact
- redaction_id = params['redaction']
+ redaction_id = params["redaction"]
if redaction_id.nil?
# if no redaction ID was provided, then this is an unredact
# operation.
class RedactionsController < ApplicationController
- layout 'site'
+ layout "site"
before_filter :authorize_web
before_filter :set_locale
# note that the description format will default to 'markdown'
if @redaction.save
- flash[:notice] = t('redaction.create.flash')
+ flash[:notice] = t("redaction.create.flash")
redirect_to @redaction
else
- render :action => 'new'
+ render :action => "new"
end
end
@redaction.description = params[:redaction][:description]
if @redaction.save
- flash[:notice] = t('redaction.update.flash')
+ flash[:notice] = t("redaction.update.flash")
redirect_to @redaction
else
- render :action => 'edit'
+ render :action => "edit"
end
end
@redaction.old_ways.empty? &&
@redaction.old_relations.empty?
if @redaction.destroy
- flash[:notice] = t('redaction.destroy.flash')
+ flash[:notice] = t("redaction.destroy.flash")
redirect_to :redactions
else
- flash[:error] = t('redaction.destroy.error')
+ flash[:error] = t("redaction.destroy.error")
redirect_to @redaction
end
else
- flash[:error] = t('redaction.destroy.not_empty')
+ flash[:error] = t("redaction.destroy.not_empty")
redirect_to @redaction
end
end
class RelationController < ApplicationController
- require 'xml/libxml'
+ require "xml/libxml"
skip_before_filter :verify_authenticity_token
before_filter :authorize, :only => [:create, :update, :delete]
# first find the ids of nodes, ways and relations referenced by this
# relation - note that we exclude this relation just in case.
- node_ids = relation.members.select { |m| m[0] == 'Node' }.map { |m| m[1] }
- way_ids = relation.members.select { |m| m[0] == 'Way' }.map { |m| m[1] }
- relation_ids = relation.members.select { |m| m[0] == 'Relation' && m[1] != relation.id }.map { |m| m[1] }
+ node_ids = relation.members.select { |m| m[0] == "Node" }.map { |m| m[1] }
+ way_ids = relation.members.select { |m| m[0] == "Way" }.map { |m| m[1] }
+ relation_ids = relation.members.select { |m| m[0] == "Relation" && m[1] != relation.id }.map { |m| m[1] }
# next load the relations and the ways.
end
def relations
- unless params['relations']
+ unless params["relations"]
fail OSM::APIBadUserInput.new("The parameter relations is required, and must be of the form relations=id[,id[,id...]]")
end
- ids = params['relations'].split(',').collect(&:to_i)
+ ids = params["relations"].split(",").collect(&:to_i)
if ids.length == 0
fail OSM::APIBadUserInput.new("No relations were given to search for")
end
def do_search(do_ways, do_nodes, do_relations)
- type = params['type']
- value = params['value']
+ type = params["type"]
+ value = params["value"]
unless type || value
- name = params['name']
+ name = params["name"]
if name
- type = 'name'
+ type = "name"
value = name
end
end
if do_nodes
- response.headers['Error'] = "Searching of nodes is currently unavailable"
+ response.headers["Error"] = "Searching of nodes is currently unavailable"
render :text => "", :status => :service_unavailable
return false
end
unless value
- response.headers['Error'] = "Searching for a key without value is currently unavailable"
+ response.headers["Error"] = "Searching for a key without value is currently unavailable"
render :text => "", :status => :service_unavailable
return false
end
class SiteController < ApplicationController
- layout 'site'
+ layout "site"
layout :map_layout, :only => [:index, :export]
before_filter :authorize_web
def index
unless STATUS == :database_readonly || STATUS == :database_offline
- session[:location] ||= OSM.ip_location(request.env['REMOTE_ADDR'])
+ session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"])
end
end
end
if params.key? :node
- new_params[:controller] = 'browse'
- new_params[:action] = 'node'
+ new_params[:controller] = "browse"
+ new_params[:action] = "node"
new_params[:id] = params[:node]
elsif params.key? :way
- new_params[:controller] = 'browse'
- new_params[:action] = 'way'
+ new_params[:controller] = "browse"
+ new_params[:action] = "way"
new_params[:id] = params[:way]
elsif params.key? :relation
- new_params[:controller] = 'browse'
- new_params[:action] = 'relation'
+ new_params[:controller] = "browse"
+ new_params[:action] = "relation"
new_params[:id] = params[:relation]
elsif params.key? :changeset
- new_params[:controller] = 'browse'
- new_params[:action] = 'changeset'
+ new_params[:controller] = "browse"
+ new_params[:action] = "changeset"
new_params[:id] = params[:changeset]
else
- new_params[:controller] = 'site'
- new_params[:action] = 'index'
+ new_params[:controller] = "site"
+ new_params[:action] = "index"
end
new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
if params[:layers]
anchor << "layers=#{params.delete(:layers)}"
- elsif params.delete(:notes) == 'yes'
+ elsif params.delete(:notes) == "yes"
anchor << "layers=N"
end
if anchor.present?
- redirect_to Hash[params].merge(:anchor => anchor.join('&'))
+ redirect_to Hash[params].merge(:anchor => anchor.join("&"))
end
end
end
def trackpoints
# - Initialise
- baselong = params['baselong'].to_f
- basey = params['basey'].to_f
- masterscale = params['masterscale'].to_f
+ baselong = params["baselong"].to_f
+ basey = params["basey"].to_f
+ masterscale = params["masterscale"].to_f
- bbox = BoundingBox.new(params['xmin'], params['ymin'],
- params['xmax'], params['ymax'])
- start = params['start'].to_i
+ bbox = BoundingBox.new(params["xmin"], params["ymin"],
+ params["xmax"], params["ymax"])
+ start = params["start"].to_i
# - Begin movie
bounds_bottom = 0
bounds_top = 240 * 20
- m = ''
+ m = ""
m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background
absx = 0
absy = 0
# - Send SQL for GPS tracks
- b = ''
+ b = ""
lasttime = 0
- lasttrack = lastfile = '-1'
+ lasttrack = lastfile = "-1"
- if params['token']
+ if params["token"]
user = User.authenticate(:token => params[:token])
sql = "SELECT gps_points.latitude*0.0000001 AS lat,gps_points.longitude*0.0000001 AS lon,gpx_files.id AS fileid," + " EXTRACT(EPOCH FROM gps_points.timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gpx_files,gps_points " + "WHERE gpx_files.id=gpx_id " + " AND gpx_files.user_id=#{user.id} " + " AND " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
else
r = start_shape
gpslist.each do |row|
- xs = (long2coord(row['lon'].to_f, baselong, masterscale) * 20).floor
- ys = (lat2coord(row['lat'].to_f, basey, masterscale) * 20).floor
+ xs = (long2coord(row["lon"].to_f, baselong, masterscale) * 20).floor
+ ys = (lat2coord(row["lat"].to_f, basey, masterscale) * 20).floor
xl = [xs, xl].min
xr = [xs, xr].max
yb = [ys, yb].min
yt = [ys, yt].max
- if row['ts'].to_i - lasttime > 180 || row['fileid'] != lastfile || row['trackid'] != lasttrack # or row['ts'].to_i==lasttime
- b += start_and_move(xs, ys, '01')
+ if row["ts"].to_i - lasttime > 180 || row["fileid"] != lastfile || row["trackid"] != lasttrack # or row['ts'].to_i==lasttime
+ b += start_and_move(xs, ys, "01")
absx = xs.floor
absy = ys.floor
end
b += draw_to(absx, absy, xs, ys)
absx = xs.floor
absy = ys.floor
- lasttime = row['ts'].to_i
- lastfile = row['fileid']
- lasttrack = row['trackid']
+ lasttime = row["ts"].to_i
+ lastfile = row["fileid"]
+ lasttrack = row["trackid"]
r += [b.slice!(0...80)].pack("B*") while b.length > 80
end
# - Create Flash header and write to browser
- m += swf_record(1, '') # Show frame
- m += swf_record(0, '') # End
+ m += swf_record(1, "") # Show frame
+ m += swf_record(0, "") # End
m = pack_rect(bounds_left, bounds_right, bounds_bottom, bounds_top) + 0.chr + 12.chr + pack_u16(1) + m
- m = 'FWS' + 6.chr + pack_u32(m.length + 8) + m
+ m = "FWS" + 6.chr + pack_u32(m.length + 8) + m
render :text => m, :content_type => "application/x-shockwave-flash"
end
end
def end_shape
- '000000'
+ "000000"
end
def start_and_move(x, y, col)
- d = '001001' # Line style change, moveTo
+ d = "001001" # Line style change, moveTo
l = [length_sb(x), length_sb(y)].max
d += sprintf("%05b%0#{l}b%0#{l}b", l, x, y)
d += col # Select line style
mstep = [dx.abs / 16383, dy.abs / 16383, 1].max.ceil
xstep = dx / mstep
ystep = dy / mstep
- d = ''
+ d = ""
1.upto(mstep).each do
d += draw_section(x, y, x + xstep, y + ystep)
x += xstep
end
def draw_section(x1, y1, x2, y2)
- d = '11' # TypeFlag, EdgeFlag
+ d = "11" # TypeFlag, EdgeFlag
dx = x2 - x1
dy = y2 - y1
l = [length_sb(dx), length_sb(dy)].max
d += sprintf("%04b", l - 2)
- d += '1' # GeneralLine
+ d += "1" # GeneralLine
d += sprintf("%0#{l}b%0#{l}b", dx, dy)
d
end
class TraceController < ApplicationController
- layout 'site'
+ layout "site"
skip_before_filter :verify_authenticity_token, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
before_filter :authorize_web
# set title
if target_user.nil?
- @title = t 'trace.list.public_traces'
+ @title = t "trace.list.public_traces"
elsif @user && @user == target_user
- @title = t 'trace.list.your_traces'
+ @title = t "trace.list.your_traces"
else
- @title = t 'trace.list.public_traces_from', :user => target_user.display_name
+ @title = t "trace.list.public_traces_from", :user => target_user.display_name
end
- @title += t 'trace.list.tagged_with', :tags => params[:tag] if params[:tag]
+ @title += t "trace.list.tagged_with", :tags => params[:tag] if params[:tag]
# four main cases:
# 1 - all traces, logged in = all public traces + all user's (i.e + all mine)
if @trace && @trace.visible? &&
(@trace.public? || @trace.user == @user)
- @title = t 'trace.view.title', :name => @trace.name
+ @title = t "trace.view.title", :name => @trace.name
else
- flash[:error] = t 'trace.view.trace_not_found'
- redirect_to :controller => 'trace', :action => 'list'
+ flash[:error] = t "trace.view.trace_not_found"
+ redirect_to :controller => "trace", :action => "list"
end
rescue ActiveRecord::RecordNotFound
- flash[:error] = t 'trace.view.trace_not_found'
- redirect_to :controller => 'trace', :action => 'list'
+ flash[:error] = t "trace.view.trace_not_found"
+ redirect_to :controller => "trace", :action => "list"
end
def create
if @trace.id
logger.info("id is #{@trace.id}")
- flash[:notice] = t 'trace.create.trace_uploaded'
+ flash[:notice] = t "trace.create.trace_uploaded"
if @user.traces.where(:inserted => false).count > 4
- flash[:warning] = t 'trace.trace_header.traces_waiting', :count => @user.traces.where(:inserted => false).count
+ flash[:warning] = t "trace.trace_header.traces_waiting", :count => @user.traces.where(:inserted => false).count
end
redirect_to :action => :list, :display_name => @user.display_name
@trace = Trace.new(:visibility => default_visibility)
end
- @title = t 'trace.create.upload_trace'
+ @title = t "trace.create.upload_trace"
end
def data
if Acl.no_trace_download(request.remote_ip)
render :text => "", :status => :forbidden
elsif request.format == Mime::XML
- send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => 'attachment')
+ send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
elsif request.format == Mime::GPX
- send_file(trace.xml_file, :filename => "#{trace.id}.gpx", :type => request.format.to_s, :disposition => 'attachment')
+ send_file(trace.xml_file, :filename => "#{trace.id}.gpx", :type => request.format.to_s, :disposition => "attachment")
else
- send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment')
+ send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
else
render :text => "", :status => :not_found
elsif @user.nil? || @trace.user != @user
render :text => "", :status => :forbidden
else
- @title = t 'trace.edit.title', :name => @trace.name
+ @title = t "trace.edit.title", :name => @trace.name
if params[:trace]
@trace.description = params[:trace][:description]
@trace.tagstring = params[:trace][:tagstring]
@trace.visibility = params[:trace][:visibility]
if @trace.save
- redirect_to :action => 'view', :display_name => @user.display_name
+ redirect_to :action => "view", :display_name => @user.display_name
end
end
end
else
trace.visible = false
trace.save
- flash[:notice] = t 'trace.delete.scheduled_for_deletion'
+ flash[:notice] = t "trace.delete.scheduled_for_deletion"
redirect_to :action => :list, :display_name => @user.display_name
end
rescue ActiveRecord::RecordNotFound
if trace.inserted?
if trace.public? || (@user && @user == trace.user)
expires_in 7.days, :private => !trace.public?, :public => trace.public?
- send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline')
+ send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => "image/gif", :disposition => "inline")
else
render :text => "", :status => :forbidden
end
if trace.inserted?
if trace.public? || (@user && @user == trace.user)
expires_in 7.days, :private => !trace.public?, :public => trace.public?
- send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline')
+ send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => "image/gif", :disposition => "inline")
else
render :text => "", :status => :forbidden
end
if trace.public? || trace.user == @user
if request.format == Mime::XML || request.format == Mime::GPX
- send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => 'attachment')
+ send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
else
- send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment')
+ send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
else
render :text => "", :status => :forbidden
def do_create(file, tags, description, visibility)
# Sanitise the user's filename
- name = file.original_filename.gsub(/[^a-zA-Z0-9.]/, '_')
+ name = file.original_filename.gsub(/[^a-zA-Z0-9.]/, "_")
# Get a temporary filename...
filename = "/tmp/#{rand}"
end
def offline_warning
- flash.now[:warning] = t 'trace.offline_warning.message' if STATUS == :gpx_offline
+ flash.now[:warning] = t "trace.offline_warning.message" if STATUS == :gpx_offline
end
def offline_redirect
class UserBlocksController < ApplicationController
- layout 'site'
+ layout "site"
before_filter :authorize_web
before_filter :set_locale
)
if @user_block.save
- flash[:notice] = t('user_block.create.flash', :name => @this_user.display_name)
+ flash[:notice] = t("user_block.create.flash", :name => @this_user.display_name)
redirect_to @user_block
else
render :action => "new"
def update
if @valid_params
if @user_block.creator_id != @user.id
- flash[:error] = t('user_block.update.only_creator_can_edit')
+ flash[:error] = t("user_block.update.only_creator_can_edit")
redirect_to :action => "edit"
elsif @user_block.update_attributes(
:ends_at => Time.now.getutc + @block_period.hours,
:reason => params[:user_block][:reason],
:needs_view => params[:user_block][:needs_view]
)
- flash[:notice] = t('user_block.update.success')
+ flash[:notice] = t("user_block.update.success")
redirect_to(@user_block)
else
render :action => "edit"
def revoke
if params[:confirm]
if @user_block.revoke! @user
- flash[:notice] = t 'user_block.revoke.flash'
+ flash[:notice] = t "user_block.revoke.flash"
redirect_to(@user_block)
end
end
@valid_params = false
if !UserBlock::PERIODS.include?(@block_period)
- flash[:error] = t('user_block.filter.block_period')
+ flash[:error] = t("user_block.filter.block_period")
elsif @user_block && !@user_block.active?
- flash[:error] = t('user_block.filter.block_expired')
+ flash[:error] = t("user_block.filter.block_expired")
else
@valid_params = true
class UserController < ApplicationController
- layout 'site', :except => [:api_details]
+ layout "site", :except => [:api_details]
skip_before_filter :verify_authenticity_token, :only => [:api_read, :api_details, :api_gpx_files]
before_filter :disable_terms_redirect, :only => [:terms, :save, :logout, :api_details]
if request.xhr?
render :partial => "terms"
else
- @title = t 'user.terms.title'
+ @title = t "user.terms.title"
if @user && @user.terms_agreed?
# Already agreed to terms, so just show settings
end
def save
- @title = t 'user.new.title'
+ @title = t "user.new.title"
if params[:decline]
if @user
@user.terms_seen = true
if @user.save
- flash[:notice] = t 'user.new.terms declined', :url => t('user.new.terms declined url')
+ flash[:notice] = t "user.new.terms declined", :url => t("user.new.terms declined url")
end
if params[:referer]
redirect_to :action => :account, :display_name => @user.display_name
end
else
- redirect_to t('user.terms.declined')
+ redirect_to t("user.terms.declined")
end
elsif @user
unless @user.terms_agreed?
@user.terms_agreed = Time.now.getutc
@user.terms_seen = true
- flash[:notice] = t 'user.new.terms accepted' if @user.save
+ flash[:notice] = t "user.new.terms accepted" if @user.save
end
if params[:referer]
begin
uri = URI(session[:referer])
/map=(.*)\/(.*)\/(.*)/.match(uri.fragment) do |m|
- editor = Rack::Utils.parse_query(uri.query).slice('editor')
- referer = welcome_path({ 'zoom' => m[1],
- 'lat' => m[2],
- 'lon' => m[3] }.merge(editor))
+ editor = Rack::Utils.parse_query(uri.query).slice("editor")
+ referer = welcome_path({ "zoom" => m[1],
+ "lat" => m[2],
+ "lon" => m[3] }.merge(editor))
end
rescue
# Use default
else
session[:token] = @user.tokens.create.token
Notifier.signup_confirm(@user, @user.tokens.create(:referer => referer)).deliver_now
- redirect_to :action => 'confirm', :display_name => @user.display_name
+ redirect_to :action => "confirm", :display_name => @user.display_name
end
else
- render :action => 'new', :referer => params[:referer]
+ render :action => "new", :referer => params[:referer]
end
end
end
end
def account
- @title = t 'user.account.title'
+ @title = t "user.account.title"
@tokens = @user.oauth_tokens.authorized
if params[:user] && params[:user][:display_name] && params[:user][:description]
def go_public
@user.data_public = true
@user.save
- flash[:notice] = t 'user.go_public.flash success'
- redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
+ flash[:notice] = t "user.go_public.flash success"
+ redirect_to :controller => "user", :action => "account", :display_name => @user.display_name
end
def lost_password
- @title = t 'user.lost_password.title'
+ @title = t "user.lost_password.title"
if params[:user] && params[:user][:email]
user = User.visible.find_by_email(params[:user][:email])
if user
token = user.tokens.create
Notifier.lost_password(user, token).deliver_now
- flash[:notice] = t 'user.lost_password.notice email on way'
- redirect_to :action => 'login'
+ flash[:notice] = t "user.lost_password.notice email on way"
+ redirect_to :action => "login"
else
- flash.now[:error] = t 'user.lost_password.notice email cannot find'
+ flash.now[:error] = t "user.lost_password.notice email cannot find"
end
end
end
def reset_password
- @title = t 'user.reset_password.title'
+ @title = t "user.reset_password.title"
if params[:token]
token = UserToken.find_by_token(params[:token])
if @user.save
token.destroy
- flash[:notice] = t 'user.reset_password.flash changed'
- redirect_to :action => 'login'
+ flash[:notice] = t "user.reset_password.flash changed"
+ redirect_to :action => "login"
end
end
else
- flash[:error] = t 'user.reset_password.flash token bad'
- redirect_to :action => 'lost_password'
+ flash[:error] = t "user.reset_password.flash token bad"
+ redirect_to :action => "lost_password"
end
else
render :text => "", :status => :bad_request
end
def new
- @title = t 'user.new.title'
+ @title = t "user.new.title"
@referer = params[:referer] || session[:referer]
if using_open_id?
end
if @user.openid_url.nil? || @user.invalid?
- render :action => 'new'
+ render :action => "new"
else
session[:new_user] = @user
- redirect_to :action => 'terms'
+ redirect_to :action => "terms"
end
elsif @user
# The user is logged in already, so don't show them the signup
if @referer
redirect_to @referer
else
- redirect_to :controller => 'site', :action => 'index'
+ redirect_to :controller => "site", :action => "index"
end
elsif params.key?(:openid)
@user = User.new(:email => params[:email],
:display_name => params[:nickname],
:openid_url => params[:openid])
- flash.now[:notice] = t 'user.new.openid association'
+ flash.now[:notice] = t "user.new.openid association"
else
check_signup_allowed
end
end
def logout
- @title = t 'user.logout.title'
+ @title = t "user.logout.title"
if params[:session] == request.session_options[:id]
if session[:token]
if params[:referer]
redirect_to params[:referer]
else
- redirect_to :controller => 'site', :action => 'index'
+ redirect_to :controller => "site", :action => "index"
end
end
end
if request.post?
token = UserToken.find_by_token(params[:confirm_string])
if token && token.user.active?
- flash[:error] = t('user.confirm.already active')
- redirect_to :action => 'login'
+ flash[:error] = t("user.confirm.already active")
+ redirect_to :action => "login"
elsif !token || token.expired?
- flash[:error] = t('user.confirm.unknown token')
- redirect_to :action => 'confirm'
+ flash[:error] = t("user.confirm.unknown token")
+ redirect_to :action => "confirm"
else
user = token.user
user.status = "active"
end
if token.nil? || token.user != user
- flash[:notice] = t('user.confirm.success')
+ flash[:notice] = t("user.confirm.success")
redirect_to :action => :login, :referer => referer
else
token.destroy
def confirm_resend
if user = User.find_by_display_name(params[:display_name])
Notifier.signup_confirm(user, user.tokens.create).deliver_now
- flash[:notice] = t 'user.confirm_resend.success', :email => user.email
+ flash[:notice] = t "user.confirm_resend.success", :email => user.email
else
- flash[:notice] = t 'user.confirm_resend.failure', :name => params[:display_name]
+ flash[:notice] = t "user.confirm_resend.failure", :name => params[:display_name]
end
- redirect_to :action => 'login'
+ redirect_to :action => "login"
end
def confirm_email
@user.new_email = nil
@user.email_valid = true
if @user.save
- flash[:notice] = t 'user.confirm_email.success'
+ flash[:notice] = t "user.confirm_email.success"
else
flash[:errors] = @user.errors
end
token.destroy
session[:user] = @user.id
- redirect_to :action => 'account', :display_name => @user.display_name
+ redirect_to :action => "account", :display_name => @user.display_name
else
- flash[:error] = t 'user.confirm_email.failure'
- redirect_to :action => 'account', :display_name => @user.display_name
+ flash[:error] = t "user.confirm_email.failure"
+ redirect_to :action => "account", :display_name => @user.display_name
end
end
end
friend.user_id = @user.id
friend.friend_user_id = @new_friend.id
if @user.is_friends_with?(@new_friend)
- flash[:warning] = t 'user.make_friend.already_a_friend', :name => @new_friend.display_name
+ flash[:warning] = t "user.make_friend.already_a_friend", :name => @new_friend.display_name
else
if friend.save
- flash[:notice] = t 'user.make_friend.success', :name => @new_friend.display_name
+ flash[:notice] = t "user.make_friend.success", :name => @new_friend.display_name
Notifier.friend_notification(friend).deliver_now
else
- friend.add_error(t('user.make_friend.failed', :name => @new_friend.display_name))
+ friend.add_error(t("user.make_friend.failed", :name => @new_friend.display_name))
end
end
if params[:referer]
redirect_to params[:referer]
else
- redirect_to :controller => 'user', :action => 'view'
+ redirect_to :controller => "user", :action => "view"
end
end
else
if request.post?
if @user.is_friends_with?(@friend)
Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{@friend.id}"
- flash[:notice] = t 'user.remove_friend.success', :name => @friend.display_name
+ flash[:notice] = t "user.remove_friend.success", :name => @friend.display_name
else
- flash[:error] = t 'user.remove_friend.not_a_friend', :name => @friend.display_name
+ flash[:error] = t "user.remove_friend.not_a_friend", :name => @friend.display_name
end
if params[:referer]
redirect_to params[:referer]
else
- redirect_to :controller => 'user', :action => 'view'
+ redirect_to :controller => "user", :action => "view"
end
end
else
def set_status
@this_user.status = params[:status]
@this_user.save
- redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
+ redirect_to :controller => "user", :action => "view", :display_name => params[:display_name]
end
##
# delete a user, marking them as deleted and removing personal data
def delete
@this_user.delete
- redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
+ redirect_to :controller => "user", :action => "view", :display_name => params[:display_name]
end
##
elsif user = User.authenticate(:username => username, :password => password, :pending => true)
unconfirmed_login(user)
elsif User.authenticate(:username => username, :password => password, :suspended => true)
- failed_login t('user.login.account is suspended', :webmaster => "mailto:webmaster@openstreetmap.org")
+ failed_login t("user.login.account is suspended", :webmaster => "mailto:webmaster@openstreetmap.org")
else
- failed_login t('user.login.auth failure')
+ failed_login t("user.login.auth failure")
end
end
when "active", "confirmed" then
successful_login(user)
when "suspended" then
- failed_login t('user.login.account is suspended', :webmaster => "mailto:webmaster@openstreetmap.org")
+ failed_login t("user.login.account is suspended", :webmaster => "mailto:webmaster@openstreetmap.org")
else
- failed_login t('user.login.auth failure')
+ failed_login t("user.login.auth failure")
end
else
# Guard against not getting any extension data
nickname = sreg["nickname"] || ax["http://axschema.org/namePerson/friendly"].first
email = sreg["email"] || ax["http://axschema.org/contact/email"].first
- redirect_to :controller => 'user', :action => 'new', :nickname => nickname, :email => email, :openid => identity_url
+ redirect_to :controller => "user", :action => "new", :nickname => nickname, :email => email, :openid => identity_url
end
elsif result.missing?
- failed_login t('user.login.openid missing provider')
+ failed_login t("user.login.openid missing provider")
elsif result.invalid?
- failed_login t('user.login.openid invalid')
+ failed_login t("user.login.openid invalid")
else
- failed_login t('user.login.auth failure')
+ failed_login t("user.login.auth failure")
end
end
end
user.openid_url = identity_url
yield user, verified_email
elsif result.missing?
- flash.now[:error] = t 'user.login.openid missing provider'
+ flash.now[:error] = t "user.login.openid missing provider"
elsif result.invalid?
- flash.now[:error] = t 'user.login.openid invalid'
+ flash.now[:error] = t "user.login.openid invalid"
else
- flash.now[:error] = t 'user.login.auth failure'
+ flash.now[:error] = t "user.login.auth failure"
end
end
end
# provider and, unlike yahoo.com, where it works automatically, Google
# have hidden their OpenID endpoint somewhere obscure this making it
# somewhat less user friendly.
- return 'https://www.google.com/accounts/o8/id'
+ return "https://www.google.com/accounts/o8/id"
else
return openid_url
end
def failed_login(message)
flash[:error] = message
- redirect_to :action => 'login', :referer => session[:referer]
+ redirect_to :action => "login", :referer => session[:referer]
session.delete(:remember_me)
session.delete(:referer)
##
#
def unconfirmed_login(user)
- redirect_to :action => 'confirm', :display_name => user.display_name
+ redirect_to :action => "confirm", :display_name => user.display_name
session.delete(:remember_me)
session.delete(:referer)
set_locale
if user.new_email.blank? || user.new_email == user.email
- flash.now[:notice] = t 'user.account.flash update success'
+ flash.now[:notice] = t "user.account.flash update success"
else
user.email = user.new_email
if user.valid?
- flash.now[:notice] = t 'user.account.flash update success confirm needed'
+ flash.now[:notice] = t "user.account.flash update success confirm needed"
begin
Notifier.email_confirm(user, user.tokens.create).deliver_now
# and return them to the user page.
def require_administrator
if @user && !@user.administrator?
- flash[:error] = t('user.filter.not_an_administrator')
+ flash[:error] = t("user.filter.not_an_administrator")
if params[:display_name]
- redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
+ redirect_to :controller => "user", :action => "view", :display_name => params[:display_name]
else
- redirect_to :controller => 'user', :action => 'login', :referer => request.fullpath
+ redirect_to :controller => "user", :action => "login", :referer => request.fullpath
end
elsif !@user
- redirect_to :controller => 'user', :action => 'login', :referer => request.fullpath
+ redirect_to :controller => "user", :action => "login", :referer => request.fullpath
end
end
def lookup_user_by_name
@this_user = User.find_by_display_name(params[:display_name])
rescue ActiveRecord::RecordNotFound
- redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name] unless @this_user
+ redirect_to :controller => "user", :action => "view", :display_name => params[:display_name] unless @this_user
end
##
if blocked = Acl.no_account_creation(request.remote_ip, domain)
logger.info "Blocked signup from #{request.remote_ip} for #{email}"
- render :action => 'blocked'
+ render :action => "blocked"
end
!blocked
prefs = @user.preferences
- el1 = XML::Node.new 'preferences'
+ el1 = XML::Node.new "preferences"
prefs.each do |pref|
el1 << pref.to_xml_node
doc = XML::Parser.string(request.raw_post).parse
- doc.find('//preferences/preference').each do |pt|
+ doc.find("//preferences/preference").each do |pt|
if preference = old_preferences.delete(pt["k"])
preference.v = pt["v"]
elsif new_preferences.include?(pt["k"])
class UserRolesController < ApplicationController
- layout 'site'
+ layout "site"
before_filter :authorize_web
before_filter :require_user
def grant
@this_user.roles.create(:role => @role, :granter_id => @user.id)
- redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
+ redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
def revoke
UserRole.delete_all(:user_id => @this_user.id, :role => @role)
- redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
+ redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
private
# and return them to theuser page.
def require_administrator
unless @user.administrator?
- flash[:error] = t 'user_role.filter.not_an_administrator'
- redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
+ flash[:error] = t "user_role.filter.not_an_administrator"
+ redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
end
def require_valid_role
@role = params[:role]
unless UserRole::ALL_ROLES.include?(@role)
- flash[:error] = t('user_role.filter.not_a_role', :role => @role)
- redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
+ flash[:error] = t("user_role.filter.not_a_role", :role => @role)
+ redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
end
# checks that the user doesn't already have this role
def not_in_role
if @this_user.has_role? @role
- flash[:error] = t('user_role.filter.already_has_role', :role => @role)
- redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
+ flash[:error] = t("user_role.filter.already_has_role", :role => @role)
+ redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
end
# checks that the user already has this role
def in_role
unless @this_user.has_role? @role
- flash[:error] = t('user_role.filter.doesnt_have_role', :role => @role)
- redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
+ flash[:error] = t("user_role.filter.doesnt_have_role", :role => @role)
+ redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
end
end
class WayController < ApplicationController
- require 'xml/libxml'
+ require "xml/libxml"
skip_before_filter :verify_authenticity_token
before_filter :authorize, :only => [:create, :update, :delete]
end
def ways
- unless params['ways']
+ unless params["ways"]
fail OSM::APIBadUserInput.new("The parameter ways is required, and must be of the form ways=id[,id[,id...]]")
end
- ids = params['ways'].split(',').collect(&:to_i)
+ ids = params["ways"].split(",").collect(&:to_i)
if ids.length == 0
fail OSM::APIBadUserInput.new("No ways were given to search for")
module ApplicationHelper
- require 'rexml/document'
+ require "rexml/document"
def linkify(text)
if text.html_safe?
else
id = object.id
end
- name = t 'printable_name.with_id', :id => id.to_s
+ name = t "printable_name.with_id", :id => id.to_s
if version
- name = t 'printable_name.with_version', :id => name, :version => object.version.to_s
+ name = t "printable_name.with_version", :id => name, :version => object.version.to_s
end
# don't look at object tags if redacted, so as to avoid giving
end
if object.tags.include? "name:#{locale}"
- name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags["name:#{locale}"].to_s), :id => content_tag(:bdi, name)
- elsif object.tags.include? 'name'
- name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags['name'].to_s), :id => content_tag(:bdi, name)
+ name = t "printable_name.with_name_html", :name => content_tag(:bdi, object.tags["name:#{locale}"].to_s), :id => content_tag(:bdi, name)
+ elsif object.tags.include? "name"
+ name = t "printable_name.with_name_html", :name => content_tag(:bdi, object.tags["name"].to_s), :id => content_tag(:bdi, name)
end
end
if object.redacted?
""
else
- h(icon_tags(object).map { |k, v| k + '=' + v }.to_sentence)
+ h(icon_tags(object).map { |k, v| k + "=" + v }.to_sentence)
end
end
def format_key(key)
if url = wiki_link("key", key)
- link_to h(key), url, :title => t('browse.tag_details.wiki_link.key', :key => key)
+ link_to h(key), url, :title => t("browse.tag_details.wiki_link.key", :key => key)
else
h(key)
end
def format_value(key, value)
if wp = wikipedia_link(key, value)
- link_to h(wp[:title]), wp[:url], :title => t('browse.tag_details.wikipedia_link', :page => wp[:title])
+ link_to h(wp[:title]), wp[:url], :title => t("browse.tag_details.wikipedia_link", :page => wp[:title])
elsif wdt = wikidata_link(key, value)
- link_to h(wdt[:title]), wdt[:url], :title => t('browse.tag_details.wikidata_link', :page => wdt[:title])
+ link_to h(wdt[:title]), wdt[:url], :title => t("browse.tag_details.wikidata_link", :page => wdt[:title])
elsif url = wiki_link("tag", "#{key}=#{value}")
- link_to h(value), url, :title => t('browse.tag_details.wiki_link.tag', :key => key, :value => value)
+ link_to h(value), url, :title => t("browse.tag_details.wiki_link.tag", :key => key, :value => value)
elsif url = telephone_link(key, value)
- link_to h(value), url, :title => t('browse.tag_details.telephone_link', :phone_number => value)
+ link_to h(value), url, :title => t("browse.tag_details.telephone_link", :phone_number => value)
else
linkify h(value)
end
lang = $1
else
# Value is <title> so default to English Wikipedia
- lang = 'en'
+ lang = "en"
end
elsif key =~ /^wikipedia:(\S+)$/
# Language is in the key, so assume value is the title
# remove all whitespace instead of encoding it http://tools.ietf.org/html/rfc3966#section-5.1.1
# "+1 (234) 567-8901 " -> "+1(234)567-8901"
- value_no_whitespace = value.gsub(/\s+/, '')
+ value_no_whitespace = value.gsub(/\s+/, "")
"tel:#{value_no_whitespace}"
end
if changeset.user.data_public?
link_to(changeset.user.display_name, user_path(changeset.user.display_name))
else
- t('browse.anonymous')
+ t("browse.anonymous")
end
end
end
result.each do |key, value|
- html_options[:data][key.to_s.tr('_', '-')] = value
+ html_options[:data][key.to_s.tr("_", "-")] = value
end
html = ""
-require 'htmlentities'
+require "htmlentities"
module TitleHelper
@@coder = HTMLEntities.new
def set_title(title = false)
if title
@title = @@coder.decode(title.gsub("<bdi>", "\u202a").gsub("</bdi>", "\u202c"))
- response.headers["X-Page-Title"] = t('layouts.project_name.title') + ' | ' + @title
+ response.headers["X-Page-Title"] = t("layouts.project_name.title") + " | " + @title
else
@title = title
- response.headers["X-Page-Title"] = t('layouts.project_name.title')
+ response.headers["X-Page-Title"] = t("layouts.project_name.title")
end
end
end
def block_status(block)
if block.active?
if block.needs_view?
- I18n.t('user_block.helper.until_login')
+ I18n.t("user_block.helper.until_login")
else
- I18n.t('user_block.helper.time_future', :time => distance_of_time_in_words_to_now(block.ends_at))
+ I18n.t("user_block.helper.time_future", :time => distance_of_time_in_words_to_now(block.ends_at))
end
else
# the max of the last update time or the ends_at time is when this block finished
# either because the user viewed the block (updated_at) or it expired or was
# revoked (ends_at)
last_time = [block.ends_at, block.updated_at].max
- I18n.t('user_block.helper.time_past', :time => distance_of_time_in_words_to_now(last_time))
+ I18n.t("user_block.helper.time_past", :time => distance_of_time_in_words_to_now(last_time))
end
end
end
# OpenID support
def openid_logo
- image_tag "openid_small.png", :alt => t('user.login.openid_logo_alt'), :class => "openid_logo"
+ image_tag "openid_small.png", :alt => t("user.login.openid_logo_alt"), :class => "openid_logo"
end
def openid_button(name, url)
class Changeset < ActiveRecord::Base
- require 'xml/libxml'
+ require "xml/libxml"
belongs_to :user, :counter_cache => true
has_many :old_relations
has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "ChangesetComment"
- has_and_belongs_to_many :subscribers, :class_name => 'User', :join_table => 'changesets_subscribers', :association_foreign_key => 'subscriber_id'
+ has_and_belongs_to_many :subscribers, :class_name => "User", :join_table => "changesets_subscribers", :association_foreign_key => "subscriber_id"
validates_presence_of :id, :on => :update
validates_presence_of :user_id, :created_at, :closed_at, :num_changes
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
- doc.find('//osm/changeset').each do |pt|
+ doc.find("//osm/changeset").each do |pt|
return Changeset.from_xml_node(pt, create)
end
fail OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
cs.num_changes = 0
end
- pt.find('tag').each do |tag|
- fail OSM::APIBadXMLError.new("changeset", pt, "tag is missing key") if tag['k'].nil?
- fail OSM::APIBadXMLError.new("changeset", pt, "tag is missing value") if tag['v'].nil?
- cs.add_tag_keyval(tag['k'], tag['v'])
+ pt.find("tag").each do |tag|
+ fail OSM::APIBadXMLError.new("changeset", pt, "tag is missing key") if tag["k"].nil?
+ fail OSM::APIBadXMLError.new("changeset", pt, "tag is missing value") if tag["v"].nil?
+ cs.add_tag_keyval(tag["k"], tag["v"])
end
cs
end
def to_xml_node(user_display_name_cache = nil, include_discussion = false)
- el1 = XML::Node.new 'changeset'
- el1['id'] = id.to_s
+ el1 = XML::Node.new "changeset"
+ el1["id"] = id.to_s
user_display_name_cache = {} if user_display_name_cache.nil?
user_display_name_cache[user_id] = nil
end
- el1['user'] = user_display_name_cache[user_id] unless user_display_name_cache[user_id].nil?
- el1['uid'] = user_id.to_s if user.data_public?
+ el1["user"] = user_display_name_cache[user_id] unless user_display_name_cache[user_id].nil?
+ el1["uid"] = user_id.to_s if user.data_public?
tags.each do |k, v|
- el2 = XML::Node.new('tag')
- el2['k'] = k.to_s
- el2['v'] = v.to_s
+ el2 = XML::Node.new("tag")
+ el2["k"] = k.to_s
+ el2["v"] = v.to_s
el1 << el2
end
- el1['created_at'] = created_at.xmlschema
- el1['closed_at'] = closed_at.xmlschema unless is_open?
- el1['open'] = is_open?.to_s
+ el1["created_at"] = created_at.xmlschema
+ el1["closed_at"] = closed_at.xmlschema unless is_open?
+ el1["open"] = is_open?.to_s
- bbox.to_unscaled.add_bounds_to(el1, '_') if bbox.complete?
+ bbox.to_unscaled.add_bounds_to(el1, "_") if bbox.complete?
- el1['comments_count'] = comments.count.to_s
+ el1["comments_count"] = comments.count.to_s
if include_discussion
- el2 = XML::Node.new('discussion')
+ el2 = XML::Node.new("discussion")
comments.includes(:author).each do |comment|
- el3 = XML::Node.new('comment')
- el3['date'] = comment.created_at.xmlschema
- el3['uid'] = comment.author.id.to_s if comment.author.data_public?
- el3['user'] = comment.author.display_name.to_s if comment.author.data_public?
- el4 = XML::Node.new('text')
+ el3 = XML::Node.new("comment")
+ el3["date"] = comment.created_at.xmlschema
+ el3["uid"] = comment.author.id.to_s if comment.author.data_public?
+ el3["user"] = comment.author.display_name.to_s if comment.author.data_public?
+ el4 = XML::Node.new("text")
el4.content = comment.body.to_s
el3 << el4
el2 << el3
-require 'oauth'
+require "oauth"
class ClientApplication < ActiveRecord::Base
belongs_to :user
class DiaryEntry < ActiveRecord::Base
belongs_to :user, :counter_cache => true
- belongs_to :language, :foreign_key => 'language_code'
+ belongs_to :language, :foreign_key => "language_code"
has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment"
has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => %w(active confirmed) }).order(:id) }, :class_name => "DiaryComment"
class Language < ActiveRecord::Base
self.primary_key = "code"
- has_many :diary_entries, :foreign_key => 'language'
+ has_many :diary_entries, :foreign_key => "language"
def self.load(file)
Language.transaction do
-require 'validators'
+require "validators"
class Message < ActiveRecord::Base
belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
class Node < ActiveRecord::Base
- require 'xml/libxml'
+ require "xml/libxml"
include GeoRecord
include ConsistencyValidations
p = XML::Parser.string(xml)
doc = p.parse
- doc.find('//osm/node').each do |pt|
+ doc.find("//osm/node").each do |pt|
return Node.from_xml_node(pt, create)
end
fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
def self.from_xml_node(pt, create = false)
node = Node.new
- fail OSM::APIBadXMLError.new("node", pt, "lat missing") if pt['lat'].nil?
- fail OSM::APIBadXMLError.new("node", pt, "lon missing") if pt['lon'].nil?
- node.lat = OSM.parse_float(pt['lat'], OSM::APIBadXMLError, "node", pt, "lat not a number")
- node.lon = OSM.parse_float(pt['lon'], OSM::APIBadXMLError, "node", pt, "lon not a number")
- fail OSM::APIBadXMLError.new("node", pt, "Changeset id is missing") if pt['changeset'].nil?
- node.changeset_id = pt['changeset'].to_i
+ fail OSM::APIBadXMLError.new("node", pt, "lat missing") if pt["lat"].nil?
+ fail OSM::APIBadXMLError.new("node", pt, "lon missing") if pt["lon"].nil?
+ node.lat = OSM.parse_float(pt["lat"], OSM::APIBadXMLError, "node", pt, "lat not a number")
+ node.lon = OSM.parse_float(pt["lon"], OSM::APIBadXMLError, "node", pt, "lon not a number")
+ fail OSM::APIBadXMLError.new("node", pt, "Changeset id is missing") if pt["changeset"].nil?
+ node.changeset_id = pt["changeset"].to_i
fail OSM::APIBadUserInput.new("The node is outside this world") unless node.in_world?
# version must be present unless creating
- fail OSM::APIBadXMLError.new("node", pt, "Version is required when updating") unless create || !pt['version'].nil?
- node.version = create ? 0 : pt['version'].to_i
+ fail OSM::APIBadXMLError.new("node", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ node.version = create ? 0 : pt["version"].to_i
unless create
- fail OSM::APIBadXMLError.new("node", pt, "ID is required when updating.") if pt['id'].nil?
- node.id = pt['id'].to_i
+ fail OSM::APIBadXMLError.new("node", pt, "ID is required when updating.") if pt["id"].nil?
+ node.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
fail OSM::APIBadUserInput.new("ID of node cannot be zero when updating.") if node.id == 0
node.tags = {}
# Add in any tags from the XML
- pt.find('tag').each do |tag|
- fail OSM::APIBadXMLError.new("node", pt, "tag is missing key") if tag['k'].nil?
- fail OSM::APIBadXMLError.new("node", pt, "tag is missing value") if tag['v'].nil?
- node.add_tag_key_val(tag['k'], tag['v'])
+ pt.find("tag").each do |tag|
+ fail OSM::APIBadXMLError.new("node", pt, "tag is missing key") if tag["k"].nil?
+ fail OSM::APIBadXMLError.new("node", pt, "tag is missing value") if tag["v"].nil?
+ node.add_tag_key_val(tag["k"], tag["v"])
end
node
end
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
- el = XML::Node.new 'node'
- el['id'] = id.to_s
+ el = XML::Node.new "node"
+ el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
if self.visible?
- el['lat'] = lat.to_s
- el['lon'] = lon.to_s
+ el["lat"] = lat.to_s
+ el["lon"] = lon.to_s
end
add_tags_to_xml_node(el, node_tags)
:confirm_string => token.token)
mail :to => user.email,
- :subject => I18n.t('notifier.signup_confirm.subject')
+ :subject => I18n.t("notifier.signup_confirm.subject")
end
end
:confirm_string => token.token)
mail :to => user.new_email,
- :subject => I18n.t('notifier.email_confirm.subject')
+ :subject => I18n.t("notifier.email_confirm.subject")
end
end
:token => token.token)
mail :to => user.email,
- :subject => I18n.t('notifier.lost_password.subject')
+ :subject => I18n.t("notifier.lost_password.subject")
end
end
@possible_points = possible_points
mail :to => trace.user.email,
- :subject => I18n.t('notifier.gpx_notification.success.subject')
+ :subject => I18n.t("notifier.gpx_notification.success.subject")
end
end
@error = error
mail :to => trace.user.email,
- :subject => I18n.t('notifier.gpx_notification.failure.subject')
+ :subject => I18n.t("notifier.gpx_notification.failure.subject")
end
end
mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
:to => message.recipient.email,
- :subject => I18n.t('notifier.message_notification.subject_header', :subject => message.title)
+ :subject => I18n.t("notifier.message_notification.subject_header", :subject => message.title)
end
end
mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
:to => comment.diary_entry.user.email,
- :subject => I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name)
+ :subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
end
end
@friend = friend
mail :to => friend.befriendee.email,
- :subject => I18n.t('notifier.friend_notification.subject', :user => friend.befriender.display_name)
+ :subject => I18n.t("notifier.friend_notification.subject", :user => friend.befriender.display_name)
end
end
@comment = comment.body
@owner = recipient == comment.changeset.user
@commenter = comment.author.display_name
- @changeset_comment = comment.changeset.tags['comment'].presence
+ @changeset_comment = comment.changeset.tags["comment"].presence
@time = comment.created_at
@changeset_author = comment.changeset.user.display_name
attr_accessor :state
def as_json(_options = {})
- d = { :access_token => token, :token_type => 'bearer' }
+ d = { :access_token => token, :token_type => "bearer" }
d[:expires_in] = expires_in if expires_at
d
end
belongs_to :redaction
belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
- has_many :old_tags, :class_name => 'OldNodeTag', :foreign_key => [:node_id, :version]
+ has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version]
def validate_position
errors.add(:base, "Node is not in the world") unless in_world?
end
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
- el = XML::Node.new 'node'
- el['id'] = node_id.to_s
+ el = XML::Node.new "node"
+ el["id"] = node_id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
if self.visible?
- el['lat'] = lat.to_s
- el['lon'] = lon.to_s
+ el["lat"] = lat.to_s
+ el["lon"] = lon.to_s
end
add_tags_to_xml_node(el, old_tags)
belongs_to :redaction
belongs_to :current_relation, :class_name => "Relation", :foreign_key => "relation_id"
- has_many :old_members, -> { order(:sequence_id) }, :class_name => 'OldRelationMember', :foreign_key => [:relation_id, :version]
- has_many :old_tags, :class_name => 'OldRelationTag', :foreign_key => [:relation_id, :version]
+ has_many :old_members, -> { order(:sequence_id) }, :class_name => "OldRelationMember", :foreign_key => [:relation_id, :version]
+ has_many :old_tags, :class_name => "OldRelationTag", :foreign_key => [:relation_id, :version]
validates_associated :changeset
end
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
- el = XML::Node.new 'relation'
- el['id'] = relation_id.to_s
+ el = XML::Node.new "relation"
+ el["id"] = relation_id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
old_members.each do |member|
- member_el = XML::Node.new 'member'
- member_el['type'] = member.member_type.to_s.downcase
- member_el['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
- member_el['role'] = member.member_role.to_s
+ member_el = XML::Node.new "member"
+ member_el["type"] = member.member_type.to_s.downcase
+ member_el["ref"] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
+ member_el["role"] = member.member_role.to_s
el << member_el
end
belongs_to :redaction
belongs_to :current_way, :class_name => "Way", :foreign_key => "way_id"
- has_many :old_nodes, :class_name => 'OldWayNode', :foreign_key => [:way_id, :version]
- has_many :old_tags, :class_name => 'OldWayTag', :foreign_key => [:way_id, :version]
+ has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version]
+ has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version]
validates_associated :changeset
attr_writer :tags
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
- el = XML::Node.new 'way'
- el['id'] = way_id.to_s
+ el = XML::Node.new "way"
+ el["id"] = way_id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
old_nodes.each do |nd| # FIXME need to make sure they come back in the right order
- node_el = XML::Node.new 'nd'
- node_el['ref'] = nd.node_id.to_s
+ node_el = XML::Node.new "nd"
+ node_el["ref"] = nd.node_id.to_s
el << node_el
end
def get_nodes_revert(timestamp)
points = []
nds.each do |n|
- oldnode = OldNode.where('node_id = ? AND timestamp <= ?', n, timestamp).unredacted.order("timestamp DESC").first
+ oldnode = OldNode.where("node_id = ? AND timestamp <= ?", n, timestamp).unredacted.order("timestamp DESC").first
curnode = Node.find(n)
id = n
reuse = curnode.visible
class Relation < ActiveRecord::Base
- require 'xml/libxml'
+ require "xml/libxml"
include ConsistencyValidations
include NotRedactable
p = XML::Parser.string(xml)
doc = p.parse
- doc.find('//osm/relation').each do |pt|
+ doc.find("//osm/relation").each do |pt|
return Relation.from_xml_node(pt, create)
end
fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
def self.from_xml_node(pt, create = false)
relation = Relation.new
- fail OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt['version'].nil?
- relation.version = pt['version']
- fail OSM::APIBadXMLError.new("relation", pt, "Changeset id is missing") if pt['changeset'].nil?
- relation.changeset_id = pt['changeset']
+ fail OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ relation.version = pt["version"]
+ fail OSM::APIBadXMLError.new("relation", pt, "Changeset id is missing") if pt["changeset"].nil?
+ relation.changeset_id = pt["changeset"]
unless create
- fail OSM::APIBadXMLError.new("relation", pt, "ID is required when updating") if pt['id'].nil?
- relation.id = pt['id'].to_i
+ fail OSM::APIBadXMLError.new("relation", pt, "ID is required when updating") if pt["id"].nil?
+ relation.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
fail OSM::APIBadUserInput.new("ID of relation cannot be zero when updating.") if relation.id == 0
relation.tags = {}
# Add in any tags from the XML
- pt.find('tag').each do |tag|
- fail OSM::APIBadXMLError.new("relation", pt, "tag is missing key") if tag['k'].nil?
- fail OSM::APIBadXMLError.new("relation", pt, "tag is missing value") if tag['v'].nil?
- relation.add_tag_keyval(tag['k'], tag['v'])
+ pt.find("tag").each do |tag|
+ fail OSM::APIBadXMLError.new("relation", pt, "tag is missing key") if tag["k"].nil?
+ fail OSM::APIBadXMLError.new("relation", pt, "tag is missing value") if tag["v"].nil?
+ relation.add_tag_keyval(tag["k"], tag["v"])
end
# need to initialise the relation members array explicitly, as if this
# empty, as intended.
relation.members = []
- pt.find('member').each do |member|
+ pt.find("member").each do |member|
# member_type =
logger.debug "each member"
- fail OSM::APIBadXMLError.new("relation", pt, "The #{member['type']} is not allowed only, #{TYPES.inspect} allowed") unless TYPES.include? member['type']
+ fail OSM::APIBadXMLError.new("relation", pt, "The #{member['type']} is not allowed only, #{TYPES.inspect} allowed") unless TYPES.include? member["type"]
logger.debug "after raise"
# member_ref = member['ref']
# member_role
- member['role'] ||= "" # Allow the upload to not include this, in which case we default to an empty string.
- logger.debug member['role']
- relation.add_member(member['type'].classify, member['ref'], member['role'])
+ member["role"] ||= "" # Allow the upload to not include this, in which case we default to an empty string.
+ logger.debug member["role"]
+ relation.add_member(member["type"].classify, member["ref"], member["role"])
end
fail OSM::APIBadUserInput.new("Some bad xml in relation") if relation.nil?
end
def to_xml_node(visible_members = nil, changeset_cache = {}, user_display_name_cache = {})
- el = XML::Node.new 'relation'
- el['id'] = id.to_s
+ el = XML::Node.new "relation"
+ el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
next unless p
- member_el = XML::Node.new 'member'
- member_el['type'] = member.member_type.downcase
- member_el['ref'] = member.member_id.to_s
- member_el['role'] = member.member_role
+ member_el = XML::Node.new "member"
+ member_el["type"] = member.member_type.downcase
+ member_el["ref"] = member.member_id.to_s
+ member_el["role"] = member.member_role
el << member_el
end
end
def oob?
- callback_url.nil? || callback_url.downcase == 'oob'
+ callback_url.nil? || callback_url.downcase == "oob"
end
def oauth10?
self.table_name = "gpx_files"
belongs_to :user, :counter_cache => true
- has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :delete_all
- has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :delete_all
+ has_many :tags, :class_name => "Tracetag", :foreign_key => "gpx_id", :dependent => :delete_all
+ has_many :points, :class_name => "Tracepoint", :foreign_key => "gpx_id", :dependent => :delete_all
scope :visible, -> { where(:visible => true) }
scope :visible_to, ->(u) { visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
end
def tagstring=(s)
- if s.include? ','
+ if s.include? ","
self.tags = s.split(/\s*,\s*/).select { |tag| tag !~ /^\s*$/ }.collect {|tag|
tt = Tracetag.new
tt.tag = tag
end
def to_xml_node
- el1 = XML::Node.new 'gpx_file'
- el1['id'] = id.to_s
- el1['name'] = name.to_s
- el1['lat'] = latitude.to_s if inserted
- el1['lon'] = longitude.to_s if inserted
- el1['user'] = user.display_name
- el1['visibility'] = visibility
- el1['pending'] = (!inserted).to_s
- el1['timestamp'] = timestamp.xmlschema
-
- el2 = XML::Node.new 'description'
+ el1 = XML::Node.new "gpx_file"
+ el1["id"] = id.to_s
+ el1["name"] = name.to_s
+ el1["lat"] = latitude.to_s if inserted
+ el1["lon"] = longitude.to_s if inserted
+ el1["user"] = user.display_name
+ el1["visibility"] = visibility
+ el1["pending"] = (!inserted).to_s
+ el1["timestamp"] = timestamp.xmlschema
+
+ el2 = XML::Node.new "description"
el2 << description
el1 << el2
tags.each do |tag|
- el2 = XML::Node.new('tag')
+ el2 = XML::Node.new("tag")
el2 << tag.tag
el1 << el2
end
p = XML::Parser.string(xml)
doc = p.parse
- doc.find('//osm/gpx_file').each do |pt|
+ doc.find("//osm/gpx_file").each do |pt|
return Trace.from_xml_node(pt, create)
end
def self.from_xml_node(pt, create = false)
trace = Trace.new
- fail OSM::APIBadXMLError.new("trace", pt, "visibility missing") if pt['visibility'].nil?
- trace.visibility = pt['visibility']
+ fail OSM::APIBadXMLError.new("trace", pt, "visibility missing") if pt["visibility"].nil?
+ trace.visibility = pt["visibility"]
unless create
- fail OSM::APIBadXMLError.new("trace", pt, "ID is required when updating.") if pt['id'].nil?
- trace.id = pt['id'].to_i
+ fail OSM::APIBadXMLError.new("trace", pt, "ID is required when updating.") if pt["id"].nil?
+ trace.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
fail OSM::APIBadUserInput.new("ID of trace cannot be zero when updating.") if trace.id == 0
# and set manually before the actual delete
trace.visible = true
- description = pt.find('description').first
+ description = pt.find("description").first
fail OSM::APIBadXMLError.new("trace", pt, "description missing") if description.nil?
trace.description = description.content
- pt.find('tag').each do |tag|
+ pt.find("tag").each do |tag|
trace.tags.build(:tag => tag.content)
end
validates_associated :trace
validates_presence_of :timestamp
- belongs_to :trace, :foreign_key => 'gpx_id'
+ belongs_to :trace, :foreign_key => "gpx_id"
def to_xml_node(print_timestamp = false)
- el1 = XML::Node.new 'trkpt'
- el1['lat'] = lat.to_s
- el1['lon'] = lon.to_s
+ el1 = XML::Node.new "trkpt"
+ el1["lat"] = lat.to_s
+ el1["lon"] = lon.to_s
el1 << (XML::Node.new("time") << timestamp.xmlschema) if print_timestamp
el1
end
validates_format_of :tag, :with => /\A[^\/;.,?]*\z/
validates_length_of :tag, :within => 1..255
- belongs_to :trace, :foreign_key => 'gpx_id'
+ belongs_to :trace, :foreign_key => "gpx_id"
end
class User < ActiveRecord::Base
- require 'xml/libxml'
+ require "xml/libxml"
has_many :traces, -> { where(:visible => true) }
has_many :diary_entries, -> { order(:created_at => :desc) }
has_many :preferences, :class_name => "UserPreference"
has_many :changesets, -> { order(:created_at => :desc) }
has_many :changeset_comments, :foreign_key => :author_id
- has_and_belongs_to_many :changeset_subscriptions, :class_name => 'Changeset', :join_table => 'changesets_subscribers', :foreign_key => 'subscriber_id'
+ has_and_belongs_to_many :changeset_subscriptions, :class_name => "Changeset", :join_table => "changesets_subscribers", :foreign_key => "subscriber_id"
has_many :note_comments, :foreign_key => :author_id
has_many :notes, :through => :note_comments
end
def to_xml_node
- el1 = XML::Node.new 'user'
- el1['display_name'] = display_name.to_s
- el1['account_created'] = creation_time.xmlschema
+ el1 = XML::Node.new "user"
+ el1["display_name"] = display_name.to_s
+ el1["account_created"] = creation_time.xmlschema
if home_lat && home_lon
- home = XML::Node.new 'home'
- home['lat'] = home_lat.to_s
- home['lon'] = home_lon.to_s
- home['zoom'] = home_zoom.to_s
+ home = XML::Node.new "home"
+ home["lat"] = home_lat.to_s
+ home["lon"] = home_lon.to_s
+ home["zoom"] = home_zoom.to_s
el1 << home
end
el1
##
# returns true if the user has the moderator role, false otherwise
def moderator?
- has_role? 'moderator'
+ has_role? "moderator"
end
##
# returns true if the user has the administrator role, false otherwise
def administrator?
- has_role? 'administrator'
+ has_role? "administrator"
end
##
# block. this should be caught and dealt with in the controller,
# but i've also included it here just in case.
def moderator_permissions
- errors.add(:base, I18n.t('user_block.model.non_moderator_update')) if creator_id_changed? && !creator.moderator?
- errors.add(:base, I18n.t('user_block.model.non_moderator_revoke')) unless revoker_id.nil? || revoker.moderator?
+ errors.add(:base, I18n.t("user_block.model.non_moderator_update")) if creator_id_changed? && !creator.moderator?
+ errors.add(:base, I18n.t("user_block.model.non_moderator_revoke")) unless revoker_id.nil? || revoker.moderator?
end
end
# Turn this Node in to an XML Node without the <osm> wrapper.
def to_xml_node
- el1 = XML::Node.new 'preference'
- el1['k'] = k
- el1['v'] = v
+ el1 = XML::Node.new "preference"
+ el1["k"] = k
+ el1["v"] = v
el1
end
class Way < ActiveRecord::Base
- require 'xml/libxml'
+ require "xml/libxml"
include ConsistencyValidations
include NotRedactable
p = XML::Parser.string(xml)
doc = p.parse
- doc.find('//osm/way').each do |pt|
+ doc.find("//osm/way").each do |pt|
return Way.from_xml_node(pt, create)
end
fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
def self.from_xml_node(pt, create = false)
way = Way.new
- fail OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt['version'].nil?
- way.version = pt['version']
- fail OSM::APIBadXMLError.new("way", pt, "Changeset id is missing") if pt['changeset'].nil?
- way.changeset_id = pt['changeset']
+ fail OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ way.version = pt["version"]
+ fail OSM::APIBadXMLError.new("way", pt, "Changeset id is missing") if pt["changeset"].nil?
+ way.changeset_id = pt["changeset"]
unless create
- fail OSM::APIBadXMLError.new("way", pt, "ID is required when updating") if pt['id'].nil?
- way.id = pt['id'].to_i
+ fail OSM::APIBadXMLError.new("way", pt, "ID is required when updating") if pt["id"].nil?
+ way.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
fail OSM::APIBadUserInput.new("ID of way cannot be zero when updating.") if way.id == 0
way.tags = {}
# Add in any tags from the XML
- pt.find('tag').each do |tag|
- fail OSM::APIBadXMLError.new("way", pt, "tag is missing key") if tag['k'].nil?
- fail OSM::APIBadXMLError.new("way", pt, "tag is missing value") if tag['v'].nil?
- way.add_tag_keyval(tag['k'], tag['v'])
+ pt.find("tag").each do |tag|
+ fail OSM::APIBadXMLError.new("way", pt, "tag is missing key") if tag["k"].nil?
+ fail OSM::APIBadXMLError.new("way", pt, "tag is missing value") if tag["v"].nil?
+ way.add_tag_keyval(tag["k"], tag["v"])
end
- pt.find('nd').each do |nd|
- way.add_nd_num(nd['ref'])
+ pt.find("nd").each do |nd|
+ way.add_nd_num(nd["ref"])
end
way
end
def to_xml_node(visible_nodes = nil, changeset_cache = {}, user_display_name_cache = {})
- el = XML::Node.new 'way'
- el['id'] = id.to_s
+ el = XML::Node.new "way"
+ el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
end
ordered_nodes.each do |nd_id|
- next unless nd_id && nd_id != '0'
+ next unless nd_id && nd_id != "0"
- node_el = XML::Node.new 'nd'
- node_el['ref'] = nd_id
+ node_el = XML::Node.new "nd"
+ node_el["ref"] = nd_id
el << node_el
end
-require File.expand_path('../boot', __FILE__)
+require File.expand_path("../boot", __FILE__)
-require File.expand_path('../preinitializer', __FILE__)
+require File.expand_path("../preinitializer", __FILE__)
if STATUS == :database_offline
require "action_controller/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
else
- require 'rails/all'
+ require "rails/all"
end
# Require the gems listed in Gemfile, including any gems
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
-require 'bundler/setup' # Set up gems listed in the Gemfile.
+require "bundler/setup" # Set up gems listed in the Gemfile.
# Load the Rails application.
-require File.expand_path('../application', __FILE__)
+require File.expand_path("../application", __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
- config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
+ config.serve_static_files = ENV["RAILS_SERVE_STATIC_FILES"].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# Configure static file server for tests with Cache-Control for performance.
config.serve_static_files = true
- config.static_cache_control = 'public, max-age=3600'
+ config.static_cache_control = "public, max-age=3600"
# Show full error reports and disable caching.
config.consider_all_requests_local = true
# Configure ActionMailer SMTP settings
ActionMailer::Base.smtp_settings = {
- :address => 'localhost',
+ :address => "localhost",
:port => 25,
- :domain => 'localhost',
+ :domain => "localhost",
:enable_starttls_auto => false
}
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
-Rails.application.config.assets.version = '1.0'
+Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-require 'classic_pagination/pagination'
-require 'classic_pagination/pagination_helper'
+require "classic_pagination/pagination"
+require "classic_pagination/pagination_helper"
ActionController::Base.class_eval do
include ActionController::Pagination
class Cors < Rack::Cors
def call(env)
status, headers, body = super env
- if headers['Access-Control-Allow-Origin']
- headers['Cache-Control'] = 'no-cache'
+ if headers["Access-Control-Allow-Origin"]
+ headers["Cache-Control"] = "no-cache"
end
[status, headers, body]
end
class_attr_index = html_tag.index 'class="'
if class_attr_index
- html_tag.insert class_attr_index + 7, 'field_with_errors '
+ html_tag.insert class_attr_index + 7, "field_with_errors "
else
html_tag.insert html_tag.index(/\/?>/), ' class="field_with_errors"'
end
Konacha.configure do |config|
- require 'capybara/poltergeist'
+ require "capybara/poltergeist"
config.spec_dir = "test/javascripts"
config.driver = :poltergeist
end if defined?(Konacha)
-require 'oauth/rack/oauth_filter'
+require "oauth/rack/oauth_filter"
Rails.configuration.middleware.use OAuth::Rack::OAuthFilter
-require 'output_compression/output_compression'
+require "output_compression/output_compression"
class R2Template < Tilt::Template
- self.default_mime_type = 'text/css'
+ self.default_mime_type = "text/css"
def self.engine_initialized?
defined? ::R2
Sanitize::Config::OSM = Sanitize::Config::RELAXED.dup
Sanitize::Config::OSM[:elements] -= %w(div style)
-Sanitize::Config::OSM[:add_attributes] = { 'a' => { 'rel' => 'nofollow' } }
+Sanitize::Config::OSM[:add_attributes] = { "a" => { "rel" => "nofollow" } }
Sanitize::Config::OSM[:remove_contents] = %w(script style)
if defined?(MEMCACHE_SERVERS)
Rails.application.config.session_store :mem_cache_store, :memcache_server => MEMCACHE_SERVERS, :namespace => "rails:session", :key => "_osm_session"
else
- Rails.application.config.session_store :cache_store, :key => '_osm_session'
+ Rails.application.config.session_store :cache_store, :key => "_osm_session"
end
-require 'yaml'
+require "yaml"
if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any?
env = "test"
else
- env = ENV['RAILS_ENV'] || 'development'
+ env = ENV["RAILS_ENV"] || "development"
end
config = YAML.load_file(File.expand_path(env == "test" ? "../example.application.yml" : "../application.yml", __FILE__))
OpenStreetMap::Application.routes.draw do
# API
- match 'api/capabilities' => 'api#capabilities', :via => :get
- match 'api/0.6/capabilities' => 'api#capabilities', :via => :get
- match 'api/0.6/permissions' => 'api#permissions', :via => :get
-
- match 'api/0.6/changeset/create' => 'changeset#create', :via => :put
- match 'api/0.6/changeset/:id/upload' => 'changeset#upload', :via => :post, :id => /\d+/
- match 'api/0.6/changeset/:id/download' => 'changeset#download', :via => :get, :as => :changeset_download, :id => /\d+/
- match 'api/0.6/changeset/:id/expand_bbox' => 'changeset#expand_bbox', :via => :post, :id => /\d+/
- match 'api/0.6/changeset/:id' => 'changeset#read', :via => :get, :as => :changeset_read, :id => /\d+/
- match 'api/0.6/changeset/:id/subscribe' => 'changeset#subscribe', :via => :post, :as => :changeset_subscribe, :id => /\d+/
- match 'api/0.6/changeset/:id/unsubscribe' => 'changeset#unsubscribe', :via => :post, :as => :changeset_unsubscribe, :id => /\d+/
- match 'api/0.6/changeset/:id' => 'changeset#update', :via => :put, :id => /\d+/
- match 'api/0.6/changeset/:id/close' => 'changeset#close', :via => :put, :id => /\d+/
- match 'api/0.6/changesets' => 'changeset#query', :via => :get
- post 'api/0.6/changeset/:id/comment' => 'changeset#comment', :as => :changeset_comment, :id => /\d+/
- post 'api/0.6/changeset/comment/:id/hide' => 'changeset#hide_comment', :as => :changeset_comment_hide, :id => /\d+/
- post 'api/0.6/changeset/comment/:id/unhide' => 'changeset#unhide_comment', :as => :changeset_comment_unhide, :id => /\d+/
-
- match 'api/0.6/node/create' => 'node#create', :via => :put
- match 'api/0.6/node/:id/ways' => 'way#ways_for_node', :via => :get, :id => /\d+/
- match 'api/0.6/node/:id/relations' => 'relation#relations_for_node', :via => :get, :id => /\d+/
- match 'api/0.6/node/:id/history' => 'old_node#history', :via => :get, :id => /\d+/
- match 'api/0.6/node/:id/:version/redact' => 'old_node#redact', :via => :post, :version => /\d+/, :id => /\d+/
- match 'api/0.6/node/:id/:version' => 'old_node#version', :via => :get, :id => /\d+/, :version => /\d+/
- match 'api/0.6/node/:id' => 'node#read', :via => :get, :id => /\d+/
- match 'api/0.6/node/:id' => 'node#update', :via => :put, :id => /\d+/
- match 'api/0.6/node/:id' => 'node#delete', :via => :delete, :id => /\d+/
- match 'api/0.6/nodes' => 'node#nodes', :via => :get
-
- match 'api/0.6/way/create' => 'way#create', :via => :put
- match 'api/0.6/way/:id/history' => 'old_way#history', :via => :get, :id => /\d+/
- match 'api/0.6/way/:id/full' => 'way#full', :via => :get, :id => /\d+/
- match 'api/0.6/way/:id/relations' => 'relation#relations_for_way', :via => :get, :id => /\d+/
- match 'api/0.6/way/:id/:version/redact' => 'old_way#redact', :via => :post, :version => /\d+/, :id => /\d+/
- match 'api/0.6/way/:id/:version' => 'old_way#version', :via => :get, :id => /\d+/, :version => /\d+/
- match 'api/0.6/way/:id' => 'way#read', :via => :get, :id => /\d+/
- match 'api/0.6/way/:id' => 'way#update', :via => :put, :id => /\d+/
- match 'api/0.6/way/:id' => 'way#delete', :via => :delete, :id => /\d+/
- match 'api/0.6/ways' => 'way#ways', :via => :get
-
- match 'api/0.6/relation/create' => 'relation#create', :via => :put
- match 'api/0.6/relation/:id/relations' => 'relation#relations_for_relation', :via => :get, :id => /\d+/
- match 'api/0.6/relation/:id/history' => 'old_relation#history', :via => :get, :id => /\d+/
- match 'api/0.6/relation/:id/full' => 'relation#full', :via => :get, :id => /\d+/
- match 'api/0.6/relation/:id/:version/redact' => 'old_relation#redact', :via => :post, :version => /\d+/, :id => /\d+/
- match 'api/0.6/relation/:id/:version' => 'old_relation#version', :via => :get, :id => /\d+/, :version => /\d+/
- match 'api/0.6/relation/:id' => 'relation#read', :via => :get, :id => /\d+/
- match 'api/0.6/relation/:id' => 'relation#update', :via => :put, :id => /\d+/
- match 'api/0.6/relation/:id' => 'relation#delete', :via => :delete, :id => /\d+/
- match 'api/0.6/relations' => 'relation#relations', :via => :get
-
- match 'api/0.6/map' => 'api#map', :via => :get
-
- match 'api/0.6/trackpoints' => 'api#trackpoints', :via => :get
-
- match 'api/0.6/changes' => 'api#changes', :via => :get
-
- match 'api/0.6/search' => 'search#search_all', :via => :get
- match 'api/0.6/ways/search' => 'search#search_ways', :via => :get
- match 'api/0.6/relations/search' => 'search#search_relations', :via => :get
- match 'api/0.6/nodes/search' => 'search#search_nodes', :via => :get
-
- match 'api/0.6/user/:id' => 'user#api_read', :via => :get, :id => /\d+/
- match 'api/0.6/user/details' => 'user#api_details', :via => :get
- match 'api/0.6/user/gpx_files' => 'user#api_gpx_files', :via => :get
-
- match 'api/0.6/user/preferences' => 'user_preference#read', :via => :get
- match 'api/0.6/user/preferences/:preference_key' => 'user_preference#read_one', :via => :get
- match 'api/0.6/user/preferences' => 'user_preference#update', :via => :put
- match 'api/0.6/user/preferences/:preference_key' => 'user_preference#update_one', :via => :put
- match 'api/0.6/user/preferences/:preference_key' => 'user_preference#delete_one', :via => :delete
-
- match 'api/0.6/gpx/create' => 'trace#api_create', :via => :post
- match 'api/0.6/gpx/:id' => 'trace#api_read', :via => :get, :id => /\d+/
- match 'api/0.6/gpx/:id' => 'trace#api_update', :via => :put, :id => /\d+/
- match 'api/0.6/gpx/:id' => 'trace#api_delete', :via => :delete, :id => /\d+/
- match 'api/0.6/gpx/:id/details' => 'trace#api_read', :via => :get, :id => /\d+/
- match 'api/0.6/gpx/:id/data' => 'trace#api_data', :via => :get
+ match "api/capabilities" => "api#capabilities", :via => :get
+ match "api/0.6/capabilities" => "api#capabilities", :via => :get
+ match "api/0.6/permissions" => "api#permissions", :via => :get
+
+ match "api/0.6/changeset/create" => "changeset#create", :via => :put
+ match "api/0.6/changeset/:id/upload" => "changeset#upload", :via => :post, :id => /\d+/
+ match "api/0.6/changeset/:id/download" => "changeset#download", :via => :get, :as => :changeset_download, :id => /\d+/
+ match "api/0.6/changeset/:id/expand_bbox" => "changeset#expand_bbox", :via => :post, :id => /\d+/
+ match "api/0.6/changeset/:id" => "changeset#read", :via => :get, :as => :changeset_read, :id => /\d+/
+ match "api/0.6/changeset/:id/subscribe" => "changeset#subscribe", :via => :post, :as => :changeset_subscribe, :id => /\d+/
+ match "api/0.6/changeset/:id/unsubscribe" => "changeset#unsubscribe", :via => :post, :as => :changeset_unsubscribe, :id => /\d+/
+ match "api/0.6/changeset/:id" => "changeset#update", :via => :put, :id => /\d+/
+ match "api/0.6/changeset/:id/close" => "changeset#close", :via => :put, :id => /\d+/
+ match "api/0.6/changesets" => "changeset#query", :via => :get
+ post "api/0.6/changeset/:id/comment" => "changeset#comment", :as => :changeset_comment, :id => /\d+/
+ post "api/0.6/changeset/comment/:id/hide" => "changeset#hide_comment", :as => :changeset_comment_hide, :id => /\d+/
+ post "api/0.6/changeset/comment/:id/unhide" => "changeset#unhide_comment", :as => :changeset_comment_unhide, :id => /\d+/
+
+ match "api/0.6/node/create" => "node#create", :via => :put
+ match "api/0.6/node/:id/ways" => "way#ways_for_node", :via => :get, :id => /\d+/
+ match "api/0.6/node/:id/relations" => "relation#relations_for_node", :via => :get, :id => /\d+/
+ match "api/0.6/node/:id/history" => "old_node#history", :via => :get, :id => /\d+/
+ match "api/0.6/node/:id/:version/redact" => "old_node#redact", :via => :post, :version => /\d+/, :id => /\d+/
+ match "api/0.6/node/:id/:version" => "old_node#version", :via => :get, :id => /\d+/, :version => /\d+/
+ match "api/0.6/node/:id" => "node#read", :via => :get, :id => /\d+/
+ match "api/0.6/node/:id" => "node#update", :via => :put, :id => /\d+/
+ match "api/0.6/node/:id" => "node#delete", :via => :delete, :id => /\d+/
+ match "api/0.6/nodes" => "node#nodes", :via => :get
+
+ match "api/0.6/way/create" => "way#create", :via => :put
+ match "api/0.6/way/:id/history" => "old_way#history", :via => :get, :id => /\d+/
+ match "api/0.6/way/:id/full" => "way#full", :via => :get, :id => /\d+/
+ match "api/0.6/way/:id/relations" => "relation#relations_for_way", :via => :get, :id => /\d+/
+ match "api/0.6/way/:id/:version/redact" => "old_way#redact", :via => :post, :version => /\d+/, :id => /\d+/
+ match "api/0.6/way/:id/:version" => "old_way#version", :via => :get, :id => /\d+/, :version => /\d+/
+ match "api/0.6/way/:id" => "way#read", :via => :get, :id => /\d+/
+ match "api/0.6/way/:id" => "way#update", :via => :put, :id => /\d+/
+ match "api/0.6/way/:id" => "way#delete", :via => :delete, :id => /\d+/
+ match "api/0.6/ways" => "way#ways", :via => :get
+
+ match "api/0.6/relation/create" => "relation#create", :via => :put
+ match "api/0.6/relation/:id/relations" => "relation#relations_for_relation", :via => :get, :id => /\d+/
+ match "api/0.6/relation/:id/history" => "old_relation#history", :via => :get, :id => /\d+/
+ match "api/0.6/relation/:id/full" => "relation#full", :via => :get, :id => /\d+/
+ match "api/0.6/relation/:id/:version/redact" => "old_relation#redact", :via => :post, :version => /\d+/, :id => /\d+/
+ match "api/0.6/relation/:id/:version" => "old_relation#version", :via => :get, :id => /\d+/, :version => /\d+/
+ match "api/0.6/relation/:id" => "relation#read", :via => :get, :id => /\d+/
+ match "api/0.6/relation/:id" => "relation#update", :via => :put, :id => /\d+/
+ match "api/0.6/relation/:id" => "relation#delete", :via => :delete, :id => /\d+/
+ match "api/0.6/relations" => "relation#relations", :via => :get
+
+ match "api/0.6/map" => "api#map", :via => :get
+
+ match "api/0.6/trackpoints" => "api#trackpoints", :via => :get
+
+ match "api/0.6/changes" => "api#changes", :via => :get
+
+ match "api/0.6/search" => "search#search_all", :via => :get
+ match "api/0.6/ways/search" => "search#search_ways", :via => :get
+ match "api/0.6/relations/search" => "search#search_relations", :via => :get
+ match "api/0.6/nodes/search" => "search#search_nodes", :via => :get
+
+ match "api/0.6/user/:id" => "user#api_read", :via => :get, :id => /\d+/
+ match "api/0.6/user/details" => "user#api_details", :via => :get
+ match "api/0.6/user/gpx_files" => "user#api_gpx_files", :via => :get
+
+ match "api/0.6/user/preferences" => "user_preference#read", :via => :get
+ match "api/0.6/user/preferences/:preference_key" => "user_preference#read_one", :via => :get
+ match "api/0.6/user/preferences" => "user_preference#update", :via => :put
+ match "api/0.6/user/preferences/:preference_key" => "user_preference#update_one", :via => :put
+ match "api/0.6/user/preferences/:preference_key" => "user_preference#delete_one", :via => :delete
+
+ match "api/0.6/gpx/create" => "trace#api_create", :via => :post
+ match "api/0.6/gpx/:id" => "trace#api_read", :via => :get, :id => /\d+/
+ match "api/0.6/gpx/:id" => "trace#api_update", :via => :put, :id => /\d+/
+ match "api/0.6/gpx/:id" => "trace#api_delete", :via => :delete, :id => /\d+/
+ match "api/0.6/gpx/:id/details" => "trace#api_read", :via => :get, :id => /\d+/
+ match "api/0.6/gpx/:id/data" => "trace#api_data", :via => :get
# AMF (ActionScript) API
- match 'api/0.6/amf/read' => 'amf#amf_read', :via => :post
- match 'api/0.6/amf/write' => 'amf#amf_write', :via => :post
- match 'api/0.6/swf/trackpoints' => 'swf#trackpoints', :via => :get
+ match "api/0.6/amf/read" => "amf#amf_read", :via => :post
+ match "api/0.6/amf/write" => "amf#amf_write", :via => :post
+ match "api/0.6/swf/trackpoints" => "swf#trackpoints", :via => :get
# Map notes API
scope "api/0.6" do
resources :notes, :except => [:new, :edit, :update], :constraints => { :id => /\d+/ }, :defaults => { :format => "xml" } do
collection do
- get 'search'
- get 'feed', :defaults => { :format => "rss" }
+ get "search"
+ get "feed", :defaults => { :format => "rss" }
end
member do
- post 'comment'
- post 'close'
- post 'reopen'
+ post "comment"
+ post "close"
+ post "reopen"
end
end
- match 'notes/addPOIexec' => 'notes#create', :via => :post
- match 'notes/closePOIexec' => 'notes#close', :via => :post
- match 'notes/editPOIexec' => 'notes#comment', :via => :post
- match 'notes/getGPX' => 'notes#index', :via => :get, :format => "gpx"
- match 'notes/getRSSfeed' => 'notes#feed', :via => :get, :format => "rss"
+ match "notes/addPOIexec" => "notes#create", :via => :post
+ match "notes/closePOIexec" => "notes#close", :via => :post
+ match "notes/editPOIexec" => "notes#comment", :via => :post
+ match "notes/getGPX" => "notes#index", :via => :get, :format => "gpx"
+ match "notes/getRSSfeed" => "notes#feed", :via => :get, :format => "rss"
end
# Data browsing
- match '/way/:id' => 'browse#way', :via => :get, :id => /\d+/, :as => :way
- match '/way/:id/history' => 'browse#way_history', :via => :get, :id => /\d+/
- match '/node/:id' => 'browse#node', :via => :get, :id => /\d+/, :as => :node
- match '/node/:id/history' => 'browse#node_history', :via => :get, :id => /\d+/
- match '/relation/:id' => 'browse#relation', :via => :get, :id => /\d+/, :as => :relation
- match '/relation/:id/history' => 'browse#relation_history', :via => :get, :id => /\d+/
- match '/changeset/:id' => 'browse#changeset', :via => :get, :as => :changeset, :id => /\d+/
- match '/changeset/:id/comments/feed' => 'changeset#comments_feed', :via => :get, :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => 'rss' }
- match '/note/:id' => 'browse#note', :via => :get, :id => /\d+/, :as => "browse_note"
- match '/note/new' => 'browse#new_note', :via => :get
- match '/user/:display_name/history' => 'changeset#list', :via => :get
- match '/user/:display_name/history/feed' => 'changeset#feed', :via => :get, :defaults => { :format => :atom }
- match '/user/:display_name/notes' => 'notes#mine', :via => :get
- match '/history/friends' => 'changeset#list', :via => :get, :friends => true, :as => "friend_changesets"
- match '/history/nearby' => 'changeset#list', :via => :get, :nearby => true, :as => "nearby_changesets"
-
- get '/browse/way/:id', :to => redirect(:path => '/way/%{id}')
- get '/browse/way/:id/history', :to => redirect(:path => '/way/%{id}/history')
- get '/browse/node/:id', :to => redirect(:path => '/node/%{id}')
- get '/browse/node/:id/history', :to => redirect(:path => '/node/%{id}/history')
- get '/browse/relation/:id', :to => redirect(:path => '/relation/%{id}')
- get '/browse/relation/:id/history', :to => redirect(:path => '/relation/%{id}/history')
- get '/browse/changeset/:id', :to => redirect(:path => '/changeset/%{id}')
- get '/browse/note/:id', :to => redirect(:path => '/note/%{id}')
- get '/user/:display_name/edits', :to => redirect(:path => '/user/%{display_name}/history')
- get '/user/:display_name/edits/feed', :to => redirect(:path => '/user/%{display_name}/history/feed')
- get '/browse/friends', :to => redirect(:path => '/history/friends')
- get '/browse/nearby', :to => redirect(:path => '/history/nearby')
- get '/browse/changesets/feed', :to => redirect(:path => '/history/feed')
- get '/browse/changesets', :to => redirect(:path => '/history')
- get '/browse', :to => redirect(:path => '/history')
+ match "/way/:id" => "browse#way", :via => :get, :id => /\d+/, :as => :way
+ match "/way/:id/history" => "browse#way_history", :via => :get, :id => /\d+/
+ match "/node/:id" => "browse#node", :via => :get, :id => /\d+/, :as => :node
+ match "/node/:id/history" => "browse#node_history", :via => :get, :id => /\d+/
+ match "/relation/:id" => "browse#relation", :via => :get, :id => /\d+/, :as => :relation
+ match "/relation/:id/history" => "browse#relation_history", :via => :get, :id => /\d+/
+ match "/changeset/:id" => "browse#changeset", :via => :get, :as => :changeset, :id => /\d+/
+ match "/changeset/:id/comments/feed" => "changeset#comments_feed", :via => :get, :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" }
+ match "/note/:id" => "browse#note", :via => :get, :id => /\d+/, :as => "browse_note"
+ match "/note/new" => "browse#new_note", :via => :get
+ match "/user/:display_name/history" => "changeset#list", :via => :get
+ match "/user/:display_name/history/feed" => "changeset#feed", :via => :get, :defaults => { :format => :atom }
+ match "/user/:display_name/notes" => "notes#mine", :via => :get
+ match "/history/friends" => "changeset#list", :via => :get, :friends => true, :as => "friend_changesets"
+ match "/history/nearby" => "changeset#list", :via => :get, :nearby => true, :as => "nearby_changesets"
+
+ get "/browse/way/:id", :to => redirect(:path => "/way/%{id}")
+ get "/browse/way/:id/history", :to => redirect(:path => "/way/%{id}/history")
+ get "/browse/node/:id", :to => redirect(:path => "/node/%{id}")
+ get "/browse/node/:id/history", :to => redirect(:path => "/node/%{id}/history")
+ get "/browse/relation/:id", :to => redirect(:path => "/relation/%{id}")
+ get "/browse/relation/:id/history", :to => redirect(:path => "/relation/%{id}/history")
+ get "/browse/changeset/:id", :to => redirect(:path => "/changeset/%{id}")
+ get "/browse/note/:id", :to => redirect(:path => "/note/%{id}")
+ get "/user/:display_name/edits", :to => redirect(:path => "/user/%{display_name}/history")
+ get "/user/:display_name/edits/feed", :to => redirect(:path => "/user/%{display_name}/history/feed")
+ get "/browse/friends", :to => redirect(:path => "/history/friends")
+ get "/browse/nearby", :to => redirect(:path => "/history/nearby")
+ get "/browse/changesets/feed", :to => redirect(:path => "/history/feed")
+ get "/browse/changesets", :to => redirect(:path => "/history")
+ get "/browse", :to => redirect(:path => "/history")
# web site
- root :to => 'site#index', :via => [:get, :post]
- match '/edit' => 'site#edit', :via => :get, :as => :edit
- match '/copyright/:copyright_locale' => 'site#copyright', :via => :get
- match '/copyright' => 'site#copyright', :via => :get
- match '/welcome' => 'site#welcome', :via => :get, :as => :welcome
- match '/fixthemap' => 'site#fixthemap', :via => :get, :as => :fixthemap
- match '/help' => 'site#help', :via => :get, :as => :help
- match '/about' => 'site#about', :via => :get, :as => :about
- match '/history' => 'changeset#list', :via => :get
- match '/history/feed' => 'changeset#feed', :via => :get, :defaults => { :format => :atom }
- match '/history/comments/feed' => 'changeset#comments_feed', :via => :get, :as => :changesets_comments_feed, :defaults => { :format => 'rss' }
- match '/export' => 'site#export', :via => :get
- match '/login' => 'user#login', :via => [:get, :post]
- match '/logout' => 'user#logout', :via => [:get, :post]
- match '/offline' => 'site#offline', :via => :get
- match '/key' => 'site#key', :via => :get
- match '/id' => 'site#id', :via => :get
- match '/query' => 'browse#query', :via => :get
- match '/user/new' => 'user#new', :via => :get
- match '/user/new' => 'user#create', :via => :post
- match '/user/terms' => 'user#terms', :via => :get
- match '/user/save' => 'user#save', :via => :post
- match '/user/:display_name/confirm/resend' => 'user#confirm_resend', :via => :get
- match '/user/:display_name/confirm' => 'user#confirm', :via => [:get, :post]
- match '/user/confirm' => 'user#confirm', :via => [:get, :post]
- match '/user/confirm-email' => 'user#confirm_email', :via => [:get, :post]
- match '/user/go_public' => 'user#go_public', :via => :post
- match '/user/reset-password' => 'user#reset_password', :via => [:get, :post]
- match '/user/forgot-password' => 'user#lost_password', :via => [:get, :post]
- match '/user/suspended' => 'user#suspended', :via => :get
-
- get '/index.html', :to => redirect(:path => "/")
- get '/create-account.html', :to => redirect(:path => "/user/new")
- get '/forgot-password.html', :to => redirect(:path => "/user/forgot-password")
+ root :to => "site#index", :via => [:get, :post]
+ match "/edit" => "site#edit", :via => :get, :as => :edit
+ match "/copyright/:copyright_locale" => "site#copyright", :via => :get
+ match "/copyright" => "site#copyright", :via => :get
+ match "/welcome" => "site#welcome", :via => :get, :as => :welcome
+ match "/fixthemap" => "site#fixthemap", :via => :get, :as => :fixthemap
+ match "/help" => "site#help", :via => :get, :as => :help
+ match "/about" => "site#about", :via => :get, :as => :about
+ match "/history" => "changeset#list", :via => :get
+ match "/history/feed" => "changeset#feed", :via => :get, :defaults => { :format => :atom }
+ match "/history/comments/feed" => "changeset#comments_feed", :via => :get, :as => :changesets_comments_feed, :defaults => { :format => "rss" }
+ match "/export" => "site#export", :via => :get
+ match "/login" => "user#login", :via => [:get, :post]
+ match "/logout" => "user#logout", :via => [:get, :post]
+ match "/offline" => "site#offline", :via => :get
+ match "/key" => "site#key", :via => :get
+ match "/id" => "site#id", :via => :get
+ match "/query" => "browse#query", :via => :get
+ match "/user/new" => "user#new", :via => :get
+ match "/user/new" => "user#create", :via => :post
+ match "/user/terms" => "user#terms", :via => :get
+ match "/user/save" => "user#save", :via => :post
+ match "/user/:display_name/confirm/resend" => "user#confirm_resend", :via => :get
+ match "/user/:display_name/confirm" => "user#confirm", :via => [:get, :post]
+ match "/user/confirm" => "user#confirm", :via => [:get, :post]
+ match "/user/confirm-email" => "user#confirm_email", :via => [:get, :post]
+ match "/user/go_public" => "user#go_public", :via => :post
+ match "/user/reset-password" => "user#reset_password", :via => [:get, :post]
+ match "/user/forgot-password" => "user#lost_password", :via => [:get, :post]
+ match "/user/suspended" => "user#suspended", :via => :get
+
+ get "/index.html", :to => redirect(:path => "/")
+ get "/create-account.html", :to => redirect(:path => "/user/new")
+ get "/forgot-password.html", :to => redirect(:path => "/user/forgot-password")
# permalink
- match '/go/:code' => 'site#permalink', :via => :get, :code => /[a-zA-Z0-9_@~]+[=-]*/
+ match "/go/:code" => "site#permalink", :via => :get, :code => /[a-zA-Z0-9_@~]+[=-]*/
# rich text preview
- match '/preview/:format' => 'site#preview', :via => :post, :as => :preview
+ match "/preview/:format" => "site#preview", :via => :post, :as => :preview
# traces
- match '/user/:display_name/traces/tag/:tag/page/:page' => 'trace#list', :via => :get
- match '/user/:display_name/traces/tag/:tag' => 'trace#list', :via => :get
- match '/user/:display_name/traces/page/:page' => 'trace#list', :via => :get
- match '/user/:display_name/traces' => 'trace#list', :via => :get
- match '/user/:display_name/traces/tag/:tag/rss' => 'trace#georss', :via => :get, :defaults => { :format => :rss }
- match '/user/:display_name/traces/rss' => 'trace#georss', :via => :get, :defaults => { :format => :rss }
- match '/user/:display_name/traces/:id' => 'trace#view', :via => :get
- match '/user/:display_name/traces/:id/picture' => 'trace#picture', :via => :get
- match '/user/:display_name/traces/:id/icon' => 'trace#icon', :via => :get
- match '/traces/tag/:tag/page/:page' => 'trace#list', :via => :get
- match '/traces/tag/:tag' => 'trace#list', :via => :get
- match '/traces/page/:page' => 'trace#list', :via => :get
- match '/traces' => 'trace#list', :via => :get
- match '/traces/tag/:tag/rss' => 'trace#georss', :via => :get, :defaults => { :format => :rss }
- match '/traces/rss' => 'trace#georss', :via => :get, :defaults => { :format => :rss }
- match '/traces/mine/tag/:tag/page/:page' => 'trace#mine', :via => :get
- match '/traces/mine/tag/:tag' => 'trace#mine', :via => :get
- match '/traces/mine/page/:page' => 'trace#mine', :via => :get
- match '/traces/mine' => 'trace#mine', :via => :get
- match '/trace/create' => 'trace#create', :via => [:get, :post]
- match '/trace/:id/data' => 'trace#data', :via => :get, :id => /\d+/, :as => "trace_data"
- match '/trace/:id/edit' => 'trace#edit', :via => [:get, :post, :patch], :id => /\d+/, :as => "trace_edit"
- match '/trace/:id/delete' => 'trace#delete', :via => :post, :id => /\d+/
+ match "/user/:display_name/traces/tag/:tag/page/:page" => "trace#list", :via => :get
+ match "/user/:display_name/traces/tag/:tag" => "trace#list", :via => :get
+ match "/user/:display_name/traces/page/:page" => "trace#list", :via => :get
+ match "/user/:display_name/traces" => "trace#list", :via => :get
+ match "/user/:display_name/traces/tag/:tag/rss" => "trace#georss", :via => :get, :defaults => { :format => :rss }
+ match "/user/:display_name/traces/rss" => "trace#georss", :via => :get, :defaults => { :format => :rss }
+ match "/user/:display_name/traces/:id" => "trace#view", :via => :get
+ match "/user/:display_name/traces/:id/picture" => "trace#picture", :via => :get
+ match "/user/:display_name/traces/:id/icon" => "trace#icon", :via => :get
+ match "/traces/tag/:tag/page/:page" => "trace#list", :via => :get
+ match "/traces/tag/:tag" => "trace#list", :via => :get
+ match "/traces/page/:page" => "trace#list", :via => :get
+ match "/traces" => "trace#list", :via => :get
+ match "/traces/tag/:tag/rss" => "trace#georss", :via => :get, :defaults => { :format => :rss }
+ match "/traces/rss" => "trace#georss", :via => :get, :defaults => { :format => :rss }
+ match "/traces/mine/tag/:tag/page/:page" => "trace#mine", :via => :get
+ match "/traces/mine/tag/:tag" => "trace#mine", :via => :get
+ match "/traces/mine/page/:page" => "trace#mine", :via => :get
+ match "/traces/mine" => "trace#mine", :via => :get
+ match "/trace/create" => "trace#create", :via => [:get, :post]
+ match "/trace/:id/data" => "trace#data", :via => :get, :id => /\d+/, :as => "trace_data"
+ match "/trace/:id/edit" => "trace#edit", :via => [:get, :post, :patch], :id => /\d+/, :as => "trace_edit"
+ match "/trace/:id/delete" => "trace#delete", :via => :post, :id => /\d+/
# diary pages
- match '/diary/new' => 'diary_entry#new', :via => [:get, :post]
- match '/diary/friends' => 'diary_entry#list', :friends => true, :via => :get, :as => "friend_diaries"
- match '/diary/nearby' => 'diary_entry#list', :nearby => true, :via => :get, :as => "nearby_diaries"
- match '/user/:display_name/diary/rss' => 'diary_entry#rss', :via => :get, :defaults => { :format => :rss }
- match '/diary/:language/rss' => 'diary_entry#rss', :via => :get, :defaults => { :format => :rss }
- match '/diary/rss' => 'diary_entry#rss', :via => :get, :defaults => { :format => :rss }
- match '/user/:display_name/diary/comments/:page' => 'diary_entry#comments', :via => :get, :page => /\d+/
- match '/user/:display_name/diary/comments/' => 'diary_entry#comments', :via => :get
- match '/user/:display_name/diary' => 'diary_entry#list', :via => :get
- match '/diary/:language' => 'diary_entry#list', :via => :get
- match '/diary' => 'diary_entry#list', :via => :get
- match '/user/:display_name/diary/:id' => 'diary_entry#view', :via => :get, :id => /\d+/
- match '/user/:display_name/diary/:id/newcomment' => 'diary_entry#comment', :via => :post, :id => /\d+/
- match '/user/:display_name/diary/:id/edit' => 'diary_entry#edit', :via => [:get, :post], :id => /\d+/
- match '/user/:display_name/diary/:id/hide' => 'diary_entry#hide', :via => :post, :id => /\d+/, :as => :hide_diary_entry
- match '/user/:display_name/diary/:id/hidecomment/:comment' => 'diary_entry#hidecomment', :via => :post, :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment
+ match "/diary/new" => "diary_entry#new", :via => [:get, :post]
+ match "/diary/friends" => "diary_entry#list", :friends => true, :via => :get, :as => "friend_diaries"
+ match "/diary/nearby" => "diary_entry#list", :nearby => true, :via => :get, :as => "nearby_diaries"
+ match "/user/:display_name/diary/rss" => "diary_entry#rss", :via => :get, :defaults => { :format => :rss }
+ match "/diary/:language/rss" => "diary_entry#rss", :via => :get, :defaults => { :format => :rss }
+ match "/diary/rss" => "diary_entry#rss", :via => :get, :defaults => { :format => :rss }
+ match "/user/:display_name/diary/comments/:page" => "diary_entry#comments", :via => :get, :page => /\d+/
+ match "/user/:display_name/diary/comments/" => "diary_entry#comments", :via => :get
+ match "/user/:display_name/diary" => "diary_entry#list", :via => :get
+ match "/diary/:language" => "diary_entry#list", :via => :get
+ match "/diary" => "diary_entry#list", :via => :get
+ match "/user/:display_name/diary/:id" => "diary_entry#view", :via => :get, :id => /\d+/
+ match "/user/:display_name/diary/:id/newcomment" => "diary_entry#comment", :via => :post, :id => /\d+/
+ match "/user/:display_name/diary/:id/edit" => "diary_entry#edit", :via => [:get, :post], :id => /\d+/
+ match "/user/:display_name/diary/:id/hide" => "diary_entry#hide", :via => :post, :id => /\d+/, :as => :hide_diary_entry
+ match "/user/:display_name/diary/:id/hidecomment/:comment" => "diary_entry#hidecomment", :via => :post, :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment
# user pages
- match '/user/:display_name' => 'user#view', :via => :get, :as => "user"
- match '/user/:display_name/make_friend' => 'user#make_friend', :via => [:get, :post], :as => "make_friend"
- match '/user/:display_name/remove_friend' => 'user#remove_friend', :via => [:get, :post], :as => "remove_friend"
- match '/user/:display_name/account' => 'user#account', :via => [:get, :post]
- match '/user/:display_name/set_status' => 'user#set_status', :via => :get, :as => :set_status_user
- match '/user/:display_name/delete' => 'user#delete', :via => :get, :as => :delete_user
+ match "/user/:display_name" => "user#view", :via => :get, :as => "user"
+ match "/user/:display_name/make_friend" => "user#make_friend", :via => [:get, :post], :as => "make_friend"
+ match "/user/:display_name/remove_friend" => "user#remove_friend", :via => [:get, :post], :as => "remove_friend"
+ match "/user/:display_name/account" => "user#account", :via => [:get, :post]
+ match "/user/:display_name/set_status" => "user#set_status", :via => :get, :as => :set_status_user
+ match "/user/:display_name/delete" => "user#delete", :via => :get, :as => :delete_user
# user lists
- match '/users' => 'user#list', :via => [:get, :post]
- match '/users/:status' => 'user#list', :via => [:get, :post]
+ match "/users" => "user#list", :via => [:get, :post]
+ match "/users/:status" => "user#list", :via => [:get, :post]
# geocoder
- match '/search' => 'geocoder#search', :via => :get, :as => :search
- match '/geocoder/search_latlon' => 'geocoder#search_latlon', :via => :get
- match '/geocoder/search_us_postcode' => 'geocoder#search_us_postcode', :via => :get
- match '/geocoder/search_uk_postcode' => 'geocoder#search_uk_postcode', :via => :get
- match '/geocoder/search_ca_postcode' => 'geocoder#search_ca_postcode', :via => :get
- match '/geocoder/search_osm_nominatim' => 'geocoder#search_osm_nominatim', :via => :get
- match '/geocoder/search_geonames' => 'geocoder#search_geonames', :via => :get
- match '/geocoder/search_osm_nominatim_reverse' => 'geocoder#search_osm_nominatim_reverse', :via => :get
- match '/geocoder/search_geonames_reverse' => 'geocoder#search_geonames_reverse', :via => :get
+ match "/search" => "geocoder#search", :via => :get, :as => :search
+ match "/geocoder/search_latlon" => "geocoder#search_latlon", :via => :get
+ match "/geocoder/search_us_postcode" => "geocoder#search_us_postcode", :via => :get
+ match "/geocoder/search_uk_postcode" => "geocoder#search_uk_postcode", :via => :get
+ match "/geocoder/search_ca_postcode" => "geocoder#search_ca_postcode", :via => :get
+ match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get
+ match "/geocoder/search_geonames" => "geocoder#search_geonames", :via => :get
+ match "/geocoder/search_osm_nominatim_reverse" => "geocoder#search_osm_nominatim_reverse", :via => :get
+ match "/geocoder/search_geonames_reverse" => "geocoder#search_geonames_reverse", :via => :get
# directions
- match '/directions' => 'directions#search', :via => :get, :as => :directions
+ match "/directions" => "directions#search", :via => :get, :as => :directions
# export
- match '/export/finish' => 'export#finish', :via => :post
- match '/export/embed' => 'export#embed', :via => :get
+ match "/export/finish" => "export#finish", :via => :post
+ match "/export/embed" => "export#embed", :via => :get
# messages
- match '/user/:display_name/inbox' => 'message#inbox', :via => :get, :as => "inbox"
- match '/user/:display_name/outbox' => 'message#outbox', :via => :get, :as => "outbox"
- match '/message/new/:display_name' => 'message#new', :via => [:get, :post], :as => "new_message"
- match '/message/read/:message_id' => 'message#read', :via => :get, :as => "read_message"
- match '/message/mark/:message_id' => 'message#mark', :via => :post, :as => "mark_message"
- match '/message/reply/:message_id' => 'message#reply', :via => [:get, :post], :as => "reply_message"
- match '/message/delete/:message_id' => 'message#delete', :via => :post, :as => "delete_message"
+ match "/user/:display_name/inbox" => "message#inbox", :via => :get, :as => "inbox"
+ match "/user/:display_name/outbox" => "message#outbox", :via => :get, :as => "outbox"
+ match "/message/new/:display_name" => "message#new", :via => [:get, :post], :as => "new_message"
+ match "/message/read/:message_id" => "message#read", :via => :get, :as => "read_message"
+ match "/message/mark/:message_id" => "message#mark", :via => :post, :as => "mark_message"
+ match "/message/reply/:message_id" => "message#reply", :via => [:get, :post], :as => "reply_message"
+ match "/message/delete/:message_id" => "message#delete", :via => :post, :as => "delete_message"
# oauth admin pages (i.e: for setting up new clients, etc...)
scope "/user/:display_name" do
resources :oauth_clients
end
- match '/oauth/revoke' => 'oauth#revoke', :via => [:get, :post]
- match '/oauth/authorize' => 'oauth#authorize', :via => [:get, :post], :as => :authorize
- match '/oauth/token' => 'oauth#token', :via => :get, :as => :token
- match '/oauth/request_token' => 'oauth#request_token', :via => [:get, :post], :as => :request_token
- match '/oauth/access_token' => 'oauth#access_token', :via => [:get, :post], :as => :access_token
- match '/oauth/test_request' => 'oauth#test_request', :via => :get, :as => :test_request
+ match "/oauth/revoke" => "oauth#revoke", :via => [:get, :post]
+ match "/oauth/authorize" => "oauth#authorize", :via => [:get, :post], :as => :authorize
+ match "/oauth/token" => "oauth#token", :via => :get, :as => :token
+ match "/oauth/request_token" => "oauth#request_token", :via => [:get, :post], :as => :request_token
+ match "/oauth/access_token" => "oauth#access_token", :via => [:get, :post], :as => :access_token
+ match "/oauth/test_request" => "oauth#test_request", :via => :get, :as => :test_request
# roles and banning pages
- match '/user/:display_name/role/:role/grant' => 'user_roles#grant', :via => :post, :as => "grant_role"
- match '/user/:display_name/role/:role/revoke' => 'user_roles#revoke', :via => :post, :as => "revoke_role"
- match '/user/:display_name/blocks' => 'user_blocks#blocks_on', :via => :get
- match '/user/:display_name/blocks_by' => 'user_blocks#blocks_by', :via => :get
- match '/blocks/new/:display_name' => 'user_blocks#new', :via => :get, :as => "new_user_block"
+ match "/user/:display_name/role/:role/grant" => "user_roles#grant", :via => :post, :as => "grant_role"
+ match "/user/:display_name/role/:role/revoke" => "user_roles#revoke", :via => :post, :as => "revoke_role"
+ match "/user/:display_name/blocks" => "user_blocks#blocks_on", :via => :get
+ match "/user/:display_name/blocks_by" => "user_blocks#blocks_by", :via => :get
+ match "/blocks/new/:display_name" => "user_blocks#new", :via => :get, :as => "new_user_block"
resources :user_blocks
- match '/blocks/:id/revoke' => 'user_blocks#revoke', :via => [:get, :post], :as => "revoke_user_block"
+ match "/blocks/:id/revoke" => "user_blocks#revoke", :via => [:get, :post], :as => "revoke_user_block"
# redactions
resources :redactions
-require 'migrate'
+require "migrate"
class CreateOsmDb < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class CleanupOsmDb < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class SqlSessionStoreSetup < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class UserEnhancements < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class TileTracepoints < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class TileNodes < ActiveRecord::Migration
def self.upgrade_table(from_table, to_table, model)
-require 'migrate'
+require "migrate"
class AddRelations < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class RemoveSegments < ActiveRecord::Migration
def self.up
cmd = "db/migrate/008_remove_segments_helper"
src = "#{cmd}.cc"
if !File.exist?(cmd) || File.mtime(cmd) < File.mtime(src)
- system('c++ -O3 -Wall `mysql_config --cflags --libs` ' +
+ system("c++ -O3 -Wall `mysql_config --cflags --libs` " +
"#{src} -o #{cmd}") || fail
end
-require 'migrate'
+require "migrate"
class DiaryComments < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class CreateAcls < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class PopulateNodeTagsAndRemove < ActiveRecord::Migration
def self.up
cmd = "db/migrate/020_populate_node_tags_and_remove_helper"
src = "#{cmd}.c"
if !File.exist?(cmd) || File.mtime(cmd) < File.mtime(src)
- system('cc -O3 -Wall `mysql_config --cflags --libs` ' +
+ system("cc -O3 -Wall `mysql_config --cflags --libs` " +
"#{src} -o #{cmd}") || fail
end
-require 'migrate'
+require "migrate"
class MoveToInnodb < ActiveRecord::Migration
@@conv_tables = %w(nodes ways way_tags way_nodes current_way_tags relation_members relations relation_tags current_relation_tags)
-require 'migrate'
+require "migrate"
class KeyConstraints < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddChangesets < ActiveRecord::Migration
@@conv_user_tables = %w(current_nodes current_relations current_ways nodes relations ways)
-require 'migrate'
+require "migrate"
class OrderRelationMembers < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddEndTimeToChangesets < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddMoreChangesetIndexes < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddUserForeignKeys < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class AddForeignKeys < ActiveRecord::Migration
def self.up
-require 'migrate'
-require 'rexml/document'
+require "migrate"
+require "rexml/document"
class CreateCountries < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class CreateLanguages < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class ChangeUserLocale < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddMoreControlsToGpxFiles < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddForeignKeysToOauthTables < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class CreateUserRoles < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class CreateUserBlocks < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class AlterUserRolesAndBlocks < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddStatusToUser < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddMapBugTables < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class RefactorMapBugTables < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class ChangeMapBugCommentType < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddDateClosed < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddMapBugCommentEvent < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class RenameBugsToNotes < ActiveRecord::Migration
def self.up
-require 'migrate'
+require "migrate"
class AddLowercaseUserIndexes < ActiveRecord::Migration
def up
-require 'migrate'
+require "migrate"
class AddTextFormat < ActiveRecord::Migration
def up
-require 'migrate'
+require "migrate"
class CreateRedactions < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class DropSessionTable < ActiveRecord::Migration
def up
-require 'migrate'
+require "migrate"
class AddUserAndDescriptionToRedaction < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class AddTextIndexToNoteComments < ActiveRecord::Migration
def up
-require 'migrate'
+require "migrate"
class CreateChangesetComments < ActiveRecord::Migration
def change
-require 'migrate'
+require "migrate"
class AddJoinTableBetweenUsersAndChangesets < ActiveRecord::Migration
def change
end
def self.from_s(s)
- BoundingBox.new(*s.split(/,/)) if s.count(',') == 3
+ BoundingBox.new(*s.split(/,/)) if s.count(",") == 3
end
def self.from_bbox_params(params)
- if params[:bbox] && params[:bbox].count(',') == 3
- bbox_array = params[:bbox].split(',')
+ if params[:bbox] && params[:bbox].count(",") == 3
+ bbox_array = params[:bbox].split(",")
end
from_bbox_array(bbox_array)
end
:include => nil,
:select => nil,
:group => nil,
- :parameter => 'page'
+ :parameter => "page"
}
end
# than or equal to zero). The page CGI parameter for links defaults to
# "page" and can be overridden with +page_parameter+.
def initialize(controller, item_count, items_per_page, current_page = 1)
- fail ArgumentError, 'must have at least one item per page' if
+ fail ArgumentError, "must have at least one item per page" if
items_per_page <= 0
@controller = controller
# not belong to this Paginator, an ArgumentError is raised.
def current_page=(page)
if page.is_a? Page
- fail ArgumentError, 'Page/Paginator mismatch' unless
+ fail ArgumentError, "Page/Paginator mismatch" unless
page.paginator == self
end
page = page.to_i
name = options[:name] || DEFAULT_OPTIONS[:name]
params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
- prefix = options[:prefix] || ''
- suffix = options[:suffix] || ''
+ prefix = options[:prefix] || ""
+ suffix = options[:suffix] || ""
pagination_links_each(paginator, options, prefix, suffix) do |n|
params[name] = n
first, last = paginator.first, paginator.last
- html = ''
+ html = ""
html << prefix if prefix
if always_show_anchors && !(wp_first = window_pages[0]).first?
html << yield(first.number)
- html << ' ... ' if wp_first.number - first.number > 1
- html << ' '
+ html << " ... " if wp_first.number - first.number > 1
+ html << " "
end
window_pages.each do |page|
else
html << yield(page.number)
end
- html << ' '
+ html << " "
end
if always_show_anchors && !(wp_last = window_pages[-1]).last?
- html << ' ... ' if last.number - wp_last.number > 1
+ html << " ... " if last.number - wp_last.number > 1
html << yield(last.number)
end
if gpx.actual_points > 0
Notifier.gpx_success(trace, gpx.actual_points).deliver
else
- Notifier.gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?').deliver
+ Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver
trace.destroy
end
rescue StandardError => ex
#!/usr/bin/env ruby
-require 'rubygems'
+require "rubygems"
require "daemons"
-require 'yaml'
-require 'erb'
+require "yaml"
+require "erb"
class Hash
def with_symbols!
)).result).with_symbols!
options[:dir_mode] = options[:dir_mode].to_sym
-Daemons.run File.dirname(__FILE__) + '/gpx_import.rb', options
+Daemons.run File.dirname(__FILE__) + "/gpx_import.rb", options
# take the first element and check that it is an osmChange element
@reader.read
- fail OSM::APIBadUserInput.new("Document element should be 'osmChange'.") if @reader.name != 'osmChange'
+ fail OSM::APIBadUserInput.new("Document element should be 'osmChange'.") if @reader.name != "osmChange"
result = OSM::API.new.get_xml_doc
result.root.name = "diffResult"
# loop at the top level, within the <osmChange> element
with_element do |action_name, action_attributes|
- if action_name == 'create'
+ if action_name == "create"
# 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|
# when this element is saved it will get a new ID, so we save it
# to produce the mapping which is sent to other elements.
- placeholder_id = xml['id'].to_i
+ placeholder_id = xml["id"].to_i
fail OSM::APIBadXMLError.new(model, xml) if placeholder_id.nil?
# check if the placeholder ID has been given before and throw
result.root << xml_result
end
- elsif action_name == 'modify'
+ elsif action_name == "modify"
# modify an existing element. again, this code doesn't directly deal
# with types, but uses duck typing to handle them transparently.
with_model do |model, xml|
result.root << xml_result
end
- elsif action_name == 'delete'
+ elsif action_name == "delete"
# delete action. this takes a payload in API 0.6, so we need to do
# most of the same checks that are done for the modify.
with_model do |model, xml|
# delete doesn't have to contain a full payload, according to
# the wiki docs, so we just extract the things we need.
- new_id = xml['id'].to_i
+ new_id = xml["id"].to_i
fail OSM::APIBadXMLError.new(model, xml, "ID attribute is required") if new_id.nil?
# if the ID is a placeholder then map it to the real ID
# build the "new" element by modifying the existing one
new = model.find(id)
- new.changeset_id = xml['changeset'].to_i
- new.version = xml['version'].to_i
+ new.changeset_id = xml["changeset"].to_i
+ new.version = xml["version"].to_i
check(model, xml, new)
# fetch the matching old element from the DB
proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
linegc = Magick::Draw.new
- linegc.stroke_linejoin('miter')
+ linegc.stroke_linejoin("miter")
linegc.stroke_width(1)
- linegc.stroke('#BBBBBB')
- linegc.fill('#BBBBBB')
+ linegc.stroke("#BBBBBB")
+ linegc.fill("#BBBBBB")
highlightgc = Magick::Draw.new
- highlightgc.stroke_linejoin('miter')
+ highlightgc.stroke_linejoin("miter")
highlightgc.stroke_width(3)
- highlightgc.stroke('#000000')
- highlightgc.fill('#000000')
+ highlightgc.stroke("#000000")
+ highlightgc.fill("#000000")
images = frames.times.collect do
Magick::Image.new(width, height) do |image|
- image.background_color = 'white'
- image.format = 'GIF'
+ image.background_color = "white"
+ image.format = "GIF"
end
end
end
il.delay = 50
- il.format = 'GIF'
+ il.format = "GIF"
il.to_blob
end
proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
gc = Magick::Draw.new
- gc.stroke_linejoin('miter')
+ gc.stroke_linejoin("miter")
gc.stroke_width(1)
- gc.stroke('#000000')
- gc.fill('#000000')
+ gc.stroke("#000000")
+ gc.fill("#000000")
image = Magick::Image.new(width, height) do |i|
- i.background_color = 'white'
- i.format = 'GIF'
+ i.background_color = "white"
+ i.format = "GIF"
end
oldpx = 0.0
module ID
- LOCALES = Rails.root.join('vendor/assets/iD/iD/locales').entries.map { |p| p.basename.to_s[/(.*).json/] && $1 }.compact
+ LOCALES = Rails.root.join("vendor/assets/iD/iD/locales").entries.map { |p| p.basename.to_s[/(.*).json/] && $1 }.compact
end
def self.describe_location(lat, lon, zoom = nil, language = nil)
zoom ||= 14
- language ||= http_accept_language.user_preferred_languages.join(',')
+ language ||= http_accept_language.user_preferred_languages.join(",")
Rails.cache.fetch "/nominatim/location/#{lat}/#{lon}/#{zoom}/#{language}" do
url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
-require 'osm'
+require "osm"
module NotRedactable
def redacted?
module ObjectMetadata
def add_metadata_to_xml_node(el, osm, changeset_cache, user_display_name_cache)
- el['changeset'] = osm.changeset_id.to_s
- el['redacted'] = osm.redaction.id.to_s if osm.redacted?
- el['timestamp'] = osm.timestamp.xmlschema
- el['version'] = osm.version.to_s
- el['visible'] = osm.visible.to_s
+ el["changeset"] = osm.changeset_id.to_s
+ el["redacted"] = osm.redaction.id.to_s if osm.redacted?
+ el["timestamp"] = osm.timestamp.xmlschema
+ el["version"] = osm.version.to_s
+ el["visible"] = osm.visible.to_s
if changeset_cache.key?(osm.changeset_id)
# use the cache if available
end
unless user_display_name_cache[user_id].nil?
- el['user'] = user_display_name_cache[user_id]
- el['uid'] = user_id.to_s
+ el["user"] = user_display_name_cache[user_id]
+ el["uid"] = user_id.to_s
end
end
def add_tags_to_xml_node(el, tags)
tags.each do |tag|
- tag_el = XML::Node.new('tag')
+ tag_el = XML::Node.new("tag")
- tag_el['k'] = tag.k
- tag_el['v'] = tag.v
+ tag_el["k"] = tag.k
+ tag_el["v"] = tag.v
el << tag_el
end
# The OSM module provides support functions for OSM.
module OSM
- require 'time'
- require 'rexml/parsers/sax2parser'
- require 'rexml/text'
- require 'xml/libxml'
+ require "time"
+ require "rexml/parsers/sax2parser"
+ require "rexml/text"
+ require "xml/libxml"
if defined?(SystemTimer)
Timer = SystemTimer
else
- require 'timeout'
+ require "timeout"
Timer = Timeout
end
def get_xml_doc
doc = XML::Document.new
doc.encoding = XML::Encoding::UTF_8
- root = XML::Node.new 'osm'
- root['version'] = API_VERSION.to_s
- root['generator'] = GENERATOR
- root['copyright'] = COPYRIGHT_OWNER
- root['attribution'] = ATTRIBUTION_URL
- root['license'] = LICENSE_URL
+ root = XML::Node.new "osm"
+ root["version"] = API_VERSION.to_s
+ root["generator"] = GENERATOR
+ root["copyright"] = COPYRIGHT_OWNER
+ root["attribution"] = ATTRIBUTION_URL
+ root["license"] = LICENSE_URL
doc.root = root
doc
end
if ipinfo.status == Quova::SUCCESS
country = ipinfo.country_code
else
- Net::HTTP.start('api.hostip.info') do |http|
+ Net::HTTP.start("api.hostip.info") do |http|
country = http.get("/country.php?ip=#{ip_address}").body
country = "GB" if country == "UK"
end
# Construct a random token of a given length
def self.make_token(length = 30)
- chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
- token = ''
+ chars = "abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+ token = ""
length.times do
token += chars[(rand * chars.length).to_i].chr
# end
begin
- require 'zlib'
- require 'stringio'
+ require "zlib"
+ require "stringio"
GZIP_SUPPORTED = true
rescue
GZIP_SUPPORTED = false
if output.length < response.body.length
@old_response_body = response.body
response.body = output.string
- response.headers['Content-encoding'] = @compression_encoding
+ response.headers["Content-encoding"] = @compression_encoding
end
end
def accepts_gzip?
return false unless GZIP_SUPPORTED
- accepts = request.env['HTTP_ACCEPT_ENCODING']
+ accepts = request.env["HTTP_ACCEPT_ENCODING"]
return false unless accepts && accepts =~ /(x-gzip|gzip)/
@compression_encoding = $1
true
def strip_whitespace
response.body.gsub!(/()|(.*?<\/script>)|()|()|\s+/m) do |m|
if m =~ /^()(.*?)<\/script>$/m
- $1 + $2.strip.gsub(/\s+/, ' ').gsub('', "\n-->") + ''
+ $1 + $2.strip.gsub(/\s+/, " ").gsub("", "\n-->") + ""
elsif m =~ /^$/m
- ''
+ ""
elsif m =~ /^<(textarea|pre)/
m
- else ' '
+ else " "
end
end
- response.body.gsub! /\s+\s+/, '>'
+ response.body.gsub! /\s+\s+/, ">"
end
end
-require 'stringio'
+require "stringio"
# The Potlatch module provides helper functions for potlatch and its communication with the server
module Potlatch
# Return eight-byte double-precision float
def self.getdouble(s)
- a = s.read(8).unpack('G') # G big-endian, E little-endian
+ a = s.read(8).unpack("G") # G big-endian, E little-endian
a[0]
end
def self.getobject(s)
arr = {}
while (key = getstring(s))
- break if key == ''
+ break if key == ""
arr[key] = getvalue(s)
end
s.getbyte # skip the 9 'end of object' value
# Pack variables as AMF
def self.encodevalue(n)
case n.class.to_s
- when 'Array'
+ when "Array"
a = 10.chr + encodelong(n.length)
n.each do |b|
a += encodevalue(b)
end
a
- when 'Hash'
+ when "Hash"
a = 3.chr
n.each do |k, v|
a += encodestring(k.to_s) + encodevalue(v)
end
a + 0.chr + 0.chr + 9.chr
- when 'String'
+ when "String"
2.chr + encodestring(n)
- when 'Bignum', 'Fixnum', 'Float'
+ when "Bignum", "Fixnum", "Float"
0.chr + encodedouble(n)
- when 'NilClass'
+ when "NilClass"
5.chr
- when 'TrueClass'
+ when "TrueClass"
0.chr + encodedouble(1)
- when 'FalseClass'
+ when "FalseClass"
0.chr + encodedouble(0)
else
Rails.logger.error("Unexpected Ruby type for AMF conversion: " + n.class.to_s)
# Encode number as eight-byte double precision float
def self.encodedouble(n)
- [n].pack('G')
+ [n].pack("G")
end
# Encode number as four-byte long
def self.encodelong(n)
- [n].pack('N')
+ [n].pack("N")
end
end
# Read preset menus
presets = {}
- presetmenus = { 'point' => [], 'way' => [], 'POI' => [] }
- presetnames = { 'point' => {}, 'way' => {}, 'POI' => {} }
- presettype = ''
- presetcategory = ''
+ presetmenus = { "point" => [], "way" => [], "POI" => [] }
+ presetnames = { "point" => {}, "way" => {}, "POI" => {} }
+ presettype = ""
+ presetcategory = ""
# StringIO.open(txt) do |file|
File.open("#{Rails.root}/config/potlatch/presets.txt") do |file|
file.each_line do|line|
kv = $2
presetnames[presettype][presetcategory].push(pre)
presets[pre] = {}
- kv.split(',').each do|a|
+ kv.split(",").each do|a|
presets[pre][$1] = $2 if a =~ /^(.+)=(.*)$/
end
end
next unless line.chomp =~ /(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/
tag = $1
- colours[tag] = $2.hex if $2 != '-'
- casing[tag] = $3.hex if $3 != '-'
- areas[tag] = $4.hex if $4 != '-'
+ colours[tag] = $2.hex if $2 != "-"
+ casing[tag] = $3.hex if $3 != "-"
+ areas[tag] = $4.hex if $4 != "-"
end
end
next unless line.chomp =~ /(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/
tag = $1
- relcolours[tag] = $2.hex if $2 != '-'
- relalphas[tag] = $3.to_i if $3 != '-'
- relwidths[tag] = $4.to_i if $4 != '-'
+ relcolours[tag] = $2.hex if $2 != "-"
+ relalphas[tag] = $3.to_i if $3 != "-"
+ relwidths[tag] = $4.to_i if $4 != "-"
end
end
icon_list.reverse!
# Read auto-complete
- autotags = { 'point' => {}, 'way' => {}, 'POI' => {} }
+ autotags = { "point" => {}, "way" => {}, "POI" => {} }
File.open("#{Rails.root}/config/potlatch/autocomplete.txt") do |file|
file.each_line do|line|
next unless line.chomp =~ /^([\w:]+)\/(\w+)\s+(.+)$/
tag = $1
type = $2
values = $3
- if values == '-'
+ if values == "-"
autotags[type][tag] = []
else
- autotags[type][tag] = values.split(',').sort.reverse
+ autotags[type][tag] = values.split(",").sort.reverse
end
end
end
##
# Load required libraries
-require 'soap/wsdlDriver'
+require "soap/wsdlDriver"
##
# Monkey patch WSDL parser to stop it moaning
-require 'osm'
+require "osm"
module Redactable
def self.included(base)
# array of 64 chars to encode 6 bits. this is almost like base64 encoding, but
# the symbolic chars are different, as base64's + and / aren't very
# URL-friendly.
- ARRAY = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['_', '~']
+ ARRAY = ("A".."Z").to_a + ("a".."z").to_a + ("0".."9").to_a + ["_", "~"]
##
# Given a string encoding a location, returns the [lon, lat, z] tuple of that
-namespace 'db' do
- desc 'Adds a version number to the nodes table'
+namespace "db" do
+ desc "Adds a version number to the nodes table"
task :node_version do
- require File.dirname(__FILE__) + '/../../config/environment'
+ require File.dirname(__FILE__) + "/../../config/environment"
increment = 1000
offset = 0
- id_max = OldNode.find(:first, :order => 'id desc').id
+ id_max = OldNode.find(:first, :order => "id desc").id
while offset < (id_max + increment)
hash = {}
# should be offsetting not selecting
- OldNode.find(:all, :limit => increment, :offset => offset, :order => 'timestamp').each do |node|
+ OldNode.find(:all, :limit => increment, :offset => offset, :order => "timestamp").each do |node|
hash[node.id] ||= []
hash[node.id] << node
end
namespace :test do
Rails::TestTask.new(lib: "test:prepare") do |t|
- t.pattern = 'test/lib/**/*_test.rb'
+ t.pattern = "test/lib/**/*_test.rb"
end
end
##
# Checks that a string is valid UTF-8 by trying to convert it to UTF-8
# using the iconv library, which is in the standard library.
- if ''.respond_to?("valid_encoding?")
+ if "".respond_to?("valid_encoding?")
def self.valid?(str)
return true if str.nil?
str.valid_encoding?
end
else
- require 'iconv'
+ require "iconv"
def self.valid?(str)
return true if str.nil?
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/environment'
+require File.dirname(__FILE__) + "/../config/environment"
UserToken.delete_all("expiry < NOW()")
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/environment'
+require File.dirname(__FILE__) + "/../config/environment"
exit 0 unless recipient = ARGV[0].match(/^([cm])-(\d+)-(.*)$/)
def po2hash(f)
trs = {}
path = []
- msgstr = ''
+ msgstr = ""
f.each_line do |line|
line.strip!
if line[0..8] == 'msgctxt "'
- path = line[9..-2].split(':')
+ path = line[9..-2].split(":")
elsif line[0..7] == 'msgstr "'
msgstr = line[8..-2]
end
add_translation(trs, path, msgstr)
path = []
- msgstr = ''
+ msgstr = ""
end
trs
end
filename = ARGV[0]
pofile = File.open(filename, "r")
-langcode = File.basename(filename, '.po')
+langcode = File.basename(filename, ".po")
tr = { langcode => po2hash(pofile) }
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/environment'
+require File.dirname(__FILE__) + "/../../config/environment"
Language.load(RAILS_ROOT + "/config/languages.yml")
require "yaml"
require "optparse"
-LOCALE_DIR = File.dirname(__FILE__) + '/../../config/locales/'
-EN = YAML.load_file(LOCALE_DIR + 'en.yml')
+LOCALE_DIR = File.dirname(__FILE__) + "/../../config/locales/"
+EN = YAML.load_file(LOCALE_DIR + "en.yml")
-def iterate(hash, fhash = {}, path = '', outfile = $stdout)
+def iterate(hash, fhash = {}, path = "", outfile = $stdout)
hash.each do |key, val|
fhash[key] = {} unless fhash.key? key
if val.is_a? Hash
fhash[key] = {} unless fhash[key].is_a? Hash
- iterate(val, fhash[key], path + key + ':', outfile)
+ iterate(val, fhash[key], path + key + ":", outfile)
else
outfile.puts "msgctxt \"#{path}#{key}\""
outfile.puts "msgid \"#{val}\""
def lang2po(lang, outfile = $stdout)
puts lang
- infile = LOCALE_DIR + lang + '.yml'
+ infile = LOCALE_DIR + lang + ".yml"
if File.exist? infile
oth = YAML.load_file(infile)
oth = oth[lang]
- iterate(EN['en'], oth, '', outfile)
+ iterate(EN["en"], oth, "", outfile)
else
- iterate(EN['en'], {}, '', outfile)
+ iterate(EN["en"], {}, "", outfile)
end
end
opt = ARGV[0]
-if opt == '--all'
+if opt == "--all"
# Produce .po files for all langs, and a .pot template
- PO_DIR = LOCALE_DIR + 'po/'
+ PO_DIR = LOCALE_DIR + "po/"
Dir.mkdir(PO_DIR) unless File.directory?(PO_DIR)
Dir.glob(LOCALE_DIR + "*.yml") do |filename|
- lang = File.basename(filename, '.yml')
- unless lang == 'en'
- outfile = File.new(PO_DIR + "#{lang}.po", 'w')
+ lang = File.basename(filename, ".yml")
+ unless lang == "en"
+ outfile = File.new(PO_DIR + "#{lang}.po", "w")
lang2po(lang, outfile)
outfile.close
end
end
- outfile = File.new(PO_DIR + "rails_port.pot", 'w')
- iterate(EN['en'], {}, '', outfile)
+ outfile = File.new(PO_DIR + "rails_port.pot", "w")
+ iterate(EN["en"], {}, "", outfile)
outfile.close
elsif opt
lang2po(opt)
else
- iterate(EN['en'])
+ iterate(EN["en"])
end
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
-APP_PATH = File.expand_path('../../config/application', __FILE__)
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands'
+APP_PATH = File.expand_path("../../config/application", __FILE__)
+require File.expand_path("../../config/boot", __FILE__)
+require "rails/commands"
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/environment'
+require File.dirname(__FILE__) + "/../config/environment"
start_time = Time.now
puts "<tr><th>User</th><th>Number of Points</th></tr>"
Trace.where(:inserted => true).group(:user_id).order("sum_size DESC").limit(50).sum(:size).each do |user, count|
- display_name = User.find(user).display_name.gsub('@', ' at ').gsub('.', ' dot ')
+ display_name = User.find(user).display_name.gsub("@", " at ").gsub(".", " dot ")
puts "<tr><td><a href=\"/user/#{display_name}\">#{display_name}</a></td><td>#{count}</td></tr>"
end
if column.nil?
puts "<td></td>"
else
- display_name = User.find(column[0]).display_name.gsub('@', ' at ').gsub('.', ' dot ')
+ display_name = User.find(column[0]).display_name.gsub("@", " at ").gsub(".", " dot ")
count = column[1]
puts "<td>#{count} <a href=\"/user/#{display_name}\">#{display_name}</a></td>"
end
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/environment'
-require 'generator'
+require File.dirname(__FILE__) + "/../config/environment"
+require "generator"
addresses = User.count(
:conditions => {
-require 'test_helper'
-require 'stringio'
+require "test_helper"
+require "stringio"
include Potlatch
class AmfControllerTest < ActionController::TestCase
# check contents of message
map = amf_result "/1"
- assert_equal 0, map[0], 'map error code should be 0'
- assert_equal "", map[1], 'map error text should be empty'
+ assert_equal 0, map[0], "map error code should be 0"
+ assert_equal "", map[1], "map error text should be empty"
# check the formatting of the message
- assert_equal 5, map.length, 'map should have length 5'
+ assert_equal 5, map.length, "map should have length 5"
assert_equal Array, map[2].class, 'map "ways" element should be an array'
assert_equal Array, map[3].class, 'map "nodes" element should be an array'
assert_equal Array, map[4].class, 'map "relations" element should be an array'
map[2].each do |w|
- assert_equal 2, w.length, 'way should be (id, version) pair'
- assert w[0] == w[0].floor, 'way ID should be an integer'
- assert w[1] == w[1].floor, 'way version should be an integer'
+ assert_equal 2, w.length, "way should be (id, version) pair"
+ assert w[0] == w[0].floor, "way ID should be an integer"
+ assert w[1] == w[1].floor, "way version should be an integer"
end
map[3].each do |n|
- assert_equal 5, w.length, 'node should be (id, lat, lon, [tags], version) tuple'
- assert n[0] == n[0].floor, 'node ID should be an integer'
- assert n[1] >= minlat - 0.01, 'node lat should be greater than min'
- assert n[1] <= maxlat - 0.01, 'node lat should be less than max'
- assert n[2] >= minlon - 0.01, 'node lon should be greater than min'
- assert n[2] <= maxlon - 0.01, 'node lon should be less than max'
- assert_equal Array, a[3].class, 'node tags should be array'
- assert n[4] == n[4].floor, 'node version should be an integer'
+ assert_equal 5, w.length, "node should be (id, lat, lon, [tags], version) tuple"
+ assert n[0] == n[0].floor, "node ID should be an integer"
+ assert n[1] >= minlat - 0.01, "node lat should be greater than min"
+ assert n[1] <= maxlat - 0.01, "node lat should be less than max"
+ assert n[2] >= minlon - 0.01, "node lon should be greater than min"
+ assert n[2] <= maxlon - 0.01, "node lon should be less than max"
+ assert_equal Array, a[3].class, "node tags should be array"
+ assert n[4] == n[4].floor, "node version should be an integer"
end
map[4].each do |r|
- assert_equal 2, r.length, 'relation should be (id, version) pair'
- assert r[0] == r[0].floor, 'relation ID should be an integer'
- assert r[1] == r[1].floor, 'relation version should be an integer'
+ assert_equal 2, r.length, "relation should be (id, version) pair"
+ assert r[0] == r[0].floor, "relation ID should be an integer"
+ assert r[1] == r[1].floor, "relation version should be an integer"
end
# TODO: looks like amf_controller changed since this test was written
assert ways.include?(current_ways(:used_way).id),
"map should include used way"
assert !ways.include?(current_ways(:invisible_way).id),
- 'map should not include deleted way'
+ "map should not include deleted way"
end
##
# check contents of message
map = amf_result "/1"
- assert_equal 0, map[0], 'first map element should be 0'
- assert_equal "", map[1], 'second map element should be an empty string'
- assert_equal Array, map[2].class, 'third map element should be an array'
+ assert_equal 0, map[0], "first map element should be 0"
+ assert_equal "", map[1], "second map element should be an empty string"
+ assert_equal Array, map[2].class, "third map element should be an array"
# TODO: looks like amf_controller changed since this test was written
# so someone who knows what they're doing should check this!
assert !map[2].include?(current_ways(:used_way).id),
"map should not include used way"
assert map[2].include?(current_ways(:invisible_way).id),
- 'map should include deleted way'
+ "map should include deleted way"
end
def test_whichways_deleted_toobig
# instead of a version number...
# try to get version 1
v1 = ways(:way_with_versions_v1)
- { latest.id => '',
+ { latest.id => "",
v1.way_id => v1.timestamp.strftime("%d %b %Y, %H:%M:%S")
}.each do |id, t|
amf_content "getway_old", "/1", [id, t]
v1 = ways(:way_with_versions_v1)
# try to get last visible version of non-existent way
# try to get specific version of non-existent way
- [[0, ''],
- [0, '1 Jan 1970, 00:00:00'],
+ [[0, ""],
+ [0, "1 Jan 1970, 00:00:00"],
[v1.way_id, (v1.timestamp - 10).strftime("%d %b %Y, %H:%M:%S")]
].each do |id, t|
amf_content "getway_old", "/1", [id, t]
history = amf_result("/1")
# ['way',wayid,history]
- assert_equal 'way', history[0]
+ assert_equal "way", history[0]
assert_equal latest.id, history[1]
# We use dates rather than version numbers here, because you might
# have moved a node within a way (i.e. way version not incremented).
history = amf_result("/1")
# ['way',wayid,history]
- assert_equal history[0], 'way'
+ assert_equal history[0], "way"
assert_equal history[1], 0
assert history[2].empty?
end
# ['node',nodeid,history]
# note that (as per getway_history) we actually round up
# to the next second
- assert_equal history[0], 'node',
+ assert_equal history[0], "node",
'first element should be "node"'
assert_equal history[1], latest.id,
- 'second element should be the input node ID'
+ "second element should be the input node ID"
assert_equal history[2].first[0],
(latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
- 'first element in third element (array) should be the latest version'
+ "first element in third element (array) should be the latest version"
assert_equal history[2].last[0],
(nodes(:node_with_versions_v1).timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
- 'last element in third element (array) should be the initial version'
+ "last element in third element (array) should be the initial version"
end
def test_getnode_history_nonexistent
history = amf_result("/1")
# ['node',nodeid,history]
- assert_equal history[0], 'node'
+ assert_equal history[0], "node"
assert_equal history[1], 0
assert history[2].empty?
end
-require 'test_helper'
-require 'api_controller'
+require "test_helper"
+require "api_controller"
class ApiControllerTest < ActionController::TestCase
api_fixtures
# http://wiki.openstreetmap.org/wiki/Rails#Installing_the_quadtile_functions
# or by looking at the readme in db/README
def test_changes_simple
- Timecop.freeze(Time.parse('2010-04-03 10:55:00'))
+ Timecop.freeze(Time.parse("2010-04-03 10:55:00"))
get :changes
assert_response :success
# print @response.body
-require 'test_helper'
-require 'browse_controller'
+require "test_helper"
+require "browse_controller"
class BrowseControllerTest < ActionController::TestCase
api_fixtures
end
def test_read_relation
- browse_check 'relation', relations(:visible_relation).relation_id, 'browse/feature'
+ browse_check "relation", relations(:visible_relation).relation_id, "browse/feature"
end
def test_read_relation_history
- browse_check 'relation_history', relations(:visible_relation).relation_id, 'browse/history'
+ browse_check "relation_history", relations(:visible_relation).relation_id, "browse/history"
end
def test_read_way
- browse_check 'way', ways(:visible_way).way_id, 'browse/feature'
+ browse_check "way", ways(:visible_way).way_id, "browse/feature"
end
def test_read_way_history
- browse_check 'way_history', ways(:visible_way).way_id, 'browse/history'
+ browse_check "way_history", ways(:visible_way).way_id, "browse/history"
end
def test_read_node
- browse_check 'node', nodes(:visible_node).node_id, 'browse/feature'
+ browse_check "node", nodes(:visible_node).node_id, "browse/feature"
end
def test_read_node_history
- browse_check 'node_history', nodes(:visible_node).node_id, 'browse/history'
+ browse_check "node_history", nodes(:visible_node).node_id, "browse/history"
end
def test_read_changeset
- browse_check 'changeset', changesets(:normal_user_first_change).id, 'browse/changeset'
+ browse_check "changeset", changesets(:normal_user_first_change).id, "browse/changeset"
end
def test_read_note
- browse_check 'note', notes(:open_note).id, 'browse/note'
+ browse_check "note", notes(:open_note).id, "browse/note"
end
##
def test_redacted_way_history
get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
assert_response :success
- assert_template 'browse/history'
+ assert_template "browse/history"
# there are 4 revisions of the redacted way, but only 2
# should be showing details here.
def test_redacted_relation_history
get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
assert_response :success
- assert_template 'browse/history'
+ assert_template "browse/history"
# there are 4 revisions of the redacted relation, but only 2
# should be showing details here.
-require 'test_helper'
-require 'changeset_controller'
+require "test_helper"
+require "changeset_controller"
class ChangesetControllerTest < ActionController::TestCase
api_fixtures
changeset_id = changesets(:public_user_first_change).id
%w(node way relation).each do |type|
delete.find("//osmChange/delete/#{type}").each do |n|
- n['changeset'] = changeset_id.to_s
+ n["changeset"] = changeset_id.to_s
end
end
content "<osm><changeset>" +
"<tag k='created_by' v='osm test suite checking changesets'/>" +
"</changeset></osm>"
- assert_difference('Changeset.count', 1) do
+ assert_difference("Changeset.count", 1) do
put :create
end
assert_response :success
assert_equal 2, Node.find(new_node_id).tags.size, "new node should have two tags"
assert_equal [new_node_id, 3], Way.find(1).nds, "way nodes should match"
Relation.find(1).members.each do |type, id, _role|
- if type == 'node'
+ if type == "node"
assert_equal new_node_id, id, "relation should contain new node"
end
end
assert_response :success, "can't get changesets by user and open"
assert_changesets [1]
- get :query, :time => '2007-12-31'
+ get :query, :time => "2007-12-31"
assert_response :success, "can't get changesets by time-since"
assert_changesets [1, 2, 4, 5, 6]
- get :query, :time => '2008-01-01T12:34Z'
+ get :query, :time => "2008-01-01T12:34Z"
assert_response :success, "can't get changesets by time-since with hour"
assert_changesets [1, 2, 4, 5, 6]
- get :query, :time => '2007-12-31T23:59Z,2008-01-01T00:01Z'
+ get :query, :time => "2007-12-31T23:59Z,2008-01-01T00:01Z"
assert_response :success, "can't get changesets by time-range"
assert_changesets [1, 5, 6]
- get :query, :open => 'true'
+ get :query, :open => "true"
assert_response :success, "can't get changesets by open-ness"
assert_changesets [1, 2, 4]
- get :query, :closed => 'true'
+ get :query, :closed => "true"
assert_response :success, "can't get changesets by closed-ness"
assert_changesets [3, 5, 6, 7, 8]
- get :query, :closed => 'true', :user => users(:normal_user).id
+ get :query, :closed => "true", :user => users(:normal_user).id
assert_response :success, "can't get changesets by closed-ness and user"
assert_changesets [3, 6, 8]
- get :query, :closed => 'true', :user => users(:public_user).id
+ get :query, :closed => "true", :user => users(:public_user).id
assert_response :success, "can't get changesets by closed-ness and user"
assert_changesets [7]
- get :query, :changesets => '1,2,3'
+ get :query, :changesets => "1,2,3"
assert_response :success, "can't get changesets by id (as comma-separated string)"
assert_changesets [1, 2, 3]
- get :query, :changesets => ''
+ get :query, :changesets => ""
assert_response :bad_request, "should be a bad request since changesets is empty"
end
changeset = changesets(:normal_user_first_change)
new_changeset = changeset.to_xml
new_tag = XML::Node.new "tag"
- new_tag['k'] = "tagtesting"
- new_tag['v'] = "valuetesting"
+ new_tag["k"] = "tagtesting"
+ new_tag["v"] = "valuetesting"
new_changeset.find("//osm/changeset").first << new_tag
content new_changeset
changeset = changesets(:public_user_first_change)
new_changeset = changeset.to_xml
new_tag = XML::Node.new "tag"
- new_tag['k'] = "tagtesting"
- new_tag['v'] = "valuetesting"
+ new_tag["k"] = "tagtesting"
+ new_tag["v"] = "valuetesting"
new_changeset.find("//osm/changeset").first << new_tag
content new_changeset
changeset = changesets(:normal_user_first_change)
new_changeset = changeset.to_xml
new_tag = XML::Node.new "tag"
- new_tag['k'] = "testing"
- new_tag['v'] = "testing"
+ new_tag["k"] = "testing"
+ new_tag["v"] = "testing"
new_changeset.find("//osm/changeset").first << new_tag
content new_changeset
# loop until we fill the changeset with nodes
offset.times do |i|
- node_xml['lat'] = rand.to_s
- node_xml['lon'] = rand.to_s
- node_xml['version'] = (i + 1).to_s
+ node_xml["lat"] = rand.to_s
+ node_xml["lon"] = rand.to_s
+ node_xml["version"] = (i + 1).to_s
content node_doc
put :update, :id => node_id
end
# trying again should fail
- node_xml['lat'] = rand.to_s
- node_xml['lon'] = rand.to_s
- node_xml['version'] = offset.to_s
+ node_xml["lat"] = rand.to_s
+ node_xml["lon"] = rand.to_s
+ node_xml["version"] = offset.to_s
content node_doc
put :update, :id => node_id
assert_template :layout => "map"
assert_select "h2", :text => "Changesets", :count => 1
- get :list, :format => "html", :list => '1', :bbox => '-180,-90,90,180'
+ get :list, :format => "html", :list => "1", :bbox => "-180,-90,90,180"
assert_response :success
assert_template "list"
assert_template :layout => "xhr"
assert_select "h2", :text => "Changesets", :count => 1
- get :list, :format => "html", :list => '1', :bbox => '-180,-90,90,180'
+ get :list, :format => "html", :list => "1", :bbox => "-180,-90,90,180"
assert_response :success
assert_template "list"
def test_list_user_not_found
get :list, :format => "html", :display_name => "Some random user"
assert_response :not_found
- assert_template 'user/no_such_user'
+ assert_template "user/no_such_user"
end
##
##
# create comment success
def test_create_comment_success
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
- assert_difference('ChangesetComment.count') do
- post :comment, :id => changesets(:normal_user_closed_change).id, :text => 'This is a comment'
+ assert_difference("ChangesetComment.count") do
+ post :comment, :id => changesets(:normal_user_closed_change).id, :text => "This is a comment"
end
assert_response :success
end
# create comment fail
def test_create_comment_fail
# unauthorized
- post :comment, :id => changesets(:normal_user_closed_change).id, :text => 'This is a comment'
+ post :comment, :id => changesets(:normal_user_closed_change).id, :text => "This is a comment"
assert_response :unauthorized
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
# bad changeset id
- assert_no_difference('ChangesetComment.count') do
- post :comment, :id => 999111, :text => 'This is a comment'
+ assert_no_difference("ChangesetComment.count") do
+ post :comment, :id => 999111, :text => "This is a comment"
end
assert_response :not_found
# not closed changeset
- assert_no_difference('ChangesetComment.count') do
- post :comment, :id => changesets(:normal_user_first_change).id, :text => 'This is a comment'
+ assert_no_difference("ChangesetComment.count") do
+ post :comment, :id => changesets(:normal_user_first_change).id, :text => "This is a comment"
end
assert_response :conflict
# no text
- assert_no_difference('ChangesetComment.count') do
+ assert_no_difference("ChangesetComment.count") do
post :comment, :id => changesets(:normal_user_closed_change).id
end
assert_response :bad_request
# empty text
- assert_no_difference('ChangesetComment.count') do
- post :comment, :id => changesets(:normal_user_closed_change).id, :text => ''
+ assert_no_difference("ChangesetComment.count") do
+ post :comment, :id => changesets(:normal_user_closed_change).id, :text => ""
end
assert_response :bad_request
end
##
# test subscribe success
def test_subscribe_success
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
changeset = changesets(:normal_user_closed_change)
- assert_difference('changeset.subscribers.count') do
+ assert_difference("changeset.subscribers.count") do
post :subscribe, :id => changeset.id
end
assert_response :success
def test_subscribe_fail
# unauthorized
changeset = changesets(:normal_user_closed_change)
- assert_no_difference('changeset.subscribers.count') do
+ assert_no_difference("changeset.subscribers.count") do
post :subscribe, :id => changeset.id
end
assert_response :unauthorized
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
# bad changeset id
- assert_no_difference('changeset.subscribers.count') do
+ assert_no_difference("changeset.subscribers.count") do
post :subscribe, :id => 999111
end
assert_response :not_found
# not closed changeset
changeset = changesets(:normal_user_first_change)
- assert_no_difference('changeset.subscribers.count') do
+ assert_no_difference("changeset.subscribers.count") do
post :subscribe, :id => changeset.id
end
assert_response :conflict
# trying to subscribe when already subscribed
changeset = changesets(:normal_user_subscribed_change)
- assert_no_difference('changeset.subscribers.count') do
+ assert_no_difference("changeset.subscribers.count") do
post :subscribe, :id => changeset.id
end
assert_response :conflict
##
# test unsubscribe success
def test_unsubscribe_success
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
changeset = changesets(:normal_user_subscribed_change)
- assert_difference('changeset.subscribers.count', -1) do
+ assert_difference("changeset.subscribers.count", -1) do
post :unsubscribe, :id => changeset.id
end
assert_response :success
def test_unsubscribe_fail
# unauthorized
changeset = changesets(:normal_user_closed_change)
- assert_no_difference('changeset.subscribers.count') do
+ assert_no_difference("changeset.subscribers.count") do
post :unsubscribe, :id => changeset.id
end
assert_response :unauthorized
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
# bad changeset id
- assert_no_difference('changeset.subscribers.count', -1) do
+ assert_no_difference("changeset.subscribers.count", -1) do
post :unsubscribe, :id => 999111
end
assert_response :not_found
# not closed changeset
changeset = changesets(:normal_user_first_change)
- assert_no_difference('changeset.subscribers.count', -1) do
+ assert_no_difference("changeset.subscribers.count", -1) do
post :unsubscribe, :id => changeset.id
end
assert_response :conflict
# trying to unsubscribe when not subscribed
changeset = changesets(:normal_user_closed_change)
- assert_no_difference('changeset.subscribers.count') do
+ assert_no_difference("changeset.subscribers.count") do
post :unsubscribe, :id => changeset.id
end
assert_response :not_found
def test_hide_comment_fail
# unauthorized
comment = changeset_comments(:normal_comment_1)
- assert('comment.visible') do
+ assert("comment.visible") do
post :hide_comment, :id => comment.id
assert_response :unauthorized
end
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
# not a moderator
- assert('comment.visible') do
+ assert("comment.visible") do
post :hide_comment, :id => comment.id
assert_response :forbidden
end
- basic_authorization(users(:moderator_user).email, 'test')
+ basic_authorization(users(:moderator_user).email, "test")
# bad comment id
post :hide_comment, :id => 999111
def test_hide_comment_success
comment = changeset_comments(:normal_comment_1)
- basic_authorization(users(:moderator_user).email, 'test')
+ basic_authorization(users(:moderator_user).email, "test")
- assert('!comment.visible') do
+ assert("!comment.visible") do
post :hide_comment, :id => comment.id
end
assert_response :success
def test_unhide_comment_fail
# unauthorized
comment = changeset_comments(:normal_comment_1)
- assert('comment.visible') do
+ assert("comment.visible") do
post :unhide_comment, :id => comment.id
assert_response :unauthorized
end
- basic_authorization(users(:public_user).email, 'test')
+ basic_authorization(users(:public_user).email, "test")
# not a moderator
- assert('comment.visible') do
+ assert("comment.visible") do
post :unhide_comment, :id => comment.id
assert_response :forbidden
end
- basic_authorization(users(:moderator_user).email, 'test')
+ basic_authorization(users(:moderator_user).email, "test")
# bad comment id
post :unhide_comment, :id => 999111
def test_unhide_comment_success
comment = changeset_comments(:normal_comment_1)
- basic_authorization(users(:moderator_user).email, 'test')
+ basic_authorization(users(:moderator_user).email, "test")
- assert('!comment.visible') do
+ assert("!comment.visible") do
post :unhide_comment, :id => comment.id
end
assert_response :success
# check the bbox
doc = XML::Parser.string(@response.body).parse
changeset = doc.find("//osm/changeset").first
- assert_equal bbox[0], changeset['min_lon'].to_f, "min lon"
- assert_equal bbox[1], changeset['min_lat'].to_f, "min lat"
- assert_equal bbox[2], changeset['max_lon'].to_f, "max lon"
- assert_equal bbox[3], changeset['max_lat'].to_f, "max lat"
+ assert_equal bbox[0], changeset["min_lon"].to_f, "min lon"
+ assert_equal bbox[1], changeset["min_lat"].to_f, "min lat"
+ assert_equal bbox[2], changeset["max_lon"].to_f, "max lon"
+ assert_equal bbox[3], changeset["max_lat"].to_f, "max lat"
end
##
# update the changeset_id of a way element
def update_changeset(xml, changeset_id)
- xml_attr_rewrite(xml, 'changeset', changeset_id)
+ xml_attr_rewrite(xml, "changeset", changeset_id)
end
##
-require 'test_helper'
+require "test_helper"
class DiaryEntryControllerTest < ActionController::TestCase
fixtures :users, :diary_entries, :diary_comments, :languages
assert_redirected_to :controller => :user, :action => "login", :referer => "/diary/new"
# Now pretend to login by using the session hash, with the
# id of the person we want to login as through session(:user)=user.id
- get(:new, nil, 'user' => users(:normal_user).id)
+ get(:new, nil, "user" => users(:normal_user).id)
assert_response :success
# print @response.body
assert_redirected_to :controller => :user, :action => "login", :referer => "/user/#{entry.user.display_name}/diary/#{entry.id}/edit"
# Verify that you get a not found error, when you pass a bogus id
- get(:edit, { :display_name => entry.user.display_name, :id => 9999 }, { 'user' => entry.user.id })
+ get(:edit, { :display_name => entry.user.display_name, :id => 9999 }, { "user" => entry.user.id })
assert_response :not_found
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
# Now pass the id, and check that you can edit it, when using the same
# user as the person who created the entry
- get(:edit, { :display_name => entry.user.display_name, :id => entry.id }, { 'user' => entry.user.id })
+ get(:edit, { :display_name => entry.user.display_name, :id => entry.id }, { "user" => entry.user.id })
assert_response :success
assert_select "title", :text => /Edit diary entry/, :count => 1
assert_select "div.content-heading", :count => 1 do
new_latitude = "1.1"
new_longitude = "2.2"
new_language_code = "en"
- post(:edit, { :display_name => entry.user.display_name, :id => entry.id, 'commit' => 'save',
- 'diary_entry' => { 'title' => new_title, 'body' => new_body, 'latitude' => new_latitude,
- 'longitude' => new_longitude, 'language_code' => new_language_code } },
- { 'user' => entry.user.id })
+ post(:edit, { :display_name => entry.user.display_name, :id => entry.id, "commit" => "save",
+ "diary_entry" => { "title" => new_title, "body" => new_body, "latitude" => new_latitude,
+ "longitude" => new_longitude, "language_code" => new_language_code } },
+ { "user" => entry.user.id })
assert_response :redirect
assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
# Now check that the new data is rendered, when logged in
- get :view, { :display_name => entry.user.display_name, :id => entry.id }, { 'user' => entry.user.id }
+ get :view, { :display_name => entry.user.display_name, :id => entry.id }, { "user" => entry.user.id }
assert_response :success
- assert_template 'diary_entry/view'
+ assert_template "diary_entry/view"
assert_select "title", :text => /Users' diaries | /, :count => 1
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1
end
# and when not logged in as the user who wrote the entry
- get :view, { :display_name => entry.user.display_name, :id => entry.id }, { 'user' => entry.user.id }
+ get :view, { :display_name => entry.user.display_name, :id => entry.id }, { "user" => entry.user.id }
assert_response :success
- assert_template 'diary_entry/view'
+ assert_template "diary_entry/view"
assert_select "title", :text => /Users' diaries | /, :count => 1
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => /#{users(:normal_user).display_name}'s diary/, :count => 1
end
def test_edit_diary_entry_i18n
- get :edit, { :display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id }, { 'user' => users(:normal_user).id }
+ get :edit, { :display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id }, { "user" => users(:normal_user).id }
assert_response :success
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
end
new_longitude = "2.2"
new_language_code = "en"
assert_difference "DiaryEntry.count", 1 do
- post(:new, { 'commit' => 'save',
- 'diary_entry' => { 'title' => new_title, 'body' => new_body, 'latitude' => new_latitude,
- 'longitude' => new_longitude, 'language_code' => new_language_code } },
+ post(:new, { "commit" => "save",
+ "diary_entry" => { "title" => new_title, "body" => new_body, "latitude" => new_latitude,
+ "longitude" => new_longitude, "language_code" => new_language_code } },
{ :user => users(:normal_user).id })
end
assert_response :redirect
def test_listing_diary_entries
get :list
assert_response :success, "Should be able to list the diary entries in locale"
- assert_template 'list', "Should use the list template in locale"
+ assert_template "list", "Should use the list template in locale"
assert_select "span[class=translation_missing]", false, "Missing translation in list of diary entries"
# Now try to find a specific user's diary entry
get :list, :display_name => users(:normal_user).display_name
assert_response :success, "Should be able to list the diary entries for a user in locale"
- assert_template 'list', "Should use the list template for a user in locale"
+ assert_template "list", "Should use the list template for a user in locale"
assert_no_missing_translations
end
# end
def test_rss_language_with_no_entries
- get :rss, :language => 'sl', :format => :rss
+ get :rss, :language => "sl", :format => :rss
assert_response :success, "Should be able to get a specific language diary RSS"
assert_select "rss>channel>item", :count => 0 # , "Diary entries should be filtered by language"
end
def test_rss_nonexisting_user
# Try a user that has never existed
- get :rss, :display_name => 'fakeUsername76543', :format => :rss
+ get :rss, :display_name => "fakeUsername76543", :format => :rss
assert_response :not_found, "Should not be able to get a nonexisting users diary RSS"
# Try a suspended user
-require 'test_helper'
+require "test_helper"
class DirectionsControllerTest < ActionController::TestCase
##
-require 'test_helper'
+require "test_helper"
class ExportControllerTest < ActionController::TestCase
##
###
# test the finish action for raw OSM data
def test_finish_osm
- get :finish, :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => 'osm'
+ get :finish, :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm"
assert_response :redirect
assert_redirected_to "http://api.openstreetmap.org/api/#{API_VERSION}/map?bbox=0.0,50.0,1.0,51.0"
end
###
# test the finish action for mapnik images
def test_finish_mapnik
- get :finish, :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => 'mapnik', :mapnik_format => 'test', :mapnik_scale => '12'
+ get :finish, :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "mapnik", :mapnik_format => "test", :mapnik_scale => "12"
assert_response :redirect
assert_redirected_to "http://render.openstreetmap.org/cgi-bin/export?bbox=0.0,50.0,1.0,51.0&scale=12&format=test"
end
# coding: utf-8
-require 'test_helper'
-require 'geocoder_controller'
+require "test_helper"
+require "geocoder_controller"
class GeocoderControllerTest < ActionController::TestCase
##
# Test identification of basic lat/lon pairs
def test_identify_latlon_basic
[
- '50.06773 14.37742',
- '50.06773, 14.37742',
- '+50.06773 +14.37742',
- '+50.06773, +14.37742'
+ "50.06773 14.37742",
+ "50.06773, 14.37742",
+ "+50.06773 +14.37742",
+ "+50.06773, +14.37742"
].each do |code|
latlon_check code, 50.06773, 14.37742
end
# Test identification of lat/lon pairs using N/E with degrees
def test_identify_latlon_ne_d
[
- 'N50.06773 E14.37742',
- 'N50.06773, E14.37742',
- '50.06773N 14.37742E',
- '50.06773N, 14.37742E'
+ "N50.06773 E14.37742",
+ "N50.06773, E14.37742",
+ "50.06773N 14.37742E",
+ "50.06773N, 14.37742E"
].each do |code|
latlon_check code, 50.06773, 14.37742
end
# Test identification of lat/lon pairs using N/W with degrees
def test_identify_latlon_nw_d
[
- 'N50.06773 W14.37742',
- 'N50.06773, W14.37742',
- '50.06773N 14.37742W',
- '50.06773N, 14.37742W'
+ "N50.06773 W14.37742",
+ "N50.06773, W14.37742",
+ "50.06773N 14.37742W",
+ "50.06773N, 14.37742W"
].each do |code|
latlon_check code, 50.06773, -14.37742
end
# Test identification of lat/lon pairs using S/E with degrees
def test_identify_latlon_se_d
[
- 'S50.06773 E14.37742',
- 'S50.06773, E14.37742',
- '50.06773S 14.37742E',
- '50.06773S, 14.37742E'
+ "S50.06773 E14.37742",
+ "S50.06773, E14.37742",
+ "50.06773S 14.37742E",
+ "50.06773S, 14.37742E"
].each do |code|
latlon_check code, -50.06773, 14.37742
end
# Test identification of lat/lon pairs using S/W with degrees
def test_identify_latlon_sw_d
[
- 'S50.06773 W14.37742',
- 'S50.06773, W14.37742',
- '50.06773S 14.37742W',
- '50.06773S, 14.37742W'
+ "S50.06773 W14.37742",
+ "S50.06773, W14.37742",
+ "50.06773S 14.37742W",
+ "50.06773S, 14.37742W"
].each do |code|
latlon_check code, -50.06773, -14.37742
end
# Test identification of lat/lon pairs using N/E with degrees/mins
def test_identify_latlon_ne_dm
[
- 'N 50° 04.064 E 014° 22.645',
+ "N 50° 04.064 E 014° 22.645",
"N 50° 04.064' E 014° 22.645",
"N 50° 04.064', E 014° 22.645'",
- 'N50° 04.064 E14° 22.645',
- 'N 50 04.064 E 014 22.645',
- 'N50 4.064 E14 22.645',
+ "N50° 04.064 E14° 22.645",
+ "N 50 04.064 E 014 22.645",
+ "N50 4.064 E14 22.645",
"50° 04.064' N, 014° 22.645' E"
].each do |code|
latlon_check code, 50.06773, 14.37742
# Test identification of lat/lon pairs using N/W with degrees/mins
def test_identify_latlon_nw_dm
[
- 'N 50° 04.064 W 014° 22.645',
+ "N 50° 04.064 W 014° 22.645",
"N 50° 04.064' W 014° 22.645",
"N 50° 04.064', W 014° 22.645'",
- 'N50° 04.064 W14° 22.645',
- 'N 50 04.064 W 014 22.645',
- 'N50 4.064 W14 22.645',
+ "N50° 04.064 W14° 22.645",
+ "N 50 04.064 W 014 22.645",
+ "N50 4.064 W14 22.645",
"50° 04.064' N, 014° 22.645' W"
].each do |code|
latlon_check code, 50.06773, -14.37742
# Test identification of lat/lon pairs using S/E with degrees/mins
def test_identify_latlon_se_dm
[
- 'S 50° 04.064 E 014° 22.645',
+ "S 50° 04.064 E 014° 22.645",
"S 50° 04.064' E 014° 22.645",
"S 50° 04.064', E 014° 22.645'",
- 'S50° 04.064 E14° 22.645',
- 'S 50 04.064 E 014 22.645',
- 'S50 4.064 E14 22.645',
+ "S50° 04.064 E14° 22.645",
+ "S 50 04.064 E 014 22.645",
+ "S50 4.064 E14 22.645",
"50° 04.064' S, 014° 22.645' E"
].each do |code|
latlon_check code, -50.06773, 14.37742
# Test identification of lat/lon pairs using S/W with degrees/mins
def test_identify_latlon_sw_dm
[
- 'S 50° 04.064 W 014° 22.645',
+ "S 50° 04.064 W 014° 22.645",
"S 50° 04.064' W 014° 22.645",
"S 50° 04.064', W 014° 22.645'",
- 'S50° 04.064 W14° 22.645',
- 'S 50 04.064 W 014 22.645',
- 'S50 4.064 W14 22.645',
+ "S50° 04.064 W14° 22.645",
+ "S 50 04.064 W 014 22.645",
+ "S50 4.064 W14 22.645",
"50° 04.064' S, 014° 22.645' W"
].each do |code|
latlon_check code, -50.06773, -14.37742
"N 50° 4' 03.828\" E 14° 22' 38.712\"",
"N 50° 4' 03.828\", E 14° 22' 38.712\"",
"N 50° 4′ 03.828″, E 14° 22′ 38.712″",
- 'N50 4 03.828 E14 22 38.712',
- 'N50 4 03.828, E14 22 38.712',
+ "N50 4 03.828 E14 22 38.712",
+ "N50 4 03.828, E14 22 38.712",
"50°4'3.828\"N 14°22'38.712\"E"
].each do |code|
latlon_check code, 50.06773, 14.37742
"N 50° 4' 03.828\" W 14° 22' 38.712\"",
"N 50° 4' 03.828\", W 14° 22' 38.712\"",
"N 50° 4′ 03.828″, W 14° 22′ 38.712″",
- 'N50 4 03.828 W14 22 38.712',
- 'N50 4 03.828, W14 22 38.712',
+ "N50 4 03.828 W14 22 38.712",
+ "N50 4 03.828, W14 22 38.712",
"50°4'3.828\"N 14°22'38.712\"W"
].each do |code|
latlon_check code, 50.06773, -14.37742
"S 50° 4' 03.828\" E 14° 22' 38.712\"",
"S 50° 4' 03.828\", E 14° 22' 38.712\"",
"S 50° 4′ 03.828″, E 14° 22′ 38.712″",
- 'S50 4 03.828 E14 22 38.712',
- 'S50 4 03.828, E14 22 38.712',
+ "S50 4 03.828 E14 22 38.712",
+ "S50 4 03.828, E14 22 38.712",
"50°4'3.828\"S 14°22'38.712\"E"
].each do |code|
latlon_check code, -50.06773, 14.37742
"S 50° 4' 03.828\" W 14° 22' 38.712\"",
"S 50° 4' 03.828\", W 14° 22' 38.712\"",
"S 50° 4′ 03.828″, W 14° 22′ 38.712″",
- 'S50 4 03.828 W14 22 38.712',
- 'S50 4 03.828, W14 22 38.712',
+ "S50 4 03.828 W14 22 38.712",
+ "S50 4 03.828, W14 22 38.712",
"50°4'3.828\"S 14°22'38.712\"W"
].each do |code|
latlon_check code, -50.06773, -14.37742
# Test identification of US zipcodes
def test_identify_us_postcode
[
- '12345',
- '12345-6789'
+ "12345",
+ "12345-6789"
].each do |code|
post :search, query: code
assert_response :success
# http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
def test_identify_uk_postcode
[
- 'EC1A 1BB',
- 'W1A 1HQ',
- 'M1 1AA',
- 'B33 8TH',
- 'CR2 6XH',
- 'DN55 1PT'
+ "EC1A 1BB",
+ "W1A 1HQ",
+ "M1 1AA",
+ "B33 8TH",
+ "CR2 6XH",
+ "DN55 1PT"
].each do |code|
search_check code, %w(uk_postcode osm_nominatim)
end
##
# Test identification of Canadian postcodes
def test_identify_ca_postcode
- search_check 'A1B 2C3', %w(ca_postcode osm_nominatim)
+ search_check "A1B 2C3", %w(ca_postcode osm_nominatim)
end
##
# Test identification fall through to the default case
def test_identify_default
- search_check 'foo bar baz', ['osm_nominatim']
+ search_check "foo bar baz", ["osm_nominatim"]
end
private
-require 'test_helper'
+require "test_helper"
class MessageControllerTest < ActionController::TestCase
fixtures :users, :messages
-require 'test_helper'
+require "test_helper"
class NodeControllerTest < ActionController::TestCase
api_fixtures
changeset = changesets(:normal_user_first_change)
# create a minimal xml file
content("<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>")
- assert_difference('OldNode.count', 0) do
+ assert_difference("OldNode.count", 0) do
put :create
end
# hope for unauthorized
changeset = changesets(:normal_user_first_change)
# create a minimal xml file
content("<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>")
- assert_difference('Node.count', 0) do
+ assert_difference("Node.count", 0) do
put :create
end
# hope for success
assert_require_public_data("update with changeset=0 should be forbidden, when data isn't public")
## try and submit invalid updates
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lat', 91.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lat", 91.0)
put :update, :id => current_nodes(:visible_node).id
assert_require_public_data "node at lat=91 should be forbidden, when data isn't public"
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lat', -91.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lat", -91.0)
put :update, :id => current_nodes(:visible_node).id
assert_require_public_data "node at lat=-91 should be forbidden, when data isn't public"
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lon', 181.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lon", 181.0)
put :update, :id => current_nodes(:visible_node).id
assert_require_public_data "node at lon=181 should be forbidden, when data isn't public"
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lon', -181.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lon", -181.0)
put :update, :id => current_nodes(:visible_node).id
assert_require_public_data "node at lon=-181 should be forbidden, when data isn't public"
assert_response :conflict, "update with changeset=0 should be rejected"
## try and submit invalid updates
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lat', 91.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lat", 91.0)
put :update, :id => current_nodes(:visible_node).id
assert_response :bad_request, "node at lat=91 should be rejected"
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lat', -91.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lat", -91.0)
put :update, :id => current_nodes(:visible_node).id
assert_response :bad_request, "node at lat=-91 should be rejected"
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lon', 181.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lon", 181.0)
put :update, :id => current_nodes(:visible_node).id
assert_response :bad_request, "node at lon=181 should be rejected"
- content xml_attr_rewrite(current_nodes(:visible_node).to_xml, 'lon', -181.0)
+ content xml_attr_rewrite(current_nodes(:visible_node).to_xml, "lon", -181.0)
put :update, :id => current_nodes(:visible_node).id
assert_response :bad_request, "node at lon=-181 should be rejected"
# try and submit a version behind
content xml_attr_rewrite(current_nodes(:visible_node).to_xml,
- 'version', current_node_version - 1)
+ "version", current_node_version - 1)
put :update, :id => current_nodes(:visible_node).id
assert_response :conflict, "should have failed on old version number"
# try and submit a version ahead
content xml_attr_rewrite(current_nodes(:visible_node).to_xml,
- 'version', current_node_version + 1)
+ "version", current_node_version + 1)
put :update, :id => current_nodes(:visible_node).id
assert_response :conflict, "should have failed on skipped version number"
# try and submit total crap in the version field
content xml_attr_rewrite(current_nodes(:visible_node).to_xml,
- 'version', 'p1r4t3s!')
+ "version", "p1r4t3s!")
put :update, :id => current_nodes(:visible_node).id
assert_response :conflict,
"should not be able to put 'p1r4at3s!' in the version field"
# add an identical tag to the node
tag_xml = XML::Node.new("tag")
- tag_xml['k'] = current_node_tags(:public_v_t1).k
- tag_xml['v'] = current_node_tags(:public_v_t1).v
+ tag_xml["k"] = current_node_tags(:public_v_t1).k
+ tag_xml["v"] = current_node_tags(:public_v_t1).v
# add the tag into the existing xml
node_xml = current_nodes(:public_visible_node).to_xml
# use unquoted and therefore allow code injection...
content "<osm><node lat='0' lon='0' changeset='#{changeset_id}'>" +
'<tag k="#{@user.inspect}" v="0"/>' +
- '</node></osm>'
+ "</node></osm>"
put :create
assert_require_public_data "Shouldn't be able to create with non-public user"
# use unquoted and therefore allow code injection...
content "<osm><node lat='0' lon='0' changeset='#{changeset_id}'>" +
'<tag k="#{@user.inspect}" v="0"/>' +
- '</node></osm>'
+ "</node></osm>"
put :create
assert_response :success
nodeid = @response.body
# check the tags are not corrupted
assert_equal checknode.tags, apinode.tags
- assert apinode.tags.include?('#{@user.inspect}')
+ assert apinode.tags.include?("\#{@user.inspect}")
end
def basic_authorization(user, pass)
##
# update the changeset_id of a node element
def update_changeset(xml, changeset_id)
- xml_attr_rewrite(xml, 'changeset', changeset_id)
+ xml_attr_rewrite(xml, "changeset", changeset_id)
end
##
-require 'test_helper'
+require "test_helper"
class NotesControllerTest < ActionController::TestCase
fixtures :users, :notes, :note_comments
end
def test_create_success
- assert_difference('Note.count') do
- assert_difference('NoteComment.count') do
+ assert_difference("Note.count") do
+ assert_difference("NoteComment.count") do
post :create, :lat => -1.0, :lon => -1.0, :text => "This is a comment", :format => "json"
end
end
end
def test_create_fail
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
post :create, :lon => -1.0, :text => "This is a comment"
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
post :create, :lat => -1.0, :text => "This is a comment"
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
post :create, :lat => -1.0, :lon => -1.0
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
post :create, :lat => -1.0, :lon => -1.0, :text => ""
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
post :create, :lat => -100.0, :lon => -1.0, :text => "This is a comment"
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
post :create, :lat => -1.0, :lon => -200.0, :text => "This is a comment"
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
- post :create, :lat => 'abc', :lon => -1.0, :text => "This is a comment"
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
+ post :create, :lat => "abc", :lon => -1.0, :text => "This is a comment"
end
end
assert_response :bad_request
- assert_no_difference('Note.count') do
- assert_no_difference('NoteComment.count') do
- post :create, :lat => -1.0, :lon => 'abc', :text => "This is a comment"
+ assert_no_difference("Note.count") do
+ assert_no_difference("NoteComment.count") do
+ post :create, :lat => -1.0, :lon => "abc", :text => "This is a comment"
end
end
assert_response :bad_request
end
def test_comment_success
- assert_difference('NoteComment.count') do
+ assert_difference("NoteComment.count") do
post :comment, :id => notes(:open_note_with_comment).id, :text => "This is an additional comment", :format => "json"
end
assert_response :success
end
def test_comment_fail
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("NoteComment.count") do
post :comment, :text => "This is an additional comment"
end
assert_response :bad_request
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("NoteComment.count") do
post :comment, :id => notes(:open_note_with_comment).id
end
assert_response :bad_request
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("NoteComment.count") do
post :comment, :id => notes(:open_note_with_comment).id, :text => ""
end
assert_response :bad_request
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("NoteComment.count") do
post :comment, :id => 12345, :text => "This is an additional comment"
end
assert_response :not_found
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("NoteComment.count") do
post :comment, :id => notes(:hidden_note_with_comment).id, :text => "This is an additional comment"
end
assert_response :gone
- assert_no_difference('NoteComment.count') do
+ assert_no_difference("NoteComment.count") do
post :comment, :id => notes(:closed_note_with_comment).id, :text => "This is an additional comment"
end
assert_response :conflict
assert_equal "This is a hide comment", js["properties"]["comments"].last["text"]
assert_equal "moderator", js["properties"]["comments"].last["user"]
- get :show, :id => notes(:open_note_with_comment).id, :format => 'json'
+ get :show, :id => notes(:open_note_with_comment).id, :format => "json"
assert_response :gone
end
end
def test_index_success
- get :index, :bbox => '1,1,1.2,1.2', :format => 'rss'
+ get :index, :bbox => "1,1,1.2,1.2", :format => "rss"
assert_response :success
assert_equal "application/rss+xml", @response.content_type
assert_select "rss", :count => 1 do
end
end
- get :index, :bbox => '1,1,1.2,1.2', :format => 'json'
+ get :index, :bbox => "1,1,1.2,1.2", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal "FeatureCollection", js["type"]
assert_equal 2, js["features"].count
- get :index, :bbox => '1,1,1.2,1.2', :format => 'xml'
+ get :index, :bbox => "1,1,1.2,1.2", :format => "xml"
assert_response :success
assert_equal "application/xml", @response.content_type
assert_select "osm", :count => 1 do
assert_select "note", :count => 2
end
- get :index, :bbox => '1,1,1.2,1.2', :format => 'gpx'
+ get :index, :bbox => "1,1,1.2,1.2", :format => "gpx"
assert_response :success
assert_equal "application/gpx+xml", @response.content_type
assert_select "gpx", :count => 1 do
end
def test_index_empty_area
- get :index, :bbox => '5,5,5.1,5.1', :format => 'rss'
+ get :index, :bbox => "5,5,5.1,5.1", :format => "rss"
assert_response :success
assert_equal "application/rss+xml", @response.content_type
assert_select "rss", :count => 1 do
end
end
- get :index, :bbox => '5,5,5.1,5.1', :format => 'json'
+ get :index, :bbox => "5,5,5.1,5.1", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal "FeatureCollection", js["type"]
assert_equal 0, js["features"].count
- get :index, :bbox => '5,5,5.1,5.1', :format => 'xml'
+ get :index, :bbox => "5,5,5.1,5.1", :format => "xml"
assert_response :success
assert_equal "application/xml", @response.content_type
assert_select "osm", :count => 1 do
assert_select "note", :count => 0
end
- get :index, :bbox => '5,5,5.1,5.1', :format => 'gpx'
+ get :index, :bbox => "5,5,5.1,5.1", :format => "gpx"
assert_response :success
assert_equal "application/gpx+xml", @response.content_type
assert_select "gpx", :count => 1 do
end
def test_index_large_area
- get :index, :bbox => '-2.5,-2.5,2.5,2.5', :format => :json
+ get :index, :bbox => "-2.5,-2.5,2.5,2.5", :format => :json
assert_response :success
assert_equal "application/json", @response.content_type
- get :index, :l => '-2.5', :b => '-2.5', :r => '2.5', :t => '2.5', :format => :json
+ get :index, :l => "-2.5", :b => "-2.5", :r => "2.5", :t => "2.5", :format => :json
assert_response :success
assert_equal "application/json", @response.content_type
- get :index, :bbox => '-10,-10,12,12', :format => :json
+ get :index, :bbox => "-10,-10,12,12", :format => :json
assert_response :bad_request
assert_equal "text/plain", @response.content_type
- get :index, :l => '-10', :b => '-10', :r => '12', :t => '12', :format => :json
+ get :index, :l => "-10", :b => "-10", :r => "12", :t => "12", :format => :json
assert_response :bad_request
assert_equal "text/plain", @response.content_type
end
def test_index_closed
- get :index, :bbox => '1,1,1.7,1.7', :closed => '7', :format => 'json'
+ get :index, :bbox => "1,1,1.7,1.7", :closed => "7", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal "FeatureCollection", js["type"]
assert_equal 4, js["features"].count
- get :index, :bbox => '1,1,1.7,1.7', :closed => '0', :format => 'json'
+ get :index, :bbox => "1,1,1.7,1.7", :closed => "0", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal "FeatureCollection", js["type"]
assert_equal 4, js["features"].count
- get :index, :bbox => '1,1,1.7,1.7', :closed => '-1', :format => 'json'
+ get :index, :bbox => "1,1,1.7,1.7", :closed => "-1", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
end
def test_index_bad_params
- get :index, :bbox => '-2.5,-2.5,2.5'
+ get :index, :bbox => "-2.5,-2.5,2.5"
assert_response :bad_request
- get :index, :bbox => '-2.5,-2.5,2.5,2.5,2.5'
+ get :index, :bbox => "-2.5,-2.5,2.5,2.5,2.5"
assert_response :bad_request
- get :index, :b => '-2.5', :r => '2.5', :t => '2.5'
+ get :index, :b => "-2.5", :r => "2.5", :t => "2.5"
assert_response :bad_request
- get :index, :l => '-2.5', :r => '2.5', :t => '2.5'
+ get :index, :l => "-2.5", :r => "2.5", :t => "2.5"
assert_response :bad_request
- get :index, :l => '-2.5', :b => '-2.5', :t => '2.5'
+ get :index, :l => "-2.5", :b => "-2.5", :t => "2.5"
assert_response :bad_request
- get :index, :l => '-2.5', :b => '-2.5', :r => '2.5'
+ get :index, :l => "-2.5", :b => "-2.5", :r => "2.5"
assert_response :bad_request
- get :index, :bbox => '1,1,1.7,1.7', :limit => '0', :format => 'json'
+ get :index, :bbox => "1,1,1.7,1.7", :limit => "0", :format => "json"
assert_response :bad_request
- get :index, :bbox => '1,1,1.7,1.7', :limit => '10001', :format => 'json'
+ get :index, :bbox => "1,1,1.7,1.7", :limit => "10001", :format => "json"
assert_response :bad_request
end
def test_search_success
- get :search, :q => 'note 1', :format => 'xml'
+ get :search, :q => "note 1", :format => "xml"
assert_response :success
assert_equal "application/xml", @response.content_type
assert_select "osm", :count => 1 do
assert_select "note", :count => 1
end
- get :search, :q => 'note 1', :format => 'json'
+ get :search, :q => "note 1", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal "FeatureCollection", js["type"]
assert_equal 1, js["features"].count
- get :search, :q => 'note 1', :format => 'rss'
+ get :search, :q => "note 1", :format => "rss"
assert_response :success
assert_equal "application/rss+xml", @response.content_type
assert_select "rss", :count => 1 do
end
end
- get :search, :q => 'note 1', :format => 'gpx'
+ get :search, :q => "note 1", :format => "gpx"
assert_response :success
assert_equal "application/gpx+xml", @response.content_type
assert_select "gpx", :count => 1 do
end
def test_search_no_match
- get :search, :q => 'no match', :format => 'xml'
+ get :search, :q => "no match", :format => "xml"
assert_response :success
assert_equal "application/xml", @response.content_type
assert_select "osm", :count => 1 do
assert_select "note", :count => 0
end
- get :search, :q => 'no match', :format => 'json'
+ get :search, :q => "no match", :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal "FeatureCollection", js["type"]
assert_equal 0, js["features"].count
- get :search, :q => 'no match', :format => 'rss'
+ get :search, :q => "no match", :format => "rss"
assert_response :success
assert_equal "application/rss+xml", @response.content_type
assert_select "rss", :count => 1 do
end
end
- get :search, :q => 'no match', :format => 'gpx'
+ get :search, :q => "no match", :format => "gpx"
assert_response :success
assert_equal "application/gpx+xml", @response.content_type
assert_select "gpx", :count => 1 do
get :search
assert_response :bad_request
- get :search, :q => 'no match', :limit => '0', :format => 'json'
+ get :search, :q => "no match", :limit => "0", :format => "json"
assert_response :bad_request
- get :search, :q => 'no match', :limit => '10001', :format => 'json'
+ get :search, :q => "no match", :limit => "10001", :format => "json"
assert_response :bad_request
end
get :feed, :bbox => "1,1,1.2,1.2,1.2", :format => "rss"
assert_response :bad_request
- get :feed, :bbox => "1,1,1.2,1.2", :limit => '0', :format => "rss"
+ get :feed, :bbox => "1,1,1.2,1.2", :limit => "0", :format => "rss"
assert_response :bad_request
- get :feed, :bbox => "1,1,1.2,1.2", :limit => '10001', :format => "rss"
+ get :feed, :bbox => "1,1,1.2,1.2", :limit => "10001", :format => "rss"
assert_response :bad_request
end
-require 'test_helper'
+require "test_helper"
class OauthClientsControllerTest < ActionController::TestCase
fixtures :users, :client_applications
-require 'test_helper'
+require "test_helper"
class OauthControllerTest < ActionController::TestCase
##
-require 'test_helper'
-require 'old_node_controller'
+require "test_helper"
+require "old_node_controller"
class OldNodeControllerTest < ActionController::TestCase
api_fixtures
versions = {}
# save a version for later checking
- versions[xml_node['version']] = xml_doc.to_s
+ versions[xml_node["version"]] = xml_doc.to_s
# randomly move the node about
20.times do
# move the node somewhere else
- xml_node['lat'] = precision(rand * 180 - 90).to_s
- xml_node['lon'] = precision(rand * 360 - 180).to_s
+ xml_node["lat"] = precision(rand * 180 - 90).to_s
+ xml_node["lon"] = precision(rand * 360 - 180).to_s
with_controller(NodeController.new) do
content xml_doc
put :update, :id => nodeid
assert_response :forbidden, "Should have rejected node update"
- xml_node['version'] = @response.body.to_s
+ xml_node["version"] = @response.body.to_s
end
# save a version for later checking
- versions[xml_node['version']] = xml_doc.to_s
+ versions[xml_node["version"]] = xml_doc.to_s
end
# add a bunch of random tags
30.times do
xml_tag = XML::Node.new("tag")
- xml_tag['k'] = random_string
- xml_tag['v'] = random_string
+ xml_tag["k"] = random_string
+ xml_tag["v"] = random_string
xml_node << xml_tag
with_controller(NodeController.new) do
content xml_doc
put :update, :id => nodeid
assert_response :forbidden,
"should have rejected node #{nodeid} (#{@response.body}) with forbidden"
- xml_node['version'] = @response.body.to_s
+ xml_node["version"] = @response.body.to_s
end
# save a version for later checking
- versions[xml_node['version']] = xml_doc.to_s
+ versions[xml_node["version"]] = xml_doc.to_s
end
# probably should check that they didn't get written to the database
versions = {}
# save a version for later checking
- versions[xml_node['version']] = xml_doc.to_s
+ versions[xml_node["version"]] = xml_doc.to_s
# randomly move the node about
20.times do
# move the node somewhere else
- xml_node['lat'] = precision(rand * 180 - 90).to_s
- xml_node['lon'] = precision(rand * 360 - 180).to_s
+ xml_node["lat"] = precision(rand * 180 - 90).to_s
+ xml_node["lon"] = precision(rand * 360 - 180).to_s
with_controller(NodeController.new) do
content xml_doc
put :update, :id => nodeid
assert_response :success
- xml_node['version'] = @response.body.to_s
+ xml_node["version"] = @response.body.to_s
end
# save a version for later checking
- versions[xml_node['version']] = xml_doc.to_s
+ versions[xml_node["version"]] = xml_doc.to_s
end
# add a bunch of random tags
30.times do
xml_tag = XML::Node.new("tag")
- xml_tag['k'] = random_string
- xml_tag['v'] = random_string
+ xml_tag["k"] = random_string
+ xml_tag["v"] = random_string
xml_node << xml_tag
with_controller(NodeController.new) do
content xml_doc
put :update, :id => nodeid
assert_response :success,
"couldn't update node #{nodeid} (#{@response.body})"
- xml_node['version'] = @response.body.to_s
+ xml_node["version"] = @response.body.to_s
end
# save a version for later checking
- versions[xml_node['version']] = xml_doc.to_s
+ versions[xml_node["version"]] = xml_doc.to_s
end
# check all the versions
# the appropriate flag
get :version, :id => node.node_id, :version => node.version
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
- get :version, :id => node.node_id, :version => node.version, :show_redactions => 'true'
+ get :version, :id => node.node_id, :version => node.version, :show_redactions => "true"
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history
get :history, :id => node.node_id
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node.node_id}'][version='#{node.version}']", 0, "node #{node.node_id} version #{node.version} should not be present in the history for moderators when not passing flag."
- get :history, :id => node.node_id, :show_redactions => 'true'
+ get :history, :id => node.node_id, :show_redactions => "true"
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node.node_id}'][version='#{node.version}']", 1, "node #{node.node_id} version #{node.version} should still be present in the history for moderators when passing flag."
end
# returns a 16 character long string with some nasty characters in it.
# this ought to stress-test the tag handling as well as the versioning.
def random_string
- letters = [['!', '"', '$', '&', ';', '@'],
- ('a'..'z').to_a,
- ('A'..'Z').to_a,
- ('0'..'9').to_a].flatten
+ letters = [["!", '"', "$", "&", ";", "@"],
+ ("a".."z").to_a,
+ ("A".."Z").to_a,
+ ("0".."9").to_a].flatten
(1..16).map { |_i| letters[rand(letters.length)] }.join
end
-require 'test_helper'
-require 'old_relation_controller'
+require "test_helper"
+require "old_relation_controller"
class OldRelationControllerTest < ActionController::TestCase
api_fixtures
# the appropriate flag
get :version, :id => relation.relation_id, :version => relation.version
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
- get :version, :id => relation.relation_id, :version => relation.version, :show_redactions => 'true'
+ get :version, :id => relation.relation_id, :version => relation.version, :show_redactions => "true"
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history
get :history, :id => relation.relation_id
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation.relation_id}'][version='#{relation.version}']", 0, "relation #{relation.relation_id} version #{relation.version} should not be present in the history for moderators when not passing flag."
- get :history, :id => relation.relation_id, :show_redactions => 'true'
+ get :history, :id => relation.relation_id, :show_redactions => "true"
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation.relation_id}'][version='#{relation.version}']", 1, "relation #{relation.relation_id} version #{relation.version} should still be present in the history for moderators when passing flag."
end
-require 'test_helper'
-require 'old_way_controller'
+require "test_helper"
+require "old_way_controller"
class OldWayControllerTest < ActionController::TestCase
api_fixtures
# the appropriate flag
get :version, :id => way.way_id, :version => way.version
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
- get :version, :id => way.way_id, :version => way.version, :show_redactions => 'true'
+ get :version, :id => way.way_id, :version => way.version, :show_redactions => "true"
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history
get :history, :id => way.way_id
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way.way_id}'][version='#{way.version}']", 0, "way #{way.way_id} version #{way.version} should not be present in the history for moderators when not passing flag."
- get :history, :id => way.way_id, :show_redactions => 'true'
+ get :history, :id => way.way_id, :show_redactions => "true"
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way.way_id}'][version='#{way.version}']", 1, "way #{way.way_id} version #{way.version} should still be present in the history for moderators when passing flag."
end
-require 'test_helper'
-require 'redactions_controller'
+require "test_helper"
+require "redactions_controller"
class RedactionsControllerTest < ActionController::TestCase
api_fixtures
-require 'test_helper'
-require 'relation_controller'
+require "test_helper"
+require "relation_controller"
class RelationControllerTest < ActionController::TestCase
api_fixtures
with_relation(rel_id) do |rel|
# alter one of the tags
tag = rel.find("//osm/relation/tag").first
- tag['v'] = 'some changed value'
+ tag["v"] = "some changed value"
update_changeset(rel, cs_id)
# check that the downloaded tags are the same as the uploaded tags...
with_relation(rel_id) do |rel|
# alter one of the tags
tag = rel.find("//osm/relation/tag").first
- tag['v'] = 'some changed value'
+ tag["v"] = "some changed value"
update_changeset(rel, cs_id)
# check that the downloaded tags are the same as the uploaded tags...
relation_xml = current_relations(:visible_relation).to_xml
relation_element = relation_xml.find("//osm/relation").first
new_tag = XML::Node.new("tag")
- new_tag['k'] = "some_new_tag"
- new_tag['v'] = "some_new_value"
+ new_tag["k"] = "some_new_tag"
+ new_tag["v"] = "some_new_value"
relation_element << new_tag
# update changeset ID to point to new changeset
relation_xml = Relation.find(relation_id).to_xml
relation_element = relation_xml.find("//osm/relation").first
new_member = XML::Node.new("member")
- new_member['ref'] = element.id.to_s
- new_member['type'] = element.class.to_s.downcase
- new_member['role'] = "some_role"
+ new_member["ref"] = element.id.to_s
+ new_member["type"] = element.class.to_s.downcase
+ new_member["role"] = "some_role"
relation_element << new_member
# update changeset ID to point to new changeset
# insert a member at the front
new_member = XML::Node.new "member"
- new_member['ref'] = 5.to_s
- new_member['type'] = 'node'
- new_member['role'] = 'new first'
+ new_member["ref"] = 5.to_s
+ new_member["type"] = "node"
+ new_member["role"] = "new first"
doc.find("//osm/relation").first.child.prev = new_member
# update the version, should be 1?
- doc.find("//osm/relation").first['id'] = relation_id.to_s
- doc.find("//osm/relation").first['version'] = 1.to_s
+ doc.find("//osm/relation").first["id"] = relation_id.to_s
+ doc.find("//osm/relation").first["version"] = 1.to_s
# upload the next version of the relation
content doc
new_doc = XML::Parser.string(xml).parse
doc_members = doc.find("//osm/relation/member").collect do |m|
- [m['ref'].to_i, m['type'].to_sym, m['role']]
+ [m["ref"].to_i, m["type"].to_sym, m["role"]]
end
new_members = new_doc.find("//osm/relation/member").collect do |m|
- [m['ref'].to_i, m['type'].to_sym, m['role']]
+ [m["ref"].to_i, m["type"].to_sym, m["role"]]
end
doc_members.zip(new_members).each do |d, n|
# the parsed XML doc is retured.
def with_update_diff(rel)
rel_id = rel.find("//osm/relation").first["id"].to_i
- cs_id = rel.find("//osm/relation").first['changeset'].to_i
+ cs_id = rel.find("//osm/relation").first["changeset"].to_i
version = nil
with_controller(ChangesetController.new) do
doc = OSM::API.new.get_xml_doc
- change = XML::Node.new 'osmChange'
+ change = XML::Node.new "osmChange"
doc.root = change
- modify = XML::Node.new 'modify'
+ modify = XML::Node.new "modify"
change << modify
modify << doc.import(rel.find("//osm/relation").first)
##
# returns a k->v hash of tags from an xml doc
def get_tags_as_hash(a)
- a.find("//osm/relation/tag").sort_by { |v| v['k'] }.each_with_object({}) do |v, h|
- h[v['k']] = v['v']
+ a.find("//osm/relation/tag").sort_by { |v| v["k"] }.each_with_object({}) do |v, h|
+ h[v["k"]] = v["v"]
end
end
##
# update the changeset_id of a node element
def update_changeset(xml, changeset_id)
- xml_attr_rewrite(xml, 'changeset', changeset_id)
+ xml_attr_rewrite(xml, "changeset", changeset_id)
end
##
-require 'test_helper'
+require "test_helper"
class SearchControllerTest < ActionController::TestCase
##
-require 'test_helper'
+require "test_helper"
class SiteControllerTest < ActionController::TestCase
api_fixtures
def test_index
get :index
assert_response :success
- assert_template 'index'
+ assert_template "index"
end
# Test the index page redirects
def test_index_redirect
get :index, :lat => 4, :lon => 5
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=5/4/5'
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
get :index, :lat => 4, :lon => 5, :zoom => 3
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4/5'
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
- get :index, :layers => 'T'
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'layers=T'
+ get :index, :layers => "T"
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
- get :index, :notes => 'yes'
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'layers=N'
+ get :index, :notes => "yes"
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
- get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4/5&layers=T'
+ get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => "T"
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
end
# Test the permalink redirect
def test_permalink
- get :permalink, :code => 'wBz3--'
+ get :permalink, :code => "wBz3--"
assert_response :redirect
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4.8779296875/3.955078125'
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :code => 'wBz3--', :m => ''
+ get :permalink, :code => "wBz3--", :m => ""
assert_response :redirect
- assert_redirected_to :controller => :site, :action => :index, :mlat => '4.8779296875', :mlon => '3.955078125', :anchor => 'map=3/4.8779296875/3.955078125'
+ assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :code => 'wBz3--', :layers => 'T'
+ get :permalink, :code => "wBz3--", :layers => "T"
assert_response :redirect
- assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4.8779296875/3.955078125&layers=T'
+ assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
- get :permalink, :code => 'wBz3--', :node => 1
+ get :permalink, :code => "wBz3--", :node => 1
assert_response :redirect
- assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => 'map=3/4.8779296875/3.955078125'
+ assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :code => 'wBz3--', :way => 2
+ get :permalink, :code => "wBz3--", :way => 2
assert_response :redirect
- assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => 'map=3/4.8779296875/3.955078125'
+ assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :code => 'wBz3--', :relation => 3
+ get :permalink, :code => "wBz3--", :relation => 3
assert_response :redirect
- assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => 'map=3/4.8779296875/3.955078125'
+ assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :code => 'wBz3--', :changeset => 4
+ get :permalink, :code => "wBz3--", :changeset => 4
assert_response :redirect
- assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => 'map=3/4.8779296875/3.955078125'
+ assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
end
# Test the key page
# Test the edit page redirects
def test_edit_redirect
get :edit, :lat => 4, :lon => 5
- assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=5/4/5'
+ assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
get :edit, :lat => 4, :lon => 5, :zoom => 3
- assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=3/4/5'
+ assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
- get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => 'id'
- assert_redirected_to :controller => :site, :action => :edit, :editor => 'id', :anchor => 'map=3/4/5'
+ get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => "id"
+ assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
end
# Test the copyright page
-require 'test_helper'
+require "test_helper"
class SwfControllerTest < ActionController::TestCase
##
-require 'test_helper'
+require "test_helper"
class TraceControllerTest < ActionController::TestCase
fixtures :users, :gpx_files
def test_list_mine
# First try to get it when not logged in
get :mine
- assert_redirected_to :controller => 'user', :action => 'login', :referer => '/traces/mine'
+ assert_redirected_to :controller => "user", :action => "login", :referer => "/traces/mine"
# Now try when logged in
get :mine, {}, { :user => users(:public_user).id }
- assert_redirected_to :controller => 'trace', :action => 'list', :display_name => users(:public_user).display_name
+ assert_redirected_to :controller => "trace", :action => "list", :display_name => users(:public_user).display_name
# Fetch the actual list
get :list, { :display_name => users(:public_user).display_name }, { :user => users(:public_user).id }
-require 'test_helper'
+require "test_helper"
class UserBlocksControllerTest < ActionController::TestCase
fixtures :users, :user_roles, :user_blocks
-require 'test_helper'
+require "test_helper"
class UserControllerTest < ActionController::TestCase
fixtures :users
def test_user_create_success
user = new_user
- assert_difference('User.count', 1) do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("User.count", 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :save, {}, { :new_user => user }
end
end
assert_match /#{@url}/, register_email.body.to_s
# Check the page
- assert_redirected_to :action => 'confirm', :display_name => user.display_name
+ assert_redirected_to :action => "confirm", :display_name => user.display_name
ActionMailer::Base.deliveries.clear
end
user = new_user
user.email = users(:public_user).email
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
end
user = new_user
user.email = users(:public_user).email.upcase
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
end
user = new_user
user.display_name = users(:public_user).display_name
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
end
user = new_user
user.display_name = users(:public_user).display_name.upcase
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
end
def test_user_save_referer_params
user = new_user
- assert_difference('User.count', 1) do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("User.count", 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :save, {}, { :new_user => user,
- :referer => '/edit?editor=id#map=1/2/3' }
+ :referer => "/edit?editor=id#map=1/2/3" }
end
end
- assert_equal welcome_path(:editor => 'id', :zoom => 1, :lat => 2, :lon => 3),
+ assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
user.tokens.order("id DESC").first.referer
ActionMailer::Base.deliveries.clear
@request.cookies["_osm_session"] = user.display_name
post :confirm, :confirm_string => token.token
- assert_redirected_to :action => 'confirm'
+ assert_redirected_to :action => "confirm"
assert_match /expired/, flash[:error]
end
@request.cookies["_osm_session"] = user.display_name
post :confirm, :confirm_string => token.token
- assert_redirected_to :action => 'login'
+ assert_redirected_to :action => "login"
assert_match /confirmed/, flash[:error]
end
# Test resetting using the address as recorded for a user that has an
# address which is duplicated in a different case by another user
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:normal_user).email }
end
assert_response :redirect
# Test resetting using an address that matches a different user
# that has the same address in a different case
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:normal_user).email.upcase }
end
assert_response :redirect
# Test resetting using an address that is a case insensitive match
# for more than one user but not an exact match for either
- assert_difference('ActionMailer::Base.deliveries.size', 0) do
+ assert_difference("ActionMailer::Base.deliveries.size", 0) do
post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
end
assert_response :success
# Test resetting using the address as recorded for a user that has an
# address which is case insensitively unique
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:public_user).email }
end
assert_response :redirect
# Test resetting using an address that matches a user that has the
# same (case insensitively unique) address in a different case
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:public_user).email.upcase }
end
assert_response :redirect
# Changing email to one that exists should fail
user.new_email = users(:public_user).email
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
end
assert_response :success
# Changing email to one that exists should fail, regardless of case
user.new_email = users(:public_user).email.upcase
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
end
assert_response :success
# Changing email to one that doesn't exist should work
user.new_email = "new_tester@example.com"
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
end
assert_response :success
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When logged in a POST should add the friendship
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :make_friend, { :display_name => friend.display_name }, { "user" => user }
end
assert_redirected_to user_path(:display_name => friend.display_name)
ActionMailer::Base.deliveries.clear
# A second POST should report that the friendship already exists
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :make_friend, { :display_name => friend.display_name }, { "user" => user }
end
assert_redirected_to user_path(:display_name => friend.display_name)
-require 'test_helper'
+require "test_helper"
class UserPreferenceControllerTest < ActionController::TestCase
fixtures :users, :user_preferences
-require 'test_helper'
+require "test_helper"
class UserRolesControllerTest < ActionController::TestCase
fixtures :users, :user_roles
-require 'test_helper'
-require 'way_controller'
+require "test_helper"
+require "way_controller"
class WayControllerTest < ActionController::TestCase
api_fixtures
# add an identical tag to the way
tag_xml = XML::Node.new("tag")
- tag_xml['k'] = current_way_tags(:t1).k
- tag_xml['v'] = current_way_tags(:t1).v
+ tag_xml["k"] = current_way_tags(:t1).k
+ tag_xml["v"] = current_way_tags(:t1).v
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
# add an identical tag to the way
tag_xml = XML::Node.new("tag")
- tag_xml['k'] = current_way_tags(:t1).k
- tag_xml['v'] = current_way_tags(:t1).v
+ tag_xml["k"] = current_way_tags(:t1).k
+ tag_xml["v"] = current_way_tags(:t1).v
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
# create duplicate tag
tag_xml = XML::Node.new("tag")
- tag_xml['k'] = "i_am_a_duplicate"
- tag_xml['v'] = "foobar"
+ tag_xml["k"] = "i_am_a_duplicate"
+ tag_xml["v"] = "foobar"
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
# create duplicate tag
tag_xml = XML::Node.new("tag")
- tag_xml['k'] = "i_am_a_duplicate"
- tag_xml['v'] = "foobar"
+ tag_xml["k"] = "i_am_a_duplicate"
+ tag_xml["v"] = "foobar"
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
##
# update the changeset_id of a node element
def update_changeset(xml, changeset_id)
- xml_attr_rewrite(xml, 'changeset', changeset_id)
+ xml_attr_rewrite(xml, "changeset", changeset_id)
end
##
-require 'test_helper'
+require "test_helper"
class ApplicationHelperTest < ActionView::TestCase
fixtures :users, :user_roles
-require 'test_helper'
+require "test_helper"
class AssetHelperTest < ActionView::TestCase
def test_assets
# -*- coding: utf-8 -*-
-require 'test_helper'
+require "test_helper"
class BrowseHelperTest < ActionView::TestCase
include ERB::Util
-require 'test_helper'
+require "test_helper"
class ChangesetHelperTest < ActionView::TestCase
fixtures :changesets, :users
-require 'test_helper'
+require "test_helper"
class NoteHelperTest < ActionView::TestCase
include ERB::Util
-require 'test_helper'
+require "test_helper"
class TitleHelperTest < ActionView::TestCase
def test_set_title
-require 'test_helper'
+require "test_helper"
class ClientApplicationTest < ActionDispatch::IntegrationTest
fixtures :users, :client_applications
# run through the procedure of creating a client application and checking
# that it shows up on the user's account page.
def test_create_application
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => "test@example.com", 'password' => "test", :referer => '/user/test2'
+ post "/login", "username" => "test@example.com", "password" => "test", :referer => "/user/test2"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'user/view'
- get '/user/test2/account'
+ assert_template "user/view"
+ get "/user/test2/account"
assert_response :success
- assert_template 'user/account'
+ assert_template "user/account"
# check that the form to allow new client application creations exists
assert_in_heading do
end
# now we follow the link to the oauth client list
- get '/user/test2/oauth_clients'
+ get "/user/test2/oauth_clients"
assert_response :success
assert_in_body do
assert_select "a[href='/user/test2/oauth_clients/new']"
end
# now we follow the link to the new oauth client page
- get '/user/test2/oauth_clients/new'
+ get "/user/test2/oauth_clients/new"
assert_response :success
assert_in_heading do
assert_select "h1", "Register a new application"
end
end
- post '/user/test2/oauth_clients', 'client_application[name]' => 'My New App',
- 'client_application[url]' => 'http://my.new.app.org/',
- 'client_application[callback_url]' => 'http://my.new.app.org/callback',
- 'client_application[support_url]' => 'http://my.new.app.org/support'
+ post "/user/test2/oauth_clients", "client_application[name]" => "My New App",
+ "client_application[url]" => "http://my.new.app.org/",
+ "client_application[callback_url]" => "http://my.new.app.org/callback",
+ "client_application[support_url]" => "http://my.new.app.org/support"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'oauth_clients/show'
- assert_equal 'Registered the information successfully', flash[:notice]
+ assert_template "oauth_clients/show"
+ assert_equal "Registered the information successfully", flash[:notice]
# now go back to the account page and check its listed under this user
- get '/user/test2/oauth_clients'
+ get "/user/test2/oauth_clients"
assert_response :success
- assert_template 'oauth_clients/index'
+ assert_template "oauth_clients/index"
assert_in_body { assert_select "div>a", "My New App" }
end
-require 'test_helper'
+require "test_helper"
class CORSTest < ActionDispatch::IntegrationTest
# Rails 4 adds a built-in `options` method. When we upgrade, we can remove
def test_api_routes_allow_cross_origin_requests
options "/api/capabilities", nil,
- 'HTTP_ORIGIN' => "http://www.example.com",
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'GET'
+ "HTTP_ORIGIN" => "http://www.example.com",
+ "HTTP_ACCESS_CONTROL_REQUEST_METHOD" => "GET"
assert_response :success
- assert_equal "http://www.example.com", response.headers['Access-Control-Allow-Origin']
+ assert_equal "http://www.example.com", response.headers["Access-Control-Allow-Origin"]
end
def test_non_api_routes_dont_allow_cross_origin_requests
assert_raises ActionController::RoutingError do
options "/", nil,
- 'HTTP_ORIGIN' => "http://www.example.com",
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'GET'
+ "HTTP_ORIGIN" => "http://www.example.com",
+ "HTTP_ACCESS_CONTROL_REQUEST_METHOD" => "GET"
end
end
end
-require 'test_helper'
+require "test_helper"
class OAuthTest < ActionDispatch::IntegrationTest
fixtures :users, :client_applications, :gpx_files
-require 'test_helper'
+require "test_helper"
class RedirectTest < ActionDispatch::IntegrationTest
def test_legacy_redirects
-require 'test_helper'
+require "test_helper"
class ShortLinksTest < ActionDispatch::IntegrationTest
##
# test the short link with various parameters and ensure they're
# kept in the redirect.
def test_short_link_params
- assert_short_link_redirect('1N8H@P_5W')
+ assert_short_link_redirect("1N8H@P_5W")
assert_short_link_redirect(ShortLink.encode(-0.107846, 51.50771, 18))
end
anchor = "map=#{zoom}/#{lat}/#{lon}"
# test without marker
- get '/go/' + short_link
- assert_redirected_to :controller => 'site', :action => 'index', :anchor => anchor
+ get "/go/" + short_link
+ assert_redirected_to :controller => "site", :action => "index", :anchor => anchor
# test with marker
- get '/go/' + short_link + "?m"
- assert_redirected_to :controller => 'site', :action => 'index', :mlat => lat.to_s, :mlon => lon.to_s, :anchor => anchor
+ get "/go/" + short_link + "?m"
+ assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => anchor
# test with layers and a marker
- get '/go/' + short_link + "?m&layers=B000FTF"
- assert_redirected_to :controller => 'site', :action => 'index', :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
- get '/go/' + short_link + "?layers=B000FTF&m"
- assert_redirected_to :controller => 'site', :action => 'index', :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
+ get "/go/" + short_link + "?m&layers=B000FTF"
+ assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
+ get "/go/" + short_link + "?layers=B000FTF&m"
+ assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
# test with some random query parameters we haven't even implemented yet
- get '/go/' + short_link + "?foobar=yes"
- assert_redirected_to :controller => 'site', :action => 'index', :foobar => "yes", :anchor => anchor
+ get "/go/" + short_link + "?foobar=yes"
+ assert_redirected_to :controller => "site", :action => "index", :foobar => "yes", :anchor => anchor
end
end
-require 'test_helper'
+require "test_helper"
class UserBlocksTest < ActionDispatch::IntegrationTest
fixtures :users, :user_blocks, :user_roles
assert_response :forbidden
# revoke the ban
- get '/login'
+ get "/login"
assert_response :success
- post '/login', 'username' => moderator.email, 'password' => "test", :referer => "/blocks/#{block.id}/revoke"
+ post "/login", "username" => moderator.email, "password" => "test", :referer => "/blocks/#{block.id}/revoke"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'user_blocks/revoke'
- post "/blocks/#{block.id}/revoke", 'confirm' => "yes"
+ assert_template "user_blocks/revoke"
+ post "/blocks/#{block.id}/revoke", "confirm" => "yes"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'user_blocks/show'
+ assert_template "user_blocks/show"
reset!
# access the API again. this time it should work
-require 'test_helper'
+require "test_helper"
class UserChangesetCommentsTest < ActionDispatch::IntegrationTest
fixtures :users, :changesets, :changeset_comments
# Test if the form is shown
def test_displaying_form
- get_via_redirect '/login'
+ get_via_redirect "/login"
# We should now be at the login page
assert_response :success
- assert_template 'user/login'
+ assert_template "user/login"
# We can now login
- post '/login', 'username' => "test@openstreetmap.org", 'password' => "test"
+ post "/login", "username" => "test@openstreetmap.org", "password" => "test"
assert_response :redirect
get "/changeset/#{changesets(:normal_user_closed_change).id}"
assert_response :success
- assert_template 'browse/changeset'
+ assert_template "browse/changeset"
assert_select "div#content" do
assert_select "div#sidebar" do
-require 'test_helper'
+require "test_helper"
class UserCreationTest < ActionDispatch::IntegrationTest
fixtures :users
def test_create_user_form
I18n.available_locales.each do |locale|
- get_via_redirect '/user/new', {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
+ get_via_redirect "/user/new", {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
assert_response :success
- assert_template 'user/new'
+ assert_template "user/new"
end
end
I18n.available_locales.each do |locale|
dup_email = users(:public_user).email
display_name = "#{locale}_new_tester"
- assert_difference('User.count', 0) do
- assert_difference('ActionMailer::Base.deliveries.size', 0) do
- post '/user/new',
+ assert_difference("User.count", 0) do
+ assert_difference("ActionMailer::Base.deliveries.size", 0) do
+ post "/user/new",
{ :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
{ "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
end
end
assert_response :success
- assert_template 'user/new'
- assert_equal response.headers['Content-Language'][0..1], locale.to_s[0..1] unless locale == :root
+ assert_template "user/new"
+ assert_equal response.headers["Content-Language"][0..1], locale.to_s[0..1] unless locale == :root
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
assert_no_missing_translations
end
I18n.available_locales.each do |locale|
dup_display_name = users(:public_user).display_name
email = "#{locale}_new_tester"
- assert_difference('User.count', 0) do
- assert_difference('ActionMailer::Base.deliveries.size', 0) do
- post '/user/new',
+ assert_difference("User.count", 0) do
+ assert_difference("ActionMailer::Base.deliveries.size", 0) do
+ post "/user/new",
{ :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
{ "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
end
end
assert_response :success
- assert_template 'user/new'
+ assert_template "user/new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
assert_no_missing_translations
end
new_email = "#{locale}newtester@osm.org"
display_name = "#{locale}_new_tester"
- assert_difference('User.count', 0) do
- assert_difference('ActionMailer::Base.deliveries.size', 0) do
+ assert_difference("User.count", 0) do
+ assert_difference("ActionMailer::Base.deliveries.size", 0) do
post "/user/new",
:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
end
assert_redirected_to "/user/terms"
- assert_difference('User.count') do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("User.count") do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post_via_redirect "/user/save", {},
{ "HTTP_ACCEPT_LANGUAGE" => "#{locale}" }
end
# Check the page
assert_response :success
- assert_template 'user/confirm'
+ assert_template "user/confirm"
ActionMailer::Base.deliveries.clear
end
password = "testtest"
# nothing special about this page, just need a protected page to redirect back to.
referer = "/traces/mine"
- assert_difference('User.count') do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("User.count") do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post "/user/new",
:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer
assert_redirected_to "/user/terms"
# Check the page
assert_response :success
- assert_template 'user/confirm'
+ assert_template "user/confirm"
ActionMailer::Base.deliveries.clear
# Go to the confirmation page
get "/user/#{display_name}/confirm", :confirm_string => confirm_string
assert_response :success
- assert_template 'user/confirm'
+ assert_template "user/confirm"
post "/user/#{display_name}/confirm", :confirm_string => confirm_string
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'site/welcome'
+ assert_template "site/welcome"
end
def test_user_create_openid_success
new_email = "newtester-openid@osm.org"
display_name = "new_tester-openid"
password = "testtest"
- assert_difference('User.count') do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("User.count") do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post "/user/new",
:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => "", :pass_crypt_confirmation => "" }
assert_response :redirect
res = openid_request(@response.redirect_url)
get "/user/new", res
assert_redirected_to "/user/terms"
- post '/user/save',
+ post "/user/save",
:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => password, :pass_crypt_confirmation => password }
assert_response :redirect
follow_redirect!
# Check the page
assert_response :success
- assert_template 'user/confirm'
+ assert_template "user/confirm"
ActionMailer::Base.deliveries.clear
end
def test_user_create_openid_failure
new_email = "newtester-openid2@osm.org"
display_name = "new_tester-openid2"
- assert_difference('User.count', 0) do
- assert_difference('ActionMailer::Base.deliveries.size', 0) do
+ assert_difference("User.count", 0) do
+ assert_difference("ActionMailer::Base.deliveries.size", 0) do
post "/user/new",
:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.failure=newuser", :pass_crypt => "", :pass_crypt_confirmation => "" }
assert_response :redirect
res = openid_request(@response.redirect_url)
- get '/user/new', res
+ get "/user/new", res
assert_response :success
- assert_template 'user/new'
+ assert_template "user/new"
end
end
display_name = "redirect_tester_openid"
# nothing special about this page, just need a protected page to redirect back to.
referer = "/traces/mine"
- assert_difference('User.count') do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("User.count") do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post "/user/new",
:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
assert_response :redirect
# Check the page
assert_response :success
- assert_template 'user/confirm'
+ assert_template "user/confirm"
ActionMailer::Base.deliveries.clear
# Go to the confirmation page
get "/user/#{display_name}/confirm", :confirm_string => confirm_string
assert_response :success
- assert_template 'user/confirm'
+ assert_template "user/confirm"
post "/user/#{display_name}/confirm", :confirm_string => confirm_string
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'site/welcome'
+ assert_template "site/welcome"
end
end
-require 'test_helper'
+require "test_helper"
class UserDiariesTest < ActionDispatch::IntegrationTest
fixtures :users, :diary_entries
# Test the creation of a diary entry, making sure that you are redirected to
# login page when not logged in
def test_showing_create_diary_entry
- get_via_redirect '/diary/new'
+ get_via_redirect "/diary/new"
# We should now be at the login page
assert_response :success
- assert_template 'user/login'
+ assert_template "user/login"
# We can now login
- post '/login', 'username' => "test@openstreetmap.org", 'password' => "test", :referer => '/diary/new'
+ post "/login", "username" => "test@openstreetmap.org", "password" => "test", :referer => "/diary/new"
assert_response :redirect
# print @response.body
# Check that there is some payload alerting the user to the redirect
follow_redirect!
assert_response :success
- assert_template 'diary_entry/edit'
+ assert_template "diary_entry/edit"
# print @response.body
# print @html_document.to_yaml
-require 'test_helper'
+require "test_helper"
class UserLoginTest < ActionDispatch::IntegrationTest
fixtures :users
def test_login_email_password_normal
user = users(:normal_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.email, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.email, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.email, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.email, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test"
end
def test_login_email_password_normal_upcase
user = users(:normal_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.email.upcase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.email.upcase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.email.upcase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.email.upcase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "TEST"
end
def test_login_email_password_normal_titlecase
user = users(:normal_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.email.titlecase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.email.titlecase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.email.titlecase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.email.titlecase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
assert_select "span.username", false
end
def test_login_email_password_public
user = users(:public_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.email, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.email, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.email, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.email, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test2"
end
def test_login_email_password_public_upcase
user = users(:public_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.email.upcase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.email.upcase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.email.upcase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.email.upcase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test2"
end
def test_login_email_password_public_titlecase
user = users(:public_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.email.titlecase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.email.titlecase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.email.titlecase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.email.titlecase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test2"
end
def test_login_username_password_normal
user = users(:normal_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.display_name, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.display_name, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.display_name, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.display_name, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test"
end
def test_login_username_password_normal_upcase
user = users(:normal_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.display_name.upcase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.display_name.upcase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.display_name.upcase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.display_name.upcase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "TEST"
end
def test_login_username_password_normal_titlecase
user = users(:normal_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.display_name.titlecase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.display_name.titlecase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.display_name.titlecase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.display_name.titlecase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
assert_select "span.username", false
end
def test_login_username_password_public
user = users(:public_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.display_name, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.display_name, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.display_name, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.display_name, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test2"
end
def test_login_username_password_public_upcase
user = users(:public_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.display_name.upcase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.display_name.upcase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.display_name.upcase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.display_name.upcase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test2"
end
def test_login_username_password_public_titlecase
user = users(:public_user)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => user.display_name.titlecase, 'password' => "wrong", :referer => "/history"
+ post "/login", "username" => user.display_name.titlecase, "password" => "wrong", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
- post '/login', 'username' => user.display_name.titlecase, 'password' => "test", :referer => "/history"
+ post "/login", "username" => user.display_name.titlecase, "password" => "test", :referer => "/history"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "test2"
end
def test_login_openid_success
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'openid_url' => "http://localhost:1123/john.doe?openid.success=true", :referer => "/history"
+ post "/login", "openid_url" => "http://localhost:1123/john.doe?openid.success=true", :referer => "/history"
assert_response :redirect
- post '/login', openid_request(@response.redirect_url)
+ post "/login", openid_request(@response.redirect_url)
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'changeset/history'
+ assert_template "changeset/history"
assert_select "span.username", "openIDuser"
end
def test_login_openid_cancel
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'openid_url' => "http://localhost:1123/john.doe", :referer => "/diary"
+ post "/login", "openid_url" => "http://localhost:1123/john.doe", :referer => "/diary"
assert_response :redirect
- post '/login', openid_request(@response.redirect_url)
+ post "/login", openid_request(@response.redirect_url)
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
assert_select "span.username", false
end
def test_login_openid_invalid_provider
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
# Use a different port that doesn't have the OpenID provider running on to test an invalid openID
- post '/login', 'openid_url' => "http://localhost:1124/john.doe", :referer => "/diary"
+ post "/login", "openid_url" => "http://localhost:1124/john.doe", :referer => "/diary"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
assert_select "span.username", false
end
def test_login_openid_invalid_url
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
# Use a url with an invalid protocol to make sure it handles that correctly too
- post '/login', 'openid_url' => "htt://localhost:1123/john.doe", :referer => "/diary"
+ post "/login", "openid_url" => "htt://localhost:1123/john.doe", :referer => "/diary"
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'login'
+ assert_template "login"
assert_select "span.username", false
end
def test_login_openid_unknown
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'openid_url' => "http://localhost:1123/john.doe?openid.success=true_somethingelse", :referer => "/diary"
+ post "/login", "openid_url" => "http://localhost:1123/john.doe?openid.success=true_somethingelse", :referer => "/diary"
assert_response :redirect
res = openid_request(@response.redirect_url)
- post '/login', res
+ post "/login", res
assert_response :redirect
follow_redirect!
assert_response :success
- assert_template 'user/new'
+ assert_template "user/new"
assert_select "span.username", false
end
end
-require 'test_helper'
+require "test_helper"
class UserRolesTest < ActionDispatch::IntegrationTest
fixtures :users, :user_roles
private
def check_fail(action, user, role)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => users(user).email, 'password' => "test", :referer => "/"
+ post "/login", "username" => users(user).email, "password" => "test", :referer => "/"
assert_response :redirect
follow_redirect!
assert_response :success
post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
- assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name
+ assert_redirected_to :controller => "user", :action => "view", :display_name => users(:second_public_user).display_name
reset!
end
def check_success(action, user, role)
- get '/login'
+ get "/login"
assert_response :redirect
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post '/login', 'username' => users(user).email, 'password' => "test", :referer => "/"
+ post "/login", "username" => users(user).email, "password" => "test", :referer => "/"
assert_response :redirect
follow_redirect!
assert_response :success
post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
- assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name
+ assert_redirected_to :controller => "user", :action => "view", :display_name => users(:second_public_user).display_name
reset!
end
-require 'test_helper'
+require "test_helper"
class UserTermsSeenTest < ActionDispatch::IntegrationTest
fixtures :users
# try to log in
get_via_redirect "/login"
assert_response :success
- assert_template 'user/login'
- post "/login", 'username' => user.email, 'password' => 'test', :referer => "/"
+ assert_template "user/login"
+ post "/login", "username" => user.email, "password" => "test", :referer => "/"
assert_response :redirect
# but now we need to look at the terms
assert_redirected_to "controller" => "user", "action" => "terms", :referer => "/"
assert_response :success
# don't agree to the terms, but hit decline
- post "/user/save", 'decline' => 'decline', 'referer' => '/'
+ post "/user/save", "decline" => "decline", "referer" => "/"
assert_redirected_to "/"
follow_redirect!
# try to log in
get_via_redirect "/login"
assert_response :success
- assert_template 'user/login'
- post "/login", 'username' => user.email, 'password' => 'test', :referer => "/"
+ assert_template "user/login"
+ post "/login", "username" => user.email, "password" => "test", :referer => "/"
assert_response :redirect
# but now we need to look at the terms
assert_redirected_to "controller" => "user", "action" => "terms", :referer => "/"
-require 'test_helper'
+require "test_helper"
class BoundingBoxTest < ActiveSupport::TestCase
def setup
def test_good_bbox_from_string
@good_bbox.each do |string|
bbox = BoundingBox.from_s(string)
- array = string.split(',').collect(&:to_f)
+ array = string.split(",").collect(&:to_f)
check_bbox(bbox, array)
end
end
def test_good_bbox_from_params
@good_bbox.each do |string|
bbox = BoundingBox.from_bbox_params(:bbox => string)
- array = string.split(',').collect(&:to_f)
+ array = string.split(",").collect(&:to_f)
check_bbox(bbox, array)
end
end
def test_good_bbox_from_lon_lat_params
@good_bbox.each do |string|
- array = string.split(',')
+ array = string.split(",")
bbox = BoundingBox.from_lon_lat_params(:minlon => array[0], :minlat => array[1], :maxlon => array[2], :maxlat => array[3])
check_bbox(bbox, array.collect(&:to_f))
end
def test_good_bbox_from_new
@good_bbox.each do |string|
- array = string.split(',')
+ array = string.split(",")
bbox = BoundingBox.new(array[0], array[1], array[2], array[3])
check_bbox(bbox, array.collect(&:to_f))
end
def test_bbox_area
@good_bbox.each do |string|
bbox = BoundingBox.from_s(string)
- array = string.split(',')
+ array = string.split(",")
assert_equal ((array[2].to_f - array[0].to_f) * (array[3].to_f - array[1].to_f)), bbox.area
end
end
def test_centre_lon
@good_bbox.each do |bbox_string|
- array = bbox_string.split(',')
+ array = bbox_string.split(",")
assert_equal ((array[0].to_f + array[2].to_f) / 2.0), BoundingBox.from_s(bbox_string).centre_lon
end
end
def test_centre_lat
@good_bbox.each do |bbox_string|
- array = bbox_string.split(',')
+ array = bbox_string.split(",")
assert_equal ((array[1].to_f + array[3].to_f) / 2.0), BoundingBox.from_s(bbox_string).centre_lat
end
end
def test_width
@good_bbox.each do |bbox_string|
- array = bbox_string.split(',')
+ array = bbox_string.split(",")
assert_equal (array[2].to_f - array[0].to_f), BoundingBox.from_s(bbox_string).width
end
end
def test_height
@good_bbox.each do |bbox_string|
- array = bbox_string.split(',')
+ array = bbox_string.split(",")
assert_equal (array[3].to_f - array[1].to_f), BoundingBox.from_s(bbox_string).height
end
end
def test_add_bounds_to_no_underscore
bounds = @bbox_from_string.add_bounds_to({})
assert_equal 4, bounds.size
- assert_equal @min_lon.to_s, bounds['minlon']
- assert_equal @min_lat.to_s, bounds['minlat']
- assert_equal @max_lon.to_s, bounds['maxlon']
- assert_equal @max_lat.to_s, bounds['maxlat']
+ assert_equal @min_lon.to_s, bounds["minlon"]
+ assert_equal @min_lat.to_s, bounds["minlat"]
+ assert_equal @max_lon.to_s, bounds["maxlon"]
+ assert_equal @max_lat.to_s, bounds["maxlat"]
end
def test_add_bounds_to_with_underscore
- bounds = @bbox_from_string.add_bounds_to({}, '_')
+ bounds = @bbox_from_string.add_bounds_to({}, "_")
assert_equal 4, bounds.size
- assert_equal @min_lon.to_s, bounds['min_lon']
- assert_equal @min_lat.to_s, bounds['min_lat']
- assert_equal @max_lon.to_s, bounds['max_lon']
- assert_equal @max_lat.to_s, bounds['max_lat']
+ assert_equal @min_lon.to_s, bounds["min_lon"]
+ assert_equal @min_lat.to_s, bounds["min_lat"]
+ assert_equal @max_lon.to_s, bounds["max_lon"]
+ assert_equal @max_lat.to_s, bounds["max_lat"]
end
def test_to_scaled
private
def check_expand(bbox, array_string, margin = 0, result = nil)
- array = array_string.split(',').collect(&:to_f)
+ array = array_string.split(",").collect(&:to_f)
result = array unless result
bbox.expand!(BoundingBox.new(array[0], array[1], array[2], array[3]), margin)
check_bbox(bbox, result)
end
def check_bbox(bbox, result)
- assert_equal result[0], bbox.min_lon, 'min_lon'
- assert_equal result[1], bbox.min_lat, 'min_lat'
- assert_equal result[2], bbox.max_lon, 'max_lon'
- assert_equal result[3], bbox.max_lat, 'max_lat'
+ assert_equal result[0], bbox.min_lon, "min_lon"
+ assert_equal result[1], bbox.min_lat, "min_lat"
+ assert_equal result[2], bbox.max_lon, "max_lon"
+ assert_equal result[3], bbox.max_lat, "max_lat"
end
end
-require 'test_helper'
+require "test_helper"
class CountryTest < ActiveSupport::TestCase
def test_gb
-require 'test_helper'
+require "test_helper"
class I18nTest < ActiveSupport::TestCase
I18n.available_locales.each do |locale|
-require 'test_helper'
+require "test_helper"
class PasswordHashTest < ActiveSupport::TestCase
def test_md5_without_salt
-require 'test_helper'
+require "test_helper"
class RichTextTest < ActiveSupport::TestCase
include Rails::Dom::Testing::Assertions::SelectorAssertions
-require 'test_helper'
+require "test_helper"
class ShortLinkTest < ActiveSupport::TestCase
##
# -*- coding: utf-8 -*-
-require 'test_helper'
+require "test_helper"
class UTF8Test < ActiveSupport::TestCase
def test_valid?
-require 'test_helper'
+require "test_helper"
class AclTest < ActiveSupport::TestCase
# Replace this with your real tests.
-require 'test_helper'
+require "test_helper"
class ChangesetCommentTest < ActiveSupport::TestCase
fixtures :changesets, :changeset_comments
-require 'test_helper'
+require "test_helper"
class ChangesetTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class ChangesetTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class DiaryCommentTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class DiaryEntryTest < ActiveSupport::TestCase
api_fixtures
def test_diary_entry_validations
diary_entry_valid({})
- diary_entry_valid({ :title => '' }, false)
- diary_entry_valid(:title => 'a' * 255)
- diary_entry_valid({ :title => 'a' * 256 }, false)
- diary_entry_valid({ :body => '' }, false)
+ diary_entry_valid({ :title => "" }, false)
+ diary_entry_valid(:title => "a" * 255)
+ diary_entry_valid({ :title => "a" * 256 }, false)
+ diary_entry_valid({ :body => "" }, false)
diary_entry_valid(:latitude => 90)
diary_entry_valid({ :latitude => 90.00001 }, false)
diary_entry_valid(:latitude => -90)
-require 'test_helper'
+require "test_helper"
class FriendTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class LanguageTest < ActiveSupport::TestCase
test "language count" do
# -*- coding: utf-8 -*-
-require 'test_helper'
+require "test_helper"
class MessageTest < ActiveSupport::TestCase
api_fixtures
def test_utf8_roundtrip
(1..255).each do |i|
- assert_message_ok('c', i)
+ assert_message_ok("c", i)
assert_message_ok(EURO, i)
end
end
def test_length_oversize
- assert_raise(ActiveRecord::RecordInvalid) { make_message('c', 256).save! }
+ assert_raise(ActiveRecord::RecordInvalid) { make_message("c", 256).save! }
assert_raise(ActiveRecord::RecordInvalid) { make_message(EURO, 256).save! }
end
to "to@example.com"
subject "Test message"
date Time.now
- content_type 'text/plain; charset=utf-8'
+ content_type "text/plain; charset=utf-8"
body "This is a test & a message"
end
message = Message.from_mail(mail, users(:normal_user), users(:public_user))
to "to@example.com"
subject "Test message"
date Time.now
- content_type 'text/html; charset=utf-8'
+ content_type "text/html; charset=utf-8"
body "<p>This is a <b>test</b> & a message</p>"
end
message = Message.from_mail(mail, users(:normal_user), users(:public_user))
date Time.now
text_part do
- content_type 'text/plain; charset=utf-8'
+ content_type "text/plain; charset=utf-8"
body "This is a test & a message in text format"
end
html_part do
- content_type 'text/html; charset=utf-8'
+ content_type "text/html; charset=utf-8"
body "<p>This is a <b>test</b> & a message in HTML format</p>"
end
end
date Time.now
html_part do
- content_type 'text/html; charset=utf-8'
+ content_type "text/html; charset=utf-8"
body "<p>This is a <b>test</b> & a message in HTML format</p>"
end
end
to "to@example.com"
subject "[OpenStreetMap] Test message"
date Time.now
- content_type 'text/plain; charset=utf-8'
+ content_type "text/plain; charset=utf-8"
body "This is a test & a message"
end
message = Message.from_mail(mail, users(:normal_user), users(:public_user))
-require 'test_helper'
+require "test_helper"
class NodeTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class NodeTest < ActiveSupport::TestCase
api_fixtures
# -*- coding: utf-8 -*-
-require 'test_helper'
+require "test_helper"
class NoteCommentTest < ActiveSupport::TestCase
fixtures :users, :notes, :note_comments
# -*- coding: utf-8 -*-
-require 'test_helper'
+require "test_helper"
class NoteTest < ActiveSupport::TestCase
fixtures :users, :notes, :note_comments
-require 'test_helper'
+require "test_helper"
class OauthNonceTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OauthTokenTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OldNodeTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OldNodeTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OldRelationTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OldRelationTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OldWayTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class OldWayTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
-require 'osm'
+require "test_helper"
+require "osm"
class RedactionTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class RelationMemberTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class RelationTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class RelationTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class TraceTest < ActiveSupport::TestCase
api_fixtures
def test_validations
trace_valid({})
trace_valid({ :user_id => nil }, false)
- trace_valid(:name => 'a' * 255)
- trace_valid({ :name => 'a' * 256 }, false)
+ trace_valid(:name => "a" * 255)
+ trace_valid({ :name => "a" * 256 }, false)
trace_valid({ :description => nil }, false)
- trace_valid(:description => 'a' * 255)
- trace_valid({ :description => 'a' * 256 }, false)
+ trace_valid(:description => "a" * 255)
+ trace_valid({ :description => "a" * 256 }, false)
trace_valid(:visibility => "private")
trace_valid(:visibility => "public")
trace_valid(:visibility => "trackable")
-require 'test_helper'
+require "test_helper"
class TracepointTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class TracetagTest < ActiveSupport::TestCase
api_fixtures
def test_validations
tracetag_valid({})
tracetag_valid({ :tag => nil }, false)
- tracetag_valid({ :tag => '' }, false)
- tracetag_valid(:tag => 'a')
- tracetag_valid(:tag => 'a' * 255)
- tracetag_valid({ :tag => 'a' * 256 }, false)
- tracetag_valid({ :tag => 'a/b' }, false)
- tracetag_valid({ :tag => 'a;b' }, false)
- tracetag_valid({ :tag => 'a.b' }, false)
- tracetag_valid({ :tag => 'a,b' }, false)
- tracetag_valid({ :tag => 'a?b' }, false)
+ tracetag_valid({ :tag => "" }, false)
+ tracetag_valid(:tag => "a")
+ tracetag_valid(:tag => "a" * 255)
+ tracetag_valid({ :tag => "a" * 256 }, false)
+ tracetag_valid({ :tag => "a/b" }, false)
+ tracetag_valid({ :tag => "a;b" }, false)
+ tracetag_valid({ :tag => "a.b" }, false)
+ tracetag_valid({ :tag => "a,b" }, false)
+ tracetag_valid({ :tag => "a?b" }, false)
end
private
-require 'test_helper'
+require "test_helper"
class UserPreferenceTest < ActiveSupport::TestCase
api_fixtures
# -*- coding: utf-8 -*-
-require 'test_helper'
+require "test_helper"
class UserTest < ActiveSupport::TestCase
api_fixtures
new_user = User.new(
:email => users(:normal_user).email,
:status => "active",
- :pass_crypt => Digest::MD5.hexdigest('test'),
+ :pass_crypt => Digest::MD5.hexdigest("test"),
:display_name => "new user",
:data_public => 1,
:description => "desc"
new_user = User.new(
:email => "tester@openstreetmap.org",
:status => "pending",
- :pass_crypt => Digest::MD5.hexdigest('test'),
+ :pass_crypt => Digest::MD5.hexdigest("test"),
:display_name => users(:normal_user).display_name,
:data_public => 1,
:description => "desc"
-require 'test_helper'
+require "test_helper"
class UserTokenTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class WayNodeTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class WayTagTest < ActiveSupport::TestCase
api_fixtures
-require 'test_helper'
+require "test_helper"
class WayTest < ActiveSupport::TestCase
api_fixtures
:invisible_way,
:used_way].each do |way_symbol|
way = current_ways(way_symbol)
- assert_equal node.bbox.min_lon, way.bbox.min_lon, 'min_lon'
- assert_equal node.bbox.min_lat, way.bbox.min_lat, 'min_lat'
- assert_equal node.bbox.max_lon, way.bbox.max_lon, 'max_lon'
- assert_equal node.bbox.max_lat, way.bbox.max_lat, 'max_lat'
+ assert_equal node.bbox.min_lon, way.bbox.min_lon, "min_lon"
+ assert_equal node.bbox.min_lat, way.bbox.min_lat, "min_lat"
+ assert_equal node.bbox.max_lon, way.bbox.max_lon, "max_lon"
+ assert_equal node.bbox.max_lat, way.bbox.max_lat, "max_lat"
end
end
ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-load 'composite_primary_keys/fixtures.rb'
+require File.expand_path("../../config/environment", __FILE__)
+require "rails/test_help"
+load "composite_primary_keys/fixtures.rb"
module ActiveSupport
class TestCase
# when the owner of the changset has their data not marked as public
def assert_require_public_data(msg = "Shouldn't be able to use API when the user's data is not public")
assert_response :forbidden, msg
- assert_equal @response.headers['Error'], "You must make your edits public to upload new data", "Wrong error message"
+ assert_equal @response.headers["Error"], "You must make your edits public to upload new data", "Wrong error message"
end
# Not sure this is the best response we could give
def openid_request(openid_request_uri)
openid_response = Net::HTTP.get_response(URI.parse(openid_request_uri))
- openid_response_uri = URI(openid_response['Location'])
+ openid_response_uri = URI(openid_response["Location"])
openid_response_qs = Rack::Utils.parse_query(openid_response_uri.query)
openid_response_qs