Skip to content

Commit

Permalink
Dropbox::Entry automatically uses metadata hash feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RISCfuture committed Dec 30, 2010
1 parent 7c16bc4 commit 3187c65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/dropbox/entry.rb
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions spec/dropbox/entry_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 3187c65

Please sign in to comment.