Skip to content
Andrew White edited this page Feb 11, 2014 · 1 revision

What are the parts of Rails?

Q: What are the components of Rails? Where do I find things?

A: The actionmailer directory contains the ActionMailer library code. It is in charge of sending out emails. If you need to deal with emails, look there.

The actionpack directory contains the ActionPack library. It is in charge of routing requests to the correct controller. It also contains the request and response class, as well as the controller base class that applications subclass.

The actionview directory contains the ActionView library. ActionView is in charge of templating. It contains logic for assembling HTML responses from templates.

The activerecord directory contains the ActiveRecord library. ActiveRecord is the ORM that ships with Rails. It is in charge of interfacing with the database, defining the schema inside Rails, etc. When you need to deal with data persistence, this is where you look.

The activemodel directory contains the ActiveModel library. ActiveModel is just an interface. ActiveRecord implements that interface. You shouldn't have to deal with ActiveModel much at all.

The activesupport directory contains the ActiveSupport library. ActiveSupport extends the Ruby language with things that make developing web applications easier. If you see a method that is non-standard Ruby, it is probably defined in ActiveSupport.

The railties directory contains "Railties". The code in here is in charge of tying together an application. It processes configuration, rake tasks, and managing startup of the application.

How do I run tests?

Q: I would like to run all tests? How do I do that?

A: You can run rake test from the rails directory to run all tests. If you need to focus on ActionPack, just cd to the actionpack directory and run rake test. This is true for each component besides ActiveRecord.

How do I run ActiveRecord tests?

Q: I would like to run the AR tests. How do I do that?

A: You can run all AR tests by running rake test, but this will run the tests for each database. If you want to run just the SQlite3 tests, do rake test_sqlite. If you want to run the mysql tests, do rake test_mysql, etc.

How do I run just one test file?

Q: I would like to run just one file. How do I do that?

A: There are two ways to do it. One with just plain ruby like this:

ruby -I lib:test test/path/to/testfile.rb

The other is with rake like this:

rake test TEST=/test/path/to/testfile.rb

How do I run just one testcase?

Q: I would like to run just one file. How do I do that?

A: Provide the -n flag along with the method name, like this:

ruby -I lib:test test/path/to/testfile.rb -n test_sometest

or like this:

rake test TEST='/test/path/to/testfile.rb -n test_sometest'