Skip to content

Commit f89d86f

Browse files
author
Kevin Farst
committed
Add unit tests for classified sort option
1 parent 15e699e commit f89d86f

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

spec/annotate/annotate_models_spec.rb

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def mock_column(name, type, options={})
4848
stubs = default_options.dup
4949
stubs.merge!(options)
5050
stubs[:name] = name
51-
stubs[:type] = type
51+
stubs[:type] = type
5252

5353
double("Column", stubs)
5454
end
@@ -218,14 +218,20 @@ def mock_column(name, type, options={})
218218
describe "#get_schema_info with custom options" do
219219
def self.when_called_with(options = {})
220220
expected = options.delete(:returns)
221+
default_columns = [
222+
[:id, :integer, { :limit => 8 }],
223+
[:active, :boolean, { :limit => 1 }],
224+
[:name, :string, { :limit => 50 }],
225+
[:notes, :text, { :limit => 55 }]
226+
]
221227

222228
it "should work with options = #{options}" do
223-
klass = mock_class(:users, :id, [
224-
mock_column(:id, :integer, :limit => 8),
225-
mock_column(:active, :boolean, :limit => 1),
226-
mock_column(:name, :string, :limit => 50),
227-
mock_column(:notes, :text, :limit => 55),
228-
])
229+
with_columns = (options.delete(:with_columns) || default_columns).map do |column|
230+
mock_column(column[0], column[1], column[2])
231+
end
232+
233+
klass = mock_class(:users, :id, with_columns)
234+
229235
schema_info = AnnotateModels.get_schema_info(klass, "Schema Info", options)
230236
expect(schema_info).to eql(expected)
231237
end
@@ -268,6 +274,24 @@ def self.when_called_with(options = {})
268274
# notes :text not null
269275
#
270276
EOS
277+
278+
mocked_columns_without_id = [
279+
[:active, :boolean, { :limit => 1 }],
280+
[:name, :string, { :limit => 50 }],
281+
[:notes, :text, { :limit => 55 }]
282+
]
283+
284+
when_called_with classified_sort: 'yes', with_columns: mocked_columns_without_id, returns:
285+
<<-EOS.strip_heredoc
286+
# Schema Info
287+
#
288+
# Table name: users
289+
#
290+
# active :boolean not null
291+
# name :string(50) not null
292+
# notes :text(55) not null
293+
#
294+
EOS
271295
end
272296

273297
describe "#get_model_class" do

0 commit comments

Comments
 (0)