2

I choose refile gem to handle file uploads in my application. I have some trouble with use it with FactoryGirl. In my factory I have something like that:

include ActionDispatch::TestProcess
FactoryGirl.define do
  factory :company do
    sequence(:name)  { |n| "Company #{n}" }
    logo_id { fixture_file_upload(Rails.root.to_s + "/spec/fixtures/images/1x1.gif") }
  end
end

When I run some feature specs it returns me the following error:

  5) Company destroying destroys company
     Failure/Error: visit companies_path
     ActionView::Template::Error:
       Refile::InvalidID

EDIT: This error is caused by this line in my view template:

  %td= image_tag attachment_url(company, :logo, :fill, 50, 50)
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133

1 Answers1

1

Don't set the logo id manually. Try something like this. And also, to speed up your tests, use something lightweight instead of a real file, like StringIO.

FactoryGirl.define do
  factory :company do
    sequence(:name) { |n| "Company #{n}" }

    logo {
      StringIO.new('hello')
    }
  end
end
Mohamad
  • 34,731
  • 32
  • 140
  • 219