# How to test Rails apps without model?

**URL:** <https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138>\
**Category:** Rails\
**Created:** [April 29, 2008, 10:15am UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138 "2008-04-29T10:15:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 29, 2008, 10:15am UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/1 "2008-04-29T10:15:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 29, 2008, 10:46am UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/2 "2008-04-29T10:46:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 29, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/3 "2008-04-29T18:59:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 29, 2008, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/4 "2008-04-29T19:38:15Z")

</div>

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!).

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 30, 2008, 2:13am UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/5 "2008-04-30T02:13:09Z")

</div>

On Tue, Apr 29, 2008 at 12:27 AM, arunmehta [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 30, 2008, 9:58am UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/6 "2008-04-30T09:58:04Z")

</div>

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/](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 🙂

Warmly,  
Arun

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [April 30, 2008, 2:26am UTC](https://www.ruby-forum.com/t/how-to-test-rails-apps-without-model/136138/7 "2008-04-30T02:26:36Z")

</div>

I have no personal experience with it, but your application sounds  
like a great candidate for Merb ([http://merbivore.com/](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.
