aboutsummaryrefslogtreecommitdiffstats
path: root/test/support/fake_record.rb
diff options
context:
space:
mode:
authorRyan Davis <ryand-ruby@zenspider.com>2010-10-18 15:41:21 -0700
committerRyan Davis <ryand-ruby@zenspider.com>2010-10-18 15:41:21 -0700
commite1ebe6e949ef3674434bfa90d271a7b74c2ac153 (patch)
treeb0c340817d75bddf9840c97a946a7217ff12e8ab /test/support/fake_record.rb
parent7959e55ead84be096247d9622404d1c60ca21c88 (diff)
downloadrails-e1ebe6e949ef3674434bfa90d271a7b74c2ac153.tar.gz
rails-e1ebe6e949ef3674434bfa90d271a7b74c2ac153.tar.bz2
rails-e1ebe6e949ef3674434bfa90d271a7b74c2ac153.zip
Fisting arel specs -- still needs tree_manager and cleanup
Diffstat (limited to 'test/support/fake_record.rb')
-rw-r--r--test/support/fake_record.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/support/fake_record.rb b/test/support/fake_record.rb
new file mode 100644
index 0000000000..ef3cc6a291
--- /dev/null
+++ b/test/support/fake_record.rb
@@ -0,0 +1,89 @@
+module FakeRecord
+ class Column < Struct.new(:name, :type)
+ end
+
+ class Connection
+ attr_reader :tables
+
+ def initialize
+ @tables = %w{ users photos developers }
+ @columns = {
+ 'users' => [
+ Column.new('id', :integer),
+ Column.new('name', :string)
+ ]
+ }
+ @primary_keys = {
+ 'users' => 'id'
+ }
+ end
+
+ def primary_key name
+ @primary_keys[name.to_s]
+ end
+
+ def table_exists? name
+ @tables.include? name.to_s
+ end
+
+ def columns name, message = nil
+ @columns[name.to_s]
+ end
+
+ def quote_table_name name
+ "\"#{name.to_s}\""
+ end
+
+ def quote_column_name name
+ "\"#{name.to_s}\""
+ end
+
+ def quote thing, column = nil
+ if column && column.type == :integer
+ return 'NULL' if thing.nil?
+ return thing.to_i
+ end
+
+ case thing
+ when true
+ "'t'"
+ when false
+ "'f'"
+ when nil
+ 'NULL'
+ when Numeric
+ thing
+ else
+ "'#{thing}'"
+ end
+ end
+ end
+
+ class ConnectionPool
+ class Spec < Struct.new(:config)
+ end
+
+ attr_reader :spec, :connection
+
+ def initialize
+ @spec = Spec.new(:adapter => 'sqlite3')
+ @connection = Connection.new
+ end
+
+ def with_connection
+ yield connection
+ end
+ end
+
+ class Base
+ attr_accessor :connection_pool
+
+ def initialize
+ @connection_pool = ConnectionPool.new
+ end
+
+ def connection
+ connection_pool.connection
+ end
+ end
+end