I am using freindly_id in my application. I have setup a few fixtures in my application. I want to do integration testing on them. During the tests I need the friendly_id, but the DB records created from fixtures do not ha开发者_Go百科ve the corresponding slugs in the Slug table.
Aren't the slugs automatically created from Fixture data? If not then what can be a solution?
The easiest would be to add the slug
s to the fixture data:
# test/fixtures/things.yml
apple:
title: Apple
restricted: hellyes
slug: apple
# app/model/thing.rb
class Thing << ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged
end
One solution is to run the rake task that generates the slugs, but in the test environment.
On Windows
>set RAILS_ENV=test
>rake friendly_id:redo_slugs MODEL=xxx
Or Unix/Linux
>export RAILS_ENV=test
>rake friendly_id:redo_slugs MODEL=xxx
Update The rake tasks have been removed, see comment to this answer or friendly_id README.
精彩评论