aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-06-17 15:10:53 -0300
committerJosé Valim <jose.valim@gmail.com>2011-06-17 15:10:53 -0300
commit08983fefd547142ef8b913af1859b96597753d9f (patch)
tree0b3d648ba38db34d114cbd8488692d85cf1f1d71 /railties/test/generators
parent9a64c8ec660a6dc20e8df26b0936502bd4c1ffb8 (diff)
downloadrails-08983fefd547142ef8b913af1859b96597753d9f.tar.gz
rails-08983fefd547142ef8b913af1859b96597753d9f.tar.bz2
rails-08983fefd547142ef8b913af1859b96597753d9f.zip
Attributes on scaffold and model generators default to string.
This allows the following: "rails g scaffold Post title body:text author"
Diffstat (limited to 'railties/test/generators')
-rw-r--r--railties/test/generators/generated_attribute_test.rb13
-rw-r--r--railties/test/generators/model_generator_test.rb12
-rw-r--r--railties/test/generators/scaffold_generator_test.rb12
3 files changed, 21 insertions, 16 deletions
diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb
index 0d2e624f44..c9f8ab0a7b 100644
--- a/railties/test/generators/generated_attribute_test.rb
+++ b/railties/test/generators/generated_attribute_test.rb
@@ -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
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index 8c5ba9926b..1b0cb425c6 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -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
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 2135ffac81..c3c6015291 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -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