diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2008-04-15 01:24:15 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2008-04-15 01:24:15 -0400 |
commit | 5a2d4f5475b8a040e2ed2da826afe50f0b3824c7 (patch) | |
tree | 1f598a69220e5c7c9c97172dafd590ad03af3bfe | |
parent | 722623dab397427df7a99b7aeefe4356cadcce25 (diff) | |
download | rails-5a2d4f5475b8a040e2ed2da826afe50f0b3824c7.tar.gz rails-5a2d4f5475b8a040e2ed2da826afe50f0b3824c7.tar.bz2 rails-5a2d4f5475b8a040e2ed2da826afe50f0b3824c7.zip |
Fake database implementation. MySQL not required to run the tests
-rw-r--r-- | config/database.yml.example | 6 | ||||
-rw-r--r-- | doc/TODO | 2 | ||||
-rw-r--r-- | schema.sql | 126 | ||||
-rw-r--r-- | spec/fakes/database.rb | 48 | ||||
-rw-r--r-- | spec/spec_helper.rb | 8 |
5 files changed, 51 insertions, 139 deletions
diff --git a/config/database.yml.example b/config/database.yml.example deleted file mode 100644 index 2230912f7d..0000000000 --- a/config/database.yml.example +++ /dev/null @@ -1,6 +0,0 @@ -test: - adapter: mysql - username: root - password: password - encoding: utf8 - database: sql_algebra_test @@ -1,13 +1,13 @@ todo: - rename ActiveRelation to arel - incorporate linq vocabularity -- mock out database - fix complex joining cases: - extract adapters - cache expiry on write - rewrite of arecord querycache test in light of this done: +- mock out database . Relation <=> Relation -> InnerJoinOperation . Relation << Relation -> LeftOuterJoinOperation . InnerJoinOperation.on(*Predicate) -> InnerJoinRelation diff --git a/schema.sql b/schema.sql deleted file mode 100644 index d42eb96944..0000000000 --- a/schema.sql +++ /dev/null @@ -1,126 +0,0 @@ --- MySQL dump 10.10 --- --- Host: localhost Database: sql_algebra_test --- ------------------------------------------------------ --- Server version 5.0.27-standard - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `bar` --- - -DROP TABLE IF EXISTS `bar`; -CREATE TABLE `bar` ( - `id` int(11) default NULL, - `name` varchar(255) default NULL, - `foo_id` int(11) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- --- Dumping data for table `bar` --- - -LOCK TABLES `bar` WRITE; -/*!40000 ALTER TABLE `bar` DISABLE KEYS */; -/*!40000 ALTER TABLE `bar` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `cameras` --- - -DROP TABLE IF EXISTS `cameras`; -CREATE TABLE `cameras` ( - `id` int(11) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- --- Dumping data for table `cameras` --- - -LOCK TABLES `cameras` WRITE; -/*!40000 ALTER TABLE `cameras` DISABLE KEYS */; -INSERT INTO `cameras` VALUES (1); -/*!40000 ALTER TABLE `cameras` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `foo` --- - -DROP TABLE IF EXISTS `foo`; -CREATE TABLE `foo` ( - `id` int(11) default NULL, - `name` varchar(255) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- --- Dumping data for table `foo` --- - -LOCK TABLES `foo` WRITE; -/*!40000 ALTER TABLE `foo` DISABLE KEYS */; -/*!40000 ALTER TABLE `foo` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `photos` --- - -DROP TABLE IF EXISTS `photos`; -CREATE TABLE `photos` ( - `id` int(11) default NULL, - `user_id` int(11) default NULL, - `camera_id` int(11) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- --- Dumping data for table `photos` --- - -LOCK TABLES `photos` WRITE; -/*!40000 ALTER TABLE `photos` DISABLE KEYS */; -INSERT INTO `photos` VALUES (1,1,1); -/*!40000 ALTER TABLE `photos` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `users` --- - -DROP TABLE IF EXISTS `users`; -CREATE TABLE `users` ( - `id` int(11) default NULL, - `name` varchar(255) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- --- Dumping data for table `users` --- - -LOCK TABLES `users` WRITE; -/*!40000 ALTER TABLE `users` DISABLE KEYS */; -INSERT INTO `users` VALUES (1,'hai'),(NULL,'bai'),(NULL,'dumpty'); -/*!40000 ALTER TABLE `users` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2008-01-11 7:15:17 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 |