diff --git a/lib/dropbox/entry.rb b/lib/dropbox/entry.rb index 1708b82..e349b7f 100644 --- a/lib/dropbox/entry.rb +++ b/lib/dropbox/entry.rb @@ -31,10 +31,16 @@ def initialize(session, path) # :nodoc: @path = path end - # Delegates to Dropbox::API#metadata. + # Delegates to Dropbox::API#metadata. Additional options: + # + # +force+:: Normally, subsequent calls to this method will use cached + # results if the file hasn't been changed. To download the full + # metadata even if the file has not been changed, set this to + # +true+. def metadata(options={}) - @session.metadata path, options + @previous_metadata = nil if options.delete(:force) + @previous_metadata = @session.metadata path, (@previous_metadata ? options.merge(:prior_response => @previous_metadata) : options) end alias :info :metadata diff --git a/spec/dropbox/entry_spec.rb b/spec/dropbox/entry_spec.rb index 094713e..7f67da0 100644 --- a/spec/dropbox/entry_spec.rb +++ b/spec/dropbox/entry_spec.rb @@ -22,6 +22,26 @@ @entry.metadata(:sandbox => true) end + + it "should record prior responses and use them automatically" do + result = mock('result') + + @session.should_receive(:metadata).once.with(@path, {}).and_return(result) + @entry.metadata.should eql(result) + + @session.should_receive(:metadata).once.with(@path, { :prior_response => result }).and_return(result) + @entry.metadata.should eql(result) + end + + it "... unless :force is set to true" do + result = mock('result') + + @session.should_receive(:metadata).once.with(@path, {}).and_return(result) + @entry.metadata + + @session.should_receive(:metadata).once.with(@path, {}).and_return(result) + @entry.metadata(:force => true) + end end describe "#move" do