问题
I am testing the creation of my Image object with FactoryGirl and Rspec.
Orignally i have been doing I am using
photo { File.new(File.join(Rails.root, 'spec/fixtures', photo_name)) }
but all of a sudden i am getting
Paperclip::AdapterRegistry::NoHandlerError:
No handler found for "#<File:0x00000003bf15c8>
So after reading various posts I have changed to fixture_file_upload
method but am having trouble creating the object.
images.rb
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :image do
transient do
photo_name 'validated_image.jpg'
end
photo { fixture_file_upload(Rails.root.join('spec', 'fixtures', photo_name), 'image/jpeg') }
end
Though originally i tried this as the fixture path was declared in my rails_helper
photo { fixture_file_upload photo_name, 'image/jpeg' }
# config.fixture_path = "#{::Rails.root}/spec/fixtures" # rails_helper
# Would produce error 'validated_image.jpg file does not exist'
My current implementation (vey top) doesnt create an instance of Image when doing this
it 'creates a new image' do
expect do
post :create, image: FactoryGirl.attributes_for(:image)
end.to change(Image, :count).by(1)
end
# ERROR
# expected #count to have changed by 1, but was changed by 0
Am i missing anything here?
Thanks
来源:https://stackoverflow.com/questions/34677780/using-fixture-file-upload-method-rails-4-rspec