Erwin
2012-Jun-08 09:32 UTC
[Rails 3.2.5] Rails: unit test fixture_path : fixture_file_upload cannot find the file ...
I am trying to perform a test unit, using FactoryGirl include ActionDispatch::TestProcess FactoryGirl.define do factory :article do ....... photo { fixture_file_upload ''/files/test.jpg'', ''image/jpg'' } end end IN mt test_helper.rb I defined the fixture_path def fixture_path File.dirname(__FILE__) + "/fixtures/" # "..../myapp/test/ fixtures/" end and I have my test.jpg in "..../myapp/test/fixtures/files/ test.jpg" but running the unit test, article = FactoryGirl.build(:article, title: nil), I get an error : RuntimeError: files/test.jpg file does not exist where should I put the file for ''fixture_file_upload'' can find it ? thanks for feedback -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Erwin
2012-Jun-08 10:00 UTC
Re: Rails: unit test fixture_path : fixture_file_upload cannot find the file ...
I looked into : actionpack/lib/action_dispatch/testing/ test_process.rb def fixture_file_upload(path, mime_type = nil, binary = false) fixture_path = self.class.fixture_path if self.class.respond_to? (:fixture_path) Rack::Test::UploadedFile.new("#{fixture_path}#{path}", mime_type, binary) end it''s trying to get the fixturePath from self.class ( Article in this case) which doesn''t respond to fixture_path however the correct path is given by ActionController::TestCase.fixture_path so using the trick: photo { fixture_file_upload "#{ActionController::TestCase.fixture_path}files/test.jpg", ''image/ jpg'' } runs well... but I guess it''s just a trick, the ''truth'' is somewhere else ..... ? how can I relate the fixture_path with the self.class thanks for your feedback On 8 juin, 11:32, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> I am trying to perform a test unit, using FactoryGirl > > include ActionDispatch::TestProcess > FactoryGirl.define do > factory :article do > ....... > photo { fixture_file_upload ''/files/test.jpg'', ''image/jpg'' } > end > end > > IN mt test_helper.rb I defined the fixture_path > > def fixture_path > File.dirname(__FILE__) + "/fixtures/" # "..../myapp/test/ > fixtures/" > end > > and I have my test.jpg in "..../myapp/test/fixtures/files/ > test.jpg" > > but running the unit test, article = FactoryGirl.build(:article, > title: nil), I get an error : > RuntimeError: files/test.jpg file does not exist > > where should I put the file for ''fixture_file_upload'' can find it ? > > thanks for feedback-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.