Question

I am using Draper for the first time and it's working great...except for the fact that it broke most of my specs. An example:

I am setting up an account_settings_controller_spec.rb

describe '#create' do
  before do
    @user = create :user
   end
end

This worked totally fine before (I have config.include FactoryGirl::Syntax::Methods set to call the factories like this)

However now when I call create :user I get undefined method 'full_name' for class 'User' which is a method I moved from my User model to my UserDecorator.

This is strange as the factory, nor the spec, use the full_name method.

I've tried multiple things:

  • ApplicationController.new.set_current_view_context in the before block (which results in an error)
  • require 'draper/test/rspec_integration' to my spec_helper.rb (which does nothing)
  • adding before/after(:create) { |instance| instance.decorate } to my factory (which also does nothing)

I'm not sure what I am missing here, or even why the error is being thrown. Perhaps my decorators aren't being included when RSpec boots up?

Was it helpful?

Solution

Ahh ha!

I knew I was being stupid.

It's because I was using friendly_id

class User < ActiveRecord::Base
  extend FriendlyId
  friendly_id :slug_candidates, use: :slugged

  ...

  def slug_candidates
    [:full_name, :id]
  end
end

I just moved the full_name method back to the model and it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top