ar-octopus 0.0.2 → 0.0.3

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.
@@ -24,13 +24,46 @@ describe Octopus::Model do
24
24
  end
25
25
 
26
26
  it "should support both groups and alone shards" do
27
- User.using(:alone_shard).create!(:name => "Alone")
27
+ u = User.using(:alone_shard).create!(:name => "Alone")
28
28
  User.using(:alone_shard).count.should == 1
29
29
  User.using(:canada).count.should == 0
30
30
  User.using(:brazil).count.should == 0
31
31
  User.count.should == 0
32
32
  end
33
33
 
34
+ describe "#current_shard attribute" do
35
+ it "should store the attribute when you create or find an object" do
36
+ u = User.using(:alone_shard).create!(:name => "Alone")
37
+ u.current_shard.should == :alone_shard
38
+ User.using(:canada).create!(:name => 'oi')
39
+ u = User.using(:canada).find_by_name("oi")
40
+ u.current_shard.should == :canada
41
+ end
42
+
43
+ it "should store the attribute when you find multiple instances" do
44
+ 5.times { User.using(:alone_shard).create!(:name => "Alone") }
45
+ User.using(:alone_shard).all.each do |u|
46
+ u.current_shard.should == :alone_shard
47
+ end
48
+ end
49
+
50
+ it "should works when you find, and after that, alter that object" do
51
+ alone_user = User.using(:alone_shard).create!(:name => "Alone")
52
+ master_user = User.using(:master).create!(:name => "Master")
53
+ alone_user.name = "teste"
54
+ alone_user.save
55
+ User.using(:master).find(:first).name.should == "Master"
56
+ User.using(:alone_shard).find(:first).name.should == "teste"
57
+ end
58
+
59
+ it "should work for the reload method" do
60
+ User.using(:alone_shard).create!(:name => "Alone")
61
+ u = User.using(:alone_shard).where(:name => "Alone").first
62
+ u.reload
63
+ u.name.should == "Alone"
64
+ end
65
+ end
66
+
34
67
  describe "passing a block" do
35
68
  it "should allow queries be executed inside the block, ponting to a specific shard" do
36
69
  User.using(:canada) do
@@ -50,20 +83,6 @@ describe Octopus::Model do
50
83
  end
51
84
  end
52
85
 
53
- describe "when you have a relationship" do
54
- it "should find all models in the specified shard" do
55
- pending()
56
- # brazil_client = Client.using(:brazil).create!(:name => "Brazil Client")
57
- # master_client = Client.create!(:name => "Master Client")
58
- #
59
- # item_brazil = Item.using(:brazil).create!(:name => "Brazil Item", :client => brazil_client)
60
- # item_master = Item.create!(:name => "Master Item", :client => master_client)
61
- # c = Client.using(:brazil).find_by_name("Brazil Client")
62
- # Client.using(:master).create!(:name => "teste")
63
- # c.items.should == [item_brazil]
64
- end
65
- end
66
-
67
86
  describe "raising errors" do
68
87
  it "should raise a error when you specify a shard that doesn't exist" do
69
88
  lambda { User.using(:crazy_shard) }.should raise_error("Nonexistent Shard Name: crazy_shard")
@@ -83,7 +102,39 @@ describe Octopus::Model do
83
102
  User.using(:alone_shard).find(:all).should == []
84
103
  end
85
104
  end
105
+
106
+ describe "AR basic methods" do
107
+ it "increment" do
108
+ u = User.using(:brazil).create!(:name => "Teste", :number => 10)
109
+ u = User.using(:brazil).find_by_number(10)
110
+ u.increment(:number)
111
+ u.save()
112
+ u = User.using(:brazil).find_by_number(11).should_not be_nil
113
+ end
114
+
115
+ it "increment!" do
116
+ u = User.using(:brazil).create!(:name => "Teste", :number => 10)
117
+ u = User.using(:brazil).find_by_number(10)
118
+ u.increment!(:number)
119
+ u = User.using(:brazil).find_by_number(11).should_not be_nil
120
+ end
121
+
122
+ it "toggle" do
123
+ u = User.using(:brazil).create!(:name => "Teste", :admin => false)
124
+ u = User.using(:brazil).find_by_name('Teste')
125
+ u.toggle(:admin)
126
+ u.save()
127
+ u = User.using(:brazil).find_by_name('Teste').admin.should be_true
128
+ end
86
129
 
130
+ it "toggle!" do
131
+ u = User.using(:brazil).create!(:name => "Teste", :admin => false)
132
+ u = User.using(:brazil).find_by_name('Teste')
133
+ u.toggle!(:admin)
134
+ u = User.using(:brazil).find_by_name('Teste').admin.should be_true
135
+ end
136
+ end
137
+
87
138
  describe "#replicated_model method" do
88
139
  it "should be replicated" do
89
140
  using_enviroment :production_replicated do
@@ -62,7 +62,7 @@ describe Octopus::Proxy do
62
62
  before(:each) do
63
63
  Octopus.stub!(:env).and_return("production_replicated")
64
64
  @proxy = Octopus::Proxy.new(Octopus.config())
65
- ActiveRecord::Base.class_eval("@@connection_proxy = nil")
65
+ clean_connection_proxy()
66
66
  end
67
67
 
68
68
  it "should have the replicated attribute as true" do
@@ -1,7 +1,7 @@
1
1
  MIGRATIONS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), 'migrations'))
2
2
  require 'spec'
3
3
  require 'spec/autorun'
4
- require "database_connection"
4
+ require "spec/database_connection"
5
5
  require "action_pack"
6
6
  require "action_controller"
7
7
  require 'octopus'
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  def clean_all_shards()
24
24
  ActiveRecord::Base.using(:master).connection.shards.keys.each do |shard_symbol|
25
- ['schema_migrations', 'users', 'clients', 'cats', 'items'].each do |tables|
25
+ ['schema_migrations', 'users', 'clients', 'cats', 'items', 'keyboards', 'computers', 'permissions_roles', 'roles', 'permissions', 'assignments', 'projects', 'programmers'].each do |tables|
26
26
  ActiveRecord::Base.using(shard_symbol).connection.execute("DELETE FROM #{tables};")
27
27
  end
28
28
  end
@@ -37,13 +37,17 @@ def migrating_to_version(version, &block)
37
37
  end
38
38
  end
39
39
 
40
+ def clean_connection_proxy()
41
+ Thread.current[:connection_proxy] = nil
42
+ end
43
+
40
44
  def using_enviroment(enviroment, &block)
41
45
  begin
42
- Octopus.class_eval("@@env = '#{enviroment.to_s}'")
43
- ActiveRecord::Base.class_eval("@@connection_proxy = nil")
46
+ Octopus.instance_variable_set(:@env, enviroment.to_s)
47
+ clean_connection_proxy()
44
48
  yield
45
49
  ensure
46
- Octopus.class_eval("@@env = 'production'")
47
- ActiveRecord::Base.class_eval("@@connection_proxy = nil")
50
+ Octopus.instance_variable_set(:@env, 'production')
51
+ clean_connection_proxy()
48
52
  end
49
53
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-octopus
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Thiago Pradi
@@ -16,16 +17,18 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-06-14 00:00:00 -03:00
20
+ date: 2010-06-22 00:00:00 -03:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
24
  name: rspec
24
25
  prerelease: false
25
26
  requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
26
28
  requirements:
27
29
  - - ">="
28
30
  - !ruby/object:Gem::Version
31
+ hash: 13
29
32
  segments:
30
33
  - 1
31
34
  - 2
@@ -52,7 +55,10 @@ files:
52
55
  - doc/libraries.textile
53
56
  - doc/shards.yml
54
57
  - lib/octopus.rb
58
+ - lib/octopus/association.rb
59
+ - lib/octopus/association_collection.rb
55
60
  - lib/octopus/controller.rb
61
+ - lib/octopus/has_and_belongs_to_many_association.rb
56
62
  - lib/octopus/migration.rb
57
63
  - lib/octopus/model.rb
58
64
  - lib/octopus/proxy.rb
@@ -70,6 +76,7 @@ files:
70
76
  - spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb
71
77
  - spec/migrations/8_raise_exception_with_invalid_group_name.rb
72
78
  - spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb
79
+ - spec/octopus/association_spec.rb
73
80
  - spec/octopus/controller_spec.rb
74
81
  - spec/octopus/migration_spec.rb
75
82
  - spec/octopus/model_spec.rb
@@ -87,23 +94,27 @@ rdoc_options:
87
94
  require_paths:
88
95
  - lib
89
96
  required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
90
98
  requirements:
91
99
  - - ">="
92
100
  - !ruby/object:Gem::Version
101
+ hash: 3
93
102
  segments:
94
103
  - 0
95
104
  version: "0"
96
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
97
107
  requirements:
98
108
  - - ">="
99
109
  - !ruby/object:Gem::Version
110
+ hash: 3
100
111
  segments:
101
112
  - 0
102
113
  version: "0"
103
114
  requirements: []
104
115
 
105
116
  rubyforge_project:
106
- rubygems_version: 1.3.6
117
+ rubygems_version: 1.3.7
107
118
  signing_key:
108
119
  specification_version: 3
109
120
  summary: Easy Database Sharding for ActiveRecord
@@ -121,6 +132,7 @@ test_files:
121
132
  - spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb
122
133
  - spec/migrations/8_raise_exception_with_invalid_group_name.rb
123
134
  - spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb
135
+ - spec/octopus/association_spec.rb
124
136
  - spec/octopus/controller_spec.rb
125
137
  - spec/octopus/migration_spec.rb
126
138
  - spec/octopus/model_spec.rb