I am trying to verify that a field is being generated properly by a callback, but I cannot figure out what it is.
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 does not work, because it album.permalinkwill not return the value if it is saved.
Is there any way to check a before_create? Should I do this at the controller level?
source
share