|
20 | 20 | '# -*- frozen_string_literal : true -*-' |
21 | 21 | ].freeze |
22 | 22 |
|
23 | | - def mock_index(name, params = {}) |
24 | | - double('IndexKeyDefinition', |
25 | | - name: name, |
26 | | - columns: params[:columns] || [], |
27 | | - unique: params[:unique] || false, |
28 | | - orders: params[:orders] || {}, |
29 | | - where: params[:where], |
30 | | - using: params[:using]) |
31 | | - end |
32 | | - |
33 | | - def mock_foreign_key(name, from_column, to_table, to_column = 'id', constraints = {}) |
34 | | - double('ForeignKeyDefinition', |
35 | | - name: name, |
36 | | - column: from_column, |
37 | | - to_table: to_table, |
38 | | - primary_key: to_column, |
39 | | - on_delete: constraints[:on_delete], |
40 | | - on_update: constraints[:on_update]) |
41 | | - end |
42 | | - |
43 | | - def mock_connection(indexes = [], foreign_keys = []) |
44 | | - double('Conn', |
45 | | - indexes: indexes, |
46 | | - foreign_keys: foreign_keys, |
47 | | - supports_foreign_keys?: true) |
48 | | - end |
49 | | - |
50 | | - def mock_class(table_name, primary_key, columns, indexes = [], foreign_keys = []) |
51 | | - options = { |
52 | | - connection: mock_connection(indexes, foreign_keys), |
53 | | - table_exists?: true, |
54 | | - table_name: table_name, |
55 | | - primary_key: primary_key, |
56 | | - column_names: columns.map { |col| col.name.to_s }, |
57 | | - columns: columns, |
58 | | - column_defaults: Hash[columns.map { |col| [col.name, col.default] }], |
59 | | - table_name_prefix: '' |
60 | | - } |
61 | | - |
62 | | - double('An ActiveRecord class', options) |
63 | | - end |
64 | | - |
65 | | - def mock_column(name, type, options = {}) |
66 | | - default_options = { |
67 | | - limit: nil, |
68 | | - null: false, |
69 | | - default: nil, |
70 | | - sql_type: type |
71 | | - } |
72 | | - |
73 | | - stubs = default_options.dup |
74 | | - stubs.merge!(options) |
75 | | - stubs[:name] = name |
76 | | - stubs[:type] = type |
77 | | - |
78 | | - double('Column', stubs) |
79 | | - end |
80 | | - |
81 | 23 | describe '.quote' do |
82 | 24 | subject do |
83 | 25 | AnnotateModels.quote(value) |
|
0 commit comments