Your are here: Home // Posts Tagged With models
ActiveRecord Observers
Podcast: Play in new window
| Download
About a month ago, I talked about ActiveRecord Callbacks. Observers are a way of moving callbacks out of the Model. Usually this is done to adhere to the Single Responsibility principle. So, for example, programmers will move sending an email when a record is updated or created to an Observer.
class UserObserver < ActiveRecord::Observer
def after_create(user)
...
ActiveRecord Callbacks
Podcast: Play in new window
| Download
You can get a full list of the ActiveRecord callbacks here.
Callbacks are a handy way of insuring specific behaviors on your models as well as managing the events that follow the callbacks.
For example, a before_destroy callback can be called to destroy associated objects. (This is best done on the association with :dependent => :destroy, but it makes...
005 RC Testing Tools for Rails
Podcast: Play in new window
| Download
There are a lot of tools for testing Rails. Here are links to several of the ones mentioned in this podcast.
Test Unit
RSpec
Cucumber
Mocha
Flexmock
Factory Girl
You can find my interview with David Heinemeier Hansson here, and my response to his comments on Twitter here.
Finally, here are a few other resources for you to get started with testing Ruby on...
Tags: bdd, cucumber, factorygirl, flexmock, integration tests, mocha, models, rspec, ruby on rails, tdd, testing, testunit, unit tests
003 RC Single Table Inheritance (STI)
Podcast: Play in new window
| Download
Single Table Inheritance is a slightly advanced topic in Ruby on Rails. It stems from class inheritance, which is a core Object Oriented Programming principle.
In Ruby, if you inherit one class from another, you use the ‘<’ operator. Here’s an example:
class Truck < Car
end
In Rails, this gets tricky because when inheriting a Model,...

