diff options
41 files changed, 404 insertions, 301 deletions
diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index 980de8ec70..201b56a739 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.homepage = "http://www.rubyonrails.org" s.add_dependency('actionpack', '= 3.0.pre') - s.add_dependency('mail', '~> 1.4.2') + s.add_dependency('mail', '~> 1.4.3') s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*'] s.has_rdoc = true diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 039715c2f5..55ddbb24f4 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -45,5 +45,3 @@ module Text autoload :Format, 'action_mailer/vendor/text_format' end - -require 'action_mailer/tmail_compat'
\ No newline at end of file diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index aea2498d4d..f34a9bae47 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/class' require 'mail' +require 'action_mailer/tmail_compat' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. @@ -149,7 +150,7 @@ module ActionMailer #:nodoc: # # part "text/plain" do |p| # p.body = render_message("signup-as-plain", :account => recipient) - # p.transfer_encoding = "base64" + # p.content_transfer_encoding = "base64" # end # end # end diff --git a/actionmailer/lib/action_mailer/rails.rb b/actionmailer/lib/action_mailer/railtie.rb index a3573cdea7..5410c7d75f 100644 --- a/actionmailer/lib/action_mailer/rails.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -1,7 +1,8 @@ require "action_mailer" +require "rails" module ActionMailer - class Plugin < Rails::Plugin + class Railtie < Rails::Railtie plugin_name :action_mailer initializer "action_mailer.set_configs" do |app| diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 445abd0b89..e8632d4559 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,5 +1,5 @@ require 'active_support/test_case' -require 'mail' +require 'action_mailer/base' module ActionMailer class NonInferrableMailerError < ::StandardError diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb index cacd79be27..2fd25ff145 100644 --- a/actionmailer/lib/action_mailer/tmail_compat.rb +++ b/actionmailer/lib/action_mailer/tmail_compat.rb @@ -6,5 +6,15 @@ module Mail content_type(*args) end + alias :old_transfer_encoding :transfer_encoding + def transfer_encoding(value = nil) + if value + STDERR.puts("Message#transfer_encoding is deprecated, please call Message#content_transfer_encoding with the same arguments.\n#{caller}") + content_transfer_encoding(value) + else + old_transfer_encoding + end + end + end end
\ No newline at end of file diff --git a/actionmailer/test/tmail_compat_test.rb b/actionmailer/test/tmail_compat_test.rb index 9b0e91f5f8..faa267e3bf 100644 --- a/actionmailer/test/tmail_compat_test.rb +++ b/actionmailer/test/tmail_compat_test.rb @@ -10,5 +10,14 @@ class TmailCompatTest < Test::Unit::TestCase end assert_equal mail.content_type.string, "text/plain" end + + def test_transfer_encoding_raises_deprecation_warning + mail = Mail.new + STDERR.expects(:puts) # Deprecation warning + assert_nothing_raised do + mail.transfer_encoding "base64" + end + assert_equal mail.content_transfer_encoding.value, "base64" + end end diff --git a/actionpack/lib/action_controller/rails.rb b/actionpack/lib/action_controller/railtie.rb index df708c315b..f861d12905 100644 --- a/actionpack/lib/action_controller/rails.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -1,5 +1,8 @@ +require "action_controller" +require "rails" + module ActionController - class Plugin < Rails::Plugin + class Railtie < Rails::Railtie plugin_name :action_controller initializer "action_controller.set_configs" do |app| diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb new file mode 100644 index 0000000000..a90e0636b9 --- /dev/null +++ b/actionpack/lib/action_view/railtie.rb @@ -0,0 +1,2 @@ +require "action_view" +require "rails"
\ No newline at end of file diff --git a/activemodel/lib/active_model/railtie.rb b/activemodel/lib/active_model/railtie.rb new file mode 100644 index 0000000000..63ffe5db63 --- /dev/null +++ b/activemodel/lib/active_model/railtie.rb @@ -0,0 +1,2 @@ +require "active_model" +require "rails"
\ No newline at end of file diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index a524dc50a1..cf439b0dc0 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -54,6 +54,7 @@ module ActiveRecord autoload :QueryMethods autoload :FinderMethods autoload :CalculationMethods + autoload :PredicateBuilder end autoload :Base diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index f0bad6c3ba..052197f7ad 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1488,7 +1488,7 @@ module ActiveRecord dependent_conditions = [] dependent_conditions << "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}" dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as] - dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.quoted_table_name) if reflection.options[:conditions] + dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.table_name) if reflection.options[:conditions] dependent_conditions << extra_conditions if extra_conditions dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") dependent_conditions = dependent_conditions.gsub('@', '\@') diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 7d8f4670fa..022dd2ae9b 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -161,7 +161,7 @@ module ActiveRecord end # Forwards the call to the reflection class. - def sanitize_sql(sql, table_name = @reflection.klass.quoted_table_name) + def sanitize_sql(sql, table_name = @reflection.klass.table_name) @reflection.klass.send(:sanitize_sql, sql, table_name) end diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 9569b0c6f9..5913189c98 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -73,7 +73,7 @@ module ActiveRecord relation = arel_table(@reflection.options[:join_table]) relation.where(relation[@reflection.primary_key_name].eq(@owner.id). and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id))) - ).delete + ).delete_all end end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index c4bdbdad08..fb160dea9a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -815,8 +815,8 @@ module ActiveRecord #:nodoc: # # # Delete multiple rows # Todo.delete([2,3,4]) - def delete(id) - delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ]) + def delete(id_or_array) + arel_table.where(construct_conditions(nil, scope(:find))).delete(id_or_array) end # Destroy an object (or multiple objects) that has the given id, the object is instantiated first, @@ -1508,6 +1508,10 @@ module ActiveRecord #:nodoc: Relation.new(self, Arel::Table.new(table || table_name)) end + def engine + @engine ||= Arel::Sql::Engine.new(self) + end + private # Finder methods must instantiate through this method to work with the # single-table inheritance model that makes it possible to create @@ -1964,7 +1968,7 @@ module ActiveRecord #:nodoc: # ["name='%s' and group_id='%s'", "foo'bar", 4] returns "name='foo''bar' and group_id='4'" # { :name => "foo'bar", :group_id => 4 } returns "name='foo''bar' and group_id='4'" # "name='foo''bar' and group_id='4'" returns "name='foo''bar' and group_id='4'" - def sanitize_sql_for_conditions(condition, table_name = quoted_table_name) + def sanitize_sql_for_conditions(condition, table_name = self.table_name) return nil if condition.blank? case condition @@ -2035,30 +2039,12 @@ module ActiveRecord #:nodoc: # And for value objects on a composed_of relationship: # { :address => Address.new("123 abc st.", "chicago") } # # => "address_street='123 abc st.' and address_city='chicago'" - def sanitize_sql_hash_for_conditions(attrs, default_table_name = quoted_table_name) + def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name) attrs = expand_hash_conditions_for_aggregates(attrs) - conditions = attrs.map do |attr, value| - table_name = default_table_name - - unless value.is_a?(Hash) - attr = attr.to_s - - # Extract table name from qualified attribute names. - if attr.include?('.') - attr_table_name, attr = attr.split('.', 2) - attr_table_name = connection.quote_table_name(attr_table_name) - else - attr_table_name = table_name - end - - attribute_condition("#{attr_table_name}.#{connection.quote_column_name(attr)}", value) - else - sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s)) - end - end.join(' AND ') - - replace_bind_variables(conditions, expand_range_bind_variables(attrs.values)) + table = Arel::Table.new(default_table_name, engine) + builder = PredicateBuilder.new(engine) + builder.build_from_hash(attrs, table).map(&:to_sql).join(' AND ') end alias_method :sanitize_sql_hash, :sanitize_sql_hash_for_conditions @@ -2323,7 +2309,7 @@ module ActiveRecord #:nodoc: # be made (since they can't be persisted). def destroy unless new_record? - self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).delete + self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).delete_all end @destroyed = true diff --git a/activerecord/lib/active_record/rails.rb b/activerecord/lib/active_record/railtie.rb index a13bd2a5da..657ee738c0 100644 --- a/activerecord/lib/active_record/rails.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -2,10 +2,12 @@ # rails, so let's make sure that it gets required before # here. This is needed for correctly setting up the middleware. # In the future, this might become an optional require. -require "action_controller/rails" +require "active_record" +require "action_controller/railtie" +require "rails" module ActiveRecord - class Plugin < Rails::Plugin + class Railtie < Rails::Railtie plugin_name :active_record rake_tasks do diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index ae03e1d7e9..6a1237cdd1 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -6,7 +6,7 @@ module ActiveRecord delegate :length, :collect, :map, :each, :all?, :to => :to_a attr_reader :relation, :klass, :preload_associations, :eager_load_associations - attr_writer :readonly, :preload_associations, :eager_load_associations + attr_writer :readonly, :preload_associations, :eager_load_associations, :table def initialize(klass, relation) @klass, @relation = klass, relation @@ -109,6 +109,10 @@ module ActiveRecord @relation.delete.tap { reset } end + def delete(id_or_array) + where(@klass.primary_key => id_or_array).delete_all + end + def loaded? @loaded end @@ -129,9 +133,18 @@ module ActiveRecord relation.readonly = @readonly relation.preload_associations = @preload_associations relation.eager_load_associations = @eager_load_associations + relation.table = table relation end + def table + @table ||= Arel::Table.new(@klass.table_name, Arel::Sql::Engine.new(@klass)) + end + + def primary_key + @primary_key ||= table[@klass.primary_key] + end + protected def method_missing(method, *args, &block) diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 7a1d6fc538..c3e5f27838 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -21,8 +21,8 @@ module ActiveRecord end def exists?(id = nil) - relation = select("#{@klass.quoted_table_name}.#{@klass.primary_key}").limit(1) - relation = relation.where(@klass.primary_key => id) if id + relation = select(primary_key).limit(1) + relation = relation.where(primary_key.eq(id)) if id relation.first ? true : false end @@ -78,7 +78,7 @@ module ActiveRecord end def find_one(id) - record = where(@klass.primary_key => id).first + record = where(primary_key.eq(id)).first unless record conditions = where_clause(', ') @@ -90,7 +90,7 @@ module ActiveRecord end def find_some(ids) - result = where(@klass.primary_key => ids).all + result = where(primary_key.in(ids)).all expected_size = if @relation.taken && ids.size > @relation.taken diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb new file mode 100644 index 0000000000..d5e0c90184 --- /dev/null +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -0,0 +1,45 @@ +module ActiveRecord + class PredicateBuilder + + def initialize(engine) + @engine = engine + end + + def build_from_hash(attributes, default_table) + predicates = attributes.map do |column, value| + arel_table = default_table + + if value.is_a?(Hash) + arel_table = Arel::Table.new(column, @engine) + build_from_hash(value, arel_table) + else + column = column.to_s + + if column.include?('.') + table_name, column = column.split('.', 2) + arel_table = Arel::Table.new(table_name, @engine) + end + + attribute = arel_table[column] || Arel::Attribute.new(arel_table, column.to_sym) + + case value + when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope + attribute.in(value) + when Range + # TODO : Arel should handle ranges with excluded end. + if value.exclude_end? + [attribute.gteq(value.begin), attribute.lt(value.end)] + else + attribute.in(value) + end + else + attribute.eq(value) + end + end + end + + predicates.flatten + end + + end +end diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 631c80da25..432b33e174 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -104,14 +104,19 @@ module ActiveRecord def where(*args) return spawn if args.blank? - if [String, Hash, Array].include?(args.first.class) - conditions = @klass.send(:merge_conditions, args.size > 1 ? Array.wrap(args) : args.first) - conditions = Arel::SqlLiteral.new(conditions) if conditions + builder = PredicateBuilder.new(Arel::Sql::Engine.new(@klass)) + + conditions = if [String, Array].include?(args.first.class) + merged = @klass.send(:merge_conditions, args.size > 1 ? Array.wrap(args) : args.first) + Arel::SqlLiteral.new(merged) if merged + elsif args.first.is_a?(Hash) + attributes = @klass.send(:expand_hash_conditions_for_aggregates, args.first) + builder.build_from_hash(attributes, table) else - conditions = args.first + args.first end - spawn(@relation.where(conditions)) + spawn(@relation.where(*conditions)) end private diff --git a/activeresource/lib/active_resource/railtie.rb b/activeresource/lib/active_resource/railtie.rb new file mode 100644 index 0000000000..4f264c82b8 --- /dev/null +++ b/activeresource/lib/active_resource/railtie.rb @@ -0,0 +1,2 @@ +require "active_resource" +require "rails"
\ No newline at end of file diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 9fb3cd9f94..d69e3eea6a 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -1,9 +1,106 @@ -require "rails/core" +require "pathname" -%w(active_model active_record action_controller action_view action_mailer active_resource).each do |framework| - begin - require framework - require "#{framework}/rails" - rescue LoadError +require 'active_support' +require 'active_support/core_ext/kernel/reporting' +require 'active_support/core_ext/logger' +require 'action_dispatch' + +require 'rails/initializable' +require 'rails/application' +require 'rails/railtie' +require 'rails/plugin' +require 'rails/railties_path' +require 'rails/version' +require 'rails/rack' +require 'rails/paths' +require 'rails/configuration' +require 'rails/deprecation' +require 'rails/ruby_version_check' + +# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the +# multibyte safe operations. Plugin authors supporting other encodings +# should override this behaviour and set the relevant +default_charset+ +# on ActionController::Base. +# +# For Ruby 1.9, UTF-8 is the default internal and external encoding. +if RUBY_VERSION < '1.9' + $KCODE='u' +else + Encoding.default_external = Encoding::UTF_8 +end + +RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV) + +module Rails + # Needs to be duplicated from Active Support since its needed before Active + # Support is available. Here both Options and Hash are namespaced to prevent + # conflicts with other implementations AND with the classes residing in Active Support. + # --- + # TODO: w0t? + class << self + def application + @@application ||= nil + end + + def application=(application) + @@application = application + end + + # The Configuration instance used to configure the Rails environment + def configuration + application.configuration + end + + def initialize! + application.initialize! + end + + def initialized? + @initialized || false + end + + def initialized=(initialized) + @initialized ||= initialized + end + + def logger + if defined?(RAILS_DEFAULT_LOGGER) + RAILS_DEFAULT_LOGGER + else + nil + end + end + + def backtrace_cleaner + @@backtrace_cleaner ||= begin + # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded + require 'rails/backtrace_cleaner' + Rails::BacktraceCleaner.new + end + end + + def root + application && application.config.root + end + + def env + @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV) + end + + def cache + RAILS_CACHE + end + + def version + VERSION::STRING + end + + def public_path + @@public_path ||= self.root ? File.join(self.root, "public") : "public" + end + + def public_path=(path) + @@public_path = path + end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb new file mode 100644 index 0000000000..7dfe2b8b63 --- /dev/null +++ b/railties/lib/rails/all.rb @@ -0,0 +1,15 @@ +require "rails" + +%w( + active_model + active_record + action_controller + action_view + action_mailer + active_resource +).each do |framework| + begin + require "#{framework}/railtie" + rescue LoadError + end +end
\ No newline at end of file diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 5419b46f19..457eef648c 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -92,8 +92,8 @@ module Rails def plugins @plugins ||= begin plugin_names = config.plugins || [:all] - Plugin.plugins.select { |p| plugin_names.include?(:all) || plugin_names.include?(p.plugin_name) }.map { |p| p.new } + - Plugin::Vendored.all(config.plugins || [:all], config.paths.vendor.plugins) + Railtie.plugins.select { |p| plugin_names.include?(:all) || plugin_names.include?(p.plugin_name) }.map { |p| p.new } + + Plugin.all(config.plugins || [:all], config.paths.vendor.plugins) end end @@ -273,7 +273,9 @@ module Rails # For each framework, search for instrument file with Notifications hooks. # initializer :load_notifications_hooks do - config.frameworks.each do |framework| + frameworks = [ :active_record, :action_controller, :action_view, + :action_mailer, :active_resource ] + frameworks.each do |framework| begin require "#{framework}/notifications" rescue LoadError => e diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 086f67a419..f0a0d5e55e 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -3,7 +3,7 @@ require 'active_support/ordered_options' module Rails # Temporarily separate the plugin configuration class from the main # configuration class while this bit is being cleaned up. - class Plugin::Configuration + class Railtie::Configuration def self.default @default ||= new @@ -45,12 +45,12 @@ module Rails end def config_keys - ([ :active_support, :action_view, :action_mailer, :active_resource ] + - Plugin.plugin_names).map { |n| n.to_s }.uniq + ([ :active_support, :action_view ] + + Railtie.plugin_names).map { |n| n.to_s }.uniq end end - class Configuration < Plugin::Configuration + class Configuration < Railtie::Configuration attr_accessor :after_initialize_blocks, :cache_classes, :consider_all_requests_local, :dependency_loading, :gems, :load_once_paths, :logger, :metals, :plugins, @@ -59,7 +59,7 @@ module Rails attr_writer :cache_store, :controller_paths, :database_configuration_file, :eager_load_paths, - :frameworks, :framework_root_path, :i18n, :load_paths, + :i18n, :load_paths, :log_level, :log_path, :paths, :routes_configuration_file, :view_path @@ -119,6 +119,13 @@ module Rails end end + def frameworks(*args) + raise "config.frameworks in no longer supported. See the generated" \ + "config/boot.rb for steps on how to limit the frameworks that" \ + "will be loaded" + end + alias frameworks= frameworks + # Enable threaded mode. Allows concurrent requests to controller actions and # multiple database connections. Also disables automatic dependency loading # after boot, and disables reloading code on every request, as these are @@ -134,21 +141,6 @@ module Rails self end - def framework_paths - paths = %w(railties railties/lib activesupport/lib) - paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view) - - [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| - paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework) - end - - paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } - end - - def framework_root_path - defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root}/vendor/rails" - end - # Loads and returns the contents of the #database_configuration_file. The # contents of the file are processed via ERB before being sent through # YAML::load. @@ -239,10 +231,6 @@ module Rails @log_level ||= RAILS_ENV == 'production' ? :info : :debug end - def frameworks - @frameworks ||= [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ] - end - def i18n @i18n ||= begin i18n = ActiveSupport::OrderedOptions.new diff --git a/railties/lib/rails/core.rb b/railties/lib/rails/core.rb deleted file mode 100644 index ab95edc676..0000000000 --- a/railties/lib/rails/core.rb +++ /dev/null @@ -1,105 +0,0 @@ -require "pathname" - -require 'active_support' -require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/logger' -require 'action_dispatch' - -require 'rails/initializable' -require 'rails/application' -require 'rails/plugin' -require 'rails/railties_path' -require 'rails/version' -require 'rails/rack' -require 'rails/paths' -require 'rails/configuration' -require 'rails/deprecation' -require 'rails/ruby_version_check' - -# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the -# multibyte safe operations. Plugin authors supporting other encodings -# should override this behaviour and set the relevant +default_charset+ -# on ActionController::Base. -# -# For Ruby 1.9, UTF-8 is the default internal and external encoding. -if RUBY_VERSION < '1.9' - $KCODE='u' -else - Encoding.default_external = Encoding::UTF_8 -end - -RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV) - -module Rails - # Needs to be duplicated from Active Support since its needed before Active - # Support is available. Here both Options and Hash are namespaced to prevent - # conflicts with other implementations AND with the classes residing in Active Support. - # --- - # TODO: w0t? - class << self - def application - @@application ||= nil - end - - def application=(application) - @@application = application - end - - # The Configuration instance used to configure the Rails environment - def configuration - application.configuration - end - - def initialize! - application.initialize! - end - - def initialized? - @initialized || false - end - - def initialized=(initialized) - @initialized ||= initialized - end - - def logger - if defined?(RAILS_DEFAULT_LOGGER) - RAILS_DEFAULT_LOGGER - else - nil - end - end - - def backtrace_cleaner - @@backtrace_cleaner ||= begin - # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded - require 'rails/backtrace_cleaner' - Rails::BacktraceCleaner.new - end - end - - def root - application && application.config.root - end - - def env - @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV) - end - - def cache - RAILS_CACHE - end - - def version - VERSION::STRING - end - - def public_path - @@public_path ||= self.root ? File.join(self.root, "public") : "public" - end - - def public_path=(path) - @@public_path = path - end - end -end diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 15dc553e53..ec0729db04 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -13,16 +13,8 @@ module <%= app_name.classify %> # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Skip frameworks you're not going to use. To use Rails without a database, - # you must remove the Active Record framework. -<% if options[:skip_activerecord] -%> - config.frameworks -= [ :active_record ] -<% else -%> - # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] - # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector, :forum_observer -<% end -%> # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb index 5aa49ca5e6..6de1725260 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb @@ -13,4 +13,13 @@ else require 'rubygems' end -require 'rails' +require 'rails/all' +# To pick the frameworks you want, remove 'require "rails/all"' +# and list the framework railties that you want: +# +# require "active_model/railtie" +# require "active_record/railtie" +# require "action_controller/railtie" +# require "action_view/railtie" +# require "action_mailer/railtie" +# require "active_resource/railtie"
\ No newline at end of file diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index e154e9b706..9cc6b9c35b 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,106 +1,64 @@ module Rails - class Plugin - include Initializable - - def self.plugin_name(plugin_name = nil) - @plugin_name ||= name.demodulize.underscore - @plugin_name = plugin_name if plugin_name - @plugin_name - end - - def self.inherited(klass) - @plugins ||= [] - @plugins << klass unless klass == Vendored - end - - def self.plugins - @plugins - end + class Plugin < Railtie + def self.all(list, paths) + plugins = [] + paths.each do |path| + Dir["#{path}/*"].each do |plugin_path| + plugin = new(plugin_path) + next unless list.include?(plugin.name) || list.include?(:all) + plugins << plugin + end + end - def self.plugin_names - plugins.map { |p| p.plugin_name } + plugins.sort_by do |p| + [list.index(p.name) || list.index(:all), p.name.to_s] + end end - def self.config - Configuration.default - end + attr_reader :name, :path - def self.rake_tasks(&blk) - @rake_tasks ||= [] - @rake_tasks << blk if blk - @rake_tasks + def initialize(path) + @name = File.basename(path).to_sym + @path = path end - def rake_tasks - self.class.rake_tasks + def load_paths + Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"] end def load_tasks - return unless rake_tasks - rake_tasks.each { |blk| blk.call } + Dir["#{path}/**/tasks/**/*.rake"].sort.each { |ext| load ext } end - class Vendored < Plugin - def self.all(list, paths) - plugins = [] - paths.each do |path| - Dir["#{path}/*"].each do |plugin_path| - plugin = new(plugin_path) - next unless list.include?(plugin.name) || list.include?(:all) - plugins << plugin - end - end - - plugins.sort_by do |p| - [list.index(p.name) || list.index(:all), p.name.to_s] - end - end - - attr_reader :name, :path - - def initialize(path) - @name = File.basename(path).to_sym - @path = path - end - - def load_paths - Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"] - end - - def load_tasks - Dir["#{path}/**/tasks/**/*.rake"].sort.each { |ext| load ext } - end - - initializer :add_to_load_path, :after => :set_autoload_paths do |app| - load_paths.each do |path| - $LOAD_PATH << path - require "active_support/dependencies" + initializer :add_to_load_path, :after => :set_autoload_paths do |app| + load_paths.each do |path| + $LOAD_PATH << path + require "active_support/dependencies" - ActiveSupport::Dependencies.load_paths << path + ActiveSupport::Dependencies.load_paths << path - unless app.config.reload_plugins - ActiveSupport::Dependencies.load_once_paths << path - end + unless app.config.reload_plugins + ActiveSupport::Dependencies.load_once_paths << path end end + end - initializer :load_init_rb, :before => :load_application_initializers do |app| - file = "#{@path}/init.rb" - config = app.config - eval File.read(file), binding, file if File.file?(file) - end + initializer :load_init_rb, :before => :load_application_initializers do |app| + file = "#{@path}/init.rb" + config = app.config + eval File.read(file), binding, file if File.file?(file) + end - initializer :add_view_paths, :after => :initialize_framework_views do - ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views") - end + initializer :add_view_paths, :after => :initialize_framework_views do + ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views") + end - initializer :add_routing_file, :after => :initialize_routing do |app| - routing_file = "#{path}/config/routes.rb" - if File.exist?(routing_file) - app.route_configuration_files << routing_file - app.reload_routes! - end + initializer :add_routing_file, :after => :initialize_routing do |app| + routing_file = "#{path}/config/routes.rb" + if File.exist?(routing_file) + app.route_configuration_files << routing_file + app.reload_routes! end end end -end +end
\ No newline at end of file diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb new file mode 100644 index 0000000000..ff28ade35d --- /dev/null +++ b/railties/lib/rails/railtie.rb @@ -0,0 +1,43 @@ +module Rails + class Railtie + include Initializable + + def self.plugin_name(plugin_name = nil) + @plugin_name ||= name.demodulize.underscore + @plugin_name = plugin_name if plugin_name + @plugin_name + end + + def self.inherited(klass) + @plugins ||= [] + @plugins << klass unless klass == Plugin + end + + def self.plugins + @plugins + end + + def self.plugin_names + plugins.map { |p| p.plugin_name } + end + + def self.config + Configuration.default + end + + def self.rake_tasks(&blk) + @rake_tasks ||= [] + @rake_tasks << blk if blk + @rake_tasks + end + + def rake_tasks + self.class.rake_tasks + end + + def load_tasks + return unless rake_tasks + rake_tasks.each { |blk| blk.call } + end + end +end diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 66ab5a08c3..2d6983076a 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -20,7 +20,7 @@ require 'active_support/core_ext/logger' require 'active_support/test_case' require 'action_controller' -require 'rails' +require 'rails/all' # TODO: Remove these hacks class TestApp < Rails::Application diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index ece41f9de8..adb867ca6d 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -16,6 +16,7 @@ module ApplicationTests FileUtils.rm_rf(new_app) if File.directory?(new_app) build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") end test "the application root is set correctly" do @@ -75,10 +76,11 @@ module ApplicationTests test "the application can be marked as threadsafe when there are no frameworks" do FileUtils.rm_rf("#{app_path}/config/environments") add_to_config <<-RUBY - config.frameworks = [] config.threadsafe! RUBY + use_frameworks [] + assert_nothing_raised do require "#{app_path}/config/application" end @@ -99,5 +101,21 @@ module ApplicationTests assert !ActionController.autoload?(:RecordIdentifier) end + + test "runtime error is raised if config.frameworks= is used" do + add_to_config "config.frameworks = []" + + assert_raises RuntimeError do + require "#{app_path}/config/environment" + end + end + + test "runtime error is raised if config.frameworks is used" do + add_to_config "config.frameworks -= []" + + assert_raises RuntimeError do + require "#{app_path}/config/environment" + end + end end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 7b27c780aa..0c858d6394 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -14,7 +14,7 @@ module ApplicationTests end def with_config - require "rails" + require "rails/all" require "rails/generators" yield app_const.config end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 42fc416faa..3fd0b0e5df 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -7,7 +7,7 @@ module ApplicationTests def setup build_app boot_rails - require "rails" + FileUtils.rm_rf "#{app_path}/config/environments" end test "initializing an application adds the application paths to the load path" do @@ -51,8 +51,9 @@ module ApplicationTests assert_nothing_raised NameError do add_to_config <<-RUBY config.root = "#{app_path}" - config.frameworks = [] RUBY + + use_frameworks [] require "#{app_path}/config/environment" end end @@ -160,6 +161,7 @@ module ApplicationTests def setup build_app boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" end test "database middleware doesn't initialize when activerecord is not in frameworks" do diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 8229e83147..b57e829cca 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -18,6 +18,7 @@ module ApplicationTests def setup build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") require "active_support/notifications" @events = [] diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 567555fdc5..2cba42551e 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -63,10 +63,11 @@ class AppGeneratorTest < GeneratorsTestCase assert_no_file "config/database.yml" end - def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] - assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ - end + # TODO: Bring this back using requires + # def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given + # run_generator ["--skip-activerecord"] + # assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ + # end def test_prototype_and_test_unit_are_added_by_default run_generator diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index a2c07ece75..311f19a28a 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -19,14 +19,14 @@ module InitializerTests def assert_rails_boots assert_nothing_raised "It appears that rails does not boot" do - require "rails" + require "rails/all" end end def assert_rails_does_not_boot $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do - require "rails" + require "rails/all" end end end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 3bbf9617a0..bfb1887d11 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -7,14 +7,14 @@ module InitializerTests def setup build_app boot_rails - require "rails" + FileUtils.rm_rf("#{app_path}/config/environments") add_to_config <<-RUBY config.root = "#{app_path}" - config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] config.after_initialize do ActionController::Base.session_store = nil end RUBY + use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] require "#{app_path}/config/environment" @paths = Rails.application.config.paths end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index ee0a812b47..dc5fddb19d 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -207,6 +207,6 @@ Module.new do `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f| f.puts "require '#{environment}'" if require_environment - f.puts "require 'rails'" + f.puts "require 'rails/all'" end end diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index 5786316d1d..25bf24eb3b 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -5,27 +5,27 @@ module PluginsTest def setup build_app boot_rails - require "rails" + require "rails/all" end test "config is available to plugins" do - class Foo < Rails::Plugin ; end + class Foo < Rails::Railtie ; end assert_nil Foo.config.action_controller.foo end test "a config name is available for the plugin" do - class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end assert_equal "hello", Foo.config.foo.greetings end test "plugin configurations are available in the application" do - class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end require "#{app_path}/config/application" assert_equal "hello", AppTemplate::Application.config.foo.greetings end test "plugin config merges are deep" do - class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end + class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end class MyApp < Rails::Application config.foo.bar = "bar" end diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb index a6c7b753f8..c920db77aa 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/plugins/framework_extension_test.rb @@ -7,13 +7,14 @@ module PluginsTest def setup build_app boot_rails - require "rails" + FileUtils.rm_rf("#{app_path}/config/environments") + require "rails/all" end test "rake_tasks block is executed when MyApp.load_tasks is called" do $ran_block = false - class MyPlugin < Rails::Plugin + class MyTie < Rails::Railtie rake_tasks do $ran_block = true end @@ -37,6 +38,7 @@ module PluginsTest def setup build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") end test "active_record extensions are applied to ActiveRecord" do |