Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Desmond Bowe

Posts By

LABS
Avoid using fixture_file_upload with FactoryGirl and Paperclip

Joe Moore and I are using FactoryGirl and Paperclip for file attachments. The factory for building our Attachment model looked like this:

 factory :attachment do
   supporting_documentation { fixture_file_upload('test.pdf', 'application/pdf') }
   # ...
 end

Yesterday our test suite began raising the following error:

 Failure/Error: let(:attachment) { FactoryGirl.create(:attachment) }
 Errno::EMFILE:
   Too many open files - /var/folders/3q/_15370v96jlbnxsk3whsks5c0000gn/T/test20120920-4004-7c2o9y.pdf

It turns out that Rails' fixture_file_upload method does not close the temporary file it creates. We found a suggestion to prevent leaking file handles by adding an after_create block that manually closes the file. We tested this fix by looping through the model spec 1000 times. More tests passed, but it eventually blew up with the same error.

Using fixture_file_upload needlessly exercises Paperclip's file uploading functionality instead of just creating the models we care about for our application. Instead, explicitly set the attributes Paperclip needs:

 factory :attachment do
   supporting_documentation_file_name { 'test.pdf' }
   supporting_documentation_content_type { 'application/pdf' }
   supporting_documentation_file_size { 1024 }
   # ...
 end

...and all of our tests passed.

Conclusion: in model factories, set the Paperclip attributes directly and don't use fixture_file_upload.

PIVOTAL LABS
Friday Hugs!

Events

  • Saturday: NYC PyLadies Meetup- 8PM

http://www.meetup.com/NYC-PyLadies/

A group for Python ladies of all levels of programming experience, in the NYC metro area.

Pyladies is an international mentorship group with a focus on helping more women become active participants and leaders in the Python open-source community. Our mission is to promote, educate and advance a diverse Python community through outreach, education, conferences, events and social gatherings.

PyLadies also aims to provide a friendly support network for women and a bridge to the larger Python world. Anyone with an interest in Python is encouraged to participate!

PIVOTAL LABS
Best Standup Ever!

(Title: 09/13/12: Best Standup Ever!)

Events

  • Thursday: NYC Lean Startup Meetup

Q&A with Eric Ries Description: Eric Ries, the author of The Lean Startup, is in NYC and joining us to answer questions from the community. We will be doing light moderation, but this event is really about you getting a chance to talk to Eric.

PIVOTAL LABS
09/12/12: [NY][Standup] 9/12/2012 $0-$4 in Chrome

Interestings

  • $0 - $4 in Chrome

You can reference the 4 most recently selected elements from the Elements panel via these variables.

  • Bundler.with_clean_env

When you shell out from your ruby script and run the "bundle" command, it will bundle within the context of your script's Gemfile (even if you cd first to another directory with a different Gemfile).

If you need to shell out and bundle outside the context of your script's bundle, use Bundler.with_clean_env. For example:

Bundler.with_clean_env do
  `cd /some/other/bundled/project  && bundle`
end

We ran into a need for this on LicenseFinder - we wrote an integration test suite that bootstraps a bundled project, adds dependencies with various licenses to it, then tests the output of license finder on the project.

Events

  • Wednesday: Happy Programmers' Day! (256th day of the year)

http://en.m.wikipedia.org/wiki/Programmers'_Day

  • Wednesday: Junior Developer Panel Meetup (or... How to Get Your First Coding Gig)

http://www.meetup.com/nyc-on-rails/events/79685082/

Are you someone teaching yourself to code, looking for your first job as a developer? This panel will address the questions of how to get your first job as a professional programmer, and what is expected of someone in that sort of role. Questions from the audience are also welcome. Our panelists: Jeffrey Baird (Junior Developer @ Medivo) Aidan Feldman (Developer @ Jux & Teacher @ NYU) - moderator Avi Flombaum (Founder of Flatiron School) Pedro Ha (Teacher @ NYU & Developer @ CNBC) Dan Langevin (CTO @ Lifebooker) Debbie Madden (Exec. VP @ Cyrus Innovation) Beforehand, make sure to check out Jeffrey's great post on getting his job. If you have other good resources around this topic, feel free to post in the comments. We will do our best to record this, for those who can't make it. Note this event is not Rails-specific. Drinks and snacks provided by Pivotal Labs. Lastly, in an unusual meetup twist,recruiting [for junior developers] is welcome!