aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/commands/dbconsole.rb12
-rw-r--r--railties/lib/generators/actions.rb11
-rw-r--r--railties/lib/generators/active_record/model/model_generator.rb6
-rw-r--r--railties/lib/generators/active_record/session_migration/session_migration_generator.rb6
-rw-r--r--railties/lib/generators/named_base.rb3
-rw-r--r--railties/lib/generators/rails/app/templates/config/boot.rb2
-rw-r--r--railties/lib/generators/test_unit/plugin/templates/test_helper.rb4
-rw-r--r--railties/lib/rails/configuration.rb3
-rw-r--r--railties/lib/tasks/databases.rake14
-rw-r--r--railties/test/generators/actions_test.rb15
-rw-r--r--railties/test/generators/model_generator_test.rb44
-rw-r--r--railties/test/generators/session_migration_generator_test.rb18
-rw-r--r--railties/test/initializer/path_test.rb3
13 files changed, 123 insertions, 18 deletions
diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb
index 8002264f7e..e6f11a45db 100644
--- a/railties/lib/commands/dbconsole.rb
+++ b/railties/lib/commands/dbconsole.rb
@@ -33,11 +33,15 @@ end
def find_cmd(*commands)
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
- commands.detect do |cmd|
- dirs_on_path.detect do |path|
- File.executable? File.join(path, cmd)
+
+ full_path_command = nil
+ found = commands.detect do |cmd|
+ dir = dirs_on_path.detect do |path|
+ full_path_command = File.join(path, cmd)
+ File.executable? full_path_command
end
- end || abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
+ end
+ found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
end
case config["adapter"]
diff --git a/railties/lib/generators/actions.rb b/railties/lib/generators/actions.rb
index 55ef212abb..03d0d11a07 100644
--- a/railties/lib/generators/actions.rb
+++ b/railties/lib/generators/actions.rb
@@ -5,22 +5,31 @@ module Rails
module Actions
# Install a plugin. You must provide either a Subversion url or Git url.
- # For a Git-hosted plugin, you can specify if it should be added as a submodule instead of cloned.
+ #
+ # For a Git-hosted plugin, you can specify a branch and
+ # whether it should be added as a submodule instead of cloned.
+ #
+ # For a Subversion-hosted plugin you can specify a revision.
#
# ==== Examples
#
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
+ # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :branch => 'stable'
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true
# plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk'
+ # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk', :revision => 1234
#
def plugin(name, options)
log :plugin, name
if options[:git] && options[:submodule]
+ options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
in_root do
run "git submodule add #{options[:git]} vendor/plugins/#{name}", :verbose => false
end
elsif options[:git] || options[:svn]
+ options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
+ options[:svn] = "-r #{options[:revision]} #{options[:svn]}" if options[:revision]
in_root do
run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false
end
diff --git a/railties/lib/generators/active_record/model/model_generator.rb b/railties/lib/generators/active_record/model/model_generator.rb
index 54187aede0..2641083e0d 100644
--- a/railties/lib/generators/active_record/model/model_generator.rb
+++ b/railties/lib/generators/active_record/model/model_generator.rb
@@ -12,10 +12,8 @@ module ActiveRecord
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
def create_migration_file
- if options[:migration] && options[:parent].nil?
- file_name = "create_#{file_path.gsub(/\//, '_').pluralize}"
- migration_template "migration.rb", "db/migrate/#{file_name}.rb"
- end
+ return unless options[:migration] && options[:parent].nil?
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
end
def create_model_file
diff --git a/railties/lib/generators/active_record/session_migration/session_migration_generator.rb b/railties/lib/generators/active_record/session_migration/session_migration_generator.rb
index d60da5c0a5..59c4792066 100644
--- a/railties/lib/generators/active_record/session_migration/session_migration_generator.rb
+++ b/railties/lib/generators/active_record/session_migration/session_migration_generator.rb
@@ -12,7 +12,11 @@ module ActiveRecord
protected
def session_table_name
- ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session'
+ current_table_name = ActiveRecord::SessionStore::Session.table_name
+ if ["sessions", "session"].include?(current_table_name)
+ current_table_name = (ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session')
+ end
+ current_table_name
end
end
diff --git a/railties/lib/generators/named_base.rb b/railties/lib/generators/named_base.rb
index 9632e6806c..cd7aa61b50 100644
--- a/railties/lib/generators/named_base.rb
+++ b/railties/lib/generators/named_base.rb
@@ -28,7 +28,6 @@ module Rails
else
singular_name
end
- @table_name.gsub! '/', '_'
if class_nesting.empty?
@class_name = class_name_without_nesting
@@ -36,6 +35,8 @@ module Rails
@table_name = class_nesting.underscore << "_" << @table_name
@class_name = "#{class_nesting}::#{class_name_without_nesting}"
end
+
+ @table_name.gsub!('/', '_')
end
# Convert attributes hash into an array with GeneratedAttribute objects.
diff --git a/railties/lib/generators/rails/app/templates/config/boot.rb b/railties/lib/generators/rails/app/templates/config/boot.rb
index 0ad0f787f8..dd5e3b6916 100644
--- a/railties/lib/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/generators/rails/app/templates/config/boot.rb
@@ -82,8 +82,8 @@ module Rails
end
def load_rubygems
+ min_version = '1.3.2'
require 'rubygems'
- min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
diff --git a/railties/lib/generators/test_unit/plugin/templates/test_helper.rb b/railties/lib/generators/test_unit/plugin/templates/test_helper.rb
index cf148b8b47..348ec33582 100644
--- a/railties/lib/generators/test_unit/plugin/templates/test_helper.rb
+++ b/railties/lib/generators/test_unit/plugin/templates/test_helper.rb
@@ -1,3 +1,5 @@
require 'rubygems'
+require 'test/unit'
require 'active_support'
-require 'active_support/test_case' \ No newline at end of file
+require 'active_support/test_case'
+
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index fe3cb67d3a..5cc4f80684 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -71,7 +71,8 @@ module Rails
@paths.lib "lib", :load_path => true
@paths.vendor "vendor", :load_path => true
@paths.vendor.plugins "vendor/plugins"
- @paths.cache "tmp/cache"
+ @paths.tmp "tmp"
+ @paths.tmp.cache "tmp/cache"
@paths.config "config"
@paths.config.locales "config/locales"
@paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake
index 23a3a73a7f..687bc00b3c 100644
--- a/railties/lib/tasks/databases.rake
+++ b/railties/lib/tasks/databases.rake
@@ -292,7 +292,11 @@ namespace :db do
desc "Load a schema.rb file into the database"
task :load => :environment do
file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
- load(file)
+ 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 ]}
+ end
end
end
@@ -440,7 +444,11 @@ def drop_database(config)
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.drop_database config['database']
when /^sqlite/
- FileUtils.rm(File.join(RAILS_ROOT, config['database']))
+ require 'pathname'
+ path = Pathname.new(config['database'])
+ file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path)
+
+ FileUtils.rm(file)
when 'postgresql'
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
ActiveRecord::Base.connection.drop_database config['database']
@@ -448,7 +456,7 @@ def drop_database(config)
end
def session_table_name
- ActiveRecord::Base.pluralize_table_names ? :sessions : :session
+ ActiveRecord::SessionStore::Session.table_name
end
def set_firebird_env(config)
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 0cda49702b..fdaef6d9cb 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -29,11 +29,26 @@ class ActionsTest < GeneratorsTestCase
action :plugin, 'restful-authentication', :svn => @svn_plugin_uri
end
+ def test_plugin_with_git_option_and_branch_should_run_plugin_install
+ generator.expects(:run_ruby_script).once.with("script/plugin install -b stable #{@git_plugin_uri}", :verbose => false)
+ action :plugin, 'restful-authentication', :git => @git_plugin_uri, :branch => 'stable'
+ end
+
+ def test_plugin_with_svn_option_and_revision_should_run_plugin_install
+ generator.expects(:run_ruby_script).once.with("script/plugin install -r 1234 #{@svn_plugin_uri}", :verbose => false)
+ action :plugin, 'restful-authentication', :svn => @svn_plugin_uri, :revision => 1234
+ end
+
def test_plugin_with_git_option_and_submodule_should_use_git_scm
generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", :verbose => false)
action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true
end
+ def test_plugin_with_git_option_and_submodule_should_use_git_scm
+ generator.expects(:run).with("git submodule add -b stable #{@git_plugin_uri} vendor/plugins/rest_auth", :verbose => false)
+ action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true, :branch => 'stable'
+ end
+
def test_plugin_with_no_options_should_skip_method
generator.expects(:run).never
action :plugin, 'rest_auth', {}
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index a9b772d67b..501c7d10c6 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -31,6 +31,50 @@ class ModelGeneratorTest < GeneratorsTestCase
assert_migration "db/migrate/create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration/
end
+ def test_migration_with_namespace
+ run_generator ["Gallery::Image"]
+ assert_migration "db/migrate/create_gallery_images", /class CreateGalleryImages < ActiveRecord::Migration/
+ assert_no_migration "db/migrate/create_images"
+ end
+
+ def test_migration_with_nested_namespace
+ run_generator ["Admin::Gallery::Image"]
+ assert_no_migration "db/migrate/create_images"
+ assert_no_migration "db/migrate/create_gallery_images"
+ assert_migration "db/migrate/create_admin_gallery_images", /class CreateAdminGalleryImages < ActiveRecord::Migration/
+ assert_migration "db/migrate/create_admin_gallery_images", /create_table :admin_gallery_images/
+ end
+
+ def test_migration_with_nested_namespace_without_pluralization
+ ActiveRecord::Base.pluralize_table_names = false
+ run_generator ["Admin::Gallery::Image"]
+ assert_no_migration "db/migrate/create_images"
+ assert_no_migration "db/migrate/create_gallery_images"
+ assert_no_migration "db/migrate/create_admin_gallery_images"
+ assert_migration "db/migrate/create_admin_gallery_image", /class CreateAdminGalleryImage < ActiveRecord::Migration/
+ assert_migration "db/migrate/create_admin_gallery_image", /create_table :admin_gallery_image/
+ ensure
+ ActiveRecord::Base.pluralize_table_names = true
+ end
+
+ def test_migration_with_namespaces_in_model_name_without_plurization
+ ActiveRecord::Base.pluralize_table_names = false
+ run_generator ["Gallery::Image"]
+ assert_migration "db/migrate/create_gallery_image", /class CreateGalleryImage < ActiveRecord::Migration/
+ assert_no_migration "db/migrate/create_gallery_images"
+ ensure
+ ActiveRecord::Base.pluralize_table_names = true
+ end
+
+ def test_migration_without_pluralization
+ ActiveRecord::Base.pluralize_table_names = false
+ run_generator
+ assert_migration "db/migrate/create_account", /class CreateAccount < ActiveRecord::Migration/
+ assert_no_migration "db/migrate/create_accounts"
+ ensure
+ ActiveRecord::Base.pluralize_table_names = true
+ end
+
def test_migration_is_skipped
run_generator ["account", "--no-migration"]
assert_no_migration "db/migrate/create_accounts.rb"
diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb
index f83109800b..57bd755a9a 100644
--- a/railties/test/generators/session_migration_generator_test.rb
+++ b/railties/test/generators/session_migration_generator_test.rb
@@ -2,6 +2,16 @@ require 'abstract_unit'
require 'generators/generators_test_helper'
require 'generators/rails/session_migration/session_migration_generator'
+module ActiveRecord
+ module SessionStore
+ class Session
+ class << self
+ attr_accessor :table_name
+ end
+ end
+ end
+end
+
class SessionMigrationGeneratorTest < GeneratorsTestCase
def test_session_migration_with_default_name
@@ -14,6 +24,14 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase
assert_migration "db/migrate/create_session_table.rb", /class CreateSessionTable < ActiveRecord::Migration/
end
+ def test_session_migration_with_custom_table_name
+ ActiveRecord::SessionStore::Session.table_name = "custom_table_name"
+ run_generator
+ assert_migration "db/migrate/add_sessions_table.rb" do |migration|
+ assert_match /class AddSessionsTable < ActiveRecord::Migration/, migration
+ assert_match /create_table :custom_table_name/, migration
+ end
+ end
protected
def run_generator(args=[])
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb
index 1b73cdc73e..8de3161546 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -30,7 +30,8 @@ class PathsTest < Test::Unit::TestCase
assert_path @paths.lib, "lib"
assert_path @paths.vendor, "vendor"
assert_path @paths.vendor.plugins, "vendor", "plugins"
- assert_path @paths.cache, "tmp", "cache"
+ assert_path @paths.tmp, "tmp"
+ assert_path @paths.tmp.cache, "tmp", "cache"
assert_path @paths.config, "config"
assert_path @paths.config.locales, "config", "locales"
assert_path @paths.config.environments, "config", "environments"