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

describe Mugshot::Proxy do
  before :each do
    def app
      Mugshot::Proxy.new("http://localhost:9292")
    end
  end

  describe 'GET /*' do
    before :each do
      @http = stub(Net::HTTP, :null_object => true)
      @res = stub(Net::HTTPResponse, :null_object => true)
      @http.stub!(:get).with('/request/path').and_return(@res)
      Net::HTTP.stub!(:start).with("localhost", 9292).and_yield(@http)
    end

    it 'should proxy the request to configured host' do
      @res.stub!(:body).and_return('body')

      get '/request/path'

      last_response.body.should == 'body'
    end

    it 'should return original response headers' do
      @res.stub!(:each_header)\
        .and_yield('content-type', 'image/jpg')\
        .and_yield('cache-control', 'public, max-age=31557600')

      get '/request/path'

      last_response.headers['content-type'].should == 'image/jpg'
      last_response.headers['cache-control'].should == 'public, max-age=31557600'
    end
  end

  describe 'other methods' do
    it 'should not be allowed' do
      post '/request/path'
      last_response.status.should == 405

      put '/request/path'
      last_response.status.should == 405

      delete '/request/path'
      last_response.status.should == 405
    end
  end
end<commit_msg>Added a spec.<commit_after>require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe Mugshot::Proxy do
  before :each do
    def app
      Mugshot::Proxy.new("http://localhost:9292")
    end
  end

  describe 'GET /*' do
    before :each do
      @http = stub(Net::HTTP, :null_object => true)
      @res = stub(Net::HTTPResponse, :null_object => true)
      @http.stub!(:get).with('/request/path').and_return(@res)
      Net::HTTP.stub!(:start).with("localhost", 9292).and_yield(@http)
    end

    it 'should proxy the request to configured host' do
      @res.stub!(:body).and_return('body')

      get '/request/path'

      last_response.body.should == 'body'
    end

    it 'should return original response headers' do
      @res.stub!(:each_header)\
        .and_yield('content-type', 'image/jpg')\
        .and_yield('cache-control', 'public, max-age=31557600')

      get '/request/path'

      last_response.headers['content-type'].should == 'image/jpg'
      last_response.headers['cache-control'].should == 'public, max-age=31557600'
    end

    it 'should not return status header' do
      @res.stub!(:each_header).and_yield('status', '200')

      get '/request/path'

      last_response.headers.should_not include('status')
    end
  end

  describe 'other methods' do
    it 'should not be allowed' do
      post '/request/path'
      last_response.status.should == 405

      put '/request/path'
      last_response.status.should == 405

      delete '/request/path'
      last_response.status.should == 405
    end
  end
end
{'fraction_non_alphanumeric': 0.1467983651226158, 'fraction_numerical': 0.023501362397820164, 'mean_word_length': 2.931726907630522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2330417', 'n_tokens_mistral': 995, 'n_tokens_neox': 917, 'n_words': 203}