aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/generator_test_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-06-23 18:26:58 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-06-23 18:26:58 +0000
commitc4075292fac0032c0df73c724e13298817f77e52 (patch)
tree296494a1f11c6dca1f6db9848ce8d59d9dac8522 /railties/test/generators/generator_test_helper.rb
parent1a0cdf74be951f9e732cfb8e6e1cd8a087c8ebdf (diff)
downloadrails-c4075292fac0032c0df73c724e13298817f77e52.tar.gz
rails-c4075292fac0032c0df73c724e13298817f77e52.tar.bz2
rails-c4075292fac0032c0df73c724e13298817f77e52.zip
Added --skip-migration option to scaffold and resource generators (closes #8656) [Michael Glaesemann]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7108 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/test/generators/generator_test_helper.rb')
-rw-r--r--railties/test/generators/generator_test_helper.rb77
1 files changed, 42 insertions, 35 deletions
diff --git a/railties/test/generators/generator_test_helper.rb b/railties/test/generators/generator_test_helper.rb
index ee971d9669..be23f5c6eb 100644
--- a/railties/test/generators/generator_test_helper.rb
+++ b/railties/test/generators/generator_test_helper.rb
@@ -3,14 +3,14 @@ module GeneratorTestHelper
def build_generator(name,params)
Rails::Generator::Base.instance(name,params)
end
-
- # Runs the create command (like the command line does)
+
+ # Runs the create command (like the command line does)
def run_generator(name,params)
- silence_generator do
- build_generator(name,params).command(:create).invoke!
- end
+ silence_generator do
+ build_generator(name,params).command(:create).invoke!
+ end
end
-
+
# Silences the logger temporarily and returns the output as a String
def silence_generator
logger_original=Rails::Generator::Base.logger
@@ -20,7 +20,7 @@ module GeneratorTestHelper
Rails::Generator::Base.logger=logger_original
myout.string
end
-
+
# asserts that the given controller was generated.
# It takes a name or symbol without the <tt>_controller</tt> part and an optional super class.
# The contents of the class source file is passed to a block.
@@ -29,7 +29,7 @@ module GeneratorTestHelper
yield body if block_given?
end
end
-
+
# asserts that the given model was generated.
# It takes a name or symbol and an optional super class.
# the contents of the class source file is passed to a block.
@@ -47,7 +47,7 @@ module GeneratorTestHelper
yield body if block_given?
end
end
-
+
# asserts that the given functional test was generated.
# It takes a name or symbol without the <tt>_controller_test</tt> part and an optional super class.
# the contents of the class source file is passed to a block.
@@ -74,45 +74,45 @@ module GeneratorTestHelper
yield f.read if block_given?
end
end
-
+
# asserts that the given file exists
def assert_file_exists(path)
assert File.exists?("#{RAILS_ROOT}/#{path}"),"The file '#{path}' should exist"
end
-
+
# 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
- assert_generated_file("#{path}.rb") do |body|
+ assert_generated_file("#{path}.rb") do |body|
assert body=~/class #{class_name}#{parent.nil? ? '':" < #{parent}"}/,"the file '#{path}.rb' should be a class"
yield body if block_given?
end
end
-
+
# asserts that the given module source file was generated.
# 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)
+ def assert_generated_module(path)
path=~/\/?(\w+)$/
module_name=$1.camelize
- assert_generated_file("#{path}.rb") do |body|
+ assert_generated_file("#{path}.rb") do |body|
assert body=~/module #{module_name}/,"the file '#{path}.rb' should be a module"
yield body if block_given?
end
end
-
+
# asserts that the given css stylesheet file was generated.
# It takes a path without the <tt>.css</tt> part.
# the contents of the stylesheet source file is passed to a block.
def assert_generated_stylesheet(path)
- assert_generated_file("public/stylesheets/#{path}.css") do |body|
+ assert_generated_file("public/stylesheets/#{path}.css") do |body|
yield body if block_given?
- end
+ end
end
-
+
# asserts that the given yaml file was generated.
# It takes a path without the <tt>.yml</tt> part.
# the parsed yaml tree is passed to a block.
@@ -120,9 +120,9 @@ module GeneratorTestHelper
assert_generated_file("#{path}.yml") do |body|
assert yaml=YAML.load(body)
yield yaml if block_given?
- end
+ end
end
-
+
# asserts that the given fixtures yaml file was generated.
# It takes a fixture name without the <tt>.yml</tt> part.
# the parsed yaml tree is passed to a block.
@@ -132,36 +132,43 @@ module GeneratorTestHelper
yield yaml if block_given?
end
end
-
+
# asserts that the given views were generated.
# It takes a controller name and a list of views (including extensions).
# The body of each view is passed to a block
def assert_generated_views_for(name,*actions)
actions.each do |action|
- assert_generated_file("app/views/#{name.to_s.underscore}/#{action.to_s}") do |body|
+ assert_generated_file("app/views/#{name.to_s.underscore}/#{action.to_s}") do |body|
yield body if block_given?
- end
+ end
end
end
-
+
# asserts that the given migration file was generated.
# It takes the name of the migration as a parameter.
- # the migration body is passed to a block.
+ # The migration body is passed to a block.
def assert_generated_migration(name,parent="ActiveRecord::Migration")
- assert_generated_class "db/migrate/001_#{name.to_s.underscore}",parent do |body|
- assert body=~/timestamps/, "should have timestamps defined"
+ assert_generated_class "db/migrate/001_#{name.to_s.underscore}",parent do |body|
+ assert body=~/timestamps/, "should have timestamps defined"
yield body if block_given?
end
end
-
+
+ # Asserts that the given migration file was not generated.
+ # It takes the name of the migration as a parameter.
+ def assert_skipped_migration(name)
+ migration_file = "#{RAILS_ROOT}/db/migrate/001_#{name.to_s.underscore}.rb"
+ assert !File.exists?(migration_file), "should not create migration #{migration_file}"
+ end
+
# asserts that the given resource was added to the routes.
def assert_added_route_for(name)
assert_generated_file("config/routes.rb") do |body|
assert body=~/map.resources :#{name.to_s.underscore}/,"should add route for :#{name.to_s.underscore}"
end
end
-
- # asserts that the given methods are defined in the body.
+
+ # asserts that the given methods are defined in the body.
# This does assume standard rails code conventions with regards to the source code.
# The body of each individual method is passed to a block.
def assert_has_method(body,*methods)
@@ -170,12 +177,12 @@ module GeneratorTestHelper
yield( name, $1 ) if block_given?
end
end
-
+
# asserts that the given column is defined in the migration
def assert_generated_column(body,name,type)
assert body=~/t\.#{type.to_s} :#{name.to_s}/, "should have column #{name.to_s} defined"
end
-
+
private
# asserts that the default timestamps are created in the fixture
def assert_generated_timestamps(yaml)
@@ -183,6 +190,6 @@ module GeneratorTestHelper
["created_at", "updated_at"].each do |field|
assert v.keys.include?(field), "should have #{field} field by default"
end
- end
+ end
end
-end \ No newline at end of file
+end