mardi 26 mai 2015

Friendly_id gem and its effects on tests (without slug)

I've implemented friendly_id gem by adding to the User model:

include FriendlyId
friendly_id :username

In the controller I've added replaced User.find(params[:id]) with:

User.friendly.find(params[:id])

So I'm not using Slug.

Problem: Now suddenly all sorts of tests fail. Just one example:

class AvatarUploadTest < ActionDispatch::IntegrationTest
  def setup
    @admin             = users(:michael)
  end

  test "avatar upload" do
    log_in_as("user", @admin)    # Helper method that logs in.
    get user_path(@admin)
    ...etc

The line get user_path(@admin) fails with the error message ActiveRecord::RecordNotFound: ActiveRecord::RecordNotFound. How does this relate to the friendly_id gem? I don't really understand it and don't know what adjustments I need to make to my tests.

Aucun commentaire:

Enregistrer un commentaire