2011-06-22 5 views
3

マイモデルには、モデル内のいくつかの属性をリモートリソースから更新するメソッドがあります。私はRspecでそれをテストしたいが、フィールドが作成されたか更新されたかどうかをテストする方法は見つけられない。属性が更新された場合のRspecテスト

質問実際に

def update_from_remote 
    attributes = {} 
    fields.each_key do |field_name| 
    attributes[field_name] = scrape_from_remote field_name 
    end 
    update_attributes(attributes) 
end 

このコードは多くの複雑ですが、それが唯一の私の質問に乱雑になりますを説明するためのいくつかの擬似コード。 create_from_remoteはどちらも似ていますが、update_attributesを呼び出さず、単純にそれらを設定してオブジェクトを保存するという点だけです。

私はこれをテストしたいと思います。私が、欲しいのはフィールドが更新または充填したかどうかをテストスペックです:

it 'should fill or set all local attributes on a new profile' do 
    #how to test if a list of fields were updated in the Database? 
end 
it 'should update all local attributes on an existing profile' do 
    #how to test if a list of fields were created in the Database? 
end 

私はmongoIdを使用していますが、その私の知る限り大きな違いを作るべきではありません。

答えて

4

私はMongoIDのドキュメントでより深く掘り下げていたはずです。 Dirty trackingには、使用できる章があります。

it "should be updated" 
    @something.field.should be_changed 
end 
関連する問題