rails

How to reindex a Radiant CMS site running solr

For a rails app, you just need to run:

rails sunspot:reindex

But this finds models in the app/models folder and a Radiant CMS site does not have this folder. To tell sunspot which models to reindex you can do this:

rake sunspot:reindex[100,ArticlePage]

This will reindex ArticlePage objects, 100 at a time. You may also want to reindex other objects.

Cucumber tests failing – looked like it was using a different database

Just spent the morning tracking down an issue where a number of our cucumber tests were failing to find the database in the state that I had just set up with my step definitions.

For example, I had a step definition:

Given /I have (\d+) servers$/ do |num_servers|
  UI::Server.delete_all;
  num_servers.to_i.times {Factory.create(:server)}
end

When the browser visited the page after this code had run, it still saw the “server” records from the fixtures instead of the factory generated record.  I checked the database connections, and even put debugging code into the step above to confirm the records that were in the database.  The debugging output matched the step definition, but the browser didn’t.  I confirmed visually by using the Selenium WebDriver that it was still seeing fixture records.

I bit of googling and I found a page discussing Browsers and Transactions – I remember reading and fixing this once before, but a quick check of the features/support/env.rb file showed that my “fix” had been changed.

The line:

DatabaseCleaner.strategy = :transaction

won’t work as any change to the database done inside a step will not be seen by the web browser.  A quick change, resetting this back to:

DatabaseCleaner.strategy = nil

and all tests working again.

Of course, this all would have much easier to track if this company had automated testing and a decent version control system, but that’s a topic for another post.

Facebook and Rails

Ok, so I thought of developing a Facebook application using Rails and kind of assumed that there’d be some fantastic library that just did all the hard work leaving me to write the app.

It seems there are a number of attempts to develop a ruby library for Facebook but finding one that is still active and useful wasn’t easy.

A quick roundup of what I found (mostly via google).

Facebooker – This seems to be the one that is recommended and there’s a book on Peepcode although it’s been said that it expects your entire app to be a facebook app.

RFacebook – The author says “I may cease development on RFacebook in favor of Facebooker”

Giant Robots useful article (one of the most recent I found!)

Facebook on Rails – The author (Hoan) has discontinued support for this plugin.

Facetime – for adding to an existing system with a User model

SocialonRails – Nothing at all at their repository: http://code.google.com/p/socialonrails/

After some attempts at using these, I’m going to proceed down the path of using Facebooker.  The docs indicate that there is an “excellent” tutorial at http://apps.facebook.com/facebooker_tutorial but it is out of date to say the least.  So perhaps I’ll write one while I’m developing an app.