July 2007
2 posts
5 tags
has_many_polymorphs and the Open/Closed Principle
I like has_many_polymorphs. I would love it if only it obeyed the open-closed principle.
Let’s say I have a PetOwner model, and I want it to have_many pets polymorphically.
has_many_polymorphs lets you do this:
class PetOwner < ActiveRecord::Base
has_many_polymorphs :from => [:dogs, :cats, :fish]
...
end
But what if I later decide I want to add a Ferret class? In addition...
5 tags
and the test_spec_on_rails Journey Continues
Test/Spec has a wonderful - if largely unnoticed - feature: you can specify the superclass of contexts. The default is the ole’ Test::Unit::TestCase, but that won’t always do.
Let’s say, hypothetically, you wanted to write some integration tests for your not-quite-shiny Rails app. You’d use ApplicationController::IntegrationTest, right? That way you can do things like get...
5 tags
test_spec_on_rails Continued...
Yesterday, I was very happy because all my controller tests (using test/spec, of course) were passing individually.
Today I decided to run rake test:functionals just to make sure they played well together. CRASH! BOOM! OTHER LOUD NOISES!
The problem, after two hours of debugging, is that I was creating the same context in different controllers. DocumentationControllerTest had an “A...