edavis10 (owner)

Revisions

gist: 225753 Download_button fork
public
Description:
Rails configuration for using two different databases.
Public Clone URL: git://gist.github.com/225753.git
Embed All Files: show embed
app/models/source_user.rb #
1
2
3
4
5
class SourceUser < ActiveRecord::Base
  include SecondDatabase
  set_table_name :users
end
 
lib/second_database.rb #
1
2
3
4
5
6
7
8
9
# Abstraction to connect to the second database
module SecondDatabase
  def self.included(base)
    base.class_eval do
      establish_connection :source_redmine
    end
  end
end
 
test_helper.rb #
1
2
3
4
5
6
7
8
9
10
# Override the actual second database connection code in order to test
# against a known database
module SecondDatabase
  def self.included(base)
    base.class_eval do
      establish_connection("adapter" => 'sqlite3', "database" => File.expand_path(File.dirname(__FILE__) + '/test_database.sqlite3'))
    end
  end
end