Hands-on Test-Driven Development - Using Ruby, Ruby on Rails, and RSpec


 Page 48 (Chapter 6)

Reference: chapter06/app/models/page.rb#L19

The make_slug method is missing an early return guard clause. This is needed for when the title is nil. It should be:

def make_slug
  return unless title

  self.slug = title
                .gsub(/[_ ]/, '-')
                .gsub(/[^-a-z0-9+]/, '')
                .gsub(/-{2,}/, '-')
                .gsub(/^-/, '')

 Reported on 2023-12-31 by Hiroaki Satou