Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add new unit test and fix implementation
  • Loading branch information
oortcloud1996 committed Mar 20, 2020
commit 9b5bd5ebcb1146286de074fbbff3e60ddcd7caf3
1 change: 1 addition & 0 deletions lib/octopus/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def using(shard)
end

if Octopus.enabled?
self.connection_proxy.current_shard_dirty = true
Octopus::ScopeProxy.new(shard, self)
else
self
Expand Down
2 changes: 1 addition & 1 deletion lib/octopus/scope_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(shard, klass)
def using(shard)
fail "Nonexistent Shard Name: #{shard}" if @klass.connection.shards[shard].nil?
@current_shard = shard
@klass.connection_proxy.current_shard_dirty = true
self
end

Expand All @@ -37,7 +38,6 @@ def connection
if @klass.custom_octopus_connection && @klass.allowed_shard?(@current_shard)
# Force use of proxy, given we called 'using' explicitly to get here
@klass.connection_proxy.current_model = @klass
@klass.connection_proxy.current_shard_dirty = true
@klass.connection_proxy
else
@klass.connection
Expand Down
8 changes: 8 additions & 0 deletions spec/octopus/octopus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
end
end

it 'sends queries to master when forced to use master' do
OctopusHelper.using_environment :production_replicated do
Octopus.fully_replicated do
expect(User.using(:master).count).to eq(0)
end
end
end

it 'allows nesting' do
OctopusHelper.using_environment :production_replicated do
Octopus.fully_replicated do
Expand Down