I think I found a solution. Was a bit of work and essentially a rework.
The main guide here is also to build small build tests along the way,
so you can be sure what exactly happens.
Also, to allow "build" (to not write to the database during tests), use
the belongs_to association (DocumentUpload belongs_to :by_client)
and test the association present. Don't manually play with by_client_id,
since that will require saving or fetching from the database to test.
The main test is this one and it passes:
peterv@ASUS:~/data/backed_up/rails-apps/apps/temp/fg/spec/model/document_upload$ cat factory_spec.rb
require 'spec_helper'
describe "DocumentUpload" do
it "builds a document" do
FactoryGirl.build(:document_upload)
end
it "builds a document_upload with a document" do
du = FactoryGirl.build(:document_upload_with_document)
du.document.should_not be_nil
end
it "builds a document_upload with a document and an order" do
du = FactoryGirl.build(:document_upload_with_document_and_order)
du.document.should_not be_nil
du.document.order.should_not be_nil
end
it "builds a document_upload with a document and an order and a client x" do
du = FactoryGirl.build(:document_upload_with_document_and_order_and_client_x)
du.document.should_not be_nil
du.document.order.should_not be_nil
du.document.order.client.should_not be_nil
du.document.order.client.last_name.should == "X"
du.by_client.should_not be_nil
end
end
The detailed code is here:
HTH,
Peter