私はrspecとfactorygirlに非常に慣れていないので、奇妙な問題に悩まされています。私はコントローラーで次のようなアクションを実行します:
def update
@property = current_user.properties.find params[:fee][:property_id]
@fee = @property.fees.find(params[:id])
if @fee.update_attributes(params[:fee])
redirect_to fee_path(:prop=>@property), :notice => "fee updated successfully!"
else
render action: "edit"
end
end
とテスト例:
describe "with valid params" do
before do
@property = FactoryGirl.create(:property)
@property.users << subject.current_user
end
it "updates the requested fee" do
fee = @property.fees.create! valid_attributes
Fee.any_instance.should_receive(:update_attributes).with({ "name" => "MyString","property_id"=>@property.id})
put :update, {:id => fee.to_param, :fee => { "name" => "MyString","property_id"=>@property.id }}, valid_session
end
end
しかし、奇妙なエラーが発生します:
#<Fee:0xb8c4884> received :update_attributes with unexpected arguments
expected: ({"name"=>"MyString", "property_id"=>"50ec0b3fa7c320ee53000002"})
got: ({"name"=>"MyString", "property_id"=>"50ec0b3fa7c320ee53000002"})
誰かが助けてくれるなら、私はとても感謝します。