diff options
Diffstat (limited to 'railties')
62 files changed, 528 insertions, 427 deletions
diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 01dd33fa8c..823916b1dc 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -3,13 +3,6 @@ require 'action_controller' require 'fileutils' require 'optparse' -# TODO: Push Thin adapter upstream so we don't need worry about requiring it -begin - require_library_or_gem 'thin' -rescue Exception - # Thin not available -end - options = { :Port => 3000, :Host => "0.0.0.0", diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index 64ec808ee4..c97c61507a 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -11,7 +11,7 @@ end $:.unshift(File.dirname(__FILE__)) -require 'vendor/thor-0.11.3/lib/thor' +require 'vendor/thor-0.11.5/lib/thor' require 'generators/base' require 'generators/named_base' @@ -83,6 +83,34 @@ module Rails @@options ||= DEFAULT_OPTIONS.dup end + # Get paths only from loaded rubygems. In other words, to use rspec + # generators, you first have to ensure that rspec gem was already loaded. + # + def self.rubygems_generators_paths + paths = [] + return paths unless defined?(Gem) + + Gem.loaded_specs.each do |name, spec| + generator_path = File.join(spec.full_gem_path, "lib/generators") + paths << generator_path if File.exist?(generator_path) + end + + paths + end + + # If RAILS_ROOT is defined, add vendor/gems, vendor/plugins and lib/generators + # paths. + # + def self.rails_root_generators_paths + paths = [] + if defined?(RAILS_ROOT) + paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")] + paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")] + paths << File.join(RAILS_ROOT, "lib", "generators") + end + paths + end + # Hold configured generators fallbacks. If a plugin developer wants a # generator group to fallback to another group in case of missing generators, # they can add a fallback. @@ -108,30 +136,25 @@ module Rails # Generators load paths used on lookup. The lookup happens as: # - # 1) builtin generators - # 2) frozen gems generators - # 3) rubygems gems generators (not available yet) - # 4) plugin generators - # 5) lib generators - # 6) ~/rails/generators + # 1) lib generators + # 2) vendor/plugin generators + # 3) vendor/gems generators + # 4) ~/rails/generators + # 5) rubygems generators + # 6) builtin generators # - # TODO Add Rubygems generators (depends on dependencies system rework) # TODO Remove hardcoded paths for all, except (1). # - def self.load_path - @@load_path ||= begin - paths = [] - paths << File.expand_path(File.join(File.dirname(__FILE__), "generators")) - if defined?(RAILS_ROOT) - paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "*", "lib", "generators")] - paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")] - paths << File.join(RAILS_ROOT, "lib", "generators") - end + def self.load_paths + @@load_paths ||= begin + paths = self.rails_root_generators_paths paths << File.join(Thor::Util.user_home, ".rails", "generators") + paths += self.rubygems_generators_paths + paths << File.expand_path(File.join(File.dirname(__FILE__), "generators")) paths end end - load_path # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths. + load_paths # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths. # Receives a namespace and tries different combinations to find a generator. # @@ -204,8 +227,8 @@ module Rails puts "Builtin: #{rails.join(', ')}." # Load paths and remove builtin - paths, others = load_path.dup, [] - paths.shift + paths, others = load_paths.dup, [] + paths.pop paths.each do |path| tail = [ "*", "*", "*_generator.rb" ] @@ -242,7 +265,6 @@ module Rails # def self.invoke_fallbacks_for(name, base) return nil unless base && fallbacks[base.to_sym] - invoked_fallbacks = [] Array(fallbacks[base.to_sym]).each do |fallback| @@ -283,7 +305,7 @@ module Rails generators_path.uniq! generators_path = "{#{generators_path.join(',')}}" - self.load_path.each do |path| + self.load_paths.each do |path| Dir[File.join(path, generators_path, name)].each do |file| begin require file 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/action_orm.rb b/railties/lib/generators/active_model.rb index 69cf227fd7..1a849a0e02 100644 --- a/railties/lib/generators/action_orm.rb +++ b/railties/lib/generators/active_model.rb @@ -1,6 +1,6 @@ module Rails module Generators - # ActionORM is a class to be implemented by each ORM to allow Rails to + # ActiveModel is a class to be implemented by each ORM to allow Rails to # generate customized controller code. # # The API has the same methods as ActiveRecord, but each method returns a @@ -8,22 +8,22 @@ module Rails # # For example: # - # ActiveRecord::Generators::ActionORM.find(Foo, "params[:id]") + # ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]") # #=> "Foo.find(params[:id])" # - # Datamapper::Generators::ActionORM.find(Foo, "params[:id]") + # Datamapper::Generators::ActiveModel.find(Foo, "params[:id]") # #=> "Foo.get(params[:id])" # - # On initialization, the ActionORM accepts the instance name that will + # On initialization, the ActiveModel accepts the instance name that will # receive the calls: # - # builder = ActiveRecord::Generators::ActionORM.new "@foo" + # builder = ActiveRecord::Generators::ActiveModel.new "@foo" # builder.save #=> "@foo.save" # - # The only exception in ActionORM for ActiveRecord is the use of self.build + # The only exception in ActiveModel for ActiveRecord is the use of self.build # instead of self.new. # - class ActionORM + class ActiveModel attr_reader :name def initialize(name) diff --git a/railties/lib/generators/active_record.rb b/railties/lib/generators/active_record.rb index 64bee3904e..924b70881a 100644 --- a/railties/lib/generators/active_record.rb +++ b/railties/lib/generators/active_record.rb @@ -1,6 +1,6 @@ require 'generators/named_base' require 'generators/migration' -require 'generators/action_orm' +require 'generators/active_model' require 'active_record' module ActiveRecord @@ -20,7 +20,7 @@ module ActiveRecord end end - class ActionORM < Rails::Generators::ActionORM #:nodoc: + class ActiveModel < Rails::Generators::ActiveModel #:nodoc: def self.all(klass) "#{klass}.all" 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 699b8ed651..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. @@ -124,18 +125,18 @@ module Rails protected - # Loads the ORM::Generators::ActionORM class. This class is responsable + # Loads the ORM::Generators::ActiveModel class. This class is responsable # to tell scaffold entities how to generate an specific method for the - # ORM. Check Rails::Generators::ActionORM for more information. + # ORM. Check Rails::Generators::ActiveModel for more information. # def orm_class @orm_class ||= begin # Raise an error if the class_option :orm was not defined. unless self.class.class_options[:orm] - raise "You need to have :orm as class option to invoke orm_class and orm_instance" + raise "You need to have :orm as class option to invoke orm_class and orm_instance" end - action_orm = "#{options[:orm].to_s.classify}::Generators::ActionORM" + action_orm = "#{options[:orm].to_s.classify}::Generators::ActiveModel" # If the orm was not loaded, try to load it at "generators/orm", # for example "generators/active_record" or "generators/sequel". @@ -152,7 +153,7 @@ module Rails end end - # Initialize ORM::Generators::ActionORM to access instance methods. + # Initialize ORM::Generators::ActiveModel to access instance methods. # def orm_instance(name=file_name) @orm_instance ||= @orm_class.new(name) diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index c8044d13b1..c80a344e0d 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -49,7 +49,7 @@ module Rails::Generators self.destination_root = File.expand_path(app_path, destination_root) empty_directory '.' - app_name # Sets the app name + set_default_accessors! FileUtils.cd(destination_root) end @@ -164,9 +164,9 @@ module Rails::Generators end def apply_rails_template - apply options[:template] if options[:template] + apply rails_template if rails_template rescue Thor::Error, LoadError, Errno::ENOENT => e - raise Error, "The template [#{options[:template]}] could not be loaded. Error: #{e}" + raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}" end def freeze? @@ -175,6 +175,21 @@ module Rails::Generators protected + attr_accessor :rails_template + + def set_default_accessors! + app_name # Cache app name + + self.rails_template = case options[:template] + when /^http:\/\// + options[:template] + when String + File.expand_path(options[:template], Dir.pwd) + else + options[:template] + end + end + # Define file as an alias to create_file for backwards compatibility. # def file(*args, &block) 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/rails/app/templates/config/environment.rb b/railties/lib/generators/rails/app/templates/config/environment.rb index 94c90475c6..adb3a3060a 100644 --- a/railties/lib/generators/rails/app/templates/config/environment.rb +++ b/railties/lib/generators/rails/app/templates/config/environment.rb @@ -45,9 +45,9 @@ Rails::Initializer.run do |config| # Configure generators values. Many other options are available, be sure to # check the documentation. - config.generators do |g| - g.orm :active_record - g.template_engine :erb - g.test_framework :test_unit, :fixture => true - end + # config.generators do |g| + # g.orm :active_record + # g.template_engine :erb + # g.test_framework :test_unit, :fixture => true + # end end diff --git a/railties/lib/generators/rails/mailer/templates/mailer.rb b/railties/lib/generators/rails/mailer/templates/mailer.rb index ce15ae9de9..90e0b712d6 100644 --- a/railties/lib/generators/rails/mailer/templates/mailer.rb +++ b/railties/lib/generators/rails/mailer/templates/mailer.rb @@ -1,5 +1,4 @@ class <%= class_name %> < ActionMailer::Base - <% for action in actions -%> def <%= action %>(sent_at = Time.now) @@ -10,6 +9,6 @@ class <%= class_name %> < ActionMailer::Base body :greeting => 'Hi,' end -<% end -%> +<% end -%> end 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/initializer.rb b/railties/lib/initializer.rb index bb04dfa370..336bff9534 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -244,7 +244,6 @@ module Rails if RUBY_VERSION < '1.9' $KCODE='u' else - Encoding.default_internal = Encoding::UTF_8 Encoding.default_external = Encoding::UTF_8 end end 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 0d4d658315..b82341ba94 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -101,8 +101,12 @@ namespace :db do ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key next unless config['database'] - # Only connect to local databases - local_database?(config) { drop_database(config) } + begin + # Only connect to local databases + local_database?(config) { drop_database(config) } + rescue Exception => e + puts "Couldn't drop #{config['database']} : #{e.inspect}" + end end end end @@ -172,6 +176,13 @@ namespace :db do Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end + desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n' + task :forward => :environment do + step = ENV['STEP'] ? ENV['STEP'].to_i : 1 + ActiveRecord::Migrator.forward('db/migrate/', step) + Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby + end + desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.' task :reset => [ 'db:drop', 'db:setup' ] @@ -429,7 +440,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'] @@ -437,7 +452,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/lib/tasks/routes.rake b/railties/lib/tasks/routes.rake index 39b7139167..abbf3258c1 100644 --- a/railties/lib/tasks/routes.rake +++ b/railties/lib/tasks/routes.rake @@ -1,6 +1,7 @@ -desc 'Print out all defined routes in match order, with names.' +desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' task :routes => :environment do - routes = ActionController::Routing::Routes.routes.collect do |route| + all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes + routes = all_routes.collect do |route| name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s verb = route.conditions[:method].to_s.upcase segs = route.segments.inject("") { |str,s| str << s.to_s } @@ -14,4 +15,4 @@ task :routes => :environment do routes.each do |r| puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}" end -end
\ No newline at end of file +end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/error.rb b/railties/lib/vendor/thor-0.11.3/lib/thor/error.rb deleted file mode 100644 index c846e9ce74..0000000000 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/error.rb +++ /dev/null @@ -1,27 +0,0 @@ -class Thor - # Thor::Error is raised when it's caused by the user invoking the task and - # only errors that inherit from it are rescued. - # - # So, for example, if the developer declares a required argument after an - # option, it should raise an ::ArgumentError and not ::Thor::ArgumentError, - # because it was caused by the developer and not the "final user". - # - class Error < StandardError #:nodoc: - end - - # Raised when a task was not found. - # - class UndefinedTaskError < Error #:nodoc: - end - - # Raised when a task was found, but not invoked properly. - # - class InvocationError < Error #:nodoc: - end - - class RequiredArgumentMissingError < InvocationError #:nodoc: - end - - class MalformattedArgumentError < InvocationError #:nodoc: - end -end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks.rb b/railties/lib/vendor/thor-0.11.3/lib/thor/tasks.rb deleted file mode 100644 index d1a7b1c673..0000000000 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks.rb +++ /dev/null @@ -1,4 +0,0 @@ -# This only loads all tasks inside tasks. -Dir[File.join(File.dirname(__FILE__), "tasks", "*.rb")].each do |task| - require task -end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/install.rb b/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/install.rb deleted file mode 100644 index 6b20ff1634..0000000000 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/install.rb +++ /dev/null @@ -1,35 +0,0 @@ -class Thor - # Creates an install task. - # - # ==== Parameters - # spec<Gem::Specification> - # - # ==== Options - # :dir - The directory where the package is hold before installation. Defaults to ./pkg. - # - def self.install_task(spec, options={}) - package_task(spec, options) - tasks['install'] = Thor::InstallTask.new(spec, options) - end - - class InstallTask < Task - attr_accessor :spec, :config - - def initialize(gemspec, config={}) - super(:install, "Install the gem", "install", {}) - @spec = gemspec - @config = { :dir => File.join(Dir.pwd, "pkg") }.merge(config) - end - - def run(instance, args=[]) - null, sudo, gem = RUBY_PLATFORM =~ /mswin|mingw/ ? ['NUL', '', 'gem.bat'] : - ['/dev/null', 'sudo', 'gem'] - - old_stderr, $stderr = $stderr.dup, File.open(null, "w") - instance.invoke(:package) - $stderr = old_stderr - - system %{#{sudo} #{Gem.ruby} -S #{gem} install #{config[:dir]}/#{spec.name}-#{spec.version} --no-rdoc --no-ri --no-update-sources} - end - end -end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/package.rb b/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/package.rb deleted file mode 100644 index 603d61b4ab..0000000000 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/package.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "fileutils" - -class Thor - # Creates a package task. - # - # ==== Parameters - # spec<Gem::Specification> - # - # ==== Options - # :dir - The package directory. Defaults to ./pkg. - # - def self.package_task(spec, options={}) - tasks['package'] = Thor::PackageTask.new(spec, options) - end - - class PackageTask < Task - attr_accessor :spec, :config - - def initialize(gemspec, config={}) - super(:package, "Build a gem package", "package", {}) - @spec = gemspec - @config = {:dir => File.join(Dir.pwd, "pkg")}.merge(config) - end - - def run(instance, args=[]) - FileUtils.mkdir_p(config[:dir]) - Gem::Builder.new(spec).build - FileUtils.mv(spec.file_name, File.join(config[:dir], spec.file_name)) - end - end -end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/spec.rb b/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/spec.rb deleted file mode 100644 index c7d00968e8..0000000000 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/tasks/spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require "fileutils" - -class Thor - # Creates a spec task. - # - # ==== Parameters - # files<Array> - Array of files to spec - # - # ==== Options - # :name - The name of the task. It can be rcov or spec. Spec is the default. - # :rcov - A hash with rcov specific options. - # :rcov_dir - Where rcov reports should be printed. - # :verbose - Sets the default value for verbose, although it can be specified - # also through the command line. - # - # All other options are added to rspec. - # - def self.spec_task(files, options={}) - name = (options.delete(:name) || 'spec').to_s - tasks[name] = Thor::SpecTask.new(name, files, options) - end - - class SpecTask < Task - attr_accessor :name, :files, :rcov_dir, :rcov_config, :spec_config - - def initialize(name, files, config={}) - options = { :verbose => Thor::Option.parse(:verbose, config.delete(:verbose) || false) } - super(name, "#{name.capitalize} task", name, options) - - @name = name - @files = files.map{ |f| %["#{f}"] }.join(" ") - @rcov_dir = config.delete(:rdoc_dir) || File.join(Dir.pwd, 'coverage') - @rcov_config = config.delete(:rcov) || {} - @spec_config = { :format => 'specdoc', :color => true }.merge(config) - end - - def run(instance, args=[]) - rcov_opts = Thor::Options.to_switches(rcov_config) - spec_opts = Thor::Options.to_switches(spec_config) - - require 'rbconfig' - cmd = RbConfig::CONFIG['ruby_install_name'] << " " - - if rcov? - FileUtils.rm_rf(rcov_dir) - cmd << "-S #{where('rcov')} -o #{rcov_dir} #{rcov_opts} " - end - - cmd << [where('spec'), rcov? ? " -- " : nil, files, spec_opts].join(" ") - - puts cmd if instance.options.verbose? - system(cmd) - exit($?.exitstatus) - end - - private - - def rcov? - name == "rcov" - end - - def where(file) - ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| - file_with_path = File.join(path, file) - next unless File.exist?(file_with_path) && File.executable?(file_with_path) - return File.expand_path(file_with_path) - end - end - end -end diff --git a/railties/lib/vendor/thor-0.11.3/CHANGELOG.rdoc b/railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc index 544dde8c02..dba25b7205 100644 --- a/railties/lib/vendor/thor-0.11.3/CHANGELOG.rdoc +++ b/railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc @@ -1,9 +1,11 @@ == TODO * Improve spec coverage for Thor::Runner -* Improve help output to list shorthand switches, too -== Current +== 0.11.x, released 2009-07-01 + +* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on + Thor classes. * BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore since it wrong behavior to the invocation system. diff --git a/railties/lib/vendor/thor-0.11.3/LICENSE b/railties/lib/vendor/thor-0.11.5/LICENSE index 98722da459..98722da459 100644 --- a/railties/lib/vendor/thor-0.11.3/LICENSE +++ b/railties/lib/vendor/thor-0.11.5/LICENSE diff --git a/railties/lib/vendor/thor-0.11.3/README.markdown b/railties/lib/vendor/thor-0.11.5/README.rdoc index a1d7259775..f1106f02b6 100644 --- a/railties/lib/vendor/thor-0.11.3/README.markdown +++ b/railties/lib/vendor/thor-0.11.5/README.rdoc @@ -1,5 +1,4 @@ -thor -==== += thor Map options to a class. Simply create a class with the appropriate annotations and have options automatically map to functions and parameters. @@ -34,26 +33,18 @@ That gets converted to: App.new.install("myname") # with {'force' => true} as options hash -1. Inherit from Thor to turn a class into an option mapper -2. Map additional non-valid identifiers to specific methods. In this case, convert -L to :list -3. Describe the method immediately below. The first parameter is the usage information, and the second parameter is the description -4. Provide any additional options that will be available the instance method options. - -Types for `method_options` --------------------------- - -<dl> - <dt><code>:boolean</code></dt> - <dd>is parsed as --option or --option=true</dd> - <dt><code>:string</code></dt> - <dd>is parsed as --option=VALUE</dd> - <dt><code>:numeric</code></dt> - <dd>is parsed as --option=N</dd> - <dt><code>:array</code></dt> - <dd>is parsed as --option=one two three</dd> - <dt><code>:hash</code></dt> - <dd>is parsed as --option=key:value key:value key:value</dd> -</dl> +1. Inherit from Thor to turn a class into an option mapper +2. Map additional non-valid identifiers to specific methods. In this case, convert -L to :list +3. Describe the method immediately below. The first parameter is the usage information, and the second parameter is the description +4. Provide any additional options that will be available the instance method options. + +== Types for <tt>method_options</tt> + +* :boolean - is parsed as <tt>--option</tt> or <tt>--option=true</tt> +* :string - is parsed as <tt>--option=VALUE</tt> +* :numeric - is parsed as <tt>--option=N</tt> +* :array - is parsed as <tt>--option=one two three</tt> +* :hash - is parsed as <tt>--option=name:string age:integer</tt> Besides, method_option allows a default value to be given, examples: @@ -66,9 +57,9 @@ Besides, method_option allows a default value to be given, examples: method_options :threshold => 3.0 #=> Creates a numeric option with default value 3.0 -You can also supply :option => :required to mark an option as required. The +You can also supply <tt>:option => :required</tt> to mark an option as required. The type is assumed to be string. If you want a required hash with default values -as option, you can use `method_option` which uses a more declarative style: +as option, you can use <tt>method_option</tt> which uses a more declarative style: method_option :attributes, :type => :hash, :default => {}, :required => true @@ -91,8 +82,7 @@ You can supply as many aliases as you want. NOTE: Type :optional available in Thor 0.9.0 was deprecated. Use :string or :boolean instead. -Namespaces ----------- +== Namespaces By default, your Thor tasks are invoked using Ruby namespace. In the example above, tasks are invoked as: @@ -124,8 +114,7 @@ And then your tasks hould be invoked as: thor myapp:install name --force -Invocations ------------ +== Invocations Thor comes with a invocation-dependency system as well which allows a task to be invoked only once. For example: @@ -158,8 +147,7 @@ The output is "1 2 3", which means that the three task was invoked only once. You can even invoke tasks from another class, so be sure to check the documentation. -Thor::Group ------------ +== Thor::Group Thor has a special class called Thor::Group. The main difference to Thor class is that it invokes all tasks at once. The example above could be rewritten in @@ -185,10 +173,10 @@ When invoked: thor counter -It prints "1 2 3" as well. Notice you should described (desc) only the class -and not each task anymore. Thor::Group is a great tool to create generators, -since you can define several steps which are invoked in the order they are -defined (Thor::Group is the tool use in generators in Rails 3.0). +It prints "1 2 3" as well. Notice you should describe (using the method <tt>desc</tt>) +only the class and not each task anymore. Thor::Group is a great tool to create +generators, since you can define several steps which are invoked in the order they +are defined (Thor::Group is the tool use in generators in Rails 3.0). Besides, Thor::Group can parse arguments and options as Thor tasks: @@ -218,17 +206,17 @@ The counter above expects one parameter and has the folling outputs: thor counter 11 # Prints "11 12 13" -You can also give options to Thor::Group, but instead of using `method_option` and -`method_options`, you should use `class_option` and `class_options`. Both argument -and class_options methods are available to Thor class as well. +You can also give options to Thor::Group, but instead of using <tt>method_option</tt> +and <tt>method_options</tt>, you should use <tt>class_option</tt> and <tt>class_options</tt>. +Both argument and class_options methods are available to Thor class as well. -Actions -------- +== Actions Thor comes with several actions which helps with script and generator tasks. You -might be familiar with them since some came from Rails Templates. They are: `say`, -`ask`, `yes?`, `no?`, `add_file`, `remove_file`, `copy_file`, `template`, -`directory`, `inside`, `run`, `inject_into_file` and a couple more. +might be familiar with them since some came from Rails Templates. They are: +<tt>say</tt>, <tt>ask</tt>, <tt>yes?</tt>, <tt>no?</tt>, <tt>add_file</tt>, +<tt>remove_file</tt>, <tt>copy_file</tt>, <tt>template</tt>, <tt>directory</tt>, +<tt>inside</tt>, <tt>run</tt>, <tt>inject_into_file</tt> and a couple more. To use them, you just need to include Thor::Actions in your Thor classes: @@ -241,7 +229,6 @@ Some actions like copy file requires that a class method called source_root is defined in your class. This is the directory where your templates should be placed. Be sure to check the documentation. -License -------- +== License See MIT LICENSE. diff --git a/railties/lib/vendor/thor-0.11.3/bin/rake2thor b/railties/lib/vendor/thor-0.11.5/bin/rake2thor index 50c7410d80..50c7410d80 100755 --- a/railties/lib/vendor/thor-0.11.3/bin/rake2thor +++ b/railties/lib/vendor/thor-0.11.5/bin/rake2thor diff --git a/railties/lib/vendor/thor-0.11.3/bin/thor b/railties/lib/vendor/thor-0.11.5/bin/thor index eaf849fb4a..eaf849fb4a 100755 --- a/railties/lib/vendor/thor-0.11.3/bin/thor +++ b/railties/lib/vendor/thor-0.11.5/bin/thor diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor.rb b/railties/lib/vendor/thor-0.11.5/lib/thor.rb index f65455cdda..8dfcfd4c5b 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor.rb @@ -101,8 +101,7 @@ class Thor # :required - If the argument is required or not. # :default - Default value for this argument. It cannot be required and have default values. # :aliases - Aliases for this option. - # :type - The type of the argument, can be :string, :hash, :array, :numeric, :boolean or :default. - # Default accepts arguments as booleans (--switch) or as strings (--switch=VALUE). + # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean. # :group - The group for this options. Use by class options to output options in different levels. # :banner - String to show on usage notes. # @@ -160,39 +159,43 @@ class Thor raise UndefinedTaskError, "task '#{meth}' could not be found in namespace '#{self.namespace}'" unless task shell.say "Usage:" - shell.say " #{banner(task, options[:namespace])}" + shell.say " #{banner(task, options[:namespace], false)}" shell.say - class_options_help(shell, "Class") + class_options_help(shell, "Class", :Method => task.options.map { |_, o| o }) shell.say task.description else list = (options[:short] ? tasks : all_tasks).map do |_, task| - item = [ " " + banner(task, options[:namespace]) ] - item << if task.short_description - "\n # #{task.short_description}\n" - else - "\n" - end + item = [ banner(task, options[:namespace]) ] + item << "# #{task.short_description}" if task.short_description + item << " " end + options[:ident] ||= 2 if options[:short] - shell.print_table(list) + shell.print_list(list, :ident => options[:ident]) else shell.say "Tasks:" - shell.print_table(list) - class_options_help(shell, "Class") + shell.print_list(list, :ident => options[:ident]) end + + Thor::Util.thor_classes_in(self).each do |subclass| + namespace = options[:namespace] == true || subclass.namespace.gsub(/^#{self.namespace}:/, '') + subclass.help(shell, options.merge(:short => true, :namespace => namespace)) + end + + class_options_help(shell, "Class") unless options[:short] end end protected # The banner for this class. You can customize it if you are invoking the - # thor class by another means which is not the Thor::Runner. It receives - # the task that is going to be invoked and if the namespace should be - # displayed. + # thor class by another ways which is not the Thor::Runner. It receives + # the task that is going to be invoked and a boolean which indicates if + # the namespace should be displayed as arguments. # - def banner(task, namespace=true) #:nodoc: - task.formatted_usage(self, namespace) + def banner(task, namespace=true, show_options=true) + task.formatted_usage(self, namespace, show_options) end def baseclass #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb index b8cfde1940..1d09dc38ae 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/actions.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb @@ -43,13 +43,11 @@ class Thor # 3) Parents source paths # def source_paths_for_search - @source_paths_for_search ||= begin - paths = [] - paths += self.source_paths - paths << self.source_root if self.respond_to?(:source_root) - paths += from_superclass(:source_paths, []) - paths - end + paths = [] + paths += self.source_paths + paths << self.source_root if self.respond_to?(:source_root) + paths += from_superclass(:source_paths, []) + paths end end @@ -60,8 +58,7 @@ class Thor # It also accepts :force, :skip and :pretend to set the behavior # and the respective option. # - # destination_root<String>:: The root directory needed for some actions. It's also known - # as destination root. + # destination_root<String>:: The root directory needed for some actions. # def initialize(args=[], options={}, config={}) self.behavior = case config[:behavior].to_s @@ -80,7 +77,7 @@ class Thor # Wraps an action object and call it accordingly to the thor class behavior. # - def action(instance) + def action(instance) #:nodoc: if behavior == :revoke instance.revoke! else @@ -110,18 +107,23 @@ class Thor remove_dot ? (path[2..-1] || '') : path end + # Holds source paths in instance so they can be manipulated. + # + def source_paths + @source_paths ||= self.class.source_paths_for_search + end + # Receives a file or directory and search for it in the source paths. # def find_in_source_paths(file) relative_root = relative_to_original_destination_root(destination_root, false) - paths = self.class.source_paths_for_search - paths.each do |source| + source_paths.each do |source| source_file = File.expand_path(file, File.join(source, relative_root)) return source_file if File.exists?(source_file) end - if paths.empty? + if source_paths.empty? raise Error, "You don't have any source path defined for class #{self.class.name}. To fix this, " << "you can define a source_root in your class." else @@ -205,7 +207,7 @@ class Thor end say_status :run, desc, config.fetch(:verbose, true) - `#{command}` unless options[:pretend] + system(command) unless options[:pretend] end # Executes a ruby script (taking into account WIN32 platform quirks). diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/create_file.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb index 8f6badee27..8f6badee27 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/create_file.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/directory.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb index e33639f4e5..be5eb822ac 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/directory.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb @@ -3,7 +3,7 @@ require 'thor/actions/empty_directory' class Thor module Actions - # Copies interactively the files from source directory to root directory. + # Copies recursively the files from source directory to root directory. # If any of the files finishes with .tt, it's considered to be a template # and is placed in the destination without the extension .tt. If any # empty directory is found, it's copied and all .empty_directory files are diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/empty_directory.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb index 03c1fe4af1..03c1fe4af1 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/empty_directory.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/file_manipulation.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb index 74c157ba8c..74c157ba8c 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/file_manipulation.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/inject_into_file.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb index 089bd894e4..66dd1f5fc1 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/actions/inject_into_file.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb @@ -34,7 +34,7 @@ class Thor action InjectIntoFile.new(self, destination, data, config) end - class InjectIntoFile < EmptyDirectory + class InjectIntoFile < EmptyDirectory #:nodoc: attr_reader :flag, :replacement def initialize(base, destination, data, config) diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/base.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/base.rb index 0bdcc1f4d5..0fa87f8162 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/base.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/base.rb @@ -8,7 +8,10 @@ require 'thor/task' require 'thor/util' class Thor + # Shortcuts for help. HELP_MAPPINGS = %w(-h -? --help -D) + + # Thor methods that should not be overwritten by the user. THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root action add_file create_file in_root inside run run_ruby_script) @@ -78,7 +81,6 @@ class Thor # Whenever a class inherits from Thor or Thor::Group, we should track the # class and the file on Thor::Base. This is the method responsable for it. - # Also adds the source root to the source paths if the klass respond to it. # def register_klass_file(klass) #:nodoc: file = caller[1].match(/(.*):\d+/)[1] @@ -246,7 +248,8 @@ class Thor # Returns the tasks for this Thor class. # # ==== Returns - # OrderedHash:: An ordered hash with this class tasks. + # OrderedHash:: An ordered hash with tasks names as keys and Thor::Task + # objects as values. # def tasks @tasks ||= Thor::CoreExt::OrderedHash.new @@ -255,7 +258,8 @@ class Thor # Returns the tasks for this Thor class and all subclasses. # # ==== Returns - # OrderedHash + # OrderedHash:: An ordered hash with tasks names as keys and Thor::Task + # objects as values. # def all_tasks @all_tasks ||= from_superclass(:all_tasks, Thor::CoreExt::OrderedHash.new) @@ -334,7 +338,7 @@ class Thor def namespace(name=nil) case name when nil - @namespace ||= Thor::Util.constant_to_namespace(self, false) + @namespace ||= Thor::Util.namespace_from_thor_class(self, false) else @namespace = name.to_s end @@ -342,7 +346,7 @@ class Thor # Default way to start generators from the command line. # - def start(given_args=ARGV, config={}) #:nodoc: + def start(given_args=ARGV, config={}) config[:shell] ||= Thor::Base.shell.new yield rescue Thor::Error => e @@ -360,7 +364,7 @@ class Thor # hooks to add extra options, one of them if the third argument called # extra_group that should be a hash in the format :group => Array[Options]. # - # The second is by returning a lamda used to print values. The lambda + # The second is by returning a lambda used to print values. The lambda # requires two options: the group name and the array of options. # def class_options_help(shell, ungrouped_name=nil, extra_group=nil) #:nodoc: @@ -377,24 +381,14 @@ class Thor options.each do |option| item = [ option.usage(padding) ] - - item << if option.description - "# #{option.description}" - else - "" - end + item.push(option.description ? "# #{option.description}" : "") list << item list << [ "", "# Default: #{option.default}" ] if option.show_default? end unless list.empty? - if group_name - shell.say "#{group_name} options:" - else - shell.say "Options:" - end - + shell.say(group_name ? "#{group_name} options:" : "Options:") shell.print_table(list, :ident => 2) shell.say "" end @@ -412,7 +406,7 @@ class Thor # Raises an error if the word given is a Thor reserved word. # - def is_thor_reserved_word?(word, type) + def is_thor_reserved_word?(word, type) #:nodoc: return false unless THOR_RESERVED_WORDS.include?(word.to_s) raise "#{word.inspect} is a Thor reserved word and cannot be defined as #{type}" end @@ -423,7 +417,7 @@ class Thor # name<Symbol>:: The name of the argument. # options<Hash>:: Described in both class_option and method_option. # - def build_option(name, options, scope) + def build_option(name, options, scope) #:nodoc: scope[name] = Thor::Option.new(name, options[:desc], options[:required], options[:type], options[:default], options[:banner], options[:group], options[:aliases]) @@ -437,7 +431,7 @@ class Thor # ==== Parameters # Hash[Symbol => Object] # - def build_options(options, scope) + def build_options(options, scope) #:nodoc: options.each do |key, value| scope[key] = Thor::Option.parse(key, value) end @@ -447,7 +441,7 @@ class Thor # class, just return it, otherwise dup it and add the fresh copy to the # current task hash. # - def find_and_refresh_task(name) + def find_and_refresh_task(name) #:nodoc: task = if task = tasks[name.to_s] task elsif task = all_tasks[name.to_s] @@ -465,7 +459,7 @@ class Thor end # Fire this callback whenever a method is added. Added methods are - # tracked as tasks if the requirements set by valid_task? are valid. + # tracked as tasks by invoking the create_task method. # def method_added(meth) meth = meth.to_s @@ -486,7 +480,7 @@ class Thor end # Retrieves a value from superclass. If it reaches the baseclass, - # returns nil. + # returns default. # def from_superclass(method, default=nil) if self == baseclass || !superclass.respond_to?(method, true) diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/core_ext/hash_with_indifferent_access.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb index 3213961fe4..78bc5cf4bf 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/core_ext/hash_with_indifferent_access.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb @@ -1,5 +1,5 @@ class Thor - module CoreExt + module CoreExt #:nodoc: # A hash with indifferent access and magic predicates. # @@ -9,7 +9,7 @@ class Thor # hash['foo'] #=> 'bar' # hash.foo? #=> true # - class HashWithIndifferentAccess < ::Hash + class HashWithIndifferentAccess < ::Hash #:nodoc: def initialize(hash={}) super() diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/core_ext/ordered_hash.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb index 5e4ad5609f..27fea5bb35 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/core_ext/ordered_hash.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb @@ -1,6 +1,4 @@ -require 'forwardable' - -class Thor #:nodoc: +class Thor module CoreExt #:nodoc: if RUBY_VERSION >= '1.9' diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb new file mode 100644 index 0000000000..f9b31a35d1 --- /dev/null +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb @@ -0,0 +1,27 @@ +class Thor + # Thor::Error is raised when it's caused by wrong usage of thor classes. Those + # errors have their backtrace supressed and are nicely shown to the user. + # + # Errors that are caused by the developer, like declaring a method which + # overwrites a thor keyword, it SHOULD NOT raise a Thor::Error. This way, we + # ensure that developer errors are shown with full backtrace. + # + class Error < StandardError + end + + # Raised when a task was not found. + # + class UndefinedTaskError < Error + end + + # Raised when a task was found, but not invoked properly. + # + class InvocationError < Error + end + + class RequiredArgumentMissingError < InvocationError + end + + class MalformattedArgumentError < InvocationError + end +end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/group.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/group.rb index 1be1c35ba5..1e59df2313 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/group.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/group.rb @@ -221,9 +221,9 @@ class Thor::Group protected # The banner for this class. You can customize it if you are invoking the - # thor class by another means which is not the Thor::Runner. + # thor class by another ways which is not the Thor::Runner. # - def banner #:nodoc: + def banner "#{self.namespace} #{self.arguments.map {|a| a.usage }.join(' ')}" end @@ -244,7 +244,7 @@ class Thor::Group # Shortcut to invoke with padding and block handling. Use internally by # invoke and invoke_from_option class methods. # - def _invoke_for_class_method(klass, task=nil, *args, &block) + def _invoke_for_class_method(klass, task=nil, *args, &block) #:nodoc: shell.padding += 1 result = if block_given? diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/invocation.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb index 34e7a4b911..c0388dd863 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/invocation.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb @@ -11,7 +11,7 @@ class Thor def prepare_for_invocation(key, name) #:nodoc: case name when Symbol, String - Thor::Util.namespace_to_thor_class(name.to_s, false) + Thor::Util.namespace_to_thor_class_and_task(name.to_s, false) else name end @@ -96,20 +96,8 @@ class Thor task, args, opts, config = nil, task, args, opts if task.nil? || task.is_a?(Array) args, opts, config = nil, args, opts if args.is_a?(Hash) - object, task = _prepare_for_invocation(name, task) - if object.is_a?(Class) - klass = object - - stored_args, stored_opts, stored_config = @_initializer - args ||= stored_args.dup - opts ||= stored_opts.dup - - config ||= {} - config = stored_config.merge(_shared_configuration).merge!(config) - instance = klass.new(args, opts, config) - else - klass, instance = object.class, object - end + object, task = _prepare_for_invocation(name, task) + klass, instance = _initialize_klass_with_initializer(object, args, opts, config) method_args = [] current = @_invocations[klass] @@ -134,7 +122,7 @@ class Thor # Configuration values that are shared between invocations. # - def _shared_configuration + def _shared_configuration #:nodoc: { :invocations => @_invocations } end @@ -154,13 +142,13 @@ class Thor # If the object was not set, use self and use the name as task. object, task = self, name unless object - return object, _validate_klass_and_task(object, task) + return object, _validate_task(object, task) end # Check if the object given is a Thor class object and get a task object # for it. # - def _validate_klass_and_task(object, task) #:nodoc: + def _validate_task(object, task) #:nodoc: klass = object.is_a?(Class) ? object : object.class raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base @@ -168,5 +156,23 @@ class Thor task = klass.all_tasks[task.to_s] || Task.dynamic(task) if task && !task.is_a?(Thor::Task) task end + + # Initialize klass using values stored in the @_initializer. + # + def _initialize_klass_with_initializer(object, args, opts, config) #:nodoc: + if object.is_a?(Class) + klass = object + + stored_args, stored_opts, stored_config = @_initializer + args ||= stored_args.dup + opts ||= stored_opts.dup + + config ||= {} + config = stored_config.merge(_shared_configuration).merge!(config) + [ klass, klass.new(args, opts, config) ] + else + [ object.class, object ] + end + end end end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/parser.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb index 57a3f6e1a5..57a3f6e1a5 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/parser.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/argument.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb index 2d7f4dbafb..aa8ace4719 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/argument.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb @@ -1,5 +1,5 @@ class Thor - class Argument + class Argument #:nodoc: VALID_TYPES = [ :numeric, :hash, :array, :string ] attr_reader :name, :description, :required, :type, :default, :banner diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/arguments.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb index 9a2262d6f7..fb5d965e06 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/arguments.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb @@ -1,5 +1,5 @@ class Thor - class Arguments + class Arguments #:nodoc: NUMERIC = /(\d*\.\d+|\d+)/ # Receives an array of args and returns two arrays, one with arguments diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/option.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb index 5c43f6b18f..9e40ec73fa 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/option.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb @@ -1,5 +1,5 @@ class Thor - class Option < Argument + class Option < Argument #:nodoc: attr_reader :aliases, :group VALID_TYPES = [:boolean, :numeric, :hash, :array, :string] diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/options.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb index 01c86b7b27..75092308b5 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/parser/options.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb @@ -2,7 +2,7 @@ class Thor # This is a modified version of Daniel Berger's Getopt::Long class, licensed # under Ruby's license. # - class Options < Arguments + class Options < Arguments #:nodoc: LONG_RE = /^(--\w+[-\w+]*)$/ SHORT_RE = /^(-[a-z])$/i EQ_RE = /^(--\w+[-\w+]*|-[a-z])=(.*)$/i diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb new file mode 100644 index 0000000000..3ab6bb21f5 --- /dev/null +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb @@ -0,0 +1,67 @@ +require 'rake' + +class Thor + # Adds a compatibility layer to your Thor classes which allows you to use + # rake package tasks. For example, to use rspec rake tasks, one can do: + # + # require 'thor/rake_compat' + # + # class Default < Thor + # include Thor::RakeCompat + # + # Spec::Rake::SpecTask.new(:spec) do |t| + # t.spec_opts = ['--options', "spec/spec.opts"] + # t.spec_files = FileList['spec/**/*_spec.rb'] + # end + # end + # + module RakeCompat + def self.rake_classes + @rake_classes ||= [] + end + + def self.included(base) + # Hack. Make rakefile point to invoker, so rdoc task is generated properly. + Rake.application.instance_variable_set(:@rakefile, caller[0].match(/(.*):\d+/)[1]) + self.rake_classes << base + end + end +end + +class Object #:nodoc: + alias :rake_task :task + alias :rake_namespace :namespace + + def task(*args, &block) + task = rake_task(*args, &block) + + if klass = Thor::RakeCompat.rake_classes.last + non_namespaced_name = task.name.split(':').last + + description = non_namespaced_name + description << task.arg_names.map{ |n| n.to_s.upcase }.join(' ') + description.strip! + + klass.desc description, task.comment || non_namespaced_name + klass.class_eval <<-METHOD + def #{non_namespaced_name}(#{task.arg_names.join(', ')}) + Rake::Task[#{task.name.to_sym.inspect}].invoke(#{task.arg_names.join(', ')}) + end + METHOD + end + + task + end + + def namespace(name, &block) + if klass = Thor::RakeCompat.rake_classes.last + const_name = Thor::Util.camel_case(name.to_s).to_sym + klass.const_set(const_name, Class.new(Thor)) + new_klass = klass.const_get(const_name) + Thor::RakeCompat.rake_classes << new_klass + end + + rake_namespace(name, &block) + Thor::RakeCompat.rake_classes.pop + end +end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/runner.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb index 6782c61dec..3639ac0aa9 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/runner.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb @@ -4,7 +4,7 @@ require 'yaml' require 'digest/md5' require 'pathname' -class Thor::Runner < Thor +class Thor::Runner < Thor #:nodoc: map "-T" => :list, "-i" => :install, "-u" => :update # Override Thor#help so it can give information about any class and any method. @@ -12,8 +12,9 @@ class Thor::Runner < Thor def help(meth=nil) if meth && !self.respond_to?(meth) initialize_thorfiles(meth) - klass, task = Thor::Util.namespace_to_thor_class(meth) - klass.start(["-h", task].compact, :shell => self.shell) # send mapping -h because it works with Thor::Group too + klass, task = Thor::Util.namespace_to_thor_class_and_task(meth) + # Send mapping -h because it works with Thor::Group too + klass.start(["-h", task].compact, :shell => self.shell) else super end @@ -25,12 +26,12 @@ class Thor::Runner < Thor def method_missing(meth, *args) meth = meth.to_s initialize_thorfiles(meth) - klass, task = Thor::Util.namespace_to_thor_class(meth) + klass, task = Thor::Util.namespace_to_thor_class_and_task(meth) args.unshift(task) if task klass.start(args, :shell => shell) end - desc "install NAME", "Install a Thor file into your system tasks, optionally named for future updates" + desc "install NAME", "Install an optionally named Thor file into your system tasks" method_options :as => :string, :relative => :boolean def install(name) initialize_thorfiles @@ -76,7 +77,7 @@ class Thor::Runner < Thor thor_yaml[as] = { :filename => Digest::MD5.hexdigest(name + as), :location => location, - :namespaces => Thor::Util.namespaces_in_contents(contents, base) + :namespaces => Thor::Util.namespaces_in_content(contents, base) } save_yaml(thor_yaml) @@ -130,8 +131,7 @@ class Thor::Runner < Thor display_klasses(true, klasses) end - desc "list [SEARCH]", - "List the available thor tasks (--substring means SEARCH anywhere in the namespace)" + desc "list [SEARCH]", "List the available thor tasks (--substring means .*SEARCH)" method_options :substring => :boolean, :group => :string, :all => :boolean def list(search="") initialize_thorfiles @@ -269,6 +269,10 @@ class Thor::Runner < Thor end unless klasses.empty? + klasses.dup.each do |klass| + klasses -= Thor::Util.thor_classes_in(klass) + end + klasses.each { |k| display_tasks(k) } else say "\033[1;34mNo Thor tasks available\033[0m" @@ -285,7 +289,7 @@ class Thor::Runner < Thor say shell.set_color(base, color, true) say "-" * base.length - klass.help(shell, :short => true, :namespace => true) + klass.help(shell, :short => true, :ident => 0, :namespace => true) end end end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/shell.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb index 7ed4a24bfb..0d3f4d5951 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/shell.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb @@ -64,7 +64,7 @@ class Thor # Allow shell to be shared between invocations. # - def _shared_configuration + def _shared_configuration #:nodoc: super.merge!(:shell => self.shell) end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/shell/basic.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb index e294c87567..3c02e47c33 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/shell/basic.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb @@ -11,9 +11,9 @@ class Thor @base, @padding = nil, 0 end - # Do not allow padding to be less than zero. + # Sets the output padding, not allowing less than zero values. # - def padding=(value) #:nodoc: + def padding=(value) @padding = [0, value].max end @@ -52,7 +52,7 @@ class Thor # in log_status, avoiding the message from being shown. If a Symbol is # given in log_status, it's used as the color. # - def say_status(status, message, log_status=true) #:nodoc: + def say_status(status, message, log_status=true) return if quiet? || log_status == false spaces = " " * (padding + 1) color = log_status.is_a?(Symbol) ? log_status : :green @@ -80,17 +80,21 @@ class Thor # # ==== Parameters # list<Array[String, String, ...]> - # mode<Symbol>:: Can be :rows or :inline. Defaults to :rows. # - def print_list(list, mode=:rows) + # ==== Options + # mode:: Can be :rows or :inline. Defaults to :rows. + # ident:: Ident each item with the value given. + # + def print_list(list, options={}) return if list.empty? - content = case mode + ident = " " * (options[:ident] || 0) + content = case options[:mode] when :inline last = list.pop "#{list.join(", ")}, and #{last}" else # rows - list.join("\n") + ident + list.join("\n#{ident}") end $stdout.puts content @@ -103,7 +107,6 @@ class Thor # # ==== Options # ident<Integer>:: Ident the first column by ident value. - # emphasize_last<Boolean>:: When true, add a different behavior to the last column. # def print_table(table, options={}) return if table.empty? @@ -131,7 +134,7 @@ class Thor # # ==== Parameters # destination<String>:: the destination file to solve conflicts - # block<Proc>:: an optional proc that returns the value to be used in diff + # block<Proc>:: an optional block that returns the value to be used in diff # def file_collision(destination) return true if @always_force @@ -164,19 +167,20 @@ class Thor # wrong, you can always raise an exception. If you raise a Thor::Error, it # will be rescued and wrapped in the method below. # - def error(statement) #:nodoc: + def error(statement) $stderr.puts statement end - # Apply color to the given string with optional bold. + # Apply color to the given string with optional bold. Disabled in the + # Thor::Shell::Basic class. # - def set_color(string, color, bold=false) + def set_color(string, color, bold=false) #:nodoc: string end protected - def is?(value) + def is?(value) #:nodoc: value = value.to_s if value.size == 1 @@ -186,7 +190,7 @@ class Thor end end - def file_collision_help + def file_collision_help #:nodoc: <<HELP Y - yes, overwrite n - no, do not overwrite @@ -197,17 +201,17 @@ h - help, show this help HELP end - def show_diff(destination, content) + def show_diff(destination, content) #:nodoc: diff_cmd = ENV['THOR_DIFF'] || ENV['RAILS_DIFF'] || 'diff -u' Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp| temp.write content temp.rewind - say `#{diff_cmd} "#{destination}" "#{temp.path}"` + system %(#{diff_cmd} "#{destination}" "#{temp.path}") end end - def quiet? + def quiet? #:nodoc: base && base.options[:quiet] end diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/shell/color.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb index be7995146a..24704f7885 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/shell/color.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb @@ -2,7 +2,8 @@ require 'thor/shell/basic' class Thor module Shell - # Set color in the output. Got color values from HighLine. + # Inherit from Thor::Shell::Basic and add set_color behavior. Check + # Thor::Shell::Basic to see all available methods. # class Color < Basic # Embed in a String to clear all previous ANSI sequences. @@ -44,9 +45,10 @@ class Thor # Set the terminal's background ANSI color to white. ON_WHITE = "\e[47m" - # Set color by using a string or one of the defined constants. Based - # on Highline implementation. CLEAR is automatically be embedded to - # the end of the returned String. + # Set color by using a string or one of the defined constants. If a third + # option is set to true, it also adds bold to the string. This is based + # on Highline implementation and it automatically appends CLEAR to the end + # of the returned String. # def set_color(string, color, bold=false) color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol) @@ -59,7 +61,7 @@ class Thor # Overwrite show_diff to show diff with colors if Diff::LCS is # available. # - def show_diff(destination, content) + def show_diff(destination, content) #:nodoc: if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil? actual = File.read(destination).to_s.split("\n") content = content.to_s.split("\n") @@ -72,7 +74,7 @@ class Thor end end - def output_diff_line(diff) + def output_diff_line(diff) #:nodoc: case diff.action when '-' say "- #{diff.old_element.chomp}", :red, true @@ -89,7 +91,7 @@ class Thor # Check if Diff::LCS is loaded. If it is, use it to create pretty output # for diff. # - def diff_lcs_loaded? + def diff_lcs_loaded? #:nodoc: return true if defined?(Diff::LCS) return @diff_lcs_loaded unless @diff_lcs_loaded.nil? diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/task.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/task.rb index 92c0776c04..23d35b883c 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/task.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/task.rb @@ -12,7 +12,7 @@ class Thor super(name.to_s, description, usage, options || {}) end - def initialize_copy(other) + def initialize_copy(other) #:nodoc: super(other) self.options = other.options.dup if other.options end @@ -36,11 +36,19 @@ class Thor # Returns the formatted usage. If a class is given, the class arguments are # injected in the usage. # - def formatted_usage(klass=nil, namespace=false) + def formatted_usage(klass=nil, namespace=false, show_options=true) formatted = '' - formatted << "#{klass.namespace.gsub(/^default/,'')}:" if klass && namespace + + formatted = if namespace.is_a?(String) + "#{namespace}:" + elsif klass && namespace + "#{klass.namespace.gsub(/^default/,'')}:" + else + "" + end + formatted << formatted_arguments(klass) - formatted << " #{formatted_options}" + formatted << " #{formatted_options}" if show_options formatted.strip! formatted end @@ -67,20 +75,20 @@ class Thor # Given a target, checks if this class name is not a private/protected method. # - def public_method?(instance) + def public_method?(instance) #:nodoc: collection = instance.private_methods + instance.protected_methods !(collection).include?(name.to_s) && !(collection).include?(name.to_sym) # For Ruby 1.9 end # Clean everything that comes from the Thor gempath and remove the caller. # - def sans_backtrace(backtrace, caller) + def sans_backtrace(backtrace, caller) #:nodoc: dirname = /^#{Regexp.escape(File.dirname(__FILE__))}/ saned = backtrace.reject { |frame| frame =~ dirname } saned -= caller end - def parse_argument_error(instance, e, caller) + def parse_argument_error(instance, e, caller) #:nodoc: backtrace = sans_backtrace(e.backtrace, caller) if backtrace.empty? && e.message =~ /wrong number of arguments/ @@ -95,7 +103,7 @@ class Thor end end - def parse_no_method_error(instance, e) + def parse_no_method_error(instance, e) #:nodoc: if e.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/ raise UndefinedTaskError, "The #{instance.class.namespace} namespace " << "doesn't have a '#{name}' task" diff --git a/railties/lib/vendor/thor-0.11.3/lib/thor/util.rb b/railties/lib/vendor/thor-0.11.5/lib/thor/util.rb index 26db24aadb..4938dc4aca 100644 --- a/railties/lib/vendor/thor-0.11.3/lib/thor/util.rb +++ b/railties/lib/vendor/thor-0.11.5/lib/thor/util.rb @@ -1,14 +1,14 @@ require 'rbconfig' class Thor - module Sandbox; end + module Sandbox #:nodoc: + end # This module holds several utilities: # # 1) Methods to convert thor namespaces to constants and vice-versa. # - # Thor::Utils.constant_to_namespace(Foo::Bar::Baz) #=> "foo:bar:baz" - # Thor::Utils.namespace_to_constant("foo:bar:baz") #=> Foo::Bar::Baz + # Thor::Utils.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz" # # 2) Loading thor files and sandboxing: # @@ -43,15 +43,15 @@ class Thor # ==== Returns # String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz" # - def self.constant_to_namespace(constant, remove_default=true) + def self.namespace_from_thor_class(constant, remove_default=true) constant = constant.to_s.gsub(/^Thor::Sandbox::/, "") constant = snake_case(constant).squeeze(":") constant.gsub!(/^default/, '') if remove_default constant end - # Given the contents, evaluate it inside the sandbox and returns the thor - # classes defined in the sandbox. + # Given the contents, evaluate it inside the sandbox and returns the + # namespaces defined in the sandbox. # # ==== Parameters # contents<String> @@ -59,7 +59,7 @@ class Thor # ==== Returns # Array[Object] # - def self.namespaces_in_contents(contents, file=__FILE__) + def self.namespaces_in_content(contents, file=__FILE__) old_constants = Thor::Base.subclasses.dup Thor::Base.subclasses.clear @@ -73,6 +73,14 @@ class Thor new_constants end + # Returns the thor classes declared inside the given class. + # + def self.thor_classes_in(klass) + Thor::Base.subclasses.select do |subclass| + klass.constants.include?(subclass.name.gsub("#{klass.name}::", '')) + end + end + # Receives a string and convert it to snake case. SnakeCase returns snake_case. # # ==== Parameters @@ -87,6 +95,19 @@ class Thor return $+.downcase end + # Receives a string and convert it to camel case. camel_case returns CamelCase. + # + # ==== Parameters + # String + # + # ==== Returns + # String + # + def self.camel_case(str) + return str if str !~ /_/ && str =~ /[A-Z]+.*/ + str.split('_').map { |i| i.capitalize }.join + end + # Receives a namespace and tries to retrieve a Thor or Thor::Group class # from it. It first searches for a class using the all the given namespace, # if it's not found, removes the highest entry and searches for the class @@ -115,7 +136,7 @@ class Thor # Thor::Error:: raised if the namespace evals to a class which does not # inherit from Thor or Thor::Group. # - def self.namespace_to_thor_class(namespace, raise_if_nil=true) + def self.namespace_to_thor_class_and_task(namespace, raise_if_nil=true) klass, task_name = Thor::Util.find_by_namespace(namespace), nil if klass.nil? && namespace.include?(?:) @@ -156,7 +177,7 @@ class Thor yaml.each do |k, v| next unless v[:constants] && v[:namespaces].nil? yaml_changed = true - yaml[k][:namespaces] = v[:constants].map{|c| Thor::Util.constant_to_namespace(c)} + yaml[k][:namespaces] = v[:constants].map{|c| Thor::Util.namespace_from_thor_class(c)} end yaml_changed @@ -214,7 +235,7 @@ class Thor # Return the path to the ruby interpreter taking into account multiple # installations and windows extensions. # - def self.ruby_command #:nodoc: + def self.ruby_command @ruby_command ||= begin ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) ruby << Config::CONFIG['EXEEXT'] diff --git a/railties/test/fixtures/lib/template.rb b/railties/test/fixtures/lib/template.rb new file mode 100644 index 0000000000..c14a1a8784 --- /dev/null +++ b/railties/test/fixtures/lib/template.rb @@ -0,0 +1 @@ +say "It works from file!" diff --git a/railties/test/fixtures/vendor/gems/mspec/lib/generators/mspec_generator.rb b/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb index 191bdbf2fc..191bdbf2fc 100644 --- a/railties/test/fixtures/vendor/gems/mspec/lib/generators/mspec_generator.rb +++ b/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb diff --git a/railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb b/railties/test/fixtures/vendor/gems/gems/wrong/lib/generators/wrong_generator.rb index 6aa7cb052e..6aa7cb052e 100644 --- a/railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb +++ b/railties/test/fixtures/vendor/gems/gems/wrong/lib/generators/wrong_generator.rb 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/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index c794a2ade6..19e41c15c8 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -131,6 +131,11 @@ class AppGeneratorTest < GeneratorsTestCase assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/ end + def test_template_from_dir_pwd + FileUtils.cd(RAILS_ROOT) + assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"]) + end + def test_template_raises_an_error_with_invalid_path content = capture(:stderr){ run_generator(["-m", "non/existant/path"]) } assert_match /The template \[.*\] could not be loaded/, content diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 011bd518f8..9444a9ed4b 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -20,7 +20,7 @@ class GeneratorsTestCase < Test::Unit::TestCase def destination_root @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__), - '..', '..', 'fixtures', 'tmp')) + '..', 'fixtures', 'tmp')) end def setup 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/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 024ea439ef..834e43e776 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -99,7 +99,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase def test_error_is_shown_if_orm_does_not_provide_interface error = capture(:stderr){ run_generator ["User", "--orm=unknown"] } - assert_equal "Could not load Unknown::Generators::ActionORM, skipping controller. " << + assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " << "Error: no such file to load -- generators/unknown.\n", error end 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" |