diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-04 03:24:39 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-04 03:24:39 +0530 |
commit | cda36a0731f14b33a920bf7e32255661e06f890a (patch) | |
tree | 79ccba37953f9fe3055503be42b1610faa6d64ad /railties/test/generators | |
parent | bd4a3cce4ecd8e648179a91e26506e3622ac2162 (diff) | |
parent | a115b5d79a850bb56cd3c9db9a05d6da35e3d7be (diff) | |
download | rails-cda36a0731f14b33a920bf7e32255661e06f890a.tar.gz rails-cda36a0731f14b33a920bf7e32255661e06f890a.tar.bz2 rails-cda36a0731f14b33a920bf7e32255661e06f890a.zip |
Merge remote branch 'mainstream/master'
Diffstat (limited to 'railties/test/generators')
20 files changed, 114 insertions, 298 deletions
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 7d03a37f2a..27b6a49566 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -1,8 +1,10 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' class ActionsTest < GeneratorsTestCase + tests Rails::Generators::AppGenerator + arguments [destination_root] + def setup super @git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git' @@ -171,21 +173,13 @@ class ActionsTest < GeneratorsTestCase def test_route_should_add_data_to_the_routes_block_in_config_routes run_generator - route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" + route_command = "route '/login', :controller => 'sessions', :action => 'new'" action :route, route_command assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ end protected - def run_generator - silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root] } - end - - def generator(config={}) - @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config)) - end - def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 10d0bc6bc2..7dd798db75 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -3,6 +3,7 @@ require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' class AppGeneratorTest < GeneratorsTestCase + arguments [destination_root] def setup super @@ -49,24 +50,35 @@ class AppGeneratorTest < GeneratorsTestCase end def test_invalid_database_option_raises_an_error - content = capture(:stderr){ run_generator(["-d", "unknown"]) } + content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } assert_match /Invalid value for \-\-database option/, content end + def test_invalid_application_name_raises_an_error + content = capture(:stderr){ Rails::Generators::AppGenerator.start [File.join(destination_root, "43-things")] } + assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content + end + + def test_invalid_application_name_is_fixed + silence(:stdout){ Rails::Generators::AppGenerator.start [File.join(destination_root, "things-43")] } + assert_file "things-43/config/environment.rb", /Things43::Application/ + end + def test_config_database_is_added_by_default run_generator assert_file "config/database.yml", /sqlite3/ end def test_config_database_is_not_added_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] + run_generator [destination_root, "--skip-activerecord"] assert_no_file "config/database.yml" end - def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] - assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ - end + # TODO: Bring this back using requires + # def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given + # run_generator ["--skip-activerecord"] + # assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ + # end def test_prototype_and_test_unit_are_added_by_default run_generator @@ -75,13 +87,13 @@ class AppGeneratorTest < GeneratorsTestCase end def test_prototype_and_test_unit_are_skipped_if_required - run_generator ["--skip-prototype", "--skip-testunit"] + run_generator [destination_root, "--skip-prototype", "--skip-testunit"] assert_no_file "public/javascripts/prototype.js" assert_no_file "test" end def test_shebang_is_added_to_files - run_generator ["--ruby", "foo/bar/baz"] + run_generator [destination_root, "--ruby", "foo/bar/baz"] %w( about @@ -96,7 +108,7 @@ class AppGeneratorTest < GeneratorsTestCase end def test_shebang_when_is_the_same_as_default_use_env - run_generator ["--ruby", Thor::Util.ruby_command] + run_generator [destination_root, "--ruby", Thor::Util.ruby_command] %w( about @@ -112,11 +124,11 @@ class AppGeneratorTest < GeneratorsTestCase def test_template_from_dir_pwd FileUtils.cd(Rails.root) - assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"]) + assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) end def test_template_raises_an_error_with_invalid_path - content = capture(:stderr){ run_generator(["-m", "non/existant/path"]) } + content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) } assert_match /The template \[.*\] could not be loaded/, content assert_match /non\/existant\/path/, content end @@ -126,7 +138,7 @@ class AppGeneratorTest < GeneratorsTestCase template = %{ say "It works!" } template.instance_eval "def read; self; end" # Make the string respond to read - generator(:template => path, :database => "sqlite3").expects(:open).with(path).returns(template) + generator([destination_root], :template => path, :database => "sqlite3").expects(:open).with(path).returns(template) assert_match /It works!/, silence(:stdout){ generator.invoke } end @@ -149,15 +161,20 @@ class AppGeneratorTest < GeneratorsTestCase assert_file 'lib/test_file.rb', 'heres test data' end - protected + def test_dev_option + run_generator [destination_root, "--dev"] + rails_path = File.expand_path('../../..', Rails.root) + dev_gem = %(gem "rails", :path => #{rails_path.inspect}) + assert_file 'Gemfile', /^#{Regexp.escape(dev_gem)}$/ + end - def run_generator(args=[]) - silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root].concat(args) } - end + def test_edge_option + run_generator [destination_root, "--edge"] + edge_gem = %(gem "rails", :git => "git://github.com/rails/rails.git") + assert_file 'Gemfile', /^#{Regexp.escape(edge_gem)}$/ + end - def generator(options={}) - @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :destination_root => destination_root) - end + protected def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 56bc688ad0..8e2fd3b9ed 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -1,12 +1,12 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/controller/controller_generator' class ControllerGeneratorTest < GeneratorsTestCase + arguments %w(Account foo bar) def test_help_does_not_show_invoked_generators_options_if_they_already_exist content = run_generator ["--help"] - assert_no_match /Helper options:/, content + assert_no_match /Helper options\:/, content end def test_controller_skeleton_is_created @@ -66,15 +66,8 @@ class ControllerGeneratorTest < GeneratorsTestCase run_generator assert_file "app/controllers/account_controller.rb" do |controller| - assert_instance_method controller, :foo - assert_instance_method controller, :bar + assert_instance_method :foo, controller + assert_instance_method :bar, controller end end - - protected - - def run_generator(args=["Account", "foo", "bar"]) - silence(:stdout) { Rails::Generators::ControllerGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb index aea3f4da51..28377f23b0 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/generator/generator_generator' class GeneratorGeneratorTest < GeneratorsTestCase + arguments %w(awesome) def test_generator_skeleton_is_created run_generator @@ -16,11 +16,4 @@ class GeneratorGeneratorTest < GeneratorsTestCase assert_file "lib/generators/awesome/awesome_generator.rb", /class AwesomeGenerator < Rails::Generators::NamedBase/ end - - protected - - def run_generator(args=["awesome"], config={}) - silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 4ce48a453b..fcd0989fd7 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -10,93 +10,19 @@ end Rails.application.config.root = Rails.root require 'rails/generators' +require 'rails/generators/test_case' + require 'rubygems' require 'active_record' require 'action_dispatch' -CURRENT_PATH = File.expand_path(Dir.pwd) -Rails::Generators.no_color! - -class GeneratorsTestCase < ActiveSupport::TestCase - include FileUtils - - def destination_root - File.join(Rails.root, "tmp") - end - - def setup - cd CURRENT_PATH - rm_rf(destination_root) - mkdir_p(destination_root) - end - - def test_truth - # don't complain, test/unit - end - - def capture(stream) - begin - stream = stream.to_s - eval "$#{stream} = StringIO.new" - yield - result = eval("$#{stream}").string - ensure - eval("$#{stream} = #{stream.upcase}") - end +class GeneratorsTestCase < Rails::Generators::TestCase + destination File.join(Rails.root, "tmp") + setup :prepare_destination - result + def self.inherited(base) + base.tests Rails::Generators.const_get(base.name.sub(/Test$/, '')) + rescue + # Do nothing. end - alias :silence :capture - - def assert_file(relative, *contents) - absolute = File.join(destination_root, relative) - assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not" - - read = File.read(absolute) if block_given? || !contents.empty? - yield read if block_given? - - contents.each do |content| - case content - when String - assert_equal content, read - when Regexp - assert_match content, read - end - end - end - - def assert_no_file(relative) - absolute = File.join(destination_root, relative) - assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does" - end - - def assert_migration(relative, *contents, &block) - file_name = migration_file_name(relative) - assert file_name, "Expected migration #{relative} to exist, but was not found" - assert_file File.join(File.dirname(relative), file_name), *contents, &block - end - - def assert_no_migration(relative) - file_name = migration_file_name(relative) - assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}" - end - - def assert_class_method(content, method, &block) - assert_instance_method content, "self.#{method}", &block - end - - def assert_instance_method(content, method) - assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}" - yield $2.strip if block_given? - end - - protected - - def migration_file_name(relative) - absolute = File.join(destination_root, relative) - dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '') - - migration = Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first - File.basename(migration) if migration - end -end +end
\ No newline at end of file diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index f8bfc517a2..cf18782986 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/helper/helper_generator' @@ -6,6 +5,7 @@ ObjectHelper = Class.new AnotherObjectHelperTest = Class.new class HelperGeneratorTest < GeneratorsTestCase + arguments %w(admin) def test_helper_skeleton_is_created run_generator @@ -50,11 +50,4 @@ class HelperGeneratorTest < GeneratorsTestCase end end end - - protected - - def run_generator(args=["admin"]) - silence(:stdout) { Rails::Generators::HelperGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/integration_test_generator_test.rb b/railties/test/generators/integration_test_generator_test.rb index 6a504ceea2..88e18be5b2 100644 --- a/railties/test/generators/integration_test_generator_test.rb +++ b/railties/test/generators/integration_test_generator_test.rb @@ -1,18 +1,11 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/integration_test/integration_test_generator' class IntegrationTestGeneratorTest < GeneratorsTestCase + arguments %w(integration) def test_integration_test_skeleton_is_created run_generator assert_file "test/integration/integration_test.rb", /class IntegrationTest < ActionController::IntegrationTest/ end - - protected - - def run_generator(args=["integration"]) - silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 251474ad16..ee4346eb71 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/mailer/mailer_generator' class MailerGeneratorTest < GeneratorsTestCase + arguments %w(notifier foo bar) def test_mailer_skeleton_is_created run_generator @@ -42,11 +42,4 @@ class MailerGeneratorTest < GeneratorsTestCase assert_file "app/models/notifier.rb", /def foo/ assert_file "app/models/notifier.rb", /def bar/ end - - protected - - def run_generator(args=["notifier", "foo", "bar"]) - silence(:stdout) { Rails::Generators::MailerGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/metal_generator_test.rb b/railties/test/generators/metal_generator_test.rb index 80bf342892..5d6a277561 100644 --- a/railties/test/generators/metal_generator_test.rb +++ b/railties/test/generators/metal_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/metal/metal_generator' class MetalGeneratorTest < GeneratorsTestCase + arguments %w(foo) def test_metal_skeleton_is_created run_generator @@ -13,11 +13,4 @@ class MetalGeneratorTest < GeneratorsTestCase content = capture(:stderr){ run_generator ["object"] } assert_match /The name 'Object' is either already used in your application or reserved/, content end - - protected - - def run_generator(args=["foo"]) - silence(:stdout) { Rails::Generators::MetalGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 35172a8be4..2fd3e5c056 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -1,32 +1,30 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/migration/migration_generator' class MigrationGeneratorTest < GeneratorsTestCase - def test_migration - @migration = "change_title_body_from_posts" - run_generator - assert_migration "db/migrate/#{@migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/ + migration = "change_title_body_from_posts" + run_generator [migration] + assert_migration "db/migrate/#{migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/ end def test_migration_with_class_name - @migration = "ChangeTitleBodyFromPosts" - run_generator - assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{@migration} < ActiveRecord::Migration/ + migration = "ChangeTitleBodyFromPosts" + run_generator [migration] + assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{migration} < ActiveRecord::Migration/ end def test_add_migration_with_attributes - @migration = "add_title_body_to_posts" - run_generator [@migration, "title:string", "body:text"] + migration = "add_title_body_to_posts" + run_generator [migration, "title:string", "body:text"] - assert_migration "db/migrate/#{@migration}.rb" do |content| - assert_class_method content, :up do |up| + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_class_method :up, content do |up| assert_match /add_column :posts, :title, :string/, up assert_match /add_column :posts, :body, :text/, up end - assert_class_method content, :down do |down| + assert_class_method :down, content do |down| assert_match /remove_column :posts, :title/, down assert_match /remove_column :posts, :body/, down end @@ -34,26 +32,19 @@ class MigrationGeneratorTest < GeneratorsTestCase end def test_remove_migration_with_attributes - @migration = "remove_title_body_from_posts" - run_generator [@migration, "title:string", "body:text"] + migration = "remove_title_body_from_posts" + run_generator [migration, "title:string", "body:text"] - assert_migration "db/migrate/#{@migration}.rb" do |content| - assert_class_method content, :up do |up| + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_class_method :up, content do |up| assert_match /remove_column :posts, :title/, up assert_match /remove_column :posts, :body/, up end - assert_class_method content, :down do |down| + assert_class_method :down, content do |down| assert_match /add_column :posts, :title, :string/, down assert_match /add_column :posts, :body, :text/, down end end end - - protected - - def run_generator(args=[@migration]) - silence(:stdout) { Rails::Generators::MigrationGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index e073b11e1e..051a43706b 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/model/model_generator' class ModelGeneratorTest < GeneratorsTestCase + arguments %w(Account name:string age:integer) def test_help_shows_invoked_generators_options content = run_generator ["--help"] @@ -84,13 +84,13 @@ class ModelGeneratorTest < GeneratorsTestCase run_generator ["product", "name:string", "supplier_id:integer"] assert_migration "db/migrate/create_products.rb" do |m| - assert_class_method m, :up do |up| + assert_class_method :up, m do |up| assert_match /create_table :products/, up assert_match /t\.string :name/, up assert_match /t\.integer :supplier_id/, up end - assert_class_method m, :down do |down| + assert_class_method :down, m do |down| assert_match /drop_table :products/, down end end @@ -126,7 +126,7 @@ class ModelGeneratorTest < GeneratorsTestCase run_generator ["account", "--no-timestamps"] assert_migration "db/migrate/create_accounts.rb" do |m| - assert_class_method m, :up do |up| + assert_class_method :up, m do |up| assert_no_match /t.timestamps/, up end end @@ -171,11 +171,4 @@ class ModelGeneratorTest < GeneratorsTestCase content = capture(:stderr){ run_generator ["object"] } assert_match /The name 'Object' is either already used in your application or reserved/, content end - - protected - - def run_generator(args=["Account", "name:string", "age:integer"], config={}) - silence(:stdout) { Rails::Generators::ModelGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 98cbf9b8f6..8c1df3b992 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' @@ -13,9 +12,10 @@ module ActiveRecord end class NamedBaseTest < GeneratorsTestCase + tests Rails::Generators::ScaffoldControllerGenerator def test_named_generator_attributes - g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"] + g = generator ["admin/foo"] assert_equal 'admin/foo', g.name assert_equal %w(admin), g.class_path assert_equal 1, g.class_nesting_depth @@ -28,12 +28,12 @@ class NamedBaseTest < GeneratorsTestCase def test_named_generator_attributes_without_pluralized ActiveRecord::Base.pluralize_table_names = false - g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"] + g = generator ["admin/foo"] assert_equal "admin_#{g.singular_name}", g.table_name end def test_scaffold_plural_names - g = Rails::Generators::ScaffoldControllerGenerator.new ["ProductLine"] + g = generator ["ProductLine"] assert_equal "ProductLines", g.controller_name assert_equal "ProductLines", g.controller_class_name assert_equal "product_lines", g.controller_file_name diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb index 6fed2998dd..44d9e4a9f3 100644 --- a/railties/test/generators/observer_generator_test.rb +++ b/railties/test/generators/observer_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/observer/observer_generator' class ObserverGeneratorTest < GeneratorsTestCase + arguments %w(account) def test_invokes_default_orm run_generator @@ -23,11 +23,4 @@ class ObserverGeneratorTest < GeneratorsTestCase content = run_generator ["account", "--test-framework=rspec"] assert_match /rspec \[not found\]/, content end - - protected - - def run_generator(args=["account"]) - silence(:stdout) { Rails::Generators::ObserverGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/performance_test_generator_test.rb b/railties/test/generators/performance_test_generator_test.rb index d19128f79a..099575ea1d 100644 --- a/railties/test/generators/performance_test_generator_test.rb +++ b/railties/test/generators/performance_test_generator_test.rb @@ -1,18 +1,11 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/performance_test/performance_test_generator' class PerformanceTestGeneratorTest < GeneratorsTestCase + arguments %w(performance) def test_performance_test_skeleton_is_created run_generator assert_file "test/performance/performance_test.rb", /class PerformanceTest < ActionController::PerformanceTest/ end - - protected - - def run_generator(args=["performance"]) - silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index f5b8b6ffb6..f84b8b6d50 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/plugin/plugin_generator' class PluginGeneratorTest < GeneratorsTestCase + arguments %w(plugin_fu) def test_plugin_skeleton_is_created run_generator @@ -46,11 +46,4 @@ class PluginGeneratorTest < GeneratorsTestCase run_generator run_generator ["plugin_fu"], :behavior => :revoke end - - protected - - def run_generator(args=["plugin_fu"], config={}) - silence(:stdout) { Rails::Generators::PluginGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 886af01b22..15c0ca0f01 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/resource/resource_generator' class ResourceGeneratorTest < GeneratorsTestCase + arguments %w(account) def setup super @@ -50,8 +50,8 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator ["account", "--actions", "index", "new"] assert_file "app/controllers/accounts_controller.rb" do |controller| - assert_instance_method controller, :index - assert_instance_method controller, :new + assert_instance_method :index, controller + assert_instance_method :new, controller end assert_file "app/views/accounts/index.html.erb" @@ -62,7 +62,7 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator assert_file "config/routes.rb" do |route| - assert_match /map\.resources :accounts$/, route + assert_match /resources :accounts$/, route end end @@ -70,7 +70,7 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator ["account", "--singleton"] assert_file "config/routes.rb" do |route| - assert_match /map\.resource :account$/, route + assert_match /resource :account$/, route end end @@ -93,14 +93,7 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator ["account"], :behavior => :revoke assert_file "config/routes.rb" do |route| - assert_no_match /map\.resources :accounts$/, route + assert_no_match /resources :accounts$/, route end end - - protected - - def run_generator(args=["account"], config={}) - silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 02155c295c..7593c14dd9 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' @@ -8,6 +7,7 @@ module Unknown end class ScaffoldControllerGeneratorTest < GeneratorsTestCase + arguments %w(User name:string age:integer) def test_controller_skeleton_is_created run_generator @@ -15,35 +15,35 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_file "app/controllers/users_controller.rb" do |content| assert_match /class UsersController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@users = User\.all/, m end - assert_instance_method content, :show do |m| + assert_instance_method :show, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m end - assert_instance_method content, :new do |m| + assert_instance_method :new, content do |m| assert_match /@user = User\.new/, m end - assert_instance_method content, :edit do |m| + assert_instance_method :edit, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m end - assert_instance_method content, :create do |m| + assert_instance_method :create, content do |m| assert_match /@user = User\.new\(params\[:user\]\)/, m assert_match /@user\.save/, m assert_match /@user\.errors/, m end - assert_instance_method content, :update do |m| + assert_instance_method :update, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m assert_match /@user\.update_attributes\(params\[:user\]\)/, m assert_match /@user\.errors/, m end - assert_instance_method content, :destroy do |m| + assert_instance_method :destroy, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m assert_match /@user\.destroy/, m end @@ -108,7 +108,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_file "app/controllers/users_controller.rb" do |content| assert_match /class UsersController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@users = User\.all/, m end end @@ -127,7 +127,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_file "app/controllers/users_controller.rb" do |content| assert_match /class UsersController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@users = User\.find\(:all\)/, m assert_no_match /@users = User\.all/, m end @@ -135,11 +135,4 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase ensure Unknown::Generators.send :remove_const, :ActiveModel end - - protected - - def run_generator(args=["User", "name:string", "age:integer"]) - silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index c0652c034f..4ddc7b1c89 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold/scaffold_generator' class ScaffoldGeneratorTest < GeneratorsTestCase + arguments %w(product_line title:string price:integer) def setup super @@ -25,42 +25,42 @@ class ScaffoldGeneratorTest < GeneratorsTestCase # Route assert_file "config/routes.rb" do |route| - assert_match /map\.resources :product_lines$/, route + assert_match /resources :product_lines$/, route end # Controller assert_file "app/controllers/product_lines_controller.rb" do |content| assert_match /class ProductLinesController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@product_lines = ProductLine\.all/, m end - assert_instance_method content, :show do |m| + assert_instance_method :show, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m end - assert_instance_method content, :new do |m| + assert_instance_method :new, content do |m| assert_match /@product_line = ProductLine\.new/, m end - assert_instance_method content, :edit do |m| + assert_instance_method :edit, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m end - assert_instance_method content, :create do |m| + assert_instance_method :create, content do |m| assert_match /@product_line = ProductLine\.new\(params\[:product_line\]\)/, m assert_match /@product_line\.save/, m assert_match /@product_line\.errors/, m end - assert_instance_method content, :update do |m| + assert_instance_method :update, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m assert_match /@product_line\.update_attributes\(params\[:product_line\]\)/, m assert_match /@product_line\.errors/, m end - assert_instance_method content, :destroy do |m| + assert_instance_method :destroy, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m assert_match /@product_line\.destroy/, m end @@ -89,7 +89,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase def test_scaffold_on_revoke run_generator - run_generator :behavior => :revoke + run_generator ["product_line"], :behavior => :revoke # Model assert_no_file "app/models/product_line.rb" @@ -99,7 +99,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase # Route assert_file "config/routes.rb" do |route| - assert_no_match /map\.resources :product_lines$/, route + assert_no_match /resources :product_lines$/, route end # Controller @@ -117,14 +117,4 @@ class ScaffoldGeneratorTest < GeneratorsTestCase # Stylesheets (should not be removed) assert_file "public/stylesheets/scaffold.css" end - - protected - - def run_generator(config={}) - silence(:stdout) do - Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], - config.merge(:destination_root => destination_root) - end - end - end diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb index 34fb996b7f..251ffb19ed 100644 --- a/railties/test/generators/session_migration_generator_test.rb +++ b/railties/test/generators/session_migration_generator_test.rb @@ -1,9 +1,7 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/session_migration/session_migration_generator' class SessionMigrationGeneratorTest < GeneratorsTestCase - def test_session_migration_with_default_name run_generator assert_migration "db/migrate/add_sessions_table.rb", /class AddSessionsTable < ActiveRecord::Migration/ @@ -24,11 +22,4 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase ensure ActiveRecord::SessionStore::Session.table_name = "sessions" end - - protected - - def run_generator(args=[]) - silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb index 15263d4bb8..d9079327ba 100644 --- a/railties/test/generators/stylesheets_generator_test.rb +++ b/railties/test/generators/stylesheets_generator_test.rb @@ -1,9 +1,7 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/stylesheets/stylesheets_generator' class StylesheetsGeneratorTest < GeneratorsTestCase - def test_copy_stylesheets run_generator assert_file "public/stylesheets/scaffold.css" @@ -11,14 +9,7 @@ class StylesheetsGeneratorTest < GeneratorsTestCase def test_stylesheets_are_not_deleted_on_revoke run_generator - run_generator :behavior => :revoke + run_generator [], :behavior => :revoke assert_file "public/stylesheets/scaffold.css" end - - protected - - def run_generator(config={}) - silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config.merge(:destination_root => destination_root) } - end - end |