How to test Rails apps without model?

Hi, I am using Rails to develop an application where I do not use a
database at all, so I have not defined a model at all, just
controllers and views. The application runs fine, but when I try to
run functional tests, it tries to connect to the database and fails
without running any of my tests.

How do I tell Rails to please not bother with databases during the
tests?

Thanks,
Arun

On 29 Apr 2008, at 05:27, arunmehta wrote:

Hi, I am using Rails to develop an application where I do not use a
database at all, so I have not defined a model at all, just
controllers and views. The application runs fine, but when I try to
run functional tests, it tries to connect to the database and fails
without running any of my tests.

How do I tell Rails to please not bother with databases during the
tests?
Don’t load the activerecord framework (There’s a thing in
environment.rb for controlling which frameworks are loaded). I can’t
remember if you still need to comment out the require of fixtures in
test_help.rb

Fred

I’ve seen some tests [such as those for the squirrel plugin] that just
create their own ‘test database’ on the fly

arunmehta wrote:

Hi, I am using Rails to develop an application where I do not use a
database at all, so I have not defined a model at all, just
controllers and views. The application runs fine, but when I try to
run functional tests, it tries to connect to the database and fails
without running any of my tests.

How do I tell Rails to please not bother with databases during the
tests?

Open config/database.yml and configure all the environments to use
sqlite3 (or
possibly less!).

On Tue, Apr 29, 2008 at 12:27 AM, arunmehta [email protected]
wrote:

Hi, I am using Rails to develop an application where I do not use a
database at all, so I have not defined a model at all, just
controllers and views. The application runs fine, but when I try to
run functional tests, it tries to connect to the database and fails
without running any of my tests.

How do I tell Rails to please not bother with databases during the
tests?

The database stuff gets pulled in by the file
railties/lib/test_help.rb which is included by test/test_helper.rb

The trick is to NOT include the test_help file, but instead copy the
lines there which don’t require active record or fixtures.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Many thanks to all the kind folk for their help. I am not opposed to
the use of databases, but for my application, i find it far more
convenient to use session[:whatever]. Instead of messing with the
standard code that rails generates, would it not be simpler to use a
database instead of session, so that I can use the standard testing
processes of Rails? Is there some way of doing this without the loss
of convenience that the session hash provides?

Great question, Robert, about why use Rails at all. Here is an
incomplete set of reasons:

  1. I teach computing, and need to very easily be able to get others to
    start using what I am. While Rails books are available at any decent
    book store in New Delhi, the Merb website http://merbivore.com/ says
    that Tutorials will be coming soon…
  2. I love the structure Rails imposes on students who are learning
    programming basics by working on my project.
  3. Ruby on Rails looks great on a resume. Very important consideration
    for my students.

I would be delighted to hear of alternatives that beat Ruby on these
considerations, while still allowing me to program in Ruby, on which
point, I am afraid, there can be no compromise :slight_smile:

Warmly,
Arun

I have no personal experience with it, but your application sounds
like a great candidate for Merb (http://merbivore.com/). If you don’t
need ActiveRecord or a database, why have all that stuff included in
your framework? Aren’t you just wasting memory?

Don’t misunderstand. I think Rails is great, but it really is designed
for database-backed applications and sort of assumes you have one.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs