ruby - AbstractController::DoubleRenderError with my respond_to in rspec -
I've got this Rail 3 action:
DIF Export to Reply | Format | Format.tdl {Render: xml = & gt; @ Template.export_as_tdl and return} format.json {render: json = & gt; @ Template.export_as_json} End End and filter before exporting:
def find_environment @ environment = KTEnvironment.find (params [: environment_id]) Enhanced HttpErrors :: NotFound, _ ("Environment '# Parameter [: Environment_ID]}' '' can not be found if '@ environment.nil? @ End of Environment and this rspec Describe "Export" should call "Export" call "get @ tpl.should_receive (export_as_json): export, id = & gt; TEMPLATE_ID end it" export_as_tdl " Should call at @ tpl.should_receive (: export_as_tdl ) Get: export, id = & gt; TEMPLATE_ID, format = & gt; TDL & end
I have also defined the following mime type: < Pre> Mime :: Type.register "application / tdl-xml" ,: tdl When I try to run my RSPEC tests, I am constantly being :
1) Api :: TemplatesController export should call export_as_tdl Error / Error: Receive: Export, ID = & gt; TEMPLATE_ID, format = & gt; 'Tdl' AbstractController :: DoubleRenderError: Render and / or redirect was called multiple times in this verb. Please note that you can only call the render or redirect, and you can take maximum action once per operation. Also keep in mind that do not terminate the operation and do not redirect, so if you want to exit any action after the redirect, then you have to do something like "redirect_to (...) and return" ./app/controllers/api/api_controller.rb: 135: in` render_exception '# ./app/controllers/api/api_controller.rb: 133: in`render_astation' # ./app/controllers/api/api_controller.rb: 22: `` __bind_1314974553_619675 '# ./spec/controllers/api/templates_controller_spec.rb:178 I have no indication what is happening there. This is my exception rendering code:
def render_wrapped_exception (status_code, ex) logger.error "*** Error: # {ex.message} (# {status_code}) ***" Logger .error "Request URL: # {request.fullpath}" Logger. Terror pp_exception (ex.original.nil ?? east: ex. Original) orig_message = (ex.original.nil? & Amp; amp; amp; & amp; amp; amp; amp; amp; & amp; ;;;) || Ex.original.message response_to do | Format | Format.json has to render: json = & gt; {: Errors = & gt; [Ex.message, orig_message]},: Status = & gt; Status_code end is presenting format.all: text = & gt; "# {Ex.message} (# {orig_message})",: position => Status_code End End Ah so my api_controller is called the general method of render_exception. It looks like:
def render_exception (status_code, exception) logger. Terror pp_exception (exception) response_to do | Format | Format.json {Render: Jason = & gt; {: Errors = & gt; [exception. Message]} ,: position => Status_code} format.all {Render: text = & gt; exception. Message,: Status = & gt; Condition_code} End End
Try disabling your error handler, the root cause is its Of self
Comments
Post a Comment