Permalink
Browse files

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
  • Loading branch information...
1 parent 575ad6d commit b04618e707a73d2bcd617fd82e54e736736158b1 @dhh dhh committed Feb 15, 2005
View
7 railties/lib/rails_generator/base.rb
@@ -145,7 +145,7 @@ def usage_message
# 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 @@ def banner
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 @@ def extract_modules(name)
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)
View
4 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
View
3 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
View
6 railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
@@ -30,7 +30,9 @@ def to_datetime_select_tag(options = {})
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 @@ def manifest
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")
View
4 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
View
13 railties/lib/rails_generator/options.rb
@@ -2,10 +2,6 @@
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 @@ def parse!(args, runtime_options = {})
@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 @@ def banner
"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 ''

0 comments on commit b04618e

Please sign in to comment.