1
공장 클라이언트 및 계약을 생성했습니다. 나는 시험 만 표시 오류FactoryGirl :: AttributeDefinitionError : 속성이 이미 정의되었습니다. 사용자
FactoryGirl.define do
factory :client, class: User do
role 'client'
first_name 'John'
sequence(:last_name) { |n| "client#{n}" }
sequence(:email) { |n| "client#{n}@example.com" }
# avatar { Rack::Test::UploadedFile.new(File.join(Rails.root, 'public', 'images', '128.jpg')) }
password 'password'
password_confirmation 'password'
end
end
지원/controller_macros.rb
module ControllerMacros
def login_client
before do
@client = create(:client)
#@request.env['devise.mapping'] = Devise.mappings[:client]
sign_in @client
end
end
end
FactoryGirl.define do
factory :contract do
sequence(:title) { |n| "translation#{n}" }
amount 150
additional_information 'X' * 500
due_date { 21.days.from_now }
association :user, factory: :client
association :user, factory: :contractor
end
end
내가 실행 테스트 RSpec에 사양/컨트롤러/contracts_controller_spec.rb
require 'rails_helper'
describe ContractsController do
login_client
let(:contract) { create(:contract) }
describe 'POST #create' do
context 'with valid attributes' do
it 'redirects to payment page' do
post :create, contract: attributes_for(:contract)
expect(response).to redirect_to payment_new_path
end
end
end
end
오류 표시를 실행합니다 :
Failure/Error: post :create, contract: attributes_for(:contract)
FactoryGirl::AttributeDefinitionError:
Attribute already defined: user
공장 또는 테스트의 문제점은 무엇입니까?
'에 대한 공장 출하시 기능 : contract'이 심지어 공장의 이름을두면,이를 단축 할 수 있습니다? –
질문이 업데이트되었습니다. – Dmitrij
'association : user'의 정의를 두 번 이해하지 못하겠습니까? – kasperite