CouchRest Rails Setup - Blank username/password issues

Setting a blank username/password is not the same as not setting a username/password

If you are using CouchRest in your Rails project and locally you don't want to set a username and password for your couchdb install then bare in mind that the following are not the same;

CouchRest::Model::Base.configure do |config|
    config.connection = {
        :protocol => 'http',
        :host     => '127.0.0.1',
        :port     => 5984,
        :prefix   => '',
        :suffix   => Rails.env,
        :join     => '_'
    }
  end

The code above has no username and password set, so it will not try and speak to CouchDB with any credentials.

The code below *has* a username and password set but they are both blank, so it will try and speak to CouchDB with the username and password both being set to an empty string, this will result in a 401 Not authorised error.

CouchRest::Model::Base.configure do |config|
    config.connection = {
        :protocol => 'http',
        :host     => '127.0.0.1',
        :port     => 5984,
        :prefix   => '',
        :suffix   => Rails.env,
        :join     => '_',
        :username => '',
        :password => ''
    }
  end

This isn't particularly unique to CouchRest at all but it tripped me up earlier so I figured I would share :-)


Recent posts View all

Ruby

How to ignore Bullet in RSpec tests

Using Bullet during a test can pick up mistakes but also has false negatives; here is an easy way to ignore them

Ruby

How we used Nokogiri to fix a sizing issue in YouTube's oEmbed

At some point, one of our calls to YouTube's oEmbed endpoint was returning videos way too small; we fixed in in our Rails application by using Nokogiri