josevalim/inherited_resources — Issue #193: Problem with create/update namespace responders
Author: jonlhouse
Created: 2012-01-05 05:58:33+00:00
State: open

I'm trying to track down this problem with rspec testing namespaced IR controllers. I thought it could be with Responders but I've tried with an without them.

*Note*: These work in development environment in a browser it just the *test cases* that fail.

```ruby
# in app/controllers/abc/encounters_controller.rb
Abc::EncountersController < Abc::ApplicationController
inherited_resources
end
```

Here is the RSpec2 controller test (note... I'm only including one failing case. Only the update/create actions fail). These are basically the scaffold test cases.

```ruby
# in spec/controllers/abc/encounters_controller_spec.rb
describe Abc::EncountersController do
login_user # from devise -- this seems to work with the rest of my tests

describe "PUT update" do
describe "with invalid params" do
it "re-renders the 'edit' template" do
encounter = Encounter.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Encounter.any_instance.stub(:save).and_return(false)
put :update, :id => encounter.id, :encounter => {}
response.should render_template("edit")
end
end
end
```

Now the error I'm getting is `undefined method `encounter_url' for #` as its not correctly prepending the 'abc_' namespace to the redirect url.

Here is the portion of the stack trace I think is critical:
```ruby
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/instrumentation.rb:59:in `redirect_to'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/responder.rb:135:in `redirect_to'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/responder.rb:193:in `navigation_behavior'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/responder.rb:162:in `rescue in to_html'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/responder.rb:160:in `to_html'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/responders-0.6.4/lib/responders/flash_responder.rb:93:in `to_html'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/responder.rb:153:in `respond'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/responder.rb:146:in `call'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.1.3/lib/action_controller/metal/mime_responds.rb:238:in `respond_with'
# /home/jonlhouse/.rvm/gems/ruby-1.9.2-p0/gems/inherited_resources-1.3.0/lib/inherited_resources/base_helpers.rb:262:in `respond_with_dual_blocks
```

Again its only a problem in RSpec and only on POST and PUT actions that are namespaced. Thanks.