dbhijacker 0.4.3 → 0.4.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/Gemfile.lock +1 -1
- data/hijacker.gemspec +1 -1
- data/lib/hijacker.rb +13 -9
- data/spec/hijacker_spec.rb +3 -2
- data/spec/spec_helper.rb +4 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/hijacker.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{dbhijacker}
|
5
5
|
s.homepage = "https://github.com/crystalcommerce/hijacker"
|
6
|
-
s.version = "0.4.
|
6
|
+
s.version = "0.4.4"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Michael Xavier", "Donald Plummer", "Woody Peterson"]
|
data/lib/hijacker.rb
CHANGED
@@ -77,17 +77,18 @@ module Hijacker
|
|
77
77
|
# we're not in a sister-site situation
|
78
78
|
def self.connect_sister_site_models(db)
|
79
79
|
return if db.nil?
|
80
|
-
|
80
|
+
database = Hijacker::Database.find_by_database(db)
|
81
|
+
|
81
82
|
sister_db_connection_pool = self.processing_sister_site? ? nil : ActiveRecord::Base.connection_pool
|
82
83
|
self.config[:sister_site_models].each do |model_name|
|
83
84
|
ar_model = model_name.constantize
|
84
|
-
|
85
|
+
|
85
86
|
if !sister_db_connection_pool
|
86
|
-
ar_model.establish_connection(
|
87
|
+
ar_model.establish_connection(connection_config(database))
|
87
88
|
begin
|
88
89
|
ar_model.connection
|
89
90
|
rescue
|
90
|
-
ar_model.establish_connection(
|
91
|
+
ar_model.establish_connection(root_config)
|
91
92
|
raise Hijacker::InvalidDatabase, db
|
92
93
|
end
|
93
94
|
sister_db_connection_pool = ar_model.connection_pool
|
@@ -131,9 +132,9 @@ module Hijacker
|
|
131
132
|
|
132
133
|
return $hijacker_root_connection
|
133
134
|
end
|
134
|
-
|
135
|
+
|
135
136
|
def self.root_config
|
136
|
-
ActiveRecord::Base.configurations['root']
|
137
|
+
ActiveRecord::Base.configurations['root'].with_indifferent_access
|
137
138
|
end
|
138
139
|
|
139
140
|
# this should establish a connection to a database containing the bare minimum
|
@@ -198,9 +199,7 @@ private
|
|
198
199
|
end
|
199
200
|
|
200
201
|
def self.establish_connection_to_database(database)
|
201
|
-
|
202
|
-
::ActiveRecord::Base.establish_connection(hijacked_config.merge(:database => database.name,
|
203
|
-
:host => database.host.hostname))
|
202
|
+
::ActiveRecord::Base.establish_connection(connection_config(database))
|
204
203
|
end
|
205
204
|
|
206
205
|
# This is a hack to get query caching back on. For some reason when we
|
@@ -216,6 +215,11 @@ private
|
|
216
215
|
::ActiveRecord::Base.connection.cache do;end
|
217
216
|
end
|
218
217
|
end
|
218
|
+
|
219
|
+
def self.connection_config(database)
|
220
|
+
root_config.merge('database' => database.name,
|
221
|
+
'host' => database.host.hostname)
|
222
|
+
end
|
219
223
|
end
|
220
224
|
|
221
225
|
require 'hijacker/database'
|
data/spec/hijacker_spec.rb
CHANGED
@@ -57,7 +57,7 @@ describe Hijacker do
|
|
57
57
|
it "establishes a connection merging in the db name and the hostname" do
|
58
58
|
Hijacker::Database.create!(:database => 'elsewhere', :host => host)
|
59
59
|
ActiveRecord::Base.should_receive(:establish_connection).
|
60
|
-
with(
|
60
|
+
with(hash_including("database" => 'elsewhere', "host" => "localhost"))
|
61
61
|
subject.connect('elsewhere')
|
62
62
|
end
|
63
63
|
|
@@ -81,7 +81,8 @@ describe Hijacker do
|
|
81
81
|
|
82
82
|
it "connects with the alias to the master and the host" do
|
83
83
|
ActiveRecord::Base.should_receive(:establish_connection).
|
84
|
-
with(
|
84
|
+
with(hash_including('database' => 'master_db',
|
85
|
+
'host' => "localhost"))
|
85
86
|
subject.connect('alias_db')
|
86
87
|
end
|
87
88
|
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,10 @@ RAILS_ENV="test"
|
|
9
9
|
ENV['RAILS_ENV'] = 'test'
|
10
10
|
$:.unshift '../lib'
|
11
11
|
ActiveRecord::Base.configurations = {
|
12
|
+
"root" => {
|
13
|
+
:adapter => 'sqlite3',
|
14
|
+
:database => File.dirname(__FILE__) + "/test_database.sqlite3"
|
15
|
+
},
|
12
16
|
"test" => {
|
13
17
|
:adapter => 'sqlite3',
|
14
18
|
:database => File.dirname(__FILE__) + "/test_database.sqlite3"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbhijacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Xavier
|
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
195
|
requirements: []
|
196
196
|
|
197
197
|
rubyforge_project:
|
198
|
-
rubygems_version: 1.8.
|
198
|
+
rubygems_version: 1.8.15
|
199
199
|
signing_key:
|
200
200
|
specification_version: 3
|
201
201
|
summary: One application, multiple client databases
|