FactoryGirl: dlaczego attribute_for pomija niektóre atrybuty?

Chcę użyć FactoryGirl.attributes_for w testowaniu kontrolera, jak w:

<code>it "raise error creating a new PremiseGroup for this user" do
  expect {
    post :create, {:premise_group => FactoryGirl.attributes_for(:premise_group)}
  }.to raise_error(CanCan::AccessDenied)
end
</code>

... ale to nie działa, ponieważ #attributes_for pomija atrybut: user_id. Oto różnica między#create i#attributes_for:

<code>>> FactoryGirl.create(:premise_group)
=> #<PremiseGroup id: 3, name: "PremiseGroup_4", user_id: 6, is_visible: false, is_open: false)
>> FactoryGirl.attributes_for(:premise_group)
=> {:name=>"PremiseGroup_5", :is_visible=>false, :is_open=>false}
</code>

Zauważ, że: user_id jest nieobecny#attributes_for. Czy to jest oczekiwane zachowanie?

FWIW, mój plik fabryk zawiera definicje dla:premise_group i dla:user:

<code>FactoryGirl.define do
  ...
  factory :premise_group do
    sequence(:name) {|n| "PremiseGroup_#{n}"}
    user
    is_visible false
    is_open false
  end
  factory :user do
    ...
  end
end
</code>

questionAnswers(4)

yourAnswerToTheQuestion