Spec + draper controller

I am using rspec and draper gem https://github.com/jcasimir/draper

In my controller this is a simple action show

def show
  @category = Category.find(params[:id])
  @products = ProductDecorator.decorate(@category.products)
end

      

and test

describe "#show" do
  before { @category = Factory :category }
  before do
    @product1 = Factory :product, category: @category
    @product2 = Factory :product, category: @category
  end
  before { get :show, id: @category.id  }

  it { should respond_with :success }
  it { assigns(:products).should eq [@product1, @product2] }
end

      

Everything works fine in the project and the products are displayed fine, but in the test I get this error

Failure/Error: it { assigns(:products).should eq [@product1, @product2] }

   expected: [#<Product ... >, #<Product ...>]
        got: nil

   (compared using ==)

      

also if i replace ProductDecorator.decorate (@ category.products) with @ category.products only - no errors

if i check @products

def show
  @category = Category.find(params[:id])
  @products = ProductDecorator.decorate(@category.products)
  puts @products.inspect
end

      

got

#<DecoratedEnumerableProxy of ProductDecorator for [#<Product ...>, #<Product ...>]>

      

Any suggestions?

+3


source to share


1 answer


Why just check that you have this Decorator in your assignments?



it { assigns(:products).should eq(ProductDecorator.decorate([@product1, @product2] }))

      

-1


source







All Articles