@@ -48,7 +48,7 @@ def mock_column(name, type, options={})
48
48
stubs = default_options . dup
49
49
stubs . merge! ( options )
50
50
stubs [ :name ] = name
51
- stubs [ :type ] = type
51
+ stubs [ :type ] = type
52
52
53
53
double ( "Column" , stubs )
54
54
end
@@ -218,14 +218,20 @@ def mock_column(name, type, options={})
218
218
describe "#get_schema_info with custom options" do
219
219
def self . when_called_with ( options = { } )
220
220
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
+ ]
221
227
222
228
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
+
229
235
schema_info = AnnotateModels . get_schema_info ( klass , "Schema Info" , options )
230
236
expect ( schema_info ) . to eql ( expected )
231
237
end
@@ -268,6 +274,24 @@ def self.when_called_with(options = {})
268
274
# notes :text not null
269
275
#
270
276
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
271
295
end
272
296
273
297
describe "#get_model_class" do
0 commit comments