Friday, October 30, 2009

Peaceful Co-Existence Between Subversion and Git

So I have been using Subversion as my source control tool for my Rails apps for a couple of years now, and I am very happy with it.

Recently, I have begun to use Git as my source control for plugin development, and using as a means to share my work with the community.

So, the dual-tool strategy begs the questions:

  • Do they play nice together?

  • How does a developer make them play nicely with one another?

The short answers to these questions is Yes. If you want the details, read on.

Given the Tidy code I am versioning using Git is not a full-blown application, I need it to reside within the context of a Rails application to test it. So this is what I did:

  1. Have my application, let's call it X, version controlled using Subversion

  2. In application X's vendor/plugins directory, I create a Git repository called tidy; this is where I maintain and test Tidy's code

  3. This Git repository is tied to, so that I can push any changes out for the community to see

  4. The tidy directory is also version controlled by Subversion, so that my application has a working copy of Tidy that I can deploy

  5. However, Subversion complains about the tidy/.git directory, and Git in turn complains about the various tidy/*/.svn directories

  6. To remedy this, I added a tidy/.gitignore file to ignore the various tidy/*/.svn directories, and I added set the svn:ignore property on tidy/ to ignore the tidy/.git directory

With this setup, I can now more easily maintain the code for both my Rails application and the Tidy plugin. Has Uptime Issues?

Since I've started to use it frequently within the last month or so, I have noticed several times where either responds very slowly or is outright unavailable. Even as I am typing this, my repeated attempts to load in another Safari tab just failed with another server error.

Has anyone else noticed this, or is it just me?

Update: Looks like they are having issues with their backend...

Thursday, October 29, 2009

Tidy Plugin Updated for Rails 2.3.4

Turns out my Tidy plugin doesn't work with Rails 2.3.4. I discovered this when I upgraded one of my apps from Rails 2.2.2 to the latest version. A quick debug session revealed and fixed the problem.

However, the change means it will no longer work with Rails 2.2.2.

Check it out here.

Monday, October 19, 2009

Announcement: Tidy Plugin for Rails

I finally put some effort and re-factored my tidy_javascripts and tidy_stylsheets helper methods into a Rails plugin to help me accomplish the following goals:

  • Ease of re-use across multiple projects

  • Learn about git and

  • Learn about authoring a Rails plugin

Check out my Tidy plugin and let me know what you think.

Friday, October 16, 2009

Unit Test: Take Two, with factory_girl + Mocha

In my day job, I occasionally interface with a group of Java developers, who pride themselves in doing a darn good job of testing their own code. We are talking about unit tests, functional tests, continuous integration tests, the whole shebang.

I learnt about mocking from them (and was the target of many such jokes, e.g. "So, here to be mocked some more?"), and decided to try out some mocking frameworks for .NET, but am having time comprehending the role of mock objects in testing. However, recently I was reading Recipe #55 in Advanced Rails Recipes, and was inspired.

So when I took my reading to the web, largely driven/led by Google, I realized that mocha is another mocking framework that some prefer over flexmock. I looked into it a bit, and decided that it is for me.

Now, like many, I have come to dislike fixtures for complex test cases where multiple instances of multiple models are involved. But I do believe that fixtures have a role. The way I look at it, if you find that you set up the same data over and over again in your tests, maybe it's time to push them into fixtures.

Anyhow, instead of using fixtures, I have been using ThoughtBot's factory_girl to create my test objects, and am loving it.

Furthermore, someone challenged me to rip out all my test code and re-write them since they are woefully out-of-date and no longer pass. But part of my failure to keep my test code fresh was due to frustration with fixtures.

So now, armed with factory_girl and Mocha, I wiped my test slate clean (removed almost all my test code and fixtures), and am starting over.

To start things off, I decided to do something akin to that recipe in the ARR book, like so:
# test/unit/project_test.rb

require 'test_helper'
require 'mocha'

class ProjectTest < ActiveSupport::TestCase

test "create" do
p =
assert p.valid?

test "use mocha to simulate failure" do
p =
assert p.invalid?

Now let's run it:
% rake test:units
----- <snipped> -----
Finished in 0.179492 seconds.

24 tests, 41 assertions, 0 failures, 0 errors
Nice! Of course I am not yet certain how mocking applies to unit tests, but I will forge ahead and see how things go.