diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-06-23 19:54:37 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-06-23 19:54:37 +0000 |
commit | 91384dd691bebfaafcd06a097ea3497512227f47 (patch) | |
tree | 931907be89d3fc846236db7fc9bfe7c9c6f730fd | |
parent | c4075292fac0032c0df73c724e13298817f77e52 (diff) | |
download | rails-91384dd691bebfaafcd06a097ea3497512227f47.tar.gz rails-91384dd691bebfaafcd06a097ea3497512227f47.tar.bz2 rails-91384dd691bebfaafcd06a097ea3497512227f47.zip |
Missing test
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7109 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | railties/test/generators/rails_resource_generator_test.rb | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/railties/test/generators/rails_resource_generator_test.rb b/railties/test/generators/rails_resource_generator_test.rb new file mode 100644 index 0000000000..23ce191852 --- /dev/null +++ b/railties/test/generators/rails_resource_generator_test.rb @@ -0,0 +1,106 @@ +require 'test/unit' + +# Optionally load RubyGems +begin + require 'rubygems' +rescue LoadError +end + +# Mock out what we need from AR::Base +module ActiveRecord + class Base + class << self + attr_accessor :pluralize_table_names + end + self.pluralize_table_names = true + end + + module ConnectionAdapters + class Column + attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale + def initialize(name, default, sql_type=nil) + @namename + @default=default + @type=@sql_type=sql_type + end + + def human_name + @name.humanize + end + end + end +end + +# Mock up necessities from ActionView +module ActionView + module Helpers + module ActionRecordHelper; end + class InstanceTag; end + end +end + +# Set RAILS_ROOT appropriately fixture generation +tmp_dir="#{File.dirname(__FILE__)}/../fixtures/tmp" +if defined?(RAILS_ROOT) + RAILS_ROOT.replace(tmp_dir) +else + RAILS_ROOT=tmp_dir +end +Dir.mkdir(RAILS_ROOT) unless File.exists?(RAILS_ROOT) + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" +require 'rails_generator' +require "#{File.dirname(__FILE__)}/generator_test_helper" + +class RailsResourceGeneratorTest < Test::Unit::TestCase + include GeneratorTestHelper + + def setup + ActiveRecord::Base.pluralize_table_names = true + Dir.mkdir("#{RAILS_ROOT}/app") unless File.exists?("#{RAILS_ROOT}/app") + Dir.mkdir("#{RAILS_ROOT}/app/views") unless File.exists?("#{RAILS_ROOT}/app/views") + Dir.mkdir("#{RAILS_ROOT}/app/views/layouts") unless File.exists?("#{RAILS_ROOT}/app/views/layouts") + Dir.mkdir("#{RAILS_ROOT}/config") unless File.exists?("#{RAILS_ROOT}/config") + Dir.mkdir("#{RAILS_ROOT}/db") unless File.exists?("#{RAILS_ROOT}/db") + Dir.mkdir("#{RAILS_ROOT}/test") unless File.exists?("#{RAILS_ROOT}/test") + Dir.mkdir("#{RAILS_ROOT}/test/fixtures") unless File.exists?("#{RAILS_ROOT}/test/fixtures") + Dir.mkdir("#{RAILS_ROOT}/public") unless File.exists?("#{RAILS_ROOT}/public") + Dir.mkdir("#{RAILS_ROOT}/public/stylesheets") unless File.exists?("#{RAILS_ROOT}/public/stylesheets") + File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f| + f<<"ActionController::Routing::Routes.draw do |map|\n\nend\n" + end + end + + def teardown + FileUtils.rm_rf "#{RAILS_ROOT}/app" + FileUtils.rm_rf "#{RAILS_ROOT}/test" + FileUtils.rm_rf "#{RAILS_ROOT}/config" + FileUtils.rm_rf "#{RAILS_ROOT}/db" + FileUtils.rm_rf "#{RAILS_ROOT}/public" + end + + def test_resource_generates_resources + run_generator('scaffold', %w(Product)) + + assert_generated_controller_for :products + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_generated_functional_test_for :products + assert_generated_helper_for :products + assert_generated_migration :create_products + assert_added_route_for :products + end + + def test_resource_skip_migration_skips_migration + run_generator('resource', %w(Product --skip-migration)) + + assert_generated_controller_for :products + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_generated_functional_test_for :products + assert_generated_helper_for :products + assert_skipped_migration :create_products + assert_added_route_for :products + end + +end |