Skip to content
Browse files

Add a hook for serializers in the scaffold generator (off for now).

  • Loading branch information...
1 parent ebb8ea2 commit 6d9f9b3b05f6ea55aad9853888912bcca4d81c9f @josevalim josevalim committed Nov 25, 2011
View
4 railties/lib/rails/generators.rb
@@ -33,7 +33,8 @@ module Generators
:stylesheets => '-y',
:stylesheet_engine => '-se',
:template_engine => '-e',
- :test_framework => '-t'
+ :test_framework => '-t',
+ :serializer => '-z'
},
:test_unit => {
@@ -58,6 +59,7 @@ module Generators
:performance_tool => nil,
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
+ :serializer => false,
:stylesheets => true,
:stylesheet_engine => :css,
:test_framework => false,
View
1 railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -10,6 +10,7 @@ class ScaffoldGenerator < ResourceGenerator #metagenerator
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]
View
9 railties/test/generators/scaffold_generator_test.rb
@@ -264,6 +264,15 @@ def test_scaffold_generator_no_javascripts
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"]

0 comments on commit 6d9f9b3

Please sign in to comment.
Something went wrong with that request. Please try again.