Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_record_shards/shard_selection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def shard(klass = nil)
if @shard == NO_SHARD
nil
else
@shard || self.class.default_shard
@shard || self.class.default_shard || raise('You can not connect a sharded model without calling on_shard.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe next PR should be removing default_shard ;)

end
end
end
Expand Down
24 changes: 24 additions & 0 deletions test/connection_switching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,30 @@ def clear_connection_pool
end
end

if ActiveRecord::VERSION::MAJOR > 3
describe "ActiveRecord::Base.connection.schema_cache.columns_hash" do
before do
ActiveRecord::Base.default_shard = nil
end

it 'works for non-sharded models' do
Account.connection.schema_cache.columns_hash('accounts')
end

it 'explodes when a shard has not been specified for sharded model' do
assert_raises('You can not connect a sharded model without calling on_shard.') do
Ticket.connection.schema_cache.columns_hash('tickets')
end
end

it 'explodes when a shard has been specified for sharded model' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it 'works ...

ActiveRecord::Base.on_first_shard do
Ticket.connection.schema_cache.columns_hash('tickets')
end
end
end
end

describe "ActiveRecord::Base.table_exists?" do
before do
ActiveRecord::Base.default_shard = nil
Expand Down