active_record_host_pool 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed2c6298e6e97323f95bf2ebdb3414c64943b129
4
- data.tar.gz: a3ffbacc3eb9b673f6a34d2f5aa188f53b10a1c8
3
+ metadata.gz: 9e48bcf35e8ac749c0b576cc314f936e77d6cda0
4
+ data.tar.gz: b18961c4654d98d8a9ffce35ec472a535a6e237f
5
5
  SHA512:
6
- metadata.gz: 5dc67a54dacb5c5f3d681b20edf988492d4a7ae6214d3c1263069a0ae467569daef7021b9a394679beddf831702ff9779ca8cf8ed51485c0a274fe61833f5483
7
- data.tar.gz: 9987fbf49b040a43df296b26b754d124e903010f6dfcc300fbe6a78854aceffda6700eb2abaee8f4c8b4080aa91b9554901cce94811dd427451ca605eb66c825
6
+ metadata.gz: e18c73fa7ade1da87b4faeda2a76705c928a31706288a6264fd6a9d3315b4e889ea0a6cfbd9f37a856ae9422c8110fb638bb1794c5e6721b3cd7909bc2845668
7
+ data.tar.gz: febcbd225b0e79d8895ec23a223dc8c17dc06a241f7adc238dced5f0906ee77313f65878a2dc045dd98c1d8915675e561470611905c928d0fb27847b4bb6cd3e
@@ -104,7 +104,7 @@ module ActiveRecordHostPool
104
104
  end
105
105
 
106
106
  def _pool_key
107
- @_pool_key ||= "#{@config[:host]}/#{@config[:port]}/#{@config[:socket]}/#{@config[:username]}"
107
+ @_pool_key ||= "#{@config[:host]}/#{@config[:port]}/#{@config[:socket]}/#{@config[:username]}/#{@config[:slave] && 'slave'}"
108
108
  end
109
109
 
110
110
  def _connection_pool(auto_create=true)
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordHostPool
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
data/test/database.yml CHANGED
@@ -8,6 +8,17 @@ test_host_1_db_1:
8
8
  host: <%= mysql.host %>
9
9
  reconnect: true
10
10
 
11
+ # Mimic configurations as read by active_record_shards/ar_flexmaster
12
+ test_host_1_db_1_slave:
13
+ adapter: mysql2
14
+ encoding: utf8
15
+ database: arhp_test_1_slave
16
+ username: <%= mysql.user %>
17
+ password: <%= mysql.password %>
18
+ host: <%= mysql.host %>
19
+ reconnect: true
20
+ slave: true
21
+
11
22
  test_host_1_db_2:
12
23
  adapter: mysql2
13
24
  encoding: utf8
data/test/helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'minitest/autorun'
4
4
  require 'active_record_host_pool'
5
5
  require 'logger'
6
6
  require 'mocha/setup'
7
- require 'erb'
7
+ require 'phenix'
8
8
 
9
9
  RAILS_ENV = "test"
10
10
 
@@ -12,28 +12,12 @@ Minitest::Test = MiniTest::Unit::TestCase unless defined?(::Minitest::Test)
12
12
 
13
13
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/test.log")
14
14
 
15
- config_content = IO.read(File.dirname(__FILE__) + '/database.yml')
16
- config_content = ERB.new(config_content).result
17
- config = YAML.load(config_content)
18
-
19
- ActiveRecord::Base.configurations = config
15
+ Phenix.configure do |config|
16
+ config.skip_database = ->(name, conf) { name =~ /not_there/ || conf['username'] == 'travis' }
17
+ end
20
18
 
21
19
  module ARHPTestSetup
22
20
  private
23
- def arhp_create_databases
24
- for_each_database do |name, conf|
25
- run_mysql_command(conf, "CREATE DATABASE #{conf['database']}")
26
- ActiveRecord::Base.establish_connection(name.to_sym)
27
- ActiveRecord::Migration.verbose = false
28
- load(File.dirname(__FILE__) + "/schema.rb")
29
- end
30
- end
31
-
32
- def arhp_drop_databases
33
- for_each_database do |name, conf|
34
- run_mysql_command(conf, "DROP DATABASE IF EXISTS #{conf['database']}")
35
- end
36
- end
37
21
 
38
22
  def arhp_create_models
39
23
  return if Object.const_defined?("Test1")
@@ -43,6 +27,11 @@ module ARHPTestSetup
43
27
  establish_connection(:test_host_1_db_1)
44
28
  end
45
29
 
30
+ class Test1Slave < ActiveRecord::Base
31
+ self.table_name = "tests"
32
+ establish_connection(:test_host_1_db_1_slave)
33
+ end
34
+
46
35
  class Test2 < ActiveRecord::Base
47
36
  self.table_name = "tests"
48
37
  establish_connection(:test_host_1_db_2)
@@ -65,28 +54,6 @@ module ARHPTestSetup
65
54
  EOL
66
55
  end
67
56
 
68
- def for_each_database
69
- ActiveRecord::Base.configurations.each do |name, conf|
70
- next if name =~ /not_there/
71
- next if conf['username'] == 'travis'
72
- yield(name, conf)
73
- end
74
- end
75
-
76
- def run_mysql_command(conf, command)
77
- @mysql_command ||= begin
78
- commands = [
79
- 'mysql',
80
- "--user=#{conf['username']}"
81
- ]
82
- commands << "--host=#{conf['host']}" if conf['host'].present?
83
- commands << "--port=#{conf['port']}" if conf['port'].present?
84
- commands << " --password=#{conf['password']} 2> /dev/null" if conf['password'].present?
85
- commands.join(' ')
86
- end
87
- `echo "#{command}" | #{@mysql_command}`
88
- end
89
-
90
57
  def current_database(klass)
91
58
  klass.connection.select_value("select DATABASE()")
92
59
  end
data/test/test_arhp.rb CHANGED
@@ -1,15 +1,14 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative 'helper'
2
2
 
3
3
  class ActiveRecordHostPoolTest < Minitest::Test
4
4
  include ARHPTestSetup
5
5
  def setup
6
- arhp_drop_databases
7
- arhp_create_databases
6
+ Phenix.rise!
8
7
  arhp_create_models
9
8
  end
10
9
 
11
10
  def teardown
12
- arhp_drop_databases
11
+ Phenix.burn!
13
12
  end
14
13
 
15
14
  def test_models_with_matching_hosts_should_share_a_connection
@@ -25,6 +24,10 @@ class ActiveRecordHostPoolTest < Minitest::Test
25
24
  assert(Test4.connection.raw_connection != Test5.connection.raw_connection)
26
25
  end
27
26
 
27
+ def test_models_without_match_slave_status_should_not_share_a_connection
28
+ assert(Test1.connection.raw_connection != Test1Slave.connection.raw_connection)
29
+ end
30
+
28
31
  def test_should_select_on_correct_database
29
32
  action_should_use_correct_database(:select_all, "select 1")
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_host_pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,6 +44,90 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mysql2
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: shoulda
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: mocha
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: bump
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: phenix
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
47
131
  description: ''
48
132
  email:
49
133
  - ben@gimbo.net
@@ -84,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
168
  version: '0'
85
169
  requirements: []
86
170
  rubyforge_project:
87
- rubygems_version: 2.5.0
171
+ rubygems_version: 2.4.5.1
88
172
  signing_key:
89
173
  specification_version: 4
90
174
  summary: Allow ActiveRecord to share a connection to multiple databases on the same