Skip to content

Commit cbb133e

Browse files
committed
Move helpers in annotate_models_spec.rb
1 parent 227e80c commit cbb133e

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
@@ -93,3 +93,61 @@ def self.clean?(test_rig)
9393
end
9494
end
9595
end
96+
97+
def mock_index(name, params = {})
98+
double('IndexKeyDefinition',
99+
name: name,
100+
columns: params[:columns] || [],
101+
unique: params[:unique] || false,
102+
orders: params[:orders] || {},
103+
where: params[:where],
104+
using: params[:using])
105+
end
106+
107+
def mock_foreign_key(name, from_column, to_table, to_column = 'id', constraints = {})
108+
double('ForeignKeyDefinition',
109+
name: name,
110+
column: from_column,
111+
to_table: to_table,
112+
primary_key: to_column,
113+
on_delete: constraints[:on_delete],
114+
on_update: constraints[:on_update])
115+
end
116+
117+
def mock_connection(indexes = [], foreign_keys = [])
118+
double('Conn',
119+
indexes: indexes,
120+
foreign_keys: foreign_keys,
121+
supports_foreign_keys?: true)
122+
end
123+
124+
def mock_class(table_name, primary_key, columns, indexes = [], foreign_keys = [])
125+
options = {
126+
connection: mock_connection(indexes, foreign_keys),
127+
table_exists?: true,
128+
table_name: table_name,
129+
primary_key: primary_key,
130+
column_names: columns.map { |col| col.name.to_s },
131+
columns: columns,
132+
column_defaults: Hash[columns.map { |col| [col.name, col.default] }],
133+
table_name_prefix: ''
134+
}
135+
136+
double('An ActiveRecord class', options)
137+
end
138+
139+
def mock_column(name, type, options = {})
140+
default_options = {
141+
limit: nil,
142+
null: false,
143+
default: nil,
144+
sql_type: type
145+
}
146+
147+
stubs = default_options.dup
148+
stubs.merge!(options)
149+
stubs[:name] = name
150+
stubs[:type] = type
151+
152+
double('Column', stubs)
153+
end

0 commit comments

Comments
 (0)