2014-12-26 5 views
1

У меня странная проблема. У меня есть модели, как это:Создание записей тестов с FactoryGirl завершается после использования проблемы

class Patient < ActiveRecord::Base 
    include Addressable 
end 

class Address < ActiveRecord::Base 
    belongs_to :addressable, polymorphic: true 
end 

и адресуемый озабоченность:

module Addressable 
    extend ActiveSupport::Concern 

    included do 
    has_one :address, as: :addressable, dependent: :destroy 
    delegate :to_formatted_s, to: :address, prefix: true 
    accepts_nested_attributes_for :address 
    end 
end 

Когда я переехал этот код, чтобы касаться моих тестов не удается:

Failure/Error: let(:patient) { create(:patient, :male, fullname: "Patient", pesel: "12345678901") } 
    NoMethodError: 
     undefined method `address=' for #<Patient:0x0000000550bb58> 

Мои заводы:

FactoryGirl.define do 
    factory :patient do 
    sequence(:fullname) { |n| "Patient #{n}" } 
    pesel "12345678901" 
    birth_date "2014-12-16" 
    address 

    trait :male do 
     sex "male" 
    end 

    trait :female do 
     sex "female" 
    end 
    end 
end 

FactoryGirl.define do 
    factory :address do 
    sequence(:street) { |n| "Street #{n}" } 
    sequence(:city) { |n| "City #{n}" } 
    sequence(:zip_code) { |n| " 12-41#{n}" } 
    end 
end 

Прежде чем переместить этот код в co ncern все работает так, как ожидалось. Почему сейчас терпит неудачу?

ответ

2

Это был конфликт имен. Я меняю название проблемы на AddresableConcern, и теперь eveyrthing работает так, как ожидалось.

Смежные вопросы