josevalim/inherited_resources — Issue #177: success/failure blocks not executing
Author: kb
Created: 2011-10-26 22:49:21+00:00
State: open

If I have an action similar to the one below... The failure block appears to never be evaluated and defaults to a 422 status code.

class FoobarController < InheritedResources::Base
respond_to: :html, :json
def create
create! do |success, failure|
success.any do
render :text => "foo"
end

failure.any do
render :text => "bar", :status => 200
end
end
end

The resulting error code is a 422 coming from this method within actionpack... lib/action_controller/metal/responder.rb

def display_errors
controller.render format => resource.errors, :status => :unprocessable_entity
end

Based on the rdoc of the Responder class, a 422 will be returned by default.

Then the response status should be 200 Created # cucumber-api-steps-c60f156fb0bf/lib/cucumber/api_steps.rb:27
expected: 200
got: 422 (using ==) (RSpec::Expectations::ExpectationNotMetError)
features/crash.feature:131:in `Then the response status should be 200 Created'

This seems to indicate that the block.call within the respond_with_dual_blocks for an object where .errors is not empty isn't evaluating correctly.