rake spec runs twice

October 22, 2008

If you are seeing your specs running twice, it might be because you have an extra rakefile in your project. In my case deleting lib/tasks/rspec.rake solved the problem.


October 9, 2008

If anyone is following this stuff, I’ve moved this blog over to my own domain:


That way I have more control over the presentation. WordPress.com sucks for displaying code in your blog.

login_required NoMethodError due to not including AuthenticatedSystem module

October 7, 2008

This post moved here.

Missing users method means your fixtures aren’t getting loaded

October 7, 2008

This post moved here

Restful Authentication plugin and AASM

October 7, 2008

This post moved here

Testing to see if a page exists

September 17, 2008

This post moved here

Rspec front-end

July 17, 2008

This post moved here

Psuedocode for server management scripts

May 11, 2008

Along the lines of my post on the Forkolator blog on how to set up the server architecture, I’ve written out some pseudocode for scripts that I think would handle the mongrel servers and the nginx load balancer properly:

% start_nginx
get all mongrels from database
create nginx conf
start nginx

% start_mongrels testproject production 2
mongrel start get_a_free_port()
insert mongrel
mongrel start get_a_free_port()
insert mongrel …
mark server for refresh

% start_mongrels testproject development 1

% reload_nginx (runs as a daemon)
get all mongrels from database
create nginx conf
reload nginx conf

% stop_mongrels testproject production
find the mongrel processes
kill them
remove them from the database
mark the server for refresh

How to get Gitorious running on your own server

May 11, 2008

This is everything I’ve figured out so far about how to get Gitorious up and running on your own server. It’s not everything yet, but it’s a lot of stuff.

OK, so first you want to install the dependencies. I think this are all of them, assuming you’ve installed the basic rails stuff:

apt-get install librmagick-ruby libonig-dev
gem install mime-types oniguruma textpow chronic BlueCloth

Then make a place for Gitorious and download the code:

mkdir /path/for/gitorious; cd /path/for/gitorious
git clone git://gitorious.org/gitorious/mainline.git  
cd mainline

It’s a good idea at this point to read the HACKING file for informational purposes.

The next thing we need to do is create a git user. This will be the user that gets used for SSH connections, running the task queue, and servering the repositories over HTTP:

adduser git

Once we’ve created a user, we can create a place for your git repositories. It has to be owned by the git user, and if you want people to be able to clone over HTTP, it has to be web-accessible. That means your web server has to be running as the git user:

mkdir /path/to/repos
chown git:git /path/to/repos

You are going to need to add your database settings and gitorious configuration. Start with:

cp config/gitorious.sample.yml config/gitorious.yml
nano config/gitorious.yml;

… and put in the necessary info. Next put in the database information:

cp config/database.sample.yml config/database.yml
nano config/database.yml

I called my databases gitorious_development, gitorious_production, and gitorious_test, and I set up a gitorious user in mysql with a fancy password. At this point you want to create the development databases, and then you can start the server:

rake db:migrate

You should now have the gitorious app running on http://localhost:3000 or wherever you specified in gitorious.yml. Give it a look in your web browser. If you want the server to run in the background, kill the current process (CTRL+C) and then run:

nohup script/server &

That will start the server up in a separate process and spit the output into nohup.out. You can try creating a user account through the web interface. If you don’t get an activation email, there’s something screwy with your mail server. I had to patch Gitorious to use a SMTP server, but that’s a separate post. As a workaround, just go into your gitorious_production database, find your account in the users table, and copy the date in the “created_at” column into the “activated_at” column.

Now you should be able to log in, create a project, and add your SSH public key to your profile. Unfortunately, Gitorious is going to tell you that your key and your project are being created, but they won’t get created without some more intervention.

In order to create the keys and the repositories, you have to set up a separate process that does those tasks regularly. Gitorious has a script set up for this purpose in script/task_performer. Go ahead and run that script, making sure that you run as the “git” user and that you set the correct rails environment. So if you are working in the development environment, run:

su git
RAILS_ENV=development script/task_performer

That will create the repositories and add the keys to /home/git/.ssh/authorized_keys. The authorized_keys file also specifies that before users can be authenticated for git push over SSH, the command “gitorious blah” needs to run (where blah is the users’s username). Except there is no gitorious command in the git user’s path. So let’s link it up:

ln -s RAILS_ROOT/script/gitorious /bin/gitorious

Now if you return to Gitorious, you should see that your keys and repositories have been created. You may want to stick that task_performer script in a cron job… or write a little script that will run it repeatedly in the background.

At this point, you should be able to do a git push (which goes over SSH) and a git clone over http, assuming your repositories are in a web accessible folder. In order to do git clones, you have to start the git daemon. Gitorious has a script for this, but again make sure to run as the git user:

su git
nohup script/git-daemon &

And now you should be able to do git:// clones too.

What’s left to do:

  • I haven’t configured ultrasphinx, so search doesn’t work.
  • I haven’t set up script/graph_generator, so there are no graphs.
  • I have no idea what script/fixup_hooks does. It might be important.

Thanks pygi and teknofire in #gitorious on irc.freenode.net for helpful pointers. Thanks Johan for guidance on getting ssh working correctly for git push.

How to slice up tests

May 7, 2008

One of the hardest things about test driven development is choosing how to slice up your tests. Do you do unit tests (trying to isolate one unit of code) or integrating tests (checking to see that it all works together to lead to some positive outcome)?

I guess you do both, but I still don’t have good instincts about what to do when. Zach Dennis responded to a post I sent to the rspec-users mailing list giving me some good advice about the test I wrote about here.

I’m starting to think my first test should really be to send an email and then see if it got there. Unfortunately, email takes minutes to deliver, and how long should the test suite wait? Maybe I should just give up on testing this component.