<commit_before>require File.dirname(__FILE__) + '/../spec_helper.rb'

describe Drop do
  
  before(:each) do
    @client = Dropio::Client.new
    @api = stub(Dropio::Api)
    @client.service = @api
    
    Dropio::Resource.stub!(:client).and_return(@client)
    Dropio::Resource.client.should == @client
    Dropio::Resource.client.service.should == @api
    
    @mydrop = Dropio::Drop.new(:name => "test_drop",:admin_token => "<PASSWORD>")
  end
  
  it "should have the attributes of a Drop" do
    Drop.new.should respond_to(:name, :email, :voicemail, :conference, :fax, :rss, :guest_token, :description,
                  :admin_token, :expires_at, :expiration_length, :guests_can_comment, :guests_can_add, :guests_can_delete,
                  :max_bytes, :current_bytes, :hidden_upload_url, :asset_count, :chat_password, :default_view, 
                  :password, :<PASSWORD>, :premium_code, :admin_email, :email_key)
  end
  
  it "should find drops by name" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    @api.should_receive(:drop).with("mydrop", nil).and_return({})
    Drop.find("mydrop").should == @mydrop
  end

  it "should find drops by name and token" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    @api.should_receive(:drop).with("mydrop", "d85a6").and_return({})
    Drop.find("mydrop", "d85a6").should == @mydrop
  end
  
  it "should have a default token and it should default to the admin" do
    @mydrop.admin_token = "tester"
    @mydrop.default_token.should == "tester"
  end
  
  it "should find a set of related assets" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:assets,{}).and_return([@asset])
    @api.stub!(:assets).with(@mydrop.name,1,:oldest,@mydrop.default_token).and_return({})
    @mydrop.assets.should == [@asset]
  end
  
  it "should be able to create a new Drop" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    @api.should_receive(:create_drop).with({:name => "tester"}).and_return({})
    Drop.create({:name => "tester"}).should == @mydrop
  end
  
  it "should fetch the upload embed code" do
    @client.should_receive(:handle).with(:response,{}).and_return({"result" => "Success"})
    @api.should_receive(:drop_upload_code).with(@mydrop.name,@mydrop.default_token).and_return({})
    @mydrop.upload_code
  end
  
  it "should be able to empty itself" do
    @client.should_receive(:handle).with(:response,{}).and_return({})
    @api.should_receive(:empty_drop).with(@mydrop.name,@mydrop.admin_token).and_return({})
    @mydrop.empty
  end
  
  it "should be able to promote a nick" do
    @client.should_receive(:handle).with(:response,{}).and_return({"result" => "Success"})
    @api.should_receive(:promote_nick).with(@mydrop.name,"jake",@mydrop.admin_token).and_return({})
    @mydrop.promote("jake")
  end
  
  it "should save itself" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    expected_hash = {:password=>"<PASSWORD>", :expiration_length=>nil, :admin_password=><PASSWORD>, :guests_can_comment=>nil, 
                     :premium_code=>nil, :guests_can_add=>nil, :chat_password=><PASSWORD>, :guests_can_delete=>nil, 
                     :admin_email=>nil, :default_view=>nil, :email_key=>nil, :description=>nil}
    @api.should_receive(:update_drop).with(@mydrop.name,@mydrop.admin_token,expected_hash).and_return({})
    @mydrop.password = "<PASSWORD>"
    @mydrop.save
  end
  
  it "should destroy itself" do
    @client.should_receive(:handle).with(:response,{}).and_return({"result" => "Success"})
    @api.should_receive(:delete_drop).with(@mydrop.name,@mydrop.admin_token).and_return({})
    @mydrop.destroy!
  end
  
  it "should add files from a url" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:add_file_from_url).with(@mydrop.name,"http://myurl.com/myfile.txt",@mydrop.default_token).and_return({})
    @mydrop.add_file_from_url("http://myurl.com/myfile.txt").should == @asset
  end
  
  it "should add files from a path" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:add_file).with(@mydrop.name,"/mypath/myfile.txt",@mydrop.default_token, nil).and_return({})
    @mydrop.add_file("/mypath/myfile.txt").should == @asset
  end
  
  it "should create notes from title and contents" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:create_note).with(@mydrop.name,"contents", "title",@mydrop.default_token).and_return({})
    @mydrop.create_note("contents","title").should == @asset
  end
  
  it "should create links from a url, title, and description" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:create_link).with(@mydrop.name,"http://drop.io","drop.io","The best!",@mydrop.default_token).and_return({})
    @mydrop.create_link("http://drop.io","drop.io","The best!").should == @asset
  end
  <commit_msg>Update spec<commit_after>require File.dirname(__FILE__) + '/../spec_helper.rb'

describe Drop do
  
  before(:each) do
    @client = Dropio::Client.new
    @api = stub(Dropio::Api)
    @client.service = @api
    
    Dropio::Resource.stub!(:client).and_return(@client)
    Dropio::Resource.client.should == @client
    Dropio::Resource.client.service.should == @api
    
    @mydrop = Dropio::Drop.new(:name => "test_drop",:admin_token => "<PASSWORD>")
  end
  
  it "should have the attributes of a Drop" do
    Drop.new.should respond_to(:name, :email, :voicemail, :conference, :fax, :rss, :guest_token, :description,
                  :admin_token, :expires_at, :expiration_length, :guests_can_comment, :guests_can_add, :guests_can_delete,
                  :max_bytes, :current_bytes, :hidden_upload_url, :asset_count, :chat_password, :default_view, 
                  :password, :<PASSWORD>_password, :premium_code, :admin_email, :email_key)
  end
  
  it "should find drops by name" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    @api.should_receive(:drop).with("mydrop", nil).and_return({})
    Drop.find("mydrop").should == @mydrop
  end

  it "should find drops by name and token" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    @api.should_receive(:drop).with("mydrop", "d85a6").and_return({})
    Drop.find("mydrop", "d85a6").should == @mydrop
  end
  
  it "should have a default token and it should default to the admin" do
    @mydrop.admin_token = "<PASSWORD>"
    @mydrop.default_token.should == "<PASSWORD>"
  end
  
  it "should find a set of related assets" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:assets,{}).and_return([@asset])
    @api.stub!(:assets).with(@mydrop.name,1,:oldest,@mydrop.default_token).and_return({})
    @mydrop.assets.should == [@asset]
  end
  
  it "should be able to create a new Drop" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    @api.should_receive(:create_drop).with({:name => "tester"}).and_return({})
    Drop.create({:name => "tester"}).should == @mydrop
  end
  
  it "should fetch the upload embed code" do
    @client.should_receive(:handle).with(:response,{}).and_return({"result" => "Success"})
    @api.should_receive(:drop_upload_code).with(@mydrop.name,@mydrop.default_token).and_return({})
    @mydrop.upload_code
  end
  
  it "should be able to empty itself" do
    @client.should_receive(:handle).with(:response,{}).and_return({})
    @api.should_receive(:empty_drop).with(@mydrop.name,@mydrop.admin_token).and_return({})
    @mydrop.empty
  end
  
  it "should be able to promote a nick" do
    @client.should_receive(:handle).with(:response,{}).and_return({"result" => "Success"})
    @api.should_receive(:promote_nick).with(@mydrop.name,"jake",@mydrop.admin_token).and_return({})
    @mydrop.promote("jake")
  end
  
  it "should save itself" do
    @client.should_receive(:handle).with(:drop,{}).and_return(@mydrop)
    expected_hash = {:password=>"<PASSWORD>", :expiration_length=>nil, :admin_password=><PASSWORD>, :guests_can_comment=>nil, 
                     :premium_code=>nil, :guests_can_add=>nil, :chat_password=><PASSWORD>, :guests_can_delete=>nil, 
                     :admin_email=>nil, :default_view=>nil, :email_key=>nil, :description=>nil}
    @api.should_receive(:update_drop).with(@mydrop.name,@mydrop.admin_token,expected_hash).and_return({})
    @mydrop.password = "<PASSWORD>"
    @mydrop.save
  end
  
  it "should destroy itself" do
    @client.should_receive(:handle).with(:response,{}).and_return({"result" => "Success"})
    @api.should_receive(:delete_drop).with(@mydrop.name,@mydrop.admin_token).and_return({})
    @mydrop.destroy!
  end
  
  it "should add files from a url" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:add_file_from_url).with(@mydrop.name,"http://myurl.com/myfile.txt",@mydrop.default_token).and_return({})
    @mydrop.add_file_from_url("http://myurl.com/myfile.txt").should == @asset
  end
  
  it "should add files from a path" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:add_file).with(@mydrop.name,"/mypath/myfile.txt", nil, nil, nil, @mydrop.default_token).and_return({})
    @mydrop.add_file("/mypath/myfile.txt").should == @asset
  end
  
  it "should add files from a path with pingback url and convertsion target" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:add_file).with(@mydrop.name,"/mypath/myfile.txt", 'H264_HIGH_RES', 'http://drop.io/test/pinged', nil, @mydrop.default_token).and_return({})
    @mydrop.add_file("/mypath/myfile.txt", 'H264_HIGH_RES', 'http://drop.io/test/pinged').should == @asset
  end
  
  it "should create notes from title and contents" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:create_note).with(@mydrop.name,"contents", "title",@mydrop.default_token).and_return({})
    @mydrop.create_note("contents","title").should == @asset
  end
  
  it "should create links from a url, title, and description" do
    @asset = stub(Asset)
    @asset.should_receive(:drop=).once
    @client.should_receive(:handle).with(:asset,{}).and_return(@asset)
    @api.should_receive(:create_link).with(@mydrop.name,"http://drop.io","drop.io","The best!",@mydrop.default_token).and_return({})
    @mydrop.create_link("http://drop.io","drop.io","The best!").should == @asset
  end
  
{'fraction_non_alphanumeric': 0.1751073729420186, 'fraction_numerical': 0.0017895490336435219, 'mean_word_length': 4.566235059760956, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2099087', 'n_tokens_mistral': 3926, 'n_tokens_neox': 3814, 'n_words': 606}