diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
commit | 9887f238871bb2dd73de6ce8855615bcc5d8d079 (patch) | |
tree | 74fa9ff9524a51701cfa23f708b3f777c65b7fe5 /railties/test/generators/scaffold_generator_test.rb | |
parent | aff821508a16245ebc03510ba29c70379718dfb7 (diff) | |
parent | 5214e73850916de3c9127d35a4ecee0424d364a3 (diff) | |
download | rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.gz rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.bz2 rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.zip |
Merge branch 'master' of https://github.com/rails/rails
Diffstat (limited to 'railties/test/generators/scaffold_generator_test.rb')
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index f12445ae35..df787f61ba 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -3,7 +3,7 @@ require 'rails/generators/rails/scaffold/scaffold_generator' class ScaffoldGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper - arguments %w(product_line title:string price:integer) + arguments %w(product_line title:string product:belongs_to user:references) setup :copy_routes @@ -14,48 +14,51 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/models/product_line.rb", /class ProductLine < ActiveRecord::Base/ assert_file "test/unit/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/ assert_file "test/fixtures/product_lines.yml" - assert_migration "db/migrate/create_product_lines.rb" + assert_migration "db/migrate/create_product_lines.rb", /belongs_to :product/ + assert_migration "db/migrate/create_product_lines.rb", /add_index :product_lines, :product_id/ + assert_migration "db/migrate/create_product_lines.rb", /references :user/ + assert_migration "db/migrate/create_product_lines.rb", /add_index :product_lines, :user_id/ # Route assert_file "config/routes.rb" do |route| - assert_match /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_match(/class ProductLinesController < ApplicationController/, content) assert_instance_method :index, content do |m| - assert_match /@product_lines = ProductLine\.all/, m + assert_match(/@product_lines = ProductLine\.all/, m) end assert_instance_method :show, content do |m| - assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m + assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m) end assert_instance_method :new, content do |m| - assert_match /@product_line = ProductLine\.new/, m + assert_match(/@product_line = ProductLine\.new/, m) end assert_instance_method :edit, content do |m| - assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m + assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m) end 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 + 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 :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 + 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 :destroy, content do |m| - assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m - assert_match /@product_line\.destroy/, m + assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m) + assert_match(/@product_line\.destroy/, m) end end @@ -92,7 +95,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Route assert_file "config/routes.rb" do |route| - assert_no_match /resources :product_lines$/, route + assert_no_match(/resources :product_lines$/, route) end # Controller @@ -123,44 +126,44 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Route assert_file "config/routes.rb" do |route| - assert_match /namespace :admin do resources :roles end$/, route + assert_match(/namespace :admin do resources :roles end$/, route) end # Controller assert_file "app/controllers/admin/roles_controller.rb" do |content| - assert_match /class Admin::RolesController < ApplicationController/, content + assert_match(/class Admin::RolesController < ApplicationController/, content) assert_instance_method :index, content do |m| - assert_match /@admin_roles = Admin::Role\.all/, m + assert_match(/@admin_roles = Admin::Role\.all/, m) end assert_instance_method :show, content do |m| - assert_match /@admin_role = Admin::Role\.find\(params\[:id\]\)/, m + assert_match(/@admin_role = Admin::Role\.find\(params\[:id\]\)/, m) end assert_instance_method :new, content do |m| - assert_match /@admin_role = Admin::Role\.new/, m + assert_match(/@admin_role = Admin::Role\.new/, m) end assert_instance_method :edit, content do |m| - assert_match /@admin_role = Admin::Role\.find\(params\[:id\]\)/, m + assert_match(/@admin_role = Admin::Role\.find\(params\[:id\]\)/, m) end assert_instance_method :create, content do |m| - assert_match /@admin_role = Admin::Role\.new\(params\[:admin_role\]\)/, m - assert_match /@admin_role\.save/, m - assert_match /@admin_role\.errors/, m + assert_match(/@admin_role = Admin::Role\.new\(params\[:admin_role\]\)/, m) + assert_match(/@admin_role\.save/, m) + assert_match(/@admin_role\.errors/, m) end assert_instance_method :update, content do |m| - assert_match /@admin_role = Admin::Role\.find\(params\[:id\]\)/, m - assert_match /@admin_role\.update_attributes\(params\[:admin_role\]\)/, m - assert_match /@admin_role\.errors/, m + assert_match(/@admin_role = Admin::Role\.find\(params\[:id\]\)/, m) + assert_match(/@admin_role\.update_attributes\(params\[:admin_role\]\)/, m) + assert_match(/@admin_role\.errors/, m) end assert_instance_method :destroy, content do |m| - assert_match /@admin_role = Admin::Role\.find\(params\[:id\]\)/, m - assert_match /@admin_role\.destroy/, m + assert_match(/@admin_role = Admin::Role\.find\(params\[:id\]\)/, m) + assert_match(/@admin_role\.destroy/, m) end end @@ -198,7 +201,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Route assert_file "config/routes.rb" do |route| - assert_no_match /namespace :admin do resources :roles end$/, route + assert_no_match(/namespace :admin do resources :roles end$/, route) end # Controller @@ -231,4 +234,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/ end + + def test_scaffold_generator_outputs_error_message_on_missing_attribute_type + content = capture(:stderr) { run_generator ["post", "title:string", "body"]} + assert_match(/Missing type for attribute 'body'/, content) + assert_match(/Example: 'body:string' where string is the type/, content) + end end |