Sha256: e62bc59c2bc8f9c09ff07dd6481fd81e092409c8c1b6f02aa5f22adbb7b82488

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

describe Draper::ModelSupport do
  subject { Product.new }

  describe '#decorator' do
    its(:decorator) { should be_kind_of(ProductDecorator) }
    its(:decorator) { should be(subject.decorator) }

    it 'have abillity to pass block' do
      a = Product.new.decorator { |d| d.awesome_title }
      a.should eql "Awesome Title"
    end

    it 'is aliased to .decorate' do
      subject.decorator.model.should == subject.decorate.model
    end
  end

  describe Draper::ModelSupport::ClassMethods do
    shared_examples_for "a call to Draper::ModelSupport::ClassMethods#decorate" do
      subject { klass.limit }

      its(:decorate) { should be_kind_of(Draper::DecoratedEnumerableProxy) }

      it "decorate the collection" do
        subject.decorate.size.should == 1
        subject.decorate.to_ary[0].model.should be_a(klass)
      end

      it "return a new instance each time it is called" do
        subject.decorate.should_not == subject.decorate
      end
    end

    describe '#decorate - decorate collections of AR objects' do
      let(:klass) { Product }

      it_should_behave_like "a call to Draper::ModelSupport::ClassMethods#decorate"
    end

    describe '#decorate - decorate collections of namespaced AR objects' do
      let(:klass) { Namespace::Product }

      it_should_behave_like "a call to Draper::ModelSupport::ClassMethods#decorate"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
draper-0.18.0 spec/draper/model_support_spec.rb
draper-0.17.0 spec/draper/model_support_spec.rb
draper-0.16.0 spec/draper/model_support_spec.rb