Permalink
Browse files

start adding rails 3.0 support

This can successfully load rails console and rails server. There are
many, many problems still. The idea is this won't change anything under
rails 2.3, it's all backwards compatible.

closes CNVS-4711

test plan: `touch RAILS3` in your Canvas Rails.root directory. The run
`bundle update` and verify that you get rails 3 installed. Run `bundle
exec rails c` to load console or `bundle exec rails s` to start a
webrick server. You can login, though the dashboard currently breaks.
Also jammit isn't working yet.

But more importantly, Rails 2.3 should still work same as ever. All
tests should pass, and a basic regression sanity check would be good too.

Change-Id: Idd6f35de88adde84cd2db3a650f44b71bd6e9684
Reviewed-on: https://gerrit.instructure.com/18453
Reviewed-by: Brian Palmer <brianp@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
Product-Review: Bracken Mosbacker <bracken@instructure.com>
  • Loading branch information...
1 parent e6ed644 commit cb5e957965f97037ce6c6b3866eaece1c84fd39f @codekitchen codekitchen committed Mar 20, 2013
View
@@ -28,8 +28,10 @@
/public/javascripts/translations/
/public/optimized/
/public/stylesheets/compiled/
+/RAILS3
/spec/javascripts/
/tmp/
+/vendor/plugins/rails_upgrade
# generated plugin stuff
/app/coffeescripts/plugins/
View
34 Gemfile
@@ -1,19 +1,35 @@
source 'https://rubygems.org/'
ONE_NINE = RUBY_VERSION >= "1.9."
+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
+ gem 'rails', '2.3.17'
+ gem 'authlogic', '2.1.3'
+end
-gem 'rails', '2.3.17'
-gem 'authlogic', '2.1.3'
gem "aws-sdk", '1.8.3.1'
gem 'barby', '0.5.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'builder', '2.1.2'
-gem 'canvas_connect', '0.0.8'
+if !CANVAS_RAILS3
+ gem 'canvas_connect', '0.0.8'
+end
gem 'daemons', '1.1.0'
gem 'diff-lcs', '1.1.2', :require => 'diff/lcs'
-gem 'encrypted_cookie_store-instructure', '1.0.2', :require => 'encrypted_cookie_store'
-gem 'erubis', '2.7.0'
-gem 'fake_arel', '1.0.0'
+if !CANVAS_RAILS3
+ gem 'encrypted_cookie_store-instructure', '1.0.2', :require => 'encrypted_cookie_store'
+end
+gem 'erubis', CANVAS_RAILS3 ? '2.6.6' : '2.7.0'
+if !CANVAS_RAILS3
+ gem 'fake_arel', '1.0.0'
+end
gem 'ffi', '1.1.5'
gem 'hairtrigger', '0.1.14'
gem 'sass', '3.2.3'
@@ -22,15 +38,15 @@ if !ONE_NINE
end
gem 'hashery', '1.3.0', :require => 'hashery/dictionary'
gem 'highline', '1.6.1'
-gem 'i18n', '0.6.0'
+gem 'i18n', CANVAS_RAILS3 ? '0.5.0' : '0.6.0'
gem 'icalendar', '1.1.5'
gem 'jammit', '0.6.0'
gem 'json', '1.5.5'
# native xml parsing, diigo
gem 'libxml-ruby', '2.3.2', :require => 'xml/libxml'
gem 'macaddr', '1.0.0' # macaddr 1.2.0 tries to require 'systemu' which isn't a dependency
if ONE_NINE
- gem 'mail', '2.5.3'
+ gem 'mail', CANVAS_RAILS3 ? '2.2.19' : '2.5.3'
else
gem 'mail', '2.4.4'
end
@@ -42,7 +58,7 @@ gem 'mini_magick', '1.3.2'
gem 'netaddr', '1.5.0'
gem 'nokogiri', '1.5.5'
gem 'oauth', '0.4.5'
-gem 'rack', '1.1.3'
+gem 'rack', CANVAS_RAILS3 ? '1.2.5' : '1.1.3'
gem 'rake', '10.0.3'
gem 'rdoc', '3.12'
gem 'ratom-instructure', '0.6.9', :require => "atom" # custom gem until necessary changes are merged into mainstream
View
@@ -1,12 +1,22 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+require File.expand_path("../config/canvas_rails3", __FILE__)
+
+if CANVAS_RAILS3
+ require File.expand_path('../config/application', __FILE__)
+else
+ require File.expand_path('../config/boot', __FILE__)
+end
require 'rake'
require 'rake/testtask'
require 'rdoc/task'
-require 'tasks/rails'
+if CANVAS_RAILS3
+ CanvasRails::Application.load_tasks
+else
+ require 'tasks/rails'
+end
begin; require 'parallelized_specs/tasks'; rescue LoadError; end
@@ -831,7 +831,11 @@ def rescue_action_in_public(exception)
end
end
- rescue_responses['AuthenticationMethods::AccessTokenError'] = 401
+ if Rails.version < "3.0"
+ rescue_responses['AuthenticationMethods::AccessTokenError'] = 401
+ else
+ ActionDispatch::ShowExceptions.rescue_responses['AuthenticationMethods::AccessTokenError'] = 401
+ end
def rescue_action_in_api(exception, error_report)
status_code = response_code_for_rescue(exception) || 500
@@ -900,9 +904,8 @@ def verify_authenticity_token
params[request_forgery_protection_token] = token if token
if protect_against_forgery? &&
- request.method != :get &&
- !api_request? &&
- verifiable_request_format?
+ !request.get? &&
+ !api_request?
if session[:_csrf_token].nil? && session.empty? && !request.xhr? && !api_request?
# the session should have the token stored by now, but doesn't? sounds
# like the user doesn't have cookies enabled.
@@ -5,7 +5,7 @@ def initialize(app)
def call(env)
Account.clear_special_account_cache!
- domain_root_account = LoadAccount.default_domain_root_account
+ domain_root_account = ::LoadAccount.default_domain_root_account
configure_for_root_account(domain_root_account)
env['canvas.domain_root_account'] = domain_root_account
View
@@ -78,25 +78,26 @@ class Submission < ActiveRecord::Base
}
}
- named_scope :needs_grading, :conditions => <<-SQL
- submissions.submission_type IS NOT NULL
- AND (submissions.workflow_state = 'pending_review'
- OR (submissions.workflow_state = 'submitted'
- AND (submissions.score IS NULL OR NOT submissions.grade_matches_current_submission)
- )
- )
- SQL
-
named_scope :for_course, lambda{ |course|
{ :conditions => ["submissions.assignment_id IN (SELECT assignments.id FROM assignments WHERE assignments.context_id = ? AND assignments.context_type = 'Course')", course.id] }
}
def self.needs_grading_conditions(prefix = nil)
- conditions = needs_grading.proxy_options[:conditions].gsub(/\s+/, ' ')
+ conditions = <<-SQL
+ submissions.submission_type IS NOT NULL
+ AND (submissions.workflow_state = 'pending_review'
+ OR (submissions.workflow_state = 'submitted'
+ AND (submissions.score IS NULL OR NOT submissions.grade_matches_current_submission)
+ )
+ )
+ SQL
+ conditions.gsub!(/\s+/, ' ')
conditions.gsub!("submissions.", prefix + ".") if prefix
conditions
end
+ named_scope :needs_grading, :conditions => needs_grading_conditions
+
sanitize_field :body, Instructure::SanitizeField::SANITIZE
View
@@ -1,2 +1,8 @@
-require File.expand_path(File.dirname(__FILE__) + '/config/environment')
-run ActionController::Dispatcher.new
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+if defined?(CanvasRails)
+ run CanvasRails::Application
+else
+ run ActionController::Dispatcher.new
+end
View
@@ -0,0 +1,16 @@
+# Put this in config/application.rb
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module CanvasRails
+ class Application < Rails::Application
+ config.autoload_paths += [config.root.join('lib').to_s]
+ $LOAD_PATH << config.root.to_s
+ config.encoding = 'utf-8'
+
+ eval(File.read(File.expand_path("../shared_boot.rb", __FILE__)), binding, "config/shared_boot.rb", 1)
+ end
+end
View
@@ -1,6 +1,16 @@
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
+require File.expand_path("../canvas_rails3", __FILE__)
+
+if CANVAS_RAILS3
+ require 'rubygems'
+
+ # Set up gems listed in the Gemfile.
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
+else
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
$LOAD_PATH.unshift RAILS_ROOT.dup
@@ -120,3 +130,4 @@ def read_environment_rb
# All that for this:
Rails.boot!
+end
View
@@ -0,0 +1,3 @@
+# 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__))
Oops, something went wrong.

0 comments on commit cb5e957

Please sign in to comment.