From 3ece4671438b78bd720b0a51e237d3b07ac653dd Mon Sep 17 00:00:00 2001 From: favdev111 Date: Sun, 26 Apr 2015 15:05:15 -0700 Subject: [PATCH] Add failing test to demonstrate 'SET' matching bug https://github.com/taskrabbit/makara/issues/70 --- .../makara_abstract_adapter_spec.rb | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb b/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb index 3a43651..8eeb096 100644 --- a/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb +++ b/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb @@ -29,7 +29,7 @@ 'select * from users where name = "lock in share mode"' => false }.each do |sql, should_go_to_master| - it "determines if \"#{sql}\" #{should_go_to_master ? 'requires' : 'does not require'} master" do + it "determines that \"#{sql}\" #{should_go_to_master ? 'requires' : 'does not require'} master" do proxy = klass.new(config(1,1)) expect(proxy.master_for?(sql)).to eq(should_go_to_master) end @@ -37,15 +37,39 @@ end + { + "SET @@things" => true, + "INSERT INTO wisdom ('The truth will set you free.')" => false, + "INSERT INTO wisdom ('The truth will\nset you free.')" => false, + "UPDATE dogs SET max_treats = 10 WHERE max_treats IS NULL" => false, + %Q{ + UPDATE + dogs + SET + max_treats = 10 + WHERE + max_treats IS NULL + } => false + }.each do |sql, should_send_to_all_connections| + + it "determines that \"#{sql}\" #{should_send_to_all_connections ? 'should' : 'should not'} be sent to all underlying connections" do + proxy = klass.new(config(1,1)) + proxy.master_pool.connections.each{|con| expect(con).to receive(:execute).with(sql).once} + proxy.slave_pool.connections.each do |con| + if should_send_to_all_connections + expect(con).to receive(:execute).with(sql).once + else + expect(con).to receive(:execute).with(sql).never + end + end - it 'should send SET operations to all underlying connections' do - proxy = klass.new(config(1,1)) - proxy.master_pool.connections.each{|con| expect(con).to receive(:execute).with('SET @@things').once } - proxy.slave_pool.connections.each{|con| expect(con).to receive(:execute).with('SET @@things').once } + proxy.execute(sql) - proxy.execute("SET @@things") + if should_send_to_all_connections + expect(proxy.master_context).to be_nil + end + end - expect(proxy.master_context).to be_nil end {