ar-octopus 0.0.6 → 0.0.7
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/Rakefile +1 -1
- data/ar-octopus.gemspec +2 -2
- data/lib/octopus/model.rb +0 -1
- data/lib/octopus/persistence.rb +10 -0
- data/lib/octopus/proxy.rb +1 -1
- data/spec/octopus/model_spec.rb +52 -4
- metadata +4 -4
data/Rakefile
CHANGED
@@ -29,7 +29,7 @@ begin
|
|
29
29
|
gem.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
|
30
30
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
31
31
|
gem.add_dependency('activerecord')
|
32
|
-
gem.version = "0.0.
|
32
|
+
gem.version = "0.0.7"
|
33
33
|
end
|
34
34
|
Jeweler::GemcutterTasks.new
|
35
35
|
rescue LoadError
|
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.7"
|
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", "Amit Agarwal"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-24}
|
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 = [
|
data/lib/octopus/model.rb
CHANGED
data/lib/octopus/persistence.rb
CHANGED
@@ -22,6 +22,16 @@ module Octopus::Persistence
|
|
22
22
|
reload_connection()
|
23
23
|
super
|
24
24
|
end
|
25
|
+
|
26
|
+
def delete
|
27
|
+
reload_connection()
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
reload_connection()
|
33
|
+
super
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
ActiveRecord::Base.send(:include, Octopus::Persistence)
|
data/lib/octopus/proxy.rb
CHANGED
@@ -138,7 +138,7 @@ class Octopus::Proxy
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def should_clean_connection?(method)
|
141
|
-
method.to_s =~ /insert|select/ && !should_send_queries_to_multiple_shards? && !self.current_group && !@replicated
|
141
|
+
method.to_s =~ /insert|select/ && !should_send_queries_to_multiple_shards? && !self.current_group && !@replicated && !self.block
|
142
142
|
end
|
143
143
|
|
144
144
|
def should_send_queries_to_multiple_shards?
|
data/spec/octopus/model_spec.rb
CHANGED
@@ -11,12 +11,12 @@ describe Octopus::Model do
|
|
11
11
|
User.using(:canada).count.should == 1
|
12
12
|
User.count.should == 0
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should select the correct shard" do
|
16
16
|
pending()
|
17
17
|
# User.using(:canada)
|
18
18
|
# User.create!(:name => 'oi')
|
19
|
-
# User.
|
19
|
+
# User.count.should == 1
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should allow scoping dynamically" do
|
@@ -109,7 +109,7 @@ describe Octopus::Model do
|
|
109
109
|
User.using(:alone_shard).find(:all).should == []
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
describe "AR basic methods" do
|
114
114
|
it "increment" do
|
115
115
|
u = User.using(:brazil).create!(:name => "Teste", :number => 10)
|
@@ -140,8 +140,56 @@ describe Octopus::Model do
|
|
140
140
|
u.toggle!(:admin)
|
141
141
|
u = User.using(:brazil).find_by_name('Teste').admin.should be_true
|
142
142
|
end
|
143
|
+
|
144
|
+
it "count" do
|
145
|
+
u = User.using(:brazil).create!(:name => "User1")
|
146
|
+
u2 = User.using(:brazil).create!(:name => "User2")
|
147
|
+
u3 = User.using(:brazil).create!(:name => "User3")
|
148
|
+
User.using(:brazil).where(:name => "User2").count.should == 1
|
149
|
+
end
|
150
|
+
|
151
|
+
it "update_attributes" do
|
152
|
+
@user = User.using(:brazil).create!(:name => "User1")
|
153
|
+
@user2 = User.using(:brazil).find(@user.id)
|
154
|
+
@user2.update_attributes(:name => "Joaquim")
|
155
|
+
User.using(:brazil).where(:name => "Joaquim").first.should_not be_nil
|
156
|
+
end
|
157
|
+
|
158
|
+
it "using update_attributes inside a block" do
|
159
|
+
ActiveRecord::Base.connection.run_queries_on_shard :brazil do
|
160
|
+
@user = User.create!(:name => "User1")
|
161
|
+
@user2 = User.find(@user.id)
|
162
|
+
@user2.update_attributes(:name => "Joaquim")
|
163
|
+
end
|
164
|
+
|
165
|
+
User.using(:brazil).where(:name => "Joaquim").first.should_not be_nil
|
166
|
+
end
|
167
|
+
|
168
|
+
it "update_attribute" do
|
169
|
+
@user = User.using(:brazil).create!(:name => "User1")
|
170
|
+
@user2 = User.using(:brazil).find(@user.id)
|
171
|
+
@user2.update_attributes(:name => "Joaquim")
|
172
|
+
User.using(:brazil).where(:name => "Joaquim").first.should_not be_nil
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "deleting a record" do
|
176
|
+
before(:each) do
|
177
|
+
@user = User.using(:brazil).create!(:name => "User1")
|
178
|
+
@user2 = User.using(:brazil).find(@user.id)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "delete" do
|
182
|
+
@user2.delete
|
183
|
+
lambda { User.using(:brazil).find(@user2.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "destroy" do
|
187
|
+
@user2.destroy
|
188
|
+
lambda { User.using(:brazil).find(@user2.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
189
|
+
end
|
190
|
+
end
|
143
191
|
end
|
144
|
-
|
192
|
+
|
145
193
|
describe "#replicated_model method" do
|
146
194
|
it "should be replicated" do
|
147
195
|
using_enviroment :production_replicated do
|
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: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Thiago Pradi
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-06-
|
20
|
+
date: 2010-06-24 00:00:00 -03:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|