I have a model, and according to the friendly_id gem, it looks like this:
class FinancialYear < ApplicationRecord
extend FriendlyId
friendly_id :slug_candidates, use: :slugged
def slug_candidates
[
:end_year,
[:end_year, :max_id]
]
end
def should_generate_new_friendly_id?
self.slug.blank? || self.year_changed?
end
def end_year
if !self.year.nil? && self.year.length > 1
self.year.split('-')[-1].strip
else
self.year
end
end
def max_id
FinancialYear.where(year: end_year).count + 1
end
end
What he had to do was to include the year: β1999-2000β in the pool: β2000β and 2000-2 ... etc. to avoid collisions.
Unfortunately, my tests did not materialize: "2000", received: "2000-f7608e8b-a2e7-449c-ae54-4785c7a68dec"
I use friendly_id on a different model in my application, and I use the same technique, and its work is excellent. Any help or suggestions as to why this does not work would be greatly appreciated.
UPDATE
After several experiments, I found that this seems to only happen in my rspec tests, but I donβt understand why? Any thoughts?