Trouble writing to db in test

I am having trouble testing the following controller method which takes
an xml_http_request to create a new User object:

class ClientsController < ApplicationController

def create_user
@client = Client.find(params[:id])
user = User.new(params[:user])
user.client_id = @client.id
if user.save
@new_user = user
return if request.xhr?
render :partial => ‘users’
end
end

The create_user method is called from the ‘show’ page. On the first line
of the test, I confirm that I am on the ‘show’ page. On the second line
I feed in the xml_http_request to create a new User object:

class UserStoriesTest < ActionController::Integration Test

fixtures :clients, :users

def test_create_user
    assert_template 'show'
    xml_http_request 'clients/create_user', :id => 1, :user => {

:name => ‘David’, :email => ‘[email protected]’, :password => ‘ruby’}
end

The test passes without any errors, but no new User is created in the
test database. What might be preventing this? Is it possible to write
new data to the test db with fixtures already there?

Thanks,

Peter

UPDATE:

I’ve discovered that this issue is not unique to this controller method.
I’m not able to write to my test database at all with anything other
than fixtures. I’m positive I’ve executed other methods (as evidenced by
files they alter) that create new rows in the development and production
db when tested manually, but not in test db with any integration test.
Any ideas?

On 2 Nov 2007, at 20:37, Peter M. wrote:

The test passes without any errors, but no new User is created in the
test database. What might be preventing this? Is it possible to write
new data to the test db with fixtures already there?

Are you checking your database after the test has run ? tests are
wrapped in a transaction which is rolled back at the end of the test-
changes to the db made by the test don’t persist (and depending on
your db settings probably aren’t visible to other connections to the
databases).

Fred

Frederick C. wrote:

Are you checking your database after the test has run ? tests are
wrapped in a transaction which is rolled back at the end of the test-
changes to the db made by the test don’t persist (and depending on
your db settings probably aren’t visible to other connections to the
databases).

Fred

I am checking the test database after the test is run. If changes to the
test db are rolled back after the test, that would certainly explain it.
I see can validate the existence of the ‘event’ objects created by using
assert_not_nil(Event.find()) in my integration test. Thanks for
clarifying this Fred :slight_smile: