From 54b8c291eacf7fbbbf492a7d8e84b71eefc2406b Mon Sep 17 00:00:00 2001 From: Joseph Mastey Date: Thu, 19 Jan 2017 13:59:40 -0600 Subject: [PATCH] upgrade(rails 5): no longer use rake to invoke rake tasks, use rails though I left the case alone where the command would previously been just `bundle exec rake`, as doing the same doesn't work for rails. --- .travis.yml | 6 +++--- README.md | 17 +++++++++-------- Rakefile | 5 ++--- config/application.rb | 2 +- config/database.yml | 2 +- config/environments/production.rb | 2 +- config/environments/test.rb | 4 ++-- db/schema.rb | 1 - db/seeds.rb | 2 +- doc/README_FOR_APP | 2 +- script/start | 2 +- 11 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index b89f6e6..867eeef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ before_install: - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf ${PWD}/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C ${PWD}/travis_phantomjs; fi" - "phantomjs --version" -before_script: rake db:setup -before_script: bundle exec rake db:setup +before_script: rails db:setup +before_script: bundle exec rails db:setup cache: bundler sudo: false -env: RAILSGOAT_MAINTAINER=true \ No newline at end of file +env: RAILSGOAT_MAINTAINER=true diff --git a/README.md b/README.md index 10bb00a..c26bd7a 100755 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ $ gem install bundler Initialize the database: ```bash -$ rake db:setup +$ rails db:setup ``` Start the Thin web server: @@ -78,7 +78,7 @@ To run Railsgoat with Docker you must first have [Docker](https://docs.docker.co ``` #~/code/railsgoat $ docker-compose build -$ docker-compose run web rake db:setup +$ docker-compose run web rails db:setup $ docker-compose up ... Creating railsgoat_web_1 @@ -103,16 +103,16 @@ In this case, remove that server.pid file and try again. Note also that this fil ## Capybara Tests -RailsGoat now includes a set of failing Capybara RSpecs, each one indicating that a separate vulnerability exists in the application. To run them, you first need to install [PhantomJS](https://github.com/jonleighton/poltergeist#installing-phantomjs) (version 2.1.1 has been tested in Dev and on Travis CI), which is required by the Poltergeist Capybara driver. Upon installation, simply run the following rake task: +RailsGoat now includes a set of failing Capybara RSpecs, each one indicating that a separate vulnerability exists in the application. To run them, you first need to install [PhantomJS](https://github.com/jonleighton/poltergeist#installing-phantomjs) (version 2.1.1 has been tested in Dev and on Travis CI), which is required by the Poltergeist Capybara driver. Upon installation, simply run the following task: ``` -$ rake training +$ rails training ``` To run just one spec: ``` -$ rake training SPEC=spec/vulnerabilities/sql_injection_spec.rb +$ rails training SPEC=spec/vulnerabilities/sql_injection_spec.rb ``` NOTE: As vulnerabilities are fixed in the application, these specs will not change to `passing`, but to `pending`. @@ -124,10 +124,10 @@ By default in development mode Railsgoat runs with a SQLite database. There is a ``` #Create the MySQL database -RAILS_ENV=mysql rake db:create +RAILS_ENV=mysql rails db:create #Run the migrations against the database -RAILS_ENV=mysql rake db:migrate +RAILS_ENV=mysql rails db:migrate #Boot Rails using MySQl RAILS_ENV=mysql rails s @@ -137,9 +137,10 @@ RAILS_ENV=mysql rails s In order for RailsGoat to effectively process email, you will first need to run MailCatcher, an SMTP server that will intercept email messages and display them in a web interface. -To start an instance of MailCatcher, simply run: +Mailcatcher is not installed by default. To install MailCatcher and start an instance of it, simply run: ``` +$ gem install mailcatcher $ mailcatcher ``` diff --git a/Rakefile b/Rakefile index b7b8c46..e85f913 100755 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,6 @@ -#!/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' -Railsgoat::Application.load_tasks +Rails.application.load_tasks diff --git a/config/application.rb b/config/application.rb index ce5141a..06727f0 100755 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,7 @@ module Railsgoat # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # Run "rails -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. diff --git a/config/database.yml b/config/database.yml index bb84441..f630e92 100755 --- a/config/database.yml +++ b/config/database.yml @@ -19,7 +19,7 @@ mysql: password: # Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". +# re-generated from your development database when you run "rails". # Do not set this db to the same as development or production. test: adapter: sqlite3 diff --git a/config/environments/production.rb b/config/environments/production.rb index 94c2767..3f3d6b0 100755 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -15,7 +15,7 @@ Railsgoat::Application.configure do # config.action_dispatch.rack_cache = true # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_files = false + config.public_file_server.enabled = false # Compress JavaScripts and CSS config.assets.compress = true diff --git a/config/environments/test.rb b/config/environments/test.rb index bd6b76c..22845da 100755 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,8 +8,8 @@ Railsgoat::Application.configure do config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + config.public_file_server.enabled = true + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/db/schema.rb b/db/schema.rb index d7745b9..da237a3 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# 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. diff --git a/db/seeds.rb b/db/seeds.rb index 9750f25..333d5ad 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,5 +1,5 @@ # This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# The data can then be loaded with the rails db:seed (or created alongside the db with db:setup). # users = [ diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP index fe41f5c..2c9ee3e 100755 --- a/doc/README_FOR_APP +++ b/doc/README_FOR_APP @@ -1,2 +1,2 @@ Use this README file to introduce your application and point to useful places in the API for learning more. -Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. +Run "rails doc:app" to generate API documentation for your models, controllers, helpers, and libraries. diff --git a/script/start b/script/start index 1e5761c..adb6b63 100644 --- a/script/start +++ b/script/start @@ -1,5 +1,5 @@ #!/bin/bash set -e -rake db:setup +rails db:setup rails server