Ruby 1.9.2でRails 3.0.9を使用しています。ユーザーがアイテムを別のクローゼットに入れることを可能にするシステムを行っています。ユーザーの可能性の 1 つは、他のユーザーのアイテムを自分のクローゼットにコピーすることです (わからない場合は教えてください。私は物事を説明するのが得意ではありません..)。
画像を処理するために、paperclip 2.3.16 を使用しています。Rspec-rails 2.6.1、Cucumber-rails 1.0.2 でアプリをテストしています。アセットのコピー部分でガードとスポークを使用してテストを実行すると、「TypeError: can't dup NilClass」というメッセージが表示されます。ネットで答えを検索しましたが、具体的で機能するものは見つかりませんでした:(。
この問題について何か考えはありますか?
closet_spec.rb の私のコード (他に何か必要な場合は、教えてください):
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