Showing posts with label Rails. Show all posts
Showing posts with label Rails. Show all posts

Thursday, July 17, 2008

Use blank fixtures for Bj tables when testing with Bj

I have an integration test where I need to test a web process that starts a background process with Ara T Howard's awesomely named Bj plugin (Background Job - but never has overhearing talk about Rails testing cause so many funny looks and stifled laughs).

I found some great notes here: http://robsanheim.com/2008/07/10/notes-on-testing-bj-background-job/ which show how to wait for a job to finish during a test.

One problem I ran into, though, was that I somehow had a bad job that got stuck in the testing database table, and that was messing up testing results because Bj would wake up during the test, see the old bad job, and resubmit it. It took a while to track that down.

I fixed it by simply putting blank fixtures in test/fixtures for each of the Bj tables: bj_config, bj_job, and bj_job_archive. That way Bj starts from a blank slate when each test starts. There's a Bj protip for you. Another one is to watch the Bj logs for the test environment.

Thursday, September 27, 2007

"Rails", "Fails", and other controversial words that rhyme

I'd like to welcome a new member to the EffectiveUI team. Simon Horwith is a great addition, and he's going to be working on some great enterprise and government projects with us, as well as helping with training. I'm glad to have him around.

But, I couldn't let one of his latest blog post pass. He titled his post 'Rails Fails' for no reason that I can see. The original post about which his post was written is called '7 Reasons I switched back to PHP', and has made the rounds lately. I see nothing in that post about Rails failing qua Rails, so I can only assume that 'Rails Fails' was a title to stir the pot a little bit.

Here's my take on the original article: Derek's post boils down to two points that I can see:

  1. CD Baby had an existing data model and a lot of php code already in place.
  2. What CD Baby really needed was some solid refactoring, not a change of tools.
Rails is best when you're building from the ground up, because then you get to enjoy the benefits of the opinions of the creators instead of shoehorning a pre-defined structure into a Rails wrapper. Trying to migrate to Rails to get Rails benefits without having access to fundamentally change the processes and structure involved is scary to me. I'm not quite sure if that was what was happening with CD Baby, but it sounds like it.

It's never a good sign when someone says "All of our problems will be solved if we just change tools". That's never the case. It's a corollary to the old saw "If all you have a is a hammer, everything looks like a nail".

Derek is completely right to say that there's nothing Rails can do that PHP can't. That's the whole point to get from his article, not that Rails failed in any way. I'm glad he said at the end that if he were building a project from the ground up, he'd give Rails another go, because that's the place for it.

Rails isn't a tool to make your existing application easier to develop, nor is it just an ORM to throw on top of an existing data structure. Rails is a framework, a platform, and a set of opinions on how to apply those tools to a problem domain. No matter what the language (for the most part) those opinions can be applied to make development better in whatever environment you choose, and I think that's what Derek took away from his foray into Rails. I hope that's what everyone else takes away from it, too, and not some sort sense that Rails failed CD Baby, and could fail you too.

Thursday, September 6, 2007

export instead of checkout in Capistrano 2

A quick PSA: In capistrano 2 there's a change to the way you get svn to export instead of checkout during a deploy.

Old way:

set :checkout, 'export'


New way:

set :deploy_via, :export

Saturday, August 25, 2007

Flex and Rails Dates

I'm not sure how I didn't run into this before, but I had some trouble parsing and dealing with dates coming from Rails' to_xml rendering of an object in Flex.

The dates were coming back looking like this: 2007-08-29T23:18:07-06:00, which I'd never seen before. I've found out since that it's in the W3C date time format.

Luckly for me, I found that the as3corelib has just what I needed: a DateUtil.parseW3CDT and DateUtil.toW3CDTF method.

If you're passing dates back and forth between Flex and Rails, at least with xml, you may want to check the corelib out, but make sure you look at it anyway.

Friday, July 27, 2007

has_many, finder_sql, and id

Jeez, has it been almost a month since my last post? Time flies when you're a lazy good for nothing.

Anyhow, since It took me some little while to track down this weirdness in rails, I thought I'd give back to the tribe and list the solution here too.

In Rails, you can specify model relationships with cool "macro" methods like 'has_many' and 'belongs_to'. If there is a fairly specific relationship you want to add to a model sometimes you may need to tell rails to just go ahead and use a query instead of the magic. Then you can specify 'finder_sql':


has_many :outstanding_invitations,
:class_name => 'FriendRecord',
:finder_sql => "select * from friend_records
where friend_id = #{id}
and invitation = true"


That's what I started with, but couldn't figure out why I wasn't getting what I wanted, and also getting a deprecation warning: "warning: Object#id will be deprecated; use Object#object_id". After a search I found this article, which has a good tip and the answer. The answer is that #{id} was being "expanded" once it was parsed, so by the time it got to the database it was already the object id, not the active record id. To fix, change the quotes to single quotes or use the %q quote delimiter to stop the id from being expanded.

Wednesday, June 20, 2007

See me at MAX

Hey all, and welcome to the brand new Hill of Beans 2.0, upgraded from 1.0 This is the first post. I hope you like it.

So, it's official! I'm confirmed as an Adobe MAX speaker, talking about the societal and physiological benefits of using Flex with Rails. The basic gist will be: unless you have some fairly complex enterprise use cases that cry for LiveCycle Data Services, or someone else is choosing your system back end and you have no say, you should be choosing Rails.

Rails values getting things done, and you'll feel how true that is to the very core of your being when you use it for the first time.

I'm excited to talk at MAX. What a great opportunity for a rookie speaker. I hope I can get some folks on board with using Rails and help get rid of this stupid stigma it seems is forming that Rails guys hate Flash. Silly. We'll fix it by getting Flex guys to love Rails and making more Rails guys that use Flex by this proven method.