ar-octopus 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +9 -9
  2. data/.rspec +1 -1
  3. data/.rubocop.yml +46 -0
  4. data/.rubocop_todo.yml +52 -0
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +3 -9
  7. data/Appraisals +4 -0
  8. data/Rakefile +17 -16
  9. data/ar-octopus.gemspec +22 -16
  10. data/gemfiles/rails41.gemfile +7 -0
  11. data/init.rb +1 -1
  12. data/lib/ar-octopus.rb +1 -1
  13. data/lib/octopus.rb +38 -37
  14. data/lib/octopus/abstract_adapter.rb +0 -2
  15. data/lib/octopus/association.rb +8 -6
  16. data/lib/octopus/association_shard_tracking.rb +80 -81
  17. data/lib/octopus/collection_association.rb +7 -5
  18. data/lib/octopus/collection_proxy.rb +11 -9
  19. data/lib/octopus/has_and_belongs_to_many_association.rb +5 -3
  20. data/lib/octopus/load_balancing.rb +3 -2
  21. data/lib/octopus/load_balancing/round_robin.rb +12 -8
  22. data/lib/octopus/migration.rb +117 -108
  23. data/lib/octopus/model.rb +130 -134
  24. data/lib/octopus/persistence.rb +1 -1
  25. data/lib/octopus/proxy.rb +345 -339
  26. data/lib/octopus/railtie.rb +2 -2
  27. data/lib/octopus/relation_proxy.rb +6 -1
  28. data/lib/octopus/scope_proxy.rb +38 -36
  29. data/lib/octopus/shard_tracking.rb +36 -35
  30. data/lib/octopus/shard_tracking/attribute.rb +12 -14
  31. data/lib/octopus/shard_tracking/dynamic.rb +7 -3
  32. data/lib/octopus/singular_association.rb +5 -3
  33. data/lib/octopus/slave_group.rb +10 -8
  34. data/lib/octopus/version.rb +1 -1
  35. data/rails/init.rb +1 -1
  36. data/sample_app/autotest/discover.rb +2 -2
  37. data/sample_app/config/application.rb +1 -1
  38. data/sample_app/config/boot.rb +1 -1
  39. data/sample_app/config/environments/test.rb +1 -1
  40. data/sample_app/config/initializers/session_store.rb +1 -1
  41. data/sample_app/config/initializers/wrap_parameters.rb +1 -1
  42. data/sample_app/config/routes.rb +1 -1
  43. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +2 -2
  44. data/sample_app/db/schema.rb +10 -10
  45. data/sample_app/db/seeds.rb +3 -3
  46. data/sample_app/features/step_definitions/seeds_steps.rb +4 -4
  47. data/sample_app/features/step_definitions/web_steps.rb +3 -4
  48. data/sample_app/features/support/env.rb +3 -4
  49. data/sample_app/features/support/paths.rb +4 -4
  50. data/sample_app/spec/spec_helper.rb +3 -3
  51. data/spec/migrations/10_create_users_using_replication.rb +3 -3
  52. data/spec/migrations/11_add_field_in_all_slaves.rb +3 -3
  53. data/spec/migrations/12_create_users_using_block.rb +7 -7
  54. data/spec/migrations/13_create_users_using_block_and_using.rb +4 -4
  55. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +2 -2
  56. data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +2 -2
  57. data/spec/migrations/1_create_users_on_master.rb +3 -3
  58. data/spec/migrations/2_create_users_on_canada.rb +3 -3
  59. data/spec/migrations/3_create_users_on_both_shards.rb +3 -3
  60. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +3 -3
  61. data/spec/migrations/5_create_users_on_multiples_groups.rb +2 -2
  62. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +3 -3
  63. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +3 -3
  64. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +3 -3
  65. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +4 -4
  66. data/spec/octopus/association_shard_tracking_spec.rb +413 -417
  67. data/spec/octopus/collection_proxy_spec.rb +6 -5
  68. data/spec/octopus/log_subscriber_spec.rb +4 -4
  69. data/spec/octopus/migration_spec.rb +48 -48
  70. data/spec/octopus/model_spec.rb +267 -292
  71. data/spec/octopus/octopus_spec.rb +40 -41
  72. data/spec/octopus/proxy_spec.rb +124 -124
  73. data/spec/octopus/relation_proxy_spec.rb +32 -32
  74. data/spec/octopus/replicated_slave_grouped_spec.rb +23 -23
  75. data/spec/octopus/replication_spec.rb +61 -66
  76. data/spec/octopus/scope_proxy_spec.rb +56 -10
  77. data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +29 -29
  78. data/spec/octopus/sharded_spec.rb +10 -10
  79. data/spec/spec_helper.rb +6 -6
  80. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +1 -3
  81. data/spec/support/database_connection.rb +2 -2
  82. data/spec/support/database_models.rb +16 -17
  83. data/spec/support/octopus_helper.rb +19 -21
  84. data/spec/support/query_count.rb +1 -3
  85. data/spec/support/shared_contexts.rb +3 -3
  86. data/spec/tasks/octopus.rake_spec.rb +10 -10
  87. metadata +43 -26
@@ -1,75 +1,75 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::RelationProxy do
4
- describe "shard tracking" do
4
+ describe 'shard tracking' do
5
5
  before :each do
6
6
  @client = Client.using(:canada).create!
7
7
  @client.items << Item.using(:canada).create!
8
8
  @relation = @client.items
9
9
  end
10
10
 
11
- it "remembers the shard on which a relation was created" do
12
- @relation.current_shard.should eq(:canada)
11
+ it 'remembers the shard on which a relation was created' do
12
+ expect(@relation.current_shard).to eq(:canada)
13
13
  end
14
14
 
15
- context "when comparing to other Relation objects" do
15
+ context 'when comparing to other Relation objects' do
16
16
  before :each do
17
17
  @relation.reset
18
18
  end
19
19
 
20
- it "is equal to its clone" do
21
- @relation.should eq(@relation.clone)
20
+ it 'is equal to its clone' do
21
+ expect(@relation).to eq(@relation.clone)
22
22
  end
23
23
  end
24
24
 
25
25
  if Octopus.rails4?
26
- context "under Rails 4" do
27
- it "is an Octopus::RelationProxy" do
28
- @relation.class.should eq(Octopus::RelationProxy)
26
+ context 'under Rails 4' do
27
+ it 'is an Octopus::RelationProxy' do
28
+ expect(@relation.class).to eq(Octopus::RelationProxy)
29
29
  end
30
30
 
31
- it "should be able to return its ActiveRecord::Relation" do
32
- @relation.ar_relation.is_a?(ActiveRecord::Relation).should be_true
31
+ it 'should be able to return its ActiveRecord::Relation' do
32
+ expect(@relation.ar_relation.is_a?(ActiveRecord::Relation)).to be true
33
33
  end
34
34
 
35
- it "is equal to an identically-defined, but different, RelationProxy" do
35
+ it 'is equal to an identically-defined, but different, RelationProxy' do
36
36
  i = @client.items
37
- @relation.should eq(i)
38
- @relation.object_id.should_not eq(i.object_id)
37
+ expect(@relation).to eq(i)
38
+ expect(@relation.object_id).not_to eq(i.object_id)
39
39
  end
40
40
 
41
- it "is equal to its own underlying ActiveRecord::Relation" do
42
- @relation.should eq(@relation.ar_relation)
43
- @relation.ar_relation.should eq(@relation)
41
+ it 'is equal to its own underlying ActiveRecord::Relation' do
42
+ expect(@relation).to eq(@relation.ar_relation)
43
+ expect(@relation.ar_relation).to eq(@relation)
44
44
  end
45
45
  end
46
46
  end
47
47
 
48
- context "when no explicit shard context is provided" do
49
- it "uses the correct shard" do
50
- @relation.count.should eq(1)
48
+ context 'when no explicit shard context is provided' do
49
+ it 'uses the correct shard' do
50
+ expect(@relation.count).to eq(1)
51
51
  end
52
52
 
53
- it "lazily evaluates on the correct shard" do
53
+ it 'lazily evaluates on the correct shard' do
54
54
  # Do something to force Client.connection_proxy.current_shard to change
55
- other_count = Client.using(:brazil).count
56
- @relation.select(:client_id).count.should == 1
55
+ _some_count = Client.using(:brazil).count
56
+ expect(@relation.select(:client_id).count).to eq(1)
57
57
  end
58
58
  end
59
59
 
60
- context "when an explicit, but different, shard context is provided" do
61
- it "uses the correct shard" do
62
- Item.using(:brazil).count.should eq(0)
63
- clients_on_brazil = Client.using(:brazil).all
60
+ context 'when an explicit, but different, shard context is provided' do
61
+ it 'uses the correct shard' do
62
+ expect(Item.using(:brazil).count).to eq(0)
63
+ _clients_on_brazil = Client.using(:brazil).all
64
64
  Client.using(:brazil) do
65
- @relation.count.should eq(1)
65
+ expect(@relation.count).to eq(1)
66
66
  end
67
67
  end
68
68
 
69
- it "lazily evaluates on the correct shard" do
70
- Item.using(:brazil).count.should eq(0)
69
+ it 'lazily evaluates on the correct shard' do
70
+ expect(Item.using(:brazil).count).to eq(0)
71
71
  Client.using(:brazil) do
72
- @relation.select(:client_id).count.should == 1
72
+ expect(@relation.select(:client_id).count).to eq(1)
73
73
  end
74
74
  end
75
75
  end
@@ -1,14 +1,14 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe "when the database is replicated and has slave groups" do
3
+ describe 'when the database is replicated and has slave groups' do
4
4
 
5
- it "should pick the slave group based on current_slave_grup when you have a replicated model" do
5
+ it 'should pick the slave group based on current_slave_grup when you have a replicated model' do
6
6
 
7
7
  OctopusHelper.using_environment :replicated_slave_grouped do
8
8
  # The following two calls of `create!` both creates cats in :master(The database `octopus_shard_1`)
9
9
  # which is configured through RAILS_ENV and database.yml
10
- Cat.create!(:name => "Thiago1")
11
- Cat.create!(:name => "Thiago2")
10
+ Cat.create!(:name => 'Thiago1')
11
+ Cat.create!(:name => 'Thiago2')
12
12
 
13
13
  # See "replicated_slave_grouped" defined in shards.yml
14
14
  # We have:
@@ -18,47 +18,47 @@ describe "when the database is replicated and has slave groups" do
18
18
  # When a select-count query is sent to `octopus_shard_2`, it should return 0.
19
19
 
20
20
  # The query goes to `octopus_shard_1`
21
- Cat.using(:master).count.should == 2
21
+ expect(Cat.using(:master).count).to eq(2)
22
22
  # The query goes to `octopus_shard_1`
23
- Cat.count.should == 2
23
+ expect(Cat.count).to eq(2)
24
24
  # The query goes to `octopus_shard_2`
25
- Cat.using(slave_group: :slaves1).count.should == 0
25
+ expect(Cat.using(:slave_group => :slaves1).count).to eq(0)
26
26
  # The query goes to `octopus_shard_1`
27
- Cat.using(slave_group: :slaves2).count.should == 2
27
+ expect(Cat.using(:slave_group => :slaves2).count).to eq(2)
28
28
  end
29
29
  end
30
30
 
31
- it "should distribute queries between slaves in a slave group in round-robin" do
31
+ it 'should distribute queries between slaves in a slave group in round-robin' do
32
32
  OctopusHelper.using_environment :replicated_slave_grouped do
33
33
  # The query goes to :master(`octopus_shard_1`)
34
- Cat.create!(:name => "Thiago1")
34
+ Cat.create!(:name => 'Thiago1')
35
35
  # The query goes to :master(`octopus_shard_1`)
36
- Cat.create!(:name => "Thiago2")
36
+ Cat.create!(:name => 'Thiago2')
37
37
 
38
38
  # The query goes to :slave32(`octopus_shard_2`)
39
- Cat.using(slave_group: :slaves3).count.should == 0
39
+ expect(Cat.using(:slave_group => :slaves3).count).to eq(0)
40
40
  # The query goes to :slave31(`octopus_shard_1`)
41
- Cat.using(slave_group: :slaves3).count.should == 2
41
+ expect(Cat.using(:slave_group => :slaves3).count).to eq(2)
42
42
  # The query goes to :slave32(`octopus_shard_2`)
43
- Cat.using(slave_group: :slaves3).count.should == 0
43
+ expect(Cat.using(:slave_group => :slaves3).count).to eq(0)
44
44
  end
45
45
  end
46
46
 
47
- it "should make queries to master when slave groups are configured but not selected" do
47
+ it 'should make queries to master when slave groups are configured but not selected' do
48
48
  OctopusHelper.using_environment :replicated_slave_grouped do
49
49
  # All the queries go to :master(`octopus_shard_1`)
50
50
 
51
- Cat.create!(:name => "Thiago1")
52
- Cat.create!(:name => "Thiago2")
51
+ Cat.create!(:name => 'Thiago1')
52
+ Cat.create!(:name => 'Thiago2')
53
53
 
54
54
  # In `database.yml` and `shards.yml`, we have configured 1 master and 4 slaves.
55
55
  # So we can ensure Octopus is not distributing queries between them
56
56
  # by asserting 1 + 4 = 5 queries go to :master(`octopus_shard_1`)
57
- Cat.count.should == 2
58
- Cat.count.should == 2
59
- Cat.count.should == 2
60
- Cat.count.should == 2
61
- Cat.count.should == 2
57
+ expect(Cat.count).to eq(2)
58
+ expect(Cat.count).to eq(2)
59
+ expect(Cat.count).to eq(2)
60
+ expect(Cat.count).to eq(2)
61
+ expect(Cat.count).to eq(2)
62
62
  end
63
63
  end
64
64
  end
@@ -1,69 +1,69 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe "when the database is replicated" do
4
- it "should send all writes/reads queries to master when you have a non replicated model" do
3
+ describe 'when the database is replicated' do
4
+ it 'should send all writes/reads queries to master when you have a non replicated model' do
5
5
  OctopusHelper.using_environment :production_replicated do
6
- u = User.create!(:name => "Replicated")
7
- User.count.should == 1
8
- User.find(u.id).should == u
6
+ u = User.create!(:name => 'Replicated')
7
+ expect(User.count).to eq(1)
8
+ expect(User.find(u.id)).to eq(u)
9
9
  end
10
10
  end
11
11
 
12
- it "should send all writes queries to master" do
12
+ it 'should send all writes queries to master' do
13
13
  OctopusHelper.using_environment :production_replicated do
14
- Cat.create!(:name => "Slave Cat")
15
- Cat.find_by_name("Slave Cat").should be_nil
16
- Client.create!(:name => "Slave Client")
17
- Client.find_by_name("Slave Client").should_not be_nil
14
+ Cat.create!(:name => 'Slave Cat')
15
+ expect(Cat.find_by_name('Slave Cat')).to be_nil
16
+ Client.create!(:name => 'Slave Client')
17
+ expect(Client.find_by_name('Slave Client')).not_to be_nil
18
18
  end
19
19
  end
20
20
 
21
- it "should allow to create multiple models on the master" do
21
+ it 'should allow to create multiple models on the master' do
22
22
  OctopusHelper.using_environment :production_replicated do
23
- Cat.create!([{:name => "Slave Cat 1"}, {:name => "Slave Cat 2"}])
24
- Cat.find_by_name("Slave Cat 1").should be_nil
25
- Cat.find_by_name("Slave Cat 2").should be_nil
23
+ Cat.create!([{ :name => 'Slave Cat 1' }, { :name => 'Slave Cat 2' }])
24
+ expect(Cat.find_by_name('Slave Cat 1')).to be_nil
25
+ expect(Cat.find_by_name('Slave Cat 2')).to be_nil
26
26
  end
27
27
  end
28
28
 
29
- describe "When enabling the query cache" do
30
- include_context "with query cache enabled"
29
+ describe 'When enabling the query cache' do
30
+ include_context 'with query cache enabled'
31
31
 
32
- it "should do the queries with cache" do
32
+ it 'should do the queries with cache' do
33
33
  OctopusHelper.using_environment :replicated_with_one_slave do
34
- cat1 = Cat.using(:master).create!(:name => "Master Cat 1")
35
- cat2 = Cat.using(:master).create!(:name => "Master Cat 2")
36
- Cat.using(:master).find(cat1.id).should eq(cat1)
37
- Cat.using(:master).find(cat1.id).should eq(cat1)
38
- Cat.using(:master).find(cat1.id).should eq(cat1)
39
-
40
- cat3 = Cat.using(:slave1).create!(:name => "Slave Cat 3")
41
- cat4 = Cat.using(:slave1).create!(:name => "Slave Cat 4")
42
- Cat.find(cat3.id).id.should eq(cat3.id)
43
- Cat.find(cat3.id).id.should eq(cat3.id)
44
- Cat.find(cat3.id).id.should eq(cat3.id)
45
-
46
- counter.query_count.should eq(16)
34
+ cat1 = Cat.using(:master).create!(:name => 'Master Cat 1')
35
+ _ct2 = Cat.using(:master).create!(:name => 'Master Cat 2')
36
+ expect(Cat.using(:master).find(cat1.id)).to eq(cat1)
37
+ expect(Cat.using(:master).find(cat1.id)).to eq(cat1)
38
+ expect(Cat.using(:master).find(cat1.id)).to eq(cat1)
39
+
40
+ cat3 = Cat.using(:slave1).create!(:name => 'Slave Cat 3')
41
+ _ct4 = Cat.using(:slave1).create!(:name => 'Slave Cat 4')
42
+ expect(Cat.find(cat3.id).id).to eq(cat3.id)
43
+ expect(Cat.find(cat3.id).id).to eq(cat3.id)
44
+ expect(Cat.find(cat3.id).id).to eq(cat3.id)
45
+
46
+ expect(counter.query_count).to eq(16)
47
47
  end
48
48
  end
49
49
  end
50
50
 
51
- it "should allow #using syntax to send queries to master" do
52
- Cat.create!(:name => "Master Cat")
51
+ it 'should allow #using syntax to send queries to master' do
52
+ Cat.create!(:name => 'Master Cat')
53
53
 
54
54
  OctopusHelper.using_environment :production_fully_replicated do
55
- Cat.using(:master).find_by_name("Master Cat").should_not be_nil
55
+ expect(Cat.using(:master).find_by_name('Master Cat')).not_to be_nil
56
56
  end
57
57
  end
58
58
 
59
- it "should send the count query to a slave" do
59
+ it 'should send the count query to a slave' do
60
60
  OctopusHelper.using_environment :production_replicated do
61
- Cat.create!(:name => "Slave Cat")
62
- Cat.count.should == 0
61
+ Cat.create!(:name => 'Slave Cat')
62
+ expect(Cat.count).to eq(0)
63
63
  end
64
64
  end
65
65
 
66
- def active_support_subscribed(callback, *args, &block)
66
+ def active_support_subscribed(callback, *args, &_block)
67
67
  subscriber = ActiveSupport::Notifications.subscribe(*args, &callback)
68
68
  yield
69
69
  ensure
@@ -71,51 +71,46 @@ describe "when the database is replicated" do
71
71
  end
72
72
  end
73
73
 
74
-
75
- describe "when the database is replicated and the entire application is replicated" do
74
+ describe 'when the database is replicated and the entire application is replicated' do
76
75
  before(:each) do
77
- Octopus.stub(:env).and_return("production_fully_replicated")
78
- OctopusHelper.clean_connection_proxy()
76
+ allow(Octopus).to receive(:env).and_return('production_fully_replicated')
77
+ OctopusHelper.clean_connection_proxy
79
78
  end
80
79
 
81
- it "should send all writes queries to master" do
80
+ it 'should send all writes queries to master' do
82
81
  OctopusHelper.using_environment :production_fully_replicated do
83
- Cat.create!(:name => "Slave Cat")
84
- Cat.find_by_name("Slave Cat").should be_nil
85
- Client.create!(:name => "Slave Client")
86
- Client.find_by_name("Slave Client").should be_nil
82
+ Cat.create!(:name => 'Slave Cat')
83
+ expect(Cat.find_by_name('Slave Cat')).to be_nil
84
+ Client.create!(:name => 'Slave Client')
85
+ expect(Client.find_by_name('Slave Client')).to be_nil
87
86
  end
88
87
  end
89
88
 
90
- it "should send all writes queries to master" do
89
+ it 'should send all writes queries to master' do
91
90
  OctopusHelper.using_environment :production_fully_replicated do
92
- Cat.create!(:name => "Slave Cat")
93
- Cat.find_by_name("Slave Cat").should be_nil
94
- Client.create!(:name => "Slave Client")
95
- Client.find_by_name("Slave Client").should be_nil
91
+ Cat.create!(:name => 'Slave Cat')
92
+ expect(Cat.find_by_name('Slave Cat')).to be_nil
93
+ Client.create!(:name => 'Slave Client')
94
+ expect(Client.find_by_name('Slave Client')).to be_nil
96
95
  end
97
96
  end
98
97
 
99
- it "should work with validate_uniquess_of" do
100
- Keyboard.create!(:name => "thiago")
98
+ it 'should work with validate_uniquess_of' do
99
+ Keyboard.create!(:name => 'thiago')
101
100
 
102
101
  OctopusHelper.using_environment :production_fully_replicated do
103
- k = Keyboard.new(:name => "thiago")
104
- k.save.should be_false
105
- k.errors.full_messages.should == ["Name has already been taken"]
102
+ k = Keyboard.new(:name => 'thiago')
103
+ expect(k.save).to be false
104
+ expect(k.errors.full_messages).to eq(['Name has already been taken'])
106
105
  end
107
106
  end
108
107
 
109
- it "should reset current shard if slave throws an exception" do
108
+ it 'should reset current shard if slave throws an exception' do
110
109
  OctopusHelper.using_environment :production_fully_replicated do
111
- Cat.create!(:name => "Slave Cat")
112
- Cat.connection.current_shard.should eql(:master)
113
- begin
114
- Cat.where(:rubbish => true)
115
- rescue
116
- end
117
- Cat.connection.current_shard.should eql(:master)
110
+ Cat.create!(:name => 'Slave Cat')
111
+ expect(Cat.connection.current_shard).to eql(:master)
112
+ Cat.where(:rubbish => true)
113
+ expect(Cat.connection.current_shard).to eql(:master)
118
114
  end
119
115
  end
120
116
  end
121
-
@@ -1,17 +1,63 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::ScopeProxy do
4
- it "should allow nested queries" do
5
- @user1 = User.using(:brazil).create!(:name => "Thiago P", :number => 3)
6
- @user2 = User.using(:brazil).create!(:name => "Thiago", :number => 1)
7
- @user3 = User.using(:brazil).create!(:name => "Thiago", :number => 2)
8
-
9
- User.using(:brazil).where(:name => "Thiago").where(:number => 4).order(:number).all.should == []
10
- User.using(:brazil).where(:name => "Thiago").using(:canada).where(:number => 2).using(:brazil).order(:number).all.should == [@user3]
11
- User.using(:brazil).where(:name => "Thiago").using(:canada).where(:number => 4).using(:brazil).order(:number).all.should == []
4
+ it 'should allow nested queries' do
5
+ @user1 = User.using(:brazil).create!(:name => 'Thiago P', :number => 3)
6
+ @user2 = User.using(:brazil).create!(:name => 'Thiago', :number => 1)
7
+ @user3 = User.using(:brazil).create!(:name => 'Thiago', :number => 2)
8
+
9
+ expect(User.using(:brazil).where(:name => 'Thiago').where(:number => 4).order(:number).all).to eq([])
10
+ expect(User.using(:brazil).where(:name => 'Thiago').using(:canada).where(:number => 2).using(:brazil).order(:number).all).to eq([@user3])
11
+ expect(User.using(:brazil).where(:name => 'Thiago').using(:canada).where(:number => 4).using(:brazil).order(:number).all).to eq([])
12
+ end
13
+
14
+ context "When array-like-selecting an item in a group" do
15
+ before(:each) do
16
+ User.using(:brazil).create!(:name => "Evan", :number => 1)
17
+ User.using(:brazil).create!(:name => "Evan", :number => 2)
18
+ User.using(:brazil).create!(:name => "Evan", :number => 3)
19
+ @evans = User.using(:brazil).where(:name => "Evan")
20
+ end
21
+
22
+ it "allows a block to select an item" do
23
+ @evans.select{|u| u.number == 2}.first.number.should eq(2)
24
+ end
25
+ end
26
+
27
+ context "When selecting a field within a scope" do
28
+ before(:each) do
29
+ User.using(:brazil).create!(:name => "Evan", :number => 4)
30
+ @evan = User.using(:brazil).where(:name => "Evan")
31
+ end
32
+
33
+ it "allows single field selection" do
34
+ @evan.select("name").first.name.should eq("Evan")
35
+ end
36
+
37
+ it "allows selection by array" do
38
+ @evan.select(["name"]).first.name.should eq("Evan")
39
+ end
40
+
41
+ it "allows multiple selection by string" do
42
+ @evan.select("id, name").first.id.should be_a Fixnum
43
+ end
44
+
45
+ it "allows multiple selection by array" do
46
+ @evan.select(["id", "name"]).first.id.should be_a Fixnum
47
+ end
48
+
49
+ if Octopus.rails4?
50
+ it "allows multiple selection by symbol" do
51
+ @evan.select(:id, :name).first.id.should be_a Fixnum
52
+ end
53
+
54
+ it "allows multiple selection by string and symbol" do
55
+ @evan.select(:id, "name").first.id.should be_a Fixnum
56
+ end
57
+ end
12
58
  end
13
59
 
14
60
  it "should raise a exception when trying to send a query to a shard that don't exists" do
15
- lambda { User.using(:dont_exists).all }.should raise_exception("Nonexistent Shard Name: dont_exists")
61
+ expect { User.using(:dont_exists).all }.to raise_exception('Nonexistent Shard Name: dont_exists')
16
62
  end
17
63
  end