mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Attributes on scaffold and model generators default to string.
This allows the following: "rails g scaffold Post title body:text author"
This commit is contained in:
parent
9a64c8ec66
commit
08983fefd5
5 changed files with 24 additions and 17 deletions
|
@ -1,5 +1,7 @@
|
|||
*Rails 3.2.0 (unreleased)*
|
||||
|
||||
* Attributes on scaffold and model generators default to string. This allows the following: "rails g scaffold Post title body:text author" [José Valim]
|
||||
|
||||
* Removed old plugin generator (`rails generate plugin`) in favor of `rails plugin new` command. [Guillermo Iguaran]
|
||||
|
||||
* Removed old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API. [Guillermo Iguaran]
|
||||
|
|
|
@ -7,7 +7,7 @@ module Rails
|
|||
attr_accessor :name, :type
|
||||
|
||||
def initialize(name, type)
|
||||
raise Thor::Error, "Missing type for attribute '#{name}'.\nExample: '#{name}:string' where string is the type." if type.blank?
|
||||
type = :string if type.blank?
|
||||
@name, @type = name, type.to_sym
|
||||
end
|
||||
|
||||
|
|
|
@ -113,15 +113,8 @@ class GeneratedAttributeTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_nil_type_raises_exception
|
||||
assert_raise Thor::Error do
|
||||
create_generated_attribute(nil, 'title')
|
||||
end
|
||||
end
|
||||
|
||||
def test_missing_type_raises_exception
|
||||
assert_raise Thor::Error do
|
||||
create_generated_attribute('', 'title')
|
||||
end
|
||||
def test_blank_type_defaults_to_string_raises_exception
|
||||
assert_equal :string, create_generated_attribute(nil, 'title').type
|
||||
assert_equal :string, create_generated_attribute("", 'title').type
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,9 +12,15 @@ class ModelGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_model_with_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)
|
||||
run_generator ["post", "title", "body:text", "author"]
|
||||
|
||||
assert_migration "db/migrate/create_posts.rb" do |m|
|
||||
assert_method :change, m do |up|
|
||||
assert_match(/t\.string :title/, up)
|
||||
assert_match(/t\.text :body/, up)
|
||||
assert_match(/t\.string :author/, up)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_invokes_default_orm
|
||||
|
|
|
@ -272,8 +272,14 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|||
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)
|
||||
run_generator ["post", "title", "body:text", "author"]
|
||||
|
||||
assert_migration "db/migrate/create_posts.rb" do |m|
|
||||
assert_method :change, m do |up|
|
||||
assert_match(/t\.string :title/, up)
|
||||
assert_match(/t\.text :body/, up)
|
||||
assert_match(/t\.string :author/, up)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue