aboutsummaryrefslogtreecommitdiffstats
path: root/spec/doubles/database.rb
blob: f8a4b38e178efe561bb4dae4fb39956da2a07908 (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
50
51
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

    def supports_count_distinct?
      true
    end
  end

  class Column
    attr_reader :name, :type

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