Rename DecoratedEnumerableProxy to CollectionDecorator

This commit is contained in:
Andrew Haines 2012-10-09 10:07:14 +01:00
parent 025742cb3b
commit 61e6027236
8 changed files with 16 additions and 16 deletions

View File

@ -8,7 +8,7 @@ require 'draper/lazy_helpers'
require 'draper/model_support'
require 'draper/helper_support'
require 'draper/view_context'
require 'draper/decorated_enumerable_proxy'
require 'draper/collection_decorator'
require 'draper/railtie' if defined?(Rails)
# Test Support

View File

@ -1,6 +1,6 @@
require 'active_support/core_ext/object/blank'
module Draper
class DecoratedEnumerableProxy
class CollectionDecorator
include Enumerable
delegate :as_json, :collect, :map, :each, :[], :all?, :include?, :first, :last, :shift, :in_groups_of, :to => :decorated_collection
@ -61,7 +61,7 @@ module Draper
end
def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
"#<CollectionDecorator of #{@klass} for #{@wrapped_collection.inspect}>"
end
def context=(input)

View File

@ -149,7 +149,7 @@ module Draper
input.options = options unless options.empty?
return input
elsif input.respond_to?(:each) && !input.is_a?(Struct) && (!defined?(Sequel) || !input.is_a?(Sequel::Model))
Draper::DecoratedEnumerableProxy.new(input, self, options)
Draper::CollectionDecorator.new(input, self, options)
elsif options[:infer]
input.decorator(options)
else
@ -160,9 +160,9 @@ module Draper
# Fetch all instances of the decorated class and decorate them.
#
# @param [Hash] options (optional)
# @return [Draper::DecoratedEnumerableProxy]
# @return [Draper::CollectionDecorator]
def self.all(options = {})
Draper::DecoratedEnumerableProxy.new(model_class.all, self, options)
Draper::CollectionDecorator.new(model_class.all, self, options)
end
def self.first(options = {})

View File

@ -1,6 +1,6 @@
require 'spec_helper'
describe Draper::DecoratedEnumerableProxy do
describe Draper::CollectionDecorator do
before(:each){ ApplicationController.new.view_context }
subject{ ProductsDecorator.new(source, ProductDecorator) }
let(:source){ Product.new }

View File

@ -560,14 +560,14 @@ describe Draper::Decorator do
end
it "return blank for a decorated empty collection" do
# This tests that respond_to? is defined for the DecoratedEnumerableProxy
# This tests that respond_to? is defined for the CollectionDecorator
# since activesupport calls respond_to?(:empty) in #blank
decorator = ProductDecorator.decorate(empty_collection)
decorator.should be_blank
end
it "return whether the member is in the array for a decorated wrapped collection" do
# This tests that include? is defined for the DecoratedEnumerableProxy
# This tests that include? is defined for the CollectionDecorator
member = paged_array.first
subject.respond_to?(:include?)
subject.include?(member).should == true
@ -596,12 +596,12 @@ describe Draper::Decorator do
context "pretends to be of kind of wrapped collection class" do
subject { ProductDecorator.decorate(paged_array) }
it "#kind_of? DecoratedEnumerableProxy" do
subject.should be_kind_of Draper::DecoratedEnumerableProxy
it "#kind_of? CollectionDecorator" do
subject.should be_kind_of Draper::CollectionDecorator
end
it "#is_a? DecoratedEnumerableProxy" do
subject.is_a?(Draper::DecoratedEnumerableProxy).should be_true
it "#is_a? CollectionDecorator" do
subject.is_a?(Draper::CollectionDecorator).should be_true
end
it "#kind_of? Array" do

View File

@ -21,7 +21,7 @@ describe Draper::ModelSupport do
shared_examples_for "a call to Draper::ModelSupport::ClassMethods#decorate" do
subject { klass.limit }
its(:decorate) { should be_kind_of(Draper::DecoratedEnumerableProxy) }
its(:decorate) { should be_kind_of(Draper::CollectionDecorator) }
it "decorate the collection" do
subject.decorate.size.should == 1

View File

@ -1,3 +1,3 @@
class EnumerableProxy < Draper::DecoratedEnumerableProxy
class EnumerableProxy < Draper::CollectionDecorator
end

View File

@ -1,4 +1,4 @@
class ProductsDecorator < Draper::DecoratedEnumerableProxy
class ProductsDecorator < Draper::CollectionDecorator
def link_to
h.link_to 'sample', "#"