On 24 Ún, 17:26, Nick Hoffman <n...@deadorange.com> wrote: > On 24/02/2009, at 8:03 AM, vo.x wrote: > > > > > On 23 Ún, 18:41, Nick Hoffman <n...@deadorange.com> wrote: > >> On 22/02/2009, at 3:34 PM, vo.x wrote: > > >>> Hello all, > > >>> Is there some best practice how to test Rails controller action > >>> which > >>> is using send_file method? Could you help me please? > > >>> Vit > > >> On 23/02/2009, at 2:43 AM, vo.x wrote: > > >>> Just to be clear, this is how the action looks: > > >>> def download > >>> log = ActivityLog.find(params[:id]) > >>> if log > >>> send_file log.path > >>> else > >>> flash[:notice] = _("Log file \"#{params[:id]}\" was not > >>> found.") > >>> redirect_to :action => 'index' > >>> end > >>> end > > >>> Vit > > >> Hi Vit. Just stub #send_file as normal. For example: > > >> before :each do > >> controller.stub!(:send_file).and_return ... > >> end > > >> it "should send the requested file" do > >> controller.should_receive(:send_file).with(...).and_return ... > >> do_get > >> end > > >> Cheers, > >> Nick > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > Hello Nick, > > > Thank you for your feedback, but your solution has one problem which > > actually led me to this question. If I will stub the send_file method > > as you recommend, then later on is automatically called render method > > and I will get following error: > > > ActionView::MissingTemplate in 'LogsController handling GET /logs/ > > test.log/download should find the log requested' > > Missing template logs/download.erb in view path app/views > > > So there has to be set somewhere some flag, or provided some > > meaningful response ... Im out of ideas :/ > > > Vit > > G'day Vit. ActionController is trying to render a view template for > your "download" controller action because ActionController does that > automatically. If you don't want anything to be rendered, you need to > tell ActionController that. > -Nick > _______________________________________________ > rspec-users mailing list > rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Well ... and how to do that? Now its starting to be interesting ;) Vit _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users