aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/lib/rails/generators.rb4
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb1
-rw-r--r--railties/test/generators/scaffold_generator_test.rb9
3 files changed, 13 insertions, 1 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 27f8d13ce8..f1ca9080ff 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -33,7 +33,8 @@ module Rails
:stylesheets => '-y',
:stylesheet_engine => '-se',
:template_engine => '-e',
- :test_framework => '-t'
+ :test_framework => '-t',
+ :serializer => '-z'
},
:test_unit => {
@@ -58,6 +59,7 @@ module Rails
:performance_tool => nil,
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
+ :serializer => false,
:stylesheets => true,
:stylesheet_engine => :css,
:test_framework => false,
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index 03a61a035e..7353a67c83 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -10,6 +10,7 @@ module Rails
class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
hook_for :scaffold_controller, :required => true
+ hook_for :serializer
hook_for :assets do |assets|
invoke assets, [controller_name]
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 2db8090621..2e8b03fbef 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -264,6 +264,15 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "app/assets/stylesheets/posts.css"
end
+ def test_scaffold_also_generators_serializer
+ run_generator [ "posts", "name:string", "author:references", "--serializer" ]
+ assert_file "app/serializers/post_serializer.rb" do |serializer|
+ assert_match /class PostSerializer < ActiveModel::Serializer/, serializer
+ assert_match /^ attributes :name$/, serializer
+ assert_match /^ has_one :author$/, serializer
+ end
+ end
+
def test_scaffold_generator_outputs_error_message_on_missing_attribute_type
run_generator ["post", "title", "body:text", "author"]