[rspec-users] ActiveRecord::RecordNotFound error Cucumber/Webrat

Andrei Erdoss erdoss at gmail.com
Wed Nov 26 06:04:46 EST 2008


I am bit new to Cucumber and Webrat and I have one issue that I can't seem
to fix on my own. I would appreciate your help.

I have a controller called places and a model called Place. I use the
acts_as_tree plugin in order for a place to have more places within it. Ex.
Georgia would have Cobb County, Cobb County would have Smyra City.

This is how my controller looks for adding  a new place:

# loading the parent place
before_filter :load_parent_place, :only => [:new, :create]
def load_parent_place
    @parent_place = Place.find(params[:parent_id])

 # GET /places/new
  def new
    @place = @parent_place.children.create

    respond_to do |format|
      format.html # new.html.erb

  # POST /places
  def create
    @place = @parent_place.children.create(params[:place])

    respond_to do |format|
      if @place.save
        flash[:notice] = 'Place was successfully created.'
        format.html { redirect_to(@place) }
        format.html { render :action => "new" }

I have created the cucumber feature also, but it errors out:

 Scenario: Register new place
    Given I am on the new place page with parent place "Georgia"
    When I fill in "Name" with "Atlanta"
    And I press "Create"
    Then I should see "Atlanta"

For the first line starting with "Given", I tried to put this step, but it
errors out with Couldn't find Place with ID=1 (ActiveRecord::RecordNotFound)

Given /I am on the new place page with parent place "(.*)"/ do |name|
  visits "/places/new?parent_id=1"
  Place.create! :name => name, :parent_id => 1

What am I doing wrong or how should I proceed with writing these steps for
this action?

Thank you,

Andrei Erdoss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/e2e74052/attachment.html>

More information about the rspec-users mailing list