I failed to google anything about this, so I bring it here.
I’ve overrode to_param on my model to concatenate it with the id for a prettier and safer URL. I’m at a loss where this should have been in my test. It seems like putting it to a routing test misses the point. I would think that this would go in the model’s spec, though:
#my model
class MyModel < ActiveRecord::Base
def to_param
[id,an_attr.parameterize].join("-")
end
end
#my model spec
describe MyModel do
mymodel = MyModel.create!(:an_attr => "test attr")
mymodel.to_param should == [mymodel.id,"test_attr"].join("-")
end
What I get is:
Failure/Error: mymodel.to_param should == [mymodel.id,"test_attr"].join("-")
expected: "1-test_atttr"
got: #<MyModel id: nil, an_attr: nil, created_at: nil, updated_at: nil> (using ==)
A model instance…I’ve got to be missing something obvious here — maybe its just late for me—
insight greatly appreciated.
It looks like you’re missing a period after
to_param.mymodel.to_param.should == [mymodel.id,"test_attr"].join("-")