Oct 272014
 

Now with full test coverage using MiniTest.

Rubygems link:
http://rubygems.org/gems/nondestructive_migrations

Github Link:
https://github.com/jasonfb/nondestructive_migrations

A few things I learned here along the way:

MiniTest has not replaced TestUnit for the hard-core Rails developer. MiniTest worked great fro this, except Rails version 4.0.x, 3.1.x and 3.2.x needs “minitest-rails”, “~> 1.0”. I tried testing with Rspec but since Rails itself is tested with Minitest this was actually easier (since I needed access to some special tests written inside of Railtie)

I used a fantastic tool called Appraisal to run my tests suite against several different versions of Rails (3.1, 3.2, 4.0, 4.1, and 4.2). Getting this set up with a little bit of work, but well worth it. You can configure Travis CI to work seamlessly with Appraisal, so you can run your Gem against different versions of Ruby, Rails, and three different databases (SQLite, MySQL, and Postgres). See the .travis.yml and Appraisals inside the gem code for details.

When writing a Gem, you’ll want to explicitly include all your files in the files setting inside the Gemspec (example). This is important, and if you fail to do this those files will work when the Gem is loaded via git: or path: but not when it is pulled from RubyGems.

Rubygems forces you to publish explicit version numbers on your gems. You cannot overwrite an existing version number, but you are allowed to “yank” a version down to remove it from Rubygems.

 Posted by at 8:28 am  Tagged with:
Oct 212014
 

This is a useful little trick to get all the methods that you can call on any Ruby object. This is extremely helpful when poking around someone else’s code (like Gem code) that is poorly documented.

foo.methods

This will return a long list of methods that you can call on the object. That list will include all the methods on all the superclasses of the object, including the Object object methods (the grandaddy of all objects). That’s often not very useful, so you can filter out the superclasses’s methods and only look at the methods associated with the subclass using:

foo.methods(false)
 Posted by at 3:49 pm  Tagged with:
Oct 142014
 

Learned something on the Rails-talk list today that blew me away.

You can install an older version of rails using this syntax:

rails _4.0.8_ new appname

(Where “4.0.8” is the version you want and “appname” is the name of your new rails app.)

Yes, you actually type those underscores around the version number. By the way, if you don’t have that version installed (it installs via bundler), bundler will tell you it can’t find the gem. In that case, you’ll want to do gem install rails -v 4.0.8 and then re-run the command above.

This is a :thumbs down: for Rails documentation. This little trick isn’t even documented when I get the manual page for the rails new command (rails new -h)

Voila!

 Posted by at 10:49 am  Tagged with:
Oct 102014
 

Every restart your Mac and have it boot up only to open all the last Safari windows you had just opened? This feature – introduced a few operating systems ago – is something I personally don’t like at all. Perhaps I’m a “power user” but I often find that I open so many browser windows in the course of my work that I don’t really want them to all re-open

Ostensibly, Safari appears to have a preference to turn this off or on, here:

However in my version of Safari (7.0.6 on Mac OS X 10.9.5), this preference appears to not actually work at all. (annoying)

So here’s how to go into your system defaults and turn it off for real:

defaults write com.apple.Safari NSQuitAlwaysKeepsWindows -bool false