From b04618e707a73d2bcd617fd82e54e736736158b1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Feb 2005 19:35:13 +0000 Subject: Fixed generated functional test for nested controllers has wrong paths #635 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@631 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/rails_generator/base.rb | 7 ++++--- .../components/controller/templates/functional_test.rb | 4 ++-- .../generators/components/model/templates/fixtures.yml | 3 --- .../generators/components/scaffold/scaffold_generator.rb | 6 ++++-- .../components/scaffold/templates/functional_test.rb | 4 ++-- railties/lib/rails_generator/options.rb | 13 ++++++++----- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/railties/lib/rails_generator/base.rb b/railties/lib/rails_generator/base.rb index eafc99728c..f7aa2169ca 100644 --- a/railties/lib/rails_generator/base.rb +++ b/railties/lib/rails_generator/base.rb @@ -145,7 +145,7 @@ module Rails # See Rails::Generator::Base for a discussion of Manifests and Commands. class NamedBase < Base attr_reader :name, :class_name, :singular_name, :plural_name - attr_reader :class_path, :class_nesting + attr_reader :class_path, :file_path, :class_nesting, :class_nesting_depth alias_method :file_name, :singular_name alias_method :table_name, :plural_name alias_method :actions, :args @@ -170,7 +170,7 @@ module Rails private def assign_names!(name) @name = name - base_name, @class_path, @class_nesting = extract_modules(@name) + base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name) @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) if @class_nesting.empty? @class_name = @class_name_without_nesting @@ -187,8 +187,9 @@ module Rails modules = name.include?('/') ? name.split('/') : name.split('::') name = modules.pop path = modules.map { |m| m.underscore } + file_path = (path + [name.underscore]).join('/') nesting = modules.map { |m| m.camelize }.join('::') - [name, path, nesting] + [name, path, file_path, nesting, modules.size] end def inflect_names(name) diff --git a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb index 76e2b33ba5..fcc3efd485 100644 --- a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/../test_helper' -require '<%= file_name %>_controller' +require File.dirname(__FILE__) + <%= '/..' * class_nesting_depth %> + '/../test_helper' +require '<%= file_path %>_controller' # Re-raise errors caught by the controller. class <%= class_name %>Controller; def rescue_action(e) raise e end; end diff --git a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml index 6285727968..d29fcff2ff 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml +++ b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml @@ -1,8 +1,5 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -# Set the $base_id variable in the setup method of your tests. -# It's used to ensure that ids don't clash in some databases. first_<%= singular_name %>: id: 1 - another_<%= singular_name %>: id: 2 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 abf9d79ffe..883bae7d3d 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -30,7 +30,9 @@ end class ScaffoldGenerator < Rails::Generator::NamedBase attr_reader :controller_name, :controller_class_path, + :controller_file_path, :controller_class_nesting, + :controller_class_nesting_depth, :controller_class_name, :controller_singular_name, :controller_plural_name @@ -40,7 +42,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase def initialize(runtime_args, runtime_options = {}) super @controller_name = args.shift || @name.pluralize - base_name, @controller_class_path, @controller_class_nesting = extract_modules(@controller_name) + base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) if @controller_class_nesting.empty? @controller_class_name = @controller_class_name_without_nesting @@ -75,7 +77,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase controller_class_path, "#{controller_file_name}_controller_test.rb") - m.template 'controller:helper.rb', + m.template 'helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb") diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb index 32185fb715..1d45f23958 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/../test_helper' -require '<%= controller_file_name %>_controller' +require File.dirname(__FILE__) + <%= '/..' * controller_class_nesting_depth %> + '/../test_helper' +require '<%= controller_file_path %>_controller' # Re-raise errors caught by the controller. class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end diff --git a/railties/lib/rails_generator/options.rb b/railties/lib/rails_generator/options.rb index 287605c852..4374249314 100644 --- a/railties/lib/rails_generator/options.rb +++ b/railties/lib/rails_generator/options.rb @@ -2,10 +2,6 @@ require 'optparse' module Rails module Generator - # Implement add_options! to add your options to the parser: - # def add_options!(opt) - # opt.on('-v', '--verbose') { |value| options[:verbose] = value } - # end module Options def self.append_features(base) super @@ -88,7 +84,7 @@ module Rails @option_parser = OptionParser.new do |opt| opt.banner = banner - add_options!(opt) if respond_to?(:add_options!) + add_options!(opt) add_general_options!(opt) opt.parse!(args) end @@ -113,6 +109,13 @@ module Rails "Usage: #{$0} [options]" end + # Override to add your options to the parser: + # def add_options!(opt) + # opt.on('-v', '--verbose') { |value| options[:verbose] = value } + # end + def add_options!(opt) + end + # Adds general options like -h and --quiet. Usually don't override. def add_general_options!(opt) opt.separator '' -- cgit v1.2.3