I was using Rails 2.3.4 (2.3.10 wouldn’t do logging in as a different user for some annoying reason).

In my data model a story can have many fragments (which in turn can have many gates out)

I had an idiom where I was forcing the ID’s of things to be something I knew, so I could do things like this in my cucumber scenarios:

  Given story 1 exists
  And story 1 has fragment 1
  And I am on story 1 fragment 1
  And follow "New Gate"
  Then I should see ....

This used to work. I had a helper in my web steps that looked a bit like this:

def create_story(attribs)
  force_id = attribs.delete(:force_id)
  story = Story.new(attribs)
  story.update_attribute(:id,force_id) if force_id
  story
end

Plus a similar one for the Fragment. This doesn’t work any more, even though the update_attribute method returns true – it just doesn’t let you update it. Neither can you force the id when you create the record. This is probably a good thing, to be honest, in the general round, but for creating test data it’s a complete pain.

So, how to proceed? I was already creating the stories and fragments with titles like test story 1 anyway. So, instead I use the names of things to get what I want:

def get_story desc_id
  Story.find_by_description("test story #{desc_id}")
end
def create_story(attribs)
  Story.create!({ :audience_classification => 1, :story_classification => 1,
                  :owner_id => @current_user.id, :originator_id => @current_user.id}.merge(attribs))
end
When /^story (.*) exists$/ do |desc_id|
  @story = get_story(desc_id) || create_story(:description => "test story #{desc_id}",:narrative => "narrative for test story #{desc_id}")
end

And the same for the fragment too, finding the story by its name and then creating the fragment for it alone. This turns the scenario above into the much more natural:

  Given story 1 exists
  And story 1 has fragment 1
  And I am on the list of stories
  And I follow "test story 1"
  And I follow "test fragment 1"
  And follow "New Gate"
  Then I should see ....

Instead of jumping straight to the page where I want to test I have to do the navigation and press the named links. I think this is better in the end.