diff --git a/Gemfile b/Gemfile index 0cdf8ce7fd..e1874a6b0f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ -source 'http://rubygems.org' +source 'https://rubygems.org' # Require rails -gem 'rails', '4.0.5' +gem 'rails', '4.1.4' # Require things which have moved to gems in ruby 1.9 gem 'bigdecimal', "~> 1.1.0", :platforms => :ruby_19 @@ -16,7 +16,7 @@ gem 'json' gem 'pg' # Use SCSS for stylesheets -gem 'sass-rails', '~> 4.0.0' +gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' @@ -41,7 +41,7 @@ gem 'rinku', '>= 1.2.2', :require => 'rails_rinku' gem 'oauth-plugin', '>= 0.5.1' gem 'open_id_authentication', '>= 1.1.0' gem 'validates_email_format_of', '>= 1.5.1' -gem 'composite_primary_keys', '>= 6.0.1' +gem 'composite_primary_keys', '~> 7.0.3' gem 'http_accept_language', '~> 2.0.0' gem 'paperclip', '~> 4.0' gem 'deadlock_retry', '>= 1.2.0' @@ -84,7 +84,7 @@ end # Gems needed for running tests group :test do gem 'timecop' - gem 'minitest', '~> 4.7.0', :platforms => [:ruby_19, :ruby_20] + gem 'minitest', '~> 5.1', :platforms => [:ruby_19, :ruby_20] end # Needed in development as well so rake can see konacha tasks diff --git a/Gemfile.lock b/Gemfile.lock index fc2d4f54be..3bd4682a4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,37 +1,39 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: SystemTimer (1.2.3) - actionmailer (4.0.5) - actionpack (= 4.0.5) + actionmailer (4.1.4) + actionpack (= 4.1.4) + actionview (= 4.1.4) mail (~> 2.5.4) - actionpack (4.0.5) - activesupport (= 4.0.5) - builder (~> 3.1.0) - erubis (~> 2.7.0) + actionpack (4.1.4) + actionview (= 4.1.4) + activesupport (= 4.1.4) rack (~> 1.5.2) rack-test (~> 0.6.2) actionpack-page_caching (1.0.2) actionpack (>= 4.0.0, < 5) - activemodel (4.0.5) - activesupport (= 4.0.5) - builder (~> 3.1.0) - activerecord (4.0.5) - activemodel (= 4.0.5) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.5) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.3) - activesupport (4.0.5) + actionview (4.1.4) + activesupport (= 4.1.4) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.4) + activesupport (= 4.1.4) + builder (~> 3.1) + activerecord (4.1.4) + activemodel (= 4.1.4) + activesupport (= 4.1.4) + arel (~> 5.0.0) + activesupport (4.1.4) i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) bigdecimal (1.1.0) - builder (3.1.4) - capybara (2.2.1) + builder (3.2.2) + capybara (2.4.1) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) @@ -49,23 +51,24 @@ GEM coffee-script-source execjs coffee-script-source (1.7.0) - colorize (0.7.2) - composite_primary_keys (6.0.3) - activerecord (>= 4.0.0) - dalli (2.7.1) + colorize (0.7.3) + composite_primary_keys (7.0.3) + activerecord (~> 4.1.4) + crass (0.2.0) + dalli (2.7.2) deadlock_retry (1.2.0) dynamic_form (1.1.4) erubis (2.7.0) - execjs (2.0.2) + execjs (2.2.1) faraday (0.9.0) multipart-post (>= 1.2, < 3) hike (1.2.3) - htmlentities (4.3.1) + htmlentities (4.3.2) http_accept_language (2.0.1) - httpclient (2.3.4.1) + httpclient (2.4.0) i18n (0.6.9) iconv (0.1) - jquery-rails (3.1.0) + jquery-rails (3.1.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) @@ -74,10 +77,9 @@ GEM jsonify-rails (0.3.2) actionpack jsonify (< 0.4.0) - jwt (0.1.13) - multi_json (>= 1.5) + jwt (1.0.0) kgio (2.9.2) - konacha (3.2.2) + konacha (3.2.3) actionpack (>= 3.1, < 5) capybara colorize @@ -88,22 +90,24 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) - mini_portile (0.5.3) - minitest (4.7.5) - multi_json (1.10.0) + mini_portile (0.6.0) + minitest (5.3.5) + multi_json (1.10.1) multi_xml (0.5.5) multipart-post (2.0.0) - nokogiri (1.6.1) - mini_portile (~> 0.5.0) + nokogiri (1.6.2.1) + mini_portile (= 0.6.0) + nokogumbo (1.1.9) + nokogiri oauth (0.4.7) oauth-plugin (0.5.1) multi_json oauth (~> 0.4.4) oauth2 (>= 0.5.0) rack - oauth2 (0.9.3) + oauth2 (0.9.4) faraday (>= 0.8, < 0.10) - jwt (~> 0.1.8) + jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (~> 1.2) @@ -117,14 +121,14 @@ GEM cocaine (~> 0.5.3) mime-types pg (0.17.1) - poltergeist (1.5.0) + poltergeist (1.5.1) capybara (~> 2.1) cliver (~> 0.3.1) multi_json (~> 1.0) websocket-driver (>= 0.2.0) - polyglot (0.3.4) + polyglot (0.3.5) psych (2.0.5) - r2 (0.2.3) + r2 (0.2.5) rack (1.5.2) rack-cors (0.2.9) rack-openid (1.4.2) @@ -132,28 +136,32 @@ GEM ruby-openid (>= 2.1.8) rack-test (0.6.2) rack (>= 1.0) - rails (4.0.5) - actionmailer (= 4.0.5) - actionpack (= 4.0.5) - activerecord (= 4.0.5) - activesupport (= 4.0.5) + rails (4.1.4) + actionmailer (= 4.1.4) + actionpack (= 4.1.4) + actionview (= 4.1.4) + activemodel (= 4.1.4) + activerecord (= 4.1.4) + activesupport (= 4.1.4) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.5) - sprockets-rails (~> 2.0.0) + railties (= 4.1.4) + sprockets-rails (~> 2.0) rails-i18n (4.0.2) i18n (~> 0.6) rails (>= 4.0) - railties (4.0.5) - actionpack (= 4.0.5) - activesupport (= 4.0.5) + railties (4.1.4) + actionpack (= 4.1.4) + activesupport (= 4.1.4) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.3.1) - redcarpet (3.1.1) + rake (10.3.2) + redcarpet (3.1.2) rinku (1.7.3) ruby-openid (2.5.0) - sanitize (2.1.0) + sanitize (3.0.0) + crass (~> 0.2.0) nokogiri (>= 1.4.4) + nokogumbo (= 1.1.9) sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -166,23 +174,24 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.1) + sprockets-rails (2.1.3) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) thor (0.19.1) - thread_safe (0.3.3) + thread_safe (0.3.4) tilt (1.4.1) timecop (0.7.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.39) - uglifier (2.5.0) + tzinfo (1.2.1) + thread_safe (~> 0.1) + uglifier (2.5.1) execjs (>= 0.3.0) json (>= 1.8.0) validates_email_format_of (1.5.3) - vendorer (0.1.15) + vendorer (0.1.16) websocket-driver (0.3.3) xpath (2.0.0) nokogiri (~> 1.3) @@ -195,7 +204,7 @@ DEPENDENCIES actionpack-page_caching bigdecimal (~> 1.1.0) coffee-rails (~> 4.0.0) - composite_primary_keys (>= 6.0.1) + composite_primary_keys (~> 7.0.3) dalli deadlock_retry (>= 1.2.0) dynamic_form @@ -209,7 +218,7 @@ DEPENDENCIES kgio konacha libxml-ruby (>= 2.0.5) - minitest (~> 4.7.0) + minitest (~> 5.1) oauth-plugin (>= 0.5.1) open_id_authentication (>= 1.1.0) openstreetmap-i18n-js (>= 3.0.0.rc5.3) @@ -219,13 +228,13 @@ DEPENDENCIES psych r2 rack-cors - rails (= 4.0.5) + rails (= 4.1.4) rails-i18n (~> 4.0.0) redcarpet rinku (>= 1.2.2) ruby-openid (>= 2.2.0) sanitize - sass-rails (~> 4.0.0) + sass-rails (~> 4.0.3) soap4r-ruby1.9 timecop uglifier (>= 1.3.0) diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index 735fa73a88..b236ba6b57 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -284,7 +284,7 @@ def list elsif params[:bbox] changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params)) elsif params[:friends] && @user - changesets = changesets.where(:user_id => @user.friend_users.public) + changesets = changesets.where(:user_id => @user.friend_users.identifiable) elsif params[:nearby] && @user changesets = changesets.where(:user_id => @user.nearby) end diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 9c4a9d8bd1..e1553cbb0f 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -49,13 +49,13 @@ def list if @user @traces = Trace.visible_to(@user) #1 else - @traces = Trace.public #2 + @traces = Trace.visible_to_all #2 end else if @user and @user == target_user @traces = @user.traces #3 (check vs user id, so no join + can't pick up non-public traces by changing name) else - @traces = target_user.traces.public #4 + @traces = target_user.traces.visible_to_all #4 end end @@ -206,7 +206,7 @@ def delete end def georss - @traces = Trace.public.visible + @traces = Trace.visible_to_all.visible if params[:display_name] @traces = @traces.joins(:user).where(:users => {:display_name => params[:display_name]}) diff --git a/app/controllers/user_preference_controller.rb b/app/controllers/user_preference_controller.rb index 059f00bbe3..a3face30d4 100644 --- a/app/controllers/user_preference_controller.rb +++ b/app/controllers/user_preference_controller.rb @@ -26,7 +26,7 @@ def read ## # return the value for a single preference def read_one - pref = UserPreference.find(@user.id, params[:preference_key]) + pref = UserPreference.find([@user.id, params[:preference_key]]) render :text => pref.v.to_s, :content_type => "text/plain" end @@ -69,7 +69,7 @@ def update # update the value of a single preference def update_one begin - pref = UserPreference.find(@user.id, params[:preference_key]) + pref = UserPreference.find([@user.id, params[:preference_key]]) rescue ActiveRecord::RecordNotFound pref = UserPreference.new pref.user = @user @@ -85,7 +85,7 @@ def update_one ## # delete a single preference def delete_one - UserPreference.find(@user.id, params[:preference_key]).delete + UserPreference.find([@user.id, params[:preference_key]]).delete render :text => "", :content_type => "text/plain" end diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index e70ec204e6..73f6420eab 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -90,7 +90,7 @@ def type_and_paginated_count(type, pages) ] def icon_tags(object) - object.tags.find_all { |k,v| ICON_TAGS.include? k } + object.tags.find_all { |k,v| ICON_TAGS.include? k }.sort end def wiki_link(type, lookup) diff --git a/app/models/trace.rb b/app/models/trace.rb index df66496a26..bf8d3731b8 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -7,7 +7,7 @@ class Trace < ActiveRecord::Base scope :visible, -> { where(:visible => true) } scope :visible_to, ->(u) { visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) } - scope :public, -> { where(:visibility => ["public", "identifiable"]) } + scope :visible_to_all, -> { where(:visibility => ["public", "identifiable"]) } scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) } validates_presence_of :user_id, :name, :timestamp diff --git a/app/models/user.rb b/app/models/user.rb index 81154fff7a..010cdf464b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User < ActiveRecord::Base scope :visible, -> { where(:status => ["pending", "active", "confirmed"]) } scope :active, -> { where(:status => ["active", "confirmed"]) } - scope :public, -> { where(:data_public => true) } + scope :identifiable, -> { where(:data_public => true) } has_attached_file :image, :default_url => "/assets/:class/:attachment/:style.png", diff --git a/config.ru b/config.ru index 205abe3536..5bc2a619e8 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run OpenStreetMap::Application +run Rails.application diff --git a/config/application.rb b/config/application.rb index 3cb01eabf0..a40336c330 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,7 @@ # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) +Bundler.require(*Rails.groups) module OpenStreetMap class Application < Rails::Application @@ -33,9 +33,6 @@ class Application < Rails::Application # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += %W(#{config.root}/lib) - # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" - # 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, # like if you have constraints or database-specific column types @@ -43,12 +40,6 @@ class Application < Rails::Application config.active_record.schema_format = :sql end - # Enable the asset pipeline - config.assets.enabled = true - - # Version of your assets, change this if you want to expire all your assets - config.assets.version = '1.0' - # Don't eager load models when the database is offline if STATUS == :database_offline config.paths["app/models"].skip_eager_load! diff --git a/config/boot.rb b/config/boot.rb index 4489e58688..5e5f0c1fac 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,4 @@ -require 'rubygems' - # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index b958021e8f..ee8d90dc65 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application +# Load the Rails application. require File.expand_path('../application', __FILE__) -# Initialize the rails application -OpenStreetMap::Application.initialize! +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 36696f8271..a414d14906 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,11 +19,19 @@ # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise an error on page load if there are pending migrations + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index c4910d86f1..2b1587a212 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -5,7 +5,7 @@ config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers + # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true @@ -32,9 +32,6 @@ # Generate digests for assets URLs. config.assets.digest = true - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx @@ -67,24 +64,7 @@ # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com" - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - config.assets.precompile += %w( index.js browse.js welcome.js fixthemap.js ) - config.assets.precompile += %w( user.js diary_entry.js swfobject.js ) - config.assets.precompile += %w( large-ltr.css small-ltr.css print-ltr.css ) - config.assets.precompile += %w( large-rtl.css small-rtl.css print-rtl.css ) - config.assets.precompile += %w( leaflet-all.css leaflet.ie.css ) - config.assets.precompile += %w( embed.js embed.css ) - config.assets.precompile += %w( html5shiv.js ) - config.assets.precompile += %w( images/marker-*.png img/*-handle.png ) - config.assets.precompile += %w( potlatch2.swf ) - config.assets.precompile += %w( potlatch2/assets.zip ) - config.assets.precompile += %w( potlatch2/FontLibrary.swf ) - config.assets.precompile += %w( potlatch2/locales/*.swf ) - config.assets.precompile += %w( help/introduction.* ) - config.assets.precompile += %w( iD.js iD.css ) - config.assets.precompile += %w( iD/img/*.svg iD/img/*.png iD/img/*.gif ) - config.assets.precompile += %w( iD/img/pattern/*.png ) + # `config.assets.precompile` has moved to config/initializers/assets.rb # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. @@ -102,4 +82,7 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index ebbda58363..b0ff645a01 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -14,7 +14,7 @@ # Configure static asset server for tests with Cache-Control for performance. config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" + config.static_cache_control = 'public, max-age=3600' # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -33,4 +33,7 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..fd6d1e4d24 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,23 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# 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 diary_entry.js swfobject.js ) +Rails.application.config.assets.precompile += %w( large-ltr.css small-ltr.css print-ltr.css ) +Rails.application.config.assets.precompile += %w( large-rtl.css small-rtl.css print-rtl.css ) +Rails.application.config.assets.precompile += %w( leaflet-all.css leaflet.ie.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( 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.js iD.css ) +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 ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000000..7a06a89f0f --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file diff --git a/config/initializers/postgresql_adapter.rb b/config/initializers/postgresql_adapter.rb index 012e401d24..9dcc34fcc0 100644 --- a/config/initializers/postgresql_adapter.rb +++ b/config/initializers/postgresql_adapter.rb @@ -2,7 +2,7 @@ module ActiveRecord module ConnectionAdapters class PostgreSQLAdapter - def initialize_type_map_with_enums + def initialize_type_map_with_enums(type_map) OID.alias_type "format_enum", "text" OID.alias_type "gpx_visibility_enum", "text" OID.alias_type "note_status_enum", "text" @@ -11,7 +11,7 @@ def initialize_type_map_with_enums OID.alias_type "user_role_enum", "text" OID.alias_type "user_status_enum", "text" - initialize_type_map_without_enums + initialize_type_map_without_enums(type_map) end alias_method_chain :initialize_type_map, :enums diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index ac761aea5a..0000000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure your secret_key_base is kept private -# if you're sharing your code publicly. -OpenStreetMap::Application.config.secret_key_base = '8be565e2e25831d88231f4bcfd83dfc3ab33957c4f33bb3cff7a279f7820ec4d0c1111f246bb347c68859c0b46b4e591be9179a53a5a7165a9936000d6d2be41' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 17173d5366..97886ab3e3 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file. if defined?(MEMCACHE_SERVERS) - OpenStreetMap::Application.config.session_store :mem_cache_store, :memcache_server => MEMCACHE_SERVERS, :namespace => "rails:session", :key => "_osm_session" + Rails.application.config.session_store :mem_cache_store, :memcache_server => MEMCACHE_SERVERS, :namespace => "rails:session", :key => "_osm_session" else - OpenStreetMap::Application.config.session_store :cache_store, :key => '_osm_session' + Rails.application.config.session_store :cache_store, :key => '_osm_session' end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000000..253f2be62c --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 1ce5ed17771b4fdc3f755c5b98459d67816f99ec5889ec2fa7bf2bd3cba3ad5cc453693ce3c5d121669be478fb811136f4f483e6f39ac1f0e34ba66e8acab574 + +test: + secret_key_base: 10d52b1bf88c429e73ffbc5e5f58b037db21f38ea88b8b454e55d52ed8bcc6e7fe3b48a79b2f36eb78a4685224d707767d083f79c51f7d81a9d4a06d1c1e2534 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/lib/migrate.rb b/lib/migrate.rb index 7c14333b30..7f8d33693d 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -1,48 +1,50 @@ module ActiveRecord module ConnectionAdapters - module SchemaStatements - def quote_column_names(column_name) - Array(column_name).map { |e| quote_column_name(e) }.join(", ") - end - - def add_primary_key(table_name, column_name, options = {}) - column_names = Array(column_name) - quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ") - execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{quoted_column_names})" - end + class PostgreSQLAdapter + class SchemaCreation + alias_method :old_add_column_options!, :add_column_options! - def remove_primary_key(table_name) - execute "ALTER TABLE #{table_name} DROP PRIMARY KEY" + def add_column_options!(sql, options) + sql << " UNSIGNED" if options[:unsigned] + old_add_column_options!(sql, options) + sql << " #{options[:options]}" + end end - def add_foreign_key(table_name, column_name, reftbl, refcol = nil) - execute "ALTER TABLE #{table_name} ADD " + - "FOREIGN KEY (#{quote_column_names(column_name)}) " + - "REFERENCES #{reftbl} (#{quote_column_names(refcol || column_name)})" - end + module SchemaStatements + def quote_column_names(column_name) + Array(column_name).map { |e| quote_column_name(e) }.join(", ") + end - def remove_foreign_key(table_name, column_name, reftbl, refcol = nil) - execute "ALTER TABLE #{table_name} DROP " + - "CONSTRAINT #{table_name}_#{column_name[0]}_fkey" - end + def add_primary_key(table_name, column_name, options = {}) + column_names = Array(column_name) + quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ") + execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{quoted_column_names})" + end - alias_method :old_options_include_default?, :options_include_default? + def remove_primary_key(table_name) + execute "ALTER TABLE #{table_name} DROP PRIMARY KEY" + end - def options_include_default?(options) - return false if options[:options] =~ /AUTO_INCREMENT/i - return old_options_include_default?(options) - end + def add_foreign_key(table_name, column_name, reftbl, refcol = nil) + execute "ALTER TABLE #{table_name} ADD " + + "FOREIGN KEY (#{quote_column_names(column_name)}) " + + "REFERENCES #{reftbl} (#{quote_column_names(refcol || column_name)})" + end - alias_method :old_add_column_options!, :add_column_options! + def remove_foreign_key(table_name, column_name, reftbl, refcol = nil) + execute "ALTER TABLE #{table_name} DROP " + + "CONSTRAINT #{table_name}_#{column_name[0]}_fkey" + end - def add_column_options!(sql, options) - sql << " UNSIGNED" if options[:unsigned] - old_add_column_options!(sql, options) - sql << " #{options[:options]}" +# alias_method :old_options_include_default?, :options_include_default? +# +# def options_include_default?(options) +# return false if options[:options] =~ /AUTO_INCREMENT/i +# return old_options_include_default?(options) +# end end - end - class PostgreSQLAdapter alias_method :old_native_database_types, :native_database_types def native_database_types diff --git a/test/controllers/trace_controller_test.rb b/test/controllers/trace_controller_test.rb index 8cbc14b316..68cacdce36 100644 --- a/test/controllers/trace_controller_test.rb +++ b/test/controllers/trace_controller_test.rb @@ -163,10 +163,10 @@ def test_routes # Check that the list of changesets is displayed def test_list get :list - check_trace_list Trace.public + check_trace_list Trace.visible_to_all get :list, :tag => "London" - check_trace_list Trace.tagged("London").public + check_trace_list Trace.tagged("London").visible_to_all end # Check that I can get mine @@ -188,15 +188,15 @@ def test_list_mine def test_list_user # Test a user with no traces get :list, :display_name => users(:second_public_user).display_name - check_trace_list users(:second_public_user).traces.public + check_trace_list users(:second_public_user).traces.visible_to_all # Test a user with some traces - should see only public ones get :list, :display_name => users(:public_user).display_name - check_trace_list users(:public_user).traces.public + check_trace_list users(:public_user).traces.visible_to_all # Should still see only public ones when authenticated as another user get :list, {:display_name => users(:public_user).display_name}, {:user => users(:normal_user).id} - check_trace_list users(:public_user).traces.public + check_trace_list users(:public_user).traces.visible_to_all # Should see all traces when authenticated as the target user get :list, {:display_name => users(:public_user).display_name}, {:user => users(:public_user).id} @@ -210,16 +210,16 @@ def test_list_user # Check that the rss loads def test_rss get :georss, :format => :rss - check_trace_feed Trace.public + check_trace_feed Trace.visible_to_all get :georss, :tag => "London", :format => :rss - check_trace_feed Trace.tagged("London").public + check_trace_feed Trace.tagged("London").visible_to_all get :georss, :display_name => users(:public_user).display_name, :format => :rss - check_trace_feed users(:public_user).traces.public + check_trace_feed users(:public_user).traces.visible_to_all get :georss, :display_name => users(:public_user).display_name, :tag => "Birmingham", :format => :rss - check_trace_feed users(:public_user).traces.tagged("Birmingham").public + check_trace_feed users(:public_user).traces.tagged("Birmingham").visible_to_all end # Test viewing a trace diff --git a/test/controllers/user_blocks_controller_test.rb b/test/controllers/user_blocks_controller_test.rb index ffb5744ea2..717f1167a2 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -223,9 +223,10 @@ def test_create :user_block_period => "12", :user_block => { :needs_view => false, :reason => "Vandalism" } end - assert_redirected_to user_block_path(:id => 4) + id = UserBlock.order(:id).ids.last + assert_redirected_to user_block_path(:id => id) assert_equal "Created a block on user #{users(:unblocked_user).display_name}.", flash[:notice] - b = UserBlock.find(4) + b = UserBlock.find(id) assert_in_delta Time.now, b.created_at, 1 assert_in_delta Time.now, b.updated_at, 1 assert_in_delta Time.now + 12.hour, b.ends_at, 1 diff --git a/test/controllers/user_preference_controller_test.rb b/test/controllers/user_preference_controller_test.rb index f8cafe6a92..4966ae7485 100644 --- a/test/controllers/user_preference_controller_test.rb +++ b/test/controllers/user_preference_controller_test.rb @@ -92,10 +92,10 @@ def test_update put :update end assert_response :unauthorized, "should be authenticated" - assert_equal "value", UserPreference.find(1, "key").v - assert_equal "some_value", UserPreference.find(1, "some_key").v + assert_equal "value", UserPreference.find([1, "key"]).v + assert_equal "some_value", UserPreference.find([1, "some_key"]).v assert_raises ActiveRecord::RecordNotFound do - UserPreference.find(1, "new_key") + UserPreference.find([1, "new_key"]) end # authenticate as a user with preferences @@ -109,10 +109,10 @@ def test_update assert_response :success assert_equal "text/plain", @response.content_type assert_equal "", @response.body - assert_equal "new_value", UserPreference.find(1, "key").v - assert_equal "value", UserPreference.find(1, "new_key").v + assert_equal "new_value", UserPreference.find([1, "key"]).v + assert_equal "value", UserPreference.find([1, "new_key"]).v assert_raises ActiveRecord::RecordNotFound do - UserPreference.find(1, "some_key") + UserPreference.find([1, "some_key"]) end # try a put with duplicate keys @@ -123,7 +123,7 @@ def test_update assert_response :bad_request assert_equal "text/plain", @response.content_type assert_equal "Duplicate preferences with key key", @response.body - assert_equal "new_value", UserPreference.find(1, "key").v + assert_equal "new_value", UserPreference.find([1, "key"]).v # try a put with invalid content assert_no_difference "UserPreference.count" do @@ -143,7 +143,7 @@ def test_update_one end assert_response :unauthorized, "should be authenticated" assert_raises ActiveRecord::RecordNotFound do - UserPreference.find(1, "new_key") + UserPreference.find([1, "new_key"]) end # authenticate as a user with preferences @@ -157,7 +157,7 @@ def test_update_one assert_response :success assert_equal "text/plain", @response.content_type assert_equal "", @response.body - assert_equal "new_value", UserPreference.find(1, "new_key").v + assert_equal "new_value", UserPreference.find([1, "new_key"]).v # try changing the value of a preference assert_no_difference "UserPreference.count" do @@ -167,7 +167,7 @@ def test_update_one assert_response :success assert_equal "text/plain", @response.content_type assert_equal "", @response.body - assert_equal "newer_value", UserPreference.find(1, "new_key").v + assert_equal "newer_value", UserPreference.find([1, "new_key"]).v end ## @@ -178,7 +178,7 @@ def test_delete_one delete :delete_one, :preference_key => "key" end assert_response :unauthorized, "should be authenticated" - assert_equal "value", UserPreference.find(1, "key").v + assert_equal "value", UserPreference.find([1, "key"]).v # authenticate as a user with preferences basic_authorization("test@openstreetmap.org", "test") @@ -191,7 +191,7 @@ def test_delete_one assert_equal "text/plain", @response.content_type assert_equal "", @response.body assert_raises ActiveRecord::RecordNotFound do - UserPreference.find(1, "key") + UserPreference.find([1, "key"]) end # try the delete again for the same key @@ -200,7 +200,7 @@ def test_delete_one end assert_response :not_found assert_raises ActiveRecord::RecordNotFound do - UserPreference.find(1, "key") + UserPreference.find([1, "key"]) end end end diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 46c35f950d..f9aeb73cc2 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -7,6 +7,10 @@ def setup I18n.locale = "en" end + def setup + I18n.locale = "en" + end + def test_linkify %w(http://example.com/test ftp://example.com/test https://example.com/test).each do |link| text = "Test #{link} is made into a link" diff --git a/test/helpers/browse_helper_test.rb b/test/helpers/browse_helper_test.rb index d5f7a91e6f..6ca65f7e74 100644 --- a/test/helpers/browse_helper_test.rb +++ b/test/helpers/browse_helper_test.rb @@ -12,6 +12,10 @@ def setup I18n.locale = "en" end + def teardown + I18n.locale = "en" + end + def test_printable_name assert_equal "17", printable_name(current_nodes(:redacted_node)) assert_equal "Test Node (18)", printable_name(current_nodes(:node_with_name)) diff --git a/test/models/trace_test.rb b/test/models/trace_test.rb index 9ec40f18f4..9f713924d1 100644 --- a/test/models/trace_test.rb +++ b/test/models/trace_test.rb @@ -27,8 +27,8 @@ def test_visible_to check_query(Trace.visible_to(3), [:public_trace_file, :identifiable_trace_file]) end - def test_public - check_query(Trace.public, [:public_trace_file, :identifiable_trace_file, :deleted_trace_file]) + def test_visible_to_all + check_query(Trace.visible_to_all, [:public_trace_file, :identifiable_trace_file, :deleted_trace_file]) end def test_tagged diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 5e03c7e032..93bb348ba3 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -180,10 +180,10 @@ def test_active end end - def test_public - assert_equal 16, User.public.count + def test_identifiable + assert_equal 16, User.identifiable.count assert_raise ActiveRecord::RecordNotFound do - User.public.find(users(:normal_user).id) + User.identifiable.find(users(:normal_user).id) end end