From 7477d4c6dda92d24046e45b5dde14cbe59b78255 Mon Sep 17 00:00:00 2001 From: Hauke Klement Date: Mon, 2 Mar 2015 15:04:37 +0100 Subject: [PATCH] transitionally downgraded to Rails 4.1 since activerecord-jdbcpostgresql-adapter is not fully compatible with Active Record 4.2 --- Gemfile | 6 +- Gemfile.lock | 111 +++++++----------- app/models/exercise.rb | 2 +- bin/rails | 6 +- bin/rake | 4 - bin/setup | 29 ----- bin/spring | 11 +- config.ru | 2 +- config/application.rb | 12 +- config/boot.rb | 3 +- config/environments/development.rb | 11 +- config/environments/production.rb | 32 ++--- config/environments/test.rb | 7 +- config/initializers/assets.rb | 11 -- config/initializers/session_store.rb | 2 +- config/routes.rb | 30 ++--- .../application_controller_spec.rb | 2 + 17 files changed, 107 insertions(+), 174 deletions(-) delete mode 100755 bin/setup delete mode 100644 config/initializers/assets.rb diff --git a/Gemfile b/Gemfile index 53811a18..19a51b8b 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby gem 'bcrypt', '~> 3.1.7' gem 'bootstrap-will_paginate' gem 'carrierwave' -gem 'coffee-rails', '~> 4.1.0' +gem 'coffee-rails', '~> 4.0.0' gem 'concurrent-ruby' gem 'concurrent-ruby-ext', platform: :ruby gem 'docker-api', require: 'docker' @@ -20,11 +20,11 @@ gem 'pg', platform: :ruby gem 'pry' gem 'puma' gem 'pundit' -gem 'rails', '~> 4.2.0' +gem 'rails', '~> 4.1.2' gem 'rails-i18n', '~> 4.0.0' gem 'ransack' gem 'rubytree' -gem 'sass-rails', '~> 5.0' +gem 'sass-rails', '~> 4.0.3' gem 'sdoc', '~> 0.4.0', group: :doc gem 'slim' gem 'sorcery' diff --git a/Gemfile.lock b/Gemfile.lock index aa87785d..58353e7d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,48 +2,39 @@ GEM remote: https://rubygems.org/ specs: ZenTest (4.11.0) - actionmailer (4.2.0) - actionpack (= 4.2.0) - actionview (= 4.2.0) - activejob (= 4.2.0) + actionmailer (4.1.9) + actionpack (= 4.1.9) + actionview (= 4.1.9) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.0) - actionview (= 4.2.0) - activesupport (= 4.2.0) - rack (~> 1.6.0) + actionpack (4.1.9) + actionview (= 4.1.9) + activesupport (= 4.1.9) + rack (~> 1.5.2) rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - actionview (4.2.0) - activesupport (= 4.2.0) + actionview (4.1.9) + activesupport (= 4.1.9) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - activejob (4.2.0) - activesupport (= 4.2.0) - globalid (>= 0.3.0) - activemodel (4.2.0) - activesupport (= 4.2.0) + activemodel (4.1.9) + activesupport (= 4.1.9) builder (~> 3.1) - activerecord (4.2.0) - activemodel (= 4.2.0) - activesupport (= 4.2.0) - arel (~> 6.0) + activerecord (4.1.9) + activemodel (= 4.1.9) + activesupport (= 4.1.9) + arel (~> 5.0.0) activerecord-jdbc-adapter (1.3.14) activerecord (>= 2.2) activerecord-jdbcpostgresql-adapter (1.3.14) activerecord-jdbc-adapter (~> 1.3.14) jdbc-postgres (>= 9.1) - activesupport (4.2.0) - i18n (~> 0.7) + activesupport (4.1.9) + i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) + thread_safe (~> 0.1) tzinfo (~> 1.1) archive-tar-minitar (0.5.2) - arel (6.0.0) + arel (5.0.1.20140414130214) ast (2.0.0) astrolabe (1.3.0) parser (>= 2.2.0.pre.3, < 3.0) @@ -100,7 +91,7 @@ GEM codeclimate-test-reporter (0.4.7) simplecov (>= 0.7.1, < 1.0.0) coderay (1.1.0) - coffee-rails (4.1.0) + coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) coffee-script (2.3.0) @@ -136,8 +127,6 @@ GEM ffi (1.9.6) ffi (1.9.6-java) forgery (0.6.0) - globalid (0.3.3) - activesupport (>= 4.1.0) highline (1.7.1) hike (1.2.3) i18n (0.7.0) @@ -148,9 +137,8 @@ GEM activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) jdbc-postgres (9.4.1200) - jquery-rails (4.0.3) - rails-dom-testing (~> 1.0) - railties (>= 4.2.0) + jquery-rails (3.1.2) + railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) jquery-turbolinks (2.1.0) railties (>= 3.1.0) @@ -159,8 +147,6 @@ GEM json (1.8.2-java) jwt (1.3.0) kramdown (1.6.0) - loofah (2.0.1) - nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) method_source (0.8.2) @@ -206,34 +192,25 @@ GEM rack (>= 1.1, < 2.0) pundit (0.3.0) activesupport (>= 3.0.0) - rack (1.6.0) + rack (1.5.2) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.0) - actionmailer (= 4.2.0) - actionpack (= 4.2.0) - actionview (= 4.2.0) - activejob (= 4.2.0) - activemodel (= 4.2.0) - activerecord (= 4.2.0) - activesupport (= 4.2.0) + rails (4.1.9) + actionmailer (= 4.1.9) + actionpack (= 4.1.9) + actionview (= 4.1.9) + activemodel (= 4.1.9) + activerecord (= 4.1.9) + activesupport (= 4.1.9) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.0) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.5) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.1) - loofah (~> 2.0) + railties (= 4.1.9) + sprockets-rails (~> 2.0) rails-i18n (4.0.4) i18n (~> 0.6) railties (~> 4.0) - railties (4.2.0) - actionpack (= 4.2.0) - activesupport (= 4.2.0) + railties (4.1.9) + actionpack (= 4.1.9) + activesupport (= 4.1.9) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.0.0) @@ -245,6 +222,7 @@ GEM i18n polyamorous (~> 1.1) rdoc (4.2.0) + json (~> 1.4) ref (1.0.5) rspec (3.1.0) rspec-core (~> 3.1.0) @@ -280,13 +258,12 @@ GEM json (~> 1.8) structured_warnings (~> 0.1) rubyzip (1.1.7) - sass (3.4.13) - sass-rails (5.0.1) + sass (3.2.19) + sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (~> 1.1) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) + sprockets-rails (~> 2.0) sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) @@ -367,7 +344,7 @@ DEPENDENCIES capybara carrierwave codeclimate-test-reporter - coffee-rails (~> 4.1.0) + coffee-rails (~> 4.0.0) concurrent-ruby concurrent-ruby-ext database_cleaner @@ -385,7 +362,7 @@ DEPENDENCIES pry puma pundit - rails (~> 4.2.0) + rails (~> 4.1.2) rails-i18n (~> 4.0.0) rake ransack @@ -394,7 +371,7 @@ DEPENDENCIES rubocop rubocop-rspec rubytree - sass-rails (~> 5.0) + sass-rails (~> 4.0.3) sdoc (~> 0.4.0) selenium-webdriver simplecov diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 357d6710..5fb887e0 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -25,7 +25,7 @@ class Exercise < ActiveRecord::Base def average_score if submissions.exists?(cause: 'submit') - maximum_scores_query = submissions.select('MAX(score) AS maximum_score').where(cause: 'submit').group(:user_id).to_sql + maximum_scores_query = submissions.select('MAX(score) AS maximum_score').where(cause: 'submit').group(:user_id).to_sql.sub('$1', id.to_s) self.class.connection.execute("SELECT AVG(maximum_score) AS average_score FROM (#{maximum_scores_query}) AS maximum_scores").first['average_score'].to_f end end diff --git a/bin/rails b/bin/rails index 4d608ede..728cd85a 100755 --- a/bin/rails +++ b/bin/rails @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 8017a027..17240489 100755 --- a/bin/rake +++ b/bin/rake @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup deleted file mode 100755 index acdb2c13..00000000 --- a/bin/setup +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -require 'pathname' - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -Dir.chdir APP_ROOT do - # This script is a starting point to setup your application. - # Add necessary setup steps to this file: - - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install" - - # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" - # end - - puts "\n== Preparing database ==" - system "bin/rake db:setup" - - puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" - - puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" -end diff --git a/bin/spring b/bin/spring index e0918249..253ec37c 100755 --- a/bin/spring +++ b/bin/spring @@ -1,14 +1,17 @@ #!/usr/bin/env ruby -# This file loads spring without using Bundler, in order to be fast. -# It gets overwritten when you run the `spring binstub` command. +# This file loads spring without using Bundler, in order to be fast +# It gets overwritten when you run the `spring binstub` command unless defined?(Spring) require "rubygems" require "bundler" - if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m) - Gem.paths = { "GEM_PATH" => Bundler.bundle_path.to_s } + if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) + ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) + ENV["GEM_HOME"] = "" + Gem.paths = ENV + gem "spring", match[1] require "spring/binstub" end diff --git a/config.ru b/config.ru index bd83b254..5bc2a619 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 ::File.expand_path('../config/environment', __FILE__) run Rails.application diff --git a/config/application.rb b/config/application.rb index 325455bc..91dec8cf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,6 +1,13 @@ require File.expand_path('../boot', __FILE__) -require 'rails/all' +# Pick the frameworks you want: +require "active_model/railtie" +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "sprockets/railtie" +# require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -21,9 +28,6 @@ module CodeOcean # config.i18n.default_locale = :de config.i18n.available_locales = [:de, :en] - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true - config.autoload_paths << Rails.root.join('lib') config.eager_load_paths << Rails.root.join('lib') end diff --git a/config/boot.rb b/config/boot.rb index 6b750f00..5e5f0c1f 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ +# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environments/development.rb b/config/environments/development.rb index 89ac1623..9ceddb73 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,6 +13,8 @@ Rails.application.configure do config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.action_mailer.perform_deliveries = true + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -22,15 +24,6 @@ Rails.application.configure do # 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 - - # 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. - config.assets.digest = true - # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e4..47d3553b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -16,13 +16,11 @@ Rails.application.configure do # 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. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. # config.action_dispatch.rack_cache = 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? + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -31,22 +29,21 @@ Rails.application.configure do # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = 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. + # Generate digests for assets URLs. config.assets.digest = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # Set to :debug to see everything in the log. + config.log_level = :info # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] @@ -58,7 +55,11 @@ Rails.application.configure do # 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' + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) # 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. @@ -71,6 +72,9 @@ Rails.application.configure do # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08b..053f5b66 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,8 +12,8 @@ Rails.application.configure do # 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 + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true config.static_cache_control = 'public, max-age=3600' # Show full error reports and disable caching. @@ -31,9 +31,6 @@ Rails.application.configure do # 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/assets.rb b/config/initializers/assets.rb deleted file mode 100644 index 01ef3e66..00000000 --- a/config/initializers/assets.rb +++ /dev/null @@ -1,11 +0,0 @@ -# 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' - -# Add additional assets to the asset load path -# Rails.application.config.assets.paths << Emoji.images_path - -# 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 ) diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index b9aa7526..1e5f1e1d 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_CodeOcean_session' +Rails.application.config.session_store :cookie_store, key: '_hands-on-programming_session' diff --git a/config/routes.rb b/config/routes.rb index 76f2325a..9ba066ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,20 +1,20 @@ FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP) Rails.application.routes.draw do - root 'application#welcome' + root to: 'application#welcome' namespace :admin do - get 'dashboard' => 'dashboard#show' + get 'dashboard', to: 'dashboard#show' end - get '/help' => 'application#help' + get '/help', to: 'application#help' resources :consumers resources :execution_environments do member do get :shell - post 'shell' => :execute_command, as: :execute_command + post 'shell', as: :execute_command, to: :execute_command end resources :errors, only: [:create, :index, :show] @@ -40,29 +40,29 @@ Rails.application.routes.draw do resources :internal_users do member do - match 'activate' => 'internal_users#activate', via: [:get, :patch, :put] - match 'reset_password' => 'internal_users#reset_password', via: [:get, :patch, :put] + match 'activate', to: 'internal_users#activate', via: [:get, :patch, :put] + match 'reset_password', to: 'internal_users#reset_password', via: [:get, :patch, :put] end end - match '/forgot_password' => 'internal_users#forgot_password', as: 'forgot_password', via: [:get, :post] + match '/forgot_password', as: 'forgot_password', to: 'internal_users#forgot_password', via: [:get, :post] resources :sessions, only: [:create, :destroy, :new] - post '/lti/launch' => 'sessions#create_through_lti', as: 'lti_launch' - get '/lti/return' => 'sessions#destroy_through_lti', as: 'lti_return' - get '/sign_in' => 'sessions#new', as: 'sign_in' - delete '/sign_out' => 'sessions#destroy', as: 'sign_out' + post '/lti/launch', as: 'lti_launch', to: 'sessions#create_through_lti' + get '/lti/return', as: 'lti_return', to: 'sessions#destroy_through_lti' + get '/sign_in', as: 'sign_in', to: 'sessions#new' + delete '/sign_out', as: 'sign_out', to: 'sessions#destroy' resources :submissions, only: [:create, :index, :show] do member do - get 'download/:filename' => :download_file, as: :download, constraints: {filename: FILENAME_REGEXP} - get 'render/:filename' => :render_file, as: :render, constraints: {filename: FILENAME_REGEXP} - get 'run/:filename' => :run, as: :run, constraints: {filename: FILENAME_REGEXP} + get 'download/:filename', as: :download, constraints: {filename: FILENAME_REGEXP}, to: :download_file + get 'render/:filename', as: :render, constraints: {filename: FILENAME_REGEXP}, to: :render_file + get 'run/:filename', as: :run, constraints: {filename: FILENAME_REGEXP}, to: :run get :score get :statistics post :stop - get 'test/:filename' => :test, as: :test, constraints: {filename: FILENAME_REGEXP} + get 'test/:filename', as: :test, constraints: {filename: FILENAME_REGEXP}, to: :test end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 0a3e3d83..695eb74c 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -40,6 +40,8 @@ describe ApplicationController do let(:locale) { :de } context 'when specifying a locale' do + before(:each) { allow(session).to receive(:[]=).at_least(:once) } + context "using the 'custom_locale' parameter" do it 'overwrites the session' do expect(session).to receive(:[]=).with(:locale, locale.to_s)