title: How can I test an HTTP request from a model spec in Rspec
body: <p>I am uploading an image to my Imagecollection model in using CarrierWave, and would like to test that when I upload the image, it is actually available online.  And that when I delete the image, it is actually removed.</p>
  
  <p>I'm using an S3 backend, so i'd like to test this in the model itself, without having to have any controller dependencies, or run integration tests.  So I would need to construct the url, Issue an HTTP reequest, and tests its return code.  This code doesn't work, but is there a way to do something similar to the following:</p>
  
  <pre><code>describe "once uploaded" do
    subject {Factory :company_with_images} 
  
    it "should be accessible from a URL" do
      image_url = subject.images.first.image.url
      get image_url                                   # Doesn't work
      response.should be_success                      # Doesn't work
    end
  end
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I ended up adding this to my Gemfile</p>
  
  <pre><code>gem rest-client
  </code></pre>
  
  <p>And using the :fog backend for my tests.   Ideally, I could change the backend during the test with something like </p>
  
  <pre><code>before do
    CarrierWave.configure do |config|
       config.storage = :fog
    end
  end
  
  describe tests
  end
  
  after do
    CarrierWave.configure do |config|
       config.storage = :end
    end
  end
  </code></pre>
  
  <p>But that doesn't seem to actually do anything.</p>
  
  <pre><code>describe "once uploaded" do
    describe "using the :fog backend" do
      subject {Factory :company_with_images} 
  
      # This test only passes beecause the S3 host is specified in the url.
      # When using CarrierWave :file storage, the host isn't specified and it
      # fails
      it "should be accessible from a URL" do
        image_url = subject.images.first.image.url
        response = RestClient.get image_url
        response.code.should eq(200)
      end
    end
  
    describe "using the :file backend" do
      subject {Factory :company_with_images} 
  
      # This test fails because the host isn't specified in the url
      it "should be accessible from a URL" do
        image_url = subject.images.first.image.url
        response = RestClient.get image_url
        response.code.should eq(200)
      end
    end
  end
  </code></pre>