aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-05-13 15:49:41 -0500
committerJoshua Peek <josh@joshpeek.com>2008-05-13 15:50:06 -0500
commit4562a5b57f5999fadc8b0957ed5777f35be8dea5 (patch)
tree567a134ec0c6862ced46132525a44ae5a2dfb39b /railties
parent3a0d8adcf25e27f7976a1d0996be05f21ffc3805 (diff)
downloadrails-4562a5b57f5999fadc8b0957ed5777f35be8dea5.tar.gz
rails-4562a5b57f5999fadc8b0957ed5777f35be8dea5.tar.bz2
rails-4562a5b57f5999fadc8b0957ed5777f35be8dea5.zip
Add some test coverage for RailsControllerGenerator.
Diffstat (limited to 'railties')
-rw-r--r--railties/test/generators/generator_test_helper.rb34
-rw-r--r--railties/test/generators/rails_controller_generator_test.rb20
2 files changed, 44 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?
diff --git a/railties/test/generators/rails_controller_generator_test.rb b/railties/test/generators/rails_controller_generator_test.rb
new file mode 100644
index 0000000000..0090d21b85
--- /dev/null
+++ b/railties/test/generators/rails_controller_generator_test.rb
@@ -0,0 +1,20 @@
+require 'generators/generator_test_helper'
+
+class RailsControllerGeneratorTest < GeneratorTestCase
+
+ def test_controller_generates_controller
+ run_generator('controller', %w(products))
+
+ assert_generated_controller_for :products
+ assert_generated_functional_test_for :products
+ assert_generated_helper_for :products
+ end
+
+ def test_controller_generates_namespaced_controller
+ run_generator('controller', %w(admin::products))
+
+ assert_generated_controller_for "admin::products"
+ assert_generated_functional_test_for "admin::products"
+ assert_generated_helper_for "admin::products"
+ end
+end