私はFriendlyId
宝石を使用していますが、レコードが保存されるとスラグが生成されます。それはうまくいきます。
次のようにスラッグにルーティングできます: places/house-of-dead
、完璧です。しかし、テストに関しては問題があります。
作成するパラメーターをスタブ化するために使用FactoryGirl
していますが、生成されたスラッグを取得して、ルートがリダイレクトされるかどうかをアサートする方法がわかりません。テストは以下と ( ???? should be the generated slug
).:
context '#create' do
it 'should redirect to place after created' do
place = FactoryGirl.attributes_for(:place)
post :create, { place: FactoryGirl.attributes_for(:place) }
response.should redirect_to places_path(slug: ????)
end
end
私のコントローラーはシンプルです:
def create
@place = Place.new(params[:place])
# setting up who owns this place
@place.user = current_user
if @place.save
flash[:success] = "Place created."
redirect_to @place
else
render :new
end
end
ご覧のとおり、使用するredirect_to @place
と「place/:slug」にリダイレクトされますが、そのリダイレクトをテストするにはどうすればよいでしょうか?
また、私のテスト方法は正しいですか?
ありがとう。