From: Tom Hughes Date: Fri, 2 Jun 2017 19:34:17 +0000 (+0100) Subject: Merge remote-tracking branch 'openstreetmap/pull/1553' X-Git-Tag: live~3411 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/124ec2e9d560e0df291e5a8e5aa67ef5db2f5d46?hp=fbbaa1bb8f34026c28f5ee6642d460a0587efbdf Merge remote-tracking branch 'openstreetmap/pull/1553' --- diff --git a/.rubocop.yml b/.rubocop.yml index a31adf03b..e1f1724e0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,18 +24,21 @@ AllCops: 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 @@ -55,6 +58,12 @@ Style/HashSyntax: Style/StringLiterals: EnforcedStyle: double_quotes +Style/SymbolArray: + EnforcedStyle: brackets + +Rails/ApplicationRecord: + Enabled: false + Rails/HttpPositionalArguments: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03fa82f0f..ce7e5d9b2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -64,7 +64,7 @@ Metrics/BlockNesting: # Offense count: 62 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 1705 + Max: 1782 # Offense count: 69 Metrics/CyclomaticComplexity: diff --git a/Gemfile b/Gemfile index 0f65c9c1d..278167d66 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem "composite_primary_keys", "~> 8.1.0" 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" diff --git a/Gemfile.lock b/Gemfile.lock index 03b033199..830d9775f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,24 +38,24 @@ GEM 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) @@ -67,14 +67,14 @@ GEM 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) @@ -95,22 +95,22 @@ GEM 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 @@ -124,7 +124,7 @@ GEM 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) @@ -149,20 +149,20 @@ GEM 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) @@ -170,8 +170,8 @@ GEM 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) @@ -181,11 +181,11 @@ GEM 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) @@ -210,10 +210,11 @@ GEM 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) @@ -222,7 +223,7 @@ GEM 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) @@ -257,14 +258,16 @@ GEM 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) @@ -277,20 +280,20 @@ GEM 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) @@ -298,7 +301,7 @@ GEM 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) @@ -307,24 +310,24 @@ GEM 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 @@ -347,7 +350,7 @@ DEPENDENCIES 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 diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index ce1a217cd..c36ded1c0 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -100,7 +100,7 @@ class ApiController < ApplicationController 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 @@ -198,7 +198,7 @@ class ApiController < ApplicationController 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 @@ -241,9 +241,9 @@ class ApiController < ApplicationController 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 @@ -294,7 +294,7 @@ class ApiController < ApplicationController 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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2ceeda7be..144904885 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -41,7 +41,7 @@ class ApplicationController < ActionController::Base if request.get? redirect_to :controller => "user", :action => "login", :referer => request.fullpath else - render :text => "", :status => :forbidden + head :forbidden end end end @@ -127,7 +127,7 @@ class ApplicationController < ActionController::Base flash[:error] = t("application.require_moderator.not_a_moderator") redirect_to :action => "index" else - render :text => "", :status => :forbidden + head :forbidden end end end @@ -181,7 +181,7 @@ class ApplicationController < ActionController::Base 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 @@ -197,7 +197,7 @@ class ApplicationController < ActionController::Base 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 @@ -288,9 +288,9 @@ class ApplicationController < ActionController::Base 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 @@ -321,7 +321,7 @@ class ApplicationController < ActionController::Base 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 @@ -391,7 +391,7 @@ class ApplicationController < ActionController::Base 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 @@ -410,9 +410,9 @@ class ApplicationController < ActionController::Base 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 diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index da066a73a..71fc2a59a 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -34,7 +34,7 @@ class ChangesetController < ApplicationController # 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 ## @@ -43,7 +43,7 @@ class ChangesetController < ApplicationController 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 ## @@ -61,7 +61,7 @@ class ChangesetController < ApplicationController changeset.set_closed_time_now changeset.save! - render :text => "" + render :nothing => true end ## @@ -104,7 +104,7 @@ class ChangesetController < ApplicationController # 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 ## @@ -132,7 +132,7 @@ class ChangesetController < ApplicationController 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 @@ -197,7 +197,7 @@ class ChangesetController < ApplicationController end end - render :text => result.to_s, :content_type => "text/xml" + render :xml => result.to_s end ## @@ -224,7 +224,7 @@ class ChangesetController < ApplicationController results.root << cs.to_xml_node end - render :text => results.to_s, :content_type => "text/xml" + render :xml => results.to_s end ## @@ -244,52 +244,54 @@ class ChangesetController < ApplicationController 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) @@ -335,7 +337,7 @@ class ChangesetController < ApplicationController 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 ## @@ -356,7 +358,7 @@ class ChangesetController < ApplicationController 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 ## @@ -377,7 +379,7 @@ class ChangesetController < ApplicationController 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 ## @@ -396,7 +398,7 @@ class ChangesetController < ApplicationController 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 ## @@ -415,7 +417,7 @@ class ChangesetController < ApplicationController 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 ## @@ -440,7 +442,7 @@ class ChangesetController < ApplicationController format.rss end rescue OSM::APIBadUserInput - render :text => "", :status => :bad_request + head :bad_request end private diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 6fb255a36..19bc84ac7 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -128,7 +128,7 @@ class DiaryEntryController < ApplicationController 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 @@ -158,11 +158,11 @@ class DiaryEntryController < ApplicationController @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]) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 57f86ec9f..234842588 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -10,22 +10,21 @@ class GeocoderController < ApplicationController 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 @@ -35,7 +34,7 @@ class GeocoderController < ApplicationController end if @sources.empty? - render :text => "", :status => :bad_request + head :bad_request else render :layout => map_layout end @@ -316,29 +315,30 @@ class GeocoderController < ApplicationController 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) diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 8d29fd072..9f6703b07 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -19,7 +19,7 @@ class NodeController < ApplicationController # 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] @@ -29,9 +29,9 @@ class NodeController < ApplicationController 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 @@ -45,7 +45,7 @@ class NodeController < ApplicationController 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 @@ -59,7 +59,7 @@ class NodeController < ApplicationController 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. @@ -79,6 +79,6 @@ class NodeController < ApplicationController doc.root << node.to_xml_node end - render :text => doc.to_s, :content_type => "text/xml" + render :xml => doc.to_s end end diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 2e847fcd5..4bb129ba4 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -49,7 +49,7 @@ class OauthController < ApplicationController 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" diff --git a/app/controllers/old_controller.rb b/app/controllers/old_controller.rb index 4869ae3e1..f41a94a33 100644 --- a/app/controllers/old_controller.rb +++ b/app/controllers/old_controller.rb @@ -33,12 +33,12 @@ class OldController < ApplicationController 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 @@ -46,7 +46,7 @@ class OldController < ApplicationController 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 @@ -64,7 +64,7 @@ class OldController < ApplicationController end # just return an empty 200 OK for success - render :text => "" + render :nothing => true end private diff --git a/app/controllers/relation_controller.rb b/app/controllers/relation_controller.rb index 587cfce82..846d623f2 100644 --- a/app/controllers/relation_controller.rb +++ b/app/controllers/relation_controller.rb @@ -16,16 +16,16 @@ class RelationController < ApplicationController # 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 @@ -40,7 +40,7 @@ class RelationController < ApplicationController 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 @@ -48,9 +48,9 @@ class RelationController < ApplicationController 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 @@ -119,10 +119,10 @@ class RelationController < ApplicationController # 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 @@ -143,7 +143,7 @@ class RelationController < ApplicationController 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 @@ -167,6 +167,6 @@ class RelationController < ApplicationController 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 diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 8a632e6a2..4b8b2f402 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -33,13 +33,13 @@ class SearchController < ApplicationController 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 @@ -94,6 +94,6 @@ class SearchController < ApplicationController 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 diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index b0552322e..abd4696e0 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -69,11 +69,11 @@ class SiteController < ApplicationController 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 @@ -115,14 +115,14 @@ class SiteController < ApplicationController 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 diff --git a/app/controllers/swf_controller.rb b/app/controllers/swf_controller.rb index 282f61613..329de0dfc 100644 --- a/app/controllers/swf_controller.rb +++ b/app/controllers/swf_controller.rb @@ -92,7 +92,7 @@ class SwfController < ApplicationController 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 diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 8d9b670c5..6e502fdc6 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -21,7 +21,7 @@ class TraceController < ApplicationController 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 @@ -145,7 +145,7 @@ class TraceController < ApplicationController 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 @@ -154,19 +154,19 @@ class TraceController < ApplicationController 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 @@ -180,16 +180,16 @@ class TraceController < ApplicationController 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 @@ -197,7 +197,7 @@ class TraceController < ApplicationController redirect_to :action => :list, :display_name => @user.display_name end rescue ActiveRecord::RecordNotFound - render :text => "", :status => :not_found + head :not_found end def georss @@ -221,13 +221,13 @@ class TraceController < ApplicationController 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 @@ -238,22 +238,22 @@ class TraceController < ApplicationController 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 @@ -272,9 +272,9 @@ class TraceController < ApplicationController trace.visibility = new_trace.visibility trace.save! - render :text => "", :status => :ok + head :ok else - render :text => "", :status => :forbidden + head :forbidden end end @@ -285,9 +285,9 @@ class TraceController < ApplicationController trace.visible = false trace.save! - render :text => "", :status => :ok + head :ok else - render :text => "", :status => :forbidden + head :forbidden end end @@ -303,7 +303,7 @@ class TraceController < ApplicationController 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 @@ -324,14 +324,14 @@ class TraceController < ApplicationController 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 diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 197b28914..430051c17 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -81,7 +81,7 @@ class UserController < ApplicationController @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 @@ -194,7 +194,7 @@ class UserController < ApplicationController redirect_to :action => "lost_password" end else - render :text => "", :status => :bad_request + head :bad_request end end @@ -375,7 +375,7 @@ class UserController < ApplicationController if @this_user.visible? render :action => :api_read, :content_type => "text/xml" else - render :text => "", :status => :gone + head :gone end end @@ -389,7 +389,7 @@ class UserController < ApplicationController @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 @@ -437,7 +437,7 @@ class UserController < ApplicationController 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 @@ -480,9 +480,11 @@ class UserController < ApplicationController 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, @@ -752,9 +754,7 @@ class UserController < ApplicationController ## # 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 ## diff --git a/app/controllers/user_preference_controller.rb b/app/controllers/user_preference_controller.rb index bf9bab213..b59289792 100644 --- a/app/controllers/user_preference_controller.rb +++ b/app/controllers/user_preference_controller.rb @@ -20,7 +20,7 @@ class UserPreferenceController < ApplicationController end doc.root << el1 - render :text => doc.to_s, :content_type => "text/xml" + render :xml => doc.to_s end ## @@ -28,7 +28,7 @@ class UserPreferenceController < ApplicationController 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 @@ -57,7 +57,7 @@ class UserPreferenceController < ApplicationController new_preferences.each_value(&:save!) - render :text => "", :content_type => "text/plain" + render :nothing => true, :content_type => "text/plain" end ## @@ -74,7 +74,7 @@ class UserPreferenceController < ApplicationController pref.v = request.raw_post.chomp pref.save! - render :text => "", :content_type => "text/plain" + render :nothing => true, :content_type => "text/plain" end ## @@ -82,6 +82,6 @@ class UserPreferenceController < ApplicationController 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 diff --git a/app/controllers/user_roles_controller.rb b/app/controllers/user_roles_controller.rb index 1cfbaf977..9c0339c7a 100644 --- a/app/controllers/user_roles_controller.rb +++ b/app/controllers/user_roles_controller.rb @@ -15,7 +15,7 @@ class UserRolesController < ApplicationController 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 diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb index c988545c7..f7f270575 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/way_controller.rb @@ -16,7 +16,7 @@ class WayController < ApplicationController # 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 @@ -25,9 +25,9 @@ class WayController < ApplicationController 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 @@ -40,7 +40,7 @@ class WayController < ApplicationController 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 @@ -50,9 +50,9 @@ class WayController < ApplicationController 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 @@ -73,9 +73,9 @@ class WayController < ApplicationController 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 @@ -96,7 +96,7 @@ class WayController < ApplicationController doc.root << way.to_xml_node end - render :text => doc.to_s, :content_type => "text/xml" + render :xml => doc.to_s end ## @@ -112,6 +112,6 @@ class WayController < ApplicationController 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 diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index ef7b3f554..998ea405f 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -99,7 +99,7 @@ module BrowseHelper 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 diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 549600df6..f41ad9955 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -149,7 +149,7 @@ class Changeset < ActiveRecord::Base 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 diff --git a/app/models/client_application.rb b/app/models/client_application.rb index 152b3912d..85b6ba68a 100644 --- a/app/models/client_application.rb +++ b/app/models/client_application.rb @@ -75,9 +75,7 @@ class ClientApplication < ActiveRecord::Base # 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] diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index e756432fd..143ddc1dc 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -3,7 +3,7 @@ class DiaryEntry < ActiveRecord::Base 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 diff --git a/app/models/node.rb b/app/models/node.rb index 6346907f1..fb9bdf68b 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -243,7 +243,7 @@ class Node < ActiveRecord::Base # 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 diff --git a/app/models/note.rb b/app/models/note.rb index 73207af0f..d2c36071d 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -7,7 +7,7 @@ class Note < ActiveRecord::Base :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 diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index 31ee6f99b..aa8635aad 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -7,7 +7,7 @@ class NoteComment < ActiveRecord::Base 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 diff --git a/app/models/redaction.rb b/app/models/redaction.rb index 49de3177a..04f002e36 100644 --- a/app/models/redaction.rb +++ b/app/models/redaction.rb @@ -15,7 +15,7 @@ class Redaction < ActiveRecord::Base 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. diff --git a/app/models/relation.rb b/app/models/relation.rb index b78c95ce4..d2490dbae 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -33,7 +33,7 @@ class Relation < ActiveRecord::Base 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) @@ -317,7 +317,7 @@ class Relation < ActiveRecord::Base # 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 @@ -347,7 +347,7 @@ class Relation < ActiveRecord::Base # 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 diff --git a/app/models/trace.rb b/app/models/trace.rb index 2d055fd28..eed09dbe5 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -7,14 +7,14 @@ class Trace < ActiveRecord::Base 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 @@ -29,7 +29,7 @@ class Trace < ActiveRecord::Base 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 @@ -261,7 +261,7 @@ class Trace < ActiveRecord::Base 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 diff --git a/app/models/user.rb b/app/models/user.rb index 3d5e71ea2..3ce48e7cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,7 @@ class User < ActiveRecord::Base 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" @@ -28,8 +28,8 @@ class User < ActiveRecord::Base 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, @@ -37,7 +37,7 @@ class User < ActiveRecord::Base :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? }, @@ -161,13 +161,13 @@ class User < ActiveRecord::Base ## # 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 ## diff --git a/app/models/user_role.rb b/app/models/user_role.rb index 4f80f1952..967850145 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -2,7 +2,7 @@ class UserRole < ActiveRecord::Base 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 diff --git a/app/models/way.rb b/app/models/way.rb index 9877b8bb8..9586094ff 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -271,7 +271,7 @@ class Way < ActiveRecord::Base 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 @@ -281,7 +281,7 @@ class Way < ActiveRecord::Base 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 diff --git a/app/views/changeset/list.atom.builder b/app/views/changeset/list.atom.builder index 68b4a1985..0235d182a 100644 --- a/app/views/changeset/list.atom.builder +++ b/app/views/changeset/list.atom.builder @@ -1,6 +1,6 @@ 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) diff --git a/app/views/geocoder/search.html.erb b/app/views/geocoder/search.html.erb index ac655147a..21484d4c0 100644 --- a/app/views/geocoder/search.html.erb +++ b/app/views/geocoder/search.html.erb @@ -4,7 +4,7 @@ <% @sources.each do |source| %>

<%= raw(t "geocoder.search.title.#{source}") %>

-
"> +
"> <%= image_tag "searching.gif", :class => "loader" %>
<% end %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index a8811c6c9..2b7d6313e 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -57,7 +57,7 @@ <% if @user && @user.id %>