From dfab0425e384b95069697716ec96f47d362c8a1e Mon Sep 17 00:00:00 2001 From: Jacob Fugal Date: Thu, 3 Oct 2013 17:17:45 -0600 Subject: [PATCH] use CANVAS_RAILS2 for conditionals rather than CANVAS_RAILS3 or Rails.version this is to be consistent, and to reinforce that any "special" branches are for rails 2.3 backwards compatibility while trying to target rails 3, rather than rails 3 "forwards compatibility". Change-Id: I4494b65e3f71108a43d09032c1569c478646a828 Reviewed-on: https://gerrit.instructure.com/24998 Tested-by: Jenkins Reviewed-by: Brian Palmer Product-Review: Jacob Fugal QA-Review: Jacob Fugal --- Gemfile | 38 +++++++++---------- Rakefile | 12 +++--- app/controllers/application_controller.rb | 4 +- app/controllers/users_controller.rb | 2 +- app/models/alert.rb | 6 +-- app/models/assignment_override.rb | 2 +- app/models/enrollment.rb | 2 +- app/models/error_report.rb | 6 +-- app/models/notification_policy.rb | 2 +- app/models/sis_batch.rb | 4 +- app/models/stream_item.rb | 4 +- app/models/user.rb | 8 ++-- config/boot.rb | 2 +- config/canvas_rails3.rb | 1 + config/environment.rb | 24 ++++++------ config/environments/development.rb | 4 +- config/environments/production.rb | 8 ++-- config/environments/test.rb | 4 +- config/initializers/active_record.rb | 2 +- config/initializers/authlogic_mods.rb | 6 ++- config/initializers/i18n.rb | 4 +- config/initializers/new_rails_defaults.rb | 2 +- config/initializers/rails2.rb | 2 +- config/initializers/ruby_version_compat.rb | 2 +- config/initializers/session_store.rb | 2 +- config/shared_boot.rb | 12 +++--- ...le_open_registration_for_delegated_auth.rb | 2 +- lib/api_route_set.rb | 8 ++-- lib/authentication_methods.rb | 2 +- lib/canvas/migration/worker.rb | 2 +- .../fix_out_of_sync_outcome_alignments.rb | 8 ++-- lib/nil_store.rb | 2 +- lib/stubs/shard.rb | 2 +- spec/spec_helper.rb | 6 +-- .../lib/technoweenie/attachment_fu.rb | 6 +-- .../lib/delayed/backend/active_record.rb | 2 +- .../plugins/respondus_soap_endpoint/init.rb | 2 +- 37 files changed, 106 insertions(+), 101 deletions(-) diff --git a/Gemfile b/Gemfile index a3c0d0767dd..f6411fee76f 100644 --- a/Gemfile +++ b/Gemfile @@ -6,13 +6,7 @@ end require File.expand_path("../config/canvas_rails3", __FILE__) -if CANVAS_RAILS3 - # 3.0.20 is transitional, we will be on 3.2.x before support is complete - # that's also why some gems below have to be downgraded, 3.0.20 relies on old versions of some gems - # just to be clear, Canvas is NOT READY to run under Rails 3 in production - gem 'rails', '3.0.20' - gem 'authlogic', '3.2.0' -else +if CANVAS_RAILS2 # If you have a license to rails lts, you can create a vendor/plugins/*/RAILS_LTS yaml file # with the Gemfile `gem` command to use (pointing to the private repo with your username/password). # Otherwise, the free community version of rails lts will be used. @@ -23,22 +17,28 @@ else gem 'rails', :git => 'https://github.com/makandra/rails.git', :branch => '2-3-lts', :ref => 'e86daf8ff727d5efc0040c876ba00c9444a5d915' end gem 'authlogic', '2.1.3' +else + # 3.0.20 is transitional, we will be on 3.2.x before support is complete + # that's also why some gems below have to be downgraded, 3.0.20 relies on old versions of some gems + # just to be clear, Canvas is NOT READY to run under Rails 3 in production + gem 'rails', '3.0.20' + gem 'authlogic', '3.2.0' end gem "aws-sdk", '1.8.3.1' gem 'barby', '0.5.0' gem 'bcrypt-ruby', '3.0.1' gem 'builder', '2.1.2' -if !CANVAS_RAILS3 +if CANVAS_RAILS2 gem 'canvas_connect', '0.2' end gem 'daemons', '1.1.0' gem 'diff-lcs', '1.1.3', :require => 'diff/lcs' -if !CANVAS_RAILS3 +if CANVAS_RAILS2 gem 'encrypted_cookie_store-instructure', '1.0.4', :require => 'encrypted_cookie_store' end -gem 'erubis', CANVAS_RAILS3 ? '2.6.6' : '2.7.0' -if !CANVAS_RAILS3 +gem 'erubis', CANVAS_RAILS2 ? '2.7.0' : '2.6.6' +if CANVAS_RAILS2 gem 'fake_arel', '1.0.0' end gem 'fake_rails3_routes', '1.0.4' @@ -47,8 +47,8 @@ gem 'hairtrigger', '0.2.3' gem 'sass', '3.2.3' gem 'hashery', '1.3.0', :require => 'hashery/dictionary' gem 'highline', '1.6.1' -gem 'i18n', CANVAS_RAILS3 ? '0.5.0' : '0.6.0' -if !CANVAS_RAILS3 +gem 'i18n', CANVAS_RAILS2 ? '0.6.0' : '0.5.0' +if CANVAS_RAILS2 gem 'i18nema', '0.0.7' end gem 'icalendar', '1.1.5' @@ -57,7 +57,7 @@ gem 'json', '1.8.0' # native xml parsing, diigo gem 'libxml-ruby', '2.6.0', :require => 'xml/libxml' gem 'macaddr', '1.0.0' # macaddr 1.2.0 tries to require 'systemu' which isn't a dependency -gem 'mail', CANVAS_RAILS3 ? '2.2.19' : '2.5.3' +gem 'mail', CANVAS_RAILS2 ? '2.5.3' : '2.2.19' # using this forked gem until https://github.com/37signals/marginalia/pull/15 is in the source gem gem 'instructure-marginalia', '1.1.3', :require => false gem 'mime-types', '1.17.2', :require => 'mime/types' @@ -68,13 +68,13 @@ gem 'netaddr', '1.5.0' gem 'nokogiri', '1.5.6' # oauth gem, with rails3 fixes rolled in gem 'oauth-instructure', '0.4.9', :require => 'oauth' -gem 'rack', CANVAS_RAILS3 ? '1.2.5' : '1.1.3' +gem 'rack', CANVAS_RAILS2 ? '1.1.3' : '1.2.5' gem 'rake', '10.1.0' gem 'rdoc', '3.12' gem 'ratom-instructure', '0.6.9', :require => "atom" # custom gem until necessary changes are merged into mainstream gem 'rdiscount', '1.6.8' gem 'ritex', '1.0.1' -if CANVAS_RAILS3 +unless CANVAS_RAILS2 gem 'routing_concerns', '0.1.0' end gem 'rotp', '1.4.1' @@ -121,11 +121,11 @@ group :test do gem 'mocha', :git => 'git://github.com/ccutrer/mocha.git', :require => false gem 'parallelized_specs', '0.4.64' gem 'thin', '1.5.1' - if CANVAS_RAILS3 - gem 'rspec-rails', '2.13.0' - else + if CANVAS_RAILS2 gem 'rspec', '1.3.2' gem 'rspec-rails', '1.3.4' + else + gem 'rspec-rails', '2.13.0' end gem 'selenium-webdriver', '2.35.0' gem 'webrat', '0.7.3' diff --git a/Rakefile b/Rakefile index 323626e53dd..9fece1ffed5 100644 --- a/Rakefile +++ b/Rakefile @@ -3,19 +3,19 @@ require File.expand_path("../config/canvas_rails3", __FILE__) -if CANVAS_RAILS3 - require File.expand_path('../config/application', __FILE__) -else +if CANVAS_RAILS2 require File.expand_path('../config/boot', __FILE__) +else + require File.expand_path('../config/application', __FILE__) end require 'rake' require 'rake/testtask' require 'rdoc/task' -if CANVAS_RAILS3 - CanvasRails::Application.load_tasks -else +if CANVAS_RAILS2 require 'tasks/rails' begin; require 'parallelized_specs/tasks'; rescue LoadError; end +else + CanvasRails::Application.load_tasks end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ce993d01c94..6112e1e126e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -889,7 +889,7 @@ class ApplicationController < ActionController::Base end end - if Rails.version < "3.0" + if CANVAS_RAILS2 rescue_responses['AuthenticationMethods::AccessTokenError'] = 401 else ActionDispatch::ShowExceptions.rescue_responses['AuthenticationMethods::AccessTokenError'] = 401 @@ -1546,7 +1546,7 @@ class ApplicationController < ActionController::Base data end - unless CANVAS_RAILS3 + if CANVAS_RAILS2 filter_parameter_logging *LoggingFilter.filtered_parameters end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8de1f447322..09d11547367 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1517,7 +1517,7 @@ class UsersController < ApplicationController joins('INNER JOIN conversation_participants ON conversation_participants.conversation_id=conversation_messages.conversation_id'). where('conversation_messages.author_id = ? AND conversation_participants.user_id IN (?) AND NOT conversation_messages.generated', teacher, ids) # fake_arel can't pass an array in the group by through the scope - last_message_dates = Rails.version < '3.0' ? + last_message_dates = CANVAS_RAILS2 ? scope.maximum(:created_at, :group => ['conversation_participants.user_id', 'conversation_messages.author_id']) : scope.group(['conversation_participants.user_id', 'conversation_messages.author_id']).maximum(:created_at) last_message_dates.each do |key, date| diff --git a/app/models/alert.rb b/app/models/alert.rb index 1406fa186ca..f9587c2a00b 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -141,7 +141,7 @@ class Alert < ActiveRecord::Base if criterion_types.include? 'Interaction' scope = SubmissionComment.for_context(course). where(:author_id => teacher_ids, :recipient_id => student_ids) - last_comment_dates = Rails.version < '3.0' ? + last_comment_dates = CANVAS_RAILS2 ? scope.maximum(:created_at, :group => [:recipient_id, :author_id]) : scope.group(:recipient_id, :author_id).maximum(:created_at) last_comment_dates.each do |key, date| @@ -151,7 +151,7 @@ class Alert < ActiveRecord::Base scope = ConversationMessage. joins('INNER JOIN conversation_participants ON conversation_participants.conversation_id=conversation_messages.conversation_id'). where(:conversation_messages => { :author_id => teacher_ids, :generated => false }, :conversation_participants => { :user_id => student_ids }) - last_message_dates = Rails.version < '3.0' ? + last_message_dates = CANVAS_RAILS2 ? scope.maximum(:created_at, :group => ['conversation_participants.user_id', 'conversation_messages.author_id']) : scope.group('conversation_participants.user_id', 'conversation_messages.author_id').maximum(:created_at) last_message_dates.each do |key, date| @@ -191,7 +191,7 @@ class Alert < ActiveRecord::Base if criterion_types.include?('UserNote') && include_user_notes scope = UserNote.active. where(:created_by_id => teacher_ids, :user_id => student_ids) - note_dates = Rails.version < '3.0' ? + note_dates = CANVAS_RAILS2 ? scope.maximum(:created_at, :group => [:user_id, :created_by_id]) : scope.group(:user_id, :created_by_id).maximum(:created_at) note_dates.each do |key, date| diff --git a/app/models/assignment_override.rb b/app/models/assignment_override.rb index 58bd829d8fc..a7f51be3d0f 100644 --- a/app/models/assignment_override.rb +++ b/app/models/assignment_override.rb @@ -274,7 +274,7 @@ class AssignmentOverride < ActiveRecord::Base # union the visible override subselects and join against them subselect = scopes.map{ |scope| scope.to_sql }.join(' UNION ') join_clause = "INNER JOIN (#{subselect}) AS visible_overrides ON visible_overrides.id=assignment_overrides.id" - if Rails.version < '3' + if CANVAS_RAILS2 { :joins => join_clause, :readonly => false } else joins(join_clause).readonly(false) diff --git a/app/models/enrollment.rb b/app/models/enrollment.rb index a554cd43ff1..0bff14af70c 100644 --- a/app/models/enrollment.rb +++ b/app/models/enrollment.rb @@ -881,7 +881,7 @@ class Enrollment < ActiveRecord::Base scope :currently_online, joins(:pseudonyms).where("pseudonyms.last_request_at>?", 5.minutes.ago) # this returns enrollments for creation_pending users; should always be used in conjunction with the invited scope scope :for_email, lambda { |email| - if Rails.version < '3.0' + if CANVAS_RAILS2 { :joins => { :user => :communication_channels }, :conditions => ["users.workflow_state='creation_pending' AND communication_channels.workflow_state='unconfirmed' AND path_type='email' AND LOWER(path)=LOWER(?)", email], diff --git a/app/models/error_report.rb b/app/models/error_report.rb index d6ccbf41f1b..c7016b5604c 100644 --- a/app/models/error_report.rb +++ b/app/models/error_report.rb @@ -30,10 +30,10 @@ class ErrorReport < ActiveRecord::Base # Define a custom callback for external notification of an error report. define_callbacks :on_send_to_external # Setup callback to default behavior. - if Rails.version >= "3.0" - set_callback :on_send_to_external, :send_via_email_or_post - else + if CANVAS_RAILS2 on_send_to_external :send_via_email_or_post + else + set_callback :on_send_to_external, :send_via_email_or_post end attr_accessible diff --git a/app/models/notification_policy.rb b/app/models/notification_policy.rb index 0957bfd36e3..315c985def8 100644 --- a/app/models/notification_policy.rb +++ b/app/models/notification_policy.rb @@ -115,7 +115,7 @@ class NotificationPolicy < ActiveRecord::Base notifications.each do |notification_id| # can't use hash syntax for the where cause Rails 2 will try to call communication_channels= for the # or_initialize portion - if Rails.version < '3.0' + if CANVAS_RAILS2 p = NotificationPolicy.includes(:communication_channel).where("communication_channels.user_id=?", user). find_or_initialize_by_communication_channel_id_and_notification_id(params[:channel_id], notification_id) else diff --git a/app/models/sis_batch.rb b/app/models/sis_batch.rb index 919b05f7f9c..55e9658d461 100644 --- a/app/models/sis_batch.rb +++ b/app/models/sis_batch.rb @@ -189,7 +189,7 @@ class SisBatch < ActiveRecord::Base if data[:supplied_batches].include?(:section) # delete sections who weren't in this batch, whose course was in the selected term scope = CourseSection.where("course_sections.workflow_state='active' AND course_sections.root_account_id=? AND course_sections.sis_batch_id IS NOT NULL AND course_sections.sis_batch_id<>?", self.account, self) - if Rails.version < '3.0' + if CANVAS_RAILS2 scope = scope.scoped(:joins => "INNER JOIN courses ON courses.id=COALESCE(nonxlist_course_id, course_id)", :select => "course_sections.*") else scope = scope.joins("INNER JOIN courses ON courses.id=COALESCE(nonxlist_course_id, course_id)").select("course_sections.*") @@ -203,7 +203,7 @@ class SisBatch < ActiveRecord::Base if data[:supplied_batches].include?(:enrollment) # delete enrollments for courses that weren't in this batch, in the selected term - if Rails.version < '3.0' + if CANVAS_RAILS2 scope = Enrollment.active.scoped(joins: :course, select: "enrollments.*") else scope = Enrollment.active.joins(:course).select("enrollments.*") diff --git a/app/models/stream_item.rb b/app/models/stream_item.rb index 07e606bdc63..a9ededfafe8 100644 --- a/app/models/stream_item.rb +++ b/app/models/stream_item.rb @@ -273,7 +273,7 @@ class StreamItem < ActiveRecord::Base # the teacher's comment even if it is farther down. # touch all the users to invalidate the cache - if Rails.version < '3.0' + if CANVAS_RAILS2 User.update_all({:updated_at => Time.now.utc}, {:id => user_ids}) else User.where(:id => user_ids).update_all(:updated_at => Time.now.utc) @@ -352,7 +352,7 @@ class StreamItem < ActiveRecord::Base unless user_ids.empty? # touch all the users to invalidate the cache - if Rails.version < '3.0' + if CANVAS_RAILS2 User.update_all({:updated_at => Time.now.utc}, {:id => user_ids.to_a}) else User.where(:id => user_ids.to_a).update_all(:updated_at => Time.now.utc) diff --git a/app/models/user.rb b/app/models/user.rb index 226fd68ff70..525844f1e5d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -566,7 +566,7 @@ class User < ActiveRecord::Base # for incremental, only update the old association if it is deeper than the new one # for non-incremental, update it if it changed if incremental && association[1] > depth || !incremental && association[1] != depth - if Rails.version < '3.0' + if CANVAS_RAILS2 UserAccountAssociation.update_all({ :depth => depth }, :id => association[0]) else UserAccountAssociation.where(:id => association[0]).update_all(:depth => depth) @@ -579,7 +579,7 @@ class User < ActiveRecord::Base end to_delete += current_associations.map { |k, v| v[0] } - if Rails.version < '3.0' + if CANVAS_RAILS2 UserAccountAssociation.delete_all(:id => to_delete) unless incremental || to_delete.empty? else UserAccountAssociation.where(:id => to_delete).delete_all unless incremental || to_delete.empty? @@ -2194,7 +2194,7 @@ class User < ActiveRecord::Base def shared_contexts(user) contexts = [] if info = load_messageable_user(user) - if Rails.version < '3.0' + if CANVAS_RAILS2 contexts += Course.find(:all, :conditions => {:id => info.common_courses.keys}) if info.common_courses.present? contexts += Group.find(:all, :conditions => {:id => info.common_groups.keys}) if info.common_groups.present? else @@ -2554,7 +2554,7 @@ class User < ActiveRecord::Base end def stamp_logout_time! - if Rails.version < '3.0' + if CANVAS_RAILS2 User.update_all({ :last_logged_out => Time.zone.now }, :id => self) else User.where(:id => self).update_all(:last_logged_out => Time.zone.now) diff --git a/config/boot.rb b/config/boot.rb index 7a1adbbd7b5..c0ce5361548 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -3,7 +3,7 @@ require File.expand_path("../canvas_rails3", __FILE__) -if CANVAS_RAILS3 +unless CANVAS_RAILS2 require 'rubygems' # Set up gems listed in the Gemfile. diff --git a/config/canvas_rails3.rb b/config/canvas_rails3.rb index 1f5452653b6..4ea5ff9da18 100644 --- a/config/canvas_rails3.rb +++ b/config/canvas_rails3.rb @@ -1,3 +1,4 @@ # You can enable the not-yet-complete Rails3 support by either defining a # CANVAS_RAILS3 env var, or create an empty RAILS3 file in the canvas RAILS_ROOT dir CANVAS_RAILS3 = !!ENV['CANVAS_RAILS3'] || File.exist?(File.expand_path("../../RAILS3", __FILE__)) +CANVAS_RAILS2 = !CANVAS_RAILS3 diff --git a/config/environment.rb b/config/environment.rb index 21ae4d7997b..1733466813f 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,6 +1,17 @@ require File.expand_path("../canvas_rails3", __FILE__) -if CANVAS_RAILS3 +if CANVAS_RAILS2 + def environment_configuration(config) + yield(config) + end + + # Bootstrap the Rails environment, frameworks, and default configuration + require File.expand_path('../boot', __FILE__) + + Rails::Initializer.run do |config| + eval(File.read(File.expand_path("../shared_boot.rb", __FILE__)), binding, "config/shared_boot.rb", 1) + end +else def environment_configuration(_config) CanvasRails::Application.configure do yield(config) @@ -12,15 +23,4 @@ if CANVAS_RAILS3 # Initialize the rails application CanvasRails::Application.initialize! -else - def environment_configuration(config) - yield(config) - end - - # Bootstrap the Rails environment, frameworks, and default configuration - require File.expand_path('../boot', __FILE__) - - Rails::Initializer.run do |config| - eval(File.read(File.expand_path("../shared_boot.rb", __FILE__)), binding, "config/shared_boot.rb", 1) - end end diff --git a/config/environments/development.rb b/config/environments/development.rb index db0c922f9b6..b22d253f785 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -10,7 +10,7 @@ environment_configuration(defined?(config) && config) do |config| config.whiny_nils = true # Show full error reports and disable caching - if Rails.version < "3.0" + if CANVAS_RAILS2 config.action_controller.consider_all_requests_local = true else config.consider_all_requests_local = true @@ -44,7 +44,7 @@ environment_configuration(defined?(config) && config) do |config| require "debugger" end - if Rails.version < "3.0" + if CANVAS_RAILS2 config.to_prepare do # Raise an exception on bad mass assignment. Helps us catch these bugs before # they hit. diff --git a/config/environments/production.rb b/config/environments/production.rb index 6f556ff505f..d5eb703bccb 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -6,11 +6,11 @@ environment_configuration(defined?(config) && config) do |config| config.cache_classes = true # Full error reports are disabled and caching is turned on - if CANVAS_RAILS3 - config.consider_all_requests_local = false - else + if CANVAS_RAILS2 config.action_controller.consider_all_requests_local = false config.action_view.cache_template_loading = true + else + config.consider_all_requests_local = false end config.action_controller.perform_caching = true @@ -27,7 +27,7 @@ environment_configuration(defined?(config) && config) do |config| # eval -local.rb if it exists Dir[File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") + "-*.rb"].each { |localfile| eval(File.new(localfile).read) } - if CANVAS_RAILS3 + unless CANVAS_RAILS2 # Specifies the header that your server uses for sending files config.action_dispatch.x_sendfile_header = "X-Sendfile" diff --git a/config/environments/test.rb b/config/environments/test.rb index ae1869e6a2b..3085e2a59a8 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,7 +12,7 @@ environment_configuration(defined?(config) && config) do |config| config.whiny_nils = false # Show full error reports and disable caching - if Rails.version < "3.0" + if CANVAS_RAILS2 config.action_controller.consider_all_requests_local = true else config.consider_all_requests_local = true @@ -41,7 +41,7 @@ environment_configuration(defined?(config) && config) do |config| require_dependency 'nil_store' config.cache_store = NilStore.new - if Rails.version < "3.0" + if CANVAS_RAILS2 # Raise an exception on bad mass assignment. Helps us catch these bugs before # they hit. Canvas.protected_attribute_error = :raise diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb index e73016f60e3..a1fb4353bd2 100644 --- a/config/initializers/active_record.rb +++ b/config/initializers/active_record.rb @@ -3,7 +3,7 @@ class ActiveRecord::Base extend ActiveSupport::Memoizable # used for a lot of the reporting queries - if Rails.version < "3.0" + if CANVAS_RAILS2 # this functionality is built into rails 3 class ProtectedAttributeAssigned < Exception; end def log_protected_attribute_removal_with_raise(*attributes) diff --git a/config/initializers/authlogic_mods.rb b/config/initializers/authlogic_mods.rb index fbf6d954a48..e285872ce8b 100644 --- a/config/initializers/authlogic_mods.rb +++ b/config/initializers/authlogic_mods.rb @@ -8,7 +8,9 @@ module Authlogic end end -callback_chain = Rails.version < "3.0" ? Authlogic::Session::Base.persist_callback_chain : Authlogic::Session::Base._persist_callbacks +callback_chain = CANVAS_RAILS2 ? + Authlogic::Session::Base.persist_callback_chain : + Authlogic::Session::Base._persist_callbacks # we need http basic auth to take precedence over the session cookie, for the api. cb = callback_chain.delete(:persist_by_http_auth) @@ -37,7 +39,7 @@ end # i18n fix so the error gets translated at run time, not initialization time. # this is fixed in new authlogic # https://github.com/jovoto-team/authlogic/commit/db01cf108985bd176e1885a3c85450020d4bcc45 -if Rails.version < '3.0' +if CANVAS_RAILS2 module Authlogic module ActsAsAuthentic module Login diff --git a/config/initializers/i18n.rb b/config/initializers/i18n.rb index 37d056a66d7..051ef299e65 100644 --- a/config/initializers/i18n.rb +++ b/config/initializers/i18n.rb @@ -4,7 +4,7 @@ skip_locale_loading = (Rails.env.development? || Rails.env.test? || $0 == 'irb') if skip_locale_loading I18n.load_path = I18n.load_path.grep(%r{/(locales|en)\.yml\z}) end -unless CANVAS_RAILS3 +if CANVAS_RAILS2 I18n.backend = I18nema::Backend.new I18nema::Backend.send(:include, I18n::Backend::Fallbacks) I18n.backend.init_translations @@ -165,7 +165,7 @@ I18n.class_eval do end ActionView::Base.class_eval do - if Rails.version < "3.0" + if CANVAS_RAILS2 def i18n_scope "#{template.base_path}.#{template.name.sub(/\A_/, '')}" end diff --git a/config/initializers/new_rails_defaults.rb b/config/initializers/new_rails_defaults.rb index 96bc7512915..6a1da01dd82 100644 --- a/config/initializers/new_rails_defaults.rb +++ b/config/initializers/new_rails_defaults.rb @@ -3,7 +3,7 @@ # These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. -if Rails.version < "3.0" +if CANVAS_RAILS2 if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true diff --git a/config/initializers/rails2.rb b/config/initializers/rails2.rb index 9be9d41ab59..855e3facaa8 100644 --- a/config/initializers/rails2.rb +++ b/config/initializers/rails2.rb @@ -1,4 +1,4 @@ -if Rails.version < '3' +if CANVAS_RAILS2 ActiveRecord::Base.class_eval do class << self diff --git a/config/initializers/ruby_version_compat.rb b/config/initializers/ruby_version_compat.rb index 6c9adef2371..6eeaf38b883 100644 --- a/config/initializers/ruby_version_compat.rb +++ b/config/initializers/ruby_version_compat.rb @@ -65,7 +65,7 @@ module TZInfo end end -if Rails.version < "3.0" +if CANVAS_RAILS2 require "active_support/core_ext/string/output_safety" class ERB diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 6af4fed8720..f414c632bab 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -36,7 +36,7 @@ when :redis_session_store config[:db] ||= config[:database] end -if Rails.version < "3.0" +if CANVAS_RAILS2 ActionController::Base.session = config ActionController::Base.session_store = session_store else diff --git a/config/shared_boot.rb b/config/shared_boot.rb index c91512b124d..41104b246e7 100644 --- a/config/shared_boot.rb +++ b/config/shared_boot.rb @@ -15,7 +15,7 @@ if ENV['RUNNING_AS_DAEMON'] == 'true' config.log_path = Rails.root+'log/delayed_job.log' end -log_config = File.exists?(Rails.root+"config/logging.yml") && YAML.load_file(Rails.root+"config/logging.yml")[CANVAS_RAILS3 ? Rails.env : RAILS_ENV] +log_config = File.exists?(Rails.root+"config/logging.yml") && YAML.load_file(Rails.root+"config/logging.yml")[CANVAS_RAILS2 ? RAILS_ENV : Rails.env] log_config = { 'logger' => 'rails', 'log_level' => 'debug' }.merge(log_config || {}) opts = {} require 'canvas_logger' @@ -35,12 +35,14 @@ when "syslog" config.logger = RAILS_DEFAULT_LOGGER = SyslogWrapper.new(ident, facilities, opts) config.logger.level = log_level else - log_path = Rails.version >= "3.0" ? config.paths.log.first : config.log_path + log_path = CANVAS_RAILS2 ? + config.log_path : + config.paths.log.first config.logger = RAILS_DEFAULT_LOGGER = CanvasLogger.new(log_path, log_level, opts) end # RailsLTS configuration (doesn't apply to rails 3) -if Rails.version < "3.0" +if CANVAS_RAILS2 config.rails_lts_options = { disable_xml_parsing: true, # this is also taken care of below, since it defaults to false in rails3 as well @@ -55,7 +57,7 @@ config.autoload_paths += %W(#{Rails.root}/app/middleware #{Rails.root}/app/observers #{Rails.root}/app/presenters) -if Rails.version < "3.0" +if CANVAS_RAILS2 # XXX: Rails3 needs SessionsTimeout config.middleware.insert_after(ActionController::Base.session_store, 'SessionsTimeout') config.middleware.insert_before('ActionController::ParamsParser', 'LoadAccount') @@ -79,7 +81,7 @@ end # this patch is perfectly placed to go in as soon as the PostgreSQLAdapter # is required for the first time, but before it's actually used # XXX: Rails3 -if Rails.version < "3.0" +if CANVAS_RAILS2 Rails::Initializer.class_eval do def initialize_database_with_postgresql_patches initialize_database_without_postgresql_patches diff --git a/db/migrate/20111121175219_disable_open_registration_for_delegated_auth.rb b/db/migrate/20111121175219_disable_open_registration_for_delegated_auth.rb index 90abd5d721c..3713e265ced 100644 --- a/db/migrate/20111121175219_disable_open_registration_for_delegated_auth.rb +++ b/db/migrate/20111121175219_disable_open_registration_for_delegated_auth.rb @@ -1,6 +1,6 @@ class DisableOpenRegistrationForDelegatedAuth < ActiveRecord::Migration def self.up - if Rails.version < '3' + if CANVAS_RAILS2 scope = Account.root_accounts.scoped(:joins => :account_authorization_configs, :readonly => false) else scope = Account.root_accounts.joins(:account_authorization_configs).readonly(false) diff --git a/lib/api_route_set.rb b/lib/api_route_set.rb index 8f00e412e8d..1bfd8085f41 100644 --- a/lib/api_route_set.rb +++ b/lib/api_route_set.rb @@ -126,16 +126,16 @@ class ApiRouteSet end opts[:constraints] ||= {} opts[:constraints][:format] = 'json' - if CANVAS_RAILS3 - opts[:format] = 'json' - mapper.send(method, "#{prefix}/#{path}(.json)", opts) - else + if CANVAS_RAILS2 # Our fake rails3 router isn't clever enough to translate (.json) to # something that rails 2 routing understands, so we help it out here for # api routes. opts[:format] = false mapper.send(method, "#{prefix}/#{path}.json", opts) mapper.send(method, "#{prefix}/#{path}", opts) + else + opts[:format] = 'json' + mapper.send(method, "#{prefix}/#{path}(.json)", opts) end end diff --git a/lib/authentication_methods.rb b/lib/authentication_methods.rb index aeb1a72b5c2..4140233c422 100644 --- a/lib/authentication_methods.rb +++ b/lib/authentication_methods.rb @@ -49,7 +49,7 @@ module AuthenticationMethods end def self.access_token(request, params_method = :params) - auth_header = CANVAS_RAILS3 ? request.authorization : ActionController::HttpAuthentication::Basic.authorization(request) + auth_header = CANVAS_RAILS2 ? ActionController::HttpAuthentication::Basic.authorization(request) : request.authorization if auth_header.present? && (header_parts = auth_header.split(' ', 2)) && header_parts[0] == 'Bearer' header_parts[1] else diff --git a/lib/canvas/migration/worker.rb b/lib/canvas/migration/worker.rb index 6ac4a37dfd5..261a3b1d5b1 100644 --- a/lib/canvas/migration/worker.rb +++ b/lib/canvas/migration/worker.rb @@ -18,7 +18,7 @@ require 'action_controller' # XXX: Rails3 doesn't have ActionController::TestUploadedFile, time to fix this -require 'action_controller/test_process.rb' if Rails.version < "3.0" +require 'action_controller/test_process.rb' if CANVAS_RAILS2 module Canvas::Migration::Worker def self.get_converter(settings) diff --git a/lib/data_fixup/fix_out_of_sync_outcome_alignments.rb b/lib/data_fixup/fix_out_of_sync_outcome_alignments.rb index 6fc7ff1a85b..688bfbfb5d6 100644 --- a/lib/data_fixup/fix_out_of_sync_outcome_alignments.rb +++ b/lib/data_fixup/fix_out_of_sync_outcome_alignments.rb @@ -1,7 +1,7 @@ module DataFixup::FixOutOfSyncOutcomeAlignments def self.run # Active alignments to deleted rubrics - if Rails.version < '3.0' + if CANVAS_RAILS2 scope = ContentTag.scoped(joins: "INNER JOIN rubrics r ON content_tags.content_id = r.id @@ -24,7 +24,7 @@ module DataFixup::FixOutOfSyncOutcomeAlignments end # Active alignments to rubrics that should no longer be aligned - if Rails.version < '3.0' + if CANVAS_RAILS2 scope = ContentTag.scoped(joins: "INNER JOIN rubrics r ON content_tags.content_id = r.id @@ -48,7 +48,7 @@ module DataFixup::FixOutOfSyncOutcomeAlignments end # Active alignments to assignments without rubrics - if Rails.version < '3.0' + if CANVAS_RAILS2 scope = ContentTag.scoped(joins: "INNER JOIN assignments a ON content_tags.content_id = a.id @@ -78,7 +78,7 @@ module DataFixup::FixOutOfSyncOutcomeAlignments # Active alignments to assignments with rubrics # that don't have a matching alignment - if Rails.version < '3.0' + if CANVAS_RAILS2 scope = ContentTag.scoped(joins: "INNER JOIN assignments a ON content_tags.content_id = a.id diff --git a/lib/nil_store.rb b/lib/nil_store.rb index 5fd039d317e..45f164d5390 100644 --- a/lib/nil_store.rb +++ b/lib/nil_store.rb @@ -27,7 +27,7 @@ class NilStore < ActiveSupport::Cache::Store def read_multi(*names); {}; end - if CANVAS_RAILS3 + unless CANVAS_RAILS2 def fetch(name, options = nil) if block_given? yield diff --git a/lib/stubs/shard.rb b/lib/stubs/shard.rb index 1fd22cb165e..354ce8c7fbf 100644 --- a/lib/stubs/shard.rb +++ b/lib/stubs/shard.rb @@ -90,7 +90,7 @@ class Shard end ActiveRecord::Base.class_eval do - if Rails.version < "3.0" + if CANVAS_RAILS2 class << self VALID_FIND_OPTIONS << :shard end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 34fa69ccd92..ce9d1eb0e95 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,12 +44,12 @@ end ENV["RAILS_ENV"] = 'test' require File.expand_path('../../config/environment', __FILE__) unless defined?(Rails) -if CANVAS_RAILS3 - require 'rspec/rails' -else +if CANVAS_RAILS2 require 'spec' # require 'spec/autorun' require 'spec/rails' +else + require 'rspec/rails' end require 'webrat' require 'mocha/api' diff --git a/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb b/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb index 9bcbb85fe50..d5869d4ff87 100644 --- a/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb +++ b/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb @@ -169,11 +169,11 @@ module Technoweenie # :nodoc: base.after_save :after_process_attachment base.after_destroy :destroy_file base.after_validation :process_attachment - if CANVAS_RAILS3 + if CANVAS_RAILS2 + base.define_callbacks :after_resize, :before_attachment_saved, :after_attachment_saved, :before_thumbnail_saved, :after_save_and_attachment_processing + else base.define_model_callbacks :resize, :attachment_saved, :save_and_attachment_processing, only: [:after] base.define_model_callbacks :attachment_saved, :thumbnail_saved, only: [:before] - else - base.define_callbacks :after_resize, :before_attachment_saved, :after_attachment_saved, :before_thumbnail_saved, :after_save_and_attachment_processing end end diff --git a/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb b/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb index 3b266a25f1f..6d2930114d3 100644 --- a/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb +++ b/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb @@ -197,7 +197,7 @@ module Delayed end scope = scope.group(:tag).offset(offset).limit(limit) - (Rails.version < "3.0" ? + (CANVAS_RAILS2 ? scope.count(:tag, :order => "COUNT(tag) DESC") : scope.order("COUNT(tag) DESC").count).map { |t,c| { :tag => t, :count => c } } end diff --git a/vendor/plugins/respondus_soap_endpoint/init.rb b/vendor/plugins/respondus_soap_endpoint/init.rb index 7cc02ca7e13..7c3f51436b6 100644 --- a/vendor/plugins/respondus_soap_endpoint/init.rb +++ b/vendor/plugins/respondus_soap_endpoint/init.rb @@ -20,7 +20,7 @@ Rails.configuration.to_prepare do # I guess we just gotta hope that no middlewares after that one have any # useful-to-this-plugin functionality. At least we still get the AR query # cache. - if Rails.version < "3.0" + if CANVAS_RAILS2 Rails.configuration.middleware.insert_before 'ActionController::ParamsParser', 'RespondusAPIMiddleware' else Rails.configuration.middleware.insert_before 'ActionDispatch::ParamsParser', 'RespondusAPIMiddleware'