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 <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
QA-Review: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
Jacob Fugal 2013-10-03 17:17:45 -06:00
parent 536f4d5038
commit dfab0425e3
37 changed files with 106 additions and 101 deletions

38
Gemfile
View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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|

View File

@ -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|

View File

@ -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)

View File

@ -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],

View File

@ -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

View File

@ -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

View File

@ -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.*")

View File

@ -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)

View File

@ -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)

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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 <env>-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"

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,4 @@
if Rails.version < '3'
if CANVAS_RAILS2
ActiveRecord::Base.class_eval do
class << self

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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'