Permalink
Browse files

add `masochistic?` predicate method for ActiveRecord::Base.connection

load masochism classes during application initialization
  • Loading branch information...
1 parent 7fb1261 commit a53ecbcb306512b8b05afdc1d7328562e0645b1f @mislav committed Apr 13, 2009
Showing with 18 additions and 1 deletion.
  1. +3 −0 init.rb
  2. +11 −1 lib/active_reload/connection_proxy.rb
  3. +4 −0 test/connection_proxy_test.rb
View
@@ -0,0 +1,3 @@
+if defined? ActiveRecord
+ require 'active_reload/connection_proxy'
+end
@@ -127,6 +127,10 @@ def respond_to?(method)
def methods
super | current.methods
end
+
+ def masochistic?
+ true
+ end
end
module ActiveRecordConnectionMethods
@@ -160,7 +164,7 @@ def self.included(base)
# Send observed_method(object) if the method exists.
def update_with_master(observed_method, object)
- if object.respond_to?(:connection) && object.connection.respond_to?(:with_master)
+ if object.respond_to?(:connection) && object.connection.masochistic?
object.connection.with_master do
update_without_master(observed_method, object)
end
@@ -170,3 +174,9 @@ def update_with_master(observed_method, object)
end
end
end
+
+ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
+ def masochistic?
+ false
+ end
+end
@@ -114,6 +114,10 @@ def test_connection_is_a_proxy
assert_equal 'ActiveReload::ConnectionProxy', connection.class.name
end
+ def test_masochistic
+ assert connection.masochistic?
+ end
+
def test_reads_go_to_slave
@slave.expects(:select_rows).with('SELECT').returns(['bar'])
assert_equal ['bar'], connection.select_rows('SELECT')

0 comments on commit a53ecbc

Please sign in to comment.