I want to create some tests for my app and I have the following error:
1) User feeds ordering should order feeds by id desc
Failure/Error: @post_1 = FactoryGirl.create(:post)
ActiveRecord::AssociationTypeMismatch:
Attachment(#87413420) expected, got Rack::Test::UploadedFile(#81956820)
# ./spec/models/user_spec.rb:37:in `block (3 levels) in <top (required)>'
This error is because I have this on my factories.rb
file
factory :post do
title "Lorem Ipsum"
description "Some random text goes here"
price "500000"
model "S 403"
makes "Toyota"
prefecture "Aichi-ken"
contact_info "ryu ryusaki"
year "2012"
shaken_validation "dec/2014"
attachments [ Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/files/example.jpg"), "image/jpeg") ]
#attachments [ File.open(Rails.root.join("spec/fixtures/files/example.jpg")) ]
end
The test expect an Attachment
object but I m creating an Rack::Test::UploadedFile
object. How can I solve this error?
Thanks.