@@ -11,7 +11,6 @@ def should_receive_api_method_with_arguments(object, method, api_method, argumen
11
11
object . should_receive ( method ) . once do |url |
12
12
front = url . split ( '?' ) . first
13
13
front . should eql ( "#{ Dropbox ::ALTERNATE_HOSTS [ api_method ] || Dropbox ::HOST } /#{ Dropbox ::VERSION } /#{ api_method } #{ '/' + root if root } #{ '/' + path if path } " )
14
-
15
14
query_params = url_args ( url )
16
15
query_params . each { |key , val | val . should eql ( arguments [ key . to_sym ] ) }
17
16
arguments . each { |key , _ | query_params . should include ( key . to_s ) }
@@ -425,6 +424,43 @@ def response_acts_as(subclass)
425
424
@session . link ( path )
426
425
end
427
426
end
427
+
428
+ describe "#shares" do
429
+ before :each do
430
+ @response . stub! ( :code ) . and_return ( 304 )
431
+ response_acts_as Net ::HTTPFound
432
+ @response . stub! ( :[] ) . and_return ( "new location" )
433
+ end
434
+
435
+ it "should call the API method shares" do
436
+ should_receive_api_method_with_arguments @token_mock , :post , 'shares' , { } , @response , 'some/file' , 'sandbox'
437
+ @session . shares 'some/file'
438
+ end
439
+
440
+ it "should strip a leading slash" do
441
+ should_receive_api_method_with_arguments @token_mock , :post , 'shares' , { } , @response , 'some/file' , 'sandbox'
442
+ @session . shares '/some/file'
443
+ end
444
+
445
+ it "should rescue 304's and return the Location header" do
446
+ should_receive_api_method_with_arguments @token_mock , :post , 'shares' , { } , @response , 'some/file' , 'sandbox'
447
+ lambda { @session . shares ( 'some/file' ) . should eql ( "new location" ) } . should_not raise_error
448
+ end
449
+
450
+ it "should re-raise other errors unmodified" do
451
+ response_acts_as nil
452
+ @token_mock . stub! ( :post ) . and_return ( @response )
453
+ lambda { @session . shares ( 'a' ) } . should raise_error ( Dropbox ::UnsuccessfulResponseError )
454
+ end
455
+
456
+ it "should check the path" do
457
+ path = "source/path"
458
+ Dropbox . should_receive ( :check_path ) . once . with ( path ) . and_return ( path )
459
+ @token_mock . stub! ( :post ) . and_return ( @response )
460
+
461
+ @session . shares ( path )
462
+ end
463
+ end
428
464
429
465
describe "#metadata" do
430
466
before :each do
0 commit comments