ar-octopus 0.8.2 → 0.8.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.
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,15 +1,16 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::CollectionProxy do
4
- describe "method dispatch" do
4
+ describe 'method dispatch' do
5
5
  before :each do
6
6
  @client = Client.using(:canada).create!
7
7
  @client.items << Item.using(:canada).create!
8
8
  end
9
9
 
10
- it "computes the size of the collection without loading it" do
11
- @client.items.size.should eq(1)
12
- @client.items.should_not be_loaded
10
+ it 'computes the size of the collection without loading it' do
11
+ expect(@client.items.size).to eq(1)
12
+
13
+ expect(@client.items.loaded?).to be false
13
14
  end
14
15
  end
15
16
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::LogSubscriber, :shards => [:canada] do
4
4
  before :each do
@@ -12,8 +12,8 @@ describe Octopus::LogSubscriber, :shards => [:canada] do
12
12
  ActiveRecord::Base.logger = nil
13
13
  end
14
14
 
15
- it "should add to the default logger the shard name the query was sent to" do
16
- User.using(:canada).create!(:name => "test")
17
- @out.string.should =~ /Shard: canada/
15
+ it 'should add to the default logger the shard name the query was sent to' do
16
+ User.using(:canada).create!(:name => 'test')
17
+ expect(@out.string).to match(/Shard: canada/)
18
18
  end
19
19
  end
@@ -1,112 +1,112 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::Migration do
4
- it "should run just in the master shard" do
4
+ it 'should run just in the master shard' do
5
5
  OctopusHelper.migrating_to_version 1 do
6
- User.using(:master).find_by_name("Master").should_not be_nil
7
- User.using(:canada).find_by_name("Master").should be_nil
6
+ expect(User.using(:master).find_by_name('Master')).not_to be_nil
7
+ expect(User.using(:canada).find_by_name('Master')).to be_nil
8
8
  end
9
9
  end
10
10
 
11
- it "should run on specific shard" do
11
+ it 'should run on specific shard' do
12
12
  OctopusHelper.migrating_to_version 2 do
13
- User.using(:master).find_by_name("Sharding").should be_nil
14
- User.using(:canada).find_by_name("Sharding").should_not be_nil
13
+ expect(User.using(:master).find_by_name('Sharding')).to be_nil
14
+ expect(User.using(:canada).find_by_name('Sharding')).not_to be_nil
15
15
  end
16
16
  end
17
17
 
18
- it "should run on specifieds shards" do
18
+ it 'should run on specifieds shards' do
19
19
  OctopusHelper.migrating_to_version 3 do
20
- User.using(:brazil).find_by_name("Both").should_not be_nil
21
- User.using(:canada).find_by_name("Both").should_not be_nil
20
+ expect(User.using(:brazil).find_by_name('Both')).not_to be_nil
21
+ expect(User.using(:canada).find_by_name('Both')).not_to be_nil
22
22
  end
23
23
  end
24
24
 
25
- it "should run on specified group" do
25
+ it 'should run on specified group' do
26
26
  OctopusHelper.migrating_to_version 4 do
27
- User.using(:canada).find_by_name("Group").should_not be_nil
28
- User.using(:brazil).find_by_name("Group").should_not be_nil
29
- User.using(:russia).find_by_name("Group").should_not be_nil
27
+ expect(User.using(:canada).find_by_name('Group')).not_to be_nil
28
+ expect(User.using(:brazil).find_by_name('Group')).not_to be_nil
29
+ expect(User.using(:russia).find_by_name('Group')).not_to be_nil
30
30
  end
31
31
  end
32
32
 
33
- it "should run once per shard" do
33
+ it 'should run once per shard' do
34
34
  OctopusHelper.migrating_to_version 5 do
35
- User.using(:canada).where(:name => 'MultipleGroup').size.should == 1
36
- User.using(:brazil).where(:name => 'MultipleGroup').size.should == 1
37
- User.using(:russia).where(:name => 'MultipleGroup').size.should == 1
35
+ expect(User.using(:canada).where(:name => 'MultipleGroup').size).to eq(1)
36
+ expect(User.using(:brazil).where(:name => 'MultipleGroup').size).to eq(1)
37
+ expect(User.using(:russia).where(:name => 'MultipleGroup').size).to eq(1)
38
38
  end
39
39
  end
40
40
 
41
- it "should create users inside block" do
41
+ it 'should create users inside block' do
42
42
  OctopusHelper.migrating_to_version 12 do
43
- User.using(:brazil).where(:name => 'UsingBlock1').size.should == 1
44
- User.using(:brazil).where(:name => 'UsingBlock2').size.should == 1
45
- User.using(:canada).where(:name => 'UsingCanada').size.should == 1
46
- User.using(:canada).where(:name => 'UsingCanada2').size.should == 1
43
+ expect(User.using(:brazil).where(:name => 'UsingBlock1').size).to eq(1)
44
+ expect(User.using(:brazil).where(:name => 'UsingBlock2').size).to eq(1)
45
+ expect(User.using(:canada).where(:name => 'UsingCanada').size).to eq(1)
46
+ expect(User.using(:canada).where(:name => 'UsingCanada2').size).to eq(1)
47
47
  end
48
48
  end
49
49
 
50
- it "should send the query to the correct shard" do
50
+ it 'should send the query to the correct shard' do
51
51
  OctopusHelper.migrating_to_version 13 do
52
- User.using(:brazil).where(:name => 'Brazil').size.should == 1
53
- User.using(:brazil).where(:name => 'Canada').size.should == 0
54
- User.using(:canada).where(:name => 'Brazil').size.should == 0
55
- User.using(:canada).where(:name => 'Canada').size.should == 1
52
+ expect(User.using(:brazil).where(:name => 'Brazil').size).to eq(1)
53
+ expect(User.using(:brazil).where(:name => 'Canada').size).to eq(0)
54
+ expect(User.using(:canada).where(:name => 'Brazil').size).to eq(0)
55
+ expect(User.using(:canada).where(:name => 'Canada').size).to eq(1)
56
56
  end
57
57
  end
58
58
 
59
- describe "when using replication" do
60
- it "should run writes on master when you use replication" do
59
+ describe 'when using replication' do
60
+ it 'should run writes on master when you use replication' do
61
61
  OctopusHelper.using_environment :production_replicated do
62
62
  OctopusHelper.migrating_to_version 10 do
63
- Cat.find_by_name("Replication").should be_nil
63
+ expect(Cat.find_by_name('Replication')).to be_nil
64
64
  end
65
65
  end
66
66
  end
67
67
 
68
- it "should run in all shards, master or another shards" do
68
+ it 'should run in all shards, master or another shards' do
69
69
  OctopusHelper.using_environment :production_replicated do
70
70
  OctopusHelper.migrating_to_version 11 do
71
- [:slave4, :slave1, :slave2, :slave3].each do |sym|
72
- Cat.find_by_name("Slaves").should_not be_nil
71
+ [:slave4, :slave1, :slave2, :slave3].each do |_sym|
72
+ expect(Cat.find_by_name('Slaves')).not_to be_nil
73
73
  end
74
74
  end
75
75
  end
76
76
  end
77
77
  end
78
78
 
79
- it "should store the migration versions in each shard" do
79
+ it 'should store the migration versions in each shard' do
80
80
  class SchemaMigration < ActiveRecord::Base; end
81
81
 
82
82
  OctopusHelper.migrating_to_version 14 do
83
- Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }.should include(14)
84
- Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }.should include(14)
85
- Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }.should include(14)
83
+ expect(Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }).to include(14)
84
+ expect(Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }).to include(14)
85
+ expect(Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }).to include(14)
86
86
  end
87
87
  end
88
88
 
89
- it "should run the migrations on shards that are missing them" do
89
+ it 'should run the migrations on shards that are missing them' do
90
90
  class SchemaMigration < ActiveRecord::Base; end
91
91
 
92
92
  Octopus.using(:master) { SchemaMigration.create(:version => 14) }
93
93
  Octopus.using(:canada) { SchemaMigration.create(:version => 14) }
94
94
 
95
95
  OctopusHelper.migrating_to_version 14 do
96
- Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }.should include(14)
97
- Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }.should include(14)
98
- Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }.should include(14)
96
+ expect(Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }).to include(14)
97
+ expect(Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }).to include(14)
98
+ expect(Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }).to include(14)
99
99
  end
100
100
  end
101
101
 
102
- describe "when using a default_migration_group" do
103
- it "should run migrations on all shards in the default_migration_group" do
102
+ describe 'when using a default_migration_group' do
103
+ it 'should run migrations on all shards in the default_migration_group' do
104
104
  OctopusHelper.using_environment :octopus_with_default_migration_group do
105
105
  OctopusHelper.migrating_to_version 15 do
106
- Octopus.using(:master) { ActiveRecord::Migrator.get_all_versions }.should_not include(15)
107
- Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }.should include(15)
108
- Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }.should include(15)
109
- Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }.should include(15)
106
+ expect(Octopus.using(:master) { ActiveRecord::Migrator.get_all_versions }).not_to include(15)
107
+ expect(Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }).to include(15)
108
+ expect(Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }).to include(15)
109
+ expect(Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }).to include(15)
110
110
  end
111
111
  end
112
112
  end
@@ -1,23 +1,23 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::Model do
4
- describe "#using method" do
5
- it "should return self after calling the #using method" do
6
- User.using(:canada).should be_a(Octopus::ScopeProxy)
4
+ describe '#using method' do
5
+ it 'should return self after calling the #using method' do
6
+ expect(User.using(:canada)).to be_a(Octopus::ScopeProxy)
7
7
  end
8
8
 
9
- it "should allow to send a block to the master shard" do
9
+ it 'should allow to send a block to the master shard' do
10
10
  Octopus.using(:master) do
11
- User.create!(:name => "Block test")
11
+ User.create!(:name => 'Block test')
12
12
  end
13
13
 
14
- User.using(:master).find_by_name("Block test").should_not be_nil
14
+ expect(User.using(:master).find_by_name('Block test')).not_to be_nil
15
15
  end
16
16
 
17
17
  it 'should allow to pass a string as the shard name to a AR subclass' do
18
18
  User.using('canada').create!(:name => 'Rafael Pilha')
19
19
 
20
- User.using('canada').find_by_name('Rafael Pilha').should_not be_nil
20
+ expect(User.using('canada').find_by_name('Rafael Pilha')).not_to be_nil
21
21
  end
22
22
 
23
23
  it 'should allow to pass a string as the shard name to a block' do
@@ -25,192 +25,191 @@ describe Octopus::Model do
25
25
  User.create!(:name => 'Rafael Pilha')
26
26
  end
27
27
 
28
- User.using('canada').find_by_name('Rafael Pilha').should_not be_nil
28
+ expect(User.using('canada').find_by_name('Rafael Pilha')).not_to be_nil
29
29
  end
30
30
 
31
- it "should allow selecting the shards on scope" do
31
+ it 'should allow selecting the shards on scope' do
32
32
  User.using(:canada).create!(:name => 'oi')
33
- User.using(:canada).count.should == 1
34
- User.count.should == 0
33
+ expect(User.using(:canada).count).to eq(1)
34
+ expect(User.count).to eq(0)
35
35
  end
36
36
 
37
- it "should allow selecting the shard using #new" do
37
+ it 'should allow selecting the shard using #new' do
38
38
  u = User.using(:canada).new
39
- u.name = "Thiago"
39
+ u.name = 'Thiago'
40
40
  u.save
41
41
 
42
- User.using(:canada).count.should == 1
43
- User.using(:brazil).count.should == 0
42
+ expect(User.using(:canada).count).to eq(1)
43
+ expect(User.using(:brazil).count).to eq(0)
44
44
 
45
45
  u1 = User.new
46
- u1.name = "Joaquim"
46
+ u1.name = 'Joaquim'
47
47
  u2 = User.using(:canada).new
48
- u2.name = "Manuel"
49
- u1.save()
50
- u2.save()
48
+ u2.name = 'Manuel'
49
+ u1.save
50
+ u2.save
51
51
 
52
- User.using(:canada).all.should == [u, u2]
53
- User.all.should == [u1]
52
+ expect(User.using(:canada).all).to eq([u, u2])
53
+ expect(User.all).to eq([u1])
54
54
  end
55
55
 
56
- describe "multiple calls to the same scope" do
57
- it "works with nil response" do
56
+ describe 'multiple calls to the same scope' do
57
+ it 'works with nil response' do
58
58
  scope = User.using(:canada)
59
- scope.count.should == 0
60
- scope.first.should be_nil
59
+ expect(scope.count).to eq(0)
60
+ expect(scope.first).to be_nil
61
61
  end
62
62
 
63
- it "works with non-nil response" do
63
+ it 'works with non-nil response' do
64
64
  user = User.using(:canada).create!(:name => 'oi')
65
65
  scope = User.using(:canada)
66
- scope.count.should == 1
67
- scope.first.should == user
66
+ expect(scope.count).to eq(1)
67
+ expect(scope.first).to eq(user)
68
68
  end
69
69
  end
70
70
 
71
- it "should select the correct shard" do
71
+ it 'should select the correct shard' do
72
72
  User.using(:canada)
73
73
  User.create!(:name => 'oi')
74
- User.count.should == 1
74
+ expect(User.count).to eq(1)
75
75
  end
76
76
 
77
- it "should ensure that the connection will be cleaned" do
78
- ActiveRecord::Base.connection.current_shard.should == :master
79
- begin
77
+ it 'should ensure that the connection will be cleaned' do
78
+ expect(ActiveRecord::Base.connection.current_shard).to eq(:master)
79
+ expect do
80
80
  Octopus.using(:canada) do
81
- raise "Some Exception"
81
+ fail 'Some Exception'
82
82
  end
83
- rescue
84
- end
83
+ end.to raise_error
85
84
 
86
- ActiveRecord::Base.connection.current_shard.should == :master
85
+ expect(ActiveRecord::Base.connection.current_shard).to eq(:master)
87
86
  end
88
87
 
89
- it "should allow creating more than one user" do
88
+ it 'should allow creating more than one user' do
90
89
  User.using(:canada).create([{ :name => 'America User 1' }, { :name => 'America User 2' }])
91
- User.create!(:name => "Thiago")
92
- User.using(:canada).find_by_name("America User 1").should_not be_nil
93
- User.using(:canada).find_by_name("America User 2").should_not be_nil
94
- User.using(:master).find_by_name("Thiago").should_not be_nil
90
+ User.create!(:name => 'Thiago')
91
+ expect(User.using(:canada).find_by_name('America User 1')).not_to be_nil
92
+ expect(User.using(:canada).find_by_name('America User 2')).not_to be_nil
93
+ expect(User.using(:master).find_by_name('Thiago')).not_to be_nil
95
94
  end
96
95
 
97
- it "should work when you have a SQLite3 shard" do
98
- u = User.using(:sqlite_shard).create!(:name => "Sqlite3")
99
- User.using(:sqlite_shard).find_by_name("Sqlite3").should == u
96
+ it 'should work when you have a SQLite3 shard' do
97
+ u = User.using(:sqlite_shard).create!(:name => 'Sqlite3')
98
+ expect(User.using(:sqlite_shard).find_by_name('Sqlite3')).to eq(u)
100
99
  end
101
100
 
102
- it "should clean #current_shard from proxy when using execute" do
103
- User.using(:canada).connection().execute("select * from users limit 1;")
104
- User.connection.current_shard.should == :master
101
+ it 'should clean #current_shard from proxy when using execute' do
102
+ User.using(:canada).connection.execute('select * from users limit 1;')
103
+ expect(User.connection.current_shard).to eq(:master)
105
104
  end
106
105
 
107
- it "should allow scoping dynamically" do
106
+ it 'should allow scoping dynamically' do
108
107
  User.using(:canada).using(:master).using(:canada).create!(:name => 'oi')
109
- User.using(:canada).using(:master).count.should == 0
110
- User.using(:master).using(:canada).count.should == 1
108
+ expect(User.using(:canada).using(:master).count).to eq(0)
109
+ expect(User.using(:master).using(:canada).count).to eq(1)
111
110
  end
112
111
 
113
- it "should allow find inside blocks" do
114
- @user = User.using(:brazil).create!(:name => "Thiago")
112
+ it 'should allow find inside blocks' do
113
+ @user = User.using(:brazil).create!(:name => 'Thiago')
115
114
 
116
115
  Octopus.using(:brazil) do
117
- User.first.should == @user
116
+ expect(User.first).to eq(@user)
118
117
  end
119
118
 
120
- User.using(:brazil).find_by_name("Thiago").should == @user
119
+ expect(User.using(:brazil).find_by_name('Thiago')).to eq(@user)
121
120
  end
122
121
 
123
- it "should clean the current_shard after executing the current query" do
124
- User.using(:canada).create!(:name => "oi")
125
- User.count.should == 0
122
+ it 'should clean the current_shard after executing the current query' do
123
+ User.using(:canada).create!(:name => 'oi')
124
+ expect(User.count).to eq(0)
126
125
  end
127
126
 
128
- it "should support both groups and alone shards" do
129
- u = User.using(:alone_shard).create!(:name => "Alone")
130
- User.using(:alone_shard).count.should == 1
131
- User.using(:canada).count.should == 0
132
- User.using(:brazil).count.should == 0
133
- User.count.should == 0
127
+ it 'should support both groups and alone shards' do
128
+ _u = User.using(:alone_shard).create!(:name => 'Alone')
129
+ expect(User.using(:alone_shard).count).to eq(1)
130
+ expect(User.using(:canada).count).to eq(0)
131
+ expect(User.using(:brazil).count).to eq(0)
132
+ expect(User.count).to eq(0)
134
133
  end
135
134
 
136
- it "should work with named scopes" do
137
- u = User.using(:brazil).create!(:name => "Thiago")
135
+ it 'should work with named scopes' do
136
+ u = User.using(:brazil).create!(:name => 'Thiago')
138
137
 
139
- User.thiago.using(:brazil).first.should eq(u)
140
- User.using(:brazil).thiago.first.should eq(u)
138
+ expect(User.thiago.using(:brazil).first).to eq(u)
139
+ expect(User.using(:brazil).thiago.first).to eq(u)
141
140
 
142
141
  Octopus.using(:brazil) do
143
- User.thiago.first.should eq(u)
142
+ expect(User.thiago.first).to eq(u)
144
143
  end
145
144
  end
146
145
 
147
- describe "#current_shard attribute" do
148
- it "should store the attribute when you create or find an object" do
149
- u = User.using(:alone_shard).create!(:name => "Alone")
150
- u.current_shard.should == :alone_shard
146
+ describe '#current_shard attribute' do
147
+ it 'should store the attribute when you create or find an object' do
148
+ u = User.using(:alone_shard).create!(:name => 'Alone')
149
+ expect(u.current_shard).to eq(:alone_shard)
151
150
  User.using(:canada).create!(:name => 'oi')
152
- u = User.using(:canada).find_by_name("oi")
153
- u.current_shard.should == :canada
151
+ u = User.using(:canada).find_by_name('oi')
152
+ expect(u.current_shard).to eq(:canada)
154
153
  end
155
154
 
156
- it "should store the attribute when you find multiple instances" do
157
- 5.times { User.using(:alone_shard).create!(:name => "Alone") }
155
+ it 'should store the attribute when you find multiple instances' do
156
+ 5.times { User.using(:alone_shard).create!(:name => 'Alone') }
158
157
 
159
158
  User.using(:alone_shard).all.each do |u|
160
- u.current_shard.should == :alone_shard
159
+ expect(u.current_shard).to eq(:alone_shard)
161
160
  end
162
161
  end
163
162
 
164
- it "should works when you find, and after that, alter that object" do
165
- alone_user = User.using(:alone_shard).create!(:name => "Alone")
166
- master_user = User.using(:master).create!(:name => "Master")
167
- alone_user.name = "teste"
163
+ it 'should works when you find, and after that, alter that object' do
164
+ alone_user = User.using(:alone_shard).create!(:name => 'Alone')
165
+ _mstr_user = User.using(:master).create!(:name => 'Master')
166
+ alone_user.name = 'teste'
168
167
  alone_user.save
169
- User.using(:master).find(:first).name.should == "Master"
170
- User.using(:alone_shard).find(:first).name.should == "teste"
168
+ expect(User.using(:master).first.name).to eq('Master')
169
+ expect(User.using(:alone_shard).first.name).to eq('teste')
171
170
  end
172
171
 
173
- it "should work for the reload method" do
174
- User.using(:alone_shard).create!(:name => "Alone")
175
- u = User.using(:alone_shard).find_by_name("Alone")
172
+ it 'should work for the reload method' do
173
+ User.using(:alone_shard).create!(:name => 'Alone')
174
+ u = User.using(:alone_shard).find_by_name('Alone')
176
175
  u.reload
177
- u.name.should == "Alone"
176
+ expect(u.name).to eq('Alone')
178
177
  end
179
178
 
180
- it "should work passing some arguments to reload method" do
181
- User.using(:alone_shard).create!(:name => "Alone")
182
- u = User.using(:alone_shard).find_by_name("Alone")
179
+ it 'should work passing some arguments to reload method' do
180
+ User.using(:alone_shard).create!(:name => 'Alone')
181
+ u = User.using(:alone_shard).find_by_name('Alone')
183
182
  u.reload(:lock => true)
184
- u.name.should == "Alone"
183
+ expect(u.name).to eq('Alone')
185
184
  end
186
185
  end
187
186
 
188
- describe "passing a block" do
189
- it "should allow queries be executed inside the block, ponting to a specific shard" do
187
+ describe 'passing a block' do
188
+ it 'should allow queries be executed inside the block, ponting to a specific shard' do
190
189
  Octopus.using(:canada) do
191
- User.create(:name => "oi")
190
+ User.create(:name => 'oi')
192
191
  end
193
192
 
194
- User.using(:canada).count.should == 1
195
- User.using(:master).count.should == 0
196
- User.count.should == 0
193
+ expect(User.using(:canada).count).to eq(1)
194
+ expect(User.using(:master).count).to eq(0)
195
+ expect(User.count).to eq(0)
197
196
  end
198
197
 
199
- it "should allow execute queries inside a model" do
198
+ it 'should allow execute queries inside a model' do
200
199
  u = User.new
201
- u.awesome_queries()
202
- User.using(:canada).count.should == 1
203
- User.count.should == 0
200
+ u.awesome_queries
201
+ expect(User.using(:canada).count).to eq(1)
202
+ expect(User.count).to eq(0)
204
203
  end
205
204
  end
206
205
 
207
- describe "raising errors" do
206
+ describe 'raising errors' do
208
207
  it "should raise a error when you specify a shard that doesn't exist" do
209
- lambda { User.using(:crazy_shard).create!(:name => 'Thiago') }.should raise_error("Nonexistent Shard Name: crazy_shard")
208
+ expect { User.using(:crazy_shard).create!(:name => 'Thiago') }.to raise_error('Nonexistent Shard Name: crazy_shard')
210
209
  end
211
210
  end
212
211
 
213
- describe "equality" do
212
+ describe 'equality' do
214
213
  let(:canada1) do
215
214
  u = User.new
216
215
  u.id = 1
@@ -232,353 +231,329 @@ describe Octopus::Model do
232
231
  u
233
232
  end
234
233
 
235
- it "should work with persisted objects" do
236
- u = User.using(:brazil).create(:name => "Mike")
237
- User.using(:brazil).find_by_name("Mike").should == u
234
+ it 'should work with persisted objects' do
235
+ u = User.using(:brazil).create(:name => 'Mike')
236
+ expect(User.using(:brazil).find_by_name('Mike')).to eq(u)
238
237
  end
239
238
 
240
- it "should check current_shard when determining equality" do
241
- canada1.should_not == brazil1
242
- canada1.should == canada1_dup
239
+ it 'should check current_shard when determining equality' do
240
+ expect(canada1).not_to eq(brazil1)
241
+ expect(canada1).to eq(canada1_dup)
243
242
  end
244
243
 
245
- it "delegates equality check on scopes" do
246
- u = User.using(:brazil).create!(:name => "Mike")
247
- User.using(:brazil).where(:name => "Mike").should == [u]
244
+ it 'delegates equality check on scopes' do
245
+ u = User.using(:brazil).create!(:name => 'Mike')
246
+ expect(User.using(:brazil).where(:name => 'Mike')).to eq([u])
248
247
  end
249
248
  end
250
249
  end
251
250
 
252
- describe "using a postgresql shard" do
253
- it "should update the Arel Engine" do
254
- if ActiveRecord::VERSION::STRING > '2.4.0'
255
- User.using(:postgresql_shard).arel_engine.connection.adapter_name.should == "PostgreSQL"
256
- User.using(:alone_shard).arel_engine.connection.adapter_name.should == "Mysql2"
257
- end
251
+ describe 'using a postgresql shard' do
252
+ it 'should update the Arel Engine' do
253
+ expect(User.using(:postgresql_shard).arel_engine.connection.adapter_name).to eq('PostgreSQL')
254
+ expect(User.using(:alone_shard).arel_engine.connection.adapter_name).to eq('Mysql2')
258
255
  end
259
256
 
260
- it "should works with writes and reads" do
261
- u = User.using(:postgresql_shard).create!(:name => "PostgreSQL User")
262
- User.using(:postgresql_shard).find(:all).should == [u]
263
- User.using(:alone_shard).find(:all).should == []
264
- User.connection_handler.connection_pools["ActiveRecord::Base"] = User.connection.instance_variable_get(:@shards)[:master]
257
+ it 'should works with writes and reads' do
258
+ u = User.using(:postgresql_shard).create!(:name => 'PostgreSQL User')
259
+ expect(User.using(:postgresql_shard).all).to eq([u])
260
+ expect(User.using(:alone_shard).all).to eq([])
261
+ User.connection_handler.connection_pools['ActiveRecord::Base'] = User.connection.instance_variable_get(:@shards)[:master]
265
262
  end
266
263
  end
267
264
 
268
- describe "AR basic methods" do
269
- it "establish_connection" do
270
- CustomConnection.connection.current_database.should == "octopus_shard_2"
265
+ describe 'AR basic methods' do
266
+ it 'establish_connection' do
267
+ expect(CustomConnection.connection.current_database).to eq('octopus_shard_2')
271
268
  end
272
269
 
273
- it "should not mess with custom connection table names" do
274
- Advert.connection.current_database.should == "octopus_shard_1"
275
- Advert.create!(:name => "Teste")
270
+ it 'should not mess with custom connection table names' do
271
+ expect(Advert.connection.current_database).to eq('octopus_shard_1')
272
+ Advert.create!(:name => 'Teste')
276
273
  end
277
274
 
278
- it "increment" do
279
- u = User.using(:brazil).create!(:name => "Teste", :number => 10)
275
+ it 'increment' do
276
+ _ = User.using(:brazil).create!(:name => 'Teste', :number => 10)
280
277
  u = User.using(:brazil).find_by_number(10)
281
278
  u.increment(:number)
282
- u.save()
283
- u = User.using(:brazil).find_by_number(11).should_not be_nil
279
+ u.save
280
+ expect(User.using(:brazil).find_by_number(11)).not_to be_nil
284
281
  end
285
282
 
286
- it "increment!" do
287
- u = User.using(:brazil).create!(:name => "Teste", :number => 10)
283
+ it 'increment!' do
284
+ _ = User.using(:brazil).create!(:name => 'Teste', :number => 10)
288
285
  u = User.using(:brazil).find_by_number(10)
289
286
  u.increment!(:number)
290
- u = User.using(:brazil).find_by_number(11).should_not be_nil
287
+ expect(User.using(:brazil).find_by_number(11)).not_to be_nil
291
288
  end
292
289
 
293
- it "decrement" do
294
- u = User.using(:brazil).create!(:name => "Teste", :number => 10)
290
+ it 'decrement' do
291
+ _ = User.using(:brazil).create!(:name => 'Teste', :number => 10)
295
292
  u = User.using(:brazil).find_by_number(10)
296
293
  u.decrement(:number)
297
- u.save()
298
- u = User.using(:brazil).find_by_number(9).should_not be_nil
294
+ u.save
295
+ expect(User.using(:brazil).find_by_number(9)).not_to be_nil
299
296
  end
300
297
 
301
- it "decrement!" do
302
- u = User.using(:brazil).create!(:name => "Teste", :number => 10)
298
+ it 'decrement!' do
299
+ _ = User.using(:brazil).create!(:name => 'Teste', :number => 10)
303
300
  u = User.using(:brazil).find_by_number(10)
304
301
  u.decrement!(:number)
305
- u = User.using(:brazil).find_by_number(9).should_not be_nil
302
+ expect(User.using(:brazil).find_by_number(9)).not_to be_nil
306
303
  end
307
304
 
308
- it "toggle" do
309
- u = User.using(:brazil).create!(:name => "Teste", :admin => false)
305
+ it 'toggle' do
306
+ _ = User.using(:brazil).create!(:name => 'Teste', :admin => false)
310
307
  u = User.using(:brazil).find_by_name('Teste')
311
308
  u.toggle(:admin)
312
- u.save()
313
- u = User.using(:brazil).find_by_name('Teste').admin.should be_true
309
+ u.save
310
+ expect(User.using(:brazil).find_by_name('Teste').admin).to be true
314
311
  end
315
312
 
316
- it "toggle!" do
317
- u = User.using(:brazil).create!(:name => "Teste", :admin => false)
313
+ it 'toggle!' do
314
+ _ = User.using(:brazil).create!(:name => 'Teste', :admin => false)
318
315
  u = User.using(:brazil).find_by_name('Teste')
319
316
  u.toggle!(:admin)
320
- u = User.using(:brazil).find_by_name('Teste').admin.should be_true
317
+ expect(User.using(:brazil).find_by_name('Teste').admin).to be true
321
318
  end
322
319
 
323
- it "count" do
324
- u = User.using(:brazil).create!(:name => "User1")
325
- u2 = User.using(:brazil).create!(:name => "User2")
326
- u3 = User.using(:brazil).create!(:name => "User3")
327
- User.using(:brazil).find(:all, :conditions => {:name => "User2"}).count.should == 1
320
+ it 'count' do
321
+ _u = User.using(:brazil).create!(:name => 'User1')
322
+ _v = User.using(:brazil).create!(:name => 'User2')
323
+ _w = User.using(:brazil).create!(:name => 'User3')
324
+ expect(User.using(:brazil).where(:name => 'User2').all.count).to eq(1)
328
325
  end
329
326
 
330
- it "maximum" do
331
- u1 = User.using(:brazil).create!(:name => "Teste", :number => 11)
332
- u2 = User.using(:master).create!(:name => "Teste", :number => 12)
327
+ it 'maximum' do
328
+ _u = User.using(:brazil).create!(:name => 'Teste', :number => 11)
329
+ _v = User.using(:master).create!(:name => 'Teste', :number => 12)
333
330
 
334
- User.using(:brazil).maximum(:number).should == 11
335
- User.using(:master).maximum(:number).should == 12
331
+ expect(User.using(:brazil).maximum(:number)).to eq(11)
332
+ expect(User.using(:master).maximum(:number)).to eq(12)
336
333
  end
337
334
 
338
- describe "any?" do
339
- before { User.using(:brazil).create!(:name => "User1") }
335
+ describe 'any?' do
336
+ before { User.using(:brazil).create!(:name => 'User1') }
340
337
 
341
- it "works when true" do
342
- scope = User.using(:brazil).where(:name => "User1")
343
- scope.any?.should be_true
338
+ it 'works when true' do
339
+ scope = User.using(:brazil).where(:name => 'User1')
340
+ expect(scope.any?).to be true
344
341
  end
345
342
 
346
- it "works when false" do
347
- scope = User.using(:brazil).where(:name => "User2")
348
- scope.any?.should be_false
343
+ it 'works when false' do
344
+ scope = User.using(:brazil).where(:name => 'User2')
345
+ expect(scope.any?).to be false
349
346
  end
350
347
  end
351
348
 
352
- it "exists?" do
353
- @user = User.using(:brazil).create!(:name => "User1")
349
+ it 'exists?' do
350
+ @user = User.using(:brazil).create!(:name => 'User1')
354
351
 
355
- User.using(:brazil).where(:name => "User1").exists?.should be_true
356
- User.using(:brazil).where(:name => "User2").exists?.should be_false
352
+ expect(User.using(:brazil).where(:name => 'User1').exists?).to be true
353
+ expect(User.using(:brazil).where(:name => 'User2').exists?).to be false
357
354
  end
358
355
 
359
- describe "touch" do
360
- it "updates updated_at by default" do
361
- @user = User.using(:brazil).create!(:name => "User1")
362
- User.using(:brazil).update_all({:updated_at => Time.now - 3.months}, {:id => @user.id})
356
+ describe 'touch' do
357
+ it 'updates updated_at by default' do
358
+ @user = User.using(:brazil).create!(:name => 'User1')
359
+ User.using(:brazil).where(:id => @user.id).update_all(:updated_at => Time.now - 3.months)
363
360
  @user.touch
364
- @user.reload.updated_at.in_time_zone('GMT').to_date.should eq(Time.now.in_time_zone('GMT').to_date)
361
+ expect(@user.reload.updated_at.in_time_zone('GMT').to_date).to eq(Time.now.in_time_zone('GMT').to_date)
365
362
  end
366
363
 
367
- it "updates passed in attribute name" do
368
- @user = User.using(:brazil).create!(:name => "User1")
369
- User.using(:brazil).update_all({:created_at => Time.now - 3.months}, {:id => @user.id})
364
+ it 'updates passed in attribute name' do
365
+ @user = User.using(:brazil).create!(:name => 'User1')
366
+ User.using(:brazil).where(:id => @user.id).update_all(:created_at => Time.now - 3.months)
370
367
  @user.touch(:created_at)
371
- @user.reload.created_at.in_time_zone('GMT').to_date.should eq(Time.now.in_time_zone('GMT').to_date)
368
+ expect(@user.reload.created_at.in_time_zone('GMT').to_date).to eq(Time.now.in_time_zone('GMT').to_date)
372
369
  end
373
370
  end
374
371
 
375
- describe "#pluck" do
376
- before { User.using(:brazil).create!(:name => "User1") }
372
+ describe '#pluck' do
373
+ before { User.using(:brazil).create!(:name => 'User1') }
377
374
 
378
- it "should works from scope proxy" do
375
+ it 'should works from scope proxy' do
379
376
  names = User.using(:brazil).pluck(:name)
380
- names.should eq(["User1"])
381
- User.using(:master).pluck(:name).should eq([])
377
+ expect(names).to eq(['User1'])
378
+ expect(User.using(:master).pluck(:name)).to eq([])
382
379
  end
383
380
  end
384
381
 
385
- it "update_column" do
386
- @user = User.using(:brazil).create!(:name => "User1")
382
+ it 'update_column' do
383
+ @user = User.using(:brazil).create!(:name => 'User1')
387
384
  @user2 = User.using(:brazil).find(@user.id)
388
- @user2.update_column(:name, "Joaquim Shard Brazil")
389
- User.using(:brazil).find_by_name("Joaquim Shard Brazil").should_not be_nil
385
+ @user2.update_column(:name, 'Joaquim Shard Brazil')
386
+ expect(User.using(:brazil).find_by_name('Joaquim Shard Brazil')).not_to be_nil
390
387
  end
391
388
 
392
- it "update_attributes" do
393
- @user = User.using(:brazil).create!(:name => "User1")
389
+ it 'update_attributes' do
390
+ @user = User.using(:brazil).create!(:name => 'User1')
394
391
  @user2 = User.using(:brazil).find(@user.id)
395
- @user2.update_attributes(:name => "Joaquim")
396
- User.using(:brazil).find_by_name("Joaquim").should_not be_nil
392
+ @user2.update_attributes(:name => 'Joaquim')
393
+ expect(User.using(:brazil).find_by_name('Joaquim')).not_to be_nil
397
394
  end
398
395
 
399
- it "using update_attributes inside a block" do
396
+ it 'using update_attributes inside a block' do
400
397
  Octopus.using(:brazil) do
401
- @user = User.create!(:name => "User1")
398
+ @user = User.create!(:name => 'User1')
402
399
  @user2 = User.find(@user.id)
403
- @user2.update_attributes(:name => "Joaquim")
400
+ @user2.update_attributes(:name => 'Joaquim')
404
401
  end
405
402
 
406
- User.find_by_name("Joaquim").should be_nil
407
- User.using(:brazil).find_by_name("Joaquim").should_not be_nil
403
+ expect(User.find_by_name('Joaquim')).to be_nil
404
+ expect(User.using(:brazil).find_by_name('Joaquim')).not_to be_nil
408
405
  end
409
406
 
410
- it "update_attribute" do
411
- @user = User.using(:brazil).create!(:name => "User1")
407
+ it 'update_attribute' do
408
+ @user = User.using(:brazil).create!(:name => 'User1')
412
409
  @user2 = User.using(:brazil).find(@user.id)
413
- @user2.update_attribute(:name, "Joaquim")
414
- User.using(:brazil).find_by_name("Joaquim").should_not be_nil
410
+ @user2.update_attribute(:name, 'Joaquim')
411
+ expect(User.using(:brazil).find_by_name('Joaquim')).not_to be_nil
415
412
  end
416
413
 
417
- it "as_json" do
418
- ActiveRecord::Base.include_root_in_json = false
414
+ it 'as_json' do
415
+ ActiveRecord::Base.include_root_in_json = false
419
416
 
420
417
  Octopus.using(:brazil) do
421
- User.create!(:name => "User1")
418
+ User.create!(:name => 'User1')
422
419
  end
423
420
 
424
- user = User.using(:brazil).where(:name => "User1").first
425
- user.as_json(:except => [:created_at, :updated_at, :id]).should eq({"admin"=>nil, "name"=>"User1", "number"=>nil})
421
+ user = User.using(:brazil).where(:name => 'User1').first
422
+ expect(user.as_json(:except => [:created_at, :updated_at, :id])).to eq('admin' => nil, 'name' => 'User1', 'number' => nil)
426
423
  end
427
424
 
428
- it "transaction" do
429
- u = User.create!(:name => "Thiago")
425
+ it 'transaction' do
426
+ _u = User.create!(:name => 'Thiago')
430
427
 
431
- User.using(:brazil).count.should == 0
432
- User.using(:master).count.should == 1
428
+ expect(User.using(:brazil).count).to eq(0)
429
+ expect(User.using(:master).count).to eq(1)
433
430
 
434
431
  User.using(:brazil).transaction do
435
- User.find_by_name("Thiago").should be_nil
436
- User.create!(:name => "Brazil")
432
+ expect(User.find_by_name('Thiago')).to be_nil
433
+ User.create!(:name => 'Brazil')
437
434
  end
438
435
 
439
- User.using(:brazil).count.should == 1
440
- User.using(:master).count.should == 1
436
+ expect(User.using(:brazil).count).to eq(1)
437
+ expect(User.using(:master).count).to eq(1)
441
438
  end
442
439
 
443
- describe "deleting a record" do
440
+ describe 'deleting a record' do
444
441
  before(:each) do
445
- @user = User.using(:brazil).create!(:name => "User1")
442
+ @user = User.using(:brazil).create!(:name => 'User1')
446
443
  @user2 = User.using(:brazil).find(@user.id)
447
444
  end
448
445
 
449
- it "delete" do
446
+ it 'delete' do
450
447
  @user2.delete
451
- lambda { User.using(:brazil).find(@user2.id) }.should raise_error(ActiveRecord::RecordNotFound)
448
+ expect { User.using(:brazil).find(@user2.id) }.to raise_error(ActiveRecord::RecordNotFound)
452
449
  end
453
450
 
454
451
  it "delete within block shouldn't lose shard" do
455
452
  Octopus.using(:brazil) do
456
453
  @user2.delete
457
- @user3 = User.create(:name => "User3")
454
+ @user3 = User.create(:name => 'User3')
458
455
 
459
- User.connection.current_shard.should == :brazil
460
- User.find(@user3.id).should == @user3
456
+ expect(User.connection.current_shard).to eq(:brazil)
457
+ expect(User.find(@user3.id)).to eq(@user3)
461
458
  end
462
459
  end
463
460
 
464
- it "destroy" do
461
+ it 'destroy' do
465
462
  @user2.destroy
466
- lambda { User.using(:brazil).find(@user2.id) }.should raise_error(ActiveRecord::RecordNotFound)
463
+ expect { User.using(:brazil).find(@user2.id) }.to raise_error(ActiveRecord::RecordNotFound)
467
464
  end
468
465
 
469
466
  it "destroy within block shouldn't lose shard" do
470
467
  Octopus.using(:brazil) do
471
468
  @user2.destroy
472
- @user3 = User.create(:name => "User3")
469
+ @user3 = User.create(:name => 'User3')
473
470
 
474
- User.connection.current_shard.should == :brazil
475
- User.find(@user3.id).should == @user3
471
+ expect(User.connection.current_shard).to eq(:brazil)
472
+ expect(User.find(@user3.id)).to eq(@user3)
476
473
  end
477
474
  end
478
475
  end
479
476
  end
480
477
 
481
- describe "when using set_table_name" do
478
+ describe 'when using set_table_name' do
482
479
  it 'should work correctly' do
483
- Bacon.using(:brazil).create!(:name => "YUMMMYYYY")
480
+ Bacon.using(:brazil).create!(:name => 'YUMMMYYYY')
484
481
  end
485
482
 
486
483
  it 'should work correctly with a block' do
487
- Cheese.using(:brazil).create!(:name => "YUMMMYYYY")
484
+ Cheese.using(:brazil).create!(:name => 'YUMMMYYYY')
488
485
  end
489
486
  end
490
487
 
491
- describe "when using table_name=" do
488
+ describe 'when using table_name=' do
492
489
  it 'should work correctly' do
493
- Ham.using(:brazil).create!(:name => "YUMMMYYYY")
490
+ Ham.using(:brazil).create!(:name => 'YUMMMYYYY')
494
491
  end
495
492
  end
496
493
 
497
- describe "when using a environment with a single adapter" do
494
+ describe 'when using a environment with a single adapter' do
498
495
  it 'should not clean the table name' do
499
496
  OctopusHelper.using_environment :production_fully_replicated do
500
- Keyboard.should_not_receive(:reset_table_name)
501
- Keyboard.using(:master).create!(:name => "Master Cat")
497
+ expect(Keyboard).not_to receive(:reset_table_name)
498
+ Keyboard.using(:master).create!(:name => 'Master Cat')
502
499
  end
503
500
  end
504
501
  end
505
502
 
506
- describe "when you have joins/include" do
503
+ describe 'when you have joins/include' do
507
504
  before(:each) do
508
- @client1 = Client.using(:brazil).create(:name => "Thiago")
505
+ @client1 = Client.using(:brazil).create(:name => 'Thiago')
509
506
 
510
507
  Octopus.using(:canada) do
511
- @client2 = Client.create(:name => "Mike")
512
- @client3 = Client.create(:name => "Joao")
513
- @item1 = Item.create(:client => @client2, :name => "Item 1")
514
- @item2 = Item.create(:client => @client2, :name => "Item 2")
515
- @item3 = Item.create(:client => @client3, :name => "Item 3")
516
- @part1 = Part.create(:item => @item1, :name => "Part 1")
517
- @part2 = Part.create(:item => @item1, :name => "Part 2")
518
- @part3 = Part.create(:item => @item2, :name => "Part 3")
508
+ @client2 = Client.create(:name => 'Mike')
509
+ @client3 = Client.create(:name => 'Joao')
510
+ @item1 = Item.create(:client => @client2, :name => 'Item 1')
511
+ @item2 = Item.create(:client => @client2, :name => 'Item 2')
512
+ @item3 = Item.create(:client => @client3, :name => 'Item 3')
513
+ @part1 = Part.create(:item => @item1, :name => 'Part 1')
514
+ @part2 = Part.create(:item => @item1, :name => 'Part 2')
515
+ @part3 = Part.create(:item => @item2, :name => 'Part 3')
519
516
  end
520
517
 
521
- @item4 = Item.using(:brazil).create(:client => @client1, :name => "Item 4")
522
- end
523
-
524
- it "should work with the rails 2.x syntax" do
525
- items = Item.using(:canada).find(:all, :joins => :client, :conditions => { :clients => { :id => @client2.id } })
526
- items.should == [@item1, @item2]
518
+ @item4 = Item.using(:brazil).create(:client => @client1, :name => 'Item 4')
527
519
  end
528
520
 
529
- it "should work using the rails 3.x syntax" do
521
+ it 'should work using the rails 3.x syntax' do
530
522
  items = Item.using(:canada).joins(:client).where("clients.id = #{@client2.id}").all
531
- items.should == [@item1, @item2]
532
- end
533
-
534
- it "should work for include also, rails 2.x syntax" do
535
- items = Item.using(:canada).find(:all, :include => :client, :conditions => { :clients => { :id => @client2.id } })
536
- items.should == [@item1, @item2]
537
- end
538
-
539
- it "should work for include also, rails 3.x syntax" do
540
- items = Item.using(:canada).includes(:client).where("clients.id = #{@client2.id}").all
541
- items.should == [@item1, @item2]
542
- end
543
-
544
- it "should work for multiple includes, with rails 2.x syntax" do
545
- parts = Part.using(:canada).find(:all, :include => {:item => :client}, :conditions => {:clients => { :id => @client2.id}})
546
- parts.should == [@part1, @part2, @part3]
547
- parts.first.item.client.should == @client2
523
+ expect(items).to eq([@item1, @item2])
548
524
  end
549
525
 
550
- it "should work for multiple join, with rails 2.x syntax" do
551
- parts = Part.using(:canada).find(:all, :joins => {:item => :client}, :conditions => {:clients => { :id => @client2.id}})
552
- parts.should == [@part1, @part2, @part3]
553
- parts.first.item.client.should == @client2
526
+ it 'should work for include also, rails 3.x syntax' do
527
+ items = Item.using(:canada).includes(:client).where(:clients => { :id => @client2.id }).all
528
+ expect(items).to eq([@item1, @item2])
554
529
  end
555
530
  end
556
531
 
557
- describe "ActiveRecord::Base Validations" do
558
- it "should work correctly when using validations" do
559
- @key = Keyboard.create!(:name => "Key")
560
- lambda { Keyboard.using(:brazil).create!(:name => "Key") }.should_not raise_error()
561
- lambda { Keyboard.create!(:name => "Key") }.should raise_error()
532
+ describe 'ActiveRecord::Base Validations' do
533
+ it 'should work correctly when using validations' do
534
+ @key = Keyboard.create!(:name => 'Key')
535
+ expect { Keyboard.using(:brazil).create!(:name => 'Key') }.not_to raise_error
536
+ expect { Keyboard.create!(:name => 'Key') }.to raise_error
562
537
  end
563
538
 
564
- it "should work correctly when using validations with using syntax" do
565
- @key = Keyboard.using(:brazil).create!(:name => "Key")
566
- lambda { Keyboard.create!(:name => "Key") }.should_not raise_error()
567
- lambda { Keyboard.using(:brazil).create!(:name => "Key") }.should raise_error()
539
+ it 'should work correctly when using validations with using syntax' do
540
+ @key = Keyboard.using(:brazil).create!(:name => 'Key')
541
+ expect { Keyboard.create!(:name => 'Key') }.not_to raise_error
542
+ expect { Keyboard.using(:brazil).create!(:name => 'Key') }.to raise_error
568
543
  end
569
544
  end
570
545
 
571
- describe "#replicated_model method" do
572
- it "should be replicated" do
546
+ describe '#replicated_model method' do
547
+ it 'should be replicated' do
573
548
  OctopusHelper.using_environment :production_replicated do
574
- ActiveRecord::Base.connection_proxy.instance_variable_get(:@replicated).should be_true
549
+ expect(ActiveRecord::Base.connection_proxy.instance_variable_get(:@replicated)).to be true
575
550
  end
576
551
  end
577
552
 
578
- it "should mark the Cat model as replicated" do
553
+ it 'should mark the Cat model as replicated' do
579
554
  OctopusHelper.using_environment :production_replicated do
580
- User.replicated.should be_false
581
- Cat.replicated.should be_true
555
+ expect(User.replicated).to be_falsey
556
+ expect(Cat.replicated).to be true
582
557
  end
583
558
  end
584
559
  end