我对 rspec 和工厂女孩很陌生,我遇到了一个奇怪的问题。我在控制器中有一个动作,例如:
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"})
如果有人可以提供帮助,我将不胜感激。