aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application.rb65
-rw-r--r--railties/lib/rails/configuration.rb21
-rw-r--r--railties/lib/rails/deprecation.rb10
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/boot.rb19
-rw-r--r--railties/lib/rails/plugin/locator.rb2
-rw-r--r--railties/lib/rails/tasks/databases.rake2
-rw-r--r--railties/test/backtrace_cleaner_test.rb2
-rw-r--r--railties/test/gem_dependency_test.rb220
-rw-r--r--railties/test/generators/actions_test.rb2
-rw-r--r--railties/test/generators_test.rb6
-rw-r--r--railties/test/rails_info_controller_test.rb12
12 files changed, 40 insertions, 327 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 521e1cafb6..943c939757 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -311,31 +311,6 @@ module Rails
end
end
- initializer :check_for_unbuilt_gems do
- unbuilt_gems = config.gems.select {|gem| gem.frozen? && !gem.built? }
- if unbuilt_gems.size > 0
- # don't print if the gems:build rake tasks are being run
- unless $gems_build_rake_task
- abort <<-end_error
- The following gems have native components that need to be built
- #{unbuilt_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "}
-
- You're running:
- ruby #{Gem.ruby_version} at #{Gem.ruby}
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
- Run `rake gems:build` to build the unbuilt gems.
- end_error
- end
- end
- end
-
- initializer :load_gems do
- unless $gems_rake_task
- config.gems.each { |gem| gem.load }
- end
- end
-
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
# defaults to <tt>vendor/plugins</tt> but may also be set to a list of
# paths, such as
@@ -356,49 +331,19 @@ module Rails
plugin_loader.load_plugins
end
- # TODO: Figure out if this needs to run a second time
- # load_gems
-
- initializer :check_gem_dependencies do
- unloaded_gems = config.gems.reject { |g| g.loaded? }
- if unloaded_gems.size > 0
- configuration.gems_dependencies_loaded = false
- # don't print if the gems rake tasks are being run
- unless $gems_rake_task
- abort <<-end_error
- Missing these required gems:
- #{unloaded_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "}
-
- You're running:
- ruby #{Gem.ruby_version} at #{Gem.ruby}
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
- Run `rake gems:install` to install the missing gems.
- end_error
- end
- else
- configuration.gems_dependencies_loaded = true
- end
- end
-
# # bail out if gems are missing - note that check_gem_dependencies will have
# # already called abort() unless $gems_rake_task is set
# return unless gems_dependencies_loaded
-
initializer :load_application_initializers do
- if config.gems_dependencies_loaded
- Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer|
- load(initializer)
- end
+ Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer|
+ load(initializer)
end
end
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
initializer :after_initialize do
- if config.gems_dependencies_loaded
- configuration.after_initialize_blocks.each do |block|
- block.call
- end
+ configuration.after_initialize_blocks.each do |block|
+ block.call
end
end
@@ -440,7 +385,7 @@ module Rails
#
# # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
initializer :load_observers do
- if config.gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
+ if configuration.frameworks.include?(:active_record)
ActiveRecord::Base.instantiate_observers
end
end
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index ce9c899400..1a7483c548 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -4,7 +4,7 @@ require 'rails/plugin/locator'
module Rails
class Configuration
attr_accessor :cache_classes, :load_paths,
- :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks,
+ :load_once_paths, :after_initialize_blocks,
:frameworks, :framework_root_path, :root, :plugin_paths, :plugins,
:plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins,
:i18n, :gems, :whiny_nils, :consider_all_requests_local,
@@ -230,25 +230,6 @@ module Rails
end
end
- # Adds a single Gem dependency to the rails application. By default, it will require
- # the library with the same name as the gem. Use :lib to specify a different name.
- #
- # # gem 'aws-s3', '>= 0.4.0'
- # # require 'aws/s3'
- # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
- # :source => "http://code.whytheluckystiff.net"
- #
- # To require a library be installed, but not attempt to load it, pass :lib => false
- #
- # config.gem 'qrp', :version => '0.4.1', :lib => false
- def gem(name, options = {})
- gems << Rails::GemDependency.new(name, options)
- end
-
- def gems
- @gems ||= []
- end
-
def environment_path
"#{root}/config/environments/#{RAILS_ENV}.rb"
end
diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb
index 42bba151d6..3c5b8bdec7 100644
--- a/railties/lib/rails/deprecation.rb
+++ b/railties/lib/rails/deprecation.rb
@@ -14,4 +14,12 @@ RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
msg = "RAILS_ROOT is deprecated! Use Rails.root instead."
ActiveSupport::Deprecation.warn(msg, callstack)
end
-end).new \ No newline at end of file
+end).new
+
+module Rails
+ class Configuration
+ def gem(*args)
+ ActiveSupport::Deprecation.warn("config.gem has been deprecated in favor of the Gemfile.")
+ end
+ end
+end \ No newline at end of file
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 7ba7c52f9e..bb30136686 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -8,12 +8,6 @@ Rails::Initializer.run do |config|
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{root}/extras )
- # Specify gems that this application depends on and have them installed with rake gems:install
- # config.gem "bj"
- # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
- # config.gem "sqlite3-ruby", :lib => "sqlite3"
- # config.gem "aws-s3", :lib => "aws/s3"
-
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
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 3165a4091e..5aa49ca5e6 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -1,15 +1,16 @@
-# Package management
-# Choose one
-
# Use Bundler (preferred)
environment = File.expand_path('../../vendor/gems/environment', __FILE__)
-require environment if File.exist?(environment)
+if File.exist?("#{environment}.rb")
+ require environment
-# Use 2.x style vendor/rails directory
-vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
-Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) } if File.exist?(vendor_rails)
+# Use 2.x style vendor/rails and RubyGems
+else
+ vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
+ if File.exist?(vendor_rails)
+ Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
+ end
-# Load Rails from traditional RubyGems
-require 'rubygems'
+ require 'rubygems'
+end
require 'rails'
diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb
index 1057c004e0..56cbaf37c6 100644
--- a/railties/lib/rails/plugin/locator.rb
+++ b/railties/lib/rails/plugin/locator.rb
@@ -78,7 +78,7 @@ module Rails
# a <tt>rails/init.rb</tt> file.
class GemLocator < Locator
def plugins
- gem_index = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem }
+ gem_index = {}
specs = gem_index.keys
specs += Gem.loaded_specs.values.select do |spec|
spec.loaded_from && # prune stubs
diff --git a/railties/lib/rails/tasks/databases.rake b/railties/lib/rails/tasks/databases.rake
index 70b59625f8..a35a6c156b 100644
--- a/railties/lib/rails/tasks/databases.rake
+++ b/railties/lib/rails/tasks/databases.rake
@@ -295,7 +295,7 @@ namespace :db do
if File.exists?(file)
load(file)
else
- abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
end
end
end
diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb
index 0319d5f38c..64a47712b7 100644
--- a/railties/test/backtrace_cleaner_test.rb
+++ b/railties/test/backtrace_cleaner_test.rb
@@ -35,7 +35,7 @@ class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
end
test "should format installed gems correctly" do
- @backtrace = [ "#{Gem.default_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
@result = @cleaner.clean(@backtrace)
assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
end
diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
deleted file mode 100644
index 92132be992..0000000000
--- a/railties/test/gem_dependency_test.rb
+++ /dev/null
@@ -1,220 +0,0 @@
-require 'plugin_test_helper'
-require 'rails/gem_dependency'
-
-class Rails::GemDependency
- public :install_command, :unpack_command
-end
-
-Rails::VendorGemSourceIndex.silence_spec_warnings = true
-
-class GemDependencyTest < Test::Unit::TestCase
- def setup
- @gem = Rails::GemDependency.new "xhpricotx"
- @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net"
- @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6"
- @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3"
- @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false
- end
-
- def test_configuration_adds_gem_dependency
- config = Rails::Configuration.new
- config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0"
- assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect { |g| g.install_command }
- end
-
- def test_gem_creates_install_command
- assert_equal %w(install xhpricotx), @gem.install_command
- end
-
- def test_gem_with_source_creates_install_command
- assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command
- end
-
- def test_gem_with_version_creates_install_command
- assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command
- end
-
- def test_gem_creates_unpack_command
- assert_equal %w(unpack xhpricotx), @gem.unpack_command
- end
-
- def test_gem_with_version_unpack_install_command
- # stub out specification method, or else test will fail if hpricot 0.6 isn't installed
- mock_spec = mock()
- mock_spec.stubs(:version).returns('0.6')
- @gem_with_version.stubs(:specification).returns(mock_spec)
- assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command
- end
-
- def test_gem_adds_load_paths
- @gem.expects(:gem).with(@gem)
- @gem.add_load_paths
- end
-
- def test_gem_with_version_adds_load_paths
- @gem_with_version.expects(:gem).with(@gem_with_version)
- @gem_with_version.add_load_paths
- assert @gem_with_version.load_paths_added?
- end
-
- def test_gem_loading
- @gem.expects(:gem).with(@gem)
- @gem.expects(:require).with(@gem.name)
- @gem.add_load_paths
- @gem.load
- assert @gem.loaded?
- end
-
- def test_gem_with_lib_loading
- @gem_with_lib.expects(:gem).with(@gem_with_lib)
- @gem_with_lib.expects(:require).with(@gem_with_lib.lib)
- @gem_with_lib.add_load_paths
- @gem_with_lib.load
- assert @gem_with_lib.loaded?
- end
-
- def test_gem_without_lib_loading
- @gem_without_load.expects(:gem).with(@gem_without_load)
- @gem_without_load.expects(:require).with(@gem_without_load.lib).never
- @gem_without_load.add_load_paths
- @gem_without_load.load
- end
-
- def test_gem_dependencies_compare_for_uniq
- gem1 = Rails::GemDependency.new "gem1"
- gem1a = Rails::GemDependency.new "gem1"
- gem2 = Rails::GemDependency.new "gem2"
- gem2a = Rails::GemDependency.new "gem2"
- gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1"
- gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1"
- gem4 = Rails::GemDependency.new "gem3"
- gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4]
- assert_equal 4, gems.uniq.size
- end
-
- def test_gem_load_frozen
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_A_VERSION
- end
-
- def test_gem_load_frozen_specific_version
- dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0'
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_B_VERSION
- assert_equal '0.4.0', DUMMY_GEM_B_VERSION
- end
-
- def test_gem_load_frozen_minimum_version
- dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0'
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_C_VERSION
- assert_equal '0.6.0', DUMMY_GEM_C_VERSION
- end
-
- def test_gem_load_missing_specification
- dummy_gem = Rails::GemDependency.new "dummy-gem-d"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_D_VERSION
- assert_equal '1.0.0', DUMMY_GEM_D_VERSION
- assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files
- end
-
- def test_gem_load_bad_specification
- dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_E_VERSION
- assert_equal '1.0.0', DUMMY_GEM_E_VERSION
- end
-
- def test_gem_handle_missing_dependencies
- dummy_gem = Rails::GemDependency.new "dummy-gem-g"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_equal 1, dummy_gem.dependencies.size
- assert_equal 1, dummy_gem.dependencies.first.dependencies.size
- assert_nothing_raised do
- dummy_gem.dependencies.each do |g|
- g.dependencies
- end
- end
- end
-
- def test_gem_ignores_development_dependencies
- dummy_gem = Rails::GemDependency.new "dummy-gem-k"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_equal 1, dummy_gem.dependencies.size
- end
-
- def test_gem_guards_against_duplicate_unpacks
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.stubs(:frozen?).returns(true)
- dummy_gem.expects(:unpack_base).never
- dummy_gem.unpack
- end
-
- def test_gem_does_not_unpack_framework_gems
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.stubs(:framework_gem?).returns(true)
- dummy_gem.expects(:unpack_base).never
- dummy_gem.unpack
- end
-
- def test_gem_from_directory_name_attempts_to_load_specification
- assert_raises RuntimeError do
- dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1')
- end
- end
-
- def test_gem_from_directory_name
- dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1', false)
- assert_equal 'dummy-gem', dummy_gem.name
- assert_equal '= 1.1', dummy_gem.version_requirements.to_s
- end
-
- def test_gem_from_directory_name_loads_specification_successfully
- assert_nothing_raised do
- dummy_gem = Rails::GemDependency.from_directory_name(File.join(Rails::GemDependency.unpacked_path, 'dummy-gem-g-1.0.0'))
- assert_not_nil dummy_gem.specification
- end
- end
-
- def test_gem_from_invalid_directory_name
- assert_raises RuntimeError do
- dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem')
- end
- assert_raises RuntimeError do
- dummy_gem = Rails::GemDependency.from_directory_name('dummy')
- end
- end
-
- def test_gem_determines_build_status
- assert_equal true, Rails::GemDependency.new("dummy-gem-a").built?
- assert_equal true, Rails::GemDependency.new("dummy-gem-i").built?
- assert_equal false, Rails::GemDependency.new("dummy-gem-j").built?
- end
-
- def test_gem_determines_build_status_only_on_vendor_gems
- framework_gem = Rails::GemDependency.new('dummy-framework-gem')
- framework_gem.stubs(:framework_gem?).returns(true) # already loaded
- framework_gem.stubs(:vendor_rails?).returns(false) # but not in vendor/rails
- framework_gem.stubs(:vendor_gem?).returns(false) # and not in vendor/gems
- framework_gem.add_load_paths # freeze framework gem early
- assert framework_gem.built?
- end
-
- def test_gem_build_passes_options_to_dependencies
- start_gem = Rails::GemDependency.new("dummy-gem-g")
- dep_gem = Rails::GemDependency.new("dummy-gem-f")
- start_gem.stubs(:dependencies).returns([dep_gem])
- dep_gem.expects(:build).with({ :force => true }).once
- start_gem.build(:force => true)
- end
-
-end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index adc61f6d8a..199b5fa8b4 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -89,7 +89,7 @@ class ActionsTest < GeneratorsTestCase
def test_environment_should_include_data_in_environment_initializer_block
run_generator
- load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]'
+ load_paths = 'config.load_paths += %w["#{Rails.root}/app/extras"]'
action :environment, load_paths
assert_file 'config/application.rb', /#{Regexp.escape(load_paths)}/
end
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 2e19169d3d..178b5ef6de 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -80,7 +80,7 @@ class GeneratorsTest < GeneratorsTestCase
Rails::Generators.instance_variable_set(:@load_paths, nil)
spec = Gem::Specification.new
- spec.expects(:full_gem_path).returns(File.join(RAILS_ROOT, 'vendor', 'another_gem_path', 'xspec'))
+ spec.expects(:full_gem_path).returns(File.join(Rails.root, 'vendor', 'another_gem_path', 'xspec'))
Gem.expects(:respond_to?).with(:loaded_specs).returns(true)
Gem.expects(:loaded_specs).returns(:spec => spec)
@@ -119,7 +119,7 @@ class GeneratorsTest < GeneratorsTestCase
end
def test_rails_root_templates
- template = File.join(RAILS_ROOT, "lib", "templates", "active_record", "model", "model.rb")
+ template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb")
# Create template
mkdir_p(File.dirname(template))
@@ -171,6 +171,6 @@ class GeneratorsTest < GeneratorsTestCase
def test_source_paths_for_not_namespaced_generators
mspec = Rails::Generators.find_by_namespace :mspec
- assert mspec.source_paths.include?(File.join(RAILS_ROOT, "lib", "templates", "mspec"))
+ assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "mspec"))
end
end
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index 99cf9168e1..a0484c0868 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -4,10 +4,6 @@ require 'action_controller'
require 'rails/info'
require 'rails/info_controller'
-ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
-end
-
module ActionController
class Base
include ActionController::Testing
@@ -18,9 +14,17 @@ class InfoControllerTest < ActionController::TestCase
tests Rails::InfoController
def setup
+ ActionController::Routing.use_controllers!(['rails/info'])
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ end
@controller.stubs(:consider_all_requests_local => false, :local_request? => true)
end
+ def teardown
+ ActionController::Routing.use_controllers! nil
+ end
+
test "info controller does not allow remote requests" do
@controller.stubs(:consider_all_requests_local => false, :local_request? => false)
get :properties