Skip to content

Commit cb5e957

Browse files
committed
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 <[email protected]> Tested-by: Jenkins <[email protected]> QA-Review: Clare Hetherington <[email protected]> Product-Review: Bracken Mosbacker <[email protected]>
1 parent e6ed644 commit cb5e957

37 files changed

+637
-462
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
/public/javascripts/translations/
2929
/public/optimized/
3030
/public/stylesheets/compiled/
31+
/RAILS3
3132
/spec/javascripts/
3233
/tmp/
34+
/vendor/plugins/rails_upgrade
3335

3436
# generated plugin stuff
3537
/app/coffeescripts/plugins/

Gemfile

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
source 'https://rubygems.org/'
22

33
ONE_NINE = RUBY_VERSION >= "1.9."
4+
require File.expand_path("../config/canvas_rails3", __FILE__)
5+
6+
if CANVAS_RAILS3
7+
# 3.0.20 is transitional, we will be on 3.2.x before support is complete
8+
# that's also why some gems below have to be downgraded, 3.0.20 relies on old versions of some gems
9+
# just to be clear, Canvas is NOT READY to run under Rails 3 in production
10+
gem 'rails', '3.0.20'
11+
gem 'authlogic', '3.2.0'
12+
else
13+
gem 'rails', '2.3.17'
14+
gem 'authlogic', '2.1.3'
15+
end
416

5-
gem 'rails', '2.3.17'
6-
gem 'authlogic', '2.1.3'
717
gem "aws-sdk", '1.8.3.1'
818
gem 'barby', '0.5.0'
919
gem 'bcrypt-ruby', '3.0.1'
1020
gem 'builder', '2.1.2'
11-
gem 'canvas_connect', '0.0.8'
21+
if !CANVAS_RAILS3
22+
gem 'canvas_connect', '0.0.8'
23+
end
1224
gem 'daemons', '1.1.0'
1325
gem 'diff-lcs', '1.1.2', :require => 'diff/lcs'
14-
gem 'encrypted_cookie_store-instructure', '1.0.2', :require => 'encrypted_cookie_store'
15-
gem 'erubis', '2.7.0'
16-
gem 'fake_arel', '1.0.0'
26+
if !CANVAS_RAILS3
27+
gem 'encrypted_cookie_store-instructure', '1.0.2', :require => 'encrypted_cookie_store'
28+
end
29+
gem 'erubis', CANVAS_RAILS3 ? '2.6.6' : '2.7.0'
30+
if !CANVAS_RAILS3
31+
gem 'fake_arel', '1.0.0'
32+
end
1733
gem 'ffi', '1.1.5'
1834
gem 'hairtrigger', '0.1.14'
1935
gem 'sass', '3.2.3'
@@ -22,15 +38,15 @@ if !ONE_NINE
2238
end
2339
gem 'hashery', '1.3.0', :require => 'hashery/dictionary'
2440
gem 'highline', '1.6.1'
25-
gem 'i18n', '0.6.0'
41+
gem 'i18n', CANVAS_RAILS3 ? '0.5.0' : '0.6.0'
2642
gem 'icalendar', '1.1.5'
2743
gem 'jammit', '0.6.0'
2844
gem 'json', '1.5.5'
2945
# native xml parsing, diigo
3046
gem 'libxml-ruby', '2.3.2', :require => 'xml/libxml'
3147
gem 'macaddr', '1.0.0' # macaddr 1.2.0 tries to require 'systemu' which isn't a dependency
3248
if ONE_NINE
33-
gem 'mail', '2.5.3'
49+
gem 'mail', CANVAS_RAILS3 ? '2.2.19' : '2.5.3'
3450
else
3551
gem 'mail', '2.4.4'
3652
end
@@ -42,7 +58,7 @@ gem 'mini_magick', '1.3.2'
4258
gem 'netaddr', '1.5.0'
4359
gem 'nokogiri', '1.5.5'
4460
gem 'oauth', '0.4.5'
45-
gem 'rack', '1.1.3'
61+
gem 'rack', CANVAS_RAILS3 ? '1.2.5' : '1.1.3'
4662
gem 'rake', '10.0.3'
4763
gem 'rdoc', '3.12'
4864
gem 'ratom-instructure', '0.6.9', :require => "atom" # custom gem until necessary changes are merged into mainstream

Rakefile

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Add your own tasks in files placed in lib/tasks ending in .rake,
22
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
33

4-
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
4+
require File.expand_path("../config/canvas_rails3", __FILE__)
5+
6+
if CANVAS_RAILS3
7+
require File.expand_path('../config/application', __FILE__)
8+
else
9+
require File.expand_path('../config/boot', __FILE__)
10+
end
511

612
require 'rake'
713
require 'rake/testtask'
814
require 'rdoc/task'
915

10-
require 'tasks/rails'
16+
if CANVAS_RAILS3
17+
CanvasRails::Application.load_tasks
18+
else
19+
require 'tasks/rails'
20+
end
1121

1222
begin; require 'parallelized_specs/tasks'; rescue LoadError; end

app/controllers/application_controller.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,11 @@ def rescue_action_in_public(exception)
831831
end
832832
end
833833

834-
rescue_responses['AuthenticationMethods::AccessTokenError'] = 401
834+
if Rails.version < "3.0"
835+
rescue_responses['AuthenticationMethods::AccessTokenError'] = 401
836+
else
837+
ActionDispatch::ShowExceptions.rescue_responses['AuthenticationMethods::AccessTokenError'] = 401
838+
end
835839

836840
def rescue_action_in_api(exception, error_report)
837841
status_code = response_code_for_rescue(exception) || 500
@@ -900,9 +904,8 @@ def verify_authenticity_token
900904
params[request_forgery_protection_token] = token if token
901905

902906
if protect_against_forgery? &&
903-
request.method != :get &&
904-
!api_request? &&
905-
verifiable_request_format?
907+
!request.get? &&
908+
!api_request?
906909
if session[:_csrf_token].nil? && session.empty? && !request.xhr? && !api_request?
907910
# the session should have the token stored by now, but doesn't? sounds
908911
# like the user doesn't have cookies enabled.

app/middleware/load_account.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def initialize(app)
55

66
def call(env)
77
Account.clear_special_account_cache!
8-
domain_root_account = LoadAccount.default_domain_root_account
8+
domain_root_account = ::LoadAccount.default_domain_root_account
99
configure_for_root_account(domain_root_account)
1010

1111
env['canvas.domain_root_account'] = domain_root_account

app/models/submission.rb

+11-10
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,26 @@ class Submission < ActiveRecord::Base
7878
}
7979
}
8080

81-
named_scope :needs_grading, :conditions => <<-SQL
82-
submissions.submission_type IS NOT NULL
83-
AND (submissions.workflow_state = 'pending_review'
84-
OR (submissions.workflow_state = 'submitted'
85-
AND (submissions.score IS NULL OR NOT submissions.grade_matches_current_submission)
86-
)
87-
)
88-
SQL
89-
9081
named_scope :for_course, lambda{ |course|
9182
{ :conditions => ["submissions.assignment_id IN (SELECT assignments.id FROM assignments WHERE assignments.context_id = ? AND assignments.context_type = 'Course')", course.id] }
9283
}
9384

9485
def self.needs_grading_conditions(prefix = nil)
95-
conditions = needs_grading.proxy_options[:conditions].gsub(/\s+/, ' ')
86+
conditions = <<-SQL
87+
submissions.submission_type IS NOT NULL
88+
AND (submissions.workflow_state = 'pending_review'
89+
OR (submissions.workflow_state = 'submitted'
90+
AND (submissions.score IS NULL OR NOT submissions.grade_matches_current_submission)
91+
)
92+
)
93+
SQL
94+
conditions.gsub!(/\s+/, ' ')
9695
conditions.gsub!("submissions.", prefix + ".") if prefix
9796
conditions
9897
end
9998

99+
named_scope :needs_grading, :conditions => needs_grading_conditions
100+
100101

101102
sanitize_field :body, Instructure::SanitizeField::SANITIZE
102103

config.ru

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
require File.expand_path(File.dirname(__FILE__) + '/config/environment')
2-
run ActionController::Dispatcher.new
1+
# This file is used by Rack-based servers to start the application.
2+
3+
require ::File.expand_path('../config/environment', __FILE__)
4+
if defined?(CanvasRails)
5+
run CanvasRails::Application
6+
else
7+
run ActionController::Dispatcher.new
8+
end

config/application.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Put this in config/application.rb
2+
require File.expand_path('../boot', __FILE__)
3+
4+
require 'rails/all'
5+
6+
Bundler.require(:default, Rails.env) if defined?(Bundler)
7+
8+
module CanvasRails
9+
class Application < Rails::Application
10+
config.autoload_paths += [config.root.join('lib').to_s]
11+
$LOAD_PATH << config.root.to_s
12+
config.encoding = 'utf-8'
13+
14+
eval(File.read(File.expand_path("../shared_boot.rb", __FILE__)), binding, "config/shared_boot.rb", 1)
15+
end
16+
end

config/boot.rb

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Don't change this file!
22
# Configure your app in config/environment.rb and config/environments/*.rb
33

4+
require File.expand_path("../canvas_rails3", __FILE__)
5+
6+
if CANVAS_RAILS3
7+
require 'rubygems'
8+
9+
# Set up gems listed in the Gemfile.
10+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
11+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
12+
else
13+
414
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
515
$LOAD_PATH.unshift RAILS_ROOT.dup
616

@@ -120,3 +130,4 @@ def read_environment_rb
120130

121131
# All that for this:
122132
Rails.boot!
133+
end

config/canvas_rails3.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# You can enable the not-yet-complete Rails3 support by either defining a
2+
# CANVAS_RAILS3 env var, or create an empty RAILS3 file in the canvas RAILS_ROOT dir
3+
CANVAS_RAILS3 = !!ENV['CANVAS_RAILS3'] || File.exist?(File.expand_path("../../RAILS3", __FILE__))

0 commit comments

Comments
 (0)