diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-05-13 15:49:41 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-05-13 15:50:06 -0500 |
commit | 4562a5b57f5999fadc8b0957ed5777f35be8dea5 (patch) | |
tree | 567a134ec0c6862ced46132525a44ae5a2dfb39b /railties/test/generators/generator_test_helper.rb | |
parent | 3a0d8adcf25e27f7976a1d0996be05f21ffc3805 (diff) | |
download | rails-4562a5b57f5999fadc8b0957ed5777f35be8dea5.tar.gz rails-4562a5b57f5999fadc8b0957ed5777f35be8dea5.tar.bz2 rails-4562a5b57f5999fadc8b0957ed5777f35be8dea5.zip |
Add some test coverage for RailsControllerGenerator.
Diffstat (limited to 'railties/test/generators/generator_test_helper.rb')
-rw-r--r-- | railties/test/generators/generator_test_helper.rb | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/railties/test/generators/generator_test_helper.rb b/railties/test/generators/generator_test_helper.rb index 190bc91d52..c99df6e2d3 100644 --- a/railties/test/generators/generator_test_helper.rb +++ b/railties/test/generators/generator_test_helper.rb @@ -13,7 +13,7 @@ module ActiveRecord module ConnectionAdapters class Column attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale - + def initialize(name, default, sql_type = nil) @name = name @default = default @@ -59,16 +59,16 @@ require 'rails_generator' class GeneratorTestCase < Test::Unit::TestCase include FileUtils - + def setup ActiveRecord::Base.pluralize_table_names = true - + mkdir_p "#{RAILS_ROOT}/app/views/layouts" mkdir_p "#{RAILS_ROOT}/config" mkdir_p "#{RAILS_ROOT}/db" mkdir_p "#{RAILS_ROOT}/test/fixtures" mkdir_p "#{RAILS_ROOT}/public/stylesheets" - + File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f| f << "ActionController::Routing::Routes.draw do |map|\n\nend" end @@ -85,7 +85,7 @@ class GeneratorTestCase < Test::Unit::TestCase def test_truth # don't complain, test/unit end - + # Instantiates the Generator def build_generator(name, params) Rails::Generator::Base.instance(name, params) @@ -171,9 +171,16 @@ class GeneratorTestCase < Test::Unit::TestCase # asserts that the given class source file was generated. # It takes a path without the <tt>.rb</tt> part and an optional super class. # the contents of the class source file is passed to a block. - def assert_generated_class(path, parent=nil) - path =~ /\/?(\d+_)?(\w+)$/ - class_name = $2.camelize + def assert_generated_class(path, parent = nil) + # FIXME: Sucky way to detect namespaced classes + if path.split('/').size > 3 + path =~ /\/?(\d+_)?(\w+)\/(\w+)$/ + class_name = "#{$2.camelize}::#{$3.camelize}" + else + path =~ /\/?(\d+_)?(\w+)$/ + class_name = $2.camelize + end + assert_generated_file("#{path}.rb") do |body| assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class" yield body if block_given? @@ -184,8 +191,15 @@ class GeneratorTestCase < Test::Unit::TestCase # It takes a path without the <tt>.rb</tt> part. # the contents of the class source file is passed to a block. def assert_generated_module(path) - path =~ /\/?(\w+)$/ - module_name = $1.camelize + # FIXME: Sucky way to detect namespaced modules + if path.split('/').size > 3 + path =~ /\/?(\w+)\/(\w+)$/ + module_name = "#{$1.camelize}::#{$2.camelize}" + else + path =~ /\/?(\w+)$/ + module_name = $1.camelize + end + assert_generated_file("#{path}.rb") do |body| assert_match /module #{module_name}/, body, "the file '#{path}.rb' should be a module" yield body if block_given? |