schoefmax-multi_db 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -94,6 +94,9 @@ And add this to your ApplicationController:
94
94
 
95
95
  after_filter { ActiveRecord::Base.connection_proxy.next_reader! }
96
96
 
97
+ *NOTE*: It's not possible to toggle this mode in a running process, as the dynamically
98
+ generated methods will have the initially defined "stickyness" built in.
99
+
97
100
  === Usage outside of Rails
98
101
 
99
102
  You can use multi_db together with other framworks or in standalone scripts.
@@ -20,7 +20,9 @@ module MultiDb
20
20
  end
21
21
 
22
22
  def reload_with_master(*args, &block)
23
- connection_proxy.with_master { reload_without_master }
23
+ self.class.connection_proxy.with_master do
24
+ reload_without_master(*args, &block)
25
+ end
24
26
  end
25
27
  end
26
28
  end
data/multi_db.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{multi_db}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Maximilian Sch\303\266fmann"]
@@ -12,7 +12,11 @@ describe MultiDb::ConnectionProxy do
12
12
  before(:all) do
13
13
  ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG
14
14
  ActiveRecord::Base.establish_connection :test
15
+ ActiveRecord::Migration.verbose = false
16
+ ActiveRecord::Migration.create_table(:master_models, :force => true) {}
15
17
  class MasterModel < ActiveRecord::Base; end
18
+ ActiveRecord::Migration.create_table(:foo_models, :force => true) {|t| t.string :bar}
19
+ class FooModel < ActiveRecord::Base; end
16
20
  @sql = 'SELECT 1 + 1 FROM DUAL'
17
21
  end
18
22
 
@@ -24,6 +28,10 @@ describe MultiDb::ConnectionProxy do
24
28
  @slave2 = MultiDb::SlaveDatabase2.retrieve_connection
25
29
  end
26
30
 
31
+ after(:each) do
32
+ ActiveRecord::Base.send :alias_method, :reload, :reload_without_master
33
+ end
34
+
27
35
  it 'AR::B#connection should return an instance of MultiDb::ConnectionProxy' do
28
36
  ActiveRecord::Base.connection.should be_kind_of(MultiDb::ConnectionProxy)
29
37
  end
@@ -138,13 +146,23 @@ describe MultiDb::ConnectionProxy do
138
146
  MasterModel.retrieve_connection.should_receive(:select_all).once.and_return([])
139
147
  MasterModel.first
140
148
  end
149
+
150
+ it 'should reload models from the master' do
151
+ foo = FooModel.create!(:bar => 'baz')
152
+ foo.bar = "not_saved"
153
+ @slave1.should_not_receive(:select_all)
154
+ @slave2.should_not_receive(:select_all)
155
+ foo.reload
156
+ # we didn't stub @master#select_all here, check that we actually hit the db
157
+ foo.bar.should == 'baz'
158
+ end
141
159
 
142
160
  describe 'with sticky_slave ' do
143
161
 
144
162
  before { MultiDb::ConnectionProxy.sticky_slave = true }
145
163
  after { MultiDb::ConnectionProxy.sticky_slave = false }
146
164
 
147
- it 'should not switch to the next reader when #sticky_master is true' do
165
+ it 'should not switch to the next reader automatically' do
148
166
  @slave1.should_receive(:select_all).exactly(3)
149
167
  @slave2.should_receive(:select_all).exactly(0)
150
168
  3.times { @proxy.select_all(@sql) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schoefmax-multi_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Maximilian Sch\xC3\xB6fmann"
@@ -14,6 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements: