strip_attributes, Rails 3, shoulda 2.11 hack

I have never understood why Rails doesn’t strip attributes by default. I know at least one person who tried committing it to core, only to have it rejected. I always end up installing the strip_attributes plugin.

I’m ramping-up a new Rails 3 project, with Shoulda 2.11. I installed strip_attributes. It works, but the strip_attributes Shoulda macros don’t work anymore. I could take the route of upgrading the plugin, but then I would “have to” also refactor the Shoulda macros since macros have been ditched for matchers. Then I’d have to re-write the tests. At that point, I might as well make it a gem and add that feature I’ve always wanted. But, I’m just not ready for that sort of commitment right now (#gtd_maybe_someday).

So, here’s a short line to add to the end of strip_attributes/init.rb to get the old strip_attributes Shoulda macros working again:

require File.expand_path(File.join(File.dirname(__FILE__), 'shoulda_macros', 'macros.rb')) if Rails.env.test?

2 thoughts on “strip_attributes, Rails 3, shoulda 2.11 hack

  1. Hi Ian,

    I’m glad you find StripAttributes useful.

    I’ve been meaning to update StripAttributes for a while now and your post was enough to encourage me to finally get around to that. As of today, it is now a gem (finally). Version ~>0.9 should work with Rails 2 and >1.0 will work with Rails 3.

    I also updated the README to reflect how to to test its usage while using shoulda (see the “Testing” section).

    https://github.com/rmm5t/strip_attributes

    I still haven’t converted the macros to matchers (I’m not a huge fan of matchers, even though I’m a core committer on shoulda), but I would gladly accept a clean pull-request if someone took the initiative, since that has become the accepted way in shoulda. I’m in no rush to write them myself, because I think the macros solve the problem fine enough for now.

    So, in summary, thanks for writing this. It helped motivate the work.

    1. Wow, you just made my weekend, Ryan. Thanks so much for doing that, and for StripAttributes itself!

      Once this new project reaches a steady pace, I’ll see what I can do about helping out.

      Regards.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.