Permalink
Browse files

Make resource generator invoke serializer generator

  • Loading branch information...
spastorino committed Jun 10, 2015
1 parent e117615 commit 4752e6723a6e0e8c4038ed4f36b87a954ad21097
@@ -0,0 +1,8 @@
module ActiveModel
class Railtie < Rails::Railtie
initializer 'generators' do |app|
app.load_generators
require 'generators/serializer/resource_override'
end
end
end
@@ -2,6 +2,7 @@
require 'active_model/serializer/version'
require 'active_model/serializer'
require 'active_model/serializer/fieldset'
require 'active_model/serializer/railtie'
begin
require 'action_controller'
@@ -0,0 +1,12 @@
require 'rails/generators'
require 'rails/generators/rails/resource/resource_generator'
module Rails
module Generators
class ResourceGenerator
def add_serializer
invoke 'serializer'
end
end
end
end
@@ -0,0 +1,24 @@
require 'test_helper'
# require 'active_model/serializer/railtie'
class ResourceGeneratorTest < Rails::Generators::TestCase
destination File.expand_path('../../tmp', __FILE__)
setup :prepare_destination, :copy_routes
tests Rails::Generators::ResourceGenerator
arguments %w(account)
def test_serializer_file_is_generated
run_generator
assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < ActiveModel::Serializer/
end
private
def copy_routes
config_dir = File.join(destination_root, 'config')
FileUtils.mkdir_p(config_dir)
File.write(File.join(config_dir, 'routes.rb'), 'Rails.application.routes.draw { }')
end
end
@@ -1,3 +1,4 @@
require 'test_helper'
require 'generators/serializer/serializer_generator'
class SerializerGeneratorTest < Rails::Generators::TestCase
View
@@ -9,18 +9,20 @@
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
require 'active_model_serializers'
class Foo < Rails::Application
if Rails::VERSION::MAJOR >= 4
config.eager_load = false
config.secret_key_base = 'abc123'
config.action_controller.perform_caching = true
config.active_support.test_order = :random
ActionController::Base.cache_store = :memory_store
config.active_support.test_order = :random
config.logger = Logger.new(nil)
ActionController::Base.cache_store = :memory_store
end
end
Foo.load_generators
require "active_model_serializers"
ActionController::Base.cache_store.clear
Foo.initialize!
require 'fixtures/poro'

1 comment on commit 4752e67

@arunagw

This comment has been minimized.

Show comment
Hide comment

💚

Please sign in to comment.