---
title: This week in open source
teaser:
tags: news,open source
author: Mike Burns
published_on: 2011-11-04
---

A somewhat short update this week, in large part because I'm writing this from a different timezone than normal. Next week I'll be five hours slower, don't you worry!

## suspenders

New in [suspenders](https://github.com/thoughtbot/suspenders), our Rails app generator: a pre-packaged email validator class ([b91ea65](http://github.com/thoughtbot/suspenders/commit/b91ea65c1885e3198fd05ae4622ef09fe00b6143 "include an email validator as seen on http://guides.rubyonrails.org/active_record_validations_callbacks.html#performing-custom-validations")), which probably mixes well with things like [liaison](http://github.com/mike-burns/liaison). Also on the email front, delivery errors are a full error in development, which means we can catch errors faster ([637427d](http://github.com/thoughtbot/suspenders/commit/637427d45a2c57f19603aaa19d2e064a6a2bb573 "raise delivery errors of emails in development environment. more visibility into problems. fail fast.")). Both of these improvements brough to you by Dan Croak ([croaky](http://github.com/croaky)).

## shoulda-matchers

The [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers) collection of RSpec/shoulda matchers has hit 1.0.0! Gabe Berke-Williams ([gabebw](http://github.com/gabebw)) made the switch from 1.0.0.beta3 to 1.0.0 ([7c408ef](http://github.com/thoughtbot/shoulda-matchers/commit/7c408eff76802e3dc91590c381ae4e9a397fb2e1 "Bump to version 1.0.0.")), but first removed a deprecation warning from the rdoc generator ([c47557c](http://github.com/thoughtbot/shoulda-matchers/commit/c47557c14c0953f46e22f7e77aa8392e29531f3d "Get rid of deprecation warning.")) and simplified the test suite ([22740fd](http://github.com/thoughtbot/shoulda-matchers/commit/22740fd95672ce701eb348453381ed9aaf96fe27 "Generated rails app no longer requires a JS runtime.")).

## shoulda-context

Another 1.0.0 release for shoulda this week, as [shoulda-context](https://github.com/thoughtbot/shoulda-context), which controversially provides nested test structures for `Test::Unit` saw an explicit dependency on `Test::Unit` so that <abbr title="Matz' Ruby Interpreter">MRI</abbr> 1.9.2 doesn't confuse it with MiniTest ([d1c5881](http://github.com/thoughtbot/shoulda-context/commit/d1c58811ae1e0f83e4f17805298095c6eed2641c "Added explicit dependency on test-unit for better Ruby 1.9 support

This will likely be a temporary solution before fully embracing Minitest"))&mdash;that's thanks to Ryan McGeary ([rmm5t](http://github.com/rmm5t))&mdash;but then Jason Morrison ([jasonm](http://github.com/jasonm)) decided that enough was enough and he released version 1.0.0 of shoulda-context ([9557425](http://github.com/thoughtbot/shoulda-context/commit/95574259b0cdde10d7e46ab2efd873d196337f69 "Releasing 1.0.0")).

## paperclip

Our file uploading gem, [paperclip](https://github.com/thoughtbot/paperclip), saw an interesting commit from yours truly, Mike Burns ([mike-burns](http://github.com/mike-burns)). With a Paperclip attachment you can get the URL (e.g. `@user.avatar.url(:medium)`). The logic for generating this URL was specified in the `Paperclip::Attachment` class, which meant that to do anything interesting like delaying the thumbnail generation or storing the style names in the database involved monkey-patching, which is clearly a mistake. So I pulled that functionality out into the UrlGenerator class, but more importantly I parameterized that class name so you can pass whatever you want. For example:

    class User < ActiveRecord::Base
      has_attached_file :avatar,
        :url_generator => DataBaseStyledUrlGenerator.new(ActiveRecord::Base.connection)
    end

    class DataBaseStyledUrlGenerator
      def initialize(db)
        @db = db
      end

      def new(attachment, attachment_options)
        @attachment = attachment
        @attachment_options = attachment_options
      end

      def for(style_name, options)
        dimensions = db.select_row("SELECT width, height FROM styles WHERE style_name = ?", style_name)
        "/assets/images/#{dimensions['width']}/#{dimensions['height']}/#{@attachment.id}.jpg"
      end
    end

Refactoring to add functionality? Heck yeah! ([bc5c51d](http://github.com/thoughtbot/paperclip/commit/bc5c51d1ece1ee45f94b056a0f5a1674d7e8cba9 "Separate the UrlGenerator out from the Attachment. Some example plugins that could be written include generating thumbnails on the fly for different thumbnail sizes, or delaying the thumbnail generation until it is first called."))

## factory_bot[^1]

A bug fix and the usual slew of refactorings for [factory_bot](https://github.com/thoughtbot/factory_bot) this week. As the bug fix, Joshua Clayton ([joshuaclayton](http://github.com/joshuaclayton)) fixed implicit traits' error output by having them know their name ([0124d42](http://github.com/thoughtbot/factory_bot/commit/0124d42bf19a06362b3d0fca52c1d48359f5e83d "Fix callback handling from implicit traits")). Small, but good to have.

Internally, he applied the [null object pattern](https://thoughtbot.com/blog/post/12179019201/design-patterns-in-the-wild-null-object) to act as a parent of orphan factories ([aee300a](http://github.com/thoughtbot/factory_bot/commit/aee300aa90a82970c1fa73df48bbc8305b99532a "Add NullFactory")). He added a `DeclarationList` to hold the collection of things declared about a factory, including attributes ([3114dcd](http://github.com/thoughtbot/factory_bot/commit/3114dcd93538fe34116350b4b3649b2427495752 "Wrap up DeclarationList DeclarationList knows how to generate an attribute list, which never really made sense outside of being generated from declarations. Now, the declaration list builds a list of attributes which is combined in Factory#attributes with attributes from traits and its parents.") and [f721bc6](http://github.com/thoughtbot/factory_bot/commit/f721bc6b83f86f566398439acf1067d5020d4ae5 "Initial work on DeclarationList and cleaning up AttributeList")). He abstracted out the idea of a factory and a trait into the `Definition` class ([41bc3ac](http://github.com/thoughtbot/factory_bot/commit/41bc3ac5ff71d24aa8f4ece7d56c3593bf8497f9 "Add FactoryBot::Definition Both Factory and Trait have similar methods and interact with a DefinitionProxy. The idea here is to move the interface DefinitionProxy expects to a separate class and both Factory and Trait can delegate to an instance of Definition.")). He also removed the unused `@ignored_attributes` instance variable ([68e8e9e](http://github.com/thoughtbot/factory_bot/commit/68e8e9ea6f93d45729bd4ee720f6dc1c78245739 "Remove extra @ignored_attributes assignments in subclasses of Proxy")) and moved the logic around adding a proxy value into one place ([3803be3](http://github.com/thoughtbot/factory_bot/commit/3803be38465ceec7d4a37f3aad0f6c126fc2b0c7 "Simplify Factory::Runner by always having attribute add_to(proxy)")).

Alexander Gronemann ([Highcode](https://github.com/agronemann)) fixed a typo in the docs for us ([5a48129](http://github.com/thoughtbot/factory_bot/commit/5a4812941ef3b5826f0859ebdaac5f740ecc27a4 "Fixing typo in GETTING_STARTED.md")). Thanks!

## capybara-webkit

All changes to the [capybara-webkit](https://github.com/thoughtbot/capybara-webkit) headless browser were documentation changes this week: Joe Sak ([joemsak](http://github.com/joemsak)) mentioned `:js => true` for specs and that transactional fixtures still cannot be used ([true should still be used, and to note the Transactional fixtures gotcha in the main README">eb6165d](http://github.com/thoughtbot/capybara-webkit/commit/eb6165d933f6c69b148f5566acaefdabfb55b79f "Add a couple of notes that :js =")). Joe Ferris ([jferris](http://github.com/jferris)) took a stance on the inconsistent authors section of the README by specifying his name and Matt Mongeau's name, but also pointing to the list of Github contributors ([8674ef7](http://github.com/thoughtbot/capybara-webkit/commit/8674ef7a51b95720c7ca7ff3838daefce316068e "Update authors")). While there he changed some grammar to his liking ([7be8f94](http://github.com/thoughtbot/capybara-webkit/commit/7be8f94c5fc8859aecbaa43dce81eaeb51c3f3b0 "Clean up README")).

## clearance

Another refactoring-based feature for us this week in [clearance](https://github.com/thoughtbot/clearance), our authentication gem. Constantine Mavromoustakos ([cmavromoustakos](https://github.com/cmavromoustakos)) split the user instance methods into an `InstanceMethods` module, which helped them be more selective about which methods they want to pull into their MongoDB-based app ([cc0d007](http://github.com/thoughtbot/clearance/commit/cc0d00786b5b8b12b2089478ff30d2c79074a969 "Merge pull request #174 from cmavromoustakos/master only include the instance methods and callbacks.")).

## fake_braintree

Mostly refactoring on the Braintree test fakes, [fake_braintree](https://github.com/thoughtbot/fake_braintree), this week, but let's see what features we can pull out of these refactorings by Gabe Berke-Williams ([gabebw](http://github.com/gabebw)). He introduced a `FakeBraintree::Subscription` class ([e4e99f8](http://github.com/thoughtbot/fake_braintree/commit/e4e99f82655198726627d30bcbea054fbd515bcc "Introduce FakeBraintree::Subscription.")), which can you use as a fake subscription. He also introduced a `FakeBraintree::Customer` class, to be a fake paying customer ([0259b9d](http://github.com/thoughtbot/fake_braintree/commit/0259b9d74efc621e0cb7614290d295b90ac88044 "Massively clean up Customer creation code.") and [9902e08](http://github.com/thoughtbot/fake_braintree/commit/9902e081f1f618d07cc6af1e4d4ca6152b3df607 "Keep Customer-related code with the Customer.")). Maybe you needed those!

On the lighter side he cleared up the test coverage question by removing most untested code ([0f6ed3f](http://github.com/thoughtbot/fake_braintree/commit/0f6ed3ff56c14daa9cbca8f57b769f1a31b10a6d "Remove comment about test coverage.") and [ad7a4b9](http://github.com/thoughtbot/fake_braintree/commit/ad7a4b9e98fb8eded19c06ad9a6ea4b250d4fca3 "Remove untested code.")), adding a test to ensure that the next billing date is a month from now ([84cfbc4](http://github.com/thoughtbot/fake_braintree/commit/84cfbc4ff872b139b3adb4d003062786eb0fec0e "Ensure next billing date is 1 month from now.")), and removing an 80-line unused method ([e1a886c](http://github.com/thoughtbot/fake_braintree/commit/e1a886c677ca887549ec0571e4e98038015c0bd5 "Remove unused method.")). He responded to my ctags file observation from last week by removing it ([8eb5988](http://github.com/thoughtbot/fake_braintree/commit/8eb5988d1228454f85d075dabf60a0953418616f "Ignore tags file.") and [7a9fb76](http://github.com/thoughtbot/fake_braintree/commit/7a9fb76dfe1e128a8063614368ff22fe41468225 "Remove tags file.")). He also did a couple of other things under the name "cleanup" ([5690d40](http://github.com/thoughtbot/fake_braintree/commit/5690d4025039c137cf3e9187c99da2115f92832b "Clean up specs."), [76675cb](http://github.com/thoughtbot/fake_braintree/commit/76675cb76a390d11b00395716af2f66b45fc4c46 "Reduce duplication."), [2aaf85c](http://github.com/thoughtbot/fake_braintree/commit/2aaf85c4380dcb2432359d992c2e47066a3617f3 "Cleanup."), [d7811aa](http://github.com/thoughtbot/fake_braintree/commit/d7811aa472a316d73721719b1fde81d9cc4b7e39 "Whitespace."), and [cc7463f](http://github.com/thoughtbot/fake_braintree/commit/cc7463f7070b740706f1d36edf81df749cdb08fb "Split up specs.")).

[^1]: Looking for FactoryGirl? The library was renamed in 2017.
[Project name history can be found here.](https://github.com/thoughtbot/factory_bot/blob/master/NAME.md)
