Monday, 24 August 2009

I am starting to hate Factory Girl

Why oh why is it not passing the associated id?
Clearly I am doing something wrong, but wtf is it?

Factory.define :output_type do |f|
f.sequence(:name) {|n| "proofer#{n}"}
f.live true
end


Factory.define :device_type do |f|
f.sequence(:name) {|n| "device_type#{n}"}
f.live true
f.association :output_type
end


Here is the controller test:
test "should create device_type" do
output_type = Factory(:output_type)
@device_types_attr = Factory.attributes_for(:device_type)
assert_difference('DeviceType.count') do
post :create, :device_type => @device_types_attr
end

assert_redirected_to device_type_path(assigns(:device_type))
end



When I run the actual script through a browser and watch the log I get this
Parameters: {"commit"=>"Create", "device_type"=>{"name"=>"testLaser", "live"=>"1", "output_type_id"=>"2"},

But when I run the test, I get this
Parameters: {"device_type"=>{"name"=>"device_type1", "live"=>true}}

ie - no output type is being sent.

Why?
(hmmm - just noticed the live=>true and live=>'1'. Don't suppose that is the problem, but worth checking it out)

No comments:

Post a Comment