Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent
+Style/ExtraSpacing:
+ AllowForAlignment: true
+
Style/FileName:
Exclude:
- 'script/deliver-message'
-# This configuration was generated by `rubocop --auto-gen-config`
-# on 2015-06-08 15:55:30 +0100 using RuboCop version 0.32.0.
+# This configuration was generated by
+# `rubocop --auto-gen-config`
+# on 2015-08-18 20:27:49 +0100 using RuboCop version 0.33.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# Offense count: 34
Lint/AmbiguousOperator:
- Enabled: false
+ Exclude:
+ - 'test/controllers/amf_controller_test.rb'
+ - 'test/controllers/changeset_controller_test.rb'
+ - 'test/lib/bounding_box_test.rb'
+ - 'test/lib/country_test.rb'
# Offense count: 115
Lint/AmbiguousRegexpLiteral:
Enabled: false
-# Offense count: 30
+# Offense count: 29
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
- Enabled: false
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/geocoder_controller.rb'
+ - 'app/controllers/notes_controller.rb'
+ - 'app/controllers/trace_controller.rb'
+ - 'app/controllers/user_controller.rb'
+ - 'app/controllers/user_preference_controller.rb'
+ - 'app/helpers/application_helper.rb'
+ - 'app/helpers/browse_helper.rb'
+ - 'app/models/client_application.rb'
+ - 'app/models/notifier.rb'
+ - 'lib/nominatim.rb'
+ - 'lib/osm.rb'
+ - 'script/deliver-message'
+
+# Offense count: 3
+Lint/FormatParameterMismatch:
+ Exclude:
+ - 'app/controllers/swf_controller.rb'
# Offense count: 5
Lint/HandleExceptions:
- Enabled: false
+ Exclude:
+ - 'app/controllers/amf_controller.rb'
+ - 'app/controllers/user_controller.rb'
+ - 'config/initializers/session.rb'
# Offense count: 8
Lint/ParenthesesAsGroupedExpression:
- Enabled: false
+ Exclude:
+ - 'test/controllers/amf_controller_test.rb'
+ - 'test/lib/bounding_box_test.rb'
+ - 'test/models/user_preference_test.rb'
-# Offense count: 669
+# Offense count: 671
Metrics/AbcSize:
Max: 277
Metrics/CyclomaticComplexity:
Max: 20
-# Offense count: 2537
+# Offense count: 2535
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 694
-# Offense count: 623
+# Offense count: 628
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 179
# Offense count: 2
# Configuration parameters: Include.
Rails/HasAndBelongsToMany:
- Enabled: false
+ Exclude:
+ - 'app/models/changeset.rb'
+ - 'app/models/user.rb'
-# Offense count: 67
+# Offense count: 66
# Configuration parameters: EnforcedStyle, SupportedStyles.
Rails/TimeZone:
Enabled: false
# Offense count: 5
Style/AccessorMethodName:
- Enabled: false
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/helpers/title_helper.rb'
+ - 'app/models/old_way.rb'
+ - 'lib/osm.rb'
+ - 'lib/potlatch.rb'
# Offense count: 1
Style/AsciiComments:
- Enabled: false
+ Exclude:
+ - 'test/models/message_test.rb'
-# Offense count: 308
+# Offense count: 310
Style/Documentation:
Enabled: false
# Offense count: 38
# Configuration parameters: MinBodyLength.
Style/GuardClause:
- Enabled: false
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/diary_entry_controller.rb'
+ - 'app/controllers/message_controller.rb'
+ - 'app/controllers/notes_controller.rb'
+ - 'app/controllers/site_controller.rb'
+ - 'app/controllers/user_blocks_controller.rb'
+ - 'app/controllers/user_controller.rb'
+ - 'app/controllers/user_roles_controller.rb'
+ - 'app/helpers/application_helper.rb'
+ - 'app/models/changeset.rb'
+ - 'app/models/user.rb'
+ - 'lib/diff_reader.rb'
+ - 'lib/object_metadata.rb'
# Offense count: 60
# Cop supports --auto-correct.
Style/LineEndConcatenation:
- Enabled: false
+ Exclude:
+ - 'db/migrate/008_remove_segments.rb'
+ - 'db/migrate/020_populate_node_tags_and_remove.rb'
+ - 'db/migrate/023_add_changesets.rb'
+ - 'lib/bounding_box.rb'
+ - 'lib/diff_reader.rb'
+ - 'lib/osm.rb'
+ - 'test/controllers/changeset_controller_test.rb'
+ - 'test/controllers/node_controller_test.rb'
+ - 'test/controllers/relation_controller_test.rb'
+ - 'test/controllers/way_controller_test.rb'
# Offense count: 69
# Cop supports --auto-correct.
# Offense count: 42
# Cop supports --auto-correct.
Style/PerlBackrefs:
- Enabled: false
+ Exclude:
+ - 'app/controllers/amf_controller.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/helpers/browse_helper.rb'
+ - 'config/initializers/paperclip.rb'
+ - 'lib/id.rb'
+ - 'lib/potlatch.rb'
+ - 'test/lib/i18n_test.rb'
# Offense count: 8
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
Style/PredicateName:
- Enabled: false
+ Exclude:
+ - 'app/models/changeset.rb'
+ - 'app/models/old_node.rb'
+ - 'app/models/old_relation.rb'
+ - 'app/models/old_way.rb'
+ - 'app/models/user.rb'
+ - 'lib/classic_pagination/pagination.rb'
# Offense count: 97
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Offense count: 2
Style/RescueModifier:
- Enabled: false
+ Exclude:
+ - 'app/helpers/browse_helper.rb'
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StringLiteralsInInterpolation:
Enabled: false
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
-Style/TrivialAccessors:
- Enabled: false
result = startchangeset(*args)
end
- err = true if result[0] == -3 # If a conflict is detected, don't execute any more writes
+ err = true if result[0] == -3 # If a conflict is detected, don't execute any more writes
end
result
# 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)
return -1, "You are not logged in, so the relation could not be saved." unless user
return -2, "Server error - node with id 0 found in way #{originalway}." if id == 0
return -2, "Server error - node with latitude -90 found in way #{originalway}." if lat == 90
- id = renumberednodes[id] if renumberednodes[id]
+ id = renumberednodes[id] if renumberednodes[id]
node = Node.new
node.changeset_id = changeset_id
# 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
+ 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
+ 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
+ elsif request.env.key? "HTTP_AUTHORIZATION" # regular location
authdata = request.env["HTTP_AUTHORIZATION"].to_s.split
end
# only basic authentication supported
# restrict changesets to those enclosed by a bounding box
# we need to return both the changesets and the bounding box
def conditions_bbox(changesets, bbox)
- if bbox
+ if bbox
bbox.check_boundaries
bbox = bbox.to_scaled
return changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?",
unless response.match(/Error/)
dataline = response.split(/\n/)[1]
data = dataline.split(/,/) # easting,northing,postcode,lat,long
- postcode = data[2].gsub(/'/, "")
+ postcode = data[2].delete("'")
zoom = POSTCODE_ZOOM - postcode.count("#")
@results.push(:lat => data[3], :lon => data[4], :zoom => zoom,
:name => postcode)
if type.empty?
prefix_name = ""
else
- prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize
+ prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.tr("_", " ").capitalize
end
if klass == "boundary" && type == "administrative"
rank = (place.attributes["place_rank"].to_i + 1) / 2
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
+ @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
bounds_top = 240 * 20
m = ""
- m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background
+ m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background
absx = 0
absy = 0
xl = yb = 9999999
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
- sql = "SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,gpx_id AS fileid," + " EXTRACT(EPOCH FROM timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gps_points " + "WHERE " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
+ sql = "SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,gpx_id AS fileid," + " EXTRACT(EPOCH FROM timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gps_points " + "WHERE " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
end
gpslist = ActiveRecord::Base.connection.select_all sql
# Line-drawing
def start_shape
- s = 0.chr # No fill styles
- s += 2.chr # Two line styles
- s += pack_u16(0) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF
- s += pack_u16(0) + 255.chr + 0.chr + 255.chr # Width 5, RGB #FF00FF
- s += 34.chr # 2 fill, 2 line index bits
+ s = 0.chr # No fill styles
+ s += 2.chr # Two line styles
+ s += pack_u16(0) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF
+ s += pack_u16(0) + 255.chr + 0.chr + 255.chr # Width 5, RGB #FF00FF
+ s += 34.chr # 2 fill, 2 line index bits
s
end
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 += format("%05b%0*b%0*b", l, l, x, l, y)
- d += col # Select line style
+ d += col # Select line style
d
end
def icon
trace = Trace.find(params[:id])
- if trace.visible? && trace.inserted?
+ if trace.visible? && 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")
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)
if value =~ /^([a-z-]{2,12}):(.+)$/i
# Value is <lang>:<title> so split it up
# Note that value is always left as-is, see: https://trac.openstreetmap.org/ticket/4315
- lang = $1
+ lang = $1
else
# Value is <title> so default to English Wikipedia
lang = "en"
# Must break it up to correctly build the url
value = $1
section = "#" + $2
- encoded_section = "#" + URI.encode($2.gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).gsub("%", ".")
+ encoded_section = "#" + URI.encode($2.gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).tr("%", ".")
else
section = ""
encoded_section = ""
:title => "Re: #{comment.diary_entry.title}")
mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
- :to => comment.diary_entry.user.email,
+ :to => comment.diary_entry.user.email,
:subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
end
end
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
has_many :changesets, -> { order(:created_at => :desc) }
- has_many :changeset_comments, :foreign_key => :author_id
+ 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_many :note_comments, :foreign_key => :author_id
has_many :notes, :through => :note_comments
create_table :current_node_tags, :id => false do |t|
t.column :id, :bigint, :null => false
- t.column :k, :string, :default => "", :null => false
- t.column :v, :string, :default => "", :null => false
+ t.column :k, :string, :default => "", :null => false
+ t.column :v, :string, :default => "", :null => false
end
create_table :node_tags, :id => false do |t|
def change
create_table :changeset_comments do |t|
t.column :changeset_id, :bigint, :null => false
- t.column :author_id, :bigint, :null => false
+ t.column :author_id, :bigint, :null => false
t.text :body, :null => false
t.timestamp :created_at, :null => false
t.boolean :visible, :null => false
# care of that for us.
if @reader.node_type == 1 # element
name = @reader.name
- attributes = {}
+ attributes = {}
if @reader.has_attributes?
while @reader.move_to_next_attribute == 1
root["generator"] = GENERATOR
root["copyright"] = COPYRIGHT_OWNER
root["attribution"] = ATTRIBUTION_URL
- root["license"] = LICENSE_URL
+ root["license"] = LICENSE_URL
doc.root = root
doc
end
# 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
break if key == ""
arr[key] = getvalue(s)
end
- s.getbyte # skip the 9 'end of object' value
+ s.getbyte # skip the 9 'end of object' value
arr
end
# Parse and get value
def self.getvalue(s)
case s.getbyte
- when 0 then return getdouble(s) # number
- when 1 then return s.getbyte # boolean
- when 2 then return getstring(s) # string
- when 3 then return getobject(s) # object/hash
- when 5 then return nil # null
- when 6 then return nil # undefined
- when 8 then s.read(4) # mixedArray
- return getobject(s) # |
- when 10 then return getarray(s) # array
- else return nil # error
+ when 0 then return getdouble(s) # number
+ when 1 then return s.getbyte # boolean
+ when 2 then return getstring(s) # string
+ when 3 then return getobject(s) # object/hash
+ when 5 then return nil # null
+ when 6 then return nil # undefined
+ when 8 then s.read(4) # mixedArray
+ return getobject(s) # |
+ when 10 then return getarray(s) # array
+ else return nil # error
end
end
# keep support for old shortlinks which use the @ character, now
# replaced by the ~ character because twitter is horribly broken
# and we can't have that.
- str.gsub!("@", "~")
+ str.tr!("@", "~")
str.each_char do |c|
t = ARRAY.index c
namespace "db" do
desc "Adds a version number to the nodes table"
- task :node_version do
+ task :node_version do
require File.dirname(__FILE__) + "/../../config/environment"
increment = 1000
#!/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__)
+APP_PATH = File.expand_path("../../config/application", __FILE__)
+require File.expand_path("../../config/boot", __FILE__)
require "rails/commands"
def amf_parse_response
req = StringIO.new(@response.body)
- req.read(2) # version
+ req.read(2) # version
# parse through any headers
- headers = AMF.getint(req) # Read number of headers
- headers.times do # Read each header
- AMF.getstring(req) # |
- req.getc # | skip boolean
- AMF.getvalue(req) # |
+ headers = AMF.getint(req) # Read number of headers
+ headers.times do # Read each header
+ AMF.getstring(req) # |
+ req.getc # | skip boolean
+ AMF.getvalue(req) # |
end
# parse through responses
results = {}
- bodies = AMF.getint(req) # Read number of bodies
- bodies.times do # Read each body
- message = AMF.getstring(req) # | get message name
- AMF.getstring(req) # | get index in response sequence
- AMF.getlong(req) # | get total size in bytes
- args = AMF.getvalue(req) # | get response (probably an array)
+ bodies = AMF.getint(req) # Read number of bodies
+ bodies.times do # Read each body
+ message = AMF.getstring(req) # | get message name
+ AMF.getstring(req) # | get index in response sequence
+ AMF.getlong(req) # | get total size in bytes
+ args = AMF.getvalue(req) # | get response (probably an array)
results[message] = args
end
@amf_result = results
end
def test_permissions_oauth
- @request.env["oauth.token"] = AccessToken.new do |token|
+ @request.env["oauth.token"] = AccessToken.new do |token|
# Just to test a few
token.allow_read_prefs = true
token.allow_write_api = true
# NOTE: the include method doesn't over-expand, like inserting
# a real method does. this is because we expect the client to
# know what it is doing!
- check_after_include(changeset_id, 1, 1, [1, 1, 1, 1])
- check_after_include(changeset_id, 3, 3, [1, 1, 3, 3])
- check_after_include(changeset_id, 4, 2, [1, 1, 4, 3])
- check_after_include(changeset_id, 2, 2, [1, 1, 4, 3])
- check_after_include(changeset_id, -1, -1, [-1, -1, 4, 3])
- check_after_include(changeset_id, -2, 5, [-2, -1, 4, 5])
+ check_after_include(changeset_id, 1, 1, [1, 1, 1, 1])
+ check_after_include(changeset_id, 3, 3, [1, 1, 3, 3])
+ check_after_include(changeset_id, 4, 2, [1, 1, 4, 3])
+ check_after_include(changeset_id, 2, 2, [1, 1, 4, 3])
+ check_after_include(changeset_id, -1, -1, [-1, -1, 4, 3])
+ check_after_include(changeset_id, -2, 5, [-2, -1, 4, 5])
end
##
xhr :get, :search_osm_nominatim_reverse, :lat => 51.7632, :lon => -0.0076, :zoom => 17
results_check :name => "Dinant Link Road, Broxbourne, Hertfordshire, East of England, England, EN11 8HX, United Kingdom",
:lat => 51.7634883, :lon => -0.0088373,
- :type => "way", :id => 3489841, :zoom => 17
+ :type => "way", :id => 3489841, :zoom => 17
end
end
:client_application => {
:name => "Test Application"
}
- }, { :user => user }
+ }, { :user => user }
end
assert_response :success
assert_template "new"
:name => "Test Application",
:url => "http://test.example.com/"
}
- }, { :user => user }
+ }, { :user => user }
end
assert_response :redirect
assert_redirected_to oauth_client_path(:id => ClientApplication.find_by_name("Test Application").id)
:name => "New Name",
:url => nil
}
- }, { :user => user }
+ }, { :user => user }
assert_response :success
assert_template "edit"
:name => "New Name",
:url => "http://new.example.com/url"
}
- }, { :user => user }
+ }, { :user => user }
assert_response :redirect
assert_redirected_to oauth_client_path(:id => client.id)
end
check_not_found_id_version(70000, 312344)
check_not_found_id_version(-1, -13)
check_not_found_id_version(nodes(:visible_node).id, 24354)
- check_not_found_id_version(24356, nodes(:visible_node).version)
+ check_not_found_id_version(24356, nodes(:visible_node).version)
end
def check_not_found_id_version(id, version)
# Test editing a specific note
def test_edit_with_note
user = users(:public_user)
- note = notes(:open_note)
+ note = notes(:open_note)
get :edit, { :note => note.id }, { :user => user.id }
assert_response :success
assert_equal [], User.find(user.id).languages
assert_select "html[lang=?]", "en"
- get "/diary/new", {}, { "HTTP_ACCEPT_LANGUAGE" => "fr, en" }
+ get "/diary/new", {}, { "HTTP_ACCEPT_LANGUAGE" => "fr, en" }
assert_equal %w(fr en), User.find(user.id).languages
assert_select "html[lang=?]", "fr"
end
@bad_lat_mixed_bbox = %w(0,0.1,0.1,0 -0.1,80,0.1,70 0.24,54.34,0.25,54.33)
@bad_lon_mixed_bbox = %w(80,-0.1,70,0.1 54.34,0.24,54.33,0.25)
@bad_limit_bbox = %w(-180.1,-90,180,90 -180,-90.1,180,90 -180,-90,180.1,90 -180,-90,180,90.1)
- @good_bbox = %w(-0.1,-0.1,0.1,0.1 51.1,-0.1,51.2,0 -0.1,%20-0.1,%200.1,%200.1
- -0.1edcd,-0.1d,0.1,0.1 -0.1E,-0.1E,0.1S,0.1N S0.1,W0.1,N0.1,E0.1)
+ @good_bbox = %w(-0.1,-0.1,0.1,0.1 51.1,-0.1,51.2,0 -0.1,%20-0.1,%200.1,%200.1
+ -0.1edcd,-0.1d,0.1,0.1 -0.1E,-0.1E,0.1S,0.1N S0.1,W0.1,N0.1,E0.1)
@expand_min_lon_array = %w(2,10,10,10 1,10,10,10 0,10,10,10 -1,10,10,10 -2,10,10,10 -8,10,10,10)
@expand_min_lat_array = %w(10,2,10,10 10,1,10,10 10,0,10,10 10,-1,10,10 10,-2,10,10 10,-8,10,10)