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:
commit
53868c2f2f
4 changed files with 21 additions and 2 deletions
|
@ -10,7 +10,8 @@ Gem::Specification.new do |s|
|
||||||
s.homepage = "http://github.com/drapergem/draper"
|
s.homepage = "http://github.com/drapergem/draper"
|
||||||
s.summary = "View Models for Rails"
|
s.summary = "View Models for Rails"
|
||||||
s.description = "Draper adds an object-oriented layer of presentation logic to your Rails apps."
|
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.files = `git ls-files`.split("\n")
|
||||||
s.test_files = `git ls-files -- {test,spec,features}/*`.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) }
|
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 'rspec-rails', '~> 2.12'
|
||||||
s.add_development_dependency 'minitest-rails', '~> 0.2'
|
s.add_development_dependency 'minitest-rails', '~> 0.2'
|
||||||
s.add_development_dependency 'capybara'
|
s.add_development_dependency 'capybara'
|
||||||
s.license = "MIT"
|
s.add_development_dependency 'active_model_serializers'
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,12 @@ module Draper
|
||||||
end
|
end
|
||||||
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
|
console do
|
||||||
require 'action_controller/test_case'
|
require 'action_controller/test_case'
|
||||||
ApplicationController.new.view_context
|
ApplicationController.new.view_context
|
||||||
|
|
|
@ -9,6 +9,7 @@ require 'rails/all'
|
||||||
require 'draper'
|
require 'draper'
|
||||||
attempt_require 'mongoid'
|
attempt_require 'mongoid'
|
||||||
attempt_require 'devise'
|
attempt_require 'devise'
|
||||||
|
require 'active_model_serializers'
|
||||||
|
|
||||||
module Dummy
|
module Dummy
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
|
|
11
spec/dummy/spec/decorators/active_model_serializers_spec.rb
Normal file
11
spec/dummy/spec/decorators/active_model_serializers_spec.rb
Normal 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
|
Loading…
Reference in a new issue