aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2008-04-15 01:24:15 -0400
committerBryan Helmkamp <bryan@brynary.com>2008-04-15 01:24:15 -0400
commit5a2d4f5475b8a040e2ed2da826afe50f0b3824c7 (patch)
tree1f598a69220e5c7c9c97172dafd590ad03af3bfe /spec
parent722623dab397427df7a99b7aeefe4356cadcce25 (diff)
downloadrails-5a2d4f5475b8a040e2ed2da826afe50f0b3824c7.tar.gz
rails-5a2d4f5475b8a040e2ed2da826afe50f0b3824c7.tar.bz2
rails-5a2d4f5475b8a040e2ed2da826afe50f0b3824c7.zip
Fake database implementation. MySQL not required to run the tests
Diffstat (limited to 'spec')
-rw-r--r--spec/fakes/database.rb48
-rw-r--r--spec/spec_helper.rb8
2 files changed, 50 insertions, 6 deletions
diff --git a/spec/fakes/database.rb b/spec/fakes/database.rb
new file mode 100644
index 0000000000..1b73986e0b
--- /dev/null
+++ b/spec/fakes/database.rb
@@ -0,0 +1,48 @@
+class FakeDatabase
+ def self.connection
+ @@conn ||= FakeConnection.new
+ end
+end
+
+class FakeConnection
+ include ActiveRecord::ConnectionAdapters::Quoting
+
+ def columns(table_name, comment)
+ case table_name
+ when "users"
+ [
+ FakeColumn.new("id", :integer),
+ FakeColumn.new("name", :string)
+ ]
+ when "photos"
+ [
+ FakeColumn.new("id", :integer),
+ FakeColumn.new("user_id", :integer),
+ FakeColumn.new("camera_id", :integer)
+ ]
+ else
+ raise "unknown table: #{table_name}"
+ end
+ end
+
+ def select_all(*args)
+ []
+ end
+
+ def quote_column_name(column_name)
+ "`#{column_name}`"
+ end
+
+ def quote_table_name(table_name)
+ "`#{table_name}`"
+ end
+end
+
+class FakeColumn
+ attr_reader :name, :type
+
+ def initialize(name, type)
+ @name = name
+ @type = type
+ end
+end \ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 0d1613e223..af4e71d2d3 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -6,11 +6,7 @@ dir = File.dirname(__FILE__)
$LOAD_PATH.unshift "#{dir}/../lib"
Dir["#{dir}/matchers/*"].each { |m| require "#{dir}/matchers/#{File.basename(m)}" }
require 'active_relation'
-
-FileUtils.cp("#{dir}/../config/database.yml.example", "#{dir}/../config/database.yml") unless File.exist?("#{dir}/../config/database.yml")
-
-ActiveRecord::Base.configurations = YAML::load(IO.read("#{dir}/../config/database.yml"))
-ActiveRecord::Base.establish_connection 'test'
+require "#{dir}/fakes/database"
class Hash
def shift
@@ -24,6 +20,6 @@ Spec::Runner.configure do |config|
config.include(BeLikeMatcher, HashTheSameAsMatcher)
config.mock_with :rr
config.before do
- ActiveRelation::Table.engine = ActiveRelation::Engine.new(ActiveRecord::Base)
+ ActiveRelation::Table.engine = ActiveRelation::Engine.new(FakeDatabase)
end
end \ No newline at end of file