Rails:
Enabled: true
+Layout/ExtraSpacing:
+ AllowForAlignment: true
+
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent
-Style/ExtraSpacing:
- AllowForAlignment: true
-
Style/FileName:
Exclude:
- 'script/deliver-message'
- 'script/locale/reload-languages'
- 'script/update-spam-blocks'
+Style/FormatStringToken:
+ EnforcedStyle: template
+
Style/IfInsideElse:
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
+Style/SymbolArray:
+ EnforcedStyle: brackets
+
+Rails/ApplicationRecord:
+ Enabled: false
+
Rails/HttpPositionalArguments:
Enabled: false
# Offense count: 62
# Configuration parameters: CountComments.
Metrics/ClassLength:
- Max: 1705
+ Max: 1782
# Offense count: 69
Metrics/CyclomaticComplexity:
gem "deadlock_retry", ">= 1.2.0"
gem "dynamic_form"
gem "http_accept_language", "~> 2.0.0"
-gem "i18n-js", ">= 3.0.0.rc10"
+gem "i18n-js", ">= 3.0.0"
gem "oauth-plugin", ">= 0.5.1"
gem "paperclip", "~> 4.0"
gem "rack-cors"
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
- addressable (2.5.0)
+ addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (6.0.4)
ast (2.3.0)
- autoprefixer-rails (6.7.7.1)
+ autoprefixer-rails (7.1.1)
execjs
bigdecimal (1.1.0)
builder (3.2.3)
- canonical-rails (0.1.2)
- rails (>= 4.1, < 5.1)
- capybara (2.13.0)
+ canonical-rails (0.2.0)
+ rails (>= 4.1, < 5.2)
+ capybara (2.14.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
- climate_control (0.1.0)
+ climate_control (0.2.0)
cliver (0.3.2)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
execjs
coffee-script-source (1.12.2)
colorize (0.8.1)
- composite_primary_keys (8.1.4)
+ composite_primary_keys (8.1.6)
activerecord (~> 4.2.0)
concurrent-ruby (1.0.5)
- coveralls (0.8.19)
+ coveralls (0.8.21)
json (>= 1.8, < 3)
- simplecov (~> 0.12.0)
+ simplecov (~> 0.14.1)
term-ansicolor (~> 1.3)
- thor (~> 0.19.1)
+ thor (~> 0.19.4)
tins (~> 1.6)
crack (0.4.3)
safe_yaml (~> 1.0.0)
multipart-post (>= 1.2, < 3)
fspath (3.1.0)
geoip (1.6.3)
- globalid (0.3.7)
- activesupport (>= 4.1.0)
- hashdiff (0.3.2)
+ globalid (0.4.0)
+ activesupport (>= 4.2.0)
+ hashdiff (0.3.4)
hashie (3.5.5)
htmlentities (4.3.4)
http_accept_language (2.0.5)
- i18n (0.8.1)
- i18n-js (3.0.0.rc16)
+ i18n (0.8.4)
+ i18n-js (3.0.0)
i18n (~> 0.6, >= 0.6.6)
- image_optim (0.24.2)
+ image_optim (0.24.3)
exifr (~> 1.2, >= 1.2.2)
fspath (~> 3.0)
image_size (~> 1.5)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
- image_optim_rails (0.3.0)
+ image_optim_rails (0.4.0)
image_optim (~> 0.24.0)
rails
sprockets
execjs (>= 1.4.0)
multi_json (~> 1.0)
therubyracer (~> 0.12.1)
- json (2.0.3)
+ json (2.1.0)
jsonify (0.3.1)
multi_json (~> 1.0)
jsonify-rails (0.3.2)
request_store
loofah (2.0.3)
nokogiri (>= 1.5.9)
- mail (2.6.4)
+ mail (2.6.5)
mime-types (>= 1.16, < 4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.0)
mini_portile2 (2.1.0)
- minitest (5.10.1)
+ minitest (5.10.2)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
- nokogiri (1.7.1)
+ nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
- nokogumbo (1.4.9)
+ nokogumbo (1.4.12)
nokogiri
oauth (0.4.7)
oauth-plugin (0.5.1)
oauth (~> 0.4.4)
oauth2 (>= 0.5.0)
rack
- oauth2 (1.3.0)
- faraday (>= 0.8, < 0.11)
+ oauth2 (1.3.1)
+ faraday (>= 0.8, < 0.12)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.6.2, < 3)
omniauth-facebook (4.0.0)
omniauth-oauth2 (~> 1.2)
- omniauth-github (1.2.3)
+ omniauth-github (1.3.0)
omniauth (~> 1.5)
omniauth-oauth2 (>= 1.4.0, < 2.0)
- omniauth-google-oauth2 (0.4.1)
- jwt (~> 1.5.2)
+ omniauth-google-oauth2 (0.5.0)
+ jwt (~> 1.5)
multi_json (~> 1.3)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.3.1)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
+ parallel (1.11.2)
parser (2.4.0.0)
ast (~> 2.2)
pg (0.20.0)
- poltergeist (1.14.0)
+ poltergeist (1.15.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
psych (2.2.4)
public_suffix (2.0.5)
r2 (0.2.6)
- rack (1.6.5)
+ rack (1.6.8)
rack-cors (0.4.1)
rack-openid (1.3.1)
rack (>= 1.1.0)
activesupport (= 4.2.8)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
- rainbow (2.2.1)
+ rainbow (2.2.2)
+ rake
rake (12.0.0)
redcarpet (3.4.0)
ref (2.0.0)
request_store (1.3.2)
rinku (2.0.2)
rotp (3.3.0)
- rubocop (0.47.1)
+ rubocop (0.49.1)
+ parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (~> 1.4.1)
- sass (3.4.23)
+ sass (3.4.24)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
- secure_headers (3.6.2)
+ secure_headers (3.6.4)
useragent
- simplecov (0.12.0)
+ simplecov (0.14.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
- simplecov-html (0.10.0)
+ simplecov-html (0.10.1)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
- term-ansicolor (1.4.0)
+ term-ansicolor (1.6.0)
tins (~> 1.0)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
thread_safe (0.3.6)
tilt (2.0.7)
timecop (0.8.1)
- tins (1.13.2)
- tzinfo (1.2.2)
+ tins (1.14.0)
+ tzinfo (1.2.3)
thread_safe (~> 0.1)
- uglifier (3.1.9)
+ uglifier (3.2.0)
execjs (>= 0.3.0, < 3)
- unicode-display_width (1.1.3)
+ unicode-display_width (1.2.1)
useragent (0.16.8)
validates_email_format_of (1.6.3)
i18n
vendorer (0.1.16)
- webmock (2.3.2)
+ webmock (3.0.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
- xpath (2.0.0)
+ xpath (2.1.0)
nokogiri (~> 1.3)
PLATFORMS
geoip
htmlentities
http_accept_language (~> 2.0.0)
- i18n-js (>= 3.0.0.rc10)
+ i18n-js (>= 3.0.0)
image_optim_rails
jquery-rails
jshint
response.headers["Content-Disposition"] = "attachment; filename=\"tracks.gpx\""
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
# This is probably the most common call of all. It is used for getting the
response.headers["Content-Disposition"] = "attachment; filename=\"map.osm\""
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
# Get a list of the tiles that have changed within a specified time
doc.root << changes
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
else
- render :text => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request
+ render :plain => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request
end
end
policy << blacklist
doc.root << policy
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
# External apps that use the api are able to query which permissions
if request.get?
redirect_to :controller => "user", :action => "login", :referer => request.fullpath
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
end
end
flash[:error] = t("application.require_moderator.not_a_moderator")
redirect_to :action => "index"
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
end
end
unless @user
# no auth, the user does not exist or the password was wrong
response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
- render :text => errormessage, :status => :unauthorized
+ render :plain => errormessage, :status => :unauthorized
return false
end
end
def authorize_moderator(errormessage = "Access restricted to moderators")
# check user is a moderator
unless @user.moderator?
- render :text => errormessage, :status => :forbidden
+ render :plain => errormessage, :status => :forbidden
false
end
end
result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}")
result.root << (XML::Node.new("message") << message)
- render :text => result.to_s, :content_type => "text/xml"
+ render :xml => result.to_s
else
- render :text => message, :status => status, :content_type => "text/plain"
+ render :plain => message, :status => status
end
end
def api_call_handle_error
yield
rescue ActiveRecord::RecordNotFound => ex
- render :text => "", :status => :not_found
+ head :not_found
rescue LibXML::XML::Error, ArgumentError => ex
report_error ex.message, :bad_request
rescue ActiveRecord::RecordInvalid => ex
respond_to do |format|
format.html { render :template => "user/no_such_user", :status => :not_found }
- format.all { render :text => "", :status => :not_found }
+ format.all { head :not_found }
end
end
def map_layout
append_content_security_policy_directives(
- :connect_src => %w(nominatim.openstreetmap.org overpass-api.de router.project-osrm.org valhalla.mapzen.com),
- :script_src => %w(graphhopper.com open.mapquestapi.com),
- :img_src => %w(developer.mapquest.com)
+ :connect_src => %w[nominatim.openstreetmap.org overpass-api.de router.project-osrm.org valhalla.mapzen.com],
+ :script_src => %w[graphhopper.com open.mapquestapi.com],
+ :img_src => %w[developer.mapquest.com]
)
if STATUS == :database_offline || STATUS == :api_offline
# Subscribe user to changeset comments
cs.subscribers << @user
- render :text => cs.id.to_s, :content_type => "text/plain"
+ render :plain => cs.id.to_s
end
##
def read
changeset = Changeset.find(params[:id])
- render :text => changeset.to_xml(params[:include_discussion].presence).to_s, :content_type => "text/xml"
+ render :xml => changeset.to_xml(params[:include_discussion].presence).to_s
end
##
changeset.set_closed_time_now
changeset.save!
- render :text => ""
+ render :nothing => true
end
##
# save the larger bounding box and return the changeset, which
# will include the bigger bounding box.
cs.save!
- render :text => cs.to_xml.to_s, :content_type => "text/xml"
+ render :xml => cs.to_xml.to_s
end
##
diff_reader = DiffReader.new(request.raw_post, changeset)
Changeset.transaction do
result = diff_reader.commit
- render :text => result.to_s, :content_type => "text/xml"
+ render :xml => result.to_s
end
end
end
end
- render :text => result.to_s, :content_type => "text/xml"
+ render :xml => result.to_s
end
##
results.root << cs.to_xml_node
end
- render :text => results.to_s, :content_type => "text/xml"
+ render :xml => results.to_s
end
##
check_changeset_consistency(changeset, @user)
changeset.update_from(new_changeset, @user)
- render :text => changeset.to_xml, :mime_type => "text/xml"
+ render :xml => changeset.to_xml
end
##
- # list edits (open changesets) in reverse chronological order
+ # list non-empty changesets in reverse chronological order
def list
- if request.format == :atom && params[:max_id]
- redirect_to url_for(params.merge(:max_id => nil)), :status => :moved_permanently
+ @params = params.permit(:display_name, :bbox, :friends, :nearby, :max_id, :list)
+
+ if request.format == :atom && @params[:max_id]
+ redirect_to url_for(@params.merge(:max_id => nil)), :status => :moved_permanently
return
end
- if params[:display_name]
- user = User.find_by(:display_name => params[:display_name])
+ if @params[:display_name]
+ user = User.find_by(:display_name => @params[:display_name])
if !user || !user.active?
- render_unknown_user params[:display_name]
+ render_unknown_user @params[:display_name]
return
end
end
- if (params[:friends] || params[:nearby]) && !@user
+ if (@params[:friends] || @params[:nearby]) && !@user
require_user
return
end
- if request.format == :html && !params[:list]
+ if request.format == :html && !@params[:list]
require_oauth
render :action => :history, :layout => map_layout
else
changesets = conditions_nonempty(Changeset.all)
- if params[:display_name]
+ if @params[:display_name]
changesets = if user.data_public? || user == @user
changesets.where(:user_id => user.id)
else
changesets.where("false")
end
- elsif params[:bbox]
+ elsif @params[:bbox]
changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
- elsif params[:friends] && @user
+ elsif @params[:friends] && @user
changesets = changesets.where(:user_id => @user.friend_users.identifiable)
- elsif params[:nearby] && @user
+ elsif @params[:nearby] && @user
changesets = changesets.where(:user_id => @user.nearby)
end
- if params[:max_id]
- changesets = changesets.where("changesets.id <= ?", params[:max_id])
+ if @params[:max_id]
+ changesets = changesets.where("changesets.id <= ?", @params[:max_id])
end
@edits = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
changeset.subscribers << @user unless changeset.subscribers.exists?(@user.id)
# Return a copy of the updated changeset
- render :text => changeset.to_xml.to_s, :content_type => "text/xml"
+ render :xml => changeset.to_xml.to_s
end
##
changeset.subscribers << @user
# Return a copy of the updated changeset
- render :text => changeset.to_xml.to_s, :content_type => "text/xml"
+ render :xml => changeset.to_xml.to_s
end
##
changeset.subscribers.delete(@user)
# Return a copy of the updated changeset
- render :text => changeset.to_xml.to_s, :content_type => "text/xml"
+ render :xml => changeset.to_xml.to_s
end
##
comment.update(:visible => false)
# Return a copy of the updated changeset
- render :text => comment.changeset.to_xml.to_s, :content_type => "text/xml"
+ render :xml => comment.changeset.to_xml.to_s
end
##
comment.update(:visible => true)
# Return a copy of the updated changeset
- render :text => comment.changeset.to_xml.to_s, :content_type => "text/xml"
+ render :xml => comment.changeset.to_xml.to_s
end
##
format.rss
end
rescue OSM::APIBadUserInput
- render :text => "", :status => :bad_request
+ head :bad_request
end
private
return
end
else
- @entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
+ @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
@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
+ head :not_found
return
end
else
- @entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
+ @entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })
if params[:language]
@entries = @entries.where(:language_code => params[:language])
before_action :require_oauth, :only => [:search]
def search
- normalize_params
-
+ @params = normalize_params
@sources = []
- if params[:lat] && params[:lon]
+ if @params[:lat] && @params[:lon]
@sources.push "latlon"
@sources.push "osm_nominatim_reverse"
@sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME)
- elsif params[:query]
- if params[:query] =~ /^\d{5}(-\d{4})?$/
+ elsif @params[:query]
+ if @params[:query] =~ /^\d{5}(-\d{4})?$/
@sources.push "us_postcode"
@sources.push "osm_nominatim"
- elsif params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
+ elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
@sources.push "uk_postcode"
@sources.push "osm_nominatim"
- elsif params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
+ elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
@sources.push "ca_postcode"
@sources.push "osm_nominatim"
else
end
if @sources.empty?
- render :text => "", :status => :bad_request
+ head :bad_request
else
render :layout => map_layout
end
end
def normalize_params
- query = params[:query]
- return unless query
-
- query.strip!
-
- if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees
- params.merge!(nsew_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW]
- params.merge!(nsew_to_decdeg(latlon)).delete(:query)
-
- elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes
- params.merge!(ddm_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW]
- params.merge!(ddm_to_decdeg(latlon)).delete(:query)
-
- elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds
- params.merge!(dms_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW]
- params.merge!(dms_to_decdeg(latlon)).delete(:query)
-
- elsif latlon = query.match(/^\s*([+-]?\d+(\.\d*)?)\s*[\s,]\s*([+-]?\d+(\.\d*)?)\s*$/)
- params.merge!(:lat => latlon[1].to_f, :lon => latlon[3].to_f).delete(:query)
+ if query = params[:query]
+ query.strip!
+
+ if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees
+ params.merge!(nsew_to_decdeg(latlon)).delete(:query)
+ elsif latlon = query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW]
+ params.merge!(nsew_to_decdeg(latlon)).delete(:query)
+
+ elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes
+ params.merge!(ddm_to_decdeg(latlon)).delete(:query)
+ elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW]
+ params.merge!(ddm_to_decdeg(latlon)).delete(:query)
+
+ elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds
+ params.merge!(dms_to_decdeg(latlon)).delete(:query)
+ elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW]
+ params.merge!(dms_to_decdeg(latlon)).delete(:query)
+
+ elsif latlon = query.match(/^\s*([+-]?\d+(\.\d*)?)\s*[\s,]\s*([+-]?\d+(\.\d*)?)\s*$/)
+ params.merge!(:lat => latlon[1].to_f, :lon => latlon[3].to_f).delete(:query)
+ end
end
+
+ params.permit(:query, :lat, :lon, :zoom, :minlat, :minlon, :maxlat, :maxlon)
end
def nsew_to_decdeg(captures)
# Assume that Node.from_xml has thrown an exception if there is an error parsing the xml
node.create_with_history @user
- render :text => node.id.to_s, :content_type => "text/plain"
+ render :plain => node.id.to_s
end
# Dump the details on a node given in params[:id]
response.last_modified = node.timestamp
if node.visible
- render :text => node.to_xml.to_s, :content_type => "text/xml"
+ render :xml => node.to_xml.to_s
else
- render :text => "", :status => :gone
+ head :gone
end
end
end
node.update_from(new_node, @user)
- render :text => node.version.to_s, :content_type => "text/plain"
+ render :plain => node.version.to_s
end
# Delete a node. Doesn't actually delete it, but retains its history
raise OSM::APIBadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
end
node.delete_with_history!(new_node, @user)
- render :text => node.version.to_s, :content_type => "text/plain"
+ render :plain => node.version.to_s
end
# Dump the details on many nodes whose ids are given in the "nodes" parameter.
doc.root << node.to_xml_node
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
end
else
@token.oob? ? @token.client_application.callback_url : @token.callback_url
end
- @redirect_url = URI.parse(callback_url) unless callback_url.blank?
+ @redirect_url = URI.parse(callback_url) if callback_url.present?
if @redirect_url.to_s.blank?
render :action => "authorize_success"
doc.root << element.to_xml_node
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
def version
if @old_element.redacted? && !show_redactions?
- render :text => "", :status => :forbidden
+ head :forbidden
else
response.last_modified = @old_element.timestamp
doc = OSM::API.new.get_xml_doc
doc.root << @old_element.to_xml_node
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
end
end
# just return an empty 200 OK for success
- render :text => ""
+ render :nothing => true
end
private
# Assume that Relation.from_xml has thrown an exception if there is an error parsing the xml
relation.create_with_history @user
- render :text => relation.id.to_s, :content_type => "text/plain"
+ render :plain => relation.id.to_s
end
def read
relation = Relation.find(params[:id])
response.last_modified = relation.timestamp
if relation.visible
- render :text => relation.to_xml.to_s, :content_type => "text/xml"
+ render :xml => relation.to_xml.to_s
else
- render :text => "", :status => :gone
+ head :gone
end
end
end
relation.update_from new_relation, @user
- render :text => relation.version.to_s, :content_type => "text/plain"
+ render :plain => relation.version.to_s
end
def delete
new_relation = Relation.from_xml(request.raw_post)
if new_relation && new_relation.id == relation.id
relation.delete_with_history!(new_relation, @user)
- render :text => relation.version.to_s, :content_type => "text/plain"
+ render :plain => relation.version.to_s
else
- render :text => "", :status => :bad_request
+ head :bad_request
end
end
# finally add self and output
doc.root << relation.to_xml_node(visible_members, changeset_cache, user_display_name_cache)
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
else
- render :text => "", :status => :gone
+ head :gone
end
end
doc.root << relation.to_xml_node
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
def relations_for_way
doc.root << relation.to_xml_node if relation.visible
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
end
if do_nodes
response.headers["Error"] = "Searching of nodes is currently unavailable"
- render :text => "", :status => :service_unavailable
+ head :service_unavailable
return false
end
unless value
response.headers["Error"] = "Searching for a key without value is currently unavailable"
- render :text => "", :status => :service_unavailable
+ head :service_unavailable
return false
end
doc.root << rel.to_xml_node(nil, changeset_cache, user_display_name_cache)
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
end
require_user
end
- if editor == "potlatch" || editor == "potlatch2"
+ if %w[potlatch potlatch2].include?(editor)
append_content_security_policy_directives(
- :object_src => %w(*),
- :plugin_types => %w(application/x-shockwave-flash),
- :script_src => %w('unsafe-inline')
+ :object_src => %w[*],
+ :plugin_types => %w[application/x-shockwave-flash],
+ :script_src => %w['unsafe-inline']
)
end
def offline; end
def preview
- render :text => RichText.new(params[:format], params[:text]).to_html
+ render :html => RichText.new(params[:format], params[:text]).to_html
end
def id
append_content_security_policy_directives(
- :connect_src => %w(taginfo.openstreetmap.org *.mapillary.com),
- :img_src => %w(*),
- :script_src => %w(dev.virtualearth.net)
+ :connect_src => %w[taginfo.openstreetmap.org *.mapillary.com],
+ :img_src => %w[*],
+ :script_src => %w[dev.virtualearth.net]
)
render "id", :layout => false
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
- render :text => m, :content_type => "application/x-shockwave-flash"
+ render :body => m, :content_type => "application/x-shockwave-flash"
end
private
def list
# from display name, pick up user id if one user's traces only
display_name = params[:display_name]
- unless display_name.blank?
+ if display_name.present?
target_user = User.active.where(:display_name => display_name).first
if target_user.nil?
render_unknown_user display_name
if trace.visible? && (trace.public? || (@user && @user == trace.user))
if Acl.no_trace_download(request.remote_ip)
- render :text => "", :status => :forbidden
+ head :forbidden
elsif request.format == Mime::XML
send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
elsif request.format == Mime::GPX
send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
else
- render :text => "", :status => :not_found
+ head :not_found
end
rescue ActiveRecord::RecordNotFound
- render :text => "", :status => :not_found
+ head :not_found
end
def edit
@trace = Trace.find(params[:id])
if !@trace.visible?
- render :text => "", :status => :not_found
+ head :not_found
elsif @user.nil? || @trace.user != @user
- render :text => "", :status => :forbidden
+ head :forbidden
else
@title = t "trace.edit.title", :name => @trace.name
end
end
rescue ActiveRecord::RecordNotFound
- render :text => "", :status => :not_found
+ head :not_found
end
def delete
trace = Trace.find(params[:id])
if !trace.visible?
- render :text => "", :status => :not_found
+ head :not_found
elsif @user.nil? || trace.user != @user
- render :text => "", :status => :forbidden
+ head :forbidden
else
trace.visible = false
trace.save
redirect_to :action => :list, :display_name => @user.display_name
end
rescue ActiveRecord::RecordNotFound
- render :text => "", :status => :not_found
+ head :not_found
end
def georss
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")
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
else
- render :text => "", :status => :not_found
+ head :not_found
end
rescue ActiveRecord::RecordNotFound
- render :text => "", :status => :not_found
+ head :not_found
end
def icon
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")
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
else
- render :text => "", :status => :not_found
+ head :not_found
end
rescue ActiveRecord::RecordNotFound
- render :text => "", :status => :not_found
+ head :not_found
end
def api_read
trace = Trace.visible.find(params[:id])
if trace.public? || trace.user == @user
- render :text => trace.to_xml.to_s, :content_type => "text/xml"
+ render :xml => trace.to_xml.to_s
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
end
trace.visibility = new_trace.visibility
trace.save!
- render :text => "", :status => :ok
+ head :ok
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
end
trace.visible = false
trace.save!
- render :text => "", :status => :ok
+ head :ok
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
end
send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
else
- render :text => "", :status => :forbidden
+ head :forbidden
end
end
do_create(params[:file], tags, description, visibility)
if @trace.id
- render :text => @trace.id.to_s, :content_type => "text/plain"
+ render :plain => @trace.id.to_s
elsif @trace.valid?
- render :text => "", :status => :internal_server_error
+ head :internal_server_error
else
- render :text => "", :status => :bad_request
+ head :bad_request
end
else
- render :text => "", :status => :bad_request
+ head :bad_request
end
end
@user.terms_agreed = Time.now.getutc
@user.terms_seen = true
- if @user.auth_uid.nil? || @user.auth_uid.empty?
+ if @user.auth_uid.blank?
@user.auth_provider = nil
@user.auth_uid = nil
end
redirect_to :action => "lost_password"
end
else
- render :text => "", :status => :bad_request
+ head :bad_request
end
end
if @this_user.visible?
render :action => :api_read, :content_type => "text/xml"
else
- render :text => "", :status => :gone
+ head :gone
end
end
@user.traces.reload.each do |trace|
doc.root << trace.to_xml_node
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
def view
if @friend
if request.post?
if @user.is_friends_with?(@friend)
- Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{@friend.id}"
+ Friend.where(:user_id => @user.id, :friend_user_id => @friend.id).delete_all
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
redirect_to url_for(:status => params[:status], :ip => params[:ip], :page => params[:page])
else
+ @params = params.permit(:status, :ip)
+
conditions = {}
- conditions[:status] = params[:status] if params[:status]
- conditions[:creation_ip] = params[:ip] if params[:ip]
+ conditions[:status] = @params[:status] if @params[:status]
+ conditions[:creation_ip] = @params[:ip] if @params[:ip]
@user_pages, @users = paginate(:users,
:conditions => conditions,
##
# require that the user in the URL is the logged in user
def require_self
- if params[:display_name] != @user.display_name
- render :text => "", :status => :forbidden
- end
+ head :forbidden if params[:display_name] != @user.display_name
end
##
end
doc.root << el1
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
##
def read_one
pref = UserPreference.find([@user.id, params[:preference_key]])
- render :text => pref.v.to_s, :content_type => "text/plain"
+ render :plain => pref.v.to_s
end
# update the entire set of preferences
new_preferences.each_value(&:save!)
- render :text => "", :content_type => "text/plain"
+ render :nothing => true, :content_type => "text/plain"
end
##
pref.v = request.raw_post.chomp
pref.save!
- render :text => "", :content_type => "text/plain"
+ render :nothing => true, :content_type => "text/plain"
end
##
def delete_one
UserPreference.find([@user.id, params[:preference_key]]).delete
- render :text => "", :content_type => "text/plain"
+ render :nothing => true, :content_type => "text/plain"
end
end
end
def revoke
- UserRole.delete_all(:user_id => @this_user.id, :role => @role)
+ UserRole.where(:user_id => @this_user.id, :role => @role).delete_all
redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
end
# Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
way.create_with_history @user
- render :text => way.id.to_s, :content_type => "text/plain"
+ render :plain => way.id.to_s
end
def read
response.last_modified = way.timestamp
if way.visible
- render :text => way.to_xml.to_s, :content_type => "text/xml"
+ render :xml => way.to_xml.to_s
else
- render :text => "", :status => :gone
+ head :gone
end
end
end
way.update_from(new_way, @user)
- render :text => way.version.to_s, :content_type => "text/plain"
+ render :plain => way.version.to_s
end
# This is the API call to delete a way
if new_way && new_way.id == way.id
way.delete_with_history!(new_way, @user)
- render :text => way.version.to_s, :content_type => "text/plain"
+ render :plain => way.version.to_s
else
- render :text => "", :status => :bad_request
+ head :bad_request
end
end
end
doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
else
- render :text => "", :status => :gone
+ head :gone
end
end
doc.root << way.to_xml_node
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
##
doc.root << way.to_xml_node if way.visible
end
- render :text => doc.to_s, :content_type => "text/xml"
+ render :xml => doc.to_s
end
end
private
- ICON_TAGS = %w(aeroway amenity barrier building highway historic landuse leisure man_made natural railway shop tourism waterway).freeze
+ ICON_TAGS = %w[aeroway amenity barrier building highway historic landuse leisure man_made natural railway shop tourism waterway].freeze
def icon_tags(object)
object.tags.find_all { |k, _v| ICON_TAGS.include? k }.sort
save!
tags = self.tags
- ChangesetTag.delete_all(:changeset_id => id)
+ ChangesetTag.where(:changeset_id => id).delete_all
tags.each do |k, v|
tag = ChangesetTag.new
# this is the set of permissions that the client can ask for. clients
# have to say up-front what permissions they want and when users sign up they
# can agree or not agree to each of them.
- PERMISSIONS = [:allow_read_prefs, :allow_write_prefs, :allow_write_diary,
- :allow_write_api, :allow_read_gpx, :allow_write_gpx,
- :allow_write_notes].freeze
+ PERMISSIONS = [:allow_read_prefs, :allow_write_prefs, :allow_write_diary, :allow_write_api, :allow_read_gpx, :allow_write_gpx, :allow_write_notes].freeze
def generate_keys
self.key = OAuth::Helper.generate_key(40)[0, 40]
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"
+ has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => %w[active confirmed] }).order(:id) }, :class_name => "DiaryComment"
has_many :subscriptions, :class_name => "DiaryEntrySubscription"
has_many :subscribers, :through => :subscriptions, :source => :user
# Create a NodeTag
tags = self.tags
- NodeTag.delete_all(:node_id => id)
+ NodeTag.where(:node_id => id).delete_all
tags.each do |k, v|
tag = NodeTag.new
tag.node_id = id
:numericality => { :on => :update, :integer_only => true }
validates :latitude, :longitude, :numericality => { :only_integer => true }
validates :closed_at, :presence => true, :if => proc { :status == "closed" }
- validates :status, :inclusion => %w(open closed hidden)
+ validates :status, :inclusion => %w[open closed hidden]
validate :validate_position
validates :note, :presence => true, :associated => true
validates :visible, :inclusion => [true, false]
validates :author, :associated => true
- validates :event, :inclusion => %w(opened closed reopened commented hidden)
+ validates :event, :inclusion => %w[opened closed reopened commented hidden]
validates :body, :format => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
# Return the comment text
has_many :old_relations
validates :description, :presence => true
- validates :description_format, :inclusion => { :in => %w(text html markdown) }
+ validates :description_format, :inclusion => { :in => %w[text html markdown] }
# this method overrides the AR default to provide the rich
# text object for the description field.
scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }
- TYPES = %w(node way relation).freeze
+ TYPES = %w[node way relation].freeze
def self.from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
# if there are left-over tags then they are new and will have to
# be added.
tags_changed |= !tags.empty?
- RelationTag.delete_all(:relation_id => id)
+ RelationTag.where(:relation_id => id).delete_all
self.tags.each do |k, v|
tag = RelationTag.new
tag.relation_id = id
# members may be in a different order and i don't feel like implementing
# a longest common subsequence algorithm to optimise this.
members = self.members
- RelationMember.delete_all(:relation_id => id)
+ RelationMember.where(:relation_id => id).delete_all
members.each_with_index do |m, i|
mem = RelationMember.new
mem.relation_id = id
scope :visible, -> { where(:visible => true) }
scope :visible_to, ->(u) { visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
- scope :visible_to_all, -> { where(:visibility => %w(public identifiable)) }
+ scope :visible_to_all, -> { where(:visibility => %w[public identifiable]) }
scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
validates :user, :presence => true, :associated => true
validates :name, :presence => true, :length => 1..255
validates :description, :presence => { :on => :create }, :length => 1..255
validates :timestamp, :presence => true
- validates :visibility, :inclusion => %w(private public trackable identifiable)
+ validates :visibility, :inclusion => %w[private public trackable identifiable]
def destroy
super
def tagstring=(s)
self.tags = if s.include? ","
- s.split(/\s*,\s*/).select { |tag| tag !~ /^\s*$/ }.collect do |tag|
+ s.split(/\s*,\s*/).reject { |tag| tag =~ /^\s*$/ }.collect do |tag|
tt = Tracetag.new
tt.tag = tag
tt
first = true
# If there are any existing points for this trace then delete them
- Tracepoint.delete_all(:gpx_id => id)
+ Tracepoint.where(:gpx_id => id).delete_all
gpx.points do |point|
if first
has_many :messages, -> { where(:to_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :foreign_key => :to_user_id
has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id
has_many :sent_messages, -> { where(:from_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :class_name => "Message", :foreign_key => :from_user_id
- has_many :friends, -> { joins(:befriendee).where(:users => { :status => %w(active confirmed) }) }
+ has_many :friends, -> { joins(:befriendee).where(:users => { :status => %w[active confirmed] }) }
has_many :friend_users, :through => :friends, :source => :befriendee
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
has_many :roles, :class_name => "UserRole"
- scope :visible, -> { where(:status => %w(pending active confirmed)) }
- scope :active, -> { where(:status => %w(active confirmed)) }
+ scope :visible, -> { where(:status => %w[pending active confirmed]) }
+ scope :active, -> { where(:status => %w[active confirmed]) }
scope :identifiable, -> { where(:data_public => true) }
has_attached_file :image,
:styles => { :large => "100x100>", :small => "50x50>" }
validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
- :exclusion => %w(new terms save confirm confirm-email go_public reset-password forgot-password suspended)
+ :exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
validates :display_name, :if => proc { |u| u.display_name_changed? },
:uniqueness => { :case_sensitive => false }
validates :display_name, :if => proc { |u| u.display_name_changed? },
##
# returns true if a user is visible
def visible?
- %w(pending active confirmed).include? status
+ %w[pending active confirmed].include? status
end
##
# returns true if a user is active
def active?
- %w(active confirmed).include? status
+ %w[active confirmed].include? status
end
##
belongs_to :user
belongs_to :granter, :class_name => "User"
- ALL_ROLES = %w(administrator moderator).freeze
+ ALL_ROLES = %w[administrator moderator].freeze
validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id }
end
clone.save!
tags = self.tags
- WayTag.delete_all(:way_id => id)
+ WayTag.where(:way_id => id).delete_all
tags.each do |k, v|
tag = WayTag.new
tag.way_id = id
end
nds = self.nds
- WayNode.delete_all(:way_id => id)
+ WayNode.where(:way_id => id).delete_all
sequence = 1
nds.each do |n|
nd = WayNode.new
atom_feed(:language => I18n.locale, :schema_date => 2009,
- :id => url_for(params.merge(:only_path => false)),
- :root_url => url_for(params.merge(:action => :list, :format => nil, :only_path => false)),
+ :id => url_for(@params.merge(:only_path => false)),
+ :root_url => url_for(@params.merge(:action => :list, :format => nil, :only_path => false)),
"xmlns:georss" => "http://www.georss.org/georss") do |feed|
feed.title changeset_list_title(params, @user)
</h2>
<% @sources.each do |source| %>
<h4 class="inner12"><%= raw(t "geocoder.search.title.#{source}") %></h4>
- <div class="search_results_entry" data-href="<%= url_for params.merge(:action => "search_#{source}") %>">
+ <div class="search_results_entry" data-href="<%= url_for @params.merge(:action => "search_#{source}") %>">
<%= image_tag "searching.gif", :class => "loader" %>
</div>
<% end %>
<% if @user && @user.id %>
<div class='dropdown user-menu logged-in'>
<a class='dropdown-toggle' data-toggle='dropdown' href="#">
- <%= user_thumbnail_tiny(@user, :size => 25, :width => 25, :height => 25)
+ <%= user_thumbnail_tiny(@user, :width => 25, :height => 25)
%><%= render :partial => 'layouts/inbox'
%><span class="user-button"><span class='username'><%= @user.display_name %></span>
<b class="caret"></b></span>
<div class='message-buttons buttons'>
<%= button_to t('message.read.reply_button'), {:controller => 'message', :action => 'reply', :message_id => @message.id}, :class => 'reply-button' %>
<%= button_to t('message.read.unread_button'), {:controller => 'message', :action => 'mark', :message_id => @message.id, :mark => 'unread'}, :class => 'mark-unread-button' %>
+ <%= button_to "Delete", {:controller => 'message', :action => 'delete', :message_id => @message.id}, :class => 'delete-button' %>
<% else %>
:count => @user_pages.current_page.last_item - @user_pages.current_page.first_item + 1
%>
<% if @user_pages.page_count > 1 %>
- | <%= raw pagination_links_each(@user_pages, {}) { |n| link_to n, params.merge(:page => n) } %>
+ | <%= raw pagination_links_each(@user_pages, {}) { |n| link_to n, @params.merge(:page => n) } %>
<% end %>
</td>
<td>
config.active_record.raise_in_transactional_callbacks = true unless STATUS == :database_offline
# Custom directories with classes and modules you want to be autoloadable.
- config.autoload_paths += %W(#{config.root}/lib)
+ config.autoload_paths += %W[#{config.root}/lib]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
if defined?(ActiveRecord::ConnectionAdaptors::AbstractAdapter)
- module ActiveRecord
- module ConnectionAdapters
- class AbstractAdapter
- protected
-
- alias old_log log
-
- def translate_exception_class_with_timeout(e, sql)
+ module OpenStreetMap
+ module AbstractAdapter
+ module PropagateTimeouts
+ def translate_exception_class(e, sql)
if e.is_a?(Timeout::Error) || e.is_a?(OSM::APITimeoutError)
e
else
- translate_exception_class_without_timeout(e, sql)
+ super(e, sql)
end
end
-
- alias_method_chain :translate_exception_class, :timeout
end
end
end
+
+ ActiveRecord::ConnectionAdaptors::AbstractAdapter.prepend(OpenStreetMap::AbstractAdapter::PropagateTimeouts)
end
# Stop rails from automatically parsing XML in request bodies
Rails.configuration.middleware.delete ActionDispatch::ParamsParser
-
-# https://github.com/rails/rails/issues/20710
-module ActionDispatch
- module Assertions
- def html_document_with_rss
- @html_document ||= if @response.content_type == Mime::RSS
- Nokogiri::XML::Document.parse(@response.body)
- else
- html_document_without_rss
- end
- end
-
- alias_method_chain :html_document, :rss
- end
-end
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
-Rails.application.config.assets.precompile += %w(index.js browse.js welcome.js fixthemap.js)
-Rails.application.config.assets.precompile += %w(user.js login.js diary_entry.js edit/*.js)
-Rails.application.config.assets.precompile += %w(screen-ltr.css print-ltr.css)
-Rails.application.config.assets.precompile += %w(screen-rtl.css print-rtl.css)
-Rails.application.config.assets.precompile += %w(leaflet-all.css leaflet.ie.css)
-Rails.application.config.assets.precompile += %w(id.js id.css)
-Rails.application.config.assets.precompile += %w(embed.js embed.css)
-Rails.application.config.assets.precompile += %w(html5shiv.js)
-Rails.application.config.assets.precompile += %w(images/marker-*.png img/*-handle.png)
-Rails.application.config.assets.precompile += %w(swfobject.js expressInstall.swf)
-Rails.application.config.assets.precompile += %w(potlatch2.swf)
-Rails.application.config.assets.precompile += %w(potlatch2/assets.zip)
-Rails.application.config.assets.precompile += %w(potlatch2/FontLibrary.swf)
-Rails.application.config.assets.precompile += %w(potlatch2/locales/*.swf)
-Rails.application.config.assets.precompile += %w(help/introduction.*)
-Rails.application.config.assets.precompile += %w(iD/img/*.svg iD/img/*.png iD/img/*.gif)
-Rails.application.config.assets.precompile += %w(iD/img/pattern/*.png)
-Rails.application.config.assets.precompile += %w(iD/locales/*.json)
-Rails.application.config.assets.precompile += %w(iD/traffico/stylesheets/traffico.css)
-Rails.application.config.assets.precompile += %w(iD/traffico/fonts/traffico_*)
-Rails.application.config.assets.precompile += %w(iD/traffico/string-maps/*.json)
+Rails.application.config.assets.precompile += %w[index.js browse.js welcome.js fixthemap.js]
+Rails.application.config.assets.precompile += %w[user.js login.js diary_entry.js edit/*.js]
+Rails.application.config.assets.precompile += %w[screen-ltr.css print-ltr.css]
+Rails.application.config.assets.precompile += %w[screen-rtl.css print-rtl.css]
+Rails.application.config.assets.precompile += %w[leaflet-all.css leaflet.ie.css]
+Rails.application.config.assets.precompile += %w[id.js id.css]
+Rails.application.config.assets.precompile += %w[embed.js embed.css]
+Rails.application.config.assets.precompile += %w[html5shiv.js]
+Rails.application.config.assets.precompile += %w[images/marker-*.png img/*-handle.png]
+Rails.application.config.assets.precompile += %w[swfobject.js expressInstall.swf]
+Rails.application.config.assets.precompile += %w[potlatch2.swf]
+Rails.application.config.assets.precompile += %w[potlatch2/assets.zip]
+Rails.application.config.assets.precompile += %w[potlatch2/FontLibrary.swf]
+Rails.application.config.assets.precompile += %w[potlatch2/locales/*.swf]
+Rails.application.config.assets.precompile += %w[help/introduction.*]
+Rails.application.config.assets.precompile += %w[iD/img/*.svg iD/img/*.png iD/img/*.gif]
+Rails.application.config.assets.precompile += %w[iD/img/pattern/*.png]
+Rails.application.config.assets.precompile += %w[iD/locales/*.json]
+Rails.application.config.assets.precompile += %w[iD/traffico/stylesheets/traffico.css]
+Rails.application.config.assets.precompile += %w[iD/traffico/fonts/traffico_*]
+Rails.application.config.assets.precompile += %w[iD/traffico/string-maps/*.json]
ex.entry[:other]
end
end
+ end
+end
- class Simple
- def store_translations_with_normalisation(locale, data, options = {})
- locale = I18n::Locale::Tag::Rfc4646.tag(locale).to_s
+module OpenStreetMap
+ module I18n
+ module NormaliseLocales
+ def store_translations(locale, data, options = {})
+ locale = ::I18n::Locale::Tag::Rfc4646.tag(locale).to_s
- store_translations_without_normalisation(locale, data, options)
+ super(locale, data, options)
end
-
- alias_method_chain :store_translations, :normalisation
end
- end
- module JS
- class FallbackLocales
- def default_fallbacks_with_validation
- default_fallbacks_without_validation.select do |locale|
+ module ValidateLocales
+ def default_fallbacks
+ super.select do |locale|
::I18n.available_locales.include?(locale)
end
end
-
- alias_method_chain :default_fallbacks, :validation
end
end
end
+I18n::Backend::Simple.prepend(OpenStreetMap::I18n::NormaliseLocales)
+I18n::JS::FallbackLocales.prepend(OpenStreetMap::I18n::ValidateLocales)
+
I18n::Backend::Simple.include(I18n::Backend::PluralizationFallback)
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
provider :github, GITHUB_AUTH_ID, GITHUB_AUTH_SECRET, github_options if defined?(GITHUB_AUTH_ID)
provider :mediawiki, WIKIPEDIA_AUTH_ID, WIKIPEDIA_AUTH_SECRET, wikipedia_options if defined?(WIKIPEDIA_AUTH_ID)
end
-
-# Pending fix for: https://github.com/intridea/omniauth/pull/795
-module OmniAuth
- module Strategy
- def mock_callback_call_with_origin
- @env["omniauth.origin"] = session["omniauth.origin"]
-
- mock_callback_call_without_origin
- end
-
- alias_method_chain :mock_callback_call, :origin
- end
-end
# Some versions of ruby seem to accidentally force the encoding
# as part of normalize_path and some don't
-module ActionDispatch
- module Journey
- class Router
- class Utils
- def self.normalize_path_with_encoding(path)
- normalize_path_without_encoding(path).force_encoding("UTF-8")
- end
-
- class << self
- alias_method_chain :normalize_path, :encoding
- end
+module OpenStreetMap
+ module Router
+ module ForceEncoding
+ def normalize_path(path)
+ super(path).force_encoding("UTF-8")
end
end
end
end
+
+ActionDispatch::Journey::Router::Utils.singleton_class.prepend(OpenStreetMap::Router::ForceEncoding)
Sanitize::Config::OSM = Sanitize::Config::RELAXED.dup
-Sanitize::Config::OSM[:elements] -= %w(div style)
+Sanitize::Config::OSM[:elements] -= %w[div style]
Sanitize::Config::OSM[:add_attributes] = { "a" => { "rel" => "nofollow" } }
-Sanitize::Config::OSM[:remove_contents] = %w(script style)
+Sanitize::Config::OSM[:remove_contents] = %w[script style]
if defined?(CSP_REPORT_URL)
policy = {
- :default_src => %w('self'),
- :child_src => %w('self'),
- :connect_src => %w('self'),
- :font_src => %w('none'),
- :form_action => %w('self'),
- :frame_ancestors => %w('self'),
- :img_src => %w('self' data: www.gravatar.com *.wp.com *.tile.openstreetmap.org *.tile.thunderforest.com *.openstreetmap.fr),
- :media_src => %w('none'),
- :object_src => %w('self'),
- :plugin_types => %w('none'),
- :script_src => %w('self'),
- :style_src => %w('self' 'unsafe-inline'),
+ :default_src => %w['self'],
+ :child_src => %w['self'],
+ :connect_src => %w['self'],
+ :font_src => %w['none'],
+ :form_action => %w['self'],
+ :frame_ancestors => %w['self'],
+ :img_src => %w['self' data: www.gravatar.com *.wp.com *.tile.openstreetmap.org *.tile.thunderforest.com *.openstreetmap.fr],
+ :media_src => %w['none'],
+ :object_src => %w['self'],
+ :plugin_types => %w['none'],
+ :script_src => %w['self'],
+ :style_src => %w['self' 'unsafe-inline'],
:report_uri => [CSP_REPORT_URL]
}
+++ /dev/null
-module ActionDispatch
- class Request < Rack::Request
- class Session
- def clear_with_rescue
- clear_without_rescue
- rescue
- # lets not worry about it...
- end
-
- alias_method_chain :clear, :rescue
- end
- end
-end
end
add_index "current_nodes", ["id"], :name => "current_nodes_id_idx"
- add_index "current_nodes", %w(latitude longitude), :name => "current_nodes_lat_lon_idx"
+ add_index "current_nodes", %w[latitude longitude], :name => "current_nodes_lat_lon_idx"
add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
create_table "current_segments", :id => false do |t|
t.column "timestamp", :datetime
end
- add_index "current_segments", %w(id visible), :name => "current_segments_id_visible_idx"
+ add_index "current_segments", %w[id visible], :name => "current_segments_id_visible_idx"
add_index "current_segments", ["node_a"], :name => "current_segments_a_idx"
add_index "current_segments", ["node_b"], :name => "current_segments_b_idx"
t.column "timestamp", :datetime
end
- add_index "gps_points", %w(latitude longitude user_id), :name => "points_idx"
+ add_index "gps_points", %w[latitude longitude user_id], :name => "points_idx"
add_index "gps_points", ["user_id"], :name => "points_uid_idx"
add_index "gps_points", ["gpx_id"], :name => "points_gpxid_idx"
end
add_index "gpx_files", ["timestamp"], :name => "gpx_files_timestamp_idx"
- add_index "gpx_files", %w(visible public), :name => "gpx_files_visible_public_idx"
+ add_index "gpx_files", %w[visible public], :name => "gpx_files_visible_public_idx"
create_table "gpx_pending_files", :id => false do |t|
t.column "originalname", :string
end
add_index "nodes", ["id"], :name => "nodes_uid_idx"
- add_index "nodes", %w(latitude longitude), :name => "nodes_latlon_idx"
+ add_index "nodes", %w[latitude longitude], :name => "nodes_latlon_idx"
create_table "segments", :id => false do |t|
t.column "id", :bigint
t.column "sequence_id", :bigint, :null => false
end
- add_primary_key "way_segments", %w(id version sequence_id)
+ add_primary_key "way_segments", %w[id version sequence_id]
create_table "way_tags", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "version", :bigint
end
- add_index "way_tags", %w(id version), :name => "way_tags_id_version_idx"
+ add_index "way_tags", %w[id version], :name => "way_tags_id_version_idx"
create_table "ways", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "visible", :boolean, :default => true
end
- add_primary_key "ways", %w(id version)
+ add_primary_key "ways", %w[id version]
add_index "ways", ["id"], :name => "ways_id_version_idx"
end
change_column "current_way_segments", "id", :bigint, :null => false
change_column "current_way_segments", "segment_id", :bigint, :null => false
change_column "current_way_segments", "sequence_id", :bigint, :null => false
- add_primary_key "current_way_segments", %w(id sequence_id)
+ add_primary_key "current_way_segments", %w[id sequence_id]
remove_index "current_way_segments", :name => "current_way_segments_id_idx"
change_column "current_way_tags", "id", :bigint, :null => false
remove_index "gps_points", :name => "points_uid_idx"
remove_index "gps_points", :name => "points_idx"
remove_column "gps_points", "user_id"
- add_index "gps_points", %w(latitude longitude), :name => "points_idx"
+ add_index "gps_points", %w[latitude longitude], :name => "points_idx"
change_column "gps_points", "trackid", :integer, :null => false
change_column "gps_points", "latitude", :integer, :null => false
change_column "gps_points", "longitude", :integer, :null => false
change_column "current_way_segments", "segment_id", :bigint
change_column "current_way_segments", "id", :bigint
- add_index "current_segments", %w(id visible), :name => "current_segments_id_visible_idx"
+ add_index "current_segments", %w[id visible], :name => "current_segments_id_visible_idx"
remove_primary_key "current_segments"
change_column "current_segments", "timestamp", :datetime
change_column "current_segments", "visible", :boolean
t.column "v", :string, :null => false
end
- add_primary_key "user_preferences", %w(user_id k)
+ add_primary_key "user_preferences", %w[user_id k]
create_table "user_tokens", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
def self.down
Tracepoint.update_all("latitude = latitude / 10, longitude = longitude / 10")
- add_index "gps_points", %w(latitude longitude), :name => "points_idx"
+ add_index "gps_points", %w[latitude longitude], :name => "points_idx"
remove_index "gps_points", :name => "points_tile_idx"
remove_column "gps_points", "tile"
end
t.column "timestamp", :datetime, :null => false
end
- add_index "current_nodes", %w(latitude longitude), :name => "current_nodes_lat_lon_idx"
+ add_index "current_nodes", %w[latitude longitude], :name => "current_nodes_lat_lon_idx"
add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
downgrade_table "current_nodes_v6", "current_nodes"
end
add_index "nodes", ["id"], :name => "nodes_uid_idx"
- add_index "nodes", %w(latitude longitude), :name => "nodes_latlon_idx"
+ add_index "nodes", %w[latitude longitude], :name => "nodes_latlon_idx"
add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
downgrade_table "nodes_v6", "nodes"
class AddRelations < ActiveRecord::Migration
def self.up
# enums work like strings but are more efficient
- create_enumeration :nwr_enum, %w(Node Way Relation)
+ create_enumeration :nwr_enum, %w[Node Way Relation]
# a relation can have members much like a way can have nodes.
# differences:
t.column "member_role", :string
end
- add_primary_key "current_relation_members", %w(id member_type member_id member_role)
- add_index "current_relation_members", %w(member_type member_id), :name => "current_relation_members_member_idx"
+ add_primary_key "current_relation_members", %w[id member_type member_id member_role]
+ add_index "current_relation_members", %w[member_type member_id], :name => "current_relation_members_member_idx"
# the following is obsolete given the primary key, is it not?
# add_index "current_relation_members", ["id"], :name => "current_relation_members_id_idx"
create_table "current_relation_tags", :id => false do |t|
t.column "version", :bigint, :default => 0, :null => false
end
- add_primary_key "relation_members", %w(id version member_type member_id member_role)
- add_index "relation_members", %w(member_type member_id), :name => "relation_members_member_idx"
+ add_primary_key "relation_members", %w[id version member_type member_id member_role]
+ add_index "relation_members", %w[member_type member_id], :name => "relation_members_member_idx"
create_table "relation_tags", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "version", :bigint, :null => false
end
- add_index "relation_tags", %w(id version), :name => "relation_tags_id_version_idx"
+ add_index "relation_tags", %w[id version], :name => "relation_tags_id_version_idx"
create_table "relations", :id => false do |t|
t.column "id", :bigint, :null => false, :default => 0
t.column "visible", :boolean, :null => false, :default => true
end
- add_primary_key "relations", %w(id version)
+ add_primary_key "relations", %w[id version]
add_index "relations", ["timestamp"], :name => "relations_timestamp_idx"
end
args = conn_opts.map(&:to_s) + [prefix]
raise "#{cmd} failed" unless system cmd, *args
- tempfiles = %w(ways way_nodes way_tags relations relation_members relation_tags)
+ tempfiles = %w[ways way_nodes way_tags relations relation_members relation_tags]
.map { |base| prefix + base }
ways, way_nodes, way_tags,
relations, relation_members, relation_tags = tempfiles
t.column "updated_at", :datetime, :null => false
end
- add_index "diary_comments", %w(diary_entry_id id), :name => "diary_comments_entry_id_idx", :unique => true
+ add_index "diary_comments", %w[diary_entry_id id], :name => "diary_comments_entry_id_idx", :unique => true
end
def self.down
args = conn_opts.map(&:to_s) + [prefix]
raise "#{cmd} failed" unless system cmd, *args
- tempfiles = %w(nodes node_tags current_nodes current_node_tags)
+ tempfiles = %w[nodes node_tags current_nodes current_node_tags]
.map { |base| prefix + base }
nodes, node_tags, current_nodes, current_node_tags = tempfiles
end
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)
+ @conv_tables = %w[nodes ways way_tags way_nodes current_way_tags relation_members relations relation_tags current_relation_tags]
- @ver_tbl = %w(nodes ways relations)
+ @ver_tbl = %w[nodes ways relations]
def self.up
remove_index :current_way_tags, :name => :current_way_tags_v_idx
require "migrate"
class AddChangesets < ActiveRecord::Migration
- @conv_user_tables = %w(current_nodes current_relations current_ways nodes relations ways)
+ @conv_user_tables = %w[current_nodes current_relations current_ways nodes relations ways]
def self.up
create_table "changesets", :id => false do |t|
def self.up
add_index "changesets", ["created_at"], :name => "changesets_created_at_idx"
add_index "changesets", ["closed_at"], :name => "changesets_closed_at_idx"
- add_index "changesets", %w(min_lat max_lat min_lon max_lon), :name => "changesets_bbox_idx", :using => "GIST"
+ add_index "changesets", %w[min_lat max_lat min_lon max_lon], :name => "changesets_bbox_idx", :using => "GIST"
end
def self.down
class AddMoreControlsToGpxFiles < ActiveRecord::Migration
def self.up
- create_enumeration :gpx_visibility_enum, %w(private public trackable identifiable)
+ create_enumeration :gpx_visibility_enum, %w[private public trackable identifiable]
add_column :gpx_files, :visibility, :gpx_visibility_enum, :default => "public", :null => false
Trace.where(:public => false).update_all(:visibility => "private")
add_index :gpx_files, [:visible, :visibility], :name => "gpx_files_visible_visibility_idx"
class AddFineOAuthPermissions < ActiveRecord::Migration
- PERMISSIONS = [:allow_read_prefs, :allow_write_prefs, :allow_write_diary,
- :allow_write_api, :allow_read_gpx, :allow_write_gpx].freeze
+ PERMISSIONS = [:allow_read_prefs, :allow_write_prefs, :allow_write_diary, :allow_write_api, :allow_read_gpx, :allow_write_gpx].freeze
def self.up
PERMISSIONS.each do |perm|
class CreateUserRoles < ActiveRecord::Migration
def self.up
- create_enumeration :user_role_enum, %w(administrator moderator)
+ create_enumeration :user_role_enum, %w[administrator moderator]
create_table :user_roles do |t|
t.column :user_id, :bigint, :null => false
class AddStatusToUser < ActiveRecord::Migration
def self.up
- create_enumeration :user_status_enum, %w(pending active confirmed suspended deleted)
+ create_enumeration :user_status_enum, %w[pending active confirmed suspended deleted]
add_column :users, :status, :user_status_enum, :null => false, :default => "pending"
class AddMapBugTables < ActiveRecord::Migration
def self.up
- create_enumeration :map_bug_status_enum, %w(open closed hidden)
+ create_enumeration :map_bug_status_enum, %w[open closed hidden]
create_table :map_bugs do |t|
t.integer :latitude, :null => false
class AddMapBugCommentEvent < ActiveRecord::Migration
def self.up
- create_enumeration :map_bug_event_enum, %w(opened closed reopened commented hidden)
+ create_enumeration :map_bug_event_enum, %w[opened closed reopened commented hidden]
add_column :map_bug_comment, :event, :map_bug_event_enum
end
class AddTextFormat < ActiveRecord::Migration
def up
- create_enumeration :format_enum, %w(html markdown text)
+ create_enumeration :format_enum, %w[html markdown text]
add_column :users, :description_format, :format_enum, :null => false, :default => "html"
add_column :user_blocks, :reason_format, :format_enum, :null => false, :default => "html"
add_column :diary_entries, :body_format, :format_enum, :null => false, :default => "html"
module Editors
- ALL_EDITORS = %w(potlatch potlatch2 id remote).freeze
- RECOMMENDED_EDITORS = %w(id potlatch2 remote).freeze
+ ALL_EDITORS = %w[potlatch potlatch2 id remote].freeze
+ RECOMMENDED_EDITORS = %w[id potlatch2 remote].freeze
end
-module ActiveRecord
- module ConnectionAdapters
- module SchemaStatements
- def add_index_options_with_columns(table_name, column_name, options = {})
+module OpenStreetMap
+ module ActiveRecord
+ module AbstractAdapter
+ def add_index_options(table_name, column_name, options = {})
columns = options.delete(:columns)
- index_name, index_type, index_columns, index_options, algorithm, using = add_index_options_without_columns(table_name, column_name, options)
+ index_name, index_type, index_columns, index_options, algorithm, using = super(table_name, column_name, options)
[index_name, index_type, columns || index_columns, index_options, algorithm, using]
end
-
- alias_method_chain :add_index_options, :columns
end
- module PostgreSQL
- module Quoting
- def quote_column_name_with_arrays(name)
- Array(name).map { |n| quote_column_name_without_arrays(n) }.join(", ")
- end
-
- alias_method_chain :quote_column_name, :arrays
+ module PostgreSQLAdapter
+ def quote_column_name(name)
+ Array(name).map { |n| super(n) }.join(", ")
end
- module SchemaStatements
- def add_primary_key(table_name, column_name, _options = {})
- execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
- end
+ def add_primary_key(table_name, column_name, _options = {})
+ execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
+ end
- def remove_primary_key(table_name)
- execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
- end
+ def remove_primary_key(table_name)
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
+ end
- def alter_primary_key(table_name, new_columns)
- execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
- execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
- end
+ def alter_primary_key(table_name, new_columns)
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
+ execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
+ end
- def create_enumeration(enumeration_name, values)
- execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
- end
+ def create_enumeration(enumeration_name, values)
+ execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
+ end
- def drop_enumeration(enumeration_name)
- execute "DROP TYPE #{enumeration_name}"
- end
+ def drop_enumeration(enumeration_name)
+ execute "DROP TYPE #{enumeration_name}"
+ end
- def rename_enumeration(old_name, new_name)
- execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
- end
+ def rename_enumeration(old_name, new_name)
+ execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
end
end
end
end
+
+ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(OpenStreetMap::ActiveRecord::AbstractAdapter)
+ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(OpenStreetMap::ActiveRecord::PostgreSQLAdapter)
module QuadTile
begin
require "quad_tile/quad_tile_so"
- rescue MissingSourceFile
+ rescue LoadError
def self.tile_for_point(lat, lon)
x = ((lon.to_f + 180) * 65535 / 360).round
y = ((lat.to_f + 90) * 65535 / 180).round
begin
ActiveRecord::Base.transaction do
- user_count = User.where(:status => %w(active confirmed suspended)).count
+ user_count = User.where(:status => %w[active confirmed suspended]).count
tracepoint_count = Tracepoint.count
node_count = Node.where(:visible => true).count
way_count = Way.where(:visible => true).count
addresses = User.count(
:conditions => {
- :status => %w(suspended deleted),
+ :status => %w[suspended deleted],
:creation_time => Time.now - 28.days..Time.now
},
:group => :creation_ip
include Potlatch
class AmfControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
end
def test_getpresets
- user_en_de = create(:user, :languages => %w(en de))
- user_de = create(:user, :languages => %w(de))
+ user_en_de = create(:user, :languages => %w[en de])
+ user_de = create(:user, :languages => %w[de])
[user_en_de, user_de].each do |user|
amf_content "getpresets", "/1", ["#{user.email}:test", ""]
post :amf_read
end
def test_whichways_deleted
- node = create(:node, :lat => 3.0, :lon => 3.0)
- way = create(:way)
- deleted_way = create(:way, :deleted)
+ node = create(:node, :with_history, :lat => 24.0, :lon => 24.0)
+ way = create(:way, :with_history)
+ way_v1 = way.old_ways.find_by(:version => 1)
+ deleted_way = create(:way, :with_history, :deleted)
+ deleted_way_v1 = deleted_way.old_ways.find_by(:version => 1)
create(:way_node, :way => way, :node => node)
create(:way_node, :way => deleted_way, :node => node)
- create(:way_tag, :way => way)
+ create(:old_way_node, :old_way => way_v1, :node => node)
+ create(:old_way_node, :old_way => deleted_way_v1, :node => node)
minlon = node.lon - 0.1
minlat = node.lat - 0.1
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),
+ assert !map[2].include?(way.id),
+ "map should not include visible way"
+ assert map[2].include?(deleted_way.id),
"map should include deleted way"
end
end
def test_getway_old
+ latest = create(:way, :version => 2)
+ v1 = create(:old_way, :current_way => latest, :version => 1, :timestamp => Time.now.utc - 2.minutes)
+ _v2 = create(:old_way, :current_way => latest, :version => 2, :timestamp => Time.now.utc - 1.minute)
+
# try to get the last visible version (specified by <0) (should be current version)
- latest = current_ways(:way_with_versions)
# NOTE: looks from the API changes that this now expects a timestamp
# instead of a version number...
# try to get version 1
- v1 = ways(:way_with_versions_v2)
{ latest.id => "",
- v1.way_id => v1.timestamp.strftime("%d %b %Y, %H:%M:%S") }.each do |id, t|
+ v1.way_id => (v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S") }.each do |id, t|
amf_content "getway_old", "/1", [id, t]
post :amf_read
assert_response :success
# test that the server doesn't fall over when rubbish is passed
# into the method args.
def test_getway_old_invalid
- way_id = current_ways(:way_with_versions).id
+ way_id = create(:way, :with_history, :version => 2).id
{ "foo" => "bar",
way_id => "not a date",
way_id => "2009-03-25 00:00:00", # <- wrong format
def test_getway_old_nonexistent
# try to get the last version-10 (shoudn't exist)
- v1 = ways(:way_with_versions_v1)
+ way = create(:way, :with_history, :version => 2)
+ v1 = way.old_ways.find_by(:version => 1)
# try to get last visible version of non-existent way
# try to get specific version of non-existent way
[[0, ""],
end
def test_getway_old_invisible
- v1 = ways(:invisible_way)
+ way = create(:way, :deleted, :with_history, :version => 1)
+ v1 = way.old_ways.find_by(:version => 1)
# try to get deleted version
[[v1.way_id, (v1.timestamp + 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
amf_content "getway_old", "/1", [id, t]
end
def test_getway_history
- latest = current_ways(:way_with_versions)
- oldest = ways(:way_with_versions_v1)
+ latest = create(:way, :version => 2)
+ oldest = create(:old_way, :current_way => latest, :version => 1, :timestamp => latest.timestamp - 2.minutes)
+ create(:old_way, :current_way => latest, :version => 2, :timestamp => latest.timestamp)
amf_content "getway_history", "/1", [latest.id]
post :amf_read
end
def test_findgpx_by_name
- amf_content "findgpx", "/1", ["Trace", "test@example.com:test"]
+ user = create(:user)
+
+ amf_content "findgpx", "/1", ["Trace", "#{user.email}:test"]
post :amf_read
assert_response :success
amf_parse_response
# check that we can open a changeset
def test_startchangeset_valid
- amf_content "startchangeset", "/1", ["test@example.com:test", { "source" => "new" }, nil, "new", 1]
+ user = create(:user)
+
+ amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "new" }, nil, "new", 1]
post :amf_write
assert_response :success
amf_parse_response
old_cs_id = new_cs_id
- amf_content "startchangeset", "/1", ["test@example.com:test", { "source" => "newer" }, old_cs_id, "newer", 1]
+ amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "newer" }, old_cs_id, "newer", 1]
post :amf_write
assert_response :success
amf_parse_response
old_cs_id = new_cs_id
- amf_content "startchangeset", "/1", ["test@example.com:test", {}, old_cs_id, "", 0]
+ amf_content "startchangeset", "/1", ["#{user.email}:test", {}, old_cs_id, "", 0]
post :amf_write
assert_response :success
amf_parse_response
# check that we can't close somebody elses changeset
def test_startchangeset_invalid_wrong_user
- amf_content "startchangeset", "/1", ["test@example.com:test", { "source" => "new" }, nil, "new", 1]
+ user = create(:user)
+ user2 = create(:user)
+
+ amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "new" }, nil, "new", 1]
post :amf_write
assert_response :success
amf_parse_response
assert_equal true, cs.is_open?
assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
- amf_content "startchangeset", "/1", ["test@openstreetmap.org:test", {}, cs_id, "delete", 0]
+ amf_content "startchangeset", "/1", ["#{user2.email}:test", {}, cs_id, "delete", 0]
post :amf_write
assert_response :success
amf_parse_response
# check that invalid characters are stripped from changeset tags
def test_startchangeset_invalid_xmlchar_comment
+ user = create(:user)
+
invalid = "\035\022"
comment = "foo#{invalid}bar"
- amf_content "startchangeset", "/1", ["test@example.com:test", {}, nil, comment, 1]
+ amf_content "startchangeset", "/1", ["#{user.email}:test", {}, nil, comment, 1]
post :amf_write
assert_response :success
amf_parse_response
require "api_controller"
class ApiControllerTest < ActionController::TestCase
- api_fixtures
-
def setup
super
- @badbigbbox = %w(-0.1,-0.1,1.1,1.1 10,10,11,11)
- @badmalformedbbox = %w(-0.1 hello
- 10N2W10.1N2.1W)
- @badlatmixedbbox = %w(0,0.1,0.1,0 -0.1,80,0.1,70 0.24,54.34,0.25,54.33)
- @badlonmixedbbox = %w(80,-0.1,70,0.1 54.34,0.24,54.33,0.25)
+ @badbigbbox = %w[-0.1,-0.1,1.1,1.1 10,10,11,11]
+ @badmalformedbbox = %w[-0.1 hello
+ 10N2W10.1N2.1W]
+ @badlatmixedbbox = %w[0,0.1,0.1,0 -0.1,80,0.1,70 0.24,54.34,0.25,54.33]
+ @badlonmixedbbox = %w[80,-0.1,70,0.1 54.34,0.24,54.33,0.25]
# @badlatlonoutboundsbbox = %w{ 191,-0.1,193,0.1 -190.1,89.9,-190,90 }
- @goodbbox = %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)
+ @goodbbox = %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]
# That last item in the goodbbox really shouldn't be there, as the API should
# reall reject it, however this is to test to see if the api changes.
end
end
def test_map_without_bbox
- %w(trackpoints map).each do |tq|
+ %w[trackpoints map].each do |tq|
get tq
assert_response :bad_request
assert_equal "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat", @response.body, "A bbox param was expected"
def test_bbox_too_big
@badbigbbox.each do |bbox|
- %w(trackpoints map).each do |tq|
+ %w[trackpoints map].each do |tq|
get tq, :bbox => bbox
assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
assert_equal "The maximum bbox size is #{MAX_REQUEST_AREA}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
def test_bbox_malformed
@badmalformedbbox.each do |bbox|
- %w(trackpoints map).each do |tq|
+ %w[trackpoints map].each do |tq|
get tq, :bbox => bbox
assert_response :bad_request, "The bbox:#{bbox} was expected to be malformed"
assert_equal "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat", @response.body, "bbox: #{bbox}"
def test_bbox_lon_mixedup
@badlonmixedbbox.each do |bbox|
- %w(trackpoints map).each do |tq|
+ %w[trackpoints map].each do |tq|
get tq, :bbox => bbox
assert_response :bad_request, "The bbox:#{bbox} was expected to have the longitude mixed up"
assert_equal "The minimum longitude must be less than the maximum longitude, but it wasn't", @response.body, "bbox: #{bbox}"
def test_bbox_lat_mixedup
@badlatmixedbbox.each do |bbox|
- %w(trackpoints map).each do |tq|
+ %w[trackpoints map].each do |tq|
get tq, :bbox => bbox
assert_response :bad_request, "The bbox:#{bbox} was expected to have the latitude mixed up"
assert_equal "The minimum latitude must be less than the maximum latitude, but it wasn't", @response.body, "bbox: #{bbox}"
# http://wiki.openstreetmap.org/wiki/Rails#Installing_the_quadtile_functions
# or by looking at the readme in db/README
def test_changes_simple
+ # create a selection of nodes
+ (1..5).each do |n|
+ create(:node, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => n, :lon => n)
+ end
+ # deleted nodes should also be counted
+ create(:node, :deleted, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => 6, :lon => 6)
+ # nodes in the same tile won't change the total
+ create(:node, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => 6, :lon => 6)
+ # nodes with a different timestamp should be ignored
+ create(:node, :timestamp => Time.utc(2008, 1, 1, 0, 0, 0), :lat => 7, :lon => 7)
+
Timecop.freeze(Time.utc(2010, 4, 3, 10, 55, 0))
get :changes
assert_response :success
- # print @response.body
- # As we have loaded the fixtures, we can assume that there are no
- # changes at the time we have frozen at
now = Time.now.getutc
hourago = now - 1.hour
assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
hourago = now - 1.hour
assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
- assert_select "tile", :count => 10
+ assert_select "tile", :count => 6
end
end
Timecop.return
end
def test_changes_zoom_invalid
- zoom_to_test = %w(p -1 0 17 one two)
+ zoom_to_test = %w[p -1 0 17 one two]
zoom_to_test.each do |zoom|
get :changes, :zoom => zoom
assert_response :bad_request
end
def test_changes_hours_invalid
- invalid = %w(-21 335 -1 0 25 26 100 one two three ping pong :)
+ invalid = %w[-21 335 -1 0 25 26 100 one two three ping pong :]
invalid.each do |hour|
get :changes, :hours => hour
assert_response :bad_request, "Problem with the hour: #{hour}"
require "browse_controller"
class BrowseControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
end
def test_read_relation
- browse_check "relation", relations(:visible_relation).relation_id, "browse/feature"
+ browse_check "relation", create(: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", create(:relation, :with_history).id, "browse/history"
end
def test_read_way
- browse_check "way", ways(:visible_way).way_id, "browse/feature"
+ browse_check "way", create(: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", create(:way, :with_history).id, "browse/history"
end
def test_read_node
end
def test_read_changeset
- browse_check "changeset", changesets(:normal_user_first_change).id, "browse/changeset"
- browse_check "changeset", changesets(:public_user_first_change).id, "browse/changeset"
+ private_changeset = create(:changeset, :user => create(:user, :data_public => false))
+ changeset = create(:changeset)
+ browse_check "changeset", private_changeset.id, "browse/changeset"
+ browse_check "changeset", changeset.id, "browse/changeset"
end
def test_read_changeset_hidden_comments
end
def test_redacted_way_history
- get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
+ way = create(:way, :with_history, :version => 4)
+ way_v1 = way.old_ways.find_by(:version => 1)
+ way_v1.redact!(create(:redaction))
+ way_v3 = way.old_ways.find_by(:version => 3)
+ way_v3.redact!(create(:redaction))
+
+ get :way_history, :id => way.id
assert_response :success
assert_template "browse/history"
end
def test_redacted_relation_history
- get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
+ relation = create(:relation, :with_history, :version => 4)
+ relation_v1 = relation.old_relations.find_by(:version => 1)
+ relation_v1.redact!(create(:redaction))
+ relation_v3 = relation.old_relations.find_by(:version => 3)
+ relation_v3.redact!(create(:redaction))
+
+ get :relation_history, :id => relation.id
assert_response :success
assert_template "browse/history"
require "changeset_controller"
class ChangesetControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
# simple diff to change a node, way and relation by removing
# their tags
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
# simple diff to change a node, way and relation by removing
# their tags
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
# simple diff to change a node, way and relation by removing
# their tags
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
def test_upload_create_valid
user = create(:user)
changeset = create(:changeset, :user => user)
+ node = create(:node)
+ way = create(:way_with_nodes, :nodes_count => 2)
+ relation = create(:relation)
basic_authorization user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
- <tag k='foo' v='bar'/>
- <tag k='baz' v='bat'/>
- </node>
- <way id='-1' changeset='#{changeset.id}'>
- <nd ref='3'/>
- </way>
- </create>
- <create>
- <relation id='-1' changeset='#{changeset.id}'>
- <member type='way' role='some' ref='3'/>
- <member type='node' role='some' ref='5'/>
- <member type='relation' role='some' ref='3'/>
- </relation>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k='foo' v='bar'/>
+ <tag k='baz' v='bat'/>
+ </node>
+ <way id='-1' changeset='#{changeset.id}'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </create>
+ <create>
+ <relation id='-1' changeset='#{changeset.id}'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{relation.id}'/>
+ </relation>
+ </create>
+ </osmChange>
EOF
# upload it
# test a complex delete where we delete elements which rely on eachother
# in the same transaction.
def test_upload_delete
- basic_authorization changesets(:public_user_first_change).user.display_name, "test"
+ changeset = create(:changeset)
+ super_relation = create(:relation)
+ used_relation = create(:relation)
+ used_way = create(:way)
+ used_node = create(:node)
+ create(:relation_member, :relation => super_relation, :member => used_relation)
+ create(:relation_member, :relation => super_relation, :member => used_way)
+ create(:relation_member, :relation => super_relation, :member => used_node)
+
+ basic_authorization changeset.user.display_name, "test"
diff = XML::Document.new
diff.root = XML::Node.new "osmChange"
delete = XML::Node.new "delete"
diff.root << delete
- delete << current_relations(:visible_relation).to_xml_node
- delete << current_relations(:used_relation).to_xml_node
- delete << current_ways(:used_way).to_xml_node
- delete << current_nodes(:node_used_by_relationship).to_xml_node
+ delete << super_relation.to_xml_node
+ delete << used_relation.to_xml_node
+ delete << used_way.to_xml_node
+ delete << used_node.to_xml_node
# update the changeset to one that this user owns
- changeset_id = changesets(:public_user_first_change).id
- %w(node way relation).each do |type|
+ %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
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :success,
"can't upload a deletion diff to changeset: #{@response.body}"
assert_select "diffResult>relation", 2
# check that everything was deleted
- assert_equal false, Node.find(current_nodes(:node_used_by_relationship).id).visible
- assert_equal false, Way.find(current_ways(:used_way).id).visible
- assert_equal false, Relation.find(current_relations(:visible_relation).id).visible
- assert_equal false, Relation.find(current_relations(:used_relation).id).visible
+ assert_equal false, Node.find(used_node.id).visible
+ assert_equal false, Way.find(used_way.id).visible
+ assert_equal false, Relation.find(super_relation.id).visible
+ assert_equal false, Relation.find(used_relation.id).visible
end
##
# test uploading a delete with no lat/lon, as they are optional in
# the osmChange spec.
def test_upload_nolatlon_delete
- basic_authorization changesets(:public_user_first_change).user.display_name, "test"
+ node = create(:node)
+ changeset = create(:changeset)
- node = current_nodes(:public_visible_node)
- cs = changesets(:public_user_first_change)
- diff = "<osmChange><delete><node id='#{node.id}' version='#{node.version}' changeset='#{cs.id}'/></delete></osmChange>"
+ basic_authorization changeset.user.display_name, "test"
+ diff = "<osmChange><delete><node id='#{node.id}' version='#{node.version}' changeset='#{changeset.id}'/></delete></osmChange>"
# upload it
content diff
- post :upload, :id => cs.id
+ post :upload, :id => changeset.id
assert_response :success,
"can't upload a deletion diff to changeset: #{@response.body}"
# upload some widely-spaced nodes, spiralling positive and negative to cause
# largest bbox over-expansion possible.
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='-20' lat='-10' changeset='#{changeset_id}'/>
- <node id='-10' lon='20' lat='10' changeset='#{changeset_id}'/>
- <node id='-2' lon='-40' lat='-20' changeset='#{changeset_id}'/>
- <node id='-11' lon='40' lat='20' changeset='#{changeset_id}'/>
- <node id='-3' lon='-60' lat='-30' changeset='#{changeset_id}'/>
- <node id='-12' lon='60' lat='30' changeset='#{changeset_id}'/>
- <node id='-4' lon='-80' lat='-40' changeset='#{changeset_id}'/>
- <node id='-13' lon='80' lat='40' changeset='#{changeset_id}'/>
- <node id='-5' lon='-100' lat='-50' changeset='#{changeset_id}'/>
- <node id='-14' lon='100' lat='50' changeset='#{changeset_id}'/>
- <node id='-6' lon='-120' lat='-60' changeset='#{changeset_id}'/>
- <node id='-15' lon='120' lat='60' changeset='#{changeset_id}'/>
- <node id='-7' lon='-140' lat='-70' changeset='#{changeset_id}'/>
- <node id='-16' lon='140' lat='70' changeset='#{changeset_id}'/>
- <node id='-8' lon='-160' lat='-80' changeset='#{changeset_id}'/>
- <node id='-17' lon='160' lat='80' changeset='#{changeset_id}'/>
- <node id='-9' lon='-179.9' lat='-89.9' changeset='#{changeset_id}'/>
- <node id='-18' lon='179.9' lat='89.9' changeset='#{changeset_id}'/>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='-20' lat='-10' changeset='#{changeset_id}'/>
+ <node id='-10' lon='20' lat='10' changeset='#{changeset_id}'/>
+ <node id='-2' lon='-40' lat='-20' changeset='#{changeset_id}'/>
+ <node id='-11' lon='40' lat='20' changeset='#{changeset_id}'/>
+ <node id='-3' lon='-60' lat='-30' changeset='#{changeset_id}'/>
+ <node id='-12' lon='60' lat='30' changeset='#{changeset_id}'/>
+ <node id='-4' lon='-80' lat='-40' changeset='#{changeset_id}'/>
+ <node id='-13' lon='80' lat='40' changeset='#{changeset_id}'/>
+ <node id='-5' lon='-100' lat='-50' changeset='#{changeset_id}'/>
+ <node id='-14' lon='100' lat='50' changeset='#{changeset_id}'/>
+ <node id='-6' lon='-120' lat='-60' changeset='#{changeset_id}'/>
+ <node id='-15' lon='120' lat='60' changeset='#{changeset_id}'/>
+ <node id='-7' lon='-140' lat='-70' changeset='#{changeset_id}'/>
+ <node id='-16' lon='140' lat='70' changeset='#{changeset_id}'/>
+ <node id='-8' lon='-160' lat='-80' changeset='#{changeset_id}'/>
+ <node id='-17' lon='160' lat='80' changeset='#{changeset_id}'/>
+ <node id='-9' lon='-179.9' lat='-89.9' changeset='#{changeset_id}'/>
+ <node id='-18' lon='179.9' lat='89.9' changeset='#{changeset_id}'/>
+ </create>
+ </osmChange>
EOF
# upload it, which used to cause an error like "PGError: ERROR:
# test that deleting stuff in a transaction doesn't bypass the checks
# to ensure that used elements are not deleted.
def test_upload_delete_invalid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs = changesets(:public_user_first_change)
+ changeset = create(:changeset)
+ relation = create(:relation)
+ other_relation = create(:relation)
+ used_way = create(:way)
+ used_node = create(:node)
+ create(:relation_member, :relation => relation, :member => used_way)
+ create(:relation_member, :relation => relation, :member => used_node)
+
+ basic_authorization changeset.user.email, "test"
diff = XML::Document.new
diff.root = XML::Node.new "osmChange"
delete = XML::Node.new "delete"
diff.root << delete
- delete << current_relations(:public_visible_relation).to_xml_node
- delete << current_ways(:used_way).to_xml_node
- delete << current_nodes(:node_used_by_relationship).to_xml_node
+ delete << other_relation.to_xml_node
+ delete << used_way.to_xml_node
+ delete << used_node.to_xml_node
+
+ # update the changeset to one that this user owns
+ %w[node way relation].each do |type|
+ delete.find("//osmChange/delete/#{type}").each do |n|
+ n["changeset"] = changeset.id.to_s
+ end
+ end
# upload it
content diff
- post :upload, :id => cs.id
+ post :upload, :id => changeset.id
assert_response :precondition_failed,
"shouldn't be able to upload a invalid deletion diff: #{@response.body}"
- assert_equal "Precondition failed: Way 3 is still used by relations 1.", @response.body
+ assert_equal "Precondition failed: Way #{used_way.id} is still used by relations #{relation.id}.", @response.body
# check that nothing was, in fact, deleted
- assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible
- assert_equal true, Way.find(current_ways(:used_way).id).visible
- assert_equal true, Relation.find(current_relations(:visible_relation).id).visible
+ assert_equal true, Node.find(used_node.id).visible
+ assert_equal true, Way.find(used_way.id).visible
+ assert_equal true, Relation.find(relation.id).visible
+ assert_equal true, Relation.find(other_relation.id).visible
end
##
# test that a conditional delete of an in use object works.
def test_upload_delete_if_unused
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs = changesets(:public_user_first_change)
+ changeset = create(:changeset)
+ super_relation = create(:relation)
+ used_relation = create(:relation)
+ used_way = create(:way)
+ used_node = create(:node)
+ create(:relation_member, :relation => super_relation, :member => used_relation)
+ create(:relation_member, :relation => super_relation, :member => used_way)
+ create(:relation_member, :relation => super_relation, :member => used_node)
+
+ basic_authorization changeset.user.email, "test"
diff = XML::Document.new
diff.root = XML::Node.new "osmChange"
delete = XML::Node.new "delete"
diff.root << delete
delete["if-unused"] = ""
- delete << current_relations(:public_used_relation).to_xml_node
- delete << current_ways(:used_way).to_xml_node
- delete << current_nodes(:node_used_by_relationship).to_xml_node
+ delete << used_relation.to_xml_node
+ delete << used_way.to_xml_node
+ delete << used_node.to_xml_node
+
+ # update the changeset to one that this user owns
+ %w[node way relation].each do |type|
+ delete.find("//osmChange/delete/#{type}").each do |n|
+ n["changeset"] = changeset.id.to_s
+ end
+ end
# upload it
content diff
- post :upload, :id => cs.id
+ post :upload, :id => changeset.id
assert_response :success,
"can't do a conditional delete of in use objects: #{@response.body}"
doc = XML::Parser.string(@response.body).parse
# check the old IDs are all present and what we expect
- assert_equal current_nodes(:node_used_by_relationship).id, doc.find("//diffResult/node").first["old_id"].to_i
- assert_equal current_ways(:used_way).id, doc.find("//diffResult/way").first["old_id"].to_i
- assert_equal current_relations(:public_used_relation).id, doc.find("//diffResult/relation").first["old_id"].to_i
+ assert_equal used_node.id, doc.find("//diffResult/node").first["old_id"].to_i
+ assert_equal used_way.id, doc.find("//diffResult/way").first["old_id"].to_i
+ assert_equal used_relation.id, doc.find("//diffResult/relation").first["old_id"].to_i
# check the new IDs are all present and unchanged
- assert_equal current_nodes(:node_used_by_relationship).id, doc.find("//diffResult/node").first["new_id"].to_i
- assert_equal current_ways(:used_way).id, doc.find("//diffResult/way").first["new_id"].to_i
- assert_equal current_relations(:public_used_relation).id, doc.find("//diffResult/relation").first["new_id"].to_i
+ assert_equal used_node.id, doc.find("//diffResult/node").first["new_id"].to_i
+ assert_equal used_way.id, doc.find("//diffResult/way").first["new_id"].to_i
+ assert_equal used_relation.id, doc.find("//diffResult/relation").first["new_id"].to_i
# check the new versions are all present and unchanged
- assert_equal current_nodes(:node_used_by_relationship).version, doc.find("//diffResult/node").first["new_version"].to_i
- assert_equal current_ways(:used_way).version, doc.find("//diffResult/way").first["new_version"].to_i
- assert_equal current_relations(:public_used_relation).version, doc.find("//diffResult/relation").first["new_version"].to_i
+ assert_equal used_node.version, doc.find("//diffResult/node").first["new_version"].to_i
+ assert_equal used_way.version, doc.find("//diffResult/way").first["new_version"].to_i
+ assert_equal used_relation.version, doc.find("//diffResult/relation").first["new_version"].to_i
# check that nothing was, in fact, deleted
- assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible
- assert_equal true, Way.find(current_ways(:used_way).id).visible
- assert_equal true, Relation.find(current_relations(:public_used_relation).id).visible
+ assert_equal true, Node.find(used_node.id).visible
+ assert_equal true, Way.find(used_way.id).visible
+ assert_equal true, Relation.find(used_relation.id).visible
end
##
# upload an element with a really long tag value
def test_upload_invalid_too_long_tag
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{cs_id}'>
- <tag k='foo' v='#{'x' * 256}'/>
- </node>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k='foo' v='#{'x' * 256}'/>
+ </node>
+ </create>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shoudln't be able to upload too long a tag to changeset: #{@response.body}"
end
# upload something which creates new objects and inserts them into
# existing containers using placeholders.
def test_upload_complex
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
+ way = create(:way)
+ node = create(:node)
+ relation = create(:relation)
+ create(:way_node, :way => way, :node => node)
+
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{cs_id}'>
- <tag k='foo' v='bar'/>
- <tag k='baz' v='bat'/>
- </node>
- </create>
- <modify>
- <way id='1' changeset='#{cs_id}' version='1'>
- <nd ref='-1'/>
- <nd ref='3'/>
- </way>
- <relation id='1' changeset='#{cs_id}' version='1'>
- <member type='way' role='some' ref='3'/>
- <member type='node' role='some' ref='-1'/>
- <member type='relation' role='some' ref='3'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k='foo' v='bar'/>
+ <tag k='baz' v='bat'/>
+ </node>
+ </create>
+ <modify>
+ <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
+ <nd ref='-1'/>
+ <nd ref='#{node.id}'/>
+ </way>
+ <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='-1'/>
+ <member type='relation' role='some' ref='#{relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :success,
"can't upload a complex diff to changeset: #{@response.body}"
# check that the changes made it into the database
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|
+ 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
# create a diff which references several changesets, which should cause
# a rollback and none of the diff gets committed
def test_upload_invalid_changesets
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
+ changeset = create(:changeset)
+ other_changeset = create(:changeset, :user => changeset.user)
+ node = create(:node)
+ way = create(:way)
+ relation = create(:relation)
+ other_relation = create(:relation)
+
+ basic_authorization changeset.user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{cs_id}' version='1'/>
- <way id='1' changeset='#{cs_id}' version='1'>
- <nd ref='3'/>
- </way>
- </modify>
- <modify>
- <relation id='1' changeset='#{cs_id}' version='1'>
- <member type='way' role='some' ref='3'/>
- <member type='node' role='some' ref='5'/>
- <member type='relation' role='some' ref='3'/>
- </relation>
- </modify>
- <create>
- <node id='-1' lon='0' lat='0' changeset='4'>
- <tag k='foo' v='bar'/>
- <tag k='baz' v='bat'/>
- </node>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{other_changeset.id}'>
+ <tag k='foo' v='bar'/>
+ <tag k='baz' v='bat'/>
+ </node>
+ </create>
+ </osmChange>
EOF
- # cache the objects before uploading them
- node = current_nodes(:visible_node)
- way = current_ways(:visible_way)
- rel = current_relations(:visible_relation)
# upload it
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :conflict,
- "uploading a diff with multiple changsets should have failed"
+ "uploading a diff with multiple changesets should have failed"
# check that objects are unmodified
- assert_nodes_are_equal(node, Node.find(1))
- assert_ways_are_equal(way, Way.find(1))
- assert_relations_are_equal(rel, Relation.find(1))
+ assert_nodes_are_equal(node, Node.find(node.id))
+ assert_ways_are_equal(way, Way.find(way.id))
+ assert_relations_are_equal(relation, Relation.find(relation.id))
end
##
# upload multiple versions of the same element in the same diff.
def test_upload_multiple_valid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
+ node = create(:node)
+ changeset = create(:changeset)
+ basic_authorization changeset.user.email, "test"
# change the location of a node multiple times, each time referencing
# the last version. doesn't this depend on version numbers being
# sequential?
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{cs_id}' version='1'/>
- <node id='1' lon='1' lat='0' changeset='#{cs_id}' version='2'/>
- <node id='1' lon='1' lat='1' changeset='#{cs_id}' version='3'/>
- <node id='1' lon='1' lat='2' changeset='#{cs_id}' version='4'/>
- <node id='1' lon='2' lat='2' changeset='#{cs_id}' version='5'/>
- <node id='1' lon='3' lat='2' changeset='#{cs_id}' version='6'/>
- <node id='1' lon='3' lat='3' changeset='#{cs_id}' version='7'/>
- <node id='1' lon='9' lat='9' changeset='#{cs_id}' version='8'/>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <node id='#{node.id}' lon='1' lat='0' changeset='#{changeset.id}' version='2'/>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='3'/>
+ <node id='#{node.id}' lon='1' lat='2' changeset='#{changeset.id}' version='4'/>
+ <node id='#{node.id}' lon='2' lat='2' changeset='#{changeset.id}' version='5'/>
+ <node id='#{node.id}' lon='3' lat='2' changeset='#{changeset.id}' version='6'/>
+ <node id='#{node.id}' lon='3' lat='3' changeset='#{changeset.id}' version='7'/>
+ <node id='#{node.id}' lon='9' lat='9' changeset='#{changeset.id}' version='8'/>
+ </modify>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :success,
"can't upload multiple versions of an element in a diff: #{@response.body}"
# upload multiple versions of the same element in the same diff, but
# keep the version numbers the same.
def test_upload_multiple_duplicate
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{cs_id}' version='1'/>
- <node id='1' lon='1' lat='1' changeset='#{cs_id}' version='1'/>
- </modify>
-</osmChange>
+ node = create(:node)
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
+ </modify>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :conflict,
"shouldn't be able to upload the same element twice in a diff: #{@response.body}"
end
##
# try to upload some elements without specifying the version
def test_upload_missing_version
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='1' lat='1' changeset='cs_id'/>
- </modify>
-</osmChange>
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='1' lon='1' lat='1' changeset='#{changeset.id}'/>
+ </modify>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shouldn't be able to upload an element without version: #{@response.body}"
end
##
# try to upload with commands other than create, modify, or delete
def test_action_upload_invalid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <ping>
- <node id='1' lon='1' lat='1' changeset='#{cs_id}' />
- </ping>
-</osmChange>
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <ping>
+ <node id='1' lon='1' lat='1' changeset='#{changeset.id}' />
+ </ping>
+ </osmChange>
EOF
content diff
- post :upload, :id => cs_id
+ post :upload, :id => changeset.id
assert_response :bad_request, "Shouldn't be able to upload a diff with the action ping"
assert_equal @response.body, "Unknown action ping, choices are create, modify, delete"
end
# upload a valid changeset which has a mixture of whitespace
# to check a bug reported by ivansanchez (#1565).
def test_upload_whitespace_valid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- changeset_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <modify><node id='1' lon='0' lat='0' changeset='#{changeset_id}'
- version='1'></node>
- <node id='1' lon='1' lat='1' changeset='#{changeset_id}' version='2'><tag k='k' v='v'/></node></modify>
- <modify>
- <relation id='1' changeset='#{changeset_id}' version='1'><member
- type='way' role='some' ref='3'/><member
- type='node' role='some' ref='5'/>
- <member type='relation' role='some' ref='3'/>
- </relation>
- </modify></osmChange>
+ changeset = create(:changeset)
+ node = create(:node)
+ way = create(:way_with_nodes, :nodes_count => 2)
+ relation = create(:relation)
+ other_relation = create(:relation)
+ create(:relation_tag, :relation => relation)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify><node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}'
+ version='1'></node>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='2'><tag k='k' v='v'/></node></modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'><member
+ type='way' role='some' ref='#{way.id}'/><member
+ type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify></osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :success,
"can't upload a valid diff with whitespace variations to changeset: #{@response.body}"
assert_select "diffResult>relation", 1
# check that the changes made it into the database
- assert_equal 1, Node.find(1).tags.size, "node 1 should now have one tag"
- assert_equal 0, Relation.find(1).tags.size, "relation 1 should now have no tags"
+ assert_equal 1, Node.find(node.id).tags.size, "node #{node.id} should now have one tag"
+ assert_equal 0, Relation.find(relation.id).tags.size, "relation #{relation.id} should now have no tags"
end
##
- # upload a valid changeset which has a mixture of whitespace
- # to check a bug reported by ivansanchez.
+ # test that a placeholder can be reused within the same upload.
def test_upload_reuse_placeholder_valid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- changeset_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset_id}'>
- <tag k="foo" v="bar"/>
- </node>
- </create>
- <modify>
- <node id='-1' lon='1' lat='1' changeset='#{changeset_id}' version='1'/>
- </modify>
- <delete>
- <node id='-1' lon='2' lat='2' changeset='#{changeset_id}' version='2'/>
- </delete>
-</osmChange>
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k="foo" v="bar"/>
+ </node>
+ </create>
+ <modify>
+ <node id='-1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
+ </modify>
+ <delete>
+ <node id='-1' lon='2' lat='2' changeset='#{changeset.id}' version='2'/>
+ </delete>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :success,
"can't upload a valid diff with re-used placeholders to changeset: #{@response.body}"
# test what happens if a diff upload re-uses placeholder IDs in an
# illegal way.
def test_upload_placeholder_invalid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- changeset_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <node id='-1' lon='1' lat='1' changeset='#{changeset_id}' version='1'/>
- <node id='-1' lon='2' lat='2' changeset='#{changeset_id}' version='2'/>
- </create>
-</osmChange>
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <node id='-1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
+ <node id='-1' lon='2' lat='2' changeset='#{changeset.id}' version='2'/>
+ </create>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shouldn't be able to re-use placeholder IDs"
end
# test that uploading a way referencing invalid placeholders gives a
# proper error, not a 500.
def test_upload_placeholder_invalid_way
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- changeset_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
- <way id="-1" changeset="#{changeset_id}" version="1">
- <nd ref="-1"/>
- <nd ref="-2"/>
- <nd ref="-3"/>
- <nd ref="-4"/>
- </way>
- </create>
-</osmChange>
+ changeset = create(:changeset)
+ way = create(:way)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <way id="-1" changeset="#{changeset.id}" version="1">
+ <nd ref="-1"/>
+ <nd ref="-2"/>
+ <nd ref="-3"/>
+ <nd ref="-4"/>
+ </way>
+ </create>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shouldn't be able to use invalid placeholder IDs"
assert_equal "Placeholder node not found for reference -4 in way -1", @response.body
# the same again, but this time use an existing way
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
- <way id="1" changeset="#{changeset_id}" version="1">
- <nd ref="-1"/>
- <nd ref="-2"/>
- <nd ref="-3"/>
- <nd ref="-4"/>
- </way>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <way id="#{way.id}" changeset="#{changeset.id}" version="1">
+ <nd ref="-1"/>
+ <nd ref="-2"/>
+ <nd ref="-3"/>
+ <nd ref="-4"/>
+ </way>
+ </create>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shouldn't be able to use invalid placeholder IDs"
- assert_equal "Placeholder node not found for reference -4 in way 1", @response.body
+ assert_equal "Placeholder node not found for reference -4 in way #{way.id}", @response.body
end
##
# test that uploading a relation referencing invalid placeholders gives a
# proper error, not a 500.
def test_upload_placeholder_invalid_relation
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- changeset_id = changesets(:public_user_first_change).id
-
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
- <relation id="-1" changeset="#{changeset_id}" version="1">
- <member type="node" role="foo" ref="-1"/>
- <member type="node" role="foo" ref="-2"/>
- <member type="node" role="foo" ref="-3"/>
- <member type="node" role="foo" ref="-4"/>
- </relation>
- </create>
-</osmChange>
+ changeset = create(:changeset)
+ relation = create(:relation)
+
+ basic_authorization changeset.user.email, "test"
+
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <relation id="-1" changeset="#{changeset.id}" version="1">
+ <member type="node" role="foo" ref="-1"/>
+ <member type="node" role="foo" ref="-2"/>
+ <member type="node" role="foo" ref="-3"/>
+ <member type="node" role="foo" ref="-4"/>
+ </relation>
+ </create>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shouldn't be able to use invalid placeholder IDs"
assert_equal "Placeholder Node not found for reference -4 in relation -1.", @response.body
- # the same again, but this time use an existing way
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
- <relation id="1" changeset="#{changeset_id}" version="1">
- <member type="node" role="foo" ref="-1"/>
- <member type="node" role="foo" ref="-2"/>
- <member type="node" role="foo" ref="-3"/>
- <member type="way" role="bar" ref="-1"/>
- </relation>
- </create>
-</osmChange>
+ # the same again, but this time use an existing relation
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <relation id="#{relation.id}" changeset="#{changeset.id}" version="1">
+ <member type="node" role="foo" ref="-1"/>
+ <member type="node" role="foo" ref="-2"/>
+ <member type="node" role="foo" ref="-3"/>
+ <member type="way" role="bar" ref="-1"/>
+ </relation>
+ </create>
+ </osmChange>
EOF
# upload it
content diff
- post :upload, :id => changeset_id
+ post :upload, :id => changeset.id
assert_response :bad_request,
"shouldn't be able to use invalid placeholder IDs"
- assert_equal "Placeholder Way not found for reference -1 in relation 1.", @response.body
+ assert_equal "Placeholder Way not found for reference -1 in relation #{relation.id}.", @response.body
end
##
assert_response :success
changeset_id = @response.body.to_i
- old_node = current_nodes(:visible_node)
+ old_node = create(:node, :lat => 1, :lon => 1)
diff = XML::Document.new
diff.root = XML::Node.new "osmChange"
assert_response :success
changeset_id = @response.body.to_i
- old_way = current_ways(:visible_way)
+ old_way = create(:way)
+ create(:way_node, :way => old_way, :node => create(:node, :lat => 1, :lon => 1))
diff = XML::Document.new
diff.root = XML::Node.new "osmChange"
modify = XML::Node.new "modify"
xml_old_way = old_way.to_xml_node
nd_ref = XML::Node.new "nd"
- nd_ref["ref"] = current_nodes(:visible_node).id.to_s
+ nd_ref["ref"] = create(:node, :lat => 3, :lon => 3).id.to_s
xml_old_way << nd_ref
xml_old_way["changeset"] = changeset_id.to_s
modify << xml_old_way
##
# test for more issues in #1568
def test_upload_empty_invalid
- basic_authorization changesets(:public_user_first_change).user.email, "test"
+ changeset = create(:changeset)
+
+ basic_authorization changeset.user.email, "test"
["<osmChange/>",
"<osmChange></osmChange>",
"<osmChange><modify></modify></osmChange>"].each do |diff|
# upload it
content diff
- post :upload, :id => changesets(:public_user_first_change).id
+ post :upload, :id => changeset.id
assert_response(:success, "should be able to upload " +
"empty changeset: " + diff)
end
##
# test that the X-Error-Format header works to request XML errors
def test_upload_xml_errors
- basic_authorization changesets(:public_user_first_change).user.email, "test"
- cs = changesets(:public_user_first_change)
+ changeset = create(:changeset)
+ node = create(:node)
+ create(:relation_member, :member => node)
+
+ basic_authorization changeset.user.email, "test"
# try and delete a node that is in use
diff = XML::Document.new
diff.root = XML::Node.new "osmChange"
delete = XML::Node.new "delete"
diff.root << delete
- delete << current_nodes(:node_used_by_relationship).to_xml_node
+ delete << node.to_xml_node
# upload it
content diff
error_format "xml"
- post :upload, :id => cs.id
+ post :upload, :id => changeset.id
assert_response :success,
"failed to return error in XML format"
# when we make some simple changes we get the same changes back from the
# diff download.
def test_diff_download_simple
+ node = create(:node)
+
## First try with a non-public user, which should get a forbidden
basic_authorization(create(:user, :data_public => false).email, "test")
changeset_id = @response.body.to_i
# add a diff to it
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <node id='1' lon='1' lat='0' changeset='#{changeset_id}' version='2'/>
- <node id='1' lon='1' lat='1' changeset='#{changeset_id}' version='3'/>
- <node id='1' lon='1' lat='2' changeset='#{changeset_id}' version='4'/>
- <node id='1' lon='2' lat='2' changeset='#{changeset_id}' version='5'/>
- <node id='1' lon='3' lat='2' changeset='#{changeset_id}' version='6'/>
- <node id='1' lon='3' lat='3' changeset='#{changeset_id}' version='7'/>
- <node id='1' lon='9' lat='9' changeset='#{changeset_id}' version='8'/>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <node id='#{node.id}' lon='1' lat='0' changeset='#{changeset_id}' version='2'/>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset_id}' version='3'/>
+ <node id='#{node.id}' lon='1' lat='2' changeset='#{changeset_id}' version='4'/>
+ <node id='#{node.id}' lon='2' lat='2' changeset='#{changeset_id}' version='5'/>
+ <node id='#{node.id}' lon='3' lat='2' changeset='#{changeset_id}' version='6'/>
+ <node id='#{node.id}' lon='3' lat='3' changeset='#{changeset_id}' version='7'/>
+ <node id='#{node.id}' lon='9' lat='9' changeset='#{changeset_id}' version='8'/>
+ </modify>
+ </osmChange>
EOF
# upload it
assert_response :success
changeset_id = @response.body.to_i
- diff = <<OSMFILE
-<osmChange version="0.6" generator="JOSM">
-<create version="0.6" generator="JOSM">
- <node id='-1' visible='true' changeset='#{changeset_id}' lat='51.49619982187321' lon='-0.18722061869438314' />
- <node id='-2' visible='true' changeset='#{changeset_id}' lat='51.496359883909605' lon='-0.18653093576241928' />
- <node id='-3' visible='true' changeset='#{changeset_id}' lat='51.49598132358285' lon='-0.18719613290981638' />
- <node id='-4' visible='true' changeset='#{changeset_id}' lat='51.4961591711078' lon='-0.18629015888084607' />
- <node id='-5' visible='true' changeset='#{changeset_id}' lat='51.49582126021711' lon='-0.18708186591517145' />
- <node id='-6' visible='true' changeset='#{changeset_id}' lat='51.49591018437858' lon='-0.1861432441734455' />
- <node id='-7' visible='true' changeset='#{changeset_id}' lat='51.49560784152179' lon='-0.18694719410005425' />
- <node id='-8' visible='true' changeset='#{changeset_id}' lat='51.49567389979617' lon='-0.1860289771788006' />
- <node id='-9' visible='true' changeset='#{changeset_id}' lat='51.49543761398892' lon='-0.186820684213126' />
- <way id='-10' action='modiy' visible='true' changeset='#{changeset_id}'>
- <nd ref='-1' />
- <nd ref='-2' />
- <nd ref='-3' />
- <nd ref='-4' />
- <nd ref='-5' />
- <nd ref='-6' />
- <nd ref='-7' />
- <nd ref='-8' />
- <nd ref='-9' />
- <tag k='highway' v='residential' />
- <tag k='name' v='Foobar Street' />
- </way>
-</create>
-</osmChange>
+ diff = <<OSMFILE.strip_heredoc
+ <osmChange version="0.6" generator="JOSM">
+ <create version="0.6" generator="JOSM">
+ <node id='-1' visible='true' changeset='#{changeset_id}' lat='51.49619982187321' lon='-0.18722061869438314' />
+ <node id='-2' visible='true' changeset='#{changeset_id}' lat='51.496359883909605' lon='-0.18653093576241928' />
+ <node id='-3' visible='true' changeset='#{changeset_id}' lat='51.49598132358285' lon='-0.18719613290981638' />
+ <node id='-4' visible='true' changeset='#{changeset_id}' lat='51.4961591711078' lon='-0.18629015888084607' />
+ <node id='-5' visible='true' changeset='#{changeset_id}' lat='51.49582126021711' lon='-0.18708186591517145' />
+ <node id='-6' visible='true' changeset='#{changeset_id}' lat='51.49591018437858' lon='-0.1861432441734455' />
+ <node id='-7' visible='true' changeset='#{changeset_id}' lat='51.49560784152179' lon='-0.18694719410005425' />
+ <node id='-8' visible='true' changeset='#{changeset_id}' lat='51.49567389979617' lon='-0.1860289771788006' />
+ <node id='-9' visible='true' changeset='#{changeset_id}' lat='51.49543761398892' lon='-0.186820684213126' />
+ <way id='-10' action='modiy' visible='true' changeset='#{changeset_id}'>
+ <nd ref='-1' />
+ <nd ref='-2' />
+ <nd ref='-3' />
+ <nd ref='-4' />
+ <nd ref='-5' />
+ <nd ref='-6' />
+ <nd ref='-7' />
+ <nd ref='-8' />
+ <nd ref='-9' />
+ <tag k='highway' v='residential' />
+ <tag k='name' v='Foobar Street' />
+ </way>
+ </create>
+ </osmChange>
OSMFILE
# upload it
# when we make some complex changes we get the same changes back from the
# diff download.
def test_diff_download_complex
+ node = create(:node)
+ node2 = create(:node)
+ way = create(:way)
basic_authorization(create(:user).email, "test")
# create a temporary changeset
changeset_id = @response.body.to_i
# add a diff to it
- diff = <<EOF
-<osmChange>
- <delete>
- <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- </delete>
- <create>
- <node id='-1' lon='9' lat='9' changeset='#{changeset_id}' version='0'/>
- <node id='-2' lon='8' lat='9' changeset='#{changeset_id}' version='0'/>
- <node id='-3' lon='7' lat='9' changeset='#{changeset_id}' version='0'/>
- </create>
- <modify>
- <node id='3' lon='20' lat='15' changeset='#{changeset_id}' version='1'/>
- <way id='1' changeset='#{changeset_id}' version='1'>
- <nd ref='3'/>
- <nd ref='-1'/>
- <nd ref='-2'/>
- <nd ref='-3'/>
- </way>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <delete>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ </delete>
+ <create>
+ <node id='-1' lon='9' lat='9' changeset='#{changeset_id}' version='0'/>
+ <node id='-2' lon='8' lat='9' changeset='#{changeset_id}' version='0'/>
+ <node id='-3' lon='7' lat='9' changeset='#{changeset_id}' version='0'/>
+ </create>
+ <modify>
+ <node id='#{node2.id}' lon='20' lat='15' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node2.id}'/>
+ <nd ref='-1'/>
+ <nd ref='-2'/>
+ <nd ref='-3'/>
+ </way>
+ </modify>
+ </osmChange>
EOF
# upload it
end
def test_changeset_download
- tag = create(:old_node_tag, :old_node => nodes(:used_node_2))
+ changeset = create(:changeset)
+ node = create(:node, :with_history, :version => 1, :changeset => changeset)
+ tag = create(:old_node_tag, :old_node => node.old_nodes.find_by(:version => 1))
+ node2 = create(:node, :with_history, :version => 1, :changeset => changeset)
+ _node3 = create(:node, :with_history, :deleted, :version => 1, :changeset => changeset)
+ _relation = create(:relation, :with_history, :version => 1, :changeset => changeset)
+ _relation2 = create(:relation, :with_history, :deleted, :version => 1, :changeset => changeset)
- get :download, :id => changesets(:normal_user_first_change).id
+ get :download, :id => changeset.id
assert_response :success
assert_template nil
# FIXME: needs more assert_select tests
assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do
assert_select "create", :count => 5
- assert_select "create>node[id='#{nodes(:used_node_2).node_id}'][visible='#{nodes(:used_node_2).visible?}'][version='#{nodes(:used_node_2).version}']" do
+ assert_select "create>node[id='#{node.id}'][visible='#{node.visible?}'][version='#{node.version}']" do
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
- assert_select "create>node[id='#{nodes(:visible_node).node_id}']"
+ assert_select "create>node[id='#{node2.id}']"
end
end
# check that the bounding box of a changeset gets updated correctly
# FIXME: This should really be moded to a integration test due to the with_controller
def test_changeset_bbox
+ way = create(:way)
+ create(:way_node, :way => way, :node => create(:node, :lat => 3, :lon => 3))
+
basic_authorization create(:user).email, "test"
# create a new changeset
# add (delete) a way to it, which contains a point at (3,3)
with_controller(WayController.new) do
- content update_changeset(current_ways(:visible_way).to_xml,
- changeset_id)
- put :delete, :id => current_ways(:visible_way).id
+ content update_changeset(way.to_xml, changeset_id)
+ put :delete, :id => way.id
assert_response :success, "Couldn't delete a way."
end
user = create(:user)
changeset = create(:changeset, :user => user)
closed_changeset = create(:changeset, :closed, :user => user, :created_at => Time.utc(2008, 1, 1, 0, 0, 0), :closed_at => Time.utc(2008, 1, 2, 0, 0, 0))
+ changeset2 = create(:changeset, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 15 * GeoRecord::SCALE, :max_lon => 15 * GeoRecord::SCALE)
+ changeset3 = create(:changeset, :min_lat => 4.5 * GeoRecord::SCALE, :min_lon => 4.5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
get :query, :bbox => "-10,-10, 10, 10"
assert_response :success, "can't get changesets in bbox"
- assert_changesets [1, 4, 6]
+ assert_changesets [changeset2, changeset3]
get :query, :bbox => "4.5,4.5,4.6,4.6"
assert_response :success, "can't get changesets in bbox"
- assert_changesets [1]
+ assert_changesets [changeset3]
# not found when looking for changesets of non-existing users
get :query, :user => User.maximum(:id) + 1
basic_authorization private_user.email, "test"
get :query, :user => private_user.id
assert_response :success, "can't get changesets by user ID"
- assert_changesets [private_user_changeset.id, private_user_closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset]
get :query, :display_name => private_user.display_name
assert_response :success, "can't get changesets by user name"
- assert_changesets [private_user_changeset.id, private_user_closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset]
# check that the correct error is given when we provide both UID and name
get :query, :user => private_user.id, :display_name => private_user.display_name
get :query, :user => private_user.id, :open => true
assert_response :success, "can't get changesets by user and open"
- assert_changesets [private_user_changeset.id]
+ assert_changesets [private_user_changeset]
get :query, :time => "2007-12-31"
assert_response :success, "can't get changesets by time-since"
- assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset, changeset, closed_changeset, changeset2, changeset3]
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, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset, changeset, closed_changeset, changeset2, changeset3]
get :query, :time => "2007-12-31T23:59Z,2008-01-02T00:01Z"
assert_response :success, "can't get changesets by time-range"
- assert_changesets [1, 5, 6, closed_changeset.id]
+ assert_changesets [closed_changeset]
get :query, :open => "true"
assert_response :success, "can't get changesets by open-ness"
- assert_changesets [1, 2, 4, private_user_changeset.id, changeset.id]
+ assert_changesets [private_user_changeset, changeset, changeset2, changeset3]
get :query, :closed => "true"
assert_response :success, "can't get changesets by closed-ness"
- assert_changesets [3, 5, 6, 7, 8, 9, private_user_closed_changeset.id, closed_changeset.id]
+ assert_changesets [private_user_closed_changeset, closed_changeset]
get :query, :closed => "true", :user => private_user.id
assert_response :success, "can't get changesets by closed-ness and user"
- assert_changesets [private_user_closed_changeset.id]
+ assert_changesets [private_user_closed_changeset]
get :query, :closed => "true", :user => user.id
assert_response :success, "can't get changesets by closed-ness and user"
- assert_changesets [closed_changeset.id]
+ assert_changesets [closed_changeset]
get :query, :changesets => "#{private_user_changeset.id},#{changeset.id},#{closed_changeset.id}"
assert_response :success, "can't get changesets by id (as comma-separated string)"
- assert_changesets [private_user_changeset.id, changeset.id, closed_changeset.id]
+ assert_changesets [private_user_changeset, changeset, closed_changeset]
get :query, :changesets => ""
assert_response :bad_request, "should be a bad request since changesets is empty"
##
# check updating tags on a changeset
def test_changeset_update
+ private_user = create(:user, :data_public => false)
+ private_changeset = create(:changeset, :user => private_user)
+ user = create(:user)
+ changeset = create(:changeset, :user => user)
+
## First try with a non-public user
- changeset = changesets(:normal_user_first_change)
- new_changeset = changeset.to_xml
+ new_changeset = private_changeset.to_xml
new_tag = XML::Node.new "tag"
new_tag["k"] = "tagtesting"
new_tag["v"] = "valuetesting"
content new_changeset
# try without any authorization
- put :update, :id => changeset.id
+ put :update, :id => private_changeset.id
assert_response :unauthorized
# try with the wrong authorization
basic_authorization create(:user).email, "test"
- put :update, :id => changeset.id
+ put :update, :id => private_changeset.id
assert_response :conflict
# now this should get an unauthorized
- basic_authorization changeset.user.email, "test"
- put :update, :id => changeset.id
+ basic_authorization private_user.email, "test"
+ put :update, :id => private_changeset.id
assert_require_public_data "user with their data non-public, shouldn't be able to edit their changeset"
## Now try with the public user
- changeset = changesets(:public_user_first_change)
create(:changeset_tag, :changeset => changeset)
new_changeset = changeset.to_xml
new_tag = XML::Node.new "tag"
assert_response :conflict
# now this should work...
- basic_authorization changeset.user.email, "test"
+ basic_authorization user.email, "test"
put :update, :id => changeset.id
assert_response :success
def test_changeset_update_invalid
basic_authorization create(:user).email, "test"
- changeset = changesets(:normal_user_first_change)
+ changeset = create(:changeset)
new_changeset = changeset.to_xml
new_tag = XML::Node.new "tag"
new_tag["k"] = "testing"
end
##
- # This should display the last 20 changesets closed
+ # This should display the last 20 non-empty changesets
def test_feed
+ changeset = create(:changeset, :num_changes => 1)
+ closed_changeset = create(:changeset, :closed, :num_changes => 1)
+ _empty_changeset = create(:changeset, :num_changes => 0)
+
get :feed, :format => :atom
assert_response :success
assert_template "list"
assert_equal "application/atom+xml", response.content_type
- check_feed_result(Changeset.all)
+ check_feed_result([changeset, closed_changeset])
end
##
# This should display the last 20 changesets closed in a specific area
def test_feed_bbox
+ changeset = create(:changeset, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
+ closed_changeset = create(:changeset, :closed, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
+ _elsewhere_changeset = create(:changeset, :num_changes => 1, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE)
+ _empty_changeset = create(:changeset, :num_changes => 0, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE)
+
get :feed, :format => :atom, :bbox => "4.5,4.5,5.5,5.5"
assert_response :success
assert_template "list"
assert_equal "application/atom+xml", response.content_type
- check_feed_result(Changeset.where("min_lon < 55000000 and max_lon > 45000000 and min_lat < 55000000 and max_lat > 45000000"))
+ check_feed_result([changeset, closed_changeset])
end
##
# Checks the display of the user changesets feed
def test_feed_user
user = create(:user)
- create_list(:changeset, 3, :user => user, :num_changes => 4)
+ changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
+ _other_changeset = create(:changeset)
get :feed, :format => :atom, :display_name => user.display_name
assert_response :success
assert_template "list"
assert_equal "application/atom+xml", response.content_type
- check_feed_result(user.changesets)
+ check_feed_result(changesets)
end
##
# check that the changeset download for a changeset with a redacted
# element in it doesn't contain that element.
def test_diff_download_redacted
- changeset_id = changesets(:public_user_first_change).id
+ changeset = create(:changeset)
+ node = create(:node, :with_history, :version => 2, :changeset => changeset)
+ node_v1 = node.old_nodes.find_by(:version => 1)
+ node_v1.redact!(create(:redaction))
- get :download, :id => changeset_id
+ get :download, :id => changeset.id
assert_response :success
assert_select "osmChange", 1
- # this changeset contains node 17 in versions 1 & 2, but 1 should
+ # this changeset contains the node in versions 1 & 2, but 1 should
# be hidden.
- assert_select "osmChange node[id='17']", 1
- assert_select "osmChange node[id='17'][version='1']", 0
+ assert_select "osmChange node[id='#{node.id}']", 1
+ assert_select "osmChange node[id='#{node.id}'][version='1']", 0
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 => create(:changeset, :closed).id, :text => "This is a comment"
assert_response :unauthorized
basic_authorization(create(:user).email, "test")
# not closed changeset
assert_no_difference "ChangesetComment.count" do
- post :comment, :id => changesets(:normal_user_first_change).id, :text => "This is a comment"
+ post :comment, :id => create(:changeset).id, :text => "This is a comment"
end
assert_response :conflict
# no text
assert_no_difference "ChangesetComment.count" do
- post :comment, :id => changesets(:normal_user_closed_change).id
+ post :comment, :id => create(:changeset, :closed).id
end
assert_response :bad_request
# empty text
assert_no_difference "ChangesetComment.count" do
- post :comment, :id => changesets(:normal_user_closed_change).id, :text => ""
+ post :comment, :id => create(:changeset, :closed).id, :text => ""
end
assert_response :bad_request
end
# test subscribe success
def test_subscribe_success
basic_authorization(create(:user).email, "test")
- changeset = changesets(:normal_user_closed_change)
+ changeset = create(:changeset, :closed)
assert_difference "changeset.subscribers.count", 1 do
post :subscribe, :id => changeset.id
user = create(:user)
# unauthorized
- changeset = changesets(:normal_user_closed_change)
+ changeset = create(:changeset, :closed)
assert_no_difference "changeset.subscribers.count" do
post :subscribe, :id => changeset.id
end
assert_response :not_found
# not closed changeset
- changeset = changesets(:normal_user_first_change)
+ changeset = create(:changeset)
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)
+ changeset = create(:changeset, :closed)
changeset.subscribers.push(user)
assert_no_difference "changeset.subscribers.count" do
post :subscribe, :id => changeset.id
def test_unsubscribe_success
user = create(:user)
basic_authorization(user.email, "test")
- changeset = changesets(:normal_user_subscribed_change)
+ changeset = create(:changeset, :closed)
changeset.subscribers.push(user)
assert_difference "changeset.subscribers.count", -1 do
# test unsubscribe fail
def test_unsubscribe_fail
# unauthorized
- changeset = changesets(:normal_user_closed_change)
+ changeset = create(:changeset, :closed)
assert_no_difference "changeset.subscribers.count" do
post :unsubscribe, :id => changeset.id
end
assert_response :not_found
# not closed changeset
- changeset = changesets(:normal_user_first_change)
+ changeset = create(:changeset)
assert_no_difference "changeset.subscribers.count" do
post :unsubscribe, :id => changeset.id
end
assert_response :conflict
# trying to unsubscribe when not subscribed
- changeset = changesets(:normal_user_closed_change)
+ changeset = create(:changeset, :closed)
assert_no_difference "changeset.subscribers.count" do
post :unsubscribe, :id => changeset.id
end
##
# test comments feed
def test_comments_feed
- create_list(:changeset_comment, 3, :changeset_id => changesets(:normal_user_closed_change).id)
+ changeset = create(:changeset, :closed)
+ create_list(:changeset_comment, 3, :changeset => changeset)
get :comments_feed, :format => "rss"
assert_response :success
end
end
- get :comments_feed, :id => changesets(:normal_user_closed_change), :format => "rss"
+ get :comments_feed, :id => changeset.id, :format => "rss"
assert_response :success
assert_equal "application/rss+xml", @response.content_type
assert_select "rss", :count => 1 do
##
# boilerplate for checking that certain changesets exist in the
# output.
- def assert_changesets(ids)
- assert_select "osm>changeset", ids.size
- ids.each do |id|
- assert_select "osm>changeset[id='#{id}']", 1
+ def assert_changesets(changesets)
+ assert_select "osm>changeset", changesets.size
+ changesets.each do |changeset|
+ assert_select "osm>changeset[id='#{changeset.id}']", 1
end
end
##
# check the result of a feed
def check_feed_result(changesets)
- changesets = changesets.where("num_changes > 0")
- .order(:created_at => :desc)
- .limit(20)
assert changesets.size <= 20
assert_select "feed", :count => [changesets.size, 1].min do
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal %w(us_postcode osm_nominatim), assigns(:sources)
+ assert_equal %w[us_postcode osm_nominatim], assigns(:sources)
end
end
"CR2 6XH",
"DN55 1PT"
].each do |code|
- search_check code, %w(uk_postcode osm_nominatim)
+ search_check code, %w[uk_postcode osm_nominatim]
end
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", %w(osm_nominatim geonames)
+ search_check "foo bar baz", %w[osm_nominatim geonames]
end
##
assert_response :success
assert_template :search
assert_template :layout => "map"
- assert_equal %w(latlon osm_nominatim_reverse geonames_reverse), assigns(:sources)
+ assert_equal %w[latlon osm_nominatim_reverse geonames_reverse], assigns(:sources)
assert_nil @controller.params[:query]
assert_in_delta lat, @controller.params[:lat]
assert_in_delta lon, @controller.params[:lon]
assert_response :success
assert_template :search
assert_template :layout => "xhr"
- assert_equal %w(latlon osm_nominatim_reverse geonames_reverse), assigns(:sources)
+ assert_equal %w[latlon osm_nominatim_reverse geonames_reverse], assigns(:sources)
assert_nil @controller.params[:query]
assert_in_delta lat, @controller.params[:lat]
assert_in_delta lon, @controller.params[:lon]
require "test_helper"
class NodeControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
##
# test fetching multiple nodes
def test_nodes
+ node1 = create(:node)
+ node2 = create(:node, :deleted)
+ node3 = create(:node)
+ node4 = create(:node, :with_history, :version => 2)
+ node5 = create(:node, :deleted, :with_history, :version => 2)
+
# check error when no parameter provided
get :nodes
assert_response :bad_request
assert_response :bad_request
# test a working call
- get :nodes, :nodes => "1,2,4,15,17"
+ get :nodes, :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}"
assert_response :success
assert_select "osm" do
assert_select "node", :count => 5
- assert_select "node[id='1'][visible='true']", :count => 1
- assert_select "node[id='2'][visible='false']", :count => 1
- assert_select "node[id='4'][visible='true']", :count => 1
- assert_select "node[id='15'][visible='true']", :count => 1
- assert_select "node[id='17'][visible='false']", :count => 1
+ assert_select "node[id='#{node1.id}'][visible='true']", :count => 1
+ assert_select "node[id='#{node2.id}'][visible='false']", :count => 1
+ assert_select "node[id='#{node3.id}'][visible='true']", :count => 1
+ assert_select "node[id='#{node4.id}'][visible='true']", :count => 1
+ assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
end
# check error when a non-existent node is included
- get :nodes, :nodes => "1,2,4,15,17,400"
+ get :nodes, :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},400"
assert_response :not_found
end
require "old_node_controller"
class OldNodeControllerTest < ActionController::TestCase
- api_fixtures
-
#
# TODO: test history
#
require "old_relation_controller"
class OldRelationControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
require "old_way_controller"
class OldWayControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
require "redactions_controller"
class RedactionsControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
end
def test_index
+ create(:redaction)
+
get :index
assert_response :success
assert_template :index
require "relation_controller"
class RelationControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
def test_read
# check that a visible relation is returned properly
- get :read, :id => current_relations(:visible_relation).id
+ get :read, :id => create(:relation).id
assert_response :success
# check that an invisible relation is not returned
- get :read, :id => current_relations(:invisible_relation).id
+ get :read, :id => create(:relation, :deleted).id
assert_response :gone
# check chat a non-existent relation is not returned
get :full, :id => 999999
assert_response :not_found
- get :full, :id => current_relations(:invisible_relation).id
+ get :full, :id => create(:relation, :deleted).id
assert_response :gone
- get :full, :id => current_relations(:visible_relation).id
+ get :full, :id => create(:relation).id
assert_response :success
# FIXME: check whether this contains the stuff we want!
end
##
# test fetching multiple relations
def test_relations
+ relation1 = create(:relation)
+ relation2 = create(:relation, :deleted)
+ relation3 = create(:relation, :with_history, :version => 2)
+ relation4 = create(:relation, :with_history, :version => 2)
+ relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
+
# check error when no parameter provided
get :relations
assert_response :bad_request
assert_response :bad_request
# test a working call
- get :relations, :relations => "1,2,4,7"
+ get :relations, :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}"
assert_response :success
assert_select "osm" do
assert_select "relation", :count => 4
- assert_select "relation[id='1'][visible='true']", :count => 1
- assert_select "relation[id='2'][visible='false']", :count => 1
- assert_select "relation[id='4'][visible='true']", :count => 1
- assert_select "relation[id='7'][visible='true']", :count => 1
+ assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
+ assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
+ assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
+ assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
end
# check error when a non-existent relation is included
- get :relations, :relations => "1,2,4,7,400"
+ get :relations, :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},400"
assert_response :not_found
end
# josm-dev.
## FIXME Move this to an integration test
def test_update_relation_tags
- basic_authorization "test@example.com", "test"
- rel_id = current_relations(:multi_tag_relation).id
- create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
- cs_id = changesets(:public_user_first_change).id
+ user = create(:user)
+ changeset = create(:changeset, :user => user)
+ relation = create(:relation)
+ create_list(:relation_tag, 4, :relation => relation)
- with_relation(rel_id) do |rel|
+ basic_authorization user.email, "test"
+
+ with_relation(relation.id) do |rel|
# alter one of the tags
tag = rel.find("//osm/relation/tag").first
tag["v"] = "some changed value"
- update_changeset(rel, cs_id)
+ update_changeset(rel, changeset.id)
# check that the downloaded tags are the same as the uploaded tags...
new_version = with_update(rel) do |new_rel|
end
# check the original one in the current_* table again
- with_relation(rel_id) { |r| assert_tags_equal rel, r }
+ with_relation(relation.id) { |r| assert_tags_equal rel, r }
# now check the version in the history
- with_relation(rel_id, new_version) { |r| assert_tags_equal rel, r }
+ with_relation(relation.id, new_version) { |r| assert_tags_equal rel, r }
end
end
# when a relation's tag is modified then it should put the bounding
# box of all its members into the changeset.
def test_tag_modify_bounding_box
- # in current fixtures, relation 5 contains nodes 3 and 5 (node 3
- # indirectly via way 3), so the bbox should be [3,3,5,5].
+ relation = create(:relation)
+ node1 = create(:node, :lat => 3, :lon => 3)
+ node2 = create(:node, :lat => 5, :lon => 5)
+ way = create(:way)
+ create(:way_node, :way => way, :node => node1)
+ create(:relation_member, :relation => relation, :member => way)
+ create(:relation_member, :relation => relation, :member => node2)
+ # the relation contains nodes1 and node2 (node1
+ # indirectly via the way), so the bbox should be [3,3,5,5].
check_changeset_modify(BoundingBox.new(3, 3, 5, 5)) do |changeset_id|
# add a tag to an existing relation
- relation_xml = current_relations(:visible_relation).to_xml
+ relation_xml = relation.to_xml
relation_element = relation_xml.find("//osm/relation").first
new_tag = XML::Node.new("tag")
new_tag["k"] = "some_new_tag"
# upload the change
content relation_xml
- put :update, :id => current_relations(:visible_relation).id
+ put :update, :id => relation.id
assert_response :success, "can't update relation for tag/bbox test"
end
end
# add a member to a relation and check the bounding box is only that
# element.
def test_add_member_bounding_box
- relation_id = current_relations(:visible_relation).id
-
- [current_nodes(:used_node_1),
- current_nodes(:used_node_2),
- current_ways(:used_way),
- current_ways(:way_with_versions)].each_with_index do |element, _version|
+ relation = create(:relation)
+ node1 = create(:node, :lat => 4, :lon => 4)
+ node2 = create(:node, :lat => 7, :lon => 7)
+ way1 = create(:way)
+ create(:way_node, :way => way1, :node => create(:node, :lat => 8, :lon => 8))
+ way2 = create(:way)
+ create(:way_node, :way => way2, :node => create(:node, :lat => 9, :lon => 9), :sequence_id => 1)
+ create(:way_node, :way => way2, :node => create(:node, :lat => 10, :lon => 10), :sequence_id => 2)
+
+ [node1, node2, way1, way2].each do |element|
bbox = element.bbox.to_unscaled
check_changeset_modify(bbox) do |changeset_id|
- relation_xml = Relation.find(relation_id).to_xml
+ 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
# upload the change
content relation_xml
- put :update, :id => current_relations(:visible_relation).id
+ put :update, :id => relation.id
assert_response :success, "can't update relation for add #{element.class}/bbox test: #{@response.body}"
# get it back and check the ordering
- get :read, :id => relation_id
+ get :read, :id => relation.id
assert_response :success, "can't read back the relation: #{@response.body}"
check_ordering(relation_xml, @response.body)
end
# remove a member from a relation and check the bounding box is
# only that element.
def test_remove_member_bounding_box
+ relation = create(:relation)
+ node1 = create(:node, :lat => 3, :lon => 3)
+ node2 = create(:node, :lat => 5, :lon => 5)
+ create(:relation_member, :relation => relation, :member => node1)
+ create(:relation_member, :relation => relation, :member => node2)
+
check_changeset_modify(BoundingBox.new(5, 5, 5, 5)) do |changeset_id|
# remove node 5 (5,5) from an existing relation
- relation_xml = current_relations(:visible_relation).to_xml
+ relation_xml = relation.to_xml
relation_xml
- .find("//osm/relation/member[@type='node'][@ref='5']")
+ .find("//osm/relation/member[@type='node'][@ref='#{node2.id}']")
.first.remove!
# update changeset ID to point to new changeset
# upload the change
content relation_xml
- put :update, :id => current_relations(:visible_relation).id
+ put :update, :id => relation.id
assert_response :success, "can't update relation for remove node/bbox test"
end
end
basic_authorization(user.email, "test")
- doc_str = <<OSM
-<osm>
- <relation changeset='#{changeset.id}'>
- <member ref='#{node1.id}' type='node' role='first'/>
- <member ref='#{node2.id}' type='node' role='second'/>
- <member ref='#{way1.id}' type='way' role='third'/>
- <member ref='#{way2.id}' type='way' role='fourth'/>
- </relation>
-</osm>
+ doc_str = <<OSM.strip_heredoc
+ <osm>
+ <relation changeset='#{changeset.id}'>
+ <member ref='#{node1.id}' type='node' role='first'/>
+ <member ref='#{node2.id}' type='node' role='second'/>
+ <member ref='#{way1.id}' type='way' role='third'/>
+ <member ref='#{way2.id}' type='way' role='fourth'/>
+ </relation>
+ </osm>
OSM
doc = XML::Parser.string(doc_str).parse
node1 = create(:node)
node2 = create(:node)
- doc_str = <<OSM
-<osm>
- <relation changeset='#{changeset.id}'>
- <member ref='#{node1.id}' type='node' role='forward'/>
- <member ref='#{node2.id}' type='node' role='forward'/>
- <member ref='#{node1.id}' type='node' role='forward'/>
- <member ref='#{node2.id}' type='node' role='forward'/>
- </relation>
-</osm>
+ doc_str = <<OSM.strip_heredoc
+ <osm>
+ <relation changeset='#{changeset.id}'>
+ <member ref='#{node1.id}' type='node' role='forward'/>
+ <member ref='#{node2.id}' type='node' role='forward'/>
+ <member ref='#{node1.id}' type='node' role='forward'/>
+ <member ref='#{node2.id}' type='node' role='forward'/>
+ </relation>
+ </osm>
OSM
doc = XML::Parser.string(doc_str).parse
node3 = create(:node)
node4 = create(:node)
- doc_str = <<OSM
-<osm>
- <relation changeset='#{changeset.id}'>
- <member ref='#{node1.id}' type='node' role='forward'/>
- <member ref='#{node4.id}' type='node' role='forward'/>
- <member ref='#{node3.id}' type='node' role='forward'/>
- <member ref='#{node2.id}' type='node' role='forward'/>
- </relation>
-</osm>
+ doc_str = <<OSM.strip_heredoc
+ <osm>
+ <relation changeset='#{changeset.id}'>
+ <member ref='#{node1.id}' type='node' role='forward'/>
+ <member ref='#{node4.id}' type='node' role='forward'/>
+ <member ref='#{node3.id}' type='node' role='forward'/>
+ <member ref='#{node2.id}' type='node' role='forward'/>
+ </relation>
+ </osm>
OSM
doc = XML::Parser.string(doc_str).parse
basic_authorization(user.email, "test")
# remove all the members from a relation. the result is pretty useless, but
# still technically valid.
def test_remove_all_members
+ relation = create(:relation)
+ node1 = create(:node, :lat => 3, :lon => 3)
+ node2 = create(:node, :lat => 5, :lon => 5)
+ way = create(:way)
+ create(:way_node, :way => way, :node => node1)
+ create(:relation_member, :relation => relation, :member => way)
+ create(:relation_member, :relation => relation, :member => node2)
+
check_changeset_modify(BoundingBox.new(3, 3, 5, 5)) do |changeset_id|
- relation_xml = current_relations(:visible_relation).to_xml
+ relation_xml = relation.to_xml
relation_xml
.find("//osm/relation/member")
.each(&:remove!)
# upload the change
content relation_xml
- put :update, :id => current_relations(:visible_relation).id
+ put :update, :id => relation.id
assert_response :success, "can't update relation for remove all members test"
- checkrelation = Relation.find(current_relations(:visible_relation).id)
+ checkrelation = Relation.find(relation.id)
assert_not_nil(checkrelation,
"uploaded relation not found in database after upload")
assert_equal(0, checkrelation.members.length,
# that the changeset bounding box is +bbox+.
def check_changeset_modify(bbox)
## First test with the private user to check that you get a forbidden
- basic_authorization(users(:normal_user).email, "test")
+ basic_authorization(create(:user, :data_public => false).email, "test")
# create a new changeset for this operation, so we are assured
# that the bounding box will be newly-generated.
end
## Now do the whole thing with the public user
- basic_authorization(users(:public_user).email, "test")
+ basic_authorization(create(:user).email, "test")
# create a new changeset for this operation, so we are assured
# that the bounding box will be newly-generated.
require "test_helper"
class SearchControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
##
# test searching ways
def test_search_ways
- [:visible_way, :invisible_way, :used_way].each do |way|
- create(:way_tag, :way => current_ways(way), :k => "test", :v => "yes")
+ first_way = create(:way_with_nodes, :nodes_count => 2)
+ deleted_way = create(:way_with_nodes, :deleted, :nodes_count => 2)
+ third_way = create(:way_with_nodes, :nodes_count => 2)
+
+ [first_way, deleted_way, third_way].each do |way|
+ create(:way_tag, :way => way, :k => "test", :v => "yes")
end
- create(:way_tag, :way => current_ways(:used_way), :k => "name", :v => "Test Way")
+ create(:way_tag, :way => third_way, :k => "name", :v => "Test Way")
get :search_ways, :type => "test"
assert_response :service_unavailable
##
# test searching relations
def test_search_relations
- [:visible_relation, :invisible_relation, :used_relation].each do |relation|
- create(:relation_tag, :relation => current_relations(relation), :k => "test", :v => "yes")
+ first_relation = create(:relation)
+ deleted_relation = create(:relation)
+ third_relation = create(:relation)
+
+ [first_relation, deleted_relation, third_relation].each do |relation|
+ create(:relation_tag, :relation => relation, :k => "test", :v => "yes")
end
- create(:relation_tag, :relation => current_relations(:used_relation), :k => "name", :v => "Test Relation")
+ create(:relation_tag, :relation => third_relation, :k => "name", :v => "Test Relation")
get :search_relations, :type => "test"
assert_response :service_unavailable
require "test_helper"
class SiteControllerTest < ActionController::TestCase
- api_fixtures
-
##
# setup oauth keys
def setup
# Test editing a specific way
def test_edit_with_way
user = create(:user)
- way = current_ways(:visible_way)
+ node = create(:node, :lat => 3, :lon => 3)
+ way = create(:way)
+ create(:way_node, :node => node, :way => way)
get :edit, { :way => way.id }, { :user => user }
assert_response :success
require "test_helper"
class SwfControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
trace = Trace.order(:id => :desc).first
assert_equal "a.gpx", trace.name
assert_equal "New Trace", trace.description
- assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
+ assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
assert_equal "trackable", trace.visibility
assert_equal false, trace.inserted
assert_equal File.new(fixture).read, File.new(trace.trace_name).read
trace = Trace.find(response.body.to_i)
assert_equal "a.gpx", trace.name
assert_equal "New Trace", trace.description
- assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
+ assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
assert_equal "trackable", trace.visibility
assert_equal false, trace.inserted
assert_equal File.new(fixture).read, File.new(trace.trace_name).read
trace = Trace.find(response.body.to_i)
assert_equal "a.gpx", trace.name
assert_equal "New Trace", trace.description
- assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
+ assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
assert_equal "public", trace.visibility
assert_equal false, trace.inserted
assert_equal File.new(fixture).read, File.new(trace.trace_name).read
trace = Trace.find(response.body.to_i)
assert_equal "a.gpx", trace.name
assert_equal "New Trace", trace.description
- assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
+ assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
assert_equal "private", trace.visibility
assert_equal false, trace.inserted
assert_equal File.new(fixture).read, File.new(trace.trace_name).read
require "test_helper"
class UserBlocksControllerTest < ActionController::TestCase
- fixtures :users, :user_roles
-
##
# test all routes which lead to this controller
def test_routes
require "test_helper"
class UserControllerTest < ActionController::TestCase
- api_fixtures
-
def setup
stub_hostip_requests
end
basic_authorization(user.email, "test")
get :api_gpx_files
assert_response :success
- assert_equal "text/xml", response.content_type
+ assert_equal "application/xml", response.content_type
# check the data that is returned
assert_select "gpx_file[id='#{trace1.id}']", 1 do
end
def test_list_get
+ user = create(:user)
+ moderator_user = create(:moderator_user)
+ administrator_user = create(:administrator_user)
+ _suspended_user = create(:user, :suspended)
+ _ip_user = create(:user, :creation_ip => "1.2.3.4")
+
+ # There are now 7 users - the five above, plus two extra "granters" for the
+ # moderator_user and administrator_user
+ assert_equal 7, User.count
+
# Shouldn't work when not logged in
get :list
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path
- session[:user] = create(:user).id
+ session[:user] = user.id
# Shouldn't work when logged in as a normal user
get :list
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path
- session[:user] = create(:moderator_user).id
+ session[:user] = moderator_user.id
# Shouldn't work when logged in as a moderator
get :list
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path
- session[:user] = create(:administrator_user).id
+ session[:user] = administrator_user.id
+ # Note there is a header row, so all row counts are users + 1
# Should work when logged in as an administrator
get :list
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => User.count + 1
+ assert_select "table#user_list tr", :count => 7 + 1
# Should be able to limit by status
get :list, :status => "suspended"
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
+ assert_select "table#user_list tr", :count => 1 + 1
# Should be able to limit by IP address
get :list, :ip => "1.2.3.4"
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
+ assert_select "table#user_list tr", :count => 1 + 1
end
def test_list_get_paginated
session[:user] = create(:administrator_user).id
+ # 100 examples, an administrator, and a granter for the admin.
+ assert_equal 102, User.count
+
get :list
assert_response :success
assert_template :list
get :list, :page => 3
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => 28
+ assert_select "table#user_list tr", :count => 3
end
def test_list_post_confirm
# try the read again
get :read
assert_response :success
- assert_equal "text/xml", @response.content_type
+ assert_equal "application/xml", @response.content_type
assert_select "osm" do
assert_select "preferences", :count => 1 do
assert_select "preference", :count => 2
require "way_controller"
class WayControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
##
# test fetching multiple ways
def test_ways
+ way1 = create(:way)
+ way2 = create(:way, :deleted)
+ way3 = create(:way)
+ way4 = create(:way)
+
# check error when no parameter provided
get :ways
assert_response :bad_request
assert_response :bad_request
# test a working call
- get :ways, :ways => "1,2,4,6"
+ get :ways, :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}"
assert_response :success
assert_select "osm" do
assert_select "way", :count => 4
- assert_select "way[id='1'][visible='true']", :count => 1
- assert_select "way[id='2'][visible='false']", :count => 1
- assert_select "way[id='4'][visible='true']", :count => 1
- assert_select "way[id='6'][visible='true']", :count => 1
+ assert_select "way[id='#{way1.id}'][visible='true']", :count => 1
+ assert_select "way[id='#{way2.id}'][visible='false']", :count => 1
+ assert_select "way[id='#{way3.id}'][visible='true']", :count => 1
+ assert_select "way[id='#{way4.id}'][visible='true']", :count => 1
end
# check error when a non-existent way is included
- get :ways, :ways => "1,2,4,6,400"
+ get :ways, :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},400"
assert_response :not_found
end
# try and update in a closed changeset
content update_changeset(private_way.to_xml,
- create(:changeset, :closed, :user => private_user))
+ create(:changeset, :closed, :user => private_user).id)
put :update, :id => private_way.id
assert_require_public_data "update with closed changeset should be forbidden, when data isn't public"
# try and update in a closed changeset
content update_changeset(way.to_xml,
- changesets(:normal_user_closed_change).id)
+ create(:changeset, :closed, :user => user).id)
put :update, :id => way.id
assert_response :conflict, "update with closed changeset should be rejected"
+++ /dev/null
-# FIXME! all of these changesets need their bounding boxes set correctly!
-#
-<% SCALE = 10000000 unless defined?(SCALE) %>
-
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-normal_user_first_change:
- id: 1
- user_id: 1
- created_at: "2007-01-01 00:00:00"
- closed_at: <%= Time.now.utc + 86400 %>
- min_lon: <%= 1 * SCALE %>
- min_lat: <%= 1 * SCALE %>
- max_lon: <%= 5 * SCALE %>
- max_lat: <%= 5 * SCALE %>
- num_changes: 11
-
-public_user_first_change:
- id: 2
- user_id: 2
- created_at: <%= Time.now.utc %>
- closed_at: <%= Time.now.utc + 86400 %>
- num_changes: 0
-
-deleted_user_first_change:
- id: 9
- user_id: 11
- created_at: "2007-01-01 00:00:00"
- closed_at: "2007-01-02 00:00:00"
- num_changes: 0
-
-normal_user_closed_change:
- id: 3
- user_id: 1
- created_at: "2007-01-01 00:00:00"
- closed_at: "2007-01-02 00:00:00"
- num_changes: 0
-
-public_user_closed_change:
- id: 7
- user_id: 2
- created_at: "2007-01-01 00:00:00"
- closed_at: "2007-01-02 00:00:00"
- num_changes: 0
-
-public_user_version_change:
- id: 4
- user_id: 2
- created_at: <%= Time.now.utc %>
- closed_at: <%= Time.now.utc + 86400 %>
- min_lon: <%= 1 * SCALE %>
- min_lat: <%= 1 * SCALE %>
- max_lon: <%= 4 * SCALE %>
- max_lat: <%= 4 * SCALE %>
- num_changes: 8
-
-# changeset to contain all the invalid stuff that is in the
-# fixtures (nodes outside the world, etc...), but needs to have
-# a valid user...
-invalid_changeset:
- id: 5
- user_id: 3
- created_at: "2008-01-01 00:00:00"
- closed_at: "2008-01-02 00:00:00"
- num_changes: 9
-
-# changeset which still has time remaining, but has been closed
-# by containing too many elements.
-too_many_elements_changeset:
- id: 6
- user_id: 1
- created_at: "2008-01-01 00:00:00"
- closed_at: <%= Time.now.utc + 86400 %>
- min_lon: <%= 1 * SCALE %>
- min_lat: <%= 1 * SCALE %>
- max_lon: <%= 4 * SCALE %>
- max_lat: <%= 4 * SCALE %>
- num_changes: <%= Changeset::MAX_ELEMENTS + 1 %>
-
-normal_user_subscribed_change:
- id: 8
- user_id: 1
- created_at: "2007-01-01 00:00:00"
- closed_at: "2007-01-02 00:00:00"
- num_changes: 0
+++ /dev/null
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-<% SCALE = 10000000 unless defined?(SCALE) %>
-
-visible_node:
- id: 1
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 1
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-invisible_node:
- id: 2
- latitude: <%= 2*SCALE %>
- longitude: <%= 2*SCALE %>
- changeset_id: 1
- visible: false
- version: 1
- tile: <%= QuadTile.tile_for_point(2,2) %>
- timestamp: 2007-01-01 00:00:00
-
-used_node_1:
- id: 3
- latitude: <%= 3*SCALE %>
- longitude: <%= 3*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(3,3) %>
- timestamp: 2007-01-01 00:00:00
-
-used_node_2:
- id: 4
- latitude: <%= 4*SCALE %>
- longitude: <%= 4*SCALE %>
- changeset_id: 1
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(4,4) %>
- timestamp: 2007-01-01 00:00:00
-
-node_used_by_relationship:
- id: 5
- latitude: <%= 5*SCALE %>
- longitude: <%= 5*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(5,5) %>
- timestamp: 2007-01-01 00:00:00
-
-node_too_far_north:
- id: 6
- latitude: <%= 90.01*SCALE %>
- longitude: <%= 6*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(90.01,6) %>
- timestamp: 2007-01-01 00:00:00
-
-node_north_limit:
- id: 11
- latitude: <%= 90*SCALE %>
- longitude: <%= 11*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(90,11) %>
- timestamp: 2008-07-08 14:50:00
-
-node_too_far_south:
- id: 7
- latitude: <%= -90.01*SCALE %>
- longitude: <%= 7*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(-90.01,7) %>
- timestamp: 2007-01-01 00:00:00
-
-node_south_limit:
- id: 12
- latitude: <%= -90*SCALE %>
- longitude: <%= 12*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(-90,12) %>
- timestamp: 2008-07-08 15:02:18
-
-node_too_far_west:
- id: 8
- latitude: <%= 8*SCALE %>
- longitude: <%= -180.01*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(8,-180.01) %>
- timestamp: 2007-01-01 00:00:00
-
-node_west_limit:
- id: 13
- latitude: <%= 13*SCALE %>
- longitude: <%= -180*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(13,-180) %>
- timestamp: 2008-07-08 15:17:37
-
-node_too_far_east:
- id: 9
- latitude: <%= 9*SCALE %>
- longitude: <%= 180.01*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(9,180.01) %>
- timestamp: 2007-01-01 00:00:00
-
-node_east_limit:
- id: 14
- latitude: <%= 14*SCALE %>
- longitude: <%= 180*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(14,180) %>
- timestamp: 2008-07-08 15:46:16
-
-node_totally_wrong:
- id: 10
- latitude: <%= 200*SCALE %>
- longitude: <%= 200*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(200,200) %>
- timestamp: 2007-01-01 00:00:00
-
-node_with_versions:
- id: 15
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 4
- visible: true
- version: 4
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2008-01-01 00:04:00
-
-public_visible_node:
- id: 16
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-redacted_node:
- id: 17
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: false
- version: 2
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-node_with_name:
- id: 18
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 2
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-node_with_ref_without_name:
- id: 19
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
+++ /dev/null
-t1:
- relation_id: 1
- sequence_id: 1
- member_role: "some"
- member_type: "Way"
- member_id: 3
-
-t2:
- relation_id: 1
- sequence_id: 2
- member_role: "some"
- member_type: "Node"
- member_id: 5
-
-t3:
- relation_id: 1
- sequence_id: 3
- member_role: "some"
- member_type: "Relation"
- member_id: 3
-
-t4:
- relation_id: 3
- sequence_id: 1
- member_role: "some"
- member_type: "Node"
- member_id: 5
-
-t5:
- relation_id: 2
- sequence_id: 1
- member_role: "some"
- member_type: "Node"
- member_id: 5
-
-public_used:
- relation_id: 6
- member_role: "used by other relation"
- member_type: "Relation"
- member_id: 5
-
-r8_m1:
- relation_id: 8
- sequence_id: 1
- member_role: "some node"
- member_type: "Node"
- member_id: 15
-
-r8_m2:
- relation_id: 8
- sequence_id: 2
- member_role: "some way"
- member_type: "Way"
- member_id: 4
-
-r8_m3:
- relation_id: 8
- sequence_id: 3
- member_role: "some relation"
- member_type: "Relation"
- member_id: 7
+++ /dev/null
-visible_relation:
- id: 1
- changeset_id: 1
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-invisible_relation:
- id: 2
- changeset_id: 3
- timestamp: 2007-01-01 00:00:00
- visible: false
- version: 1
-
-used_relation:
- id: 3
- changeset_id: 1
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-multi_tag_relation:
- id: 4
- changeset_id: 4
- timestamp: 2009-04-21 09:50:57
- visible: true
- version: 1
-
-public_used_relation:
- id: 5
- changeset_id: 2
- timestamp: 2009-04-22 00:30:33
- visible: true
- version: 1
-
-public_visible_relation:
- id: 6
- changeset_id: 2
- timestamp: 2009-04-22 00:34:12
- visible: true
- version: 1
-
-relation_with_redacted_versions:
- id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:04:13
- visible: true
- version: 4
-
-relation_with_versions:
- id: 8
- changeset_id: 4
- timestamp: 2008-01-01 00:04:00
- visible: true
- version: 4
+++ /dev/null
-t1:
- way_id: 1
- node_id: 3
- sequence_id: 1
-
-t2:
- way_id: 2
- node_id: 3
- sequence_id: 1
-
-t3:
- way_id: 3
- node_id: 3
- sequence_id: 1
-
-t4:
- way_id: 4
- node_id: 15
- sequence_id: 1
-
-w5_n1:
- way_id: 5
- node_id: 4
- sequence_id: 1
-
-w5_n2:
- way_id: 5
- node_id: 4
- sequence_id: 2
-
-w7_n1:
- way_id: 7
- node_id: 4
- sequence_id: 1
-
-w7_n2:
- way_id: 7
- node_id: 15
- sequence_id: 2
-
-w7_n3:
- way_id: 7
- node_id: 11
- sequence_id: 3
+++ /dev/null
-visible_way:
- id: 1
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-invisible_way:
- id: 2
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: false
- version: 1
-
-used_way:
- id: 3
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-way_with_versions:
- id: 4
- changeset_id: 4
- timestamp: 2008-01-01 00:04:00
- visible: true
- version: 4
-
-way_with_duplicate_nodes:
- id: 5
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-way_with_redacted_versions:
- id: 6
- changeset_id: 4
- timestamp: 2008-01-01 00:04:13
- visible: true
- version: 4
-
-way_with_multiple_nodes:
- id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:00:00
- visible: true
- version: 2
+++ /dev/null
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-<% SCALE = 10000000 unless defined?(SCALE) %>
-
-visible_node:
- node_id: 1
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 1
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-invisible_node:
- node_id: 2
- latitude: <%= 2*SCALE %>
- longitude: <%= 2*SCALE %>
- changeset_id: 1
- visible: false
- version: 1
- tile: <%= QuadTile.tile_for_point(2,2) %>
- timestamp: 2007-01-01 00:00:00
-
-used_node_1:
- node_id: 3
- latitude: <%= 3*SCALE %>
- longitude: <%= 3*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(3,3) %>
- timestamp: 2007-01-01 00:00:00
-
-used_node_2:
- node_id: 4
- latitude: <%= 4*SCALE %>
- longitude: <%= 4*SCALE %>
- changeset_id: 1
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(4,4) %>
- timestamp: 2007-01-01 00:00:00
-
-node_used_by_relationship:
- node_id: 5
- latitude: <%= 5*SCALE %>
- longitude: <%= 5*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(5,5) %>
- timestamp: 2007-01-01 00:00:00
-
-node_too_far_north:
- node_id: 6
- latitude: <%= 90.01*SCALE %>
- longitude: <%= 6*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(90.01,6) %>
- timestamp: 2007-01-01 00:00:00
-
-node_north_limit:
- node_id: 11
- latitude: <%= 90*SCALE %>
- longitude: <%= 11*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(90,11) %>
- timestamp: 2008-07-08 14:50:00
-
-node_too_far_south:
- node_id: 7
- latitude: <%= -90.01*SCALE %>
- longitude: <%= 7*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(-90.01,7) %>
- timestamp: 2007-01-01 00:00:00
-
-node_south_limit:
- node_id: 12
- latitude: <%= -90*SCALE %>
- longitude: <%= 12*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(-90,12) %>
- timestamp: 2008-07-08 15:02:18
-
-node_too_far_west:
- node_id: 8
- latitude: <%= 8*SCALE %>
- longitude: <%= -180.01*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(8,-180.01) %>
- timestamp: 2007-01-01 00:00:00
-
-node_west_limit:
- node_id: 13
- latitude: <%= 13*SCALE %>
- longitude: <%= -180*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(13,-180) %>
- timestamp: 2008-07-08 15:17:37
-
-node_too_far_east:
- node_id: 9
- latitude: <%= 9*SCALE %>
- longitude: <%= 180.01*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(9,180.01) %>
- timestamp: 2007-01-01 00:00:00
-
-node_east_limit:
- node_id: 14
- latitude: <%= 14*SCALE %>
- longitude: <%= 180*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(14,180) %>
- timestamp: 2008-07-08 15:46:16
-
-node_totally_wrong:
- node_id: 10
- latitude: <%= 200*SCALE %>
- longitude: <%= 200*SCALE %>
- changeset_id: 5
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(200,200) %>
- timestamp: 2007-01-01 00:00:00
-
-node_with_versions_v1:
- node_id: 15
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 4
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2008-01-01 00:01:00
-
-node_with_versions_v2:
- node_id: 15
- latitude: <%= 2*SCALE %>
- longitude: <%= 2*SCALE %>
- changeset_id: 4
- visible: true
- version: 2
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2008-01-01 00:02:00
-
-node_with_versions_v3:
- node_id: 15
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 4
- visible: true
- version: 3
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2008-01-01 00:03:00
-
-node_with_versions_v4:
- node_id: 15
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 4
- visible: true
- version: 4
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2008-01-01 00:04:00
-
-public_visible_node:
- node_id: 16
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-redacted_node_redacted_version:
- node_id: 17
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
- redaction_id: 1
-
-redacted_node_current_version:
- node_id: 17
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: false
- version: 2
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
-
-node_with_name_redacted_version:
- node_id: 18
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 1
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
- redaction_id: 1
-
-node_with_name_current_version:
- node_id: 18
- latitude: <%= 1*SCALE %>
- longitude: <%= 1*SCALE %>
- changeset_id: 2
- visible: true
- version: 2
- tile: <%= QuadTile.tile_for_point(1,1) %>
- timestamp: 2007-01-01 00:00:00
+++ /dev/null
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-example:
- id: 1
- user_id: 5 # the moderator user
- title: Example redaction
- description: Usually some text would go here to say something about why the redaction happened.
+++ /dev/null
-t1:
- relation_id: 1
- sequence_id: 1
- member_role: "some"
- member_type: "Way"
- member_id: 3
- version: 1
-
-t2:
- relation_id: 1
- sequence_id: 2
- member_role: "some"
- member_type: "Node"
- member_id: 5
- version: 1
-
-t3:
- relation_id: 1
- sequence_id: 3
- member_role: "some"
- member_type: "Relation"
- member_id: 3
- version: 1
-
-t4:
- relation_id: 3
- sequence_id: 1
- member_role: "some"
- member_type: "Node"
- member_id: 5
- version: 1
-
-t5:
- relation_id: 2
- sequence_id: 1
- member_role: "some"
- member_type: "Node"
- member_id: 5
- version: 1
-
-public_used:
- relation_id: 6
- sequence_id: 1
- member_role: "used by other relation"
- member_type: "Relation"
- member_id: 5
- version: 1
-
-r8_v1_m1:
- relation_id: 8
- sequence_id: 1
- member_role: "some node"
- member_type: "Node"
- member_id: 15
- version: 1
-
-r8_v2_m1:
- relation_id: 8
- sequence_id: 1
- member_role: "some changed node"
- member_type: "Node"
- member_id: 15
- version: 2
-
-r8_v3_m1:
- relation_id: 8
- sequence_id: 1
- member_role: "some changed node"
- member_type: "Node"
- member_id: 15
- version: 3
-
-r8_v3_m3:
- relation_id: 8
- sequence_id: 2
- member_role: "some relation"
- member_type: "Relation"
- member_id: 7
- version: 3
-
-r8_v4_m1:
- relation_id: 8
- sequence_id: 1
- member_role: "some node"
- member_type: "Node"
- member_id: 15
- version: 4
-
-r8_v4_m2:
- relation_id: 8
- sequence_id: 2
- member_role: "some way"
- member_type: "Way"
- member_id: 4
- version: 4
-
-r8_v4_m3:
- relation_id: 8
- sequence_id: 3
- member_role: "some relation"
- member_type: "Relation"
- member_id: 7
- version: 4
+++ /dev/null
-visible_relation:
- relation_id: 1
- changeset_id: 1
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-invisible_relation:
- relation_id: 2
- changeset_id: 3
- timestamp: 2007-01-01 00:00:00
- visible: false
- version: 1
-
-used_relation:
- relation_id: 3
- changeset_id: 1
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-multi_tag_relation:
- relation_id: 4
- changeset_id: 4
- timestamp: 2009-04-21 09:50:57
- visible: true
- version: 1
-
-public_used_relation:
- relation_id: 5
- changeset_id: 2
- timestamp: 2009-04-22 00:30:03
- visible: true
- version: 1
-
-public_visible_relation:
- relation_id: 6
- changeset_id: 2
- timestamp: 2009-04-22 00:34:12
- visible: true
- version: 1
-
-relation_with_redacted_versions_v1:
- relation_id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:04:10
- visible: true
- version: 1
-
-relation_with_redacted_versions_v2:
- relation_id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:04:11
- visible: true
- version: 2
- redaction_id: 1
-
-relation_with_redacted_versions_v3:
- relation_id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:04:12
- visible: true
- version: 3
- redaction_id: 1
-
-relation_with_redacted_versions_v4:
- relation_id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:04:13
- visible: true
- version: 4
-
-relation_with_versions_v1:
- relation_id: 8
- changeset_id: 4
- timestamp: 2008-01-01 00:01:00
- visible: true
- version: 1
-
-relation_with_versions_v2:
- relation_id: 8
- changeset_id: 4
- timestamp: 2008-01-01 00:02:00
- visible: true
- version: 2
-
-relation_with_versions_v3:
- relation_id: 8
- changeset_id: 4
- timestamp: 2008-01-01 00:03:00
- visible: true
- version: 3
-
-relation_with_versions_v4:
- relation_id: 8
- changeset_id: 4
- timestamp: 2008-01-01 00:04:00
- visible: true
- version: 4
+++ /dev/null
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-administrator:
- user_id: 6
- role: administrator
- granter_id: 6
-
-moderator:
- user_id: 5
- role: moderator
- granter_id: 6
-
-second_moderator:
- user_id: 15
- role: moderator
- granter_id: 6
-
-super_moderator:
- user_id: 16
- role: moderator
- granter_id: 6
-
-super_administrator:
- user_id: 16
- role: administrator
- granter_id: 6
+++ /dev/null
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-normal_user:
- id: 1
- email: test@openstreetmap.org
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: test
- data_public: false
- description: test
- home_lat: 12.1
- home_lon: 12.1
- home_zoom: 3
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
- creation_ip: "1.2.3.4"
-
-public_user:
- id: 2
- email: test@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: test2
- data_public: true
- description: some test description
- home_lat: 12
- home_lon: 12
- home_zoom: 12
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: "en de"
- creation_ip: "4.5.6.7"
-
-inactive_user:
- id: 3
- email: inactive@openstreetmap.org
- status: pending
- pass_crypt: <%= Digest::MD5::hexdigest('test2') %>
- creation_time: "2008-07-01 02:23:45"
- display_name: Inactive User
- data_public: true
- description: description
- home_lat: 123.4
- home_lon: 12.34
- home_zoom: 15
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
- email_valid: false
-
-second_public_user:
- id: 4
- email: public@OpenStreetMap.org
- new_email: new_public@OpenStreetMap.org
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: pulibc_test2
- data_public: true
- description: some test description
- home_lat: 89
- home_lon: 87
- home_zoom: 12
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- creation_ip: "1.2.3.4"
-
-moderator_user:
- id: 5
- email: moderator@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: moderator
- data_public: true
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
- image_use_gravatar: false
-
-administrator_user:
- id: 6
- email: administrator@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: administrator
- data_public: true
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-terms_not_seen_user:
- id: 7
- email: not_agreed@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2011-03-22 00:23:45"
- display_name: not_agreed
- data_public: true
- terms_seen: false
- languages: en
-
-openid_user:
- id: 8
- email: openid-user@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: openIDuser
- data_public: true
- auth_provider: openid
- auth_uid: http://localhost:1123/john.doe
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-uppercase_user:
- id: 9
- email: TEST@OPENSTREETMAP.ORG
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: TEST
- data_public: true
- description: test
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-suspended_user:
- id: 10
- email: suspended@openstreetmap.org
- status: suspended
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: suspended user
- data_public: true
- description: test
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-deleted_user:
- id: 11
- email: deleted@openstreetmap.org
- status: deleted
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: deleted
- data_public: true
- description: test
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-confirmed_user:
- id: 12
- email: confirmed@openstreetmap.org
- status: confirmed
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: confirmed
- data_public: true
- description: test
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-blocked_user:
- id: 13
- email: blocked@openstreetmap.org
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: blocked
- data_public: true
- description: test
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-unblocked_user:
- id: 14
- email: unblocked@openstreetmap.org
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2007-01-01 00:00:00"
- display_name: unblocked
- data_public: true
- description: test
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-second_moderator_user:
- id: 15
- email: second_moderator@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: second_moderator
- data_public: true
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-super_user:
- id: 16
- email: super@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: super
- data_public: true
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-north_pole_user:
- id: 17
- email: santa@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: santa
- data_public: true
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
- home_lat: 89.9
- home_lon: 146.8
-
-german_user:
- id: 18
- email: german@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: germanuser
- data_public: true
- description: deutsch sprechen
- home_lat: 11.9
- home_lon: 12.1
- home_zoom: 12
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: de
-
-google_user:
- id: 19
- email: google-user@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: googleuser
- data_public: true
- auth_provider: google
- auth_uid: 123456789
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-facebook_user:
- id: 20
- email: facebook-user@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: facebookuser
- data_public: true
- auth_provider: facebook
- auth_uid: 123456789
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-windowslive_user:
- id: 21
- email: windowslive-user@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: windowsliveuser
- data_public: true
- auth_provider: windowslive
- auth_uid: 123456789
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-github_user:
- id: 22
- email: github-user@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: githubuser
- data_public: true
- auth_provider: github
- auth_uid: 123456789
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
-
-first_gravatar_user:
- id: 23
- email: g1@OpenStreetMap.org
- new_email: new_g1@OpenStreetMap.org
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: gravatar1
- data_public: true
- description: some test description
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- creation_ip: "1.2.3.4"
-
-second_gravatar_user:
- id: 24
- email: g2@OpenStreetMap.org
- new_email: new_g2@OpenStreetMap.org
- image_use_gravatar: true
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: gravatar2
- data_public: true
- description: some test description
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- creation_ip: "1.2.3.4"
-
-wikipedia_user:
- id: 25
- email: wikipedia-user@example.com
- status: active
- pass_crypt: <%= Digest::MD5.hexdigest('test') %>
- creation_time: "2008-05-01 01:23:45"
- display_name: wikipediauser
- data_public: true
- auth_provider: wikipedia
- auth_uid: 123456789
- terms_agreed: "2010-01-01 11:22:33"
- terms_seen: true
- languages: en
+++ /dev/null
-t1a:
- way_id: 1
- node_id: 3
- sequence_id: 1
- version: 1
-
-t2:
- way_id: 2
- node_id: 3
- sequence_id: 1
- version: 1
-
-t3:
- way_id: 3
- node_id: 3
- sequence_id: 1
- version: 1
-
-w4_v1_n1:
- way_id: 4
- node_id: 3
- sequence_id: 1
- version: 1
-
-w4_v1_n2:
- way_id: 4
- node_id: 4
- sequence_id: 2
- version: 1
-
-w4_v2_n1:
- way_id: 4
- node_id: 15
- sequence_id: 1
- version: 2
-
-w4_v2_n2:
- way_id: 4
- node_id: 3
- sequence_id: 2
- version: 2
-
-w4_v2_n3:
- way_id: 4
- node_id: 4
- sequence_id: 3
- version: 2
-
-w4_v3_n1:
- way_id: 4
- node_id: 15
- sequence_id: 1
- version: 3
-
-w4_v3_n2:
- way_id: 4
- node_id: 3
- sequence_id: 2
- version: 3
-
-w4_v4_n1:
- way_id: 4
- node_id: 15
- sequence_id: 1
- version: 4
-
-w5_n1:
- way_id: 5
- node_id: 4
- sequence_id: 1
- version: 1
-
-w5_n2:
- way_id: 5
- node_id: 4
- sequence_id: 2
- version: 1
-
-w6_v1_n1:
- way_id: 6
- node_id: 3
- sequence_id: 1
- version: 1
-
-w6_v1_n2:
- way_id: 6
- node_id: 2
- sequence_id: 2
- version: 1
-
-w6_v2_n1:
- way_id: 6
- node_id: 3
- sequence_id: 1
- version: 2
-
-w6_v2_n2:
- way_id: 6
- node_id: 2
- sequence_id: 2
- version: 2
-
-w6_v3_n1:
- way_id: 6
- node_id: 3
- sequence_id: 1
- version: 3
-
-w6_v3_n2:
- way_id: 6
- node_id: 2
- sequence_id: 2
- version: 3
-
-w6_v4_n1:
- way_id: 6
- node_id: 3
- sequence_id: 1
- version: 4
-
-w6_v4_n2:
- way_id: 6
- node_id: 2
- sequence_id: 2
- version: 4
-
-w6_v4_n3:
- way_id: 6
- node_id: 4
- sequence_id: 3
- version: 4
-
-w7_v1_n1:
- way_id: 7
- node_id: 2
- sequence_id: 1
- version: 1
-
-w7_v1_n2:
- way_id: 7
- node_id: 6
- sequence_id: 2
- version: 1
-
-w7_v2_n1:
- way_id: 7
- node_id: 4
- sequence_id: 1
- version: 2
-
-w7_v2_n2:
- way_id: 7
- node_id: 15
- sequence_id: 2
- version: 2
-
-w7_v2_n3:
- way_id: 7
- node_id: 6
- sequence_id: 3
- version: 2
+++ /dev/null
-visible_way:
- way_id: 1
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-invisible_way:
- way_id: 2
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: false
- version: 1
-
-used_way:
- way_id: 3
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-way_with_versions_v1:
- way_id: 4
- changeset_id: 4
- timestamp: 2008-01-01 00:01:00
- visible: true
- version: 1
-
-way_with_versions_v2:
- way_id: 4
- changeset_id: 4
- timestamp: 2008-01-01 00:02:00
- visible: true
- version: 2
-
-way_with_versions_v3:
- way_id: 4
- changeset_id: 4
- timestamp: 2008-01-01 00:03:00
- visible: true
- version: 3
-
-way_with_versions_v4:
- way_id: 4
- changeset_id: 4
- timestamp: 2008-01-01 00:04:00
- visible: true
- version: 4
-
-way_with_duplicate_nodes:
- way_id: 5
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-way_with_redacted_versions_v1:
- way_id: 6
- changeset_id: 4
- timestamp: 2008-01-01 00:04:10
- visible: true
- version: 1
-
-way_with_redacted_versions_v2:
- way_id: 6
- changeset_id: 4
- timestamp: 2008-01-01 00:04:11
- visible: true
- version: 2
- redaction_id: 1
-
-way_with_redacted_versions_v3:
- way_id: 6
- changeset_id: 4
- timestamp: 2008-01-01 00:04:12
- visible: true
- version: 3
- redaction_id: 1
-
-way_with_redacted_versions_v4:
- way_id: 6
- changeset_id: 4
- timestamp: 2008-01-01 00:04:13
- visible: true
- version: 4
-
-way_with_multiple_nodes_v1:
- way_id: 7
- changeset_id: 2
- timestamp: 2007-01-01 00:00:00
- visible: true
- version: 1
-
-way_with_multiple_nodes_v2:
- way_id: 7
- changeset_id: 4
- timestamp: 2008-01-01 00:00:00
- visible: true
- version: 2
end
def test_linkify
- %w(http://example.com/test ftp://example.com/test https://example.com/test).each do |link|
+ %w[http://example.com/test ftp://example.com/test https://example.com/test].each do |link|
text = "Test #{link} is made into a link"
html = linkify(text)
assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
end
- %w(test@example.com mailto:test@example.com).each do |link|
+ %w[test@example.com mailto:test@example.com].each do |link|
text = "Test #{link} is not made into a link"
html = linkify(text)
include ERB::Util
include ApplicationHelper
- api_fixtures
-
def setup
I18n.locale = "en"
end
tags = icon_tags(node)
assert_equal 3, tags.count
- assert tags.include?(%w(building yes))
- assert tags.include?(%w(tourism museum))
- assert tags.include?(%w(shop gift))
+ assert tags.include?(%w[building yes])
+ assert tags.include?(%w[tourism museum])
+ assert tags.include?(%w[shop gift])
add_old_tags_selection(node_v2)
add_old_tags_selection(node_v1)
tags = icon_tags(node_v2)
assert_equal 3, tags.count
- assert tags.include?(%w(building yes))
- assert tags.include?(%w(tourism museum))
- assert tags.include?(%w(shop gift))
+ assert tags.include?(%w[building yes])
+ assert tags.include?(%w[tourism museum])
+ assert tags.include?(%w[shop gift])
tags = icon_tags(node_v1)
assert_equal 3, tags.count
- assert tags.include?(%w(building yes))
- assert tags.include?(%w(tourism museum))
- assert tags.include?(%w(shop gift))
+ assert tags.include?(%w[building yes])
+ assert tags.include?(%w[tourism museum])
+ assert tags.include?(%w[shop gift])
end
def test_wiki_link
# coding: utf-8
+
require "test_helper"
class TitleHelperTest < ActionView::TestCase
require "test_helper"
class ClientApplicationsTest < ActionDispatch::IntegrationTest
- fixtures :users
-
##
# 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
+ user = create(:user)
+
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" => user.email, "password" => "test", :referer => "/user/#{URI.encode(user.display_name)}"
assert_response :redirect
follow_redirect!
assert_response :success
assert_template "user/view"
- get "/user/test2/account"
+ get "/user/#{URI.encode(user.display_name)}/account"
assert_response :success
assert_template "user/account"
# check that the form to allow new client application creations exists
assert_in_heading do
- assert_select "ul.secondary-actions li a[href='/user/test2/oauth_clients']"
+ assert_select "ul.secondary-actions li a[href='/user/#{URI.encode(user.display_name)}/oauth_clients']"
end
# now we follow the link to the oauth client list
- get "/user/test2/oauth_clients"
+ get "/user/#{URI.encode(user.display_name)}/oauth_clients"
assert_response :success
assert_in_body do
- assert_select "a[href='/user/test2/oauth_clients/new']"
+ assert_select "a[href='/user/#{URI.encode(user.display_name)}/oauth_clients/new']"
end
# now we follow the link to the new oauth client page
- get "/user/test2/oauth_clients/new"
+ get "/user/#{URI.encode(user.display_name)}/oauth_clients/new"
assert_response :success
assert_in_heading do
assert_select "h1", "Register a new application"
end
assert_in_body do
- assert_select "form[action='/user/test2/oauth_clients']" do
+ assert_select "form[action='/user/#{URI.encode(user.display_name)}/oauth_clients']" do
[:name, :url, :callback_url, :support_url].each do |inp|
assert_select "input[name=?]", "client_application[#{inp}]"
end
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/#{URI.encode(user.display_name)}/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_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/#{URI.encode(user.display_name)}/oauth_clients"
assert_response :success
assert_template "oauth_clients/index"
assert_in_body { assert_select "div>a", "My New App" }
assert_select "html[lang=?]", "en"
get "/diary/new", {}, { "HTTP_ACCEPT_LANGUAGE" => "fr, en" }
- assert_equal %w(fr en), User.find(user.id).languages
+ assert_equal %w[fr en], User.find(user.id).languages
assert_select "html[lang=?]", "fr"
end
require "test_helper"
class UserChangesetCommentsTest < ActionDispatch::IntegrationTest
- fixtures :users, :changesets
-
# Test 'log in to comment' message for nonlogged in user
def test_log_in_message
- get "/changeset/#{changesets(:normal_user_closed_change).id}"
+ changeset = create(:changeset, :closed)
+
+ get "/changeset/#{changeset.id}"
assert_response :success
assert_select "div#content" do
# Test if the form is shown
def test_displaying_form
+ user = create(:user)
+ changeset = create(:changeset, :closed)
+
get_via_redirect "/login"
# We should now be at the login page
assert_response :success
assert_template "user/login"
# We can now login
- post "/login", "username" => "test@openstreetmap.org", "password" => "test"
+ post "/login", "username" => user.email, "password" => "test"
assert_response :redirect
- get "/changeset/#{changesets(:normal_user_closed_change).id}"
+ get "/changeset/#{changeset.id}"
assert_response :success
assert_template "browse/changeset"
assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
follow_redirect!
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
assert_redirected_to "/user/terms"
assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
follow_redirect!
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
follow_redirect!
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
assert_redirected_to "/user/terms"
require "test_helper"
class UserDiariesTest < ActionDispatch::IntegrationTest
- fixtures :users
-
# 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
+ user = create(:user)
+
get_via_redirect "/diary/new"
# We should now be at the login page
assert_response :success
assert_template "user/login"
# We can now login
- post "/login", "username" => "test@openstreetmap.org", "password" => "test", :referer => "/diary/new"
+ post "/login", "username" => user.email, "password" => "test", :referer => "/diary/new"
assert_response :redirect
# print @response.body
# Check that there is some payload alerting the user to the redirect
assert_template "user/login"
get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
follow_redirect!
assert_template "user/login"
get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
assert_template "user/login"
get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
assert_template "user/login"
get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
assert_response :redirect
- assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+ assert_redirected_to auth_success_path(:provider => "github")
follow_redirect!
assert_response :redirect
follow_redirect!
@max_lon = 3.0
@max_lat = 4.0
- @bad_positive_boundary_bbox = %w(181,91,0,0 0,0,181,91)
- @bad_negative_boundary_bbox = %w(-181,-91,0,0 0,0,-181,-91)
- @bad_big_bbox = %w(-0.1,-0.1,1.1,1.1 10,10,11,11)
- @bad_malformed_bbox = %w(-0.1 hello 10N2W10.1N2.1W)
- @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)
-
- @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)
- @expand_max_lon_array = %w(-2,-2,-1,-2 -2,-2,0,-2 -2,-2,1,-2 -2,-2,2,-2)
- @expand_max_lat_array = %w(-2,-2,-2,-1 -2,-2,-2,0 -2,-2,-2,1 -2,-2,-2,2)
+ @bad_positive_boundary_bbox = %w[181,91,0,0 0,0,181,91]
+ @bad_negative_boundary_bbox = %w[-181,-91,0,0 0,0,-181,-91]
+ @bad_big_bbox = %w[-0.1,-0.1,1.1,1.1 10,10,11,11]
+ @bad_malformed_bbox = %w[-0.1 hello 10N2W10.1N2.1W]
+ @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]
+
+ @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]
+ @expand_max_lon_array = %w[-2,-2,-1,-2 -2,-2,0,-2 -2,-2,1,-2 -2,-2,2,-2]
+ @expand_max_lat_array = %w[-2,-2,-2,-1 -2,-2,-2,0 -2,-2,-2,1 -2,-2,-2,2]
@expand_min_lon_margin_response = [[2, 10, 10, 10], [-7, 10, 10, 10], [-7, 10, 10, 10], [-7, 10, 10, 10], [-7, 10, 10, 10], [-25, 10, 10, 10]]
@expand_min_lat_margin_response = [[10, 2, 10, 10], [10, -7, 10, 10], [10, -7, 10, 10], [10, -7, 10, 10], [10, -7, 10, 10], [10, -25, 10, 10]]
@expand_max_lon_margin_response = [[-2, -2, -1, -2], [-2, -2, 1, -2], [-2, -2, 1, -2], [-2, -2, 5, -2]]
def test_good_bbox_boundaries
@good_bbox.each do |bbox_string|
- assert_nothing_raised(OSM::APIBadBoundingBox) { BoundingBox.from_s(bbox_string).check_boundaries }
+ assert_nothing_raised { BoundingBox.from_s(bbox_string).check_boundaries }
end
end
def test_good_bbox_size
@good_bbox.each do |bbox_string|
- assert_nothing_raised(OSM::APIBadBoundingBox) { BoundingBox.from_s(bbox_string).check_size }
+ assert_nothing_raised { BoundingBox.from_s(bbox_string).check_size }
end
end
def test_size_to_big
@bad_big_bbox.each do |bbox_string|
bbox = nil
- assert_nothing_raised(OSM::APIBadBoundingBox) { bbox = BoundingBox.from_bbox_params(:bbox => bbox_string).check_boundaries }
+ assert_nothing_raised { bbox = BoundingBox.from_bbox_params(:bbox => bbox_string).check_boundaries }
exception = assert_raise(OSM::APIBadBoundingBox) { bbox.check_size }
assert_equal(@size_error_message, exception.message)
end
end
end
- assert %w(ltr rtl).include?(I18n.t("html.dir", :locale => locale)), "html.dir must be ltr or rtl"
+ assert %w[ltr rtl].include?(I18n.t("html.dir", :locale => locale)), "html.dir must be ltr or rtl"
end
end
require "test_helper"
class ChangesetCommentTest < ActiveSupport::TestCase
- fixtures :changesets, :users
-
# validations
def test_does_not_accept_invalid_author
comment = create(:changeset_comment)
end
def test_body_valid
- ok = %W(Name vergrößern foo\nbar
- ルシステムにも対応します 輕觸搖晃的遊戲)
+ ok = %W[Name vergrößern foo\nbar
+ ルシステムにも対応します 輕觸搖晃的遊戲]
bad = ["foo\x00bar", "foo\x08bar", "foo\x1fbar", "foo\x7fbar",
"foo\ufffebar", "foo\uffffbar"]
require "test_helper"
class ChangesetTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
+ changeset = create(:changeset)
+
key = "k"
(0..255).each do |i|
tag = ChangesetTag.new
- tag.changeset_id = 1
+ tag.changeset_id = changeset.id
tag.k = key * i
tag.v = "v"
assert tag.valid?
end
def test_length_value_valid
+ changeset = create(:changeset)
+
val = "v"
(0..255).each do |i|
tag = ChangesetTag.new
- tag.changeset_id = 1
+ tag.changeset_id = changeset.id
tag.k = "k"
tag.v = val * i
assert tag.valid?
def test_from_xml_valid
# Example taken from the Update section on the API_v0.6 docs on the wiki
xml = "<osm><changeset><tag k=\"comment\" v=\"Just adding some streetnames and a restaurant\"/></changeset></osm>"
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Changeset.from_xml(xml, false)
end
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Changeset.from_xml(xml, true)
end
end
require "test_helper"
class FriendTest < ActiveSupport::TestCase
- api_fixtures
-
- def test_friend_count
- create(:friend)
- assert_equal 1, Friend.count
- end
end
# coding: utf-8
+
require "test_helper"
class LanguageTest < ActiveSupport::TestCase
require "test_helper"
class MessageTest < ActiveSupport::TestCase
- api_fixtures
-
EURO = "\xe2\x82\xac".freeze # euro symbol
def test_check_empty_message_fails
# its OK to accept invalid UTF-8 as long as we return it unmodified.
db_msg = msg.class.find(msg.id)
assert_equal char, db_msg.title, "Database silently truncated message title"
-
rescue ArgumentError => ex
assert_equal ex.to_s, "invalid byte sequence in UTF-8"
-
end
end
end
require "test_helper"
class NodeTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
tag = create(:node_tag)
(0..255).each do |i|
require "test_helper"
class NodeTest < ActiveSupport::TestCase
- api_fixtures
-
def test_node_too_far_north
node = build(:node, :latitude => 90.01 * OldNode::SCALE)
assert_equal false, node.valid?
version = 1
noid = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset}' version='#{version}' /></osm>"
# First try a create which doesn't need the id
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Node.from_xml(noid, true)
end
# Now try an update with no id, and make sure that it gives the appropriate exception
def test_from_xml_no_version
no_version = "<osm><node id='123' lat='23' lon='23' changeset='23' /></osm>"
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Node.from_xml(no_version, true)
end
message_update = assert_raise(OSM::APIBadXMLError) do
id_list = ["", "0", "00", "0.0", "a"]
id_list.each do |id|
zero_id = "<osm><node id='#{id}' lat='12.3' lon='12.3' changeset='33' version='23' /></osm>"
- assert_nothing_raised(OSM::APIBadUserInput) do
+ assert_nothing_raised do
Node.from_xml(zero_id, true)
end
message_update = assert_raise(OSM::APIBadUserInput) do
require "test_helper"
class NoteCommentTest < ActiveSupport::TestCase
- fixtures :users
-
def test_event_valid
- ok = %w(opened closed reopened commented hidden)
- bad = %w(expropriated fubared)
+ ok = %w[opened closed reopened commented hidden]
+ bad = %w[expropriated fubared]
ok.each do |event|
note_comment = create(:note_comment)
end
def test_body_valid
- ok = %W(Name vergrößern foo\nbar
- ルシステムにも対応します 輕觸搖晃的遊戲)
+ ok = %W[Name vergrößern foo\nbar
+ ルシステムにも対応します 輕觸搖晃的遊戲]
bad = ["foo\x00bar", "foo\x08bar", "foo\x1fbar", "foo\x7fbar",
"foo\ufffebar", "foo\uffffbar"]
require "test_helper"
class NoteTest < ActiveSupport::TestCase
- fixtures :users
-
def test_status_valid
- ok = %w(open closed hidden)
- bad = %w(expropriated fubared)
+ ok = %w[open closed hidden]
+ bad = %w[expropriated fubared]
ok.each do |status|
note = create(:note)
require "test_helper"
class OauthNonceTest < ActiveSupport::TestCase
- api_fixtures
-
##
# the nonce has only one property, that it is a unique pair of
# string and timestamp.
require "test_helper"
class OldNodeTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
tag = create(:old_node_tag)
(0..255).each do |i|
require "test_helper"
class OldRelationTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
tag = create(:old_relation_tag)
(0..255).each do |i|
require "test_helper"
class OldRelationTest < ActiveSupport::TestCase
- api_fixtures
-
def test_relation_tags
old_relation_v1 = create(:old_relation, :version => 1)
old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
require "test_helper"
class OldWayTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
tag = create(:old_way_tag)
(0..255).each do |i|
require "test_helper"
class OldWayTest < ActiveSupport::TestCase
- api_fixtures
-
def test_old_nodes
old_way_v1 = create(:old_way, :version => 1)
old_way_v2 = create(:old_way, :current_way => old_way_v1.current_way, :version => 2)
r = create(:redaction)
assert_equal(false, node_v1.redacted?, "Expected node to not be redacted already.")
- assert_nothing_raised(OSM::APICannotRedactError) do
+ assert_nothing_raised do
node_v1.redact!(r)
end
assert_equal(true, node_v1.redacted?, "Expected node version 1 to be redacted after redact! call.")
require "test_helper"
class RelationMemberTest < ActiveSupport::TestCase
- api_fixtures
-
- def test_relation_member_count
- assert_equal 9, RelationMember.count
- end
end
require "test_helper"
class RelationTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
tag = create(:relation_tag)
(0..255).each do |i|
require "test_helper"
class RelationTest < ActiveSupport::TestCase
- api_fixtures
-
- def test_relation_count
- assert_equal 8, Relation.count
- end
-
def test_from_xml_no_id
noid = "<osm><relation version='12' changeset='23' /></osm>"
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Relation.from_xml(noid, true)
end
message = assert_raise(OSM::APIBadXMLError) do
def test_from_xml_no_version
no_version = "<osm><relation id='123' changeset='23' /></osm>"
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Relation.from_xml(no_version, true)
end
message_update = assert_raise(OSM::APIBadXMLError) do
id_list = ["", "0", "00", "0.0", "a"]
id_list.each do |id|
zero_id = "<osm><relation id='#{id}' changeset='332' version='23' /></osm>"
- assert_nothing_raised(OSM::APIBadUserInput) do
+ assert_nothing_raised do
Relation.from_xml(zero_id, true)
end
message_update = assert_raise(OSM::APIBadUserInput) do
end
def test_relation_members
- relation = current_relations(:relation_with_versions)
+ relation = create(:relation)
+ node = create(:node)
+ way = create(:way)
+ other_relation = create(:relation)
+ create(:relation_member, :relation => relation, :member => node, :member_role => "some node")
+ create(:relation_member, :relation => relation, :member => way, :member_role => "some way")
+ create(:relation_member, :relation => relation, :member => other_relation, :member_role => "some relation")
+
members = Relation.find(relation.id).relation_members
assert_equal 3, members.count
assert_equal "some node", members[0].member_role
assert_equal "Node", members[0].member_type
- assert_equal 15, members[0].member_id
+ assert_equal node.id, members[0].member_id
assert_equal "some way", members[1].member_role
assert_equal "Way", members[1].member_type
- assert_equal 4, members[1].member_id
+ assert_equal way.id, members[1].member_id
assert_equal "some relation", members[2].member_role
assert_equal "Relation", members[2].member_type
- assert_equal 7, members[2].member_id
+ assert_equal other_relation.id, members[2].member_id
end
def test_relations
- relation = current_relations(:relation_with_versions)
+ relation = create(:relation)
+ node = create(:node)
+ way = create(:way)
+ other_relation = create(:relation)
+ create(:relation_member, :relation => relation, :member => node, :member_role => "some node")
+ create(:relation_member, :relation => relation, :member => way, :member_role => "some way")
+ create(:relation_member, :relation => relation, :member => other_relation, :member_role => "some relation")
+
members = Relation.find(relation.id).members
assert_equal 3, members.count
- assert_equal ["Node", 15, "some node"], members[0]
- assert_equal ["Way", 4, "some way"], members[1]
- assert_equal ["Relation", 7, "some relation"], members[2]
+ assert_equal ["Node", node.id, "some node"], members[0]
+ assert_equal ["Way", way.id, "some way"], members[1]
+ assert_equal ["Relation", other_relation.id, "some relation"], members[2]
end
def test_relation_tags
- relation = current_relations(:relation_with_versions)
+ relation = create(:relation)
taglist = create_list(:relation_tag, 2, :relation => relation)
tags = Relation.find(relation.id).relation_tags.order(:k)
end
def test_tags
- relation = current_relations(:relation_with_versions)
+ relation = create(:relation)
taglist = create_list(:relation_tag, 2, :relation => relation)
tags = Relation.find(relation.id).tags
end
def test_containing_relation_members
- relation = current_relations(:used_relation)
+ relation = create(:relation)
+ super_relation = create(:relation)
+ create(:relation_member, :relation => super_relation, :member => relation)
+
crm = Relation.find(relation.id).containing_relation_members.order(:relation_id)
# assert_equal 1, crm.size
- assert_equal 1, crm.first.relation_id
+ assert_equal super_relation.id, crm.first.relation_id
assert_equal "Relation", crm.first.member_type
assert_equal relation.id, crm.first.member_id
- assert_equal 1, crm.first.relation.id
+ assert_equal super_relation.id, crm.first.relation.id
end
def test_containing_relations
- relation = current_relations(:used_relation)
+ relation = create(:relation)
+ super_relation = create(:relation)
+ create(:relation_member, :relation => super_relation, :member => relation)
+
cr = Relation.find(relation.id).containing_relations.order(:id)
assert_equal 1, cr.size
- assert_equal 1, cr.first.id
+ assert_equal super_relation.id, cr.first.id
end
end
require "test_helper"
class RequestTokenTest < ActiveSupport::TestCase
- api_fixtures
-
def test_oob
assert_equal true, RequestToken.new.oob?
assert_equal true, RequestToken.new(:callback_url => "oob").oob?
class UserTest < ActiveSupport::TestCase
include Rails::Dom::Testing::Assertions::SelectorAssertions
- api_fixtures
- fixtures :user_roles
-
def test_invalid_with_empty_attributes
user = User.new
assert !user.valid?
assert user.errors[:pass_crypt].any?
assert user.errors[:display_name].any?
assert user.errors[:email].any?
- assert !user.errors[:home_lat].any?
- assert !user.errors[:home_lon].any?
- assert !user.errors[:home_zoom].any?
+ assert user.errors[:home_lat].none?
+ assert user.errors[:home_lon].none?
+ assert user.errors[:home_zoom].none?
end
def test_unique_email
end
def test_email_valid
- ok = %w(a@s.com test@shaunmcdonald.me.uk hello_local@ping-d.ng
- test_local@openstreetmap.org test-local@example.com)
- bad = %w(hi ht@ n@ @.com help@.me.uk help"hi.me.uk も対@応します
- 輕觸搖晃的遊戲@ah.com も対応します@s.name)
+ ok = %w[a@s.com test@shaunmcdonald.me.uk hello_local@ping-d.ng
+ test_local@openstreetmap.org test-local@example.com]
+ bad = %w[hi ht@ n@ @.com help@.me.uk help"hi.me.uk も対@応します
+ 輕觸搖晃的遊戲@ah.com も対応します@s.name]
ok.each do |name|
user = build(:user)
user = create(:user, :languages => ["en"])
assert_equal ["en"], user.languages
- user.languages = %w(de fr en)
- assert_equal %w(de fr en), user.languages
- user.languages = %w(fr de sl)
+ user.languages = %w[de fr en]
+ assert_equal %w[de fr en], user.languages
+ user.languages = %w[fr de sl]
assert_equal "de", user.preferred_language
- assert_equal %w(fr de sl), user.preferred_languages.map(&:to_s)
- user = create(:user, :languages => %w(en de))
- assert_equal %w(en de), user.languages
+ assert_equal %w[fr de sl], user.preferred_languages.map(&:to_s)
+ user = create(:user, :languages => %w[en de])
+ assert_equal %w[en de], user.languages
end
def test_visible?
require "test_helper"
class WayNodeTest < ActiveSupport::TestCase
- api_fixtures
-
- def test_way_nodes_count
- assert_equal 9, WayNode.count
- end
end
require "test_helper"
class WayTagTest < ActiveSupport::TestCase
- api_fixtures
-
def test_length_key_valid
tag = create(:way_tag)
(0..255).each do |i|
require "test_helper"
class WayTest < ActiveSupport::TestCase
- api_fixtures
-
- # Check that we have the correct number of currnet ways in the db
- # This will need to updated whenever the current_ways.yml is updated
- def test_db_count
- assert_equal 7, Way.count
- end
-
def test_bbox
node = create(:node)
visible_way = create(:way)
node_c = create(:node)
way = create(:way_with_nodes, :nodes_count => 1)
# Take one of the current ways and add nodes to it until we are near the limit
- way = Way.find(current_ways(:visible_way).id)
assert way.valid?
# it already has 1 node
1.upto(MAX_NUMBER_OF_WAY_NODES / 2) do
def test_from_xml_no_id
noid = "<osm><way version='12' changeset='23' /></osm>"
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Way.from_xml(noid, true)
end
message = assert_raise(OSM::APIBadXMLError) do
def test_from_xml_no_version
no_version = "<osm><way id='123' changeset='23' /></osm>"
- assert_nothing_raised(OSM::APIBadXMLError) do
+ assert_nothing_raised do
Way.from_xml(no_version, true)
end
message_update = assert_raise(OSM::APIBadXMLError) do
id_list = ["", "0", "00", "0.0", "a"]
id_list.each do |id|
zero_id = "<osm><way id='#{id}' changeset='33' version='23' /></osm>"
- assert_nothing_raised(OSM::APIBadUserInput) do
+ assert_nothing_raised do
Way.from_xml(zero_id, true)
end
message_update = assert_raise(OSM::APIBadUserInput) do
end
def test_way_nodes
- way = current_ways(:way_with_multiple_nodes)
+ way = create(:way)
+ node1 = create(:way_node, :way => way, :sequence_id => 1).node
+ node2 = create(:way_node, :way => way, :sequence_id => 2).node
+ node3 = create(:way_node, :way => way, :sequence_id => 3).node
+
nodes = Way.find(way.id).way_nodes
assert_equal 3, nodes.count
- assert_equal 4, nodes[0].node_id
- assert_equal 15, nodes[1].node_id
- assert_equal 11, nodes[2].node_id
+ assert_equal node1.id, nodes[0].node_id
+ assert_equal node2.id, nodes[1].node_id
+ assert_equal node3.id, nodes[2].node_id
end
def test_nodes
- way = current_ways(:way_with_multiple_nodes)
+ way = create(:way)
+ node1 = create(:way_node, :way => way, :sequence_id => 1).node
+ node2 = create(:way_node, :way => way, :sequence_id => 2).node
+ node3 = create(:way_node, :way => way, :sequence_id => 3).node
+
nodes = Way.find(way.id).nodes
assert_equal 3, nodes.count
- assert_equal 4, nodes[0].id
- assert_equal 15, nodes[1].id
- assert_equal 11, nodes[2].id
+ assert_equal node1.id, nodes[0].id
+ assert_equal node2.id, nodes[1].id
+ assert_equal node3.id, nodes[2].id
end
def test_nds
- way = current_ways(:way_with_multiple_nodes)
+ way = create(:way)
+ node1 = create(:way_node, :way => way, :sequence_id => 1).node
+ node2 = create(:way_node, :way => way, :sequence_id => 2).node
+ node3 = create(:way_node, :way => way, :sequence_id => 3).node
+
nodes = Way.find(way.id).nds
assert_equal 3, nodes.count
- assert_equal 4, nodes[0]
- assert_equal 15, nodes[1]
- assert_equal 11, nodes[2]
+ assert_equal node1.id, nodes[0]
+ assert_equal node2.id, nodes[1]
+ assert_equal node3.id, nodes[2]
end
def test_way_tags
- way = current_ways(:way_with_versions)
+ way = create(:way)
taglist = create_list(:way_tag, 2, :way => way)
tags = Way.find(way.id).way_tags.order(:k)
assert_equal taglist.count, tags.count
end
def test_tags
- way = current_ways(:way_with_versions)
+ way = create(:way)
taglist = create_list(:way_tag, 2, :way => way)
tags = Way.find(way.id).tags
assert_equal taglist.count, tags.count
end
def test_containing_relation_members
- way = current_ways(:used_way)
+ way = create(:way)
+ relation = create(:relation)
+ create(:relation_member, :relation => relation, :member => way)
+
crm = Way.find(way.id).containing_relation_members.order(:relation_id)
# assert_equal 1, crm.size
- assert_equal 1, crm.first.relation_id
+ assert_equal relation.id, crm.first.relation_id
assert_equal "Way", crm.first.member_type
assert_equal way.id, crm.first.member_id
- assert_equal 1, crm.first.relation.id
+ assert_equal relation.id, crm.first.relation.id
end
def test_containing_relations
- way = current_ways(:used_way)
+ way = create(:way)
+ relation = create(:relation)
+ create(:relation_member, :relation => relation, :member => way)
+
cr = Way.find(way.id).containing_relations.order(:id)
assert_equal 1, cr.size
- assert_equal 1, cr.first.id
+ assert_equal relation.id, cr.first.id
end
end
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "webmock/minitest"
-load "composite_primary_keys/fixtures.rb"
module ActiveSupport
class TestCase
include FactoryGirl::Syntax::Methods
- # Load standard fixtures needed to test API methods
- def self.api_fixtures
- # print "setting up the api_fixtures"
- fixtures :users, :user_roles
- fixtures :changesets
-
- fixtures :current_nodes, :nodes
- set_fixture_class :current_nodes => Node
- set_fixture_class :nodes => OldNode
-
- fixtures :current_ways
- set_fixture_class :current_ways => Way
-
- fixtures :current_way_nodes
- set_fixture_class :current_way_nodes => WayNode
-
- fixtures :ways
- set_fixture_class :ways => OldWay
-
- fixtures :way_nodes
- set_fixture_class :way_nodes => OldWayNode
-
- fixtures :current_relations
- set_fixture_class :current_relations => Relation
-
- fixtures :current_relation_members
- set_fixture_class :current_relation_members => RelationMember
-
- fixtures :relations
- set_fixture_class :relations => OldRelation
-
- fixtures :relation_members
- set_fixture_class :relation_members => OldRelationMember
-
- fixtures :redactions
- end
-
##
# takes a block which is executed in the context of a different
# ActionController instance. this is used so that code can call methods