Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added ability to specify different database configuration

  • Loading branch information...
commit 5cf53a123d3245ca4455b4b43a8e267fbc011802 1 parent d7101fa
@nakajima authored
View
14 README.textile
@@ -48,8 +48,6 @@ Then in your specs:
The @build_model@ method allows you to build an ActiveRecord on
the fly. It takes a block where you can specify columns and methods.
-The table will be created in in an in-memory sqlite3 database. If
-you need another adapter, this project ain't for you. Sorry.
h4. Single Table Inheritance
@@ -66,6 +64,18 @@ use the @:superclass@ option:
The @Picture@ model will then be a subclass of the @Asset@ model.
+h4. Custom database configuration
+
+If the in-memory sqlite3 database doesn't suit your needs, you can
+specify an alternative configuration with the @ActsAsFu.connect!@ method:
+
+ ActsAsFu.connect! \
+ :adapter => 'mysql',
+ :database => 'some-db',
+ :username => 'some-user',
+ :password => 'some-password',
+ :socket => '/path/to/mysql.sock'
+
h3. Install
gem install nakajima-acts_as_fu --source=http://gems.github.com
View
6 lib/acts_as_fu/helper.rb
@@ -1,4 +1,8 @@
module ActsAsFu
+ def self.connect!(config={})
+ ActiveRecord::Base.establish_connection(config)
+ end
+
def build_model(name, options={}, &block)
connect!
@@ -27,7 +31,7 @@ def connect!
# This blows up if there's no connection
ActiveRecord::Base.connection
rescue
- ActiveRecord::Base.establish_connection({
+ ActsAsFu.connect!({
:adapter => "sqlite3",
:database => ":memory:"
})
View
18 spec/acts_as_fu_spec.rb
@@ -95,4 +95,22 @@ class << Foo; attr_reader :bar end
end
end
end
+
+ describe "custom DB config" do
+ it "allows connection to custom DB config" do
+ db = "#{File.dirname(__FILE__)}/tmp.sqlite3"
+
+ ActsAsFu.connect! \
+ :adapter => 'sqlite3',
+ :database => db
+
+ build_model(:acts) do
+ string :body
+ end
+
+ File.exists?(db).should be_true
+
+ system("rm #{db}")
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.