diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rails', '~>4.0.0' +gem 'rails', '~>4.1.0' gem 'activerecord-session_store' gem 'select2-rails' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,38 +10,40 @@ remote: https://rubygems.org/ specs: ace-rails-ap (4.1.1) - actionmailer (4.0.13) - actionpack (= 4.0.13) + actionmailer (4.1.16) + actionpack (= 4.1.16) + actionview (= 4.1.16) mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) + actionpack (4.1.16) + actionview (= 4.1.16) + activesupport (= 4.1.16) rack (~> 1.5.2) rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) + actionview (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + activerecord (4.1.16) + activemodel (= 4.1.16) + activesupport (= 4.1.16) + arel (~> 5.0.0) activerecord-session_store (1.0.0) actionpack (>= 4.0, < 5.1) activerecord (>= 4.0, < 5.1) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0, < 5.1) - activesupport (4.0.13) + activesupport (4.1.16) i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) - autoprefixer-rails (6.5.2) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) + autoprefixer-rails (6.5.3.1) execjs best_in_place (3.0.3) actionpack (>= 3.2) @@ -50,14 +52,14 @@ sass (~> 3.2) bootstrap-switch-rails (3.3.3) bootstrap-toggle-rails (2.2.1.0) - builder (3.1.4) + builder (3.2.2) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) + coffee-script-source (1.11.1) concurrent-ruby (1.0.2) diff-lcs (1.2.5) dynamic_form (1.1.4) @@ -82,7 +84,7 @@ jquery-rails (3.1.4) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - jquery-tablesorter (1.22.7) + jquery-tablesorter (1.23.1) railties (>= 3.2, < 6) jquery-timepicker-addon-rails (1.4.1) railties (>= 3.1) @@ -93,41 +95,44 @@ jquery-rails jquery-ui-rails (= 4.0.3) railties (>= 3.1.0) + json (1.8.3) mail (2.6.4) mime-types (>= 1.16, < 4) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.1.0) - minitest (4.7.5) + minitest (5.10.1) momentjs-rails (2.15.1) railties (>= 3.1) multi_json (1.12.1) mysql2 (0.3.21) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - power_assert (0.3.1) + power_assert (0.4.1) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) + rails (4.1.16) + actionmailer (= 4.1.16) + actionpack (= 4.1.16) + actionview (= 4.1.16) + activemodel (= 4.1.16) + activerecord (= 4.1.16) + activesupport (= 4.1.16) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) + railties (= 4.1.16) sprockets-rails (~> 2.0) rails_bootstrap_sortable (2.0.1) momentjs-rails (>= 2.8.3) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) + railties (4.1.16) + actionpack (= 4.1.16) + activesupport (= 4.1.16) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.3.0) + rake (12.0.0) rdiscount (2.2.0.1) - rouge (2.0.6) + rouge (2.0.7) rspec-collection_matchers (1.1.2) rspec-expectations (>= 2.99.0.beta1) rspec-core (2.99.2) @@ -162,13 +167,14 @@ actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - test-unit (3.2.2) + test-unit (3.2.3) power_assert - thor (0.19.1) + thor (0.19.4) thread_safe (0.3.5) tilt (2.0.5) - tzinfo (0.3.52) - uglifier (3.0.3) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (3.0.4) execjs (>= 0.3.0, < 3) will_paginate (3.0.12) @@ -196,7 +202,7 @@ mail momentjs-rails mysql2 (~> 0.3.0) - rails (~> 4.0.0) + rails (~> 4.1.0) rails_bootstrap_sortable rdiscount rouge diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -7,8 +7,7 @@ # GET /announcements # GET /announcements.xml def index - @announcements = Announcement.find(:all, - :order => "created_at DESC") + @announcements = Announcement.order(created_at: :desc) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -20,7 +20,7 @@ def admin_authorization return false unless authenticate - user = User.find(session[:user_id], :include => ['roles']) + user = User.includes(:roles).find(session[:user_id]) unless user.admin? unauthorized_redirect return false diff --git a/app/controllers/configurations_controller.rb b/app/controllers/configurations_controller.rb --- a/app/controllers/configurations_controller.rb +++ b/app/controllers/configurations_controller.rb @@ -5,8 +5,7 @@ def index - @configurations = GraderConfiguration.find(:all, - :order => '`key`') + @configurations = GraderConfiguration.order(:key) @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort end diff --git a/app/controllers/contest_management_controller.rb b/app/controllers/contest_management_controller.rb --- a/app/controllers/contest_management_controller.rb +++ b/app/controllers/contest_management_controller.rb @@ -11,9 +11,9 @@ redirect_to :action => 'index' and return end - @users = User.find(:all) + @users = User.all @start_times = {} - UserContestStat.find(:all).each do |stat| + UserContestStat.all.each do |stat| @start_times[stat.user_id] = stat.started_at end end diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -35,10 +35,8 @@ @terminated_processes = GraderProcess.find_terminated_graders - @last_task = Task.find(:first, - :order => 'created_at DESC') - @last_test_request = TestRequest.find(:first, - :order => 'created_at DESC') + @last_task = Task.last + @last_test_request = TestRequest.last @submission = Submission.order("id desc").limit(20) @backlog_submission = Submission.where('graded_at is null') end @@ -57,7 +55,7 @@ end def clear_all - GraderProcess.find(:all).each do |p| + GraderProcess.all.each do |p| p.destroy end redirect_to :action => 'list' diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -45,7 +45,7 @@ # @hidelogin = true # end - @announcements = Announcement.find_for_frontpage + @announcements = Announcement.frontpage render :action => 'login', :layout => 'empty' end @@ -217,9 +217,9 @@ def prepare_announcements(recent=nil) if GraderConfiguration.show_tasks_to?(@user) - @announcements = Announcement.find_published(true) + @announcements = Announcement.published(true) else - @announcements = Announcement.find_published + @announcements = Announcement.published end if recent!=nil recent_id = recent.to_i diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -7,7 +7,7 @@ in_place_edit_for :problem, :full_score def index - @problems = Problem.find(:all, :order => 'date_added DESC') + @problems = Problem.order(date_added: :desc) end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) @@ -135,8 +135,7 @@ end def turn_all_off - Problem.find(:all, - :conditions => "available = 1").each do |problem| + Problem.available.all.each do |problem| problem.available = false problem.save end @@ -144,8 +143,7 @@ end def turn_all_on - Problem.find(:all, - :conditions => "available = 0").each do |problem| + Problem.where.not(available: true).each do |problem| problem.available = true problem.save end @@ -176,7 +174,7 @@ end def manage - @problems = Problem.find(:all, :order => 'date_added DESC') + @problems = Problem.order(date_added: :desc) end def do_manage diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -9,18 +9,14 @@ before_filter(only: [:problem_hof]) { |c| return false unless authenticate - if GraderConfiguration["right.user_view_submission"] - return true; - end - - admin_authorization + admin_authorization unless GraderConfiguration["right.user_view_submission"] } def max_score end def current_score - @problems = Problem.find_available_problems + @problems = Problem.available_problems @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) @scorearray = calculate_max_score(@problems, @users,0,0,true) @@ -46,7 +42,7 @@ #users @users = if params[:user] == "all" then - User.find(:all, :include => [:contests, :contest_stat]) + User.includes(:contests).includes(:contest_stat) else User.includes(:contests).includes(:contest_stat).where(enabled: true) end @@ -73,9 +69,9 @@ if params[:commit] == 'download csv' @problems = Problem.all else - @problems = Problem.find_available_problems + @problems = Problem.available_problems end - @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) + @users = User.includes(:contests, :contest_stat).where(enabled: true) @scorearray = Array.new @users.each do |u| ustat = Array.new diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -4,7 +4,7 @@ def login # Site administrator login - @countries = Country.find(:all, :include => :sites) + @countries = Country.includes(:sites).all @country_select = @countries.collect { |c| [c.name, c.id] } @country_select_with_all = [['Any',0]] diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -5,7 +5,7 @@ # GET /sites # GET /sites.xml def index - @sites = Site.find(:all, :order => 'country_id') + @sites = Site.order(:country_id) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -29,7 +29,7 @@ end def active - sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) + sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) @users = [] sessions.each do |session| if session.data[:user_id] @@ -135,9 +135,9 @@ if params[:commit] == 'download csv' @problems = Problem.all else - @problems = Problem.find_available_problems + @problems = Problem.available_problems end - @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) + @users = User.includes(:contests, :contest_stat).where(enabled: true) @scorearray = Array.new @users.each do |u| ustat = Array.new @@ -164,9 +164,9 @@ if params[:commit] == 'download csv' @problems = Problem.all else - @problems = Problem.find_available_problems + @problems = Problem.available_problems end - @users = User.find(:all, :include => [:contests, :contest_stat]) + @users = User.includes(:contests).includes(:contest_stat).all @scorearray = Array.new #set up range from param since_id = params.fetch(:since_id, 0).to_i @@ -201,7 +201,7 @@ end def random_all_passwords - users = User.find(:all) + users = User.all @prefix = params[:prefix] || '' @non_admin_users = User.find_non_admin_with_prefix(@prefix) @changed = false @@ -324,7 +324,7 @@ # admin management def admin - @admins = User.find(:all).find_all {|user| user.admin? } + @admins = User.all.find_all {|user| user.admin? } end def grant_admin diff --git a/app/models/announcement.rb b/app/models/announcement.rb --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -1,21 +1,15 @@ class Announcement < ActiveRecord::Base - def self.find_published(contest_started=false) + def self.published(contest_started=false) if contest_started - Announcement.find(:all, - :conditions => "(published = 1) AND (frontpage = 0)", - :order => "created_at DESC") + where(published: true).where(frontpage: false).order(created_at: :desc) else - Announcement.find(:all, - :conditions => "(published = 1) AND (frontpage = 0) AND (contest_only = 0)", - :order => "created_at DESC") + where(published: true).where(frontpage: false).where(contest_only: false).order(created_at: :desc) end end - def self.find_for_frontpage - Announcement.find(:all, - :conditions => "(published = 1) AND (frontpage = 1)", - :order => "created_at DESC") + def self.frontpage + where(published: 1).where(frontpage: 1).order(created_at: :desc) end end diff --git a/app/models/grader_configuration.rb b/app/models/grader_configuration.rb --- a/app/models/grader_configuration.rb +++ b/app/models/grader_configuration.rb @@ -152,7 +152,7 @@ def self.read_config GraderConfiguration.config_cache = {} - GraderConfiguration.find(:all).each do |conf| + GraderConfiguration.all.each do |conf| key = conf.key val = conf.value GraderConfiguration.config_cache[key] = GraderConfiguration.convert_type(val,conf.value_type) diff --git a/app/models/grader_process.rb b/app/models/grader_process.rb --- a/app/models/grader_process.rb +++ b/app/models/grader_process.rb @@ -1,11 +1,7 @@ class GraderProcess < ActiveRecord::Base def self.find_by_host_and_pid(host,pid) - return GraderProcess.find(:first, - :conditions => { - :host => host, - :pid => pid - }) + return GraderProcess.where(host:host).where(pid: pid).first end def self.register(host,pid,mode) @@ -27,20 +23,15 @@ end def self.find_running_graders - GraderProcess.find(:all, - :conditions => {:terminated => 0}) + where(terminated: false) end def self.find_terminated_graders - GraderProcess.find(:all, - :conditions => "`terminated`") + where(terminated: true) end def self.find_stalled_process - GraderProcess.find(:all, - :conditions => ["(`terminated` = 0) AND active AND " + - "(updated_at < ?)", - Time.now.gmtime - GraderProcess.stalled_time]) + where(terminated: false).where(active: true).where("updated_at < ?",Time.now.gmtime - GraderProcess.stalled_time) end def report_active(task=nil) diff --git a/app/models/language.rb b/app/models/language.rb --- a/app/models/language.rb +++ b/app/models/language.rb @@ -4,7 +4,7 @@ def self.cache_ext_hash @@languages_by_ext = {} - Language.find(:all).each do |language| + Language.all.each do |language| language.common_ext.split(',').each do |ext| @@languages_by_ext[ext] = language end diff --git a/app/models/message.rb b/app/models/message.rb --- a/app/models/message.rb +++ b/app/models/message.rb @@ -23,10 +23,8 @@ end def self.find_all_system_unreplied_messages - self.find(:all, - :conditions => 'ISNULL(receiver_id) ' + - 'AND (ISNULL(replied) OR replied=0)', - :order => 'created_at') + where('ISNULL(receiver_id) ' + + 'AND (ISNULL(replied) OR replied=0)') end def self.build_replying_message_hierarchy(*args) diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -9,13 +9,14 @@ validates_format_of :name, :with => /\A\w+\z/ validates_presence_of :full_name - scope :available, :conditions => {:available => true} + scope :available, -> { where(available: true) } DEFAULT_TIME_LIMIT = 1 DEFAULT_MEMORY_LIMIT = 32 - def self.find_available_problems - Problem.available.all(:order => "date_added DESC, name ASC") + def self.available_problems + available.order(date_added: :desc).order(:name) + #Problem.available.all(:order => "date_added DESC, name ASC") end def self.create_from_import_form_params(params, old_problem=nil) diff --git a/app/models/submission.rb b/app/models/submission.rb --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -16,11 +16,7 @@ before_save :assign_latest_number_if_new_recond def self.find_last_by_user_and_problem(user_id, problem_id) - last_sub = find(:first, - :conditions => {:user_id => user_id, - :problem_id => problem_id}, - :order => 'number DESC') - return last_sub + where("user_id = ? AND problem_id = ?",user_id,problem_id).last end def self.find_all_last_by_problem(problem_id) @@ -43,7 +39,7 @@ def self.find_last_for_all_available_problems(user_id) submissions = Array.new - problems = Problem.find_available_problems + problems = Problem.available_problems problems.each do |problem| sub = Submission.find_last_by_user_and_problem(user_id, problem.id) submissions << sub if sub!=nil @@ -52,20 +48,11 @@ end def self.find_by_user_problem_number(user_id, problem_id, number) - Submission.find(:first, - :conditions => { - :user_id => user_id, - :problem_id => problem_id, - :number => number - }) + where("user_id = ? AND problem_id = ? AND number = ?",user_id,problem_id,number).first end def self.find_all_by_user_problem(user_id, problem_id) - Submission.find(:all, - :conditions => { - :user_id => user_id, - :problem_id => problem_id, - }) + where("user_id = ? AND problem_id = ?",user_id,problem_id) end def download_filename diff --git a/app/models/task.rb b/app/models/task.rb --- a/app/models/task.rb +++ b/app/models/task.rb @@ -48,10 +48,7 @@ task = nil begin Task.transaction do - task = Task.find(:first, - :order => "created_at", - :conditions => {:status=> Task::STATUS_INQUEUE}, - :lock => true) + task = Task.where(status: Task::STATUS_INQUEUE).where(lock: true).first if task!=nil task.status = status task.save! diff --git a/app/models/test_request.rb b/app/models/test_request.rb --- a/app/models/test_request.rb +++ b/app/models/test_request.rb @@ -37,9 +37,7 @@ # since there will be only one grader grading TestRequest # we do not need locking (hopefully) - test_request = TestRequest.find(:first, - :order => "created_at", - :conditions => {:status=> Task::STATUS_INQUEUE}) + test_request = TestRequest.where(status: Task::STATUS_INQUEUE).first if test_request!=nil test_request.status = status test_request.save! diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -175,14 +175,14 @@ end def self.find_non_admin_with_prefix(prefix='') - users = User.find(:all) + users = User.all return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } end # Contest information def self.find_users_with_no_contest() - users = User.find(:all) + users = User.all return users.find_all { |u| u.contests.length == 0 } end @@ -281,7 +281,7 @@ def available_problems if not GraderConfiguration.multicontests? - return Problem.find_available_problems + return Problem.available_problems else contest_problems = [] pin = {} diff --git a/app/views/report/_score_table.html.haml b/app/views/report/_score_table.html.haml --- a/app/views/report/_score_table.html.haml +++ b/app/views/report/_score_table.html.haml @@ -17,7 +17,7 @@ - total,num_passed = 0,0 - sc.each_index do |i| - if i == 0 - %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i] + %td= link_to sc[i].login, stat_user_path(sc[i]) %td= sc[i].full_name / %td= sc[i].activated / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no' diff --git a/test/concurrent/task_test_setup.rb b/test/concurrent/task_test_setup.rb --- a/test/concurrent/task_test_setup.rb +++ b/test/concurrent/task_test_setup.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") def clear_all_tasks - Task.find(:all).each do |task| + Task.all.each do |task| task.destroy end end diff --git a/test/concurrent/task_test_teardown.rb b/test/concurrent/task_test_teardown.rb --- a/test/concurrent/task_test_teardown.rb +++ b/test/concurrent/task_test_teardown.rb @@ -2,13 +2,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") def clear_all_tasks - Task.find(:all).each do |task| + Task.all.each do |task| task.destroy end end -puts Task.find(:all, - :conditions => {:status => Task::STATUS_COMPLETE}).length +puts Task.where(status: Task::STATUS_COMPLETE).length clear_all_tasks