1

I'm using rails 3.0.9 with ruby 1.9.2. I am doing a system that allow users to put items into different closets. One of the user's possibility is to copy an item of an other user into his own closet (please tell me if you don't understand, I'm not good in explaining things..).

To handle images, I'm using paperclip 2.3.16. I'm testing my app with Rspec-rails 2.6.1, Cucumber-rails 1.0.2. When I run my tests with guard & spork on the asset's copy part, i'm having a "TypeError: can't dup NilClass". I've search on the net for an answer but didn't find anything specific and working :(.

Have you an idea about this issue ?

My code for closet_spec.rb (if you need something else, just tell me) :

  describe '#tidy_up' do
let!(:other_user) { Factory.create(:confirmed_user, :user_name => 'Plop', :email => 'coin@plop.fr') }
let!(:closet) { other_user.closets.first }
let!(:item) { Item.create! :type_id => 42, :closet_id => dream_dressing.id }
let!(:dressing_item) { Item.create! :type_id => 42, :closet_id => dressing.id }

before do
  path = File.join(Rails.root, "spec", "support", 'image.jpg')
  f = File.open(path)
  2.times.map do |n| 
    i = Item.new :type_id => 2#, :asset => Asset.new(picture)
    i.save!
    puts ">>>>>>>>>>>>>>>>>>>>> #{i.id}"
    i.build_asset(:picture => f)
    closet.items << i
  end
  @count = 0
end

it 'copies given items and assets to closet' do
  expect { dream_dressing.tidy_up closet.items }.to change { dream_dressing.items.count }.by 2
  expect { dream_dressing.tidy_up closet.items }.to change { dream_dressing.items.map{|i| i.asset; puts ">>>>>>>>>>>>>>>>> asset : #{i.asset} " }.length }.by 2
end
Neil Knight
  • 47,437
  • 25
  • 129
  • 188
JennyR
  • 11
  • 2

0 Answers0