Gavin Morrice

is a web and iOS developer from Edinburgh, Scotland.

more about me ยป

Installing riaksearch on OS X Lion (10.7)

I've spent the day trying to install erlang on OS Lion and also to install Riak Search - quite frustrating to say the least.

The installation instructions on the basho site don't seem to work as they link to a tar ball that doesn't seem to exist.

Here's how I managed to install RiakSearch on OS Lion:

$ curl -O http://downloads.basho.com/riak-search/riak-search-0.14/riak_search-0.14.0-osx-i386.tar.gz
$ tar xzvf riak_search-0.14.0-osx-i386.tar.gz

The tar ball is precompiled so you should be able to test if it worked simply by typing:

$ riak_search-0.14.0-osx-i386/bin/riaksearch start

Note - that the time of writing, the latest version is 0.14.0. You can check for the latest version by looking in the riak downloads directory

Hope that helps.


Installing Erlang on Mac OS X Lion (10.7)

If you've just upgraded to Mac OS Lion, you might have a little trouble installing erlang.

If you're like me, and would rather not spend an entire day compiling code, try running these steps below. Note, this should be run on a freshly unpacked tar ball as Erlang's make clean doesn't clean everything properly.

# download the tar ball
$ wget http://erlang.org/download/otp_src_R13B04.tar.gz

# unpack the tar ball
$ tar zxvf otp_src_R13B04.tar.gz

# cd to the directory 
$ cd otp_src_R13B04

# This will prepare the Makefile
$ CFLAGS=-O0 ./configure --prefix=/usr/share/erlang --enable-threads --enable-darwin-64bit

# Compile and install
$ make && sudo make install

Now, add the following to ~/.bash_profile:

# For erlang
# I was told to add this by Gavin Morrice: http://gavinmorrice.com/blog_posts/12
ERLANG_HOME=/usr/share/erlang
export PATH=$PATH:$ERLANG_HOME/bin

Save .bash_profile and then run:

$ source ~/.bash_profile

You can check that Erlang is now working with the shell command erl


How to write a controller spec for a Rails 3.1 Engine

This week I've been building a Rails gem which mounts as an engine.

When I started to spec out the controllers I kept hitting ActionController::RoutingErrors telling me that no route matches the controller and action I was testing.

I knew this had to be a problem within my specs or with Rspec itself because routes worked fine in the browser.

On poking around the Rails ActionDispatch::Routing code I discovered the :use_route option.

Applying this to the controller specs was the fix I was looking for!

Here's a quick demo:

# in my_gem/spec/controllers/my_gem/my_controller.rb
require "spec_helper"

# Where MyGem is the namespace I've isolated my Gem under
describe MyGem::MyController do

  describe "GET /index" do

    # get the index action
    def do_get
      # :my_gem should be the name of your engine
      get :index, :use_route => :my_gem
    end
    it "should not raise an error when I try a simple GET request!" do
      lambda { do_get }.should_not raise_exception
    end

  end

end

If you have any interesting Rails 3.1 engines that you're working on, leave a comment with a link below :)