Rails/ApplicationRecord:
Enabled: false
+Rails/CreateTableWithTimestamps:
+ Enabled: false
+
Rails/HasManyOrHasOneDependent:
Enabled: false
Rails/HttpPositionalArguments:
Enabled: false
+Rails/InverseOf:
+ Enabled: false
+
Rails/SkipsModelValidations:
Exclude:
- 'db/migrate/*.rb'
Exclude:
- 'test/controllers/node_controller_test.rb'
-# Offense count: 2
-Lint/RescueWithoutErrorClass:
- Exclude:
- - 'app/helpers/browse_helper.rb'
-
# Offense count: 2
Lint/ShadowingOuterLocalVariable:
Exclude:
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Enabled: false
+
+# Offense count: 2
+Style/RescueStandardError:
+ Exclude:
+ - 'app/helpers/browse_helper.rb'
rels = []
if searchterm.to_i > 0
rel = Relation.where(:id => searchterm.to_i).first
- if rel && rel.visible
- rels.push([rel.id, rel.tags, rel.members, rel.version])
- end
+ rels.push([rel.id, rel.tags, rel.members, rel.version]) if rel && rel.visible
else
RelationTag.where("v like ?", "%#{searchterm}%").limit(11).each do |t|
- if t.relation.visible
- rels.push([t.relation.id, t.relation.tags, t.relation.members, t.relation.version])
- end
+ rels.push([t.relation.id, t.relation.tags, t.relation.members, t.relation.version]) if t.relation.visible
end
end
rels
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
+ typedmembers << [m[0], mid, m[2].delete("\000-\037\ufffe\uffff", "^\011\012\015")] if mid
end
# assign new contents
return [-4, "node", id]
end
- unless visible || node.ways.empty?
- return -1, "Point #{id} has since become part of a way, so you cannot save it as a POI.", id, id, version
- end
+ return -1, "Point #{id} has since become part of a way, so you cannot save it as a POI.", id, id, version unless visible || node.ways.empty?
end
# We always need a new node, based on the data that has been sent to us
new_node = Node.new
n = Node.where(:id => id).first
if n
v = n.version
- unless timestamp == ""
- n = OldNode.where("node_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first
- end
+ n = OldNode.where("node_id = ? AND timestamp <= ?", id, timestamp).unredacted.order("timestamp DESC").first unless timestamp == ""
end
if n
# - [0] in case some thing links to node 0 which doesn't exist. Shouldn't actually ever happen but it does. FIXME: file a ticket for this
nodes_to_fetch = (list_of_way_nodes.uniq - node_ids) - [0]
- unless nodes_to_fetch.empty?
- nodes += Node.includes(:node_tags).find(nodes_to_fetch)
- end
+ nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty?
visible_nodes = {}
changeset_cache = {}
end
end
elsif session[:token]
- if self.current_user = User.authenticate(:token => session[:token])
- session[:user] = current_user.id
- end
+ session[:user] = current_user.id if self.current_user = User.authenticate(:token => session[:token])
end
rescue StandardError => ex
logger.info("Exception authorizing user: #{ex}")
##
# ensure that there is a "this_user" instance variable
def lookup_this_user
- unless @this_user = User.active.find_by(:display_name => params[:display_name])
- render_unknown_user params[:display_name]
- end
+ render_unknown_user params[:display_name] unless @this_user = User.active.find_by(:display_name => params[:display_name])
end
##
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)
- end
+ user, pass = Base64.decode64(authdata[1]).split(":", 2) if authdata && authdata[0] == "Basic"
[user, pass]
end
skip_before_action :verify_authenticity_token, :except => [:list]
before_action :authorize_web, :only => [:list, :feed, :comments_feed]
before_action :set_locale, :only => [:list, :feed, :comments_feed]
- before_action :authorize, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
+ before_action :authorize, :only => [:create, :update, :upload, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
before_action :require_moderator, :only => [:hide_comment, :unhide_comment]
- before_action :require_allow_write_api, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
- before_action :require_public_data, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe]
- before_action :check_api_writable, :only => [:create, :update, :delete, :upload, :include, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
- before_action :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query, :list, :feed, :comment, :subscribe, :unsubscribe, :comments_feed]
+ before_action :require_allow_write_api, :only => [:create, :update, :upload, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
+ before_action :require_public_data, :only => [:create, :update, :upload, :close, :comment, :subscribe, :unsubscribe]
+ before_action :check_api_writable, :only => [:create, :update, :upload, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
+ before_action :check_api_readable, :except => [:create, :update, :upload, :download, :query, :list, :feed, :comment, :subscribe, :unsubscribe, :comments_feed]
before_action(:only => [:list, :feed, :comments_feed]) { |c| c.check_database_readable(true) }
around_action :api_call_handle_error, :except => [:list, :feed, :comments_feed]
around_action :api_call_timeout, :except => [:list, :feed, :comments_feed, :upload]
changesets = changesets.where(:user_id => current_user.nearby)
end
- if @params[:max_id]
- changesets = changesets.where("changesets.id <= ?", @params[:max_id])
- end
+ changesets = changesets.where("changesets.id <= ?", @params[:max_id]) if @params[:max_id]
@edits = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
# Notify current subscribers of the new comment
changeset.subscribers.visible.each do |user|
- if current_user != user
- Notifier.changeset_comment_notification(comment, user).deliver_now
- end
+ Notifier.changeset_comment_notification(comment, user).deliver_now if current_user != user
end
# Add the commenter to the subscribers if necessary
# Notify current subscribers of the new comment
@entry.subscribers.visible.each do |user|
- if current_user != user
- Notifier.diary_comment_notification(@diary_comment, user).deliver_now
- end
+ Notifier.diary_comment_notification(@diary_comment, user).deliver_now if current_user != user
end
# Add the commenter to the subscribers if necessary
maxlat = params[:maxlat]
# get view box
- if minlon && minlat && maxlon && maxlat
- viewbox = "&viewbox=#{minlon},#{maxlat},#{maxlon},#{minlat}"
- end
+ viewbox = "&viewbox=#{minlon},#{maxlat},#{maxlon},#{minlat}" if minlon && minlat && maxlon && maxlat
# get objects to excude
exclude = "&exclude_place_ids=#{params[:exclude]}" if params[:exclude]
rank = (place.attributes["place_rank"].to_i + 1) / 2
prefix_name = t "geocoder.search_osm_nominatim.admin_levels.level#{rank}", :default => prefix_name
place.elements["extratags"].elements.each("tag") do |extratag|
- if extratag.attributes["key"] == "place"
- prefix_name = t "geocoder.search_osm_nominatim.prefix.place.#{extratag.attributes['value']}", :default => prefix_name
- end
+ prefix_name = t "geocoder.search_osm_nominatim.prefix.place.#{extratag.attributes['value']}", :default => prefix_name if extratag.attributes["key"] == "place"
end
end
prefix = t "geocoder.search_osm_nominatim.prefix_format", :name => prefix_name
node = Node.find(params[:id])
new_node = Node.from_xml(request.raw_post)
- unless new_node && new_node.id == node.id
- raise OSM::APIBadUserInput, "The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})"
- end
+ raise OSM::APIBadUserInput, "The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})" unless new_node && new_node.id == node.id
node.update_from(new_node, current_user)
render :plain => node.version.to_s
node = Node.find(params[:id])
new_node = Node.from_xml(request.raw_post)
- unless new_node && new_node.id == node.id
- raise OSM::APIBadUserInput, "The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})"
- end
+ raise OSM::APIBadUserInput, "The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})" unless new_node && new_node.id == node.id
node.delete_with_history!(new_node, current_user)
render :plain => node.version.to_s
end
# Dump the details on many nodes whose ids are given in the "nodes" parameter.
def nodes
- unless params["nodes"]
- raise OSM::APIBadUserInput, "The parameter nodes is required, and must be of the form nodes=id[,id[,id...]]"
- end
+ raise OSM::APIBadUserInput, "The parameter nodes is required, and must be of the form nodes=id[,id[,id...]]" unless params["nodes"]
ids = params["nodes"].split(",").collect(&:to_i)
- if ids.empty?
- raise OSM::APIBadUserInput, "No nodes were given to search for"
- end
+ raise OSM::APIBadUserInput, "No nodes were given to search for" if ids.empty?
doc = OSM::API.new.get_xml_doc
Node.find(ids).each do |node|
comment = note.comments.create!(attributes)
note.comments.map(&:author).uniq.each do |user|
- if notify && user && user != current_user && user.visible?
- Notifier.note_comment_notification(comment, user).deliver_now
- end
+ Notifier.note_comment_notification(comment, user).deliver_now if notify && user && user != current_user && user.visible?
end
end
end
"&oauth_token=#{@token.token}"
end
- unless @token.oauth10?
- @redirect_url.query += "&oauth_verifier=#{@token.verifier}"
- end
+ @redirect_url.query += "&oauth_verifier=#{@token.verifier}" unless @token.oauth10?
redirect_to @redirect_url.to_s
end
relation = Relation.find(params[:id])
new_relation = Relation.from_xml(request.raw_post)
- unless new_relation && new_relation.id == relation.id
- raise OSM::APIBadUserInput, "The id in the url (#{relation.id}) is not the same as provided in the xml (#{new_relation.id})"
- end
+ raise OSM::APIBadUserInput, "The id in the url (#{relation.id}) is not the same as provided in the xml (#{new_relation.id})" unless new_relation && new_relation.id == relation.id
relation.update_from new_relation, current_user
render :plain => relation.version.to_s
end
def relations
- unless params["relations"]
- raise OSM::APIBadUserInput, "The parameter relations is required, and must be of the form relations=id[,id[,id...]]"
- end
+ raise OSM::APIBadUserInput, "The parameter relations is required, and must be of the form relations=id[,id[,id...]]" unless params["relations"]
ids = params["relations"].split(",").collect(&:to_i)
- if ids.empty?
- raise OSM::APIBadUserInput, "No relations were given to search for"
- end
+ raise OSM::APIBadUserInput, "No relations were given to search for" if ids.empty?
doc = OSM::API.new.get_xml_doc
before_action :update_totp, :only => [:index]
def index
- unless STATUS == :database_readonly || STATUS == :database_offline
- session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"])
- end
+ session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless STATUS == :database_readonly || STATUS == :database_offline
end
def permalink
def redirect_map_params
anchor = []
- if params[:lat] && params[:lon]
- anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
- end
+ anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
if params[:layers]
anchor << "layers=#{params.delete(:layers)}"
anchor << "layers=N"
end
- if anchor.present?
- redirect_to params.to_unsafe_h.merge(:anchor => anchor.join("&"))
- end
+ redirect_to params.to_unsafe_h.merge(:anchor => anchor.join("&")) if anchor.present?
end
end
if @trace.id
flash[:notice] = t "trace.create.trace_uploaded"
- if current_user.traces.where(:inserted => false).count > 4
- flash[:warning] = t "trace.trace_header.traces_waiting", :count => current_user.traces.where(:inserted => false).count
- end
+ flash[:warning] = t "trace.trace_header.traces_waiting", :count => current_user.traces.where(:inserted => false).count if current_user.traces.where(:inserted => false).count > 4
redirect_to :action => :list, :display_name => current_user.display_name
end
@trace.description = params[:trace][:description]
@trace.tagstring = params[:trace][:tagstring]
@trace.visibility = params[:trace][:visibility]
- if @trace.save
- redirect_to :action => "view", :display_name => current_user.display_name
- end
+ redirect_to :action => "view", :display_name => current_user.display_name if @trace.save
end
end
rescue ActiveRecord::RecordNotFound
def georss
@traces = Trace.visible_to_all.visible
- if params[:display_name]
- @traces = @traces.joins(:user).where(:users => { :display_name => params[:display_name] })
- end
+ @traces = @traces.joins(:user).where(:users => { :display_name => params[:display_name] }) if params[:display_name]
@traces = @traces.tagged(params[:tag]) if params[:tag]
@traces = @traces.order("timestamp DESC")
if current_user
current_user.terms_seen = true
- if current_user.save
- flash[:notice] = t("user.new.terms declined", :url => t("user.new.terms declined url")).html_safe
- end
+ flash[:notice] = t("user.new.terms declined", :url => t("user.new.terms declined url")).html_safe if current_user.save
if params[:referer]
redirect_to params[:referer]
session[:new_user].auth_provider = provider
session[:new_user].auth_uid = uid
- if email_verified && email == session[:new_user].email
- session[:new_user].status = "active"
- end
+ session[:new_user].status = "active" if email_verified && email == session[:new_user].email
redirect_to :action => "terms"
else
end
def if_user(user, tag = :div, &block)
- if user
- content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}")
- end
+ content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}") if user
end
def unless_user(user, tag = :div, &block)
if current_user
data[:user] = current_user.id.to_json
- unless current_user.home_lon.nil? || current_user.home_lat.nil?
- data[:user_home] = { :lat => current_user.home_lat, :lon => current_user.home_lon }
- end
+ data[:user_home] = { :lat => current_user.home_lat, :lon => current_user.home_lon } unless current_user.home_lon.nil? || current_user.home_lat.nil?
end
data[:location] = session[:location] if session[:location]
object.id
end
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
- end
+ name = t "printable_name.with_version", :id => name, :version => object.version.to_s if version
# don't look at object tags if redacted, so as to avoid giving
# away redacted version tag information.
unless object.redacted?
locale = I18n.locale.to_s
- while locale =~ /-[^-]+/ && !object.tags.include?("name:#{I18n.locale}")
- locale = locale.sub(/-[^-]+/, "")
- end
+ locale = locale.sub(/-[^-]+/, "") while locale =~ /-[^-]+/ && !object.tags.include?("name:#{I18n.locale}")
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)
end
def delete_with_history!(new_relation, user)
- unless visible
- raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id)
- end
+ raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id) unless visible
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
Relation.transaction do
lock!
check_consistency(self, new_relation, user)
- unless new_relation.preconditions_ok?(members)
- raise OSM::APIPreconditionFailedError, "Cannot update relation #{id}: data or member data is invalid."
- end
+ raise OSM::APIPreconditionFailedError, "Cannot update relation #{id}: data or member data is invalid." unless new_relation.preconditions_ok?(members)
self.changeset_id = new_relation.changeset_id
self.changeset = new_relation.changeset
self.tags = new_relation.tags
def create_with_history(user)
check_create_consistency(self, user)
- unless preconditions_ok?
- raise OSM::APIPreconditionFailedError, "Cannot create relation: data or member data is invalid."
- end
+ raise OSM::APIPreconditionFailedError, "Cannot create relation: data or member data is invalid." unless preconditions_ok?
self.version = 0
self.visible = true
save_with_history!
element = model.lock("for share").find_by(:id => m[1])
# and check that it is OK to use.
- unless element && element.visible? && element.preconditions_ok?
- raise OSM::APIPreconditionFailedError, "Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}"
- end
+ raise OSM::APIPreconditionFailedError, "Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}" unless element && element.visible? && element.preconditions_ok?
hash[m[1]] = true
end
##
# perform a spam check on a user
def spam_check
- if status == "active" && spam_score > SPAM_THRESHOLD
- update(:status => "suspended")
- end
+ update(:status => "suspended") if status == "active" && spam_score > SPAM_THRESHOLD
end
##
way_nodes.each do |nd|
if visible_nodes
# if there is a list of visible nodes then use that to weed out deleted nodes
- if visible_nodes[nd.node_id]
- ordered_nodes[nd.sequence_id] = nd.node_id.to_s
- end
+ ordered_nodes[nd.sequence_id] = nd.node_id.to_s if visible_nodes[nd.node_id]
else
# otherwise, manually go to the db to check things
- if nd.node && nd.node.visible?
- ordered_nodes[nd.sequence_id] = nd.node_id.to_s
- end
+ ordered_nodes[nd.sequence_id] = nd.node_id.to_s if nd.node && nd.node.visible?
end
end
Way.transaction do
lock!
check_consistency(self, new_way, user)
- unless new_way.preconditions_ok?(nds)
- raise OSM::APIPreconditionFailedError, "Cannot update way #{id}: data is invalid."
- end
+ raise OSM::APIPreconditionFailedError, "Cannot update way #{id}: data is invalid." unless new_way.preconditions_ok?(nds)
self.changeset_id = new_way.changeset_id
self.changeset = new_way.changeset
def create_with_history(user)
check_create_consistency(self, user)
- unless preconditions_ok?
- raise OSM::APIPreconditionFailedError, "Cannot create way: data is invalid."
- end
+ raise OSM::APIPreconditionFailedError, "Cannot create way: data is invalid." unless preconditions_ok?
self.version = 0
self.visible = true
save_with_history!
def preconditions_ok?(old_nodes = [])
return false if nds.empty?
- if nds.length > MAX_NUMBER_OF_WAY_NODES
- raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES)
- end
+ raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES) if nds.length > MAX_NUMBER_OF_WAY_NODES
# check only the new nodes, for efficiency - old nodes having been checked last time and can't
# be deleted when they're in-use.
else
xml.tag! "contributor-terms", :agreed => @this_user.terms_agreed.present?
end
- if @this_user.image.file? || @this_user.image_use_gravatar
- xml.tag! "img", :href => user_image_url(@this_user, :size => 256)
- end
+ xml.tag! "img", :href => user_image_url(@this_user, :size => 256) if @this_user.image.file? || @this_user.image_use_gravatar
xml.tag! "roles" do
@this_user.roles.each do |role|
xml.tag! role.role
config.paths["app/models"].skip_eager_load! if STATUS == :database_offline
# Use memcached for caching if required
- if defined?(MEMCACHE_SERVERS)
- config.cache_store = :mem_cache_store, MEMCACHE_SERVERS, { :namespace => "rails:cache" }
- end
+ config.cache_store = :mem_cache_store, MEMCACHE_SERVERS, { :namespace => "rails:cache" } if defined?(MEMCACHE_SERVERS)
# Use logstash for logging if required
if defined?(LOGSTASH_PATH)
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
- unless STATUS == :database_offline
- config.active_record.migration_error = :page_load
- end
+ config.active_record.migration_error = :page_load unless STATUS == :database_offline
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
end
# Do not dump schema after migrations.
- unless STATUS == :database_offline
- config.active_record.dump_schema_after_migration = false
- end
+ config.active_record.dump_schema_after_migration = false unless STATUS == :database_offline
# Enable autoloading of dependencies.
config.enable_dependency_loading = true
class Cors < Rack::Cors
def call(env)
status, headers, body = super env
- if headers["Access-Control-Allow-Origin"]
- headers["Cache-Control"] = "no-cache"
- end
+ headers["Cache-Control"] = "no-cache" if headers["Access-Control-Allow-Origin"]
[status, headers, body]
end
end
github_options = { :name => "github", :scope => "user:email" }
wikipedia_options = { :name => "wikipedia", :client_options => { :site => "https://meta.wikimedia.org" } }
-if defined?(GOOGLE_OPENID_REALM)
- google_options[:openid_realm] = GOOGLE_OPENID_REALM
-end
+google_options[:openid_realm] = GOOGLE_OPENID_REALM if defined?(GOOGLE_OPENID_REALM)
Rails.application.config.middleware.use OmniAuth::Builder do
provider :openid, openid_options
# current version to something less so that we can update the version in
# batches of 10000
tbl.classify.constantize.update_all(:version => -1)
- while tbl.classify.constantize.where(:version => -1).count > 0
- tbl.classify.constantize.update_all("version=(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)", { :version => -1 }, { :limit => 10000 })
- end
+ tbl.classify.constantize.update_all("version=(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)", { :version => -1 }, { :limit => 10000 }) while tbl.classify.constantize.where(:version => -1).count > 0
# execute "UPDATE current_#{tbl} SET version = " +
# "(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)"
# The above update causes a MySQL error:
end
def self.from_bbox_params(params)
- if params[:bbox] && params[:bbox].count(",") == 3
- bbox_array = params[:bbox].split(",")
- end
+ bbox_array = params[:bbox].split(",") if params[:bbox] && params[:bbox].count(",") == 3
from_bbox_array(bbox_array)
end
def self.from_lon_lat_params(params)
- if params[:minlon] && params[:minlat] && params[:maxlon] && params[:maxlat]
- bbox_array = [params[:minlon], params[:minlat], params[:maxlon], params[:maxlat]]
- end
+ bbox_array = [params[:minlon], params[:minlat], params[:maxlon], params[:maxlat]] if params[:minlon] && params[:minlat] && params[:maxlon] && params[:maxlat]
from_bbox_array(bbox_array)
end
def self.from_lrbt_params(params)
- if params[:l] && params[:b] && params[:t] && params[:t]
- bbox_array = [params[:l], params[:b], params[:r], params[:t]]
- end
+ bbox_array = [params[:l], params[:b], params[:r], params[:t]] if params[:l] && params[:b] && params[:t] && params[:t]
from_bbox_array(bbox_array)
end
def check_boundaries
# check the bbox is sane
- if min_lon > max_lon
- raise OSM::APIBadBoundingBox, "The minimum longitude must be less than the maximum longitude, but it wasn't"
- end
- if min_lat > max_lat
- raise OSM::APIBadBoundingBox, "The minimum latitude must be less than the maximum latitude, but it wasn't"
- end
+ raise OSM::APIBadBoundingBox, "The minimum longitude must be less than the maximum longitude, but it wasn't" if min_lon > max_lon
+ raise OSM::APIBadBoundingBox, "The minimum latitude must be less than the maximum latitude, but it wasn't" if min_lat > max_lat
if min_lon < -LON_LIMIT || min_lat < -LAT_LIMIT || max_lon > +LON_LIMIT || max_lat > +LAT_LIMIT
raise OSM::APIBadBoundingBox, "The latitudes must be between #{-LAT_LIMIT} and #{LAT_LIMIT}," \
" and longitudes between #{-LON_LIMIT} and #{LON_LIMIT}"
private
def from_bbox_array(bbox_array)
- unless bbox_array
- raise OSM::APIBadUserInput, "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat"
- end
+ raise OSM::APIBadUserInput, "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat" unless bbox_array
# Take an array of length 4, create a bounding box with min_lon, min_lat, max_lon and
# max_lat within their respective boundaries.
min_lon = [[bbox_array[0].to_f, -LON_LIMIT].max, +LON_LIMIT].min
attributes = {}
if @reader.has_attributes?
- while @reader.move_to_next_attribute == 1
- attributes[@reader.name] = @reader.value
- end
+ attributes[@reader.name] = @reader.value while @reader.move_to_next_attribute == 1
@reader.move_to_element
end
# such as save_ and delete_with_history.
def check(model, xml, new)
raise OSM::APIBadXMLError.new(model, xml) if new.nil?
- unless new.changeset_id == @changeset.id
- raise OSM::APIChangesetMismatchError.new(new.changeset_id, @changeset.id)
- end
+ raise OSM::APIChangesetMismatchError.new(new.changeset_id, @changeset.id) unless new.changeset_id == @changeset.id
end
##
# Filter callback
def persist_session
- if session[session_persistence_key]
- request.session_options[:expire_after] = session[session_persistence_key]
- end
+ request.session_options[:expire_after] = session[session_persistence_key] if session[session_persistence_key]
rescue StandardError
reset_session
end
require "test_helper"
require "stringio"
-include Potlatch
class AmfControllerTest < ActionController::TestCase
+ include Potlatch
+
##
# test all routes which lead to this controller
def test_routes
# This node has no tags
# create a node with random lat/lon
- lat = rand(100) - 50 + rand
- lon = rand(100) - 50 + rand
+ lat = rand(-50..49) + rand
+ lon = rand(-50..49) + rand
changeset = create(:changeset)
user = changeset.user
# This node has some tags
# create a node with random lat/lon
- lat = rand(100) - 50 + rand
- lon = rand(100) - 50 + rand
+ lat = rand(-50..49) + rand
+ lon = rand(-50..49) + rand
amf_content "putpoi", "/2", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, { "key" => "value", "ping" => "pong" }, nil]
post :amf_write
# This node has no tags
# create a node with random lat/lon
- lat = rand(100) - 50 + rand
- lon = rand(100) - 50 + rand
+ lat = rand(-50..49) + rand
+ lon = rand(-50..49) + rand
changeset = create(:changeset)
user = changeset.user
# This node has no tags
# create a node with random lat/lon
- lat = rand(100) - 50 + rand
- lon = rand(100) - 50 + rand
+ lat = rand(-50..49) + rand
+ lon = rand(-50..49) + rand
changeset = create(:changeset)
user = changeset.user
assert_equal 2, Node.find(new_node_id).tags.size, "new node should have two tags"
assert_equal [new_node_id, node.id], Way.find(way.id).nds, "way nodes should match"
Relation.find(relation.id).members.each do |type, id, _role|
- if type == "node"
- assert_equal new_node_id, id, "relation should contain new node"
- end
+ assert_equal new_node_id, id, "relation should contain new node" if type == "node"
end
end
changeset = create(:changeset, :user => user)
# create a node with random lat/lon
- lat = rand(100) - 50 + rand
- lon = rand(100) - 50 + rand
+ lat = rand(-50..50) + rand
+ lon = rand(-50..50) + rand
## First try with no auth
# create a minimal xml file
class UserBlocksTest < ActionDispatch::IntegrationTest
def auth_header(user, pass)
- { "HTTP_AUTHORIZATION" => format("Basic %s", Base64.encode64("#{user}:#{pass}")) }
+ { "HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}")) }
end
def test_api_blocked
private
def auth_header(user, pass)
- { "HTTP_AUTHORIZATION" => format("Basic %s", Base64.encode64("#{user}:#{pass}")) }
+ { "HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}")) }
end
def with_terms_seen(value)
end
end
- if key =~ /^(active(model|record)\.)?errors\./
- variables.push("attribute")
- end
+ variables.push("attribute") if key =~ /^(active(model|record)\.)?errors\./
value = I18n.t(key, :locale => locale, :fallback => true)
##
# set request headers for HTTP basic authentication
def basic_authorization(user, pass)
- @request.env["HTTP_AUTHORIZATION"] = format("Basic %s", Base64.encode64("#{user}:#{pass}"))
+ @request.env["HTTP_AUTHORIZATION"] = format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}"))
end
##