diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 16:23:25 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 16:23:25 -0700 |
commit | 72a857a7822a308498d15064390ed2f8153f4db0 (patch) | |
tree | 110f25a17fb9bed84b8b6ea0d1665c1dcef48078 /spec/support | |
parent | 6549b3c8ed13c1c5bf9d5772d3f02c0557e01e01 (diff) | |
download | rails-72a857a7822a308498d15064390ed2f8153f4db0.tar.gz rails-72a857a7822a308498d15064390ed2f8153f4db0.tar.bz2 rails-72a857a7822a308498d15064390ed2f8153f4db0.zip |
specs run without an AR connection
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/fake_record.rb | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/spec/support/fake_record.rb b/spec/support/fake_record.rb new file mode 100644 index 0000000000..eb6aa2c472 --- /dev/null +++ b/spec/support/fake_record.rb @@ -0,0 +1,85 @@ +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 + 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 + + def initialize + @spec = Spec.new('sqlite3') + end + + def connection + Connection.new + end + + def with_connection + yield connection + end + end + + class Base + def self.connection_pool + ConnectionPool.new + end + + def self.connection + connection_pool.connection + end + end +end |