Hello everybody! Im wondering what is the best way of specing action with send file such as: 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 You can see that the ActivityLog class is not inherited from AR and the path dependes on specified ID. Thank you in advance. Vit
On Fri, Feb 20, 2009 at 5:45 PM, vo.x <v.ondruch at gmail.com> wrote:> Hello everybody! > > Im wondering what is the best way of specing action with send file > such as:I''d probably do it on two fronts. On the unit test level, you can stub it in your setup so that it won''t try to send that file every time you run tests, then mock it in one particular spec with "[yourcontroller].should_receive(:send_file).with([your params])" to make sure it''s getting called with the right values. In your integration tests (with RSpec or Cucumber or Selenium or trained gerbils or whatever), have it actually send the file. Then, if you''re using RSpec or Cucumber with Webrat, you can check the response object to make sure it has the right length, the right content-type, and if you want to be thorough, do a checksum on the body to make sure the right stuff was sent. If you''re using Selenium, life''s even better: you can look to make sure that the file showed up in your Downloads directory (set your browser to not prompt you on that file type first) and checksum the actual file as it was actually saved. Does that make sense? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org
On 23 ?n, 17:30, Stephen Eley <sfe... at gmail.com> wrote:> On Fri, Feb 20, 2009 at 5:45 PM, vo.x <v.ondr... at gmail.com> wrote: > > Hello everybody! > > > Im wondering what is the best way of specing action with send file > > such as: > > I''d probably do it on two fronts. ?On the unit test level, you can > stub it in your setup so that it won''t try to send that file every > time you run tests, then mock it in one particular spec with > "[yourcontroller].should_receive(:send_file).with([your params])" to > make sure it''s getting called with the right values. > > In your integration tests (with RSpec or Cucumber or Selenium or > trained gerbils or whatever), have it actually send the file. ?Then, > if you''re using RSpec or Cucumber with Webrat, you can check the > response object to make sure it has the right length, the right > content-type, and if you want to be thorough, do a checksum on the > body to make sure the right stuff was sent. > > If you''re using Selenium, life''s even better: you can look to make > sure that the file showed up in your Downloads directory (set your > browser to not prompt you on that file type first) and checksum the > actual file as it was actually saved. > > Does that make sense? > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-usersAha, it seems that there is difference between behavior of Rails 2.1 and 2.3. In Rails 2.1 stubbing works like a charm but it fails with Rails 2.3 :/ Vit
On Wed, Feb 25, 2009 at 8:20 AM, vo.x <v.ondruch at gmail.com> wrote:> Aha, it seems that there is difference between behavior of Rails 2.1 > and 2.3. In Rails 2.1 stubbing works like a charm but it fails with > Rails 2.3 :/That''s a very general statement. Can you be more specific? What version of rspec are you using? Are you using rspec''s mock/stub framework? What sort of failure messages do you get?
On 25 ?n, 16:18, David Chelimsky <dchelim... at gmail.com> wrote:> On Wed, Feb 25, 2009 at 8:20 AM, vo.x <v.ondr... at gmail.com> wrote: > > Aha, it seems that there is difference between behavior of Rails 2.1 > > and 2.3. In Rails 2.1 stubbing works like a charm but it fails with > > Rails 2.3 :/ > > That''s a very general statement. Can you be more specific? What > version of rspec are you using? Are you using rspec''s mock/stub > framework? What sort of failure messages do you get? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-usersHello David, I''m using rspec-rails 1.1.12, I''m using just rspec''s mock/stub framework. With Rails 2.3 RC1 I experienced errors such as: 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 Of course this template was not found since it is not necessary for normal app run. With Rails 2.1 the same spec passes. Vit
On Thu, Feb 26, 2009 at 7:13 AM, vo.x <v.ondruch at gmail.com> wrote:> On 25 ?n, 16:18, David Chelimsky <dchelim... at gmail.com> wrote: >> On Wed, Feb 25, 2009 at 8:20 AM, vo.x <v.ondr... at gmail.com> wrote: >> > Aha, it seems that there is difference between behavior of Rails 2.1 >> > and 2.3. In Rails 2.1 stubbing works like a charm but it fails with >> > Rails 2.3 :/ >> >> That''s a very general statement. Can you be more specific? What >> version of rspec are you using? Are you using rspec''s mock/stub >> framework? What sort of failure messages do you get? >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > Hello David, > > I''m using rspec-rails 1.1.12, I''m using just rspec''s mock/stub > framework. > > With Rails 2.3 RC1 I experienced errors such as:rspec-rails 1.1.12 does not support rails 2.3 Please use the latest source from github http://wiki.github.com/dchelimsky/rspec/rails-230> > 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 > > Of course this template was not found since it is not necessary for > normal app run. With Rails 2.1 the same spec passes. > > Vit > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Uhh, sorry ... I will give it a try! Thank you for your help. Vit On 26 ?n, 15:29, David Chelimsky <dchelim... at gmail.com> wrote:> On Thu, Feb 26, 2009 at 7:13 AM, vo.x <v.ondr... at gmail.com> wrote: > > On 25 ?n, 16:18, David Chelimsky <dchelim... at gmail.com> wrote: > >> On Wed, Feb 25, 2009 at 8:20 AM, vo.x <v.ondr... at gmail.com> wrote: > >> > Aha, it seems that there is difference between behavior of Rails 2.1 > >> > and 2.3. In Rails 2.1 stubbing works like a charm but it fails with > >> > Rails 2.3 :/ > > >> That''s a very general statement. Can you be more specific? What > >> version of rspec are you using? Are you using rspec''s mock/stub > >> framework? What sort of failure messages do you get? > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > Hello David, > > > I''m using rspec-rails 1.1.12, I''m using just rspec''s mock/stub > > framework. > > > With Rails 2.3 RC1 I experienced errors such as: > > rspec-rails 1.1.12 does not support rails 2.3 > > Please use the latest source from github > > http://wiki.github.com/dchelimsky/rspec/rails-230 > > > > > 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 > > > Of course this template was not found since it is not necessary for > > normal app run. With Rails 2.1 the same spec passes. > > > Vit > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users