I am trying to test that a field is being generated properly by a callback, but I can't figure this one out.
album.rb
before_create :generate_permalink
private
def generate_permalink
@title = album.downcase.gsub(/\W/, '_')
@artist = artist.downcase.gsub(/\W/, '_')
self.permalink = @artist + "-" + @title
end
album_test.rb
test "should return a proper permalink" do
album = Album.new(:artist=>'Dead Weathers', :album=>'Primary Colours')
album.save
assert_equal "dead_weathers-primary_colours", album.permalink
end
But this doesn't work because album.permalink won't return the value if its saved.
Is there a way to test a before_create? Should I be doing this at the controller level?