aboutsummaryrefslogtreecommitdiffstats
path: root/spec/doubles/database.rb
blob: 3be11a91649ae2ab29cca25be2b5d66dc8e4619b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'active_record/connection_adapters/abstract/quoting'

module Fake
  class Engine
    def connection
      @conn ||= Connection.new
    end
  end

  class Connection
    include ActiveRecord::ConnectionAdapters::Quoting

    def columns(table_name, comment)
      { "users" =>
        [
          Column.new("id", :integer),
          Column.new("name", :string)
        ],
      "photos" =>
        [
          Column.new("id", :integer),
          Column.new("user_id", :integer),
          Column.new("camera_id", :integer)
        ]
      }[table_name]
    end

    def execute(*args)
      []
    end

    def quote_column_name(column_name)
      "`#{column_name}`"
    end

    def quote_table_name(table_name)
      "`#{table_name}`"
    end
  end

  class Column
    attr_reader :name, :type

    def initialize(name, type)
      @name = name
      @type = type
    end
  end
end