Ruby Forum Test > Basic integration testing question

Posted by Peter Marks (petermarks)
on 14.10.2007 10:54
I'm new to testing and am having trouble testing a controller method
that creates a row in a table. The method create_barnumber creates a new
barnumber object and saves it:

class AttorneysController < ApplicationController

  def create_barnumber
    @attorney = Attorney.find(params[:id])
    barnumber = Barnumber.new(params[:barnumber])
    barnumber.attorney_id = @attorney.id
    if barnumber.save
      @new_bar = barnumber
      return if request.xhr?
      render :partial => 'bar_numbers'
    end
  end

This method functions fine in practice. The following integration test
logs into the system, accesses the attorneys controller 'show' page,
then creates a new barnumber:

require "#{File.dirname(__FILE__)}/../test_helper"

class UserStoriesTest < ActionController::IntegrationTest
  fixtures :users, :firms, :attorneys

  def test_attorneys_show_page
    post 'login/login', :name => 'user', :password => 'secret'
    get 'attorneys/show', :id => 1
    assert_template 'show'
    xml_http_request '/attorneys/create_barnumber', :id => 1, :barnumber
=> { :state_id => 38, :number => '5555' }
  end
end

The test executes without and errors or failures, but there is no new
row created in the test database. What might be prohibiting this?