Skip to content

Commit 1bf0a7d

Browse files
committed
Move helpers in annotate_models_spec.rb
1 parent 6f5da38 commit 1bf0a7d

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,64 +20,6 @@
2020
'# -*- frozen_string_literal : true -*-'
2121
].freeze
2222

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-
8123
describe '.quote' do
8224
subject do
8325
AnnotateModels.quote(value)

spec/spec_helper.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,61 @@
3232
require 'annotate/helpers'
3333
require 'annotate/constants'
3434
require 'byebug'
35+
36+
def mock_index(name, params = {})
37+
double('IndexKeyDefinition',
38+
name: name,
39+
columns: params[:columns] || [],
40+
unique: params[:unique] || false,
41+
orders: params[:orders] || {},
42+
where: params[:where],
43+
using: params[:using])
44+
end
45+
46+
def mock_foreign_key(name, from_column, to_table, to_column = 'id', constraints = {})
47+
double('ForeignKeyDefinition',
48+
name: name,
49+
column: from_column,
50+
to_table: to_table,
51+
primary_key: to_column,
52+
on_delete: constraints[:on_delete],
53+
on_update: constraints[:on_update])
54+
end
55+
56+
def mock_connection(indexes = [], foreign_keys = [])
57+
double('Conn',
58+
indexes: indexes,
59+
foreign_keys: foreign_keys,
60+
supports_foreign_keys?: true)
61+
end
62+
63+
def mock_class(table_name, primary_key, columns, indexes = [], foreign_keys = [])
64+
options = {
65+
connection: mock_connection(indexes, foreign_keys),
66+
table_exists?: true,
67+
table_name: table_name,
68+
primary_key: primary_key,
69+
column_names: columns.map { |col| col.name.to_s },
70+
columns: columns,
71+
column_defaults: Hash[columns.map { |col| [col.name, col.default] }],
72+
table_name_prefix: ''
73+
}
74+
75+
double('An ActiveRecord class', options)
76+
end
77+
78+
def mock_column(name, type, options = {})
79+
default_options = {
80+
limit: nil,
81+
null: false,
82+
default: nil,
83+
sql_type: type
84+
}
85+
86+
stubs = default_options.dup
87+
stubs.merge!(options)
88+
stubs[:name] = name
89+
stubs[:type] = type
90+
91+
double('Column', stubs)
92+
end

0 commit comments

Comments
 (0)