Standard test fails on RESTful controller

Hi all

I am messing around with RESTful controller using edge rails (revision
5222) and am having the following problem. I have changed the function
that is failing by adding the client name in the flasg but that it is
and I haven’t changed the test code either but I am getting this error.
The fact that “Expected” is empty makes me wonder if it is a bug in edge
rails?

—Failure message—

  1. Failure:
    test_should_create_client(ClientsControllerTest)
    [./test/functional/clients_controller_test.rb:30]:
    <3> expected but was
    <2>.

—Controller code—

def create
@client = Client.new(params[:client])

respond_to do |format|
  if @client.save
    flash[:notice] = @client.name + ' was successfully created.'

    format.html { redirect_to clients_url  }
    format.xml do
      headers["Location"] = client_url(@client)
      render :nothing => true, :status => "201 Created"
    end
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @client.errors.to_xml }
  end
end

end

—Test code—

def test_should_create_client
old_count = Client.count
post :create, :client => { }
assert_equal old_count+1, Client.count

assert_redirected_to client_path(assigns(:client))

end

Any help would be much appreciated because the perfectionist in me
refuses to commit and continue until all the tests are passing :slight_smile:

RJ

RJ wrote:

Hi all

I am messing around with RESTful controller using edge rails (revision
5222) and am having the following problem. I have changed the function
that is failing by adding the client name in the flasg but that it is
and I haven’t changed the test code either but I am getting this error.
The fact that “Expected” is empty makes me wonder if it is a bug in edge
rails?

Its not empty, it’s 3 :slight_smile:

If you take out the assert_equal, does the assert_redirectd_to work ?

A>

Alan C Francis wrote:

RJ wrote:

Hi all

I am messing around with RESTful controller using edge rails (revision
5222) and am having the following problem. I have changed the function
that is failing by adding the client name in the flasg but that it is
and I haven’t changed the test code either but I am getting this error.
The fact that “Expected” is empty makes me wonder if it is a bug in edge
rails?

Its not empty, it’s 3 :slight_smile:

If you take out the assert_equal, does the assert_redirectd_to work ?

A>

Aaaah I thought that was some sort of line numbering. I thought the
messages were “Expected FOO but was BAR”. Not “FOO expected but was
BAR”…

Crawls back into the corner.

Ok, so why isn’t it registering the new client :wink:

Thanks

RJ

Ok, so why isn’t it registering the new client :wink:

If you comment out the assert_equal, and let the assert_redirected_to
have a go, you’ll be able to see if the controller method succeeds.

I think there must also be a way to assert the contents of the flash,
which you can try as long as you comment out the assert_equal(which
stops the test in its tracks)

Alan

Whoops, that was me thinking to myself with my fingers, wasn’t actually
looking for an answer :wink:

But thanks regardless.

RJ

RJ wrote:

Aaaah I thought that was some sort of line numbering. I thought the
messages were “Expected FOO but was BAR”. Not “FOO expected but was
BAR”…

Crawls back into the corner.

Ok, so why isn’t it registering the new client :wink:

If you comment out the assert_equal, and let the assert_redirected_to
have a go, you’ll be able to see if the controller method succeeds.

I think there must also be a way to assert the contents of the flash,
which you can try as long as you comment out the assert_equal(which
stops the test in its tracks)

Alan