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

describe PublicDownloadsController do
  render_views
  
  before do
    make_a_typical_project
    @upload = @project.uploads.new({:asset => mock_uploader('semicolons.js', 'application/javascript', "alert('what?!')")})
    @upload.user = @user
    @upload.save!
  end
  
  route_matches("/d/aaBBccdd33ffGG44",
    :get, 
    :controller => "public_downloads",
    :action => "download", 
    :token => "<KEY>")

  route_matches("/send/aaBBccdd33ffGG44",
    :get,
    :controller => "public_downloads",
    :action => "download_send",
    :token => "<KEY>")
  
  describe "GET #download" do
    it "should display downloads landing page for correct token" do
      get :download, :token => @upload.token
      response.code.should eq("200")
      response.should render_template("public_downloads/download")
    end
    
    it "should show file not found page for invalid token" do
      get :download, :token => '<PASSWORD>'
      response.code.should eq("404")
      response.should render_template("public_downloads/not_found")
    end
  end

  describe "GET #send" do
    it "should send a file with correct headers to the browser" do
      
      get :download_send, :token => @upload.token

      response.code.should eq("200")
      response.body.should eq("alert('what?!')")
      response.header["Content-Disposition"].should match(/filename=\"#{@upload.asset_file_name}\"/)
      response.header["Content-Type"].should eq(@upload.asset_content_type)
    end

    it "should return not found for invalid token" do

      get :download_send, :token => '<PASSWORD>'<commit_msg>Added spec for public downloads folders<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe PublicDownloadsController do
  render_views
  
  before do
    make_a_typical_project
    @upload = @project.uploads.new({:asset => mock_uploader('semicolons.js', 'application/javascript', "alert('what?!')")})
    @upload.user = @user
    @upload.save!

    @folder = Factory(:folder, :user => @user, :project => @project)
  end
  
  route_matches("/d/aaBBccdd33ffGG44",
    :get, 
    :controller => "public_downloads",
    :action => "download", 
    :token => "<KEY>")

  route_matches("/f/hhyy66GGJJeeXXll",
    :get,
    :controller => "public_downloads",
    :action => "folder",
    :token => "<PASSWORD>")

  route_matches("/send/aaBBccdd33ffGG44",
    :get,
    :controller => "public_downloads",
    :action => "download_send",
    :token => "<KEY>")
  
  describe "GET #download" do
    it "should display downloads landing page for correct token" do
      get :download, :token => @upload.token
      response.code.should eq("200")
      response.should render_template("public_downloads/download")
    end
    
    it "should show file not found page for invalid token" do
      get :download, :token => '<PASSWORD>'
      response.code.should eq("404")
      response.should render_template("public_downloads/not_found")
    end
  end

  describe "GET #folder" do
    it "should display download folder landing page for correct token" do
      get :folder, :token => @folder.token
      response.code.should eq("200")
      response.should render_template("public_downloads/folder")
    end

    it "should show file not found page for invalid token" do
      get :folder, :token => '<PASSWORD>'
      response.code.should eq("404")
      response.should render_template("public_downloads/not_found")
    end
  end

  describe "GET #send" do
    it "should send a file with correct headers to the browser" do
      
      get :download_send, :token => @upload.token

      response.code.should eq("200")
      response.body.should eq("alert('what?!')")
      response.header["Content-Disposition"].should match(/filename=\"#{@upload.asset_file_name}\"/)
      response.header["Content-Type"].should eq(@upload.asset_content_type)
    end

    it "should return not found for invalid token" do

      get :download_send, :token => '<PASSWORD>'
{'fraction_non_alphanumeric': 0.13475882645450024, 'fraction_numerical': 0.0104425658876181, 'mean_word_length': 3.4600886917960088, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 33, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3103060', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1198, 'n_words': 305}