From a93ea88c0623b4f65af98c0eb55924c335bb3ac1 Mon Sep 17 00:00:00 2001 From: Bob Klosinski Date: Wed, 25 Jun 2008 16:40:00 -0500 Subject: Added Thin support to script/server. [#488 state:resolved] --- railties/CHANGELOG | 2 ++ railties/lib/commands/server.rb | 14 ++++++++++++-- railties/lib/commands/servers/thin.rb | 25 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 railties/lib/commands/servers/thin.rb (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 7e5c35da15..a37dc6c0eb 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Added Thin support to script/server. #488 [Bob Klosinski] + * Fix script/about in production mode. #370 [Cheah Chu Yeow, Xavier Noria, David Krmpotic] * Add the gem load paths before the framework is loaded, so certain gems like RedCloth and BlueCloth can be frozen. diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 40ffdd1167..7306c248fb 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -13,11 +13,19 @@ rescue Exception # Mongrel not available end +begin + require_library_or_gem 'thin' +rescue Exception + # Thin not available +end + server = case ARGV.first - when "lighttpd", "mongrel", "new_mongrel", "webrick" + when "lighttpd", "mongrel", "new_mongrel", "webrick", "thin" ARGV.shift else - if defined?(Mongrel) + if defined?(Thin) + "thin" + elsif defined?(Mongrel) "mongrel" elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI) "lighttpd" @@ -33,6 +41,8 @@ case server puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)" when "mongrel", "new_mongrel" puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)" + when "thin" + puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)" end %w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) } diff --git a/railties/lib/commands/servers/thin.rb b/railties/lib/commands/servers/thin.rb new file mode 100644 index 0000000000..833469cab1 --- /dev/null +++ b/railties/lib/commands/servers/thin.rb @@ -0,0 +1,25 @@ +require 'rbconfig' +require 'commands/servers/base' +require 'thin' + + +options = ARGV.clone +options.insert(0,'start') unless Thin::Runner.commands.include?(options[0]) + +thin = Thin::Runner.new(options) + +puts "=> Rails #{Rails.version} application starting on http://#{thin.options[:address]}:#{thin.options[:port]}" +puts "=> Ctrl-C to shutdown server" + +log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath +open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log +tail_thread = tail(log) +trap(:INT) { exit } + +begin + thin.run! +ensure + tail_thread.kill if tail_thread + puts 'Exiting' +end + -- cgit v1.2.3 From 4ddca325eeef46e640a225efb9b297260e1e8e7d Mon Sep 17 00:00:00 2001 From: Pat George Date: Wed, 4 Jun 2008 15:13:50 -0400 Subject: Warn and uses singularized ModelName if a plural ModelName is given to script/generate. Override with --force-plural. [#333 state:resolved] Signed-off-by: Pratik Naik --- .../components/scaffold/scaffold_generator.rb | 9 ++++- .../generators/rails_scaffold_generator_test.rb | 42 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb index e2902bf4b9..5fecfe0167 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -1,5 +1,5 @@ class ScaffoldGenerator < Rails::Generator::NamedBase - default_options :skip_timestamps => false, :skip_migration => false + default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false attr_reader :controller_name, :controller_class_path, @@ -16,6 +16,11 @@ class ScaffoldGenerator < Rails::Generator::NamedBase def initialize(runtime_args, runtime_options = {}) super + if @name == @name.pluralize && !options[:force_plural] + logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural." + @name = @name.singularize + end + @controller_name = @name.pluralize base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) @@ -81,6 +86,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v } opt.on("--skip-migration", "Don't generate a migration file for this model") { |v| options[:skip_migration] = v } + opt.on("--force-plural", + "Forces the generation of a plural ModelName") { |v| options[:force_plural] = v } end def scaffold_views diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb index 220f9e372e..de6b38dafe 100644 --- a/railties/test/generators/rails_scaffold_generator_test.rb +++ b/railties/test/generators/rails_scaffold_generator_test.rb @@ -1,4 +1,5 @@ require 'generators/generator_test_helper' +require 'abstract_unit' class RailsScaffoldGeneratorTest < GeneratorTestCase @@ -104,4 +105,45 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_added_route_for :products end + uses_mocha("scaffold_force_plural_names") do + def test_scaffolded_plural_names + Rails::Generator::Base.logger.expects(:warning) + g = Rails::Generator::Base.instance('scaffold', %w(ProductLines)) + assert_equal "ProductLines", g.controller_name + assert_equal "ProductLines", g.controller_class_name + assert_equal "ProductLine", g.controller_singular_name + assert_equal "product_lines", g.controller_plural_name + assert_equal "product_lines", g.controller_file_name + assert_equal "product_lines", g.controller_table_name + end + end + + def test_scaffold_plural_model_name_without_force_plural_generates_singular_model + run_generator('scaffold', %w(Products name:string)) + + assert_generated_model_for :product + assert_generated_functional_test_for :products + assert_generated_unit_test_for :product + assert_generated_fixtures_for :products + assert_generated_helper_for :products + assert_generated_stylesheet :scaffold + assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" + assert_skipped_migration :create_products + assert_added_route_for :products + end + + def test_scaffold_plural_model_name_with_force_plural_forces_plural_model + run_generator('scaffold', %w(Products name:string --force-plural)) + + assert_generated_model_for :products + assert_generated_functional_test_for :products + assert_generated_unit_test_for :products + assert_generated_fixtures_for :products + assert_generated_helper_for :products + assert_generated_stylesheet :scaffold + assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" + assert_skipped_migration :create_products + assert_added_route_for :products + end + end -- cgit v1.2.3 From 76e00fc784f1f2d87727d9cb230f40588aa7f5a6 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 27 Jun 2008 18:18:39 +0100 Subject: Ensure observer test inherits from ActiveSupport::TestCase --- .../generators/components/observer/templates/unit_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb index cae38e9a2a..03f6d5666e 100644 --- a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class <%= class_name %>ObserverTest < Test::Unit::TestCase +class <%= class_name %>ObserverTest < ActiveSupport::TestCase # Replace this with your real tests. test "the truth" do assert true -- cgit v1.2.3 From a81f16af31b28203a7c2c6cd89249a90487b7fe0 Mon Sep 17 00:00:00 2001 From: Carl Porth Date: Tue, 27 May 2008 14:21:01 -0700 Subject: Ensure Rails::Generator quotes file names while generating diff. [#264 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/rails_generator/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 08ecbfb5cf..fb62ba6940 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -88,7 +88,7 @@ module Rails Tempfile.open(File.basename(destination), File.dirname(dst)) do |temp| temp.write render_file(src, file_options, &block) temp.rewind - $stdout.puts `#{diff_cmd} #{dst} #{temp.path}` + $stdout.puts `#{diff_cmd} "#{dst}" "#{temp.path}"` end puts "retrying" raise 'retry diff' -- cgit v1.2.3 From 3a95ee73cfbcfeada3b053c5b0fb7b5125ef12c7 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 19 Apr 2008 00:42:26 -0500 Subject: Make rake test:uncommitted work with Git. Note : rake test:uncommitted is considering only unstaged files. Signed-off-by: Pratik Naik --- railties/CHANGELOG | 2 ++ railties/lib/tasks/testing.rake | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index a37dc6c0eb..c18d5ac9b2 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Make rake test:uncommitted work with Git. [Tim Pope] + * Added Thin support to script/server. #488 [Bob Klosinski] * Fix script/about in production mode. #370 [Cheah Chu Yeow, Xavier Noria, David Krmpotic] diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake index c8ba6eed94..328bde7442 100644 --- a/railties/lib/tasks/testing.rake +++ b/railties/lib/tasks/testing.rake @@ -66,10 +66,16 @@ namespace :test do Rake::TestTask.new(:uncommitted => "db:test:prepare") do |t| def t.file_list - changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] } + if File.directory?(".svn") + changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] } + elsif File.directory?(".git") + changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.map { |path| path.chomp } + else + abort "Not a Subversion or Git checkout." + end - models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb/ } - controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb/ } + models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ } + controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ } unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } @@ -80,7 +86,7 @@ namespace :test do t.libs << 'test' t.verbose = true end - Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion)" + Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" Rake::TestTask.new(:units => "db:test:prepare") do |t| t.libs << "test" -- cgit v1.2.3 From 820992c98f27abf8a20746283d0e16caece99b5e Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Tue, 1 Jul 2008 16:33:40 +0100 Subject: Ensure script/plugin unsource 'Usage' text is correct. [#526 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/commands/plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 105819ce90..ce4b0d051d 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -632,7 +632,7 @@ module Commands def options OptionParser.new do |o| o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} source URI [URI [URI]...]" + o.banner = "Usage: #{@base_command.script_name} unsource URI [URI [URI]...]" o.define_head "Remove repositories from the default search list." o.separator "" o.on_tail("-h", "--help", "Show this help message.") { puts o; exit } -- cgit v1.2.3 From 6c0edef26ee1c0e5f0964cae64c9f48da6daf1fa Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 2 Jul 2008 21:29:57 -0500 Subject: Added Rails.initialized? flag --- railties/CHANGELOG | 2 ++ railties/lib/initializer.rb | 55 ++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 23 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index c18d5ac9b2..1b9bdb57f2 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Added Rails.initialized? flag [Josh Peek] + * Make rake test:uncommitted work with Git. [Tim Pope] * Added Thin support to script/server. #488 [Bob Klosinski] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 3d94cedb47..d80460d4bc 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -19,15 +19,23 @@ module Rails def configuration @@configuration end - + def configuration=(configuration) @@configuration = configuration end - + + def initialized? + @initialized || false + end + + def initialized=(initialized) + @initialized ||= initialized + end + def logger RAILS_DEFAULT_LOGGER end - + def root if defined?(RAILS_ROOT) RAILS_ROOT @@ -35,11 +43,11 @@ module Rails nil end end - + def env ActiveSupport::StringInquirer.new(RAILS_ENV) end - + def cache RAILS_CACHE end @@ -56,7 +64,7 @@ module Rails @@public_path = path end end - + # The Initializer is responsible for processing the Rails configuration, such # as setting the $LOAD_PATH, requiring the right frameworks, initializing # logging, and more. It can be run either as a single command that'll just @@ -145,7 +153,7 @@ module Rails add_gem_load_paths load_gems check_gem_dependencies - + load_application_initializers # the framework is now fully initialized @@ -158,8 +166,10 @@ module Rails initialize_routing # Observers are loaded after plugins in case Observers or observed models are modified by plugins. - load_observers + + # Flag initialized + Rails.initialized = true end # Check for valid Ruby version @@ -297,12 +307,12 @@ module Rails silence_warnings do return if @environment_loaded @environment_loaded = true - + config = configuration constants = self.class.constants - + eval(IO.read(configuration.environment_path), binding, configuration.environment_path) - + (self.class.constants - constants).each do |const| Object.const_set(const, self.class.const_get(const)) end @@ -390,7 +400,7 @@ module Rails for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks) framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER end - + RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER end @@ -486,7 +496,6 @@ module Rails Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch end - end # The Configuration class holds all the parameters for the Initializer and @@ -531,7 +540,7 @@ module Rails # The path to the database configuration file to use. (Defaults to # config/database.yml.) attr_accessor :database_configuration_file - + # The path to the routes configuration file to use. (Defaults to # config/routes.rb.) attr_accessor :routes_configuration_file @@ -597,7 +606,7 @@ module Rails # a sub class would have access to fine grained modification of the loading behavior. See # the implementation of Rails::Plugin::Loader for more details. attr_accessor :plugin_loader - + # Enables or disables plugin reloading. You can get around this setting per plugin. # If reload_plugins? is false, add this to your plugin's init.rb # to make it reloadable: @@ -634,7 +643,7 @@ module Rails def gem(name, options = {}) @gems << Rails::GemDependency.new(name, options) end - + # Deprecated options: def breakpoint_server(_ = nil) $stderr.puts %( @@ -693,7 +702,7 @@ module Rails else Pathname.new(::RAILS_ROOT).realpath.to_s end - + Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT) ::RAILS_ROOT.replace @root_path end @@ -734,7 +743,7 @@ module Rails # # See Dispatcher#to_prepare. def to_prepare(&callback) - after_initialize do + after_initialize do require 'dispatcher' unless defined?(::Dispatcher) Dispatcher.to_prepare(&callback) end @@ -748,11 +757,11 @@ module Rails def framework_paths paths = %w(railties railties/lib activesupport/lib) paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view - + [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework end - + paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } end @@ -767,7 +776,7 @@ module Rails def default_load_paths paths = [] - + # Add the old mock paths only if the directories exists paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}") @@ -853,7 +862,7 @@ module Rails def default_plugin_loader Plugin::Loader end - + def default_cache_store if File.exist?("#{root_path}/tmp/cache/") [ :file_store, "#{root_path}/tmp/cache/" ] @@ -861,7 +870,7 @@ module Rails :memory_store end end - + def default_gems [] end -- cgit v1.2.3 From dc2d754d60378b529c239e1291932503d4d8fca5 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sun, 22 Jun 2008 16:00:40 +0300 Subject: Support for custom annotations with rake notes:custom and DRY up the task definition. e.g. rake notes:custom ANNOTATION=WTF --- railties/lib/tasks/annotations.rake | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/lib/tasks/annotations.rake b/railties/lib/tasks/annotations.rake index ea6046670f..48ac40099a 100644 --- a/railties/lib/tasks/annotations.rake +++ b/railties/lib/tasks/annotations.rake @@ -6,18 +6,15 @@ task :notes do end namespace :notes do - desc "Enumerate all OPTIMIZE annotations" - task :optimize do - SourceAnnotationExtractor.enumerate "OPTIMIZE" + ["OPTIMIZE", "FIXME", "TODO"].each do |annotation| + desc "Enumerate all #{annotation} annotations" + task annotation.downcase.intern do + SourceAnnotationExtractor.enumerate annotation + end end - desc "Enumerate all FIXME annotations" - task :fixme do - SourceAnnotationExtractor.enumerate "FIXME" - end - - desc "Enumerate all TODO annotations" - task :todo do - SourceAnnotationExtractor.enumerate "TODO" + desc "Enumerate a custom annotation, specify with ANNOTATION=WTFHAX" + task :custom do + SourceAnnotationExtractor.enumerate ENV['ANNOTATION'] end end \ No newline at end of file -- cgit v1.2.3