Mocking Fog Storage in test cases.

583 views
Skip to first unread message

deepak kumar

unread,
Mar 27, 2013, 3:37:04 AM3/27/13
to bangal...@googlegroups.com
Hi I am using carrierwave direct gem. So the problem now I am facing is my tests are failing with the following message.

ArgumentError:
        is not a recognized storage provider

I have tried engineyard blog post, but it doesn't seem to work. 

--
Thanks & Regards
Deepak Kumar ND
Software Engineer | @_deepak0
+91-9895821948 | skype: deepakkumarnd

arun vydianathan

unread,
Mar 27, 2013, 5:37:14 AM3/27/13
to bangal...@googlegroups.com
Hi the setup given works for me.

I am using something like this in my project

Fog.mock!
connection = Fog::Storage.new(
                          :aws_access_key_id      => ENV["AWS_ACCESS_KEY"],
                          :aws_secret_access_key  => ENV["AWS_SECRET_ACCESS_KEY"],
                          :provider               => 'AWS'
                          )
connection.directories.create(:key => "xxxx-test")

And it works fine.
Did you try to inspect the connection object and see if it has everything set properly?



--
You received this message because you are subscribed to the Google Groups "BANGALORE RUG-Ruby Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bangalorerug...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks,
--
Arun
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you're not on the edge, you're taking up too much room.

Deepak Kumar

unread,
Mar 27, 2013, 5:55:45 AM3/27/13
to bangal...@googlegroups.com
hi Arun thanks for the reply. Let me try that.
Software Engineer @wowmakers
Phone: +91 9895821948

bijendra kumar

unread,
Mar 28, 2013, 2:16:50 AM3/28/13
to bangal...@googlegroups.com
Hi Deepak

The below code creates a bucket and the last line uploads a file from a specific path making the visibility public.

def create_bucket
    bucket = "app-bucket"
    aws_credentials = {
      :aws_access_key_id => 'AKI**',
      :aws_secret_access_key => 'vaj**'
    }
    storage = Fog::Storage.new(aws_credentials.merge(:provider => 'AWS'))
    storage.put_bucket(bucket)
    storage.put_object(bucket, 'games-229a.jpg', File.open('/home/bijendra/Pictures/games-229a.jpg'),
      options = {"x-amz-acl" => 'public-read'})
end

The upload can also be done using below once the bucket is available.

def upload_file
    AWS::S3::Base.establish_connection!(
    :access_key_id     => 'AKI**',
    :secret_access_key => 'vaj**'
    )
    mime_type = "application/octet-stream"
    base_name = File.basename('games-228v.jpg')
    AWS::S3::S3Object.store(
      base_name,
      File.open('/home/bijendra/Pictures/games-228v.jpg'),
      @@BUCKET,
      :content_type => mime_type
    )
end 

Thanks
Bijendra Singh 
Bangalore 
T: (+91)741.129.0280  |  Skype bijendra.kr | Twitter bijendrakr

deepak kumar

unread,
Mar 28, 2013, 2:39:43 AM3/28/13
to bangal...@googlegroups.com
Sorry guys the issue was caused by the existing fixtures in my test case. When I removed them the tests are passing. 
Anyway there are some inconsistencies in carrierwave wiki. For example setting the credentials directly didn't work for 
me when I used just fog.

CarrierWave.configure do |config|
    config.fog_credentials = { 
      provider: 'AWS',
      aws_access_key_id: "XXXX",
      aws_secret_access_key: "XXXX" 
     }
    config.storage        = :fog
    config.fog_directory  = "xxx-#{Rails.env}"
    config.fog_public     = true
    config.fog_attributes = { 'Cache-Control' => 'max-age=315576000'}
  end 

I had use use this to make it work.

Fog.credentials_path = Rails.root.join('config/fog_credentials.yml')

but when i started using carrierwave direct it said aws_access_key_id is missing. So added this code back in my carrierwave.rb

config.fog_credentials = { 
      provider: 'AWS',
      aws_access_key_id: "XXXX",
      aws_secret_access_key: "XXXX" 
 }

I am mentioning this because it may help someone to save time.

Thanks guys for helping me. 
Reply all
Reply to author
Forward
0 new messages