aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/commands/plugin.rb47
-rw-r--r--railties/lib/commands/process/spawner.rb4
-rw-r--r--railties/lib/console_with_helpers.rb2
-rw-r--r--railties/lib/initializer.rb83
-rw-r--r--railties/lib/performance_test_help.rb5
-rw-r--r--railties/lib/rails/plugin/locator.rb2
-rw-r--r--railties/lib/rails_generator/commands.rb25
-rw-r--r--railties/lib/rails_generator/generators/applications/app/app_generator.rb1
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold/USAGE14
-rw-r--r--railties/lib/rails_generator/lookup.rb2
-rw-r--r--railties/lib/rails_generator/scripts.rb2
-rw-r--r--railties/lib/rails_generator/scripts/destroy.rb13
-rw-r--r--railties/lib/rails_generator/secret_key_generator.rb2
-rw-r--r--railties/lib/tasks/annotations.rake19
-rw-r--r--railties/lib/tasks/databases.rake34
-rw-r--r--railties/lib/tasks/misc.rake2
16 files changed, 148 insertions, 109 deletions
diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb
index ce4b0d051d..0256090d16 100644
--- a/railties/lib/commands/plugin.rb
+++ b/railties/lib/commands/plugin.rb
@@ -43,6 +43,16 @@
# plugin is pulled via `svn checkout` or `svn export` but looks
# exactly the same.
#
+# Specifying revisions:
+#
+# * Subversion revision is a single integer.
+#
+# * Git revision format:
+# - full - 'refs/tags/1.8.0' or 'refs/heads/experimental'
+# - short: 'experimental' (equivalent to 'refs/heads/experimental')
+# 'tag 1.8.0' (equivalent to 'refs/tags/1.8.0')
+#
+#
# This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com)
# and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php)
@@ -175,7 +185,7 @@ class Plugin
method ||= rails_env.best_install_method?
if :http == method
method = :export if svn_url?
- method = :clone if git_url?
+ method = :git if git_url?
end
uninstall if installed? and options[:force]
@@ -255,8 +265,25 @@ class Plugin
end
end
- def install_using_clone(options = {})
- git_command :clone, options
+ def install_using_git(options = {})
+ root = rails_env.root
+ install_path = mkdir_p "#{root}/vendor/plugins/#{name}"
+ Dir.chdir install_path do
+ init_cmd = "git init"
+ init_cmd += " -q" if options[:quiet] and not $verbose
+ puts init_cmd if $verbose
+ system(init_cmd)
+ base_cmd = "git pull --depth 1 #{uri}"
+ base_cmd += " -q" if options[:quiet] and not $verbose
+ base_cmd += " #{options[:revision]}" if options[:revision]
+ puts base_cmd if $verbose
+ if system(base_cmd)
+ puts "removing: .git" if $verbose
+ rm_rf ".git"
+ else
+ rm_rf install_path
+ end
+ end
end
def svn_command(cmd, options = {})
@@ -268,16 +295,6 @@ class Plugin
puts base_cmd if $verbose
system(base_cmd)
end
-
- def git_command(cmd, options = {})
- root = rails_env.root
- mkdir_p "#{root}/vendor/plugins"
- base_cmd = "git #{cmd} --depth 1 #{uri} \"#{root}/vendor/plugins/#{name}\""
- puts base_cmd if $verbose
- puts "removing: #{root}/vendor/plugins/#{name}/.git"
- system(base_cmd)
- rm_rf "#{root}/vendor/plugins/#{name}/.git"
- end
def guess_name(url)
@name = File.basename(url)
@@ -756,8 +773,8 @@ module Commands
"Suppresses the output from installation.",
"Ignored if -v is passed (./script/plugin -v install ...)") { |v| @options[:quiet] = true }
o.on( "-r REVISION", "--revision REVISION",
- "Checks out the given revision from subversion.",
- "Ignored if subversion is not used.") { |v| @options[:revision] = v }
+ "Checks out the given revision from subversion or git.",
+ "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
o.on( "-f", "--force",
"Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
o.separator ""
diff --git a/railties/lib/commands/process/spawner.rb b/railties/lib/commands/process/spawner.rb
index fd09daa55b..dc0008698a 100644
--- a/railties/lib/commands/process/spawner.rb
+++ b/railties/lib/commands/process/spawner.rb
@@ -66,9 +66,9 @@ class MongrelSpawner < Spawner
"-l #{OPTIONS[:rails_root]}/log/mongrel.log"
# Add prefix functionality to spawner's call to mongrel_rails
- # Digging through monrel's project subversion server, the earliest
+ # Digging through mongrel's project subversion server, the earliest
# Tag that has prefix implemented in the bin/mongrel_rails file
- # is 0.3.15 which also happens to be the earilest tag listed.
+ # is 0.3.15 which also happens to be the earliest tag listed.
# References: http://mongrel.rubyforge.org/svn/tags
if Mongrel::Const::MONGREL_VERSION.to_f >=0.3 && !OPTIONS[:prefix].nil?
cmd = cmd + " --prefix #{OPTIONS[:prefix]}"
diff --git a/railties/lib/console_with_helpers.rb b/railties/lib/console_with_helpers.rb
index 79018a9f76..be453a6896 100644
--- a/railties/lib/console_with_helpers.rb
+++ b/railties/lib/console_with_helpers.rb
@@ -16,7 +16,7 @@ def helper(*helper_names)
end
end
-require 'application'
+require_dependency 'application'
class << helper
include_all_modules_from ActionView
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 3d94cedb47..b8b071d4c9 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -19,15 +19,23 @@ module Rails
def configuration
@@configuration
end
-
+
def configuration=(configuration)
@@configuration = configuration
end
-
+
+ def initialized?
+ @initialized || false
+ end
+
+ def initialized=(initialized)
+ @initialized ||= initialized
+ end
+
def logger
RAILS_DEFAULT_LOGGER
end
-
+
def root
if defined?(RAILS_ROOT)
RAILS_ROOT
@@ -35,11 +43,11 @@ module Rails
nil
end
end
-
+
def env
ActiveSupport::StringInquirer.new(RAILS_ENV)
end
-
+
def cache
RAILS_CACHE
end
@@ -56,7 +64,7 @@ module Rails
@@public_path = path
end
end
-
+
# The Initializer is responsible for processing the Rails configuration, such
# as setting the $LOAD_PATH, requiring the right frameworks, initializing
# logging, and more. It can be run either as a single command that'll just
@@ -90,7 +98,7 @@ module Rails
# Rails::Initializer.run(:set_load_path)
#
# This is useful if you only want the load path initialized, without
- # incuring the overhead of completely loading the entire environment.
+ # incurring the overhead of completely loading the entire environment.
def self.run(command = :process, configuration = Configuration.new)
yield configuration if block_given?
initializer = new configuration
@@ -129,12 +137,12 @@ module Rails
initialize_logger
initialize_framework_logging
- initialize_framework_views
initialize_dependency_mechanism
initialize_whiny_nils
initialize_temporary_session_directory
initialize_time_zone
initialize_framework_settings
+ initialize_framework_views
add_support_load_paths
@@ -145,7 +153,7 @@ module Rails
add_gem_load_paths
load_gems
check_gem_dependencies
-
+
load_application_initializers
# the framework is now fully initialized
@@ -158,8 +166,10 @@ module Rails
initialize_routing
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
-
load_observers
+
+ # Flag initialized
+ Rails.initialized = true
end
# Check for valid Ruby version
@@ -256,11 +266,16 @@ module Rails
@gems_dependencies_loaded = false
# don't print if the gems rake tasks are being run
unless $rails_gem_installer
- puts %{These gems that this application depends on are missing:}
- unloaded_gems.each do |gem|
- puts " - #{gem.name}"
- end
- puts %{Run "rake gems:install" to install them.}
+ abort <<-end_error
+Missing these required gems:
+ #{unloaded_gems.map { |gem| "#{gem.name} #{gem.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
@gems_dependencies_loaded = true
@@ -297,12 +312,12 @@ module Rails
silence_warnings do
return if @environment_loaded
@environment_loaded = true
-
+
config = configuration
constants = self.class.constants
-
+
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
-
+
(self.class.constants - constants).each do |const|
Object.const_set(const, self.class.const_get(const))
end
@@ -390,7 +405,7 @@ module Rails
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
end
-
+
RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER
end
@@ -399,8 +414,11 @@ module Rails
# paths have already been set, it is not changed, otherwise it is
# set to use Configuration#view_path.
def initialize_framework_views
- ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer)
- ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
+ ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
+ view_path = ActionView::PathSet::Path.new(configuration.view_path)
+
+ ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
+ ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
end
# If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
@@ -486,7 +504,6 @@ module Rails
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
end
-
end
# The Configuration class holds all the parameters for the Initializer and
@@ -514,7 +531,7 @@ module Rails
# A stub for setting options on ActiveRecord::Base.
attr_accessor :active_record
- # A stub for setting options on ActiveRecord::Base.
+ # A stub for setting options on ActiveResource::Base.
attr_accessor :active_resource
# A stub for setting options on ActiveSupport.
@@ -531,7 +548,7 @@ module Rails
# The path to the database configuration file to use. (Defaults to
# <tt>config/database.yml</tt>.)
attr_accessor :database_configuration_file
-
+
# The path to the routes configuration file to use. (Defaults to
# <tt>config/routes.rb</tt>.)
attr_accessor :routes_configuration_file
@@ -597,7 +614,7 @@ module Rails
# a sub class would have access to fine grained modification of the loading behavior. See
# the implementation of Rails::Plugin::Loader for more details.
attr_accessor :plugin_loader
-
+
# Enables or disables plugin reloading. You can get around this setting per plugin.
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
# to make it reloadable:
@@ -634,7 +651,7 @@ module Rails
def gem(name, options = {})
@gems << Rails::GemDependency.new(name, options)
end
-
+
# Deprecated options:
def breakpoint_server(_ = nil)
$stderr.puts %(
@@ -693,7 +710,7 @@ module Rails
else
Pathname.new(::RAILS_ROOT).realpath.to_s
end
-
+
Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
::RAILS_ROOT.replace @root_path
end
@@ -734,7 +751,7 @@ module Rails
#
# See Dispatcher#to_prepare.
def to_prepare(&callback)
- after_initialize do
+ after_initialize do
require 'dispatcher' unless defined?(::Dispatcher)
Dispatcher.to_prepare(&callback)
end
@@ -748,11 +765,11 @@ module Rails
def framework_paths
paths = %w(railties railties/lib activesupport/lib)
paths << 'actionpack/lib' if frameworks.include? :action_controller or 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
@@ -767,7 +784,7 @@ module Rails
def default_load_paths
paths = []
-
+
# Add the old mock paths only if the directories exists
paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
@@ -853,7 +870,7 @@ module Rails
def default_plugin_loader
Plugin::Loader
end
-
+
def default_cache_store
if File.exist?("#{root_path}/tmp/cache/")
[ :file_store, "#{root_path}/tmp/cache/" ]
@@ -861,7 +878,7 @@ module Rails
:memory_store
end
end
-
+
def default_gems
[]
end
diff --git a/railties/lib/performance_test_help.rb b/railties/lib/performance_test_help.rb
new file mode 100644
index 0000000000..5148b4ab77
--- /dev/null
+++ b/railties/lib/performance_test_help.rb
@@ -0,0 +1,5 @@
+require 'action_controller/performance_test'
+
+ActionController::Base.perform_caching = true
+ActiveSupport::Dependencies.mechanism = :require
+Rails.logger.level = ActiveSupport::BufferedLogger::INFO
diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb
index 79c07fccd1..678b295dc9 100644
--- a/railties/lib/rails/plugin/locator.rb
+++ b/railties/lib/rails/plugin/locator.rb
@@ -63,7 +63,7 @@ module Rails
# => <Rails::Plugin name: 'acts_as_chunky_bacon' ... >
#
def locate_plugins_under(base_path)
- Dir.glob(File.join(base_path, '*')).inject([]) do |plugins, path|
+ Dir.glob(File.join(base_path, '*')).sort.inject([]) do |plugins, path|
if plugin = create_plugin(path)
plugins << plugin
elsif File.directory?(path)
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb
index fb62ba6940..d258aeaa0a 100644
--- a/railties/lib/rails_generator/commands.rb
+++ b/railties/lib/rails_generator/commands.rb
@@ -154,35 +154,28 @@ HELP
# Ruby or Rails. In the future, expand to check other namespaces
# such as the rest of the user's app.
def class_collisions(*class_names)
-
- # Initialize some check varibles
- last_class = Object
- current_class = nil
- name = nil
-
class_names.flatten.each do |class_name|
# Convert to string to allow symbol arguments.
class_name = class_name.to_s
# Skip empty strings.
- class_name.strip.empty? ? next : current_class = class_name
+ next if class_name.strip.empty?
# Split the class from its module nesting.
nesting = class_name.split('::')
name = nesting.pop
# Extract the last Module in the nesting.
- last = nesting.inject(last_class) { |last, nest|
- break unless last_class.const_defined?(nest)
- last_class = last_class.const_get(nest)
+ last = nesting.inject(Object) { |last, nest|
+ break unless last.const_defined?(nest)
+ last.const_get(nest)
}
- end
- # If the last Module exists, check whether the given
- # class exists and raise a collision if so.
-
- if last_class and last_class.const_defined?(name.camelize)
- raise_class_collision(current_class)
+ # If the last Module exists, check whether the given
+ # class exists and raise a collision if so.
+ if last and last.const_defined?(name.camelize)
+ raise_class_collision(class_name)
+ end
end
end
diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb
index 80e8eabfd3..98fe163455 100644
--- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb
+++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb
@@ -46,6 +46,7 @@ class AppGenerator < Rails::Generator::Base
# Root
m.file "fresh_rakefile", "Rakefile"
m.file "README", "README"
+ m.file "config.ru", "config.ru"
# Application
m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest }
diff --git a/railties/lib/rails_generator/generators/components/scaffold/USAGE b/railties/lib/rails_generator/generators/components/scaffold/USAGE
index a0e4baea08..810aea16f1 100644
--- a/railties/lib/rails_generator/generators/components/scaffold/USAGE
+++ b/railties/lib/rails_generator/generators/components/scaffold/USAGE
@@ -1,10 +1,11 @@
Description:
Scaffolds an entire resource, from model and migration to controller and
views, along with a full test suite. The resource is ready to use as a
- starting point for your restful, resource-oriented application.
+ starting point for your RESTful, resource-oriented application.
- Pass the name of the model, either CamelCased or under_scored, as the first
- argument, and an optional list of attribute pairs.
+ Pass the name of the model (in singular form), either CamelCased or
+ under_scored, as the first argument, and an optional list of attribute
+ pairs.
Attribute pairs are column_name:sql_type arguments specifying the
model's attributes. Timestamps are added by default, so you don't have to
@@ -13,13 +14,16 @@ Description:
You don't have to think up every attribute up front, but it helps to
sketch out a few so you can start working with the resource immediately.
- For example, `scaffold post title:string body:text published:boolean`
+ For example, 'scaffold post title:string body:text published:boolean'
gives you a model with those three attributes, a controller that handles
the create/show/update/destroy, forms to create and edit your posts, and
an index that lists them all, as well as a map.resources :posts
declaration in config/routes.rb.
+ If you want to remove all the generated files, run
+ 'script/destroy scaffold ModelName'.
+
Examples:
- `./script/generate scaffold post` # no attributes, view will be anemic
+ `./script/generate scaffold post`
`./script/generate scaffold post title:string body:text published:boolean`
`./script/generate scaffold purchase order_id:integer amount:decimal`
diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb
index 1f28c39d55..0526d526ad 100644
--- a/railties/lib/rails_generator/lookup.rb
+++ b/railties/lib/rails_generator/lookup.rb
@@ -108,7 +108,7 @@ module Rails
sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators")
Rails.configuration.plugin_paths.each do |path|
relative_path = Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(::RAILS_ROOT))
- sources << PathSource.new(:"plugins (#{relative_path})", "#{path}/**/{,rails_}generators")
+ sources << PathSource.new(:"plugins (#{relative_path})", "#{path}/*/**/{,rails_}generators")
end
end
sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators")
diff --git a/railties/lib/rails_generator/scripts.rb b/railties/lib/rails_generator/scripts.rb
index f857f68de4..9b1a99838a 100644
--- a/railties/lib/rails_generator/scripts.rb
+++ b/railties/lib/rails_generator/scripts.rb
@@ -45,7 +45,7 @@ module Rails
usage = "\nInstalled Generators\n"
Rails::Generator::Base.sources.inject([]) do |mem, source|
# Using an association list instead of a hash to preserve order,
- # for esthetic reasons more than anything else.
+ # for aesthetic reasons more than anything else.
label = source.label.to_s.capitalize
pair = mem.assoc(label)
mem << (pair = [label, []]) if pair.nil?
diff --git a/railties/lib/rails_generator/scripts/destroy.rb b/railties/lib/rails_generator/scripts/destroy.rb
index 4fcbc3e0df..a7c2a14751 100644
--- a/railties/lib/rails_generator/scripts/destroy.rb
+++ b/railties/lib/rails_generator/scripts/destroy.rb
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../scripts'
module Rails::Generator::Scripts
class Destroy < Base
mandatory_options :command => :destroy
-
+
protected
def usage_message
usage = "\nInstalled Generators\n"
@@ -15,14 +15,13 @@ module Rails::Generator::Scripts
usage << <<end_blurb
-This script will destroy all files created by the corresponding
-script/generate command. For instance, script/destroy migration CreatePost
-will delete the appropriate ###_create_post.rb file in db/migrate, while
-script/destroy scaffold Post will delete the posts controller and
+script/generate command. For instance, 'script/destroy migration CreatePost'
+will delete the appropriate XXX_create_post.rb migration file in db/migrate,
+while 'script/destroy scaffold Post' will delete the posts controller and
views, post model and migration, all associated tests, and the map.resources
:posts line in config/routes.rb.
-
-For instructions on finding new generators, run script/generate
+
+For instructions on finding new generators, run script/generate.
end_blurb
return usage
end
diff --git a/railties/lib/rails_generator/secret_key_generator.rb b/railties/lib/rails_generator/secret_key_generator.rb
index 64fbbb90f8..5ae492312e 100644
--- a/railties/lib/rails_generator/secret_key_generator.rb
+++ b/railties/lib/rails_generator/secret_key_generator.rb
@@ -23,7 +23,7 @@ module Rails
# Generate a random secret key by using the Win32 API. Raises LoadError
# if the current platform cannot make use of the Win32 API. Raises
- # SystemCallError if some other error occured.
+ # SystemCallError if some other error occurred.
def generate_secret_with_win32_api
# Following code is based on David Garamond's GUID library for Ruby.
require 'Win32API'
diff --git a/railties/lib/tasks/annotations.rake b/railties/lib/tasks/annotations.rake
index ea6046670f..48ac40099a 100644
--- a/railties/lib/tasks/annotations.rake
+++ b/railties/lib/tasks/annotations.rake
@@ -6,18 +6,15 @@ task :notes do
end
namespace :notes do
- desc "Enumerate all OPTIMIZE annotations"
- task :optimize do
- SourceAnnotationExtractor.enumerate "OPTIMIZE"
+ ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
+ desc "Enumerate all #{annotation} annotations"
+ task annotation.downcase.intern do
+ SourceAnnotationExtractor.enumerate annotation
+ end
end
- desc "Enumerate all FIXME annotations"
- task :fixme do
- SourceAnnotationExtractor.enumerate "FIXME"
- end
-
- desc "Enumerate all TODO annotations"
- task :todo do
- SourceAnnotationExtractor.enumerate "TODO"
+ desc "Enumerate a custom annotation, specify with ANNOTATION=WTFHAX"
+ task :custom do
+ SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
end
end \ No newline at end of file
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake
index 75fba8b45a..5ec712a02d 100644
--- a/railties/lib/tasks/databases.rake
+++ b/railties/lib/tasks/databases.rake
@@ -141,6 +141,9 @@ namespace :db do
when 'mysql'
ActiveRecord::Base.establish_connection(config)
puts ActiveRecord::Base.connection.charset
+ when 'postgresql'
+ ActiveRecord::Base.establish_connection(config)
+ puts ActiveRecord::Base.connection.encoding
else
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
end
@@ -179,12 +182,15 @@ namespace :db do
end
namespace :fixtures do
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
+ desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
task :load => :environment do
require 'active_record/fixtures'
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
- Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
+ ActiveRecord::Base.establish_connection(Rails.env)
+ base_dir = File.join(Rails.root, 'test', 'fixtures')
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
+
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
end
end
@@ -215,14 +221,14 @@ namespace :db do
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
task :dump => :environment do
require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
+ File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
desc "Load a schema.rb file into the database"
task :load => :environment do
- file = ENV['SCHEMA'] || "db/schema.rb"
+ file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
load(file)
end
end
@@ -234,7 +240,7 @@ namespace :db do
case abcs[RAILS_ENV]["adapter"]
when "mysql", "oci", "oracle"
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
- File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
+ File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
when "postgresql"
ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
@@ -252,13 +258,13 @@ namespace :db do
when "firebird"
set_firebird_env(abcs[RAILS_ENV])
db_string = firebird_db_string(abcs[RAILS_ENV])
- sh "isql -a #{db_string} > db/#{RAILS_ENV}_structure.sql"
+ sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
if ActiveRecord::Base.connection.supports_migrations?
- File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
+ File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end
end
end
@@ -281,28 +287,28 @@ namespace :db do
when "mysql"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
- IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
+ IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table)
end
when "postgresql"
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
- `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
+ `psql -U "#{abcs["test"]["username"]}" -f #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
when "sqlite", "sqlite3"
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
- `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql`
+ `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql`
when "sqlserver"
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
- IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
+ IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl)
end
when "firebird"
set_firebird_env(abcs["test"])
db_string = firebird_db_string(abcs["test"])
- sh "isql -i db/#{RAILS_ENV}_structure.sql #{db_string}"
+ sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake
index 61042595f9..33bbba1101 100644
--- a/railties/lib/tasks/misc.rake
+++ b/railties/lib/tasks/misc.rake
@@ -44,7 +44,7 @@ namespace :time do
end
end
previous_offset = nil
- TimeZone.__send__(method).each do |zone|
+ ActiveSupport::TimeZone.__send__(method).each do |zone|
if offset.nil? || offset == zone.utc_offset
puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset
puts zone.name