Topic: Another newbie controller question

I just started using rspec.. I was playing around with a model  I finally got that working and was expecting to have a full passing grade but instead found out that a test in my controller is failing:

  it "should map { :controller => 'users', :action => 'edit', :id => 1 } to /users/1;edit" do
    route_for(:controller => "users", :action => "edit", :id => 1).should == "/users/1;edit"
  end

The thing is I haven't changed a thing in my controller.  The only thing that's changed is that I now have a user in my database.  Here's the error:

'UsersController#route_for should map { :controller => 'users', :action => 'edit', :id => 1 } to /users/1;edit' FAILED
expected: "/users/1;edit",
     got: "/users/1/edit" (using ==)

And here's the edit function in my controller:

  # GET /users/1;edit
  def edit
    @user = User.find(params[:id])
  end

Last edited by viniosity (2007-10-19 16:53:54)

Re: Another newbie controller question

I, too, just started out with RSpec, and have run into the same sort of issue.  Upon using script/generate rspec_scaffold User, and rake db:migrating, I'm coming out with a route error as well:

1)

'UsersController#route_for should map { :controller => 'users', :action => 'edit', :id => 1 } to /users/1;edit' FAILED

expected: "/users/1;edit",

     got: "/users/1/edit" (using ==)


Havent touched the controller, or anything else.  Generated, migrated, ran autotest.

Re: Another newbie controller question

I asked around a bit in #rubyonrails, it seems the REST urls changed from ;edit to /edit .  So either our plugins are not the most recent, or rspec hasn't caught up with it?  Either way the tests it generates for that particular method in the controller are expecting the wrong outcome.

Re: Another newbie controller question

Rspec hasn't caught up with it most likely.

Re: Another newbie controller question

Radar wrote:

Rspec hasn't caught up with it most likely.

Actually URLs changed from /edit to ;edit as of Rails 1.2. So I think rspec is actually correct in expecting ;edit even though /edit will work too.  It would point to a routes issue but I haven't touched my routes file either so the default map.resources :users should give me /users/1;edit (and in fact does).

This is the thing I was afraid of with testing.. it takes more time to write your tests than it does to write your code. sad

Re: Another newbie controller question

URLs may have changed at 1.2 (I don't know the exact version they changed) from /edit to ;edit, but they have changed back again as of Rails 1.2.5. Rails 2.0 will have /edit instead of ;edit.