1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge pull request #473 from haines/am_serializers

Allow serialization of CollectionDecorators with ActiveModel::Serializers
This commit is contained in:
Steve Klabnik 2013-02-12 11:17:53 -08:00
commit 53868c2f2f
4 changed files with 21 additions and 2 deletions

View file

@ -10,7 +10,8 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/drapergem/draper"
s.summary = "View Models for Rails"
s.description = "Draper adds an object-oriented layer of presentation logic to your Rails apps."
s.rubyforge_project = "draper"
s.license = "MIT"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@ -27,5 +28,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec-rails', '~> 2.12'
s.add_development_dependency 'minitest-rails', '~> 0.2'
s.add_development_dependency 'capybara'
s.license = "MIT"
s.add_development_dependency 'active_model_serializers'
end

View file

@ -44,6 +44,12 @@ module Draper
end
end
initializer "draper.setup_active_model_serializers" do |app|
ActiveSupport.on_load :active_model_serializers do
Draper::CollectionDecorator.send :include, ActiveModel::ArraySerializerSupport
end
end
console do
require 'action_controller/test_case'
ApplicationController.new.view_context

View file

@ -9,6 +9,7 @@ require 'rails/all'
require 'draper'
attempt_require 'mongoid'
attempt_require 'devise'
require 'active_model_serializers'
module Dummy
class Application < Rails::Application

View file

@ -0,0 +1,11 @@
require 'spec_helper'
describe Draper::CollectionDecorator do
describe "#active_model_serializer" do
it "returns ActiveModel::ArraySerializer" do
collection_decorator = Draper::CollectionDecorator.new([])
expect(collection_decorator.active_model_serializer).to be ActiveModel::ArraySerializer
end
end
end