Send_file testing

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

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

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:

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

On 23 Ún, 18:41, Nick H. [email protected] wrote:

end
controller.should_receive(:send_file).with(…).and_return …
do_get
end

Cheers,
Nick


rspec-users mailing list
[email protected]://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 :confused:

Vit

On 24/02/2009, at 8:03 AM, vo.x wrote:

found.")
end
[email protected]://rubyforge.org/mailman/listinfo/rspec-users
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 :confused:

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

On 24 Ún, 17:26, Nick H. [email protected] wrote:

which
if log
Hi Vit. Just stub #send_file as normal. For example:
Cheers,
and I will get following error:
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
[email protected]://rubyforge.org/mailman/listinfo/rspec-users

Well … and how to do that? Now its starting to be interesting :wink:

Vit