diff --git a/.rubocop.yml b/.rubocop.yml index 709769f4d..9d1f9dc76 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +require: rubocop-performance + # Start with Spotifys style guide as a base then customize from there inherit_from: - .rubocop_shopify_styleguide.yml diff --git a/.travis.yml b/.travis.yml index dc829fd54..f6a51e967 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: ruby + rvm: - 2.4.6 @@ -7,20 +8,24 @@ services: - docker cache: - bundler: true directories: - - public/lib/ + - $PWD/public/lib/ + - $PWD/vendor/.bundle/ install: - cp config/database.yml.example config/database.yml - cp config/config.yml.example config/config.yml - cp db/schema.rb.example db/schema.rb - ./lib/exporter-deps.sh > /dev/null 2>&1 - - bundle install && yarn install + - bundle check --path vendor/.bundle/ || bundle install --path vendor/.bundle/ + - yarn check || yarn install - if [ $RAILS_ENV == 'production' ]; then - bundle exec rake db:create; + mysql -e "CREATE DATABASE mapknitter;"; + mysql -e "CREATE USER 'mapknitter'@'%' IDENTIFIED BY 'mapknitter';"; + mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'mapknitter'@'%';"; + bundle exec rails db:schema:load; else - bundle exec rake db:setup || bundle exec rake db:migrate; + bundle exec rails db:setup || bundle exec rails db:migrate; fi env: @@ -29,14 +34,17 @@ env: - CI=true - TRAVIS=true +# FIXME - Later change 'test/unit' and 'test/funcional' folders +# to 'test/unit' and 'test/funcional', respectively + jobs: include: - name: "Unit Tests" - script: bundle exec rake test:unit + script: bundle exec rails test:unit - name: "Integration Tests" - script: bundle exec rake test:integration + script: bundle exec rails test:integration - name: "Functional Tests" - script: bundle exec rake test:functional + script: bundle exec rails test:functional - name: "Rubocop Linter" script: bundle exec rubocop - name: "Docker Builds" @@ -44,11 +52,11 @@ jobs: - name: "Asset Precompilation" env: - RAILS_ENV=production - script: bundle exec rake assets:precompile + script: + - bundle exec rails assets:precompile branches: only: - main - unstable - development - diff --git a/Gemfile b/Gemfile index 26ac423e8..f8f9c3ab3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,54 +1,59 @@ -source "https://rubygems.org" +source 'https://rubygems.org' ruby '2.4.6' -gem 'rails', '4.2.11.1' +gem 'rails', '~> 5.2.3' gem 'rake', '~> 12.3.2' gem 'tzinfo-data' gem 'skylight' -gem "will_paginate", "3.1.7" -gem 'will_paginate-bootstrap4' -gem "friendly_id" +gem 'will_paginate', '3.1.7' +gem 'will_paginate-bootstrap4', '~> 0.2.2' +gem 'friendly_id' gem 'popper_js', '~> 1.11', '>= 1.11.1' -gem 'protected_attributes' # dependencies group :dependencies do - gem 'mysql2', '< 0.4' - gem "geokit-rails", "1.1.4" + gem 'mysql2', '< 0.6' + gem 'geokit-rails', '1.1.4' gem 'image_science', '1.3.0' - gem "recaptcha", :require => "recaptcha/rails" - gem "oa-openid", "0.3.2" - gem "ruby-openid", "~>2.5" - gem "open_id_authentication" - gem "RubyInline" - gem "paperclip", "~>4.3.7" + gem 'recaptcha', '~> 4.14.0', require: 'recaptcha/rails' + gem 'oa-openid', '0.3.2' + gem 'ruby-openid', '~>2.5' + gem 'open_id_authentication' + gem 'RubyInline', '~> 3.12.4' + gem 'paperclip', '~> 6.1.0' + gem 'bootsnap', '~> 1.4.4' + gem 'turbolinks', '~> 5' + gem 'mini_magick', '~> 4.8' # if you use amazon s3 for warpable image storage gem 'aws-sdk', '~> 1.5.7' # for rake image migration tasks # gem 'right_aws' - gem 'right_aws_api' + gem 'right_aws_api', '~> 0.3.5' # compiling markdown to html - gem "rdiscount", "2.2.0.1" + gem 'rdiscount', '2.2.0.1' # asset pipelining gem 'bootstrap-sass' gem 'sassc-rails' gem 'jquery-rails' - gem "sprockets" + gem 'sprockets', '3.7.2' gem "sprockets-rails" - gem "sass", :require => 'sass' - gem "autoprefixer-rails" - gem "uglifier" + gem 'sass', require: 'sass' + gem 'autoprefixer-rails', '~> 9.5.1.1' + gem 'uglifier', '~> 4.1.20' + end group :test do - gem 'rubocop', '~> 0.52.0' + gem 'rubocop', '~> 0.70.0' + gem 'rubocop-performance' gem 'ruby-prof' gem 'rails-perftest' + gem 'rails-controller-testing' gem 'simplecov', require: false gem 'codecov', require: false gem 'minitest' @@ -56,25 +61,28 @@ group :test do end group :development, :test do - gem "byebug" - gem 'faker' - gem 'pry-rails' + gem 'byebug', '~> 11.0.1', platforms: [:mri, :mingw, :x64_mingw] + gem 'faker', '~> 1.9.3' + gem 'pry-rails', '~> 0.3.9' end group :development do - gem "jshintrb" - gem "therubyracer" + gem 'jshintrb', '~> 0.3.0' + gem 'mini_racer', platforms: :ruby + gem 'listen', '~> 3.1.5' gem 'web-console', '~> 3.3' + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' end group :sqlite do # if you decide to use sqlite3 as the database - gem "sqlite3" + gem 'sqlite3' end group :passenger do # passenger server - gem "passenger" + gem 'passenger' end gem 'httparty' diff --git a/Gemfile.lock b/Gemfile.lock index 96d1185b4..6a9dae479 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,58 +4,66 @@ GEM RubyInline (3.12.4) ZenTest (~> 4.3) ZenTest (4.11.2) - actionmailer (4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) + actioncable (5.2.3) + actionpack (= 5.2.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.1) - actionview (= 4.2.11.1) - activesupport (= 4.2.11.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.2.3) + actionview (= 5.2.3) + activesupport (= 5.2.3) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.1) - activesupport (= 4.2.11.1) + actionview (5.2.3) + activesupport (= 5.2.3) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.11.1) - activesupport (= 4.2.11.1) - globalid (>= 0.3.0) - activemodel (4.2.11.1) - activesupport (= 4.2.11.1) - builder (~> 3.1) - activerecord (4.2.11.1) - activemodel (= 4.2.11.1) - activesupport (= 4.2.11.1) - arel (~> 6.0) - activesupport (4.2.11.1) - i18n (~> 0.7) + activejob (5.2.3) + activesupport (= 5.2.3) + globalid (>= 0.3.6) + activemodel (5.2.3) + activesupport (= 5.2.3) + activerecord (5.2.3) + activemodel (= 5.2.3) + activesupport (= 5.2.3) + arel (>= 9.0) + activestorage (5.2.3) + actionpack (= 5.2.3) + activerecord (= 5.2.3) + marcel (~> 0.3.1) + activesupport (5.2.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) ansi (1.5.0) - arel (6.0.4) + arel (9.0.0) ast (2.4.0) - autoprefixer-rails (9.6.0) + autoprefixer-rails (9.5.1.1) execjs aws-sdk (1.5.8) httparty (~> 0.7) json (~> 1.4) nokogiri (>= 1.4.4) uuidtools (~> 2.1) + bindex (0.7.0) + bootsnap (1.4.4) + msgpack (~> 1.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) builder (3.2.3) byebug (11.0.1) climate_control (0.2.0) - cocaine (0.5.8) - climate_control (>= 0.0.3, < 1.0) codecov (0.1.14) json simplecov @@ -63,10 +71,9 @@ GEM coderay (1.1.2) concurrent-ruby (1.1.5) crass (1.0.4) - debug_inspector (0.0.3) docile (1.3.2) equatable (0.6.1) - erubis (2.7.0) + erubi (1.8.0) execjs (2.7.0) faker (1.9.4) i18n (>= 0.7) @@ -86,10 +93,11 @@ GEM httparty (0.17.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (0.9.5) + i18n (1.6.0) concurrent-ruby (~> 1.0) image_science (1.3.0) RubyInline (~> 3.9) + jaro_winkler (1.5.3) jquery-rails (4.3.5) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -99,30 +107,41 @@ GEM multi_json (>= 1.3) rake json (1.8.6) - libv8 (3.16.14.19) + libv8 (7.3.492.27.1) libxml-ruby (3.1.0) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2019.0331) - mimemagic (0.3.0) + mimemagic (0.3.3) + mini_magick (4.9.3) mini_mime (1.0.1) mini_portile2 (2.4.0) + mini_racer (0.2.6) + libv8 (>= 6.9.411) minitest (5.11.3) minitest-reporters (1.3.6) ansi builder minitest (>= 5.0) ruby-progressbar + msgpack (1.3.0) multi_json (1.13.1) multi_xml (0.6.0) - mysql2 (0.3.21) + mysql2 (0.5.2) net-http-persistent (2.9.4) + nio4r (2.3.1) nokogiri (1.10.3) mini_portile2 (~> 2.4.0) oa-core (0.3.2) @@ -132,12 +151,12 @@ GEM ruby-openid-apps-discovery (~> 1.2.0) open_id_authentication (1.3.0) rack-openid (~> 1.3) - paperclip (4.3.7) - activemodel (>= 3.2.0) - activesupport (>= 3.2.0) - cocaine (~> 0.5.5) + paperclip (6.1.0) + activemodel (>= 4.2.0) + activesupport (>= 4.2.0) mime-types - mimemagic (= 0.3.0) + mimemagic (~> 0.3.0) + terrapin (~> 0.6.0) parallel (1.17.0) parser (2.6.3.0) ast (~> 2.4.0) @@ -148,55 +167,55 @@ GEM equatable (~> 0.6) tty-color (~> 0.5) popper_js (1.14.5) - powerpack (0.1.2) - protected_attributes (1.1.4) - activemodel (>= 4.0.1, < 5.0) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) pry-rails (0.3.9) pry (>= 0.10.4) - rack (1.6.11) + rack (2.0.7) rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.11.1) - actionmailer (= 4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) - activemodel (= 4.2.11.1) - activerecord (= 4.2.11.1) - activesupport (= 4.2.11.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.1) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.3) + actioncable (= 5.2.3) + actionmailer (= 5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + activemodel (= 5.2.3) + activerecord (= 5.2.3) + activestorage (= 5.2.3) + activesupport (= 5.2.3) + bundler (>= 1.3.0) + railties (= 5.2.3) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.4) + actionpack (>= 5.0.1.x) + actionview (>= 5.0.1.x) + activesupport (>= 5.0.1.x) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) rails-perftest (0.0.7) - railties (4.2.11.1) - actionpack (= 4.2.11.1) - activesupport (= 4.2.11.1) + railties (5.2.3) + actionpack (= 5.2.3) + activesupport (= 5.2.3) + method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.0.0) rake (12.3.2) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) rdiscount (2.2.0.1) - recaptcha (5.0.0) + recaptcha (4.14.0) json redcarpet (3.4.0) - ref (2.0.0) right_aws_api (0.3.5) right_cloud_api_base (>= 0.2.6) right_cloud_api_base (0.2.6) @@ -205,19 +224,22 @@ GEM net-http-persistent (~> 2.9) redcarpet (>= 3.0.0) ruby-hmac (>= 0.4.0) - rubocop (0.52.1) + rubocop (0.70.0) + jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.4.0.2, < 3.0) - powerpack (~> 0.1) + parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) + unicode-display_width (>= 1.4.0, < 1.7) + rubocop-performance (1.3.0) + rubocop (>= 0.68.0) ruby-hmac (0.4.0) ruby-openid (2.7.0) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) ruby-prof (0.18.0) ruby-progressbar (1.10.1) + ruby_dep (1.5.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -241,6 +263,10 @@ GEM skylight-core (= 4.1.2) skylight-core (4.1.2) activesupport (>= 4.2.0) + spring (2.1.0) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -254,9 +280,8 @@ GEM unicode-display_width (~> 1.5) unicode_utils (~> 1.4) strings-ansi (0.1.0) - therubyracer (0.12.3) - libv8 (~> 3.16.14.15) - ref + terrapin (0.6.0) + climate_control (>= 0.0.3, < 1.0) thor (0.20.3) thread_safe (0.3.6) tilt (2.0.9) @@ -268,6 +293,9 @@ GEM tty-screen (0.6.5) tty-tree (0.3.0) tty-which (0.4.1) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) tzinfo (1.2.5) thread_safe (~> 0.1) tzinfo-data (1.2019.1) @@ -278,10 +306,14 @@ GEM unicode_utils (1.4.0) url (0.3.2) uuidtools (2.1.5) - web-console (3.3.0) - activemodel (>= 4.2) - debug_inspector - railties (>= 4.2) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.1) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.4) will_paginate (3.1.7) will_paginate-bootstrap4 (0.2.2) will_paginate (~> 3.0, >= 3.0.0) @@ -290,51 +322,58 @@ PLATFORMS ruby DEPENDENCIES - RubyInline - autoprefixer-rails + RubyInline (~> 3.12.4) + autoprefixer-rails (~> 9.5.1.1) aws-sdk (~> 1.5.7) + bootsnap (~> 1.4.4) bootstrap-sass - byebug + byebug (~> 11.0.1) codecov - faker + faker (~> 1.9.3) friendly_id geokit-rails (= 1.1.4) httparty image_science (= 1.3.0) jquery-rails - jshintrb + jshintrb (~> 0.3.0) + listen (~> 3.1.5) + mini_magick (~> 4.8) + mini_racer minitest minitest-reporters - mysql2 (< 0.4) + mysql2 (< 0.6) oa-openid (= 0.3.2) open_id_authentication - paperclip (~> 4.3.7) + paperclip (~> 6.1.0) passenger popper_js (~> 1.11, >= 1.11.1) - protected_attributes - pry-rails - rails (= 4.2.11.1) + pry-rails (~> 0.3.9) + rails (~> 5.2.3) + rails-controller-testing rails-perftest rake (~> 12.3.2) rdiscount (= 2.2.0.1) - recaptcha - right_aws_api - rubocop (~> 0.52.0) + recaptcha (~> 4.14.0) + right_aws_api (~> 0.3.5) + rubocop (~> 0.70.0) + rubocop-performance ruby-openid (~> 2.5) ruby-prof sass sassc-rails simplecov skylight - sprockets + spring + spring-watcher-listen (~> 2.0.0) + sprockets (= 3.7.2) sprockets-rails sqlite3 - therubyracer + turbolinks (~> 5) tzinfo-data - uglifier + uglifier (~> 4.1.20) web-console (~> 3.3) will_paginate (= 3.1.7) - will_paginate-bootstrap4 + will_paginate-bootstrap4 (~> 0.2.2) RUBY VERSION ruby 2.4.6p354 diff --git a/Rakefile b/Rakefile index ffd116932..b3fe3d210 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ #!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require_relative 'config/application' # Load all the rake tasks from the "tasks" folder. task_dir = File.expand_path("../tasks", __FILE__) @@ -9,4 +9,4 @@ Dir["#{task_dir}/**/*.rake"].each do |task_file| load task_file end -Mapknitter::Application.load_tasks \ No newline at end of file +Rails.application.load_tasks \ No newline at end of file diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index b27494903..0a0f780ff 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -1,8 +1,8 @@ require 'json' class AnnotationsController < ApplicationController - # before_filter :require_user, :except => [ :index, :show ] - before_filter :find_map + # before_action :require_user, :except => [ :index, :show ] + before_action :find_map def index render file: 'annotations/index.json.erb', content_type: 'application/json' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 06862c217..4d4bf7521 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base helper :all # include all helpers, all the time - before_filter :current_user + before_action :current_user helper_method :logged_in?, :current_location def current_user diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 231f18d6c..2def4b577 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -17,7 +17,7 @@ def logger if params[:action] == 'progress' nil else - RAILS_DEFAULT_LOGGER + Rails.logger end end diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb index 392051d23..12740d81e 100644 --- a/app/controllers/feeds_controller.rb +++ b/app/controllers/feeds_controller.rb @@ -1,5 +1,5 @@ class FeedsController < ApplicationController - before_filter :query, only: %i(clean license) + before_action :query, only: %i(clean license) def all # (Warpable.all + Map.all).sort_by(&:created_at) diff --git a/app/controllers/front_ui_controller.rb b/app/controllers/front_ui_controller.rb index a34b7a8ad..a41b4f540 100644 --- a/app/controllers/front_ui_controller.rb +++ b/app/controllers/front_ui_controller.rb @@ -8,9 +8,11 @@ def index @maps = Map.new_maps.first(4) @unpaginated = true # TODO: these could use optimization but are better than prev: - tag = Tag.where(name: 'featured').first # note that this is not a join table but the .maps method still works - @mappers = User.where(login: tag.maps.collect(&:author)) if tag - @mappers ||= [] + @mappers = if Tag.where(name: 'featured').first + User.where(login: tag.maps.collect(&:author)) + else + [] + end end def all_maps diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 66b2cbbc9..7fa9de0e4 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -3,8 +3,8 @@ class MapsController < ApplicationController protect_from_forgery except: :export - before_filter :require_login, only: %i(edit update destroy) - before_filter :find_map, only: %i(show annotate embed edit update images destroy archive) + before_action :require_login, only: %i(edit update destroy) + before_action :find_map, only: %i(show annotate embed edit update images destroy archive) layout 'knitter2' diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index b3bf053c2..aeb1f937c 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,5 +1,5 @@ class TagsController < ApplicationController - before_filter :require_login, only: %i(edit update destroy) + before_action :require_login, only: %i(edit update destroy) def create @map = Map.find_by(slug: params[:map_id]) diff --git a/app/helpers/front_ui_helper.rb b/app/helpers/front_ui_helper.rb index 5a4976030..c58fd7a23 100644 --- a/app/helpers/front_ui_helper.rb +++ b/app/helpers/front_ui_helper.rb @@ -1,7 +1,6 @@ module FrontUiHelper def profile_image(author) - img = author&.warpables&.last&.image&.url - img ||= "/images/yarn.png" + author&.warpables&.last&.image&.url || "/images/yarn.png" end def anonymous(maps) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..00655e720 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' + end diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb index cb369928a..7a4e0902b 100644 --- a/app/mailers/comment_mailer.rb +++ b/app/mailers/comment_mailer.rb @@ -1,4 +1,4 @@ -class CommentMailer < ActionMailer::Base +class CommentMailer < ApplicationMailer default from: "do-not-reply@mapknitter.org" # CommentMailer.notify_of_comment(user,self).deliver diff --git a/app/models/annotation.rb b/app/models/annotation.rb index e681cb9bc..cba78ff2b 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -1,9 +1,10 @@ -class Annotation < ActiveRecord::Base - include ActiveModel::MassAssignmentSecurity - belongs_to :map - belongs_to :user +class Annotation < ApplicationRecord + # FIXME: - We should start using strong parameters here in favor of this below + # include ActiveModel::MassAssignmentSecurity + belongs_to :map, optional: true + belongs_to :user, optional: true - attr_accessible :annotation_type, :coordinates, :text, :style + attr_accessor :annotation_type, :coordinates, :text, :style serialize :coordinates, Array serialize :style, Hash diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 05d55677e..a7a327bc3 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,6 +1,6 @@ -class Comment < ActiveRecord::Base - belongs_to :map - belongs_to :user +class Comment < ApplicationRecord + belongs_to :map, optional: true + belongs_to :user, optional: true validates_presence_of :body, :user_id, :map_id diff --git a/app/models/export.rb b/app/models/export.rb index 57099f612..07365476e 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -1,6 +1,6 @@ -class Export < ActiveRecord::Base - belongs_to :map - belongs_to :user +class Export < ApplicationRecord + belongs_to :map, optional: true + belongs_to :user, optional: true # currently exporting? def running? diff --git a/app/models/map.rb b/app/models/map.rb index b687bda71..2bd9d6c3a 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -1,4 +1,4 @@ -class Map < ActiveRecord::Base +class Map < ApplicationRecord include ActiveModel::Validations extend FriendlyId friendly_id :name, use: %i(slugged static) @@ -20,7 +20,7 @@ class Map < ActiveRecord::Base has_many :tags, dependent: :destroy has_many :comments, dependent: :destroy has_many :annotations, dependent: :destroy - belongs_to :user + belongs_to :user, optional: true has_many :warpables scope :active, -> { where(archived: false) } diff --git a/app/models/node.rb b/app/models/node.rb index a6e3018b7..85f7777db 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -1,3 +1,3 @@ -class Node < ActiveRecord::Base - belongs_to :way +class Node < ApplicationRecord + belongs_to :way, optional: true end diff --git a/app/models/tag.rb b/app/models/tag.rb index 390df29ac..2a298824e 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,6 +1,6 @@ -class Tag < ActiveRecord::Base - belongs_to :map - belongs_to :user +class Tag < ApplicationRecord + belongs_to :map, optional: true + belongs_to :user, optional: true validates_presence_of :name, on: :create, message: "can't be blank" validates_presence_of :user_id, on: :create, message: "can't be blank" diff --git a/app/models/user.rb b/app/models/user.rb index 0274d6bdd..d40a02ca0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ require 'digest/sha1' -class User < ActiveRecord::Base +class User < ApplicationRecord has_many :maps has_many :tags has_many :comments @@ -16,7 +16,7 @@ class User < ActiveRecord::Base validates_length_of :email, within: 6..100 # r@a.wk validates_uniqueness_of :email - # HACK: HACK HACK -- how to do attr_accessible from here? + # HACK: HACK HACK -- how to do attr_accessor from here? # prevents a user from submitting a crafted form that bypasses activation # anything else you want your user to change should be added here. diff --git a/app/models/warpable.rb b/app/models/warpable.rb index b225b51ea..f21187f3b 100755 --- a/app/models/warpable.rb +++ b/app/models/warpable.rb @@ -1,6 +1,9 @@ -class Warpable < ActiveRecord::Base - include ActiveModel::MassAssignmentSecurity - attr_accessible :image +class Warpable < ApplicationRecord + # FIXME: - We should start using strong parameters here in favor of this below + # include ActiveModel::MassAssignmentSecurity + # attr_accessible :image + + attr_accessor :image attr_accessor :src, :srcmedium # for json generation # Paperclip; config and production/development specific configs @@ -15,8 +18,8 @@ class Warpable < ActiveRecord::Base validates_attachment_content_type :image, content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] - belongs_to :map - belongs_to :user + belongs_to :map, optional: true + belongs_to :user, optional: true # overriding JSON formatting for Leaflet.DistortableImage def as_json(options = {}) diff --git a/app/models/way.rb b/app/models/way.rb index 7fb80d1ed..d29acbdf9 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -1,4 +1,4 @@ -class Way < ActiveRecord::Base +class Way < ApplicationRecord has_many :nodes, dependent: :destroy def bbox=(bbox) diff --git a/app/views/feeds/all.builder b/app/views/feeds/all.builder index 760a02c18..d4d36d0d3 100644 --- a/app/views/feeds/all.builder +++ b/app/views/feeds/all.builder @@ -4,7 +4,7 @@ xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Recent maps at MapKnitter.org" - xml.link url_for :only_path => false, :controller => 'spectrums' + xml.link url_for only_path: false, controller: 'feeds', action: 'all' xml.description "Recently posted maps at MapKnitter.org, a Public Lab open source research initiative" @maps.each do |map| diff --git a/app/views/feeds/author.builder b/app/views/feeds/author.builder index 7fca6154f..67057ff9f 100644 --- a/app/views/feeds/author.builder +++ b/app/views/feeds/author.builder @@ -4,7 +4,7 @@ xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Maps by "+params[:id]+" at MapKnitter.org" - xml.link url_for :only_path => false, :controller => 'spectrums' + xml.link url_for only_path: false, controller: 'feeds', action: 'author' xml.description "Recently posted maps at MapKnitter.org, a Public Laboratory open source research initiative" @maps.each do |map| diff --git a/app/views/feeds/clean.builder b/app/views/feeds/clean.builder index 36a2d114d..e05be36f6 100644 --- a/app/views/feeds/clean.builder +++ b/app/views/feeds/clean.builder @@ -4,7 +4,7 @@ xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Recent maps at MapKnitter.org" - xml.link url_for :only_path => false, :controller => 'spectrums' + xml.link url_for only_path: false, controller: 'feeds', action: 'clean' xml.description "Recently posted maps at MapKnitter.org, a Public Lab open source research initiative" @maps.each do |map| diff --git a/app/views/feeds/license.builder b/app/views/feeds/license.builder index 829abbafe..244f54ae8 100644 --- a/app/views/feeds/license.builder +++ b/app/views/feeds/license.builder @@ -4,7 +4,7 @@ xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Recent maps at MapKnitter.org" - xml.link url_for :only_path => false, :controller => 'spectrums' + xml.link url_for only_path: false, controller: 'feeds', action: 'license' xml.description "Recently posted maps at MapKnitter.org, a Public Laboratory open source research initiative" @maps.each do |map| diff --git a/app/views/feeds/tag.builder b/app/views/feeds/tag.builder index 829abbafe..bf50efe89 100644 --- a/app/views/feeds/tag.builder +++ b/app/views/feeds/tag.builder @@ -4,7 +4,7 @@ xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Recent maps at MapKnitter.org" - xml.link url_for :only_path => false, :controller => 'spectrums' + xml.link url_for only_path: false, controller: 'feeds', action: 'tag' xml.description "Recently posted maps at MapKnitter.org, a Public Laboratory open source research initiative" @maps.each do |map| diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 000000000..cb2589829 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,8 @@ + + +
+ + + + <%= yield %> + \ No newline at end of file diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 000000000..cd9bb66dd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> \ No newline at end of file diff --git a/bin/bundle b/bin/bundle index 66e9889e8..f19acf5b5 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 5191e6927..073966023 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/setup b/bin/setup index acdb2c138..94fd4d797 100755 --- a/bin/setup +++ b/bin/setup @@ -1,29 +1,36 @@ #!/usr/bin/env ruby -require 'pathname' +require 'fileutils' +include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) -Dir.chdir APP_ROOT do +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do # This script is a starting point to setup your application. - # Add necessary setup steps to this file: + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install" + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system "bin/rake db:setup" + system! 'bin/rails db:setup' puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" + system! 'bin/rails restart' end diff --git a/bin/update b/bin/update new file mode 100755 index 000000000..58bfaed51 --- /dev/null +++ b/bin/update @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 000000000..460dd565b --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru index 2b2ae190a..afac488a9 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__) +require_relative 'config/environment' run Mapknitter::Application diff --git a/config/application.rb b/config/application.rb index 09d4d4575..653e04541 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,5 +1,4 @@ -require File.expand_path('../boot', __FILE__) - +require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems @@ -27,6 +26,9 @@ class Application < Rails::Application # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] @@ -39,9 +41,6 @@ class Application < Rails::Application # parameters by using an attr_accessible or attr_protected declaration. # config.active_record.whitelist_attributes = true - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true - # Enable the asset pipeline config.assets.enabled = true diff --git a/config/boot.rb b/config/boot.rb index 44358b8e4..b9e460cef 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) # Set up gems listed in the Gemfile. +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 000000000..8648dafa2 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: mapknitter_production diff --git a/config/database.yml.example b/config/database.yml.example index 0607fcd1d..6f196c70d 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -6,15 +6,15 @@ default: &default development: <<: *default - username: - password: + username: + password: database: mapknitter_dev production: adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - host: db + host: <%= ENV.fetch("MYSQL_HOST") { '127.0.0.1' } %> username: mapknitter password: mapknitter database: mapknitter diff --git a/config/environment.rb b/config/environment.rb index 99fb29737..426333bb4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the Rails application. -Mapknitter::Application.initialize! +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 1ab5e7b64..d4ca60dce 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,4 @@ -Mapknitter::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -9,23 +9,31 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true - # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true - # Print deprecation notices to the Rails logger. - config.active_support.deprecation = :log + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false - # Raise an error on page load if there are pending migrations. - config.active_record.migration_error = :page_load + config.cache_store = :null_store + end - # 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 + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + config.action_mailer.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. @@ -36,15 +44,34 @@ # Raises helpful error messages. config.assets.raise_runtime_errors = true - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + # 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 # Do not compress assets config.assets.compress = false - # Expands the lines which load the assets + config.assets.logger = false config.assets.debug = true#false + config.serve_static_files = true - config.assets.logger = false + # Suppress logger output for asset requests. + config.assets.quiet = true + +# Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/config/environments/production.rb b/config/environments/production.rb index 219f7fc32..a963d8cd9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,6 @@ -Mapknitter::Application.configure do +require 'uglifier' +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -15,18 +16,16 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like - # NGINX, varnish or squid. - # config.action_dispatch.rack_cache = true + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + config.assets.js_compressor = Uglifier.new(harmony: true) # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. @@ -36,18 +35,23 @@ # yet still be able to expire them through the digest params. config.assets.digest = true - config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ - config.assets.precompile += ['tags.js', - 'uploads.js', - 'knitter.js', - 'annotations.js', - 'maps.js'] # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + # 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 + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -56,25 +60,20 @@ config.log_level = :debug # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "mapknitter_#{Rails.env}" + + config.action_mailer.perform_caching = false # 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. # config.action_mailer.raise_delivery_errors = false - config.action_mailer.delivery_method = :sendmail - config.action_mailer.sendmail_settings = { - location: '/usr/sbin/sendmail', - arguments: '-i' - } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). @@ -86,6 +85,21 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + config.action_mailer.delivery_method = :sendmail + config.action_mailer.sendmail_settings = { + location: '/usr/sbin/sendmail', + arguments: '-i' + } + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + # 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 278bd7e91..0a38fd3ce 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,4 @@ -Mapknitter::Application.configure do - +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -13,9 +12,11 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -27,14 +28,16 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Randomize the order test cases are executed. - config.active_support.test_order = :random - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/active_record_belongs_to_required_by_default.rb b/config/initializers/active_record_belongs_to_required_by_default.rb new file mode 100644 index 000000000..16e252ab8 --- /dev/null +++ b/config/initializers/active_record_belongs_to_required_by_default.rb @@ -0,0 +1 @@ +Rails.application.config.active_record.belongs_to_required_by_default = true \ No newline at end of file diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index b666a7c43..aa1ca5174 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,17 +1,27 @@ # 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' -Rails.application.config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif *.svg] +Rails.application.configure do + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] -# Add additional assets to the asset load path -# Rails.application.config.assets.paths << Emoji.images_path + # Add additional assets to the asset load path. + # Rails.application.config.assets.paths << Emoji.images_path + # Add Yarn node_modules folder to the asset load path. + config.assets.paths << Rails.root.join('public/lib') -# 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( search.js ) -Rails.application.config.assets.precompile += ['tags.js', - 'uploads.js', - 'knitter.js', - 'annotations.js', - 'maps.js'] + config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ + config.assets.precompile += ['tags.js', + 'uploads.js', + 'knitter.js', + 'annotations.js', + 'maps.js', + 'admin.js', + 'admin.css'] + + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in the app/assets + # folder are already added. + # Rails.application.config.assets.precompile += %w( admin.js admin.css ) +end \ No newline at end of file diff --git a/config/initializers/column_definition.rb b/config/initializers/column_definition.rb index feca93639..501e955b1 100644 --- a/config/initializers/column_definition.rb +++ b/config/initializers/column_definition.rb @@ -11,15 +11,15 @@ # or, alternatively, -# This can also be removed if DEFAULT NULL is removed from all columns; -# Read more at https://github.com/publiclab/mapknitter/pull/323 + # # This can also be removed if DEFAULT NULL is removed from all columns; + # # Read more at https://github.com/publiclab/mapknitter/pull/323 class ActiveRecord::ConnectionAdapters::ColumnDefinition - if ActiveRecord::Base.connection.adapter_name != 'sqlite3' && ActiveRecord::Base.connection.adapter_name != 'SQLite' - def sql_type - type.to_sym == :primary_key ? 'int(11) auto_increment PRIMARY KEY' : base.type_to_sql(type.to_sym, limit, precision, scale) rescue type - end - end + # if ActiveRecord::Base.connection.adapter_name != 'sqlite3' && ActiveRecord::Base.connection.adapter_name != 'SQLite' + # def sql_type + # type.to_sym == :primary_key ? 'int(11) auto_increment PRIMARY KEY' : base.type_to_sql(type.to_sym, limit, precision, scale) rescue type + # end + # end end diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 000000000..d3bcaa5ec --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 54516e3f2..f51a497e1 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ # Be sure to restart your server when you modify this file. +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :hybrid diff --git a/config/initializers/duration.rb b/config/initializers/duration.rb deleted file mode 100644 index ac6e2f581..000000000 --- a/config/initializers/duration.rb +++ /dev/null @@ -1,48 +0,0 @@ -# this is a customization created to bridge incompatabilities when upgrading Ruby 2.1.2 -# to 2.4.4 with Rails 3.2. - -# explanation -# There's a fundamental asymmetry in how operators work in Ruby - -# `1 * 1.second` dispatches -> * on Integer. -# `1.second * 1` dispatches -> * on Duration -> throws error 'Duration can't be coerced into Integer' - -# the source code for Rails 3.2 puts duration second: https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/core_ext/numeric/time.rb - -# the solution: the order of multiplication has to be swtiched, and Duration put first. - -# this code can be removed with ActiveSupport v.5.0.3: https://github.com/rails/rails/blob/v5.0.3/activesupport/lib/active_support/core_ext/numeric/time.rb -# (Rails 5) - -class Numeric - def days - ActiveSupport::Duration.new(24.hours * self, [[:days, self]]) - end - alias :day :days - - def weeks - ActiveSupport::Duration.new(7.days * self, [[:days, self * 7]]) - end - alias :week :weeks - - def fortnights - ActiveSupport::Duration.new(2.weeks * self, [[:days, self * 14]]) - end - alias :fortnight :fortnights -end - -# source code: https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/core_ext/integer/time.rb - -# fixed as of ActiveSupport v.4.1.2 https://github.com/rails/rails/blob/v4.1.12/activesupport/lib/active_support/core_ext/integer/time.rb -# (Rails 4) - -class Integer - def months - ActiveSupport::Duration.new(30.days * self, [[:months, self]]) - end - alias :month :months - - def years - ActiveSupport::Duration.new(365.25.days * self, [[:years, self]]) - end - alias :year :years -end \ No newline at end of file diff --git a/config/initializers/new_framework_defaults_5_2.rb b/config/initializers/new_framework_defaults_5_2.rb new file mode 100644 index 000000000..c383d072b --- /dev/null +++ b/config/initializers/new_framework_defaults_5_2.rb @@ -0,0 +1,38 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.2 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make Active Record use stable #cache_key alongside new #cache_version method. +# This is needed for recyclable cache keys. +# Rails.application.config.active_record.cache_versioning = true + +# Use AES-256-GCM authenticated encryption for encrypted cookies. +# Also, embed cookie expiry in signed or encrypted cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 5.2. +# +# Existing cookies will be converted on read then written with the new scheme. +# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true + +# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages +# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. +# Rails.application.config.active_support.use_authenticated_message_encryption = true + +# Add default protection from forgery to ActionController::Base instead of in +# ApplicationController. +# Rails.application.config.action_controller.default_protect_from_forgery = true + +# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and +# 'f' after migrating old data. +# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true + +# Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. +# Rails.application.config.active_support.use_sha1_digests = true + +# Make `form_with` generate id attributes for any generated HTML tags. +# Rails.application.config.action_view.form_with_generates_ids = true diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index b7bba1a47..cf23dc7a0 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -4,4 +4,4 @@ # 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. -Mapknitter::Application.config.secret_token = 'asdfjdasgaisaolghrwiohrkahguilboiwelkxwbranjkl' +Mapknitter::Application.config.secret_key_base = 'asdfjdasgaisaolghrwiohrkahguilboiwelkxwbranjkl' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index b8e3fb7b6..bbfc3961b 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end -# Disable root element in JSON for ActiveRecord objects. +# To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = false +# self.include_root_in_json = true # end diff --git a/config/locales/en.yml b/config/locales/en.yml index 065395716..decc5a857 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,6 +16,16 @@ # # This would use the information in config/locales/es.yml. # +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. diff --git a/config/routes.rb b/config/routes.rb index 727f6518c..f36cdc4c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,78 +1,95 @@ Mapknitter::Application.routes.draw do - root :to => 'front_ui#index' + root to: 'front_ui#index' + get 'front-page', to: 'front_ui#index' + get 'mappers', to: 'front_ui#nearby_mappers' + get 'about', to: 'front_ui#about' + post 'save_location' => 'front_ui#save_location' + get 'all_maps', to: 'front_ui#all_maps' get 'legacy' => 'maps#index' # remove once new front page is stable - get 'front-page' => 'front_ui#index' - get 'mappers' => 'front_ui#nearby_mappers' - get 'gallery' => 'front_ui#gallery' - post "save_location" => 'front_ui#save_location' - get 'about' => 'front_ui#about' - get 'all_maps' => 'front_ui#all_maps' - - get 'external_url_test' => 'export#external_url_test' - get 'local/:login' => 'sessions#local' - get 'logout' => 'sessions#logout' - get 'login' => 'sessions#new' - get 'register' => 'users#create' - get 'signup' => 'users#new' + + post 'save_location', to: 'front_ui#save_location' + + get 'external_url_test', to: 'export#external_url_test' + get 'local/:login', to: 'sessions#local' + get 'logout', to: 'sessions#logout' + get 'login', to: 'sessions#new' + get 'register', to: 'users#create' + get 'signup', to: 'users#new' # since rails 3.2, we use this to log in: - get 'sessions/create' => 'sessions#create' + get 'sessions/create', to: 'sessions#create' - resources :users, :sessions, :maps + resources :users, :sessions, :maps, :images, :comments, :tags # redirect legacy route: get 'tag/:id', to: redirect('/tags/%{id}') - get 'tags/:id' => 'tags#show' # Registered user pages: - get 'profile' => 'users#profile', :id => 0 - get 'profile/:id' => 'users#profile' - get 'dashboard' => 'users#dashboard' + get 'profile', to: 'users#profile', id: 0 + get 'profile/:id', to: 'users#profile' + get 'dashboard', to: 'users#dashboard' - get 'authors' => 'users#index' + get 'authors', to: 'users#index' - get 'feeds/all' => 'feeds#all', :format => 'rss' - get 'feeds/license/:id' => 'feeds#license', :format => 'rss' - get 'feeds/author/:id' => 'feeds#author', :format => 'rss' - get 'feeds/tag/:id' => 'feeds#tag', :format => 'rss' + get 'images/:url', to: 'images#fetch' - get 'tms/:id/alt/:z/:x/:y.png' => 'utility#tms_alt' - get 'tms/:id/' => 'utility#tms_info' - get 'tms/:id/alt/' => 'utility#tms_info' + get 'tms/:id/alt/:z/:x/:y.png', to: 'utility#tms_alt' + get 'tms/:id/', to: 'utility#tms_info' + get 'tms/:id/alt/', to: 'utility#tms_info' # once we have string-based ids, reorganize these around 'maps' and resourceful routing - get 'map/map' => 'maps#map' - get 'search/:id' => 'maps#search' - get 'search' => 'maps#search' - get 'map/archive/:id' => 'maps#archive' - get 'map/region/:id' => 'maps#region' - get 'map/license/:id' => 'maps#license' - get 'maps/featured' => 'maps#featured' - get 'map/view/:id', to: redirect('/maps/%{id}') # legacy - get 'maps/:id/annotate' => 'maps#annotate' - get 'maps/exports/:id' => 'maps#exports' - get 'maps/:id/warpables' => 'maps#images' # deprecate this in favor of resourceful route below; this is just to override maps/:id - post 'maps/:map_id/warpables' => 'images#create' # deprecate this in favor of resourceful route below; this is just to override maps/:id - get 'export/progress/:id' => 'export#progress' - get 'export/status/:id' => 'export#status' - get 'exports' => 'export#index' + get 'search/:id', to: 'maps#search' + get 'search', to: 'maps#search' + get 'maps/:id/warpables', to: 'maps#images' # deprecate this in favor of resourceful route below; this is just to override maps/:id + get 'maps/view/:id', to: redirect('/maps/%{id}') # legacy + get 'export/progress/:id', to: 'export#progress' + get 'export/status/:id', to: 'export#status' + get 'exports', to: 'export#index' get 'map/:id', to: redirect('/maps/%{id}') - get 'embed/:id' => 'maps#embed' - post 'maps/export/:id' => 'maps#export' - post 'maps/:id' => 'maps#export' + get 'embed/:id', to: 'maps#embed' + post 'maps/:map_id/warpables', to: 'images#create' # deprecate this in favor of resourceful route below; this is just to override maps/:id + post 'maps/export/:id', to: 'maps#export' + post 'maps/:id', to: 'maps#export' + + get 'import/:name', to: 'images#import' # this was for auto-adding images via URL + + namespace 'feeds' do + %w(all clean).each do |action| + get action, action: action, format: 'rss' + end + + %w(license author tag).each do |action| + get action + "/:id", action: action, format: 'rss' + end + end + + namespace 'maps' do + %w(map featured region license).each do |action| + get action, action: action + end + + %w(archive exports).each do |action| + get action + "/:id", action: action + end - get 'import/:name' => 'images#import' # this was for auto-adding images via URL - post 'export/:action/:id' => 'export' + %w(annotate warpables).each do |action| + get "/:id/" + action, action: action + end + end + + namespace 'export' do + %w(index logger jpg geotiff cancel + progress status external_url_test).each do |action| + post action + "/:id", action: action + end + end # make these resourceful after renaming warpables to images - post 'images/create/:id' => 'images#create' # used? - post 'warper/update' => 'images#update' # legacy for cartagen.js - post 'images/update' => 'images#update' - post 'images/delete/:id' => 'images#delete' - delete 'maps/:map_id/warpables/:id' => 'images#destroy' #legacy, will be resourceful - delete 'images/:id' => 'images#destroy' #legacy, will be resourceful + post 'warper/update', to: 'images#update' # legacy for cartagen.js + delete 'maps/:map_id/warpables/:id', to: 'images#destroy' #legacy, will be resourceful + delete 'images/:id', to: 'images#destroy' #legacy, will be resourceful # RESTful API resources :maps do @@ -85,13 +102,6 @@ end end - # See how all your routes lay out with 'rake routes' - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - get ':controller/:action' - get ':controller/:action/:id' - get ':controller/:action.:format' - get ':controller/:action/:id.:format' + # See how all your routes lay out with 'rails routes' end diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 000000000..b54a862a0 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } \ No newline at end of file diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 000000000..d32f76e8f --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/migrate/20090309034933_create_tweets.rb b/db/migrate/20090309034933_create_tweets.rb index 89acd7baf..15865229c 100644 --- a/db/migrate/20090309034933_create_tweets.rb +++ b/db/migrate/20090309034933_create_tweets.rb @@ -1,4 +1,4 @@ -class CreateTweets < ActiveRecord::Migration +class CreateTweets < ActiveRecord::Migration[5.2] def self.up create_table :tweets do |t| diff --git a/db/migrate/20090309220337_create_messages.rb b/db/migrate/20090309220337_create_messages.rb index 5ddc555bd..3cb3848ec 100644 --- a/db/migrate/20090309220337_create_messages.rb +++ b/db/migrate/20090309220337_create_messages.rb @@ -1,4 +1,4 @@ -class CreateMessages < ActiveRecord::Migration +class CreateMessages < ActiveRecord::Migration[5.2] def self.up create_table :messages do |t| t.string :author diff --git a/db/migrate/20090323162902_add_message_id.rb b/db/migrate/20090323162902_add_message_id.rb index 8588293c4..a7fd5882f 100644 --- a/db/migrate/20090323162902_add_message_id.rb +++ b/db/migrate/20090323162902_add_message_id.rb @@ -1,4 +1,4 @@ -class AddMessageId < ActiveRecord::Migration +class AddMessageId < ActiveRecord::Migration[5.2] def self.up add_column :keyvalues, :message_id, :integer, :default => 0 end diff --git a/db/migrate/20090605191716_create_nodes.rb b/db/migrate/20090605191716_create_nodes.rb index ee0b41645..149b1fc18 100644 --- a/db/migrate/20090605191716_create_nodes.rb +++ b/db/migrate/20090605191716_create_nodes.rb @@ -1,4 +1,4 @@ -class CreateNodes < ActiveRecord::Migration +class CreateNodes < ActiveRecord::Migration[5.2] def self.up create_table :nodes do |t| t.string :color, :default => 'red' diff --git a/db/migrate/20090605201606_create_ways.rb b/db/migrate/20090605201606_create_ways.rb index f2f97ea19..72111b1b1 100644 --- a/db/migrate/20090605201606_create_ways.rb +++ b/db/migrate/20090605201606_create_ways.rb @@ -1,4 +1,4 @@ -class CreateWays < ActiveRecord::Migration +class CreateWays < ActiveRecord::Migration[5.2] def self.up create_table :ways do |t| t.string :color, :default => 'red' diff --git a/db/migrate/20090611170805_create_sms.rb b/db/migrate/20090611170805_create_sms.rb index ffc9b50d8..d653a2269 100644 --- a/db/migrate/20090611170805_create_sms.rb +++ b/db/migrate/20090611170805_create_sms.rb @@ -1,4 +1,4 @@ -class CreateSms < ActiveRecord::Migration +class CreateSms < ActiveRecord::Migration[5.2] def self.up # create_table "frontline_actions_triggers", :id => false, :force => true do |t| # t.integer "action_id" diff --git a/db/migrate/20090611204112_add_name_desc_nodes_ways.rb b/db/migrate/20090611204112_add_name_desc_nodes_ways.rb index 6b0f39950..7f09f57de 100644 --- a/db/migrate/20090611204112_add_name_desc_nodes_ways.rb +++ b/db/migrate/20090611204112_add_name_desc_nodes_ways.rb @@ -1,4 +1,4 @@ -class AddNameDescNodesWays < ActiveRecord::Migration +class AddNameDescNodesWays < ActiveRecord::Migration[5.2] def self.up add_column :ways, :name, :string, :default => "" add_column :ways, :description, :string, :default => "" diff --git a/db/migrate/20090611205227_change_lat_lon_types.rb b/db/migrate/20090611205227_change_lat_lon_types.rb index f586e0b1c..952038a8e 100644 --- a/db/migrate/20090611205227_change_lat_lon_types.rb +++ b/db/migrate/20090611205227_change_lat_lon_types.rb @@ -1,4 +1,4 @@ -class ChangeLatLonTypes < ActiveRecord::Migration +class ChangeLatLonTypes < ActiveRecord::Migration[5.2] def self.up drop_table :ways drop_table :nodes diff --git a/db/migrate/20090612011846_add_way_complete.rb b/db/migrate/20090612011846_add_way_complete.rb index 5ec563608..80f6708e3 100644 --- a/db/migrate/20090612011846_add_way_complete.rb +++ b/db/migrate/20090612011846_add_way_complete.rb @@ -1,4 +1,4 @@ -class AddWayComplete < ActiveRecord::Migration +class AddWayComplete < ActiveRecord::Migration[5.2] def self.up add_column :ways, :complete, :boolean, :default => true end diff --git a/db/migrate/20091016214109_create_maps.rb b/db/migrate/20091016214109_create_maps.rb index d0dd25b39..55688a4ce 100644 --- a/db/migrate/20091016214109_create_maps.rb +++ b/db/migrate/20091016214109_create_maps.rb @@ -1,4 +1,4 @@ -class CreateMaps < ActiveRecord::Migration +class CreateMaps < ActiveRecord::Migration[5.2] def self.up create_table :maps do |t| t.string :name, :default => '' diff --git a/db/migrate/20100301013330_create_warpables.rb b/db/migrate/20100301013330_create_warpables.rb index f0b157399..76d3acdde 100644 --- a/db/migrate/20100301013330_create_warpables.rb +++ b/db/migrate/20100301013330_create_warpables.rb @@ -1,4 +1,4 @@ -class CreateWarpables < ActiveRecord::Migration +class CreateWarpables < ActiveRecord::Migration[5.2] def self.up create_table :warpables do |t| t.column :parent_id, :integer diff --git a/db/migrate/20100306184916_add_map_id.rb b/db/migrate/20100306184916_add_map_id.rb index b4d92d8f8..1c585b638 100644 --- a/db/migrate/20100306184916_add_map_id.rb +++ b/db/migrate/20100306184916_add_map_id.rb @@ -1,4 +1,4 @@ -class AddMapId < ActiveRecord::Migration +class AddMapId < ActiveRecord::Migration[5.2] def self.up add_column :warpables, :map_id, :integer, :default => 0 end diff --git a/db/migrate/20100308193343_add_map_description_author.rb b/db/migrate/20100308193343_add_map_description_author.rb index aa963e37f..274c871dd 100644 --- a/db/migrate/20100308193343_add_map_description_author.rb +++ b/db/migrate/20100308193343_add_map_description_author.rb @@ -1,4 +1,4 @@ -class AddMapDescriptionAuthor < ActiveRecord::Migration +class AddMapDescriptionAuthor < ActiveRecord::Migration[5.2] def self.up add_column :maps, :description, :text, :default => '' add_column :maps, :author, :string, :default => 'anonymous' diff --git a/db/migrate/20100310191643_add_warper_data.rb b/db/migrate/20100310191643_add_warper_data.rb index f19115b8c..62611f85b 100644 --- a/db/migrate/20100310191643_add_warper_data.rb +++ b/db/migrate/20100310191643_add_warper_data.rb @@ -1,4 +1,4 @@ -class AddWarperData < ActiveRecord::Migration +class AddWarperData < ActiveRecord::Migration[5.2] def self.up add_column :warpables, :nodes, :string, :default => '' end diff --git a/db/migrate/20100316142953_zoom_to_float.rb b/db/migrate/20100316142953_zoom_to_float.rb index 05c9715a5..a3a0288b5 100644 --- a/db/migrate/20100316142953_zoom_to_float.rb +++ b/db/migrate/20100316142953_zoom_to_float.rb @@ -1,4 +1,4 @@ -class ZoomToFloat < ActiveRecord::Migration +class ZoomToFloat < ActiveRecord::Migration[5.2] def self.up remove_column :maps, :zoom add_column :maps, :zoom, :decimal, :precision => 15, :scale => 10, :default => 2 diff --git a/db/migrate/20100330233734_add_location.rb b/db/migrate/20100330233734_add_location.rb index efd42ac0f..b9abc6996 100644 --- a/db/migrate/20100330233734_add_location.rb +++ b/db/migrate/20100330233734_add_location.rb @@ -1,4 +1,4 @@ -class AddLocation < ActiveRecord::Migration +class AddLocation < ActiveRecord::Migration[5.2] def self.up add_column :maps, :location, :string, :default => '' end diff --git a/db/migrate/20100404061203_add_warpable_lock.rb b/db/migrate/20100404061203_add_warpable_lock.rb index 9d1dac195..434629939 100644 --- a/db/migrate/20100404061203_add_warpable_lock.rb +++ b/db/migrate/20100404061203_add_warpable_lock.rb @@ -1,4 +1,4 @@ -class AddWarpableLock < ActiveRecord::Migration +class AddWarpableLock < ActiveRecord::Migration[5.2] def self.up add_column :warpables, :locked, :boolean, :default => false, :null => false end diff --git a/db/migrate/20100505153420_add_warpable_deleted.rb b/db/migrate/20100505153420_add_warpable_deleted.rb index 47d5de9e6..e865431ba 100644 --- a/db/migrate/20100505153420_add_warpable_deleted.rb +++ b/db/migrate/20100505153420_add_warpable_deleted.rb @@ -1,4 +1,4 @@ -class AddWarpableDeleted < ActiveRecord::Migration +class AddWarpableDeleted < ActiveRecord::Migration[5.2] def self.up add_column :warpables, :deleted, :boolean, :default => false, :null => false end diff --git a/db/migrate/20100531175725_create_warps.rb b/db/migrate/20100531175725_create_warps.rb index faada095d..ae8f5d1fd 100644 --- a/db/migrate/20100531175725_create_warps.rb +++ b/db/migrate/20100531175725_create_warps.rb @@ -1,4 +1,4 @@ -class CreateWarps < ActiveRecord::Migration +class CreateWarps < ActiveRecord::Migration[5.2] def self.up create_table :warps do |t| t.integer :parent_id diff --git a/db/migrate/20100614190507_add_warp_map_id.rb b/db/migrate/20100614190507_add_warp_map_id.rb index 9f3a5e2f8..fd90481ae 100644 --- a/db/migrate/20100614190507_add_warp_map_id.rb +++ b/db/migrate/20100614190507_add_warp_map_id.rb @@ -1,4 +1,4 @@ -class AddWarpMapId < ActiveRecord::Migration +class AddWarpMapId < ActiveRecord::Migration[5.2] def self.up add_column :warps, :map_id, :integer, :default => 0, :null => false add_column :warps, :warpable_id, :integer, :default => 0, :null => false diff --git a/db/migrate/20100709061039_add_static_data_maps.rb b/db/migrate/20100709061039_add_static_data_maps.rb index b033cda3b..162e6a7b8 100644 --- a/db/migrate/20100709061039_add_static_data_maps.rb +++ b/db/migrate/20100709061039_add_static_data_maps.rb @@ -1,4 +1,4 @@ -class AddStaticDataMaps < ActiveRecord::Migration +class AddStaticDataMaps < ActiveRecord::Migration[5.2] def self.up add_column :maps, :static_data, :string, :default => '' end diff --git a/db/migrate/20100731141421_add_warps_additional_fields.rb b/db/migrate/20100731141421_add_warps_additional_fields.rb index b4d8cfcb0..82429d2ba 100644 --- a/db/migrate/20100731141421_add_warps_additional_fields.rb +++ b/db/migrate/20100731141421_add_warps_additional_fields.rb @@ -1,4 +1,4 @@ -class AddWarpsAdditionalFields < ActiveRecord::Migration +class AddWarpsAdditionalFields < ActiveRecord::Migration[5.2] def self.up drop_table :warps create_table :exports do |t| diff --git a/db/migrate/20101014151404_add_vectors_tiles.rb b/db/migrate/20101014151404_add_vectors_tiles.rb index d29cc1d1e..c1726b58d 100644 --- a/db/migrate/20101014151404_add_vectors_tiles.rb +++ b/db/migrate/20101014151404_add_vectors_tiles.rb @@ -1,4 +1,4 @@ -class AddVectorsTiles < ActiveRecord::Migration +class AddVectorsTiles < ActiveRecord::Migration[5.2] def self.up add_column :maps, :vectors, :boolean, :default => true, :null => false add_column :maps, :tiles, :string, :default => '', :null => false diff --git a/db/migrate/20110701105813_change_map_tile_default.rb b/db/migrate/20110701105813_change_map_tile_default.rb index c4cfb0680..c5cde0963 100644 --- a/db/migrate/20110701105813_change_map_tile_default.rb +++ b/db/migrate/20110701105813_change_map_tile_default.rb @@ -1,4 +1,4 @@ -class ChangeMapTileDefault < ActiveRecord::Migration +class ChangeMapTileDefault < ActiveRecord::Migration[5.2] def self.up change_column_default(:maps, :tiles, "google") end diff --git a/db/migrate/20110813004143_change_map_vector_default.rb b/db/migrate/20110813004143_change_map_vector_default.rb index 24233c365..d9bd6cfbd 100644 --- a/db/migrate/20110813004143_change_map_vector_default.rb +++ b/db/migrate/20110813004143_change_map_vector_default.rb @@ -1,4 +1,4 @@ -class ChangeMapVectorDefault < ActiveRecord::Migration +class ChangeMapVectorDefault < ActiveRecord::Migration[5.2] def self.up change_column_default(:maps, :vectors, false) end diff --git a/db/migrate/20110916060555_cleanup_knitter_add_map_archive_and_user_email.rb b/db/migrate/20110916060555_cleanup_knitter_add_map_archive_and_user_email.rb index 66929045d..6ee14a666 100644 --- a/db/migrate/20110916060555_cleanup_knitter_add_map_archive_and_user_email.rb +++ b/db/migrate/20110916060555_cleanup_knitter_add_map_archive_and_user_email.rb @@ -1,4 +1,4 @@ -class CleanupKnitterAddMapArchiveAndUserEmail < ActiveRecord::Migration +class CleanupKnitterAddMapArchiveAndUserEmail < ActiveRecord::Migration[5.2] def self.up add_column :maps, :email, :string, :default => "", :null => false add_column :maps, :archived, :boolean, :default => false, :null => false diff --git a/db/migrate/20111005211631_add_zip_warpable_res_history.rb b/db/migrate/20111005211631_add_zip_warpable_res_history.rb index 3aa796b1e..eb2520cca 100644 --- a/db/migrate/20111005211631_add_zip_warpable_res_history.rb +++ b/db/migrate/20111005211631_add_zip_warpable_res_history.rb @@ -1,4 +1,4 @@ -class AddZipWarpableResHistory < ActiveRecord::Migration +class AddZipWarpableResHistory < ActiveRecord::Migration[5.2] def self.up add_column :warpables, :history, :text, :default => "", :null => false add_column :warpables, :cm_per_pixel, :float, :default => 0, :null => false diff --git a/db/migrate/20111006153011_add_map_tile_url.rb b/db/migrate/20111006153011_add_map_tile_url.rb index b915968f0..2034f0f96 100644 --- a/db/migrate/20111006153011_add_map_tile_url.rb +++ b/db/migrate/20111006153011_add_map_tile_url.rb @@ -1,4 +1,4 @@ -class AddMapTileUrl < ActiveRecord::Migration +class AddMapTileUrl < ActiveRecord::Migration[5.2] def self.up add_column :maps, :tile_url, :text, :default => "", :null => false add_column :maps, :tile_layer, :text, :default => "", :null => false diff --git a/db/migrate/20120104164144_add_export_type_bands.rb b/db/migrate/20120104164144_add_export_type_bands.rb index 199bd4107..572efea6c 100644 --- a/db/migrate/20120104164144_add_export_type_bands.rb +++ b/db/migrate/20120104164144_add_export_type_bands.rb @@ -1,4 +1,4 @@ -class AddExportTypeBands < ActiveRecord::Migration +class AddExportTypeBands < ActiveRecord::Migration[5.2] def self.up add_column :exports, :bands_string, :text, :default => "", :null => false add_column :exports, :export_type, :string, :default => "normal", :null => false diff --git a/db/migrate/20120229164021_add_license.rb b/db/migrate/20120229164021_add_license.rb index 878d4e257..264ee34dc 100644 --- a/db/migrate/20120229164021_add_license.rb +++ b/db/migrate/20120229164021_add_license.rb @@ -1,4 +1,4 @@ -class AddLicense < ActiveRecord::Migration +class AddLicense < ActiveRecord::Migration[5.2] def self.up add_column :maps, :license, :string, :default => 'copyright' end diff --git a/db/migrate/20120525201148_create_users.rb b/db/migrate/20120525201148_create_users.rb index e4f11da29..5ff54a0b0 100644 --- a/db/migrate/20120525201148_create_users.rb +++ b/db/migrate/20120525201148_create_users.rb @@ -1,4 +1,4 @@ -class CreateUsers < ActiveRecord::Migration +class CreateUsers < ActiveRecord::Migration[5.2] def self.up create_table "users", :force => true do |t| t.string :login, :limit => 40 diff --git a/db/migrate/20120525215158_add_user_role_default.rb b/db/migrate/20120525215158_add_user_role_default.rb index 637b26eb7..cf41cb86a 100644 --- a/db/migrate/20120525215158_add_user_role_default.rb +++ b/db/migrate/20120525215158_add_user_role_default.rb @@ -1,4 +1,4 @@ -class AddUserRoleDefault < ActiveRecord::Migration +class AddUserRoleDefault < ActiveRecord::Migration[5.2] def self.up change_column_default(:users, :role, "basic") end diff --git a/db/migrate/20120601185008_remove_identity_url_limit.rb b/db/migrate/20120601185008_remove_identity_url_limit.rb index 9d558b49b..822e21f2c 100644 --- a/db/migrate/20120601185008_remove_identity_url_limit.rb +++ b/db/migrate/20120601185008_remove_identity_url_limit.rb @@ -1,4 +1,4 @@ -class RemoveIdentityUrlLimit < ActiveRecord::Migration +class RemoveIdentityUrlLimit < ActiveRecord::Migration[5.2] def self.up change_column :users, :identity_url, :string, :limit => 255 end diff --git a/db/migrate/20120701165519_create_tags.rb b/db/migrate/20120701165519_create_tags.rb index c2938bba2..37c7467ec 100644 --- a/db/migrate/20120701165519_create_tags.rb +++ b/db/migrate/20120701165519_create_tags.rb @@ -1,4 +1,4 @@ -class CreateTags < ActiveRecord::Migration +class CreateTags < ActiveRecord::Migration[5.2] def self.up create_table :tags do |t| t.string :user_id diff --git a/db/migrate/20130113164917_add_node_map_id.rb b/db/migrate/20130113164917_add_node_map_id.rb index 63eb584d6..6058876f8 100644 --- a/db/migrate/20130113164917_add_node_map_id.rb +++ b/db/migrate/20130113164917_add_node_map_id.rb @@ -1,4 +1,4 @@ -class AddNodeMapId < ActiveRecord::Migration +class AddNodeMapId < ActiveRecord::Migration[5.2] def self.up add_column :nodes, :map_id, :integer, :default => 0 add_column :ways, :map_id, :integer, :default => 0 diff --git a/db/migrate/20130124160539_add_way_order.rb b/db/migrate/20130124160539_add_way_order.rb index 8d084d6a8..afd989761 100644 --- a/db/migrate/20130124160539_add_way_order.rb +++ b/db/migrate/20130124160539_add_way_order.rb @@ -1,4 +1,4 @@ -class AddWayOrder < ActiveRecord::Migration +class AddWayOrder < ActiveRecord::Migration[5.2] def self.up add_column :nodes, :way_order, :integer, :default => 0 end diff --git a/db/migrate/20130128184718_add_node_and_way_body.rb b/db/migrate/20130128184718_add_node_and_way_body.rb index 7a0d13070..dd91eb697 100644 --- a/db/migrate/20130128184718_add_node_and_way_body.rb +++ b/db/migrate/20130128184718_add_node_and_way_body.rb @@ -1,4 +1,4 @@ -class AddNodeAndWayBody < ActiveRecord::Migration +class AddNodeAndWayBody < ActiveRecord::Migration[5.2] def self.up add_column :nodes, :body, :text add_column :ways, :body, :text diff --git a/db/migrate/20130605202555_add_map_anonymously_annotatable.rb b/db/migrate/20130605202555_add_map_anonymously_annotatable.rb index ef5f01f23..37a2906bb 100644 --- a/db/migrate/20130605202555_add_map_anonymously_annotatable.rb +++ b/db/migrate/20130605202555_add_map_anonymously_annotatable.rb @@ -1,4 +1,4 @@ -class AddMapAnonymouslyAnnotatable < ActiveRecord::Migration +class AddMapAnonymouslyAnnotatable < ActiveRecord::Migration[5.2] def self.up add_column :maps, :anon_annotatable, :boolean, :default => false end diff --git a/db/migrate/20140811184901_add_tag_index.rb b/db/migrate/20140811184901_add_tag_index.rb index fbc6cff1e..28c273e09 100644 --- a/db/migrate/20140811184901_add_tag_index.rb +++ b/db/migrate/20140811184901_add_tag_index.rb @@ -1,4 +1,4 @@ -class AddTagIndex < ActiveRecord::Migration +class AddTagIndex < ActiveRecord::Migration[5.2] def self.up add_index :tags, :map_id add_index :tags, :warpable_id diff --git a/db/migrate/20140811185342_create_comments.rb b/db/migrate/20140811185342_create_comments.rb index aea70043b..36a5b1fb9 100644 --- a/db/migrate/20140811185342_create_comments.rb +++ b/db/migrate/20140811185342_create_comments.rb @@ -1,4 +1,4 @@ -class CreateComments < ActiveRecord::Migration +class CreateComments < ActiveRecord::Migration[5.2] def self.up create_table :comments do |t| t.string :user_id diff --git a/db/migrate/20140902182631_create_annotations.rb b/db/migrate/20140902182631_create_annotations.rb index 0dbe8471e..9be8d2ea8 100644 --- a/db/migrate/20140902182631_create_annotations.rb +++ b/db/migrate/20140902182631_create_annotations.rb @@ -1,4 +1,4 @@ -class CreateAnnotations < ActiveRecord::Migration +class CreateAnnotations < ActiveRecord::Migration[5.2] def self.up create_table :annotations do |t| t.integer :map_id diff --git a/db/migrate/20140902201706_rename_annotation_type.rb b/db/migrate/20140902201706_rename_annotation_type.rb index 26bd9bd3d..b657ff5eb 100644 --- a/db/migrate/20140902201706_rename_annotation_type.rb +++ b/db/migrate/20140902201706_rename_annotation_type.rb @@ -1,4 +1,4 @@ -class RenameAnnotationType < ActiveRecord::Migration +class RenameAnnotationType < ActiveRecord::Migration[5.2] def self.up rename_column :annotations, :type, :annotation_type end diff --git a/db/migrate/20141103164503_change_warpable_columns.rb b/db/migrate/20141103164503_change_warpable_columns.rb index aa22ccff0..dd9d97d0c 100644 --- a/db/migrate/20141103164503_change_warpable_columns.rb +++ b/db/migrate/20141103164503_change_warpable_columns.rb @@ -1,4 +1,4 @@ -class ChangeWarpableColumns < ActiveRecord::Migration +class ChangeWarpableColumns < ActiveRecord::Migration[5.2] def up rename_column(:warpables, :filename, :image_file_name) rename_column(:warpables, :content_type, :image_content_type) diff --git a/db/migrate/20141104184417_change_openid_identity_urls.rb b/db/migrate/20141104184417_change_openid_identity_urls.rb index 941426cc9..b079ffce8 100644 --- a/db/migrate/20141104184417_change_openid_identity_urls.rb +++ b/db/migrate/20141104184417_change_openid_identity_urls.rb @@ -1,4 +1,4 @@ -class ChangeOpenidIdentityUrls < ActiveRecord::Migration +class ChangeOpenidIdentityUrls < ActiveRecord::Migration[5.2] def up users = User.find :all diff --git a/db/migrate/20150117041411_add_slug_field_to_maps.rb b/db/migrate/20150117041411_add_slug_field_to_maps.rb index 023037296..4cd5072a8 100644 --- a/db/migrate/20150117041411_add_slug_field_to_maps.rb +++ b/db/migrate/20150117041411_add_slug_field_to_maps.rb @@ -1,4 +1,4 @@ -class AddSlugFieldToMaps < ActiveRecord::Migration +class AddSlugFieldToMaps < ActiveRecord::Migration[5.2] def change # There are some duplicate maps, but none have images, so we can delete dupes that don't have images. dupes = [] diff --git a/db/migrate/20150117041704_move_current_values_in_map_name_to_slug_field.rb b/db/migrate/20150117041704_move_current_values_in_map_name_to_slug_field.rb index 5b3ad170a..6bb1a01a2 100644 --- a/db/migrate/20150117041704_move_current_values_in_map_name_to_slug_field.rb +++ b/db/migrate/20150117041704_move_current_values_in_map_name_to_slug_field.rb @@ -1,4 +1,4 @@ -class MoveCurrentValuesInMapNameToSlugField < ActiveRecord::Migration +class MoveCurrentValuesInMapNameToSlugField < ActiveRecord::Migration[5.2] def up execute "UPDATE maps m SET m.slug = m.name" end diff --git a/db/migrate/20150715162314_change_map_null.rb b/db/migrate/20150715162314_change_map_null.rb index 1ddd7e990..c4d25fec9 100644 --- a/db/migrate/20150715162314_change_map_null.rb +++ b/db/migrate/20150715162314_change_map_null.rb @@ -1,4 +1,4 @@ -class ChangeMapNull < ActiveRecord::Migration +class ChangeMapNull < ActiveRecord::Migration[5.2] def up change_column_null :maps, :tile_url, true change_column_null :maps, :tile_layer, true diff --git a/db/migrate/20190420025012_add_remote_url_to_exports.rb b/db/migrate/20190420025012_add_remote_url_to_exports.rb index ac9a0bc68..53a1859a0 100644 --- a/db/migrate/20190420025012_add_remote_url_to_exports.rb +++ b/db/migrate/20190420025012_add_remote_url_to_exports.rb @@ -1,4 +1,4 @@ -class AddRemoteUrlToExports < ActiveRecord::Migration +class AddRemoteUrlToExports < ActiveRecord::Migration[5.2] def change add_column :exports, :export_url, :string end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..220d6e9d8 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,161 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20190420025012) do + + create_table "annotations", force: :cascade do |t| + t.integer "map_id", limit: 4 + t.integer "user_id", limit: 4 + t.string "annotation_type", limit: 255 + t.string "text", limit: 255 + t.string "style", limit: 255 + t.string "coordinates", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "comments", force: :cascade do |t| + t.string "user_id", limit: 255 + t.string "body", limit: 255 + t.integer "map_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "exports", force: :cascade do |t| + t.integer "map_id", limit: 4, default: 0 + t.integer "size", limit: 4, default: 0 + t.integer "width", limit: 4, default: 0 + t.integer "height", limit: 4, default: 0 + t.float "cm_per_pixel", limit: 24, default: 0.0 + t.string "status", limit: 255, default: "none" + t.boolean "tms", default: false + t.boolean "jpg", default: false + t.boolean "geotiff", default: false + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "zip", default: false, null: false + t.text "bands_string", limit: 65535, null: false + t.string "export_type", limit: 255, default: "normal", null: false + t.integer "user_id", limit: 4, default: 0 + t.string "export_url", limit: 255 + end + + create_table "maps", force: :cascade do |t| + t.string "name", limit: 255, default: "" + t.decimal "lat", precision: 20, scale: 10, default: 0.0 + t.decimal "lon", precision: 20, scale: 10, default: 0.0 + t.integer "version", limit: 4, default: 1 + t.string "password", limit: 255, default: "" + t.text "styles", limit: 65535 + t.datetime "created_at" + t.datetime "updated_at" + t.text "description", limit: 65535 + t.string "author", limit: 255, default: "anonymous" + t.decimal "zoom", precision: 15, scale: 10, default: 2.0 + t.string "location", limit: 255, default: "" + t.string "static_data", limit: 255, default: "" + t.boolean "vectors", default: false, null: false + t.string "tiles", limit: 255, default: "google", null: false + t.string "email", limit: 255, default: "", null: false + t.boolean "archived", default: false, null: false + t.text "tile_url", limit: 65535 + t.text "tile_layer", limit: 65535 + t.string "license", limit: 255, default: "copyright" + t.integer "user_id", limit: 4, default: 0 + t.boolean "anon_annotatable", default: false + t.string "slug", limit: 255 + end + + add_index "maps", ["slug"], name: "index_maps_on_slug", unique: true, using: :btree + + create_table "nodes", force: :cascade do |t| + t.string "color", limit: 255, default: "red" + t.string "author", limit: 255, default: "anonymous" + t.decimal "lat", precision: 20, scale: 10, default: 0.0 + t.decimal "lon", precision: 20, scale: 10, default: 0.0 + t.integer "way_id", limit: 4, default: 0 + t.integer "order", limit: 4, default: 0 + t.datetime "created_at" + t.datetime "updated_at" + t.string "name", limit: 255, default: "" + t.string "description", limit: 255, default: "" + t.integer "map_id", limit: 4, default: 0 + t.integer "way_order", limit: 4, default: 0 + t.text "body", limit: 65535 + end + + create_table "tags", force: :cascade do |t| + t.string "user_id", limit: 255 + t.string "name", limit: 255 + t.integer "map_id", limit: 4 + t.integer "warpable_id", limit: 4 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "tags", ["map_id"], name: "index_tags_on_map_id", using: :btree + add_index "tags", ["user_id"], name: "index_tags_on_user_id", using: :btree + add_index "tags", ["warpable_id"], name: "index_tags_on_warpable_id", using: :btree + + create_table "users", force: :cascade do |t| + t.string "login", limit: 40 + t.string "name", limit: 100, default: "" + t.string "email", limit: 100 + t.string "crypted_password", limit: 40 + t.string "salt", limit: 40 + t.string "identity_url", limit: 255 + t.string "role", limit: 40, default: "basic" + t.datetime "created_at" + t.datetime "updated_at" + t.string "remember_token", limit: 40 + t.datetime "remember_token_expires_at" + end + + add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree + + create_table "warpables", force: :cascade do |t| + t.integer "parent_id", limit: 4 + t.string "image_content_type", limit: 255 + t.string "image_file_name", limit: 255 + t.string "thumbnail", limit: 255 + t.integer "image_file_size", limit: 4 + t.integer "width", limit: 4 + t.integer "height", limit: 4 + t.datetime "created_at" + t.datetime "updated_at" + t.integer "map_id", limit: 4, default: 0 + t.string "nodes", limit: 255, default: "" + t.boolean "locked", default: false, null: false + t.boolean "deleted", default: false, null: false + t.text "history", limit: 65535, null: false + t.float "cm_per_pixel", limit: 24, default: 0.0, null: false + end + + create_table "ways", force: :cascade do |t| + t.string "color", limit: 255, default: "red" + t.string "author", limit: 255, default: "anonymous" + t.decimal "lat1", precision: 20, scale: 10, default: 0.0 + t.decimal "lat2", precision: 20, scale: 10, default: 0.0 + t.decimal "lon1", precision: 20, scale: 10, default: 0.0 + t.decimal "lon2", precision: 20, scale: 10, default: 0.0 + t.datetime "created_at" + t.datetime "updated_at" + t.string "name", limit: 255, default: "" + t.string "description", limit: 255, default: "" + t.boolean "complete", default: true + t.integer "map_id", limit: 4, default: 0 + t.text "body", limit: 65535 + end + +end \ No newline at end of file diff --git a/db/schema.rb.example b/db/schema.rb.example index 6a46422dd..220d6e9d8 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -9,152 +9,153 @@ # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # -# It's strongly recommended to check this file into your version control system. +# It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150715162314) do +ActiveRecord::Schema.define(version: 20190420025012) do - create_table "annotations", :force => true do |t| - t.integer "map_id" - t.integer "user_id" - t.string "annotation_type" - t.string "text" - t.string "style" - t.string "coordinates" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "annotations", force: :cascade do |t| + t.integer "map_id", limit: 4 + t.integer "user_id", limit: 4 + t.string "annotation_type", limit: 255 + t.string "text", limit: 255 + t.string "style", limit: 255 + t.string "coordinates", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "comments", :force => true do |t| - t.string "user_id" - t.string "body" - t.integer "map_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "comments", force: :cascade do |t| + t.string "user_id", limit: 255 + t.string "body", limit: 255 + t.integer "map_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "exports", :force => true do |t| - t.integer "map_id", :default => 0 - t.integer "size", :default => 0 - t.integer "width", :default => 0 - t.integer "height", :default => 0 - t.float "cm_per_pixel", :default => 0.0 - t.string "status", :default => "none" - t.boolean "tms", :default => false - t.boolean "jpg", :default => false - t.boolean "geotiff", :default => false + create_table "exports", force: :cascade do |t| + t.integer "map_id", limit: 4, default: 0 + t.integer "size", limit: 4, default: 0 + t.integer "width", limit: 4, default: 0 + t.integer "height", limit: 4, default: 0 + t.float "cm_per_pixel", limit: 24, default: 0.0 + t.string "status", limit: 255, default: "none" + t.boolean "tms", default: false + t.boolean "jpg", default: false + t.boolean "geotiff", default: false t.datetime "created_at" t.datetime "updated_at" - t.boolean "zip", :default => false, :null => false - t.text "bands_string", :null => false - t.string "export_type", :default => "normal", :null => false - t.integer "user_id", :default => 0 + t.boolean "zip", default: false, null: false + t.text "bands_string", limit: 65535, null: false + t.string "export_type", limit: 255, default: "normal", null: false + t.integer "user_id", limit: 4, default: 0 + t.string "export_url", limit: 255 end - create_table "maps", :force => true do |t| - t.string "name", :default => "" - t.decimal "lat", :precision => 20, :scale => 10, :default => 0.0 - t.decimal "lon", :precision => 20, :scale => 10, :default => 0.0 - t.integer "version", :default => 1 - t.string "password", :default => "" - t.text "styles" + create_table "maps", force: :cascade do |t| + t.string "name", limit: 255, default: "" + t.decimal "lat", precision: 20, scale: 10, default: 0.0 + t.decimal "lon", precision: 20, scale: 10, default: 0.0 + t.integer "version", limit: 4, default: 1 + t.string "password", limit: 255, default: "" + t.text "styles", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.text "description" - t.string "author", :default => "anonymous" - t.decimal "zoom", :precision => 15, :scale => 10, :default => 2.0 - t.string "location", :default => "" - t.string "static_data", :default => "" - t.boolean "vectors", :default => false, :null => false - t.string "tiles", :default => "google", :null => false - t.string "email", :default => "", :null => false - t.boolean "archived", :default => false, :null => false - t.text "tile_url" - t.text "tile_layer" - t.string "license", :default => "copyright" - t.integer "user_id", :default => 0 - t.boolean "anon_annotatable", :default => false - t.string "slug" + t.text "description", limit: 65535 + t.string "author", limit: 255, default: "anonymous" + t.decimal "zoom", precision: 15, scale: 10, default: 2.0 + t.string "location", limit: 255, default: "" + t.string "static_data", limit: 255, default: "" + t.boolean "vectors", default: false, null: false + t.string "tiles", limit: 255, default: "google", null: false + t.string "email", limit: 255, default: "", null: false + t.boolean "archived", default: false, null: false + t.text "tile_url", limit: 65535 + t.text "tile_layer", limit: 65535 + t.string "license", limit: 255, default: "copyright" + t.integer "user_id", limit: 4, default: 0 + t.boolean "anon_annotatable", default: false + t.string "slug", limit: 255 end - add_index "maps", ["slug"], :name => "index_maps_on_slug", :unique => true + add_index "maps", ["slug"], name: "index_maps_on_slug", unique: true, using: :btree - create_table "nodes", :force => true do |t| - t.string "color", :default => "red" - t.string "author", :default => "anonymous" - t.decimal "lat", :precision => 20, :scale => 10, :default => 0.0 - t.decimal "lon", :precision => 20, :scale => 10, :default => 0.0 - t.integer "way_id", :default => 0 - t.integer "order", :default => 0 + create_table "nodes", force: :cascade do |t| + t.string "color", limit: 255, default: "red" + t.string "author", limit: 255, default: "anonymous" + t.decimal "lat", precision: 20, scale: 10, default: 0.0 + t.decimal "lon", precision: 20, scale: 10, default: 0.0 + t.integer "way_id", limit: 4, default: 0 + t.integer "order", limit: 4, default: 0 t.datetime "created_at" t.datetime "updated_at" - t.string "name", :default => "" - t.string "description", :default => "" - t.integer "map_id", :default => 0 - t.integer "way_order", :default => 0 - t.text "body" + t.string "name", limit: 255, default: "" + t.string "description", limit: 255, default: "" + t.integer "map_id", limit: 4, default: 0 + t.integer "way_order", limit: 4, default: 0 + t.text "body", limit: 65535 end - create_table "tags", :force => true do |t| - t.string "user_id" - t.string "name" - t.integer "map_id" - t.integer "warpable_id" + create_table "tags", force: :cascade do |t| + t.string "user_id", limit: 255 + t.string "name", limit: 255 + t.integer "map_id", limit: 4 + t.integer "warpable_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end - add_index "tags", ["map_id"], :name => "index_tags_on_map_id" - add_index "tags", ["user_id"], :name => "index_tags_on_user_id" - add_index "tags", ["warpable_id"], :name => "index_tags_on_warpable_id" + add_index "tags", ["map_id"], name: "index_tags_on_map_id", using: :btree + add_index "tags", ["user_id"], name: "index_tags_on_user_id", using: :btree + add_index "tags", ["warpable_id"], name: "index_tags_on_warpable_id", using: :btree - create_table "users", :force => true do |t| - t.string "login", :limit => 40 - t.string "name", :limit => 100, :default => "" - t.string "email", :limit => 100 - t.string "crypted_password", :limit => 40 - t.string "salt", :limit => 40 - t.string "identity_url" - t.string "role", :limit => 40, :default => "basic" + create_table "users", force: :cascade do |t| + t.string "login", limit: 40 + t.string "name", limit: 100, default: "" + t.string "email", limit: 100 + t.string "crypted_password", limit: 40 + t.string "salt", limit: 40 + t.string "identity_url", limit: 255 + t.string "role", limit: 40, default: "basic" t.datetime "created_at" t.datetime "updated_at" - t.string "remember_token", :limit => 40 + t.string "remember_token", limit: 40 t.datetime "remember_token_expires_at" end - add_index "users", ["login"], :name => "index_users_on_login", :unique => true + add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree - create_table "warpables", :force => true do |t| - t.integer "parent_id" - t.string "image_content_type" - t.string "image_file_name" - t.string "thumbnail" - t.integer "image_file_size" - t.integer "width" - t.integer "height" + create_table "warpables", force: :cascade do |t| + t.integer "parent_id", limit: 4 + t.string "image_content_type", limit: 255 + t.string "image_file_name", limit: 255 + t.string "thumbnail", limit: 255 + t.integer "image_file_size", limit: 4 + t.integer "width", limit: 4 + t.integer "height", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "map_id", :default => 0 - t.string "nodes", :default => "" - t.boolean "locked", :default => false, :null => false - t.boolean "deleted", :default => false, :null => false - t.text "history", :null => false - t.float "cm_per_pixel", :default => 0.0, :null => false + t.integer "map_id", limit: 4, default: 0 + t.string "nodes", limit: 255, default: "" + t.boolean "locked", default: false, null: false + t.boolean "deleted", default: false, null: false + t.text "history", limit: 65535, null: false + t.float "cm_per_pixel", limit: 24, default: 0.0, null: false end - create_table "ways", :force => true do |t| - t.string "color", :default => "red" - t.string "author", :default => "anonymous" - t.decimal "lat1", :precision => 20, :scale => 10, :default => 0.0 - t.decimal "lat2", :precision => 20, :scale => 10, :default => 0.0 - t.decimal "lon1", :precision => 20, :scale => 10, :default => 0.0 - t.decimal "lon2", :precision => 20, :scale => 10, :default => 0.0 + create_table "ways", force: :cascade do |t| + t.string "color", limit: 255, default: "red" + t.string "author", limit: 255, default: "anonymous" + t.decimal "lat1", precision: 20, scale: 10, default: 0.0 + t.decimal "lat2", precision: 20, scale: 10, default: 0.0 + t.decimal "lon1", precision: 20, scale: 10, default: 0.0 + t.decimal "lon2", precision: 20, scale: 10, default: 0.0 t.datetime "created_at" t.datetime "updated_at" - t.string "name", :default => "" - t.string "description", :default => "" - t.boolean "complete", :default => true - t.integer "map_id", :default => 0 - t.text "body" + t.string "name", limit: 255, default: "" + t.string "description", limit: 255, default: "" + t.boolean "complete", default: true + t.integer "map_id", limit: 4, default: 0 + t.text "body", limit: 65535 end -end +end \ No newline at end of file diff --git a/lib/tasks/test_unit.rake b/lib/tasks/test_unit.rake index 803b8645b..8a9dd11b0 100644 --- a/lib/tasks/test_unit.rake +++ b/lib/tasks/test_unit.rake @@ -1,3 +1,4 @@ +require 'rake/testtask' # ==================== # # HOW TO RUN # @@ -109,4 +110,4 @@ namespace :test do desc "Autotask - run integration tests in parallel" multitask :integration_parallel => COMPUTE_INTEGRATION_TASKS -end \ No newline at end of file +end diff --git a/mapknitter.env b/mapknitter.env index eb1a7a8ca..b88791f34 100644 --- a/mapknitter.env +++ b/mapknitter.env @@ -2,4 +2,5 @@ MYSQL_DATABASE=mapknitter MYSQL_USER=mapknitter MYSQL_PASSWORD=mapknitter MYSQL_RANDOM_ROOT_PASSWORD=true +MYSQL_HOST=db RAILS_ENV=production diff --git a/test/functional/annotations_controller_test.rb b/test/functional/annotations_controller_test.rb index ea259ef1c..deec0dec7 100644 --- a/test/functional/annotations_controller_test.rb +++ b/test/functional/annotations_controller_test.rb @@ -15,14 +15,14 @@ def teardown; end session[:user_id] = 1 post :create, format: :json, - map_id: 1, + params: {map_id: 1, annotation: { properties: { annotation_type: 'polyline', textContent: 'Some cool text' }, geometry: { coordinates: [10, 33] } - } + }} @map.reload assert_response 302 @@ -34,14 +34,14 @@ def teardown; end before_count = @map.annotations.count post :create, format: :json, - map_id: 1, + params: { map_id: 1, annotation: { properties: { annotation_type: 'polyline', textContent: 'Some cool text' }, geometry: { coordinates: [10, 33] } - } + }} @map.reload assert_response 302 diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb index b8dd69c39..c5142b18b 100644 --- a/test/functional/comments_controller_test.rb +++ b/test/functional/comments_controller_test.rb @@ -16,10 +16,10 @@ def teardown before_count = Comment.count post(:create, - map_id: @map.slug, + params: { map_id: @map.slug, comment: { user_id: 1 - }) + }}) assert_response :success assert_equal before_count, Comment.count @@ -30,10 +30,10 @@ def teardown before_count = Comment.count post(:create, - comment: { + params: { comment: { map_id: @map.id, body: "I'm gonna troll you!" - }) + }}) assert_response :success assert_not_equal before_count, Comment.count @@ -45,11 +45,11 @@ def teardown session[:user_id] = 4 put(:update, - id: @comment.id, + params: { id: @comment.id, comment: { map_id: @map.id, body: "I'm gonna troll you!" - }) + }}) # refresh the object @comment.reload @@ -63,11 +63,11 @@ def teardown session[:user_id] = 3 put(:update, - id: @comment.id, + params: { id: @comment.id, map_id: @map.slug, comment: { body: "I'm gonna troll you!" - }) + }}) @comment.reload @@ -81,11 +81,11 @@ def teardown @comment = comments(:one) put(:update, - id: @comment.id, + params: { id: @comment.id, map_id: @map.slug, comment: { body: "I'm gonna troll you!" - }) + }}) @comment.reload @@ -101,8 +101,8 @@ def teardown before_count = Comment.count delete(:destroy, - id: @comment.id, - map_id: @map.slug) + params: { id: @comment.id, + map_id: @map.slug}) assert_redirected_to "/maps/" + @map.slug assert_not_equal before_count, Comment.count @@ -115,8 +115,8 @@ def teardown before_count = Comment.count delete(:destroy, - id: @comment.id, - map_id: @map.slug) + params: { id: @comment.id, + map_id: @map.slug}) assert_redirected_to "/maps/" + @map.slug assert_equal before_count, Comment.count @@ -128,8 +128,8 @@ def teardown before_count = Comment.count delete(:destroy, - id: @comment.id, - map_id: @map.slug) + params: { id: @comment.id, + map_id: @map.slug}) assert_redirected_to "/maps/" + @map.slug assert_equal before_count, Comment.count @@ -141,10 +141,10 @@ def teardown session[:user_id] = @user.id post(:create, - comment: { + params: { comment: { map_id: @map.id, body: "I'm gonna troll you!" - }) + }}) assert_response :success assert_not @emails.collect(&:to).include?([@user.email]) @@ -155,10 +155,10 @@ def teardown session[:user_id] = 3 post(:create, - comment: { + params: { comment: { map_id: @map.id, body: "I'm gonna troll you!" - }) + }}) assert_response :success assert @emails.collect(&:to).include?([@user.email]) @@ -172,18 +172,18 @@ def teardown session[:user_id] = @chris.id post(:create, - comment: { + params: { comment: { map_id: @map.id, body: "I'm gonna troll you!" - }) + }}) session[:user_id] = @joshua.id post(:create, - comment: { + params: { comment: { map_id: @map.id, body: "Yeah we'll see!" - }) + }}) assert_response :success assert @emails.collect(&:to).include?([@chris.email]) diff --git a/test/functional/export_controller_test.rb b/test/functional/export_controller_test.rb index d67b3cb96..d75ec1dd7 100644 --- a/test/functional/export_controller_test.rb +++ b/test/functional/export_controller_test.rb @@ -21,7 +21,7 @@ def teardown system('mkdir -p public/warps/cubbon-park') system('cp test/fixtures/demo.png public/warps/cubbon-park/cubbon-park.jpg') - get :jpg, id: map.slug + get :jpg, params: { id: map.slug} assert_response :success assert_includes 'image/jpeg', response.content_type end @@ -31,13 +31,13 @@ def teardown system('mkdir -p public/warps/cubbon-park') system('cp test/fixtures/demo.png public/warps/cubbon-park/cubbon-park-geo.tif') - get :geotiff, id: map.slug + get :geotiff, params: { id: map.slug} assert_response :success assert_includes 'image/tiff', response.content_type end test 'should not cancel if not logged in' do - get :cancel, id: @map.id + get :cancel, params: { id: @map.id} assert_response :success assert_equal 'You must be logged in to export, unless the map is anonymous.', @response.body assert assigns[:map] @@ -47,7 +47,7 @@ def teardown test 'should cancel export' do session[:user_id] = 1 - get :cancel, id: @map.id + get :cancel, params: { id: @map.id} assert_response :success assert_equal 'cancelled', @response.body assert assigns[:map] @@ -55,33 +55,33 @@ def teardown test 'should redirect after cancelling' do session[:user_id] = 1 - get :cancel, id: @map.id, exports: 'cess' + get :cancel, params: { id: @map.id, exports: 'cess'} assert_response :redirect assert flash.present? assert_redirected_to '/exports' end test 'should display export progress' do - get :progress, id: @map.id + get :progress, params: { id: @map.id} assert_response :success assert_equal 'export not running', @response.body assert_equal 'text/plain', @response.content_type end test 'should display progress with no export' do - get :progress, id: 4 + get :progress, params: { id: 4} assert_response :success assert_equal 'export has not been run', @response.body end test 'should display progress completed' do - get :progress, id: 2 + get :progress, params: { id: 2} assert_response :success assert_equal 'complete', @response.body end test 'should display progress failed' do - get :progress, id: 3 + get :progress, params: { id: 3} assert_response :success assert_equal 'export failed', @response.body end @@ -89,13 +89,13 @@ def teardown # does not test the exporter client test 'should display export status' do session[:user_id] = 1 - get :status, id: @map.id + get :status, params: { id: @map.id} assert_response :success end test 'should display error if no export' do session[:user_id] = 1 - get :status, id: 4 + get :status, params: { id: 4} assert_response :success # assert_equal { status: 'export has not been run' }.to_json, @response.body end diff --git a/test/functional/feeds_controller_test.rb b/test/functional/feeds_controller_test.rb index 6074acbab..05bb78d6e 100644 --- a/test/functional/feeds_controller_test.rb +++ b/test/functional/feeds_controller_test.rb @@ -19,6 +19,8 @@ def setup get :all assert_response :success assert_not_nil :maps + assert_equal 'application/xml', @response.content_type + assert_template 'feeds/all' end test 'get clean' do @@ -29,13 +31,15 @@ def setup end test "should get clean feed with moderators links" do - get :all, :moderators => 'true' + get :all, params: { moderators: 'true'} assert_response :success assert_not_nil :maps + assert_equal 'application/xml', @response.content_type + assert_template 'feeds/all' end test "should get license feed" do - get :license, :id => "publicdomain" + get :license, params: { :id => "publicdomain"} assert_response :success assert_not_nil :maps assert_equal 'application/xml', @response.content_type @@ -43,7 +47,7 @@ def setup end test "should get author feed" do - get :author, :id => "quentin" + get :author, params: { :id => "quentin"} assert_response :success assert_not_nil :maps assert_equal 'application/xml', @response.content_type @@ -51,7 +55,7 @@ def setup end test "should get tag feed" do - get :tag, id: 'nice' + get :tag, params: { id: 'nice'} assert_response :success assert_not_nil :tag assert_not_nil :maps @@ -59,7 +63,7 @@ def setup end test 'rescues if tag not present' do - get :tag, id: 'cess' + get :tag, params: { id: 'cess'} assert_equal 'text/plain', @response.content_type assert_equal 'No maps with tag cess', @response.body end diff --git a/test/functional/images_controller_test.rb b/test/functional/images_controller_test.rb index 5e7d427ab..23d6524f6 100644 --- a/test/functional/images_controller_test.rb +++ b/test/functional/images_controller_test.rb @@ -6,22 +6,22 @@ def setup @map = maps(:saugus) @warp = warpables(:one) - @file ||= File.open(File.expand_path(Rails.root + 'test/fixtures/demo.png', __FILE__)) - @uploaded_data = ActionDispatch::Http::UploadedFile.new(tempfile: @file, filename: File.basename(@file), type: "image/png") + file_location = Rails.root + 'test/fixtures/demo.png' + @uploaded_data = Rack::Test::UploadedFile.new(file_location.to_s, 'demo.png', "image/png") end def teardown end test 'fetch locally should redirect to url' do - get :fetch, url: '/maps' + get :fetch, params: { url: '/maps'} assert_response :redirect assert_redirected_to '/maps' end def fetch_in_production Rails.stub(:env, ActiveSupport::StringInquirer.new('production')) do - get :fetch, url: '/maps' + get :fetch, params: { url: '/maps'} assert_response :success assert_equal data, response.body assert_equal 'text/html', response.content_type @@ -31,20 +31,20 @@ def fetch_in_production test 'create uploads an image' do before_count = Warpable.count - post :create, map_id: @map.slug, uploaded_data: @uploaded_data + post :create, params: { map_id: @map.slug, uploaded_data: @uploaded_data} assert_response :success assert_equal before_count + 1, Warpable.count end test 'should return correct status and type on create' do - post :create, map_id: @map.slug, uploaded_data: @uploaded_data + post :create, params: { map_id: @map.slug, uploaded_data: @uploaded_data} assert_equal 200, response.status assert_equal "text/html", response.content_type end test 'should show the image' do - get :show, id: @warp.id, format: 'json' + get :show, params: { id: @warp.id, format: 'json'} json_response = JSON.parse(response.body) assert_equal @warp.id, json_response["id"] assert_response :success @@ -53,20 +53,20 @@ def fetch_in_production test 'should update an image' do session[:user_id] = 1 points = "-71.39,41.83:-71.39,41.83:-71.39,41.83:-71.39,41.83" - patch :update, id: @map.id, warpable_id: @warp.id, locked: false, points: points + patch :update, params: { id: @map.id, warpable_id: @warp.id, locked: false, points: points} assert_not_nil @warp.nodes assert_equal "text/html", response.content_type end test 'correct user should destroy an image' do session[:user_id] = 1 - delete :destroy, id: @warp.id + delete :destroy, params: { id: @warp.id} assert_response :redirect assert_redirected_to "/maps/#{@map.slug}" end test 'redirects to login if attempt destroy and not logged in' do - delete :destroy, id: @warp.id + delete :destroy, params: { id: @warp.id} assert_response :redirect assert_redirected_to '/login' assert_not_nil flash[:error] diff --git a/test/functional/maps_controller_test.rb b/test/functional/maps_controller_test.rb index a26156c76..0c51baa22 100644 --- a/test/functional/maps_controller_test.rb +++ b/test/functional/maps_controller_test.rb @@ -13,7 +13,8 @@ def teardown test 'should display image url for maps by region' do get :region, - { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60, format: :json } + params: { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60}, + format: :json image_urls = [] @map.warpables.each do |warpable| @@ -38,7 +39,7 @@ def teardown test 'should not display archived maps' do session[:user_id] = 1 - get(:archive, id: @map.slug) + get(:archive, params: { id: @map.slug } ) get :index @maps = assigns(:maps) @@ -61,7 +62,7 @@ def teardown end test 'should search for maps by name' do - get :search, q: 'Saugus' + get :search, params: { q: 'Saugus'} @maps = assigns(:maps) assert_response :success @@ -70,7 +71,7 @@ def teardown end test 'should search for maps by location' do - get :search, q: 'India' + get :search, params: { q: 'India'} @maps = assigns(:maps) assert_response :success @@ -79,7 +80,7 @@ def teardown end test 'should search for maps by description' do - get :search, q: 'a park' + get :search, params: { q: 'a park'} @maps = assigns(:maps) assert_response :success @@ -90,13 +91,13 @@ def teardown test 'should create map if logged in' do session[:user_id] = 1 before_count = Map.count - post(:create, map: { + post(:create, params: { map: { name: 'Coal terminal map', slug: 'coal-terminal', location: 'London', lat: 42.43823313018592, lon: -70.9849190711975 - }) + }}) @map = assigns(:map) assert_response 302 @@ -108,13 +109,13 @@ def teardown test 'should create map if not logged in' do before_count = Map.count - post(:create, map: { + post(:create, params: { map: { name: 'Coal terminal map', slug: 'coal-terminal', location: 'London', lat: 42.43823313018592, lon: -70.9849190711975 - }) + }}) @map = assigns(:map) assert_redirected_to '/maps/' + @map.slug @@ -128,13 +129,13 @@ def teardown before_count = Map.count user = users(:quentin) session[:user_id] = user.id - post :create, map: { + post :create, params: { map: { name: 'Yaya Center', slug: 'yaya-center', location: 'Nairobi', lat: -0.3030988, lon: 36.080026 - } + }} @map = assigns(:map) assert_redirected_to '/maps/' + @map.slug @@ -148,10 +149,10 @@ def teardown skip 'images and warpable naming contradicts with rails naming convention' session[:user_id] = 1 before_count = Map.count - post(:create, map: { + post(:create, params: { map: { name: 'Coal terminal map', slug: 'coal-terminal' - }) + }}) @map = assigns(:map) assert_not @map.save @@ -164,7 +165,7 @@ def teardown test 'should not delete map if not owner' do session[:user_id] = 3 before_count = Map.count - post(:destroy, id: @map.slug) + post(:destroy, params: { id: @map.slug}) assert_redirected_to '/maps/' + @map.slug assert_equal flash[:error], 'Only admins or map owners may delete maps.' @@ -174,7 +175,7 @@ def teardown test 'should delete map if owner' do session[:user_id] = 1 before_count = Map.count - post(:destroy, id: @map.slug) + post(:destroy, params: { id: @map.slug}) assert_redirected_to '/' assert_not_equal before_count, Map.count @@ -182,14 +183,14 @@ def teardown end test "should get show" do - get(:show, id: @map.slug) + get(:show, params: { id: @map.slug}) assert_response :success assert_not_nil assigns(:map) end test 'should archive map' do session[:user_id] = 1 - get(:archive, id: @map.slug) + get(:archive, params: { id: @map.slug}) @map.reload assert_redirected_to '/?_=' + Time.now.to_i.to_s @@ -198,7 +199,7 @@ def teardown test 'should not archive map without enough permissions' do session[:user_id] = 3 - get(:archive, id: @map.slug) + get(:archive, params: { id: @map.slug}) @map.reload assert_redirected_to '/?_=' + Time.now.to_i.to_s @@ -208,7 +209,7 @@ def teardown test 'should update map' do session[:user_id] = 1 put(:update, - id: @map.slug, + params: { id: @map.slug, map: { name: 'Schrute farms', location: 'USA', @@ -216,7 +217,7 @@ def teardown lon: -74, description: 'A really green farm' }, - tags: 'beets bears') + tags: 'beets bears'}) @map.reload assert_redirected_to "/maps/#{@map.slug}" @@ -229,12 +230,12 @@ def teardown end test 'should not update unless logged in' do - put :update, id: 2, map: { name: 'Street 5'} + put :update, params: { id: 2, map: { name: 'Street 5'}} assert_redirected_to '/login?back_to=/maps/2' end test 'should display maps by region' do - get :region, { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60 } + get :region, params: { minlat: 40, maxlat: 50, minlon: -80, maxlon: -60 } @maps = assigns(:maps) assert_response :success @@ -242,19 +243,19 @@ def teardown end test 'should annotate maps' do - get :annotate, id: @map.slug + get :annotate, params: { id: @map.slug} assert_response :success assigns(:annotations) == true end test 'embed' do - get :embed, id: @map.slug + get :embed, params: { id: @map.slug} assert_response :success assert_template :show end test 'it returns the images' do - get :images, id: @map.slug + get :images, params: { id: @map.slug} assert_response :success assert_equal 'application/json', response.content_type end @@ -262,7 +263,7 @@ def teardown def export_if_logged_in Rails.stub(:env, ActiveSupport::StringInquirer.new('development')) do session[:user_id] = 1 - post :export, id: @map.id, resolution: 5 + post :export, params: { id: @map.id, resolution: 5} assert_response :success assert_equal 'complete', @response.body end @@ -271,13 +272,13 @@ def export_if_logged_in def export_anonmymous_map Rails.stub(:env, ActiveSupport::StringInquirer.new('development')) do map = maps(:cubbon) - post :export, id: map.id, resolution: 5 + post :export, params: { id: map.id, resolution: 5} assert_response :success end end test 'returns the exports' do - get :exports, id: @map.id + get :exports, params: { id: @map.id} assert_response :success end diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb index 98da1b9dd..26b78f271 100644 --- a/test/functional/sessions_controller_test.rb +++ b/test/functional/sessions_controller_test.rb @@ -27,7 +27,7 @@ class SessionsControllerTest < ActionController::TestCase test 'successful local login' do system('cp config/config.yml.example config/config.yml') - get :local, login: 'quentin' + get :local, params: { login: 'quentin'} assert_response :redirect assert flash[:success].present? assert_not_nil session[:user_id] @@ -36,7 +36,7 @@ class SessionsControllerTest < ActionController::TestCase end test 'unsuccessful local login' do - get :local, login: 'cess' + get :local, params: { login: 'cess'} assert_response :redirect assert flash[:error].present? assert_nil session[:user_id] diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 90a325700..d3c275f9d 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -9,31 +9,31 @@ def setup test "should create tag" do session[:user_id] = 1 # log in - post(:create, :map_id => @map.slug, :tags => "test,nice") + post(:create, params: { :map_id => @map.slug, :tags => "test,nice"}) assert_response :redirect end test "should get tag show page" do - get :show, :id => "nice" + get :show, params: {id: "nice"} assert_response :success assert_not_nil :maps, :tag end test "should redirect to login when not logged in" do - post :create, map_id: @map.slug, tags: "test,nice" + post :create, params: { map_id: @map.slug, tags: "test,nice"} assert_redirected_to "/login?back_to=/maps/#{@map.slug}" assert flash.present? end test 'should destroy a tag' do session[:user_id] = 1 - delete :destroy, id: @tag + delete :destroy, params: { id: @tag} assert flash[:notice].present? assert_redirected_to @tag.map end test 'should redirect destroy when not logged in' do - delete :destroy, id: @tag + delete :destroy, params: { id: @tag} assert_response :redirect assert flash.present? end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index d9bdd61f0..d38e1d61c 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -19,7 +19,7 @@ def setup end test "should get profile" do - get(:profile, id: @user.login) + get(:profile, params: {id: @user.login} ) assert_response :success assert_not_nil :user end diff --git a/test/functional/utility_controller_test.rb b/test/functional/utility_controller_test.rb index 87ae42f9f..c929329d5 100644 --- a/test/functional/utility_controller_test.rb +++ b/test/functional/utility_controller_test.rb @@ -5,10 +5,13 @@ class UtilityControllerTest < ActionController::TestCase test 'should translate tms format' do get(:tms_alt, - id: 1, - x: 10, - y: 30, - z: 40) + params: { + id: 1, + x: 10, + y: 30, + z: 40 + } + ) y = 2**40.to_i - 30.to_i - 1 assert_redirected_to "/tms/1/40/10/#{y}.png" diff --git a/test/test_helper.rb b/test/test_helper.rb index e796f422e..cf0daa4af 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,7 @@ -require 'simplecov' -require File.expand_path('../../config/environment', __FILE__) +require_relative '../config/environment' require 'rails/test_help' +require 'simplecov' require 'minitest/reporters' MiniTest::Reporters.use! [MiniTest::Reporters::ProgressReporter.new, MiniTest::Reporters::JUnitReporter.new] @@ -9,11 +9,7 @@ class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. - # - # Note: You'll currently still have to declare fixtures explicitly in integration tests - # -- they do not yet inherit this setting fixtures :all - # Add more helper methods to be used by all tests here... include ApplicationHelper end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 1612c84db..4821c931c 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -43,7 +43,12 @@ class UserTest < ActiveSupport::TestCase user = users(:quentin) map_images = user.maps.map(&:warpables) - assert_equal Warpable::ActiveRecord_Associations_CollectionProxy, user.warpables.class + map_images.flatten.each do |image| + user.warpables.each do |warpable| + assert_equal image.class, warpable.class + end + end + assert_equal map_images.flatten, user.warpables end