slavery 1.4.1 → 1.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6bb1c07735678dd8d9c2bd1e3c87c45ae8241ad
4
- data.tar.gz: 99bdf13f18d2979a636472caa117228297fe425b
3
+ metadata.gz: 3a72383d23b47853dae485cfffd2c582a3257aa5
4
+ data.tar.gz: 59afa26e1e61a5dc9224b57a80e8b0c20d8e76e2
5
5
  SHA512:
6
- metadata.gz: 6303b5dd01e3ba85b87fe48e8d63ce7a9bbe31a976274e247862d2beb4f09123f1189ec41e4928307157bae6c08532bf06116b140b36069b2719d778993ea8b3
7
- data.tar.gz: 1702fc7d7bf42f9fed96a209aaa7e512a2b6ecc9ca253204395cde55c684c52f9a929a75626f915007eee51c622c9ba9ff3931b85997d824c1f7e9cca95d8c09
6
+ metadata.gz: 77be949569beed8c5b2aca64531997995ad3074b46e0da6b0a359d15db98214360254bfed192f46760d827446e79221cb76a3acbbe08d56b9fbd0c62ce8db5e2
7
+ data.tar.gz: 8fa0d6c8b97e67b690b61399d736d256fcbb41a283714b6d520c1db666d5c90447d3d4d6c7082f1835bcf5e82e43a6791151452e67315447d17a8aa33fd42b9c
@@ -66,10 +66,12 @@ module Slavery
66
66
  end
67
67
 
68
68
  def slaveryable?
69
- base_transaction_depth = defined?(ActiveSupport::TestCase) &&
69
+ @base_transaction_depth ||= begin
70
+ defined?(ActiveSupport::TestCase) &&
70
71
  ActiveSupport::TestCase.respond_to?(:use_transactional_fixtures) &&
71
72
  ActiveSupport::TestCase.try(:use_transactional_fixtures) ? 1 : 0
72
- inside_transaction = master_connection.open_transactions > base_transaction_depth
73
+ end
74
+ inside_transaction = master_connection.open_transactions > @base_transaction_depth
73
75
  raise Error.new('on_slave cannot be used inside transaction block!') if inside_transaction
74
76
 
75
77
  !Slavery.disabled
@@ -1,3 +1,3 @@
1
1
  module Slavery
2
- VERSION = '1.4.1'
2
+ VERSION = '1.4.2'
3
3
  end
@@ -6,36 +6,36 @@ describe Slavery do
6
6
  end
7
7
 
8
8
  it 'sets thread local' do
9
- Slavery.on_master { on_slave?.should == false }
10
- Slavery.on_slave { on_slave?.should == true }
9
+ Slavery.on_master { expect(on_slave?).to be false }
10
+ Slavery.on_slave { expect(on_slave?).to be true }
11
11
  end
12
12
 
13
13
  it 'returns value from block' do
14
- Slavery.on_master { User.count }.should == 2
15
- Slavery.on_slave { User.count }.should == 1
14
+ expect(Slavery.on_master { User.count }).to be 2
15
+ expect(Slavery.on_slave { User.count }).to be 1
16
16
  end
17
17
 
18
18
  it 'handles nested calls' do
19
19
  # Slave -> Slave
20
20
  Slavery.on_slave do
21
- on_slave?.should == true
21
+ expect(on_slave?).to be true
22
22
 
23
23
  Slavery.on_slave do
24
- on_slave?.should == true
24
+ expect(on_slave?).to be true
25
25
  end
26
26
 
27
- on_slave?.should == true
27
+ expect(on_slave?).to be true
28
28
  end
29
29
 
30
30
  # Slave -> Master
31
31
  Slavery.on_slave do
32
- on_slave?.should == true
32
+ expect(on_slave?).to be true
33
33
 
34
34
  Slavery.on_master do
35
- on_slave?.should == false
35
+ expect(on_slave?).to be false
36
36
  end
37
37
 
38
- on_slave?.should == true
38
+ expect(on_slave?).to be true
39
39
  end
40
40
  end
41
41
 
@@ -46,36 +46,36 @@ describe Slavery do
46
46
  end
47
47
 
48
48
  it 'disables by configuration' do
49
- Slavery.stub(:disabled).and_return(false)
50
- Slavery.on_slave { User.slaveryable?.should == true }
49
+ allow(Slavery).to receive(:disabled).and_return(false)
50
+ Slavery.on_slave { expect(User.slaveryable?).to be true }
51
51
 
52
- Slavery.stub(:disabled).and_return(true)
53
- Slavery.on_slave { User.slaveryable?.should == false }
52
+ allow(Slavery).to receive(:disabled).and_return(true)
53
+ Slavery.on_slave { expect(User.slaveryable?).to be false }
54
54
  end
55
55
 
56
56
  it 'sets the Slavery database spec name by configuration' do
57
57
  Slavery.spec_key = "custom_slave"
58
- Slavery.spec_key.should eq 'custom_slave'
58
+ expect(Slavery.spec_key).to eq 'custom_slave'
59
59
 
60
60
  Slavery.spec_key = lambda{
61
61
  "kewl_slave"
62
62
  }
63
- Slavery.spec_key.should eq "kewl_slave"
63
+ expect(Slavery.spec_key).to eq "kewl_slave"
64
64
 
65
65
  Slavery.spec_key = lambda{
66
66
  "#{Slavery.env}_slave"
67
67
  }
68
- Slavery.spec_key.should eq "test_slave"
68
+ expect(Slavery.spec_key).to eq "test_slave"
69
69
  end
70
70
 
71
71
  it 'works with scopes' do
72
- User.count.should == 2
73
- User.on_slave.count.should == 1
72
+ expect(User.count).to be 2
73
+ expect(User.on_slave.count).to be 1
74
74
 
75
75
  # Why where(nil)?
76
76
  # http://stackoverflow.com/questions/18198963/with-rails-4-model-scoped-is-deprecated-but-model-all-cant-replace-it
77
- User.where(nil).to_a.size.should == 2
78
- User.on_slave.where(nil).to_a.size.should == 1
77
+ expect(User.where(nil).to_a.size).to be 2
78
+ expect(User.on_slave.where(nil).to_a.size).to be 1
79
79
  end
80
80
 
81
81
  describe 'configuration' do
@@ -95,7 +95,7 @@ describe Slavery do
95
95
  it 'connects to master if slave configuration not specified' do
96
96
  ActiveRecord::Base.configurations[Slavery.spec_key] = nil
97
97
 
98
- Slavery.on_slave { User.count }.should == 2
98
+ expect(Slavery.on_slave { User.count }).to be 2
99
99
  end
100
100
 
101
101
  it 'raises error when no configuration found' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slavery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenn Ejima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.2.2
94
+ rubygems_version: 2.6.4
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Simple, conservative slave reads for ActiveRecord