File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def shard(klass = nil)
1616 if @shard == NO_SHARD
1717 nil
1818 else
19- @shard || self . class . default_shard
19+ @shard || self . class . default_shard || raise ( 'You can not connect a sharded model without calling on_shard.' )
2020 end
2121 end
2222 end
Original file line number Diff line number Diff line change @@ -286,6 +286,30 @@ def clear_connection_pool
286286 end
287287 end
288288
289+ if ActiveRecord ::VERSION ::MAJOR > 3
290+ describe "ActiveRecord::Base.connection.schema_cache.columns_hash" do
291+ before do
292+ ActiveRecord ::Base . default_shard = nil
293+ end
294+
295+ it 'works for non-sharded models' do
296+ Account . connection . schema_cache . columns_hash ( 'accounts' )
297+ end
298+
299+ it 'explodes when a shard has not been specified for sharded model' do
300+ assert_raises ( 'You can not connect a sharded model without calling on_shard.' ) do
301+ Ticket . connection . schema_cache . columns_hash ( 'tickets' )
302+ end
303+ end
304+
305+ it 'explodes when a shard has been specified for sharded model' do
306+ ActiveRecord ::Base . on_first_shard do
307+ Ticket . connection . schema_cache . columns_hash ( 'tickets' )
308+ end
309+ end
310+ end
311+ end
312+
289313 describe "ActiveRecord::Base.table_exists?" do
290314 before do
291315 ActiveRecord ::Base . default_shard = nil
You can’t perform that action at this time.
0 commit comments