提交的模型形式出廠值我有一個需要以下字段的客戶端模式:如何通過水豚
validates :name, :address1, :city, :state, :country, :zipcode,
:contactname, :email, presence: true
創建一個新的客戶現在我書面方式測試。我創建FactoryGirl客戶對象,我該如何填寫表格出廠值,而無需手動編寫fill_in "field_id", with: factory.field_value
用於各個領域,像我已經做了,如下圖所示的代碼。
describe "with valid information" do
let(:client) { FactoryGirl.create(:client) }
before(:each) do
visit new_client_path
fill_in "client_name", with: client.name
fill_in "client_address1", with: client.address1
fill_in "client_city", with: client.city
fill_in "client_state", with: client.state
select client.country, from: "client_country"
fill_in "client_zipcode", with: client.zipcode
fill_in "client_contactname", with: client.contactname
fill_in "client_email", with: client.email
end
it "should create a client" do
expect { click_button "Create Client" }.to change(Client, :count)
end
describe "success messages" do
before { click_button "Create Client" }
it { should have_content('created') }
end
end
感謝
不FactoryGirl已經將其保存到數據庫? –
是的,它應該。爲了剛剛生成的屬性,應該使用'FactoryGirl.build(...)' – khustochka