From ace6a0eb03ce4a1b25944a6aa7f702405c4ea1ab Mon Sep 17 00:00:00 2001 From: Markus Fenske Date: Mon, 16 Jul 2012 19:23:35 +0200 Subject: [PATCH] Support for Sequel --- lib/draper/base.rb | 2 +- spec/draper/base_spec.rb | 9 +++++++++ spec/spec_helper.rb | 1 + spec/support/samples/sequel_product.rb | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 spec/support/samples/sequel_product.rb diff --git a/lib/draper/base.rb b/lib/draper/base.rb index 74f5210..3d517d1 100755 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -136,7 +136,7 @@ module Draper if input.instance_of?(self) input.options = options unless options.empty? return input - elsif input.respond_to?(:each) + elsif input.is_a?(Enumerable) Draper::DecoratedEnumerableProxy.new(input, self, options) elsif options[:infer] input.decorator(options) diff --git a/spec/draper/base_spec.rb b/spec/draper/base_spec.rb index 1c810d6..c3c0a32 100755 --- a/spec/draper/base_spec.rb +++ b/spec/draper/base_spec.rb @@ -363,6 +363,15 @@ describe Draper::Base do end end + context "when given a collection of objects which respond to #each" do + # Sequel models implement #each + let(:source) { [SequelProduct.new, SequelProduct.new] } + + it "returns a collection of wrapped objects" do + subject.each{ |decorated| decorated.should be_instance_of(Draper::Base) } + end + end + context "when given a single source object" do let(:source) { Product.new } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 71e67d5..50358d6 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,7 @@ require './spec/support/samples/namespaced_product_decorator' require './spec/support/samples/non_active_model_product' require './spec/support/samples/product' require './spec/support/samples/product_decorator' +require './spec/support/samples/sequel_product' require './spec/support/samples/specific_product_decorator' require './spec/support/samples/some_thing' require './spec/support/samples/some_thing_decorator' diff --git a/spec/support/samples/sequel_product.rb b/spec/support/samples/sequel_product.rb new file mode 100644 index 0000000..a3fceeb --- /dev/null +++ b/spec/support/samples/sequel_product.rb @@ -0,0 +1,9 @@ +class SequelProduct + def each + end + + def some_attribute + "hello" + end +end +