Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:56:10+00:00 2026-05-23T01:56:10+00:00

I am uploading an image to my Imagecollection model in using CarrierWave, and would

  • 0

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.

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:

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

EDIT:

I ended up adding this to my Gemfile

gem rest-client

And using the :fog backend for my tests. Ideally, I could change the backend during the test with something like

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

But that doesn’t seem to actually do anything.

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:56:11+00:00Added an answer on May 23, 2026 at 1:56 am

    I ended up redefining the spec as follows

      describe "using the :fog backend" do
        subject {Factory :company_with_images} 
    
        it "should be accessible from a URL" do
          image_url = subject.images.first.image.url
          rest_response(image_url).code.should eq(200)
        end
      end
    

    with this helper

    def rest_response url
      # https://github.com/archiloque/rest-client
      RestClient.get(url){|response, request, result| response }
    end
    

    and using the restclient gem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am uploading an image to a server and before that happens, I would
I am having problem uploading image to mongodb using rails and carrierwave. This is
Instead of uploading image one by one, how do i achieve to upload all
I am uploading image to server using base64 its working fine if image is
So i'm uploading any image file via my great upload form and it uploads
How should I handle image uploading using PHP? How should I handle the chmod
Here I have the problem with uploading image in PHP. The problem is that
I am uploading an image using the Graph API. The image is successfully uploaded
We are trying to get image uploading working with TinyPic that tracks the progress
I have developed an image uploading application that uses Flash to load an image,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.