ar-octopus 0.0.28 → 0.0.29
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +69 -0
- data/README.mkdn +23 -1
- data/Rakefile +12 -19
- data/ar-octopus.gemspec +16 -6
- data/lib/octopus.rb +1 -1
- data/lib/octopus/association.rb +1 -0
- data/lib/octopus/model.rb +10 -3
- data/lib/octopus/proxy.rb +4 -1
- data/sample_app/Gemfile +2 -2
- data/sample_app/Gemfile.lock +50 -50
- data/sample_app/app/models/item.rb +1 -0
- data/sample_app/app/models/user.rb +1 -0
- data/spec/config/shards.yml +22 -0
- data/spec/database_models.rb +1 -0
- data/spec/octopus/association_spec.rb +23 -14
- data/spec/octopus/controller_spec.rb +1 -1
- data/spec/octopus/model_spec.rb +1 -1
- data/spec/octopus/proxy_spec.rb +7 -0
- data/spec/octopus/sharded_spec.rb +33 -0
- data/spec/spec_helper.rb +7 -7
- metadata +63 -27
- data/spec/spec.opts +0 -2
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionpack (3.0.0.rc)
|
6
|
+
activemodel (= 3.0.0.rc)
|
7
|
+
activesupport (= 3.0.0.rc)
|
8
|
+
builder (~> 2.1.2)
|
9
|
+
erubis (~> 2.6.6)
|
10
|
+
i18n (~> 0.4.1)
|
11
|
+
rack (~> 1.2.1)
|
12
|
+
rack-mount (~> 0.6.9)
|
13
|
+
rack-test (~> 0.5.4)
|
14
|
+
tzinfo (~> 0.3.22)
|
15
|
+
activemodel (3.0.0.rc)
|
16
|
+
activesupport (= 3.0.0.rc)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
i18n (~> 0.4.1)
|
19
|
+
activerecord (3.0.0.rc)
|
20
|
+
activemodel (= 3.0.0.rc)
|
21
|
+
activesupport (= 3.0.0.rc)
|
22
|
+
arel (~> 0.4.0)
|
23
|
+
tzinfo (~> 0.3.22)
|
24
|
+
activesupport (3.0.0.rc)
|
25
|
+
arel (0.4.0)
|
26
|
+
activesupport (>= 3.0.0.beta)
|
27
|
+
builder (2.1.2)
|
28
|
+
diff-lcs (1.1.2)
|
29
|
+
erubis (2.6.6)
|
30
|
+
abstract (>= 1.0.0)
|
31
|
+
gemcutter (0.6.1)
|
32
|
+
git (1.2.5)
|
33
|
+
i18n (0.4.1)
|
34
|
+
jeweler (1.4.0)
|
35
|
+
gemcutter (>= 0.1.0)
|
36
|
+
git (>= 1.2.5)
|
37
|
+
rubyforge (>= 2.0.0)
|
38
|
+
json_pure (1.4.3)
|
39
|
+
mysql (2.8.1)
|
40
|
+
pg (0.9.0)
|
41
|
+
rack (1.2.1)
|
42
|
+
rack-mount (0.6.9)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
rack-test (0.5.4)
|
45
|
+
rack (>= 1.0)
|
46
|
+
rspec (2.0.0.beta.19)
|
47
|
+
rspec-core (= 2.0.0.beta.19)
|
48
|
+
rspec-expectations (= 2.0.0.beta.19)
|
49
|
+
rspec-mocks (= 2.0.0.beta.19)
|
50
|
+
rspec-core (2.0.0.beta.19)
|
51
|
+
rspec-expectations (2.0.0.beta.19)
|
52
|
+
diff-lcs (>= 1.1.2)
|
53
|
+
rspec-mocks (2.0.0.beta.19)
|
54
|
+
rubyforge (2.0.4)
|
55
|
+
json_pure (>= 1.1.7)
|
56
|
+
sqlite3-ruby (1.3.1)
|
57
|
+
tzinfo (0.3.22)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
actionpack (>= 3.0.0.rc)
|
64
|
+
activerecord (>= 3.0.0.rc)
|
65
|
+
jeweler (>= 1.4)
|
66
|
+
mysql (>= 2.8.1)
|
67
|
+
pg (>= 0.9.0)
|
68
|
+
rspec (= 2.0.0.beta.19)
|
69
|
+
sqlite3-ruby (>= 1.3.1)
|
data/README.mkdn
CHANGED
@@ -116,7 +116,29 @@ If you want to send a specified action, or all actions from a controller, to a s
|
|
116
116
|
|
117
117
|
To see the complete list of features and syntax, please check out our <a href="http://wiki.github.com/tchandy/octopus/"> Wiki</a>
|
118
118
|
Wanna see sample rails applications using octopus features? please check it out: <a href="http://github.com/tchandy/octopus_sharding_example">Sharding Example</a> and <a href="http://github.com/tchandy/octopus_replication_example">Replication Example</a>
|
119
|
-
|
119
|
+
|
120
|
+
|
121
|
+
## Contributing with Octopus
|
122
|
+
Contributors are welcome! To run the test suite, you need mysql, postgresql and sqlite3 installed. In order to install necessary gems, this is what you need to setup your Octopus development environment:
|
123
|
+
|
124
|
+
<pre>
|
125
|
+
git clone http://github.com/tchandy/octopus.git
|
126
|
+
cd octopus
|
127
|
+
bundle install
|
128
|
+
rake db:prepare
|
129
|
+
rake spec
|
130
|
+
</pre>
|
131
|
+
|
132
|
+
To run our integrations tests inside sample_app, you need to following commands:
|
133
|
+
|
134
|
+
<pre>
|
135
|
+
cd sample_app
|
136
|
+
bundle install
|
137
|
+
cucumber
|
138
|
+
</pre>
|
139
|
+
|
140
|
+
If you are having issues with octopus spec suite, check all databases password inside the config files, and make sure that your passwords/permissions are right.
|
141
|
+
|
120
142
|
## Thanks
|
121
143
|
|
122
144
|
This project is sponsored by the <a href="http://www.rubysoc.org">Ruby Summer of Code</a>,
|
data/Rakefile
CHANGED
@@ -2,7 +2,10 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
|
2
2
|
$LOAD_PATH << (File.dirname(__FILE__) + '/spec')
|
3
3
|
require 'rubygems'
|
4
4
|
require 'rake'
|
5
|
+
require 'rake/tasklib'
|
5
6
|
require "yaml"
|
7
|
+
require "bundler"
|
8
|
+
Bundler.setup()
|
6
9
|
|
7
10
|
begin
|
8
11
|
require 'metric_fu'
|
@@ -27,43 +30,33 @@ begin
|
|
27
30
|
gem.email = "tchandy@gmail.com"
|
28
31
|
gem.homepage = "http://github.com/tchandy/octopus"
|
29
32
|
gem.authors = ["Thiago Pradi", "Mike Perham"]
|
30
|
-
gem.add_development_dependency "rspec", ">=
|
33
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
|
31
34
|
gem.add_development_dependency "mysql", ">= 2.8.1"
|
32
35
|
gem.add_development_dependency "pg", ">= 0.9.0"
|
33
36
|
gem.add_development_dependency "sqlite3-ruby", ">= 1.3.1"
|
37
|
+
gem.add_development_dependency "jeweler", ">= 1.4"
|
38
|
+
gem.add_development_dependency "actionpack", ">= 2.3"
|
34
39
|
gem.add_dependency('activerecord', '>= 2.3')
|
35
|
-
gem.version = "0.0.
|
40
|
+
gem.version = "0.0.29"
|
36
41
|
end
|
37
42
|
Jeweler::GemcutterTasks.new
|
38
43
|
rescue LoadError
|
39
44
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
40
45
|
end
|
41
46
|
|
42
|
-
require '
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
require 'rspec/core'
|
48
|
+
require 'rspec/core/rake_task'
|
49
|
+
|
50
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
46
51
|
end
|
47
52
|
|
48
|
-
|
49
|
-
spec.libs << 'lib' << 'spec'
|
50
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
51
|
-
spec.rcov = true
|
53
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
52
54
|
end
|
53
55
|
|
54
56
|
task :spec => :check_dependencies
|
55
57
|
|
56
58
|
task :default => :spec
|
57
59
|
|
58
|
-
require 'rake/rdoctask'
|
59
|
-
Rake::RDocTask.new do |rdoc|
|
60
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
61
|
-
|
62
|
-
rdoc.rdoc_dir = 'rdoc'
|
63
|
-
rdoc.title = "octopus #{version}"
|
64
|
-
rdoc.rdoc_files.include('README*')
|
65
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
66
|
-
end
|
67
60
|
|
68
61
|
namespace :db do
|
69
62
|
desc 'Build the databases for tests'
|
data/ar-octopus.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ar-octopus}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.29"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thiago Pradi", "Mike Perham"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-30}
|
13
13
|
s.description = %q{This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards.}
|
14
14
|
s.email = %q{tchandy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,6 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
20
23
|
"README.mkdn",
|
21
24
|
"Rakefile",
|
22
25
|
"VERSION",
|
@@ -128,8 +131,8 @@ Gem::Specification.new do |s|
|
|
128
131
|
"spec/octopus/proxy_spec.rb",
|
129
132
|
"spec/octopus/replication_specs.rb",
|
130
133
|
"spec/octopus/scope_proxy_spec.rb",
|
134
|
+
"spec/octopus/sharded_spec.rb",
|
131
135
|
"spec/octopus_helper.rb",
|
132
|
-
"spec/spec.opts",
|
133
136
|
"spec/spec_helper.rb"
|
134
137
|
]
|
135
138
|
s.homepage = %q{http://github.com/tchandy/octopus}
|
@@ -161,6 +164,7 @@ Gem::Specification.new do |s|
|
|
161
164
|
"spec/octopus/proxy_spec.rb",
|
162
165
|
"spec/octopus/replication_specs.rb",
|
163
166
|
"spec/octopus/scope_proxy_spec.rb",
|
167
|
+
"spec/octopus/sharded_spec.rb",
|
164
168
|
"spec/octopus_helper.rb",
|
165
169
|
"spec/spec_helper.rb"
|
166
170
|
]
|
@@ -170,23 +174,29 @@ Gem::Specification.new do |s|
|
|
170
174
|
s.specification_version = 3
|
171
175
|
|
172
176
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
173
|
-
s.add_development_dependency(%q<rspec>, [">=
|
177
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
174
178
|
s.add_development_dependency(%q<mysql>, [">= 2.8.1"])
|
175
179
|
s.add_development_dependency(%q<pg>, [">= 0.9.0"])
|
176
180
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
|
181
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.4"])
|
182
|
+
s.add_development_dependency(%q<actionpack>, [">= 2.3"])
|
177
183
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
|
178
184
|
else
|
179
|
-
s.add_dependency(%q<rspec>, [">=
|
185
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
180
186
|
s.add_dependency(%q<mysql>, [">= 2.8.1"])
|
181
187
|
s.add_dependency(%q<pg>, [">= 0.9.0"])
|
182
188
|
s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
|
189
|
+
s.add_dependency(%q<jeweler>, [">= 1.4"])
|
190
|
+
s.add_dependency(%q<actionpack>, [">= 2.3"])
|
183
191
|
s.add_dependency(%q<activerecord>, [">= 2.3"])
|
184
192
|
end
|
185
193
|
else
|
186
|
-
s.add_dependency(%q<rspec>, [">=
|
194
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
187
195
|
s.add_dependency(%q<mysql>, [">= 2.8.1"])
|
188
196
|
s.add_dependency(%q<pg>, [">= 0.9.0"])
|
189
197
|
s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
|
198
|
+
s.add_dependency(%q<jeweler>, [">= 1.4"])
|
199
|
+
s.add_dependency(%q<actionpack>, [">= 2.3"])
|
190
200
|
s.add_dependency(%q<activerecord>, [">= 2.3"])
|
191
201
|
end
|
192
202
|
end
|
data/lib/octopus.rb
CHANGED
@@ -27,7 +27,7 @@ module Octopus
|
|
27
27
|
|
28
28
|
# This is the default way to do Octopus Setup
|
29
29
|
# Available variables:
|
30
|
-
# :enviroments => the enviroments that octopus will run. default:
|
30
|
+
# :enviroments => the enviroments that octopus will run. default: 'production'
|
31
31
|
def self.setup
|
32
32
|
yield self
|
33
33
|
end
|
data/lib/octopus/association.rb
CHANGED
@@ -5,6 +5,7 @@ module Octopus::Association
|
|
5
5
|
|
6
6
|
module InstanceMethods
|
7
7
|
def set_connection_on_association(record)
|
8
|
+
return if !self.connection.respond_to?(:current_shard) || !self.respond_to?(:current_shard)
|
8
9
|
if !record.current_shard.nil? && !self.current_shard.nil? && record.current_shard != self.current_shard
|
9
10
|
raise "Association Error: Records are from different shards"
|
10
11
|
end
|
data/lib/octopus/model.rb
CHANGED
@@ -42,14 +42,17 @@ module Octopus::Model
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def hijack_connection()
|
45
|
+
|
46
|
+
def self.should_use_normal_connection?
|
47
|
+
defined?(Rails) && Octopus.config() && !Octopus.enviroments.include?(Rails.env.to_s)
|
48
|
+
end
|
49
|
+
|
45
50
|
def self.connection_proxy
|
46
51
|
Thread.current[:connection_proxy] ||= Octopus::Proxy.new(Octopus.config())
|
47
52
|
end
|
48
53
|
|
49
54
|
def self.connection_with_octopus()
|
50
|
-
|
51
|
-
return connection_without_octopus()
|
52
|
-
end
|
55
|
+
return connection_without_octopus() if should_use_normal_connection?
|
53
56
|
|
54
57
|
self.connection_proxy().current_model = self
|
55
58
|
self.connection_proxy()
|
@@ -79,6 +82,10 @@ module Octopus::Model
|
|
79
82
|
def replicated_model()
|
80
83
|
write_inheritable_attribute(:replicated, true)
|
81
84
|
end
|
85
|
+
|
86
|
+
def sharded_model()
|
87
|
+
write_inheritable_attribute(:sharded, true)
|
88
|
+
end
|
82
89
|
end
|
83
90
|
end
|
84
91
|
|
data/lib/octopus/proxy.rb
CHANGED
@@ -11,8 +11,11 @@ class Octopus::Proxy
|
|
11
11
|
@groups = {}
|
12
12
|
@shards[:master] = ActiveRecord::Base.connection_pool()
|
13
13
|
@current_shard = :master
|
14
|
+
if !config.nil?
|
15
|
+
@entire_sharded = config['entire_sharded']
|
16
|
+
shards_config = config[Octopus.rails_env()]
|
17
|
+
end
|
14
18
|
|
15
|
-
shards_config = config[Octopus.rails_env()] if !config.nil?
|
16
19
|
shards_config ||= []
|
17
20
|
|
18
21
|
shards_config.each do |key, value|
|
data/sample_app/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '3.0.0.
|
3
|
+
gem 'rails', '3.0.0.rc'
|
4
4
|
|
5
5
|
# Bundle edge Rails instead:
|
6
6
|
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
@@ -17,6 +17,6 @@ group :test do
|
|
17
17
|
gem 'spork'
|
18
18
|
gem 'launchy'
|
19
19
|
gem "rspec-rails", ">= 2.0.0.beta.16"
|
20
|
-
gem 'ruby-debug'
|
20
|
+
gem 'ruby-debug' if RUBY_VERSION < "1.9"
|
21
21
|
gem "aruba"
|
22
22
|
end
|
data/sample_app/Gemfile.lock
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git://github.com/tchandy/octopus.git
|
3
|
-
revision:
|
3
|
+
revision: 074e64f
|
4
4
|
specs:
|
5
|
-
ar-octopus (0.0.
|
6
|
-
activerecord (>= 3
|
5
|
+
ar-octopus (0.0.28)
|
6
|
+
activerecord (>= 2.3)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
abstract (1.0.0)
|
12
|
-
actionmailer (3.0.0.
|
13
|
-
actionpack (= 3.0.0.
|
14
|
-
mail (~> 2.2.
|
15
|
-
actionpack (3.0.0.
|
16
|
-
activemodel (= 3.0.0.
|
17
|
-
activesupport (= 3.0.0.
|
12
|
+
actionmailer (3.0.0.rc)
|
13
|
+
actionpack (= 3.0.0.rc)
|
14
|
+
mail (~> 2.2.5)
|
15
|
+
actionpack (3.0.0.rc)
|
16
|
+
activemodel (= 3.0.0.rc)
|
17
|
+
activesupport (= 3.0.0.rc)
|
18
18
|
builder (~> 2.1.2)
|
19
|
-
erubis (~> 2.6.
|
19
|
+
erubis (~> 2.6.6)
|
20
20
|
i18n (~> 0.4.1)
|
21
|
-
rack (~> 1.1
|
22
|
-
rack-mount (~> 0.6.
|
21
|
+
rack (~> 1.2.1)
|
22
|
+
rack-mount (~> 0.6.9)
|
23
23
|
rack-test (~> 0.5.4)
|
24
|
-
tzinfo (~> 0.3.
|
25
|
-
activemodel (3.0.0.
|
26
|
-
activesupport (= 3.0.0.
|
24
|
+
tzinfo (~> 0.3.22)
|
25
|
+
activemodel (3.0.0.rc)
|
26
|
+
activesupport (= 3.0.0.rc)
|
27
27
|
builder (~> 2.1.2)
|
28
28
|
i18n (~> 0.4.1)
|
29
|
-
activerecord (3.0.0.
|
30
|
-
activemodel (= 3.0.0.
|
31
|
-
activesupport (= 3.0.0.
|
29
|
+
activerecord (3.0.0.rc)
|
30
|
+
activemodel (= 3.0.0.rc)
|
31
|
+
activesupport (= 3.0.0.rc)
|
32
32
|
arel (~> 0.4.0)
|
33
|
-
tzinfo (~> 0.3.
|
34
|
-
activeresource (3.0.0.
|
35
|
-
activemodel (= 3.0.0.
|
36
|
-
activesupport (= 3.0.0.
|
37
|
-
activesupport (3.0.0.
|
33
|
+
tzinfo (~> 0.3.22)
|
34
|
+
activeresource (3.0.0.rc)
|
35
|
+
activemodel (= 3.0.0.rc)
|
36
|
+
activesupport (= 3.0.0.rc)
|
37
|
+
activesupport (3.0.0.rc)
|
38
38
|
arel (0.4.0)
|
39
39
|
activesupport (>= 3.0.0.beta)
|
40
40
|
aruba (0.2.1)
|
@@ -78,55 +78,55 @@ GEM
|
|
78
78
|
mime-types (1.16)
|
79
79
|
nokogiri (1.4.2)
|
80
80
|
polyglot (0.3.1)
|
81
|
-
rack (1.1
|
81
|
+
rack (1.2.1)
|
82
82
|
rack-mount (0.6.9)
|
83
83
|
rack (>= 1.0.0)
|
84
84
|
rack-test (0.5.4)
|
85
85
|
rack (>= 1.0)
|
86
|
-
rails (3.0.0.
|
87
|
-
actionmailer (= 3.0.0.
|
88
|
-
actionpack (= 3.0.0.
|
89
|
-
activerecord (= 3.0.0.
|
90
|
-
activeresource (= 3.0.0.
|
91
|
-
activesupport (= 3.0.0.
|
92
|
-
bundler (>= 0.
|
93
|
-
railties (= 3.0.0.
|
94
|
-
railties (3.0.0.
|
95
|
-
actionpack (= 3.0.0.
|
96
|
-
activesupport (= 3.0.0.
|
86
|
+
rails (3.0.0.rc)
|
87
|
+
actionmailer (= 3.0.0.rc)
|
88
|
+
actionpack (= 3.0.0.rc)
|
89
|
+
activerecord (= 3.0.0.rc)
|
90
|
+
activeresource (= 3.0.0.rc)
|
91
|
+
activesupport (= 3.0.0.rc)
|
92
|
+
bundler (>= 1.0.0.rc.1)
|
93
|
+
railties (= 3.0.0.rc)
|
94
|
+
railties (3.0.0.rc)
|
95
|
+
actionpack (= 3.0.0.rc)
|
96
|
+
activesupport (= 3.0.0.rc)
|
97
97
|
rake (>= 0.8.3)
|
98
|
-
thor (~> 0.
|
98
|
+
thor (~> 0.14.0)
|
99
99
|
rake (0.8.7)
|
100
|
-
rspec (2.0.0.beta.
|
101
|
-
rspec-core (= 2.0.0.beta.
|
102
|
-
rspec-expectations (= 2.0.0.beta.
|
103
|
-
rspec-mocks (= 2.0.0.beta.
|
104
|
-
rspec-core (2.0.0.beta.
|
105
|
-
rspec-expectations (2.0.0.beta.
|
100
|
+
rspec (2.0.0.beta.19)
|
101
|
+
rspec-core (= 2.0.0.beta.19)
|
102
|
+
rspec-expectations (= 2.0.0.beta.19)
|
103
|
+
rspec-mocks (= 2.0.0.beta.19)
|
104
|
+
rspec-core (2.0.0.beta.19)
|
105
|
+
rspec-expectations (2.0.0.beta.19)
|
106
106
|
diff-lcs (>= 1.1.2)
|
107
|
-
rspec-mocks (2.0.0.beta.
|
108
|
-
rspec-rails (2.0.0.beta.
|
109
|
-
rspec (
|
110
|
-
webrat (>= 0.7.
|
107
|
+
rspec-mocks (2.0.0.beta.19)
|
108
|
+
rspec-rails (2.0.0.beta.19)
|
109
|
+
rspec (= 2.0.0.beta.19)
|
110
|
+
webrat (>= 0.7.2.beta.1)
|
111
111
|
ruby-debug (0.10.3)
|
112
112
|
columnize (>= 0.1)
|
113
113
|
ruby-debug-base (~> 0.10.3.0)
|
114
114
|
ruby-debug-base (0.10.3)
|
115
115
|
linecache (>= 0.3)
|
116
116
|
rubyzip (0.9.4)
|
117
|
-
selenium-webdriver (0.0.
|
117
|
+
selenium-webdriver (0.0.27)
|
118
118
|
ffi (>= 0.6.1)
|
119
119
|
json_pure
|
120
120
|
rubyzip
|
121
121
|
spork (0.8.4)
|
122
122
|
sqlite3-ruby (1.3.1)
|
123
123
|
term-ansicolor (1.0.5)
|
124
|
-
thor (0.
|
124
|
+
thor (0.14.0)
|
125
125
|
treetop (1.4.8)
|
126
126
|
polyglot (>= 0.3.1)
|
127
127
|
trollop (1.16.2)
|
128
128
|
tzinfo (0.3.22)
|
129
|
-
webrat (0.7.1)
|
129
|
+
webrat (0.7.2.beta.1)
|
130
130
|
nokogiri (>= 1.2.0)
|
131
131
|
rack (>= 1.0)
|
132
132
|
rack-test (>= 0.5.3)
|
@@ -142,7 +142,7 @@ DEPENDENCIES
|
|
142
142
|
cucumber-rails
|
143
143
|
database_cleaner
|
144
144
|
launchy
|
145
|
-
rails (= 3.0.0.
|
145
|
+
rails (= 3.0.0.rc)
|
146
146
|
rspec-rails (>= 2.0.0.beta.16)
|
147
147
|
ruby-debug
|
148
148
|
spork
|
data/spec/config/shards.yml
CHANGED
@@ -127,6 +127,28 @@ octopus_rails:
|
|
127
127
|
adapter: mysql
|
128
128
|
host: localhost
|
129
129
|
database: octopus_shard5
|
130
|
+
|
131
|
+
|
132
|
+
not_entire_sharded:
|
133
|
+
entire_sharded: false
|
134
|
+
shards:
|
135
|
+
europe:
|
136
|
+
adapter: mysql
|
137
|
+
host: localhost
|
138
|
+
database: octopus_shard2
|
139
|
+
canada:
|
140
|
+
adapter: mysql
|
141
|
+
host: localhost
|
142
|
+
database: octopus_shard3
|
143
|
+
brazil:
|
144
|
+
adapter: mysql
|
145
|
+
host: localhost
|
146
|
+
database: octopus_shard4
|
147
|
+
russia:
|
148
|
+
adapter: mysql
|
149
|
+
host: localhost
|
150
|
+
database: octopus_shard5
|
151
|
+
|
130
152
|
|
131
153
|
|
132
154
|
|
data/spec/database_models.rb
CHANGED
@@ -99,9 +99,11 @@ describe Octopus::Association do
|
|
99
99
|
@permission_brazil_2.roles.to_set.should == [@role].to_set
|
100
100
|
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
if !Octopus.rails3?
|
103
|
+
it "update_attribute" do
|
104
|
+
@permission_brazil_2.update_attribute(:role_ids, [@role.id])
|
105
|
+
@permission_brazil_2.roles.to_set.should == [@role].to_set
|
106
|
+
end
|
105
107
|
end
|
106
108
|
|
107
109
|
it "<<" do
|
@@ -252,9 +254,11 @@ describe Octopus::Association do
|
|
252
254
|
@new_brazil_programmer.projects.to_set.should == [@project].to_set
|
253
255
|
end
|
254
256
|
|
255
|
-
|
256
|
-
|
257
|
-
|
257
|
+
if !Octopus.rails3?
|
258
|
+
it "update_attribute" do
|
259
|
+
@new_brazil_programmer.update_attribute(:project_ids, [@project.id])
|
260
|
+
@new_brazil_programmer.projects.to_set.should == [@project].to_set
|
261
|
+
end
|
258
262
|
end
|
259
263
|
|
260
264
|
it "<<" do
|
@@ -377,7 +381,7 @@ describe Octopus::Association do
|
|
377
381
|
it "should finds the client that the item belongs" do
|
378
382
|
@item_brazil.client.should == @brazil_client
|
379
383
|
end
|
380
|
-
|
384
|
+
|
381
385
|
it "should raise error if you try to add a record from a different shard" do
|
382
386
|
lambda do
|
383
387
|
@brazil_client.items << Item.using(:canada).create!(:name => "New User")
|
@@ -409,14 +413,17 @@ describe Octopus::Association do
|
|
409
413
|
@brazil_client.items.to_set.should == [@item_brazil].to_set
|
410
414
|
end
|
411
415
|
|
416
|
+
|
412
417
|
it "update_attributes" do
|
413
418
|
@brazil_client.update_attributes(:item_ids => [@item_brazil_2.id, @item_brazil.id])
|
414
419
|
@brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
|
415
420
|
end
|
416
421
|
|
417
|
-
|
418
|
-
|
419
|
-
|
422
|
+
if !Octopus.rails3?
|
423
|
+
it "update_attribute" do
|
424
|
+
@brazil_client.update_attribute(:item_ids, [@item_brazil_2.id, @item_brazil.id])
|
425
|
+
@brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
|
426
|
+
end
|
420
427
|
end
|
421
428
|
|
422
429
|
it "<<" do
|
@@ -509,7 +516,7 @@ describe Octopus::Association do
|
|
509
516
|
end
|
510
517
|
end
|
511
518
|
end
|
512
|
-
|
519
|
+
|
513
520
|
describe "when you have a 1 x N polymorphic relationship" do
|
514
521
|
before(:each) do
|
515
522
|
@brazil_client = Client.using(:brazil).create!(:name => "Brazil Client")
|
@@ -550,9 +557,11 @@ describe Octopus::Association do
|
|
550
557
|
@brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
|
551
558
|
end
|
552
559
|
|
553
|
-
|
554
|
-
|
555
|
-
|
560
|
+
if !Octopus.rails3?
|
561
|
+
it "update_attribute" do
|
562
|
+
@brazil_client.update_attribute(:comment_ids, [@comment_brazil_2.id, @comment_brazil.id])
|
563
|
+
@brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
|
564
|
+
end
|
556
565
|
end
|
557
566
|
|
558
567
|
it "<<" do
|
data/spec/octopus/model_spec.rb
CHANGED
@@ -218,7 +218,7 @@ describe Octopus::Model do
|
|
218
218
|
it "update_attribute" do
|
219
219
|
@user = User.using(:brazil).create!(:name => "User1")
|
220
220
|
@user2 = User.using(:brazil).find(@user.id)
|
221
|
-
@user2.
|
221
|
+
@user2.update_attribute(:name, "Joaquim")
|
222
222
|
User.using(:brazil).find_by_name("Joaquim").should_not be_nil
|
223
223
|
end
|
224
224
|
|
data/spec/octopus/proxy_spec.rb
CHANGED
@@ -116,6 +116,13 @@ describe Octopus::Proxy do
|
|
116
116
|
|
117
117
|
User.find_by_name("Thiago").should == @user
|
118
118
|
end
|
119
|
+
|
120
|
+
it "should work with associations" do
|
121
|
+
u = Client.create!(:name => "Thiago")
|
122
|
+
i = Item.create(:name => "Item")
|
123
|
+
u.items << i
|
124
|
+
u.save()
|
125
|
+
end
|
119
126
|
end
|
120
127
|
|
121
128
|
after(:each) do
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "when the database is not entire sharded" do
|
4
|
+
before(:each) do
|
5
|
+
Octopus.stub!(:env).and_return("not_entire_sharded")
|
6
|
+
clean_connection_proxy()
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not send all queries to the specified slave" do
|
10
|
+
pending()
|
11
|
+
# User.create!(:name => "Thiago")
|
12
|
+
#
|
13
|
+
# using_enviroment :not_entire_sharded do
|
14
|
+
# Octopus.using(:russia) do
|
15
|
+
# User.create!(:name => "Thiago")
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# User.count.should == 2
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should pick the shard based on current_shard when you have a sharded model" do
|
23
|
+
Cat.create!(:name => "Thiago")
|
24
|
+
|
25
|
+
using_enviroment :not_entire_sharded do
|
26
|
+
Octopus.using(:russia) do
|
27
|
+
Cat.create!(:name => "Thiago")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Cat.count.should == 1
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require "rubygems"
|
2
|
-
MIGRATIONS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), 'migrations'))
|
3
|
-
|
4
2
|
if ENV["VERSION"]
|
5
3
|
gem 'activerecord', ENV["VERSION"]
|
6
4
|
gem 'activesupport', ENV["VERSION"]
|
7
5
|
gem 'actionpack', ENV["VERSION"]
|
8
6
|
end
|
9
7
|
|
10
|
-
require
|
11
|
-
|
8
|
+
require "bundler"
|
9
|
+
Bundler.setup()
|
12
10
|
require File.expand_path(File.dirname(__FILE__)) + "/database_connection"
|
13
|
-
require "
|
14
|
-
require 'octopus'
|
11
|
+
require "octopus"
|
15
12
|
require "octopus_helper"
|
13
|
+
require "action_controller"
|
14
|
+
require 'rspec/core'
|
16
15
|
|
16
|
+
MIGRATIONS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), 'migrations'))
|
17
17
|
|
18
|
-
|
18
|
+
RSpec.configure do |config|
|
19
19
|
config.before(:each) do
|
20
20
|
Octopus.stub!(:directory).and_return(File.dirname(__FILE__))
|
21
21
|
require "database_models"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-octopus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 37
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 29
|
10
|
+
version: 0.0.29
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Thiago Pradi
|
@@ -16,29 +16,32 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-30 00:00:00 -03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
name: rspec
|
24
23
|
prerelease: false
|
25
|
-
|
24
|
+
type: :development
|
25
|
+
name: rspec
|
26
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
27
|
none: false
|
27
28
|
requirements:
|
28
29
|
- - ">="
|
29
30
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
31
|
+
hash: 62196421
|
31
32
|
segments:
|
32
|
-
- 1
|
33
33
|
- 2
|
34
|
-
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
- 0
|
35
|
+
- 0
|
36
|
+
- beta
|
37
|
+
- 19
|
38
|
+
version: 2.0.0.beta.19
|
39
|
+
requirement: *id001
|
38
40
|
- !ruby/object:Gem::Dependency
|
39
|
-
name: mysql
|
40
41
|
prerelease: false
|
41
|
-
|
42
|
+
type: :development
|
43
|
+
name: mysql
|
44
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
45
|
none: false
|
43
46
|
requirements:
|
44
47
|
- - ">="
|
@@ -49,12 +52,12 @@ dependencies:
|
|
49
52
|
- 8
|
50
53
|
- 1
|
51
54
|
version: 2.8.1
|
52
|
-
|
53
|
-
version_requirements: *id002
|
55
|
+
requirement: *id002
|
54
56
|
- !ruby/object:Gem::Dependency
|
55
|
-
name: pg
|
56
57
|
prerelease: false
|
57
|
-
|
58
|
+
type: :development
|
59
|
+
name: pg
|
60
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
61
|
none: false
|
59
62
|
requirements:
|
60
63
|
- - ">="
|
@@ -65,12 +68,12 @@ dependencies:
|
|
65
68
|
- 9
|
66
69
|
- 0
|
67
70
|
version: 0.9.0
|
68
|
-
|
69
|
-
version_requirements: *id003
|
71
|
+
requirement: *id003
|
70
72
|
- !ruby/object:Gem::Dependency
|
71
|
-
name: sqlite3-ruby
|
72
73
|
prerelease: false
|
73
|
-
|
74
|
+
type: :development
|
75
|
+
name: sqlite3-ruby
|
76
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
77
|
none: false
|
75
78
|
requirements:
|
76
79
|
- - ">="
|
@@ -81,12 +84,27 @@ dependencies:
|
|
81
84
|
- 3
|
82
85
|
- 1
|
83
86
|
version: 1.3.1
|
87
|
+
requirement: *id004
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
prerelease: false
|
84
90
|
type: :development
|
85
|
-
|
91
|
+
name: jeweler
|
92
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 7
|
98
|
+
segments:
|
99
|
+
- 1
|
100
|
+
- 4
|
101
|
+
version: "1.4"
|
102
|
+
requirement: *id005
|
86
103
|
- !ruby/object:Gem::Dependency
|
87
|
-
name: activerecord
|
88
104
|
prerelease: false
|
89
|
-
|
105
|
+
type: :development
|
106
|
+
name: actionpack
|
107
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
90
108
|
none: false
|
91
109
|
requirements:
|
92
110
|
- - ">="
|
@@ -96,8 +114,22 @@ dependencies:
|
|
96
114
|
- 2
|
97
115
|
- 3
|
98
116
|
version: "2.3"
|
117
|
+
requirement: *id006
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
prerelease: false
|
99
120
|
type: :runtime
|
100
|
-
|
121
|
+
name: activerecord
|
122
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
hash: 5
|
128
|
+
segments:
|
129
|
+
- 2
|
130
|
+
- 3
|
131
|
+
version: "2.3"
|
132
|
+
requirement: *id007
|
101
133
|
description: This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards.
|
102
134
|
email: tchandy@gmail.com
|
103
135
|
executables: []
|
@@ -108,6 +140,9 @@ extra_rdoc_files:
|
|
108
140
|
- README.mkdn
|
109
141
|
files:
|
110
142
|
- .gitignore
|
143
|
+
- .rspec
|
144
|
+
- Gemfile
|
145
|
+
- Gemfile.lock
|
111
146
|
- README.mkdn
|
112
147
|
- Rakefile
|
113
148
|
- VERSION
|
@@ -219,8 +254,8 @@ files:
|
|
219
254
|
- spec/octopus/proxy_spec.rb
|
220
255
|
- spec/octopus/replication_specs.rb
|
221
256
|
- spec/octopus/scope_proxy_spec.rb
|
257
|
+
- spec/octopus/sharded_spec.rb
|
222
258
|
- spec/octopus_helper.rb
|
223
|
-
- spec/spec.opts
|
224
259
|
- spec/spec_helper.rb
|
225
260
|
has_rdoc: true
|
226
261
|
homepage: http://github.com/tchandy/octopus
|
@@ -280,5 +315,6 @@ test_files:
|
|
280
315
|
- spec/octopus/proxy_spec.rb
|
281
316
|
- spec/octopus/replication_specs.rb
|
282
317
|
- spec/octopus/scope_proxy_spec.rb
|
318
|
+
- spec/octopus/sharded_spec.rb
|
283
319
|
- spec/octopus_helper.rb
|
284
320
|
- spec/spec_helper.rb
|
data/spec/spec.opts
DELETED