Tuesday, July 20, 2010


I have been using Redcar this morning after hearing about it on the Ruby5 podcast.

I am pretty impressed so far. It has good support for Textmate bundles and works cross-platform. This was an important detail for me since I use OSX at home and Linux at work and it would be nice to use the same editor everywhere. I also like the fact that my editor is written in Ruby and is open source.

Using rvm, I was able to set it up pretty easily:

And then since I don't usually use jruby, I set up a quick bash function to call it:

From there I can just call rc [dir] from the command line and it opens the project.

I did have one small issue with installing the ruby-shoulda bundle. The wiki says that if you put bundles in  ~/.redcar/textmate/Bundles and delete the cache, then they should show up. However, I wasn't able to get it to work unless I put in in the system bundle directory at:  ~/.rvm/gems/jruby-1.5.1/gems/redcar-

I am pretty excited where they can take this project, and possibly even contribute to it in the future.

Monday, July 5, 2010

LDAP Authentication With Devise

I have been meaning to give Devise a try for quite a while. This weekend I was finally able to try it out. One of my requirements was to be able to authenticate against an LDAP server. There was a module already written to do this for Devise, but it was only for Rails 2.3.8 and I wanted to start new projects in Rails 3, so I set out to fork the project and re-write it as a Rails 3 gem.

Since this was my first experience with Devise, to write a gem, I spent a lot of time in the ruby debugger going line by line in Devise and Warden to see how things worked and why things were breaking, which usually turned out with me making a stupid mistake.

Eventually I was able to finish up, luckily I had already went through the process of creating a gem with a generator, so I was able to add some basic generators to make the setup process easier.

I made a quick screencast on how to setup a new Rails 3 application and use LDAP authentication:

There's still a lot to do, including locking, registrations, password changes, testing, making a single sign-on solution, and a lot more. Hopefully this is enough to get people up and running for now, though.

You can find it on the rails3 branch on github at: 

Friday, July 2, 2010

Stubbing the User Model

I've been working a lot these days on testing. I try my best to follow a TDD/BDD workflow when developing applications, but I still have bad habits left over from the PHP days where I will start working on something, realize I need something else, and then something else, and before you know it, I am way behind on tests.

Before, I was relying completely on testing with Cucumber, but after speaking to a lot of people at Railsconf, it seemed that a lot of people were using Test::Unit and Shoulda. I decided to give them a try here. I also used Factory Girl as a fixture replacement, like I had done in the past with some other problems.

The project I am working on is a host tracking system. Basically the main model is Host, and the frontline controller is HostsController.

For the Host model, I didn't do anything too outside of what is in the Shoulda README, but the controller took some work. I have a custom written authentication gem that basically just includes the recommended methods (require_user, current_user, logged_in?, etc..) into ApplicationController or whichever controller that needs them, since I am aiming for a single-sign-on type system, I use the same session secret for all applications, and the User model reads from a central database using a separate "establish_connection" call at the top of the model. The database is for the User model that managed through another application.


I want the entire application to be protected, so I use the before filter to require a user (which looks at the current_user method), if current_user is not set to a valid User, they're redirected to the other application that will log them in and set the proper cookies using LDAP and Authlogic (this will require another post sometime.)


But since I call an external database, the User isn't getting created properly when setting up the databases for testing. I also have my own tests on the other application to validate that people are logging in properly and that everything is working there. I'd like to just make the assumption that the user is logged in. The absolute easiest way to do this, is to just use mocha to make current_user always return the Factory that was created for my user.



From there, I will be able to start building my functional tests, using different User factories (admin user, normal user, read-only user) and make sure that I am getting the proper result.