Permalink
Browse files

Initial commit of Rails 2.3 shims for Rails 3

  • Loading branch information...
0 parents commit 01150bfa56520623e3c6d4984e080a4e492a9413 @wycats committed Jul 27, 2010
@@ -0,0 +1,7 @@
+ARGV.unshift "server"
+
+APP_PATH = File.expand_path("../../../../config/environment.rb", __FILE__)
+$".push File.expand_path("../boot.rb", APP_PATH)
+
+require "rails/commands"
+exit!
@@ -0,0 +1,75 @@
+$:.push File.expand_path("..", __FILE__)
+require "rubygems"
+require "rails/all"
+require "active_support/all"
+
+require "rails_upgrade/application"
+require "rails_upgrade/action_controller"
+require "rails_upgrade/active_record"
+require "rails_upgrade/action_view"
+
+# This is needed because Rails 3 requires development.rb, while Rails 2.3
+# invoked it in a special scope
+def self.config
+ Rails.application.config
+end
+
+module Kernel
+ def returning(value)
+ yield value
+ value
+ end
+end
+
+module Rails
+ module VERSION
+ class VersionFaker < ActiveSupport::BasicObject
+ def initialize(real_value, pretend_value)
+ @real_value, @pretend_value = real_value, pretend_value
+ end
+
+ def >=(other)
+ @pretend_value >= other
+ end
+
+ def >(other)
+ @pretend_value > other
+ end
+
+ def <=(other)
+ @pretend_value <= other
+ end
+
+ def <(other)
+ @pretend_value < other
+ end
+
+ def method_missing(meth, *args, &block)
+ @real_value.send(meth, *args, &block)
+ end
+ end
+
+ MAJOR = VersionFaker.new(MAJOR, 2)
+ MINOR = VersionFaker.new(MINOR, 3)
+ TINY = VersionFaker.new(TINY, 5)
+ end
+
+ module Initializer
+ def self.run(&block)
+ klass = Class.new(Rails::Application)
+ klass.instance_exec(klass.config, &block)
+ klass.config.autoload_paths << klass.root.join("lib")
+ Object.const_set(:RAILS_ROOT, klass.root.to_s)
+ klass.initialize!
+ end
+ end
+
+ class Boot
+ def self.inherited(klass)
+ Rails.module_eval do
+ def self.boot!
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,28 @@
+require "action_controller"
+require "action_controller/base"
+
+module ActionController
+ def self.const_missing(const)
+ if const == :UrlWriter
+ const_set(:UrlWriter, Rails.application.routes.url_helpers)
+ else
+ super
+ end
+ end
+
+ class Base
+ def self.exempt_from_layout(*)
+ end
+
+ module ExtendedDeprecation
+ def session=(value)
+ super
+ if secret = value[:secret]
+ Rails.application.config.secret_token = secret
+ end
+ end
+ end
+
+ extend ExtendedDeprecation
+ end
+end
@@ -0,0 +1,39 @@
+require "action_view"
+require "action_view/base"
+require "active_support/all"
+
+module ActiveSupport
+ remove_const :SafeBuffer
+ class SafeBuffer < String
+ alias safe_concat concat
+ end
+end
+
+
+
+module ActionView
+ class Base
+ alias old_initialize initialize
+ def initialize(*args)
+ old_initialize(*args)
+ @controller = @_controller
+ end
+
+ # change the default behavior for tag and content_tag to not escape
+ module DeactivateEscape
+ def tag(name, options = nil, open = false, escape = false)
+ super
+ end
+
+ def content_tag(name, content_or_options_with_block = nil, options = nil, escape = false, &block)
+ super
+ end
+
+ def content_tag_string(name, content, options, escape = false)
+ super
+ end
+ end
+
+ include DeactivateEscape
+ end
+end
@@ -0,0 +1,30 @@
+module ActiveRecord
+ module ConnectionAdapters
+ class AbstractAdapter
+ def add_index(table_name, column_name, options = {})
+ if options.key?(:name)
+ options[:name] = options[:name].to_s
+ end
+ super
+ end
+ end
+ end
+
+ class Base
+ def self.before_validation_on_create(name = nil, &block)
+ if name
+ before_validation name, :on => :create
+ else
+ before_validation({:on => :create}, &block)
+ end
+ end
+
+ def self.validate_on_create(name = nil, &block)
+ if name
+ validate name, :on => :create
+ else
+ validate({:on => :create}, &block)
+ end
+ end
+ end
+end
@@ -0,0 +1,16 @@
+module Rails
+ class Application
+ class Configuration
+ def load_paths
+ autoload_paths
+ end
+
+ def gem(name, options = {})
+ super name, options[:version] || ">= 0"
+ require options[:lib] || name
+ rescue Gem::LoadError
+ puts "Tried, but failed, to load #{name}"
+ end
+ end
+ end
+end
@@ -0,0 +1 @@
+require "rails/source_annotation_extractor"
@@ -0,0 +1,3 @@
+require File.expand_path("../../../../config/environment", __FILE__)
+Rails.application.load_tasks
+

1 comment on commit 01150bf

@zilkey
zilkey commented on 01150bf Jul 30, 2010

Nice! I imagine people will want to be able to opt out of the safe_buffer changes, since rails_xss has been out for a while.

It seems like a lot of these changes could be easily added to Rails 3. The before_validation_on_x methods could be easily deprecated, the load_paths could be easily deprecated, all the safe buffer changes seem like they could be opt-in from a config variable, add_index could be deprecated.

Please sign in to comment.