Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

May 9, 2009

Cucumber + Paperclip

I just spent an inordinately long time trying to figure out how to get Cucumber tests to create records with Paperclip files attached. Those of you with an equally troglodytic IQ may thus find this snippet useful. The idea here, which is probably obvious, is that I have an upload-files folder in my Cucumber features folder in the root of the Rails application. I put the required sample files there. Be warned that this is actually saving the files to your public folder and they will not get removed when the test is done. When I figure out a better way of doing this I will update this article. Or better yet, if you know a better way of doing this, please a post a comment!

features/page_stepbs.rb:

Given /^I have 1 page$/ do    
    path = "#{RAILS_ROOT}/features/upload-files/"
    image = File.new(path + "image.jpg")
    song = File.new(path + "song.mp3")
    Page.create!(:image=>image,:song=>song)
end

I am available for Ruby on Rails consulting work – get in touch to learn more.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus