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...@mac.com> 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@googlegroups.com.
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.
No comments:
Post a Comment