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
@@ -12,8 +12,8 @@ require 'cucumber/rails'
12
12
  # Capybara.default_selector = :xpath
13
13
 
14
14
  # By default, any exception happening in your Rails application will bubble up
15
- # to Cucumber so that your scenario will fail. This is a different from how
16
- # your application behaves in the production environment, where an error page will
15
+ # to Cucumber so that your scenario will fail. This is a different from how
16
+ # your application behaves in the production environment, where an error page will
17
17
  # be rendered instead.
18
18
  #
19
19
  # Sometimes we want to override this default behaviour and allow Rails to rescue
@@ -33,7 +33,7 @@ ActionController::Base.allow_rescue = false
33
33
  begin
34
34
  DatabaseCleaner.strategy = :transaction
35
35
  rescue NameError
36
- raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
36
+ raise 'You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it.'
37
37
  end
38
38
 
39
39
  # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
@@ -55,4 +55,3 @@ end
55
55
  # The :transaction strategy is faster, but might give you threading problems.
56
56
  # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
57
57
  Cucumber::Rails::Database.javascript_strategy = :truncation
58
-
@@ -20,10 +20,10 @@ module NavigationHelpers
20
20
  else
21
21
  begin
22
22
  page_name =~ /the (.*) page/
23
- path_components = $1.split(/\s+/)
24
- self.send(path_components.push('path').join('_').to_sym)
25
- rescue Object => e
26
- raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
23
+ path_components = Regexp.last_match[1].split(/\s+/)
24
+ send(path_components.push('path').join('_').to_sym)
25
+ rescue
26
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" \
27
27
  "Now, go and add a mapping in #{__FILE__}"
28
28
  end
29
29
  end
@@ -1,12 +1,12 @@
1
1
  # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
2
  # from the project root directory.
3
- ENV["RAILS_ENV"] ||= 'test'
4
- require File.expand_path("../../config/environment", __FILE__)
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path('../../config/environment', __FILE__)
5
5
  require 'rspec/rails'
6
6
 
7
7
  # Requires supporting files with custom matchers and macros, etc,
8
8
  # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
10
10
 
11
11
  RSpec.configure do |config|
12
12
  # == Mock Framework
@@ -1,9 +1,9 @@
1
1
  class CreateUsersUsingReplication < ActiveRecord::Migration
2
2
  def self.up
3
- Cat.create!(:name => "Replication")
3
+ Cat.create!(:name => 'Replication')
4
4
  end
5
5
 
6
6
  def self.down
7
- Cat.delete_all()
7
+ Cat.delete_all
8
8
  end
9
- end
9
+ end
@@ -2,10 +2,10 @@ class AddFieldInAllSlaves < ActiveRecord::Migration
2
2
  using(:slave1, :slave2, :slave3, :slave4)
3
3
 
4
4
  def self.up
5
- Cat.create!(:name => "Slaves")
5
+ Cat.create!(:name => 'Slaves')
6
6
  end
7
7
 
8
8
  def self.down
9
- Cat.delete_all()
9
+ Cat.delete_all
10
10
  end
11
- end
11
+ end
@@ -1,23 +1,23 @@
1
1
  class CreateUsersUsingBlock < ActiveRecord::Migration
2
2
  def self.up
3
3
  Octopus.using(:brazil) do
4
- User.create!(:name => "UsingBlock1")
5
- User.create!(:name => "UsingBlock2")
4
+ User.create!(:name => 'UsingBlock1')
5
+ User.create!(:name => 'UsingBlock2')
6
6
  end
7
7
 
8
8
  Octopus.using(:canada) do
9
- User.create!(:name => "UsingCanada")
10
- User.create!(:name => "UsingCanada2")
9
+ User.create!(:name => 'UsingCanada')
10
+ User.create!(:name => 'UsingCanada2')
11
11
  end
12
12
  end
13
13
 
14
14
  def self.down
15
15
  Octopus.using(:brazil) do
16
- User.delete_all()
16
+ User.delete_all
17
17
  end
18
18
 
19
19
  Octopus.using(:canada) do
20
- User.delete_all()
20
+ User.delete_all
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -3,13 +3,13 @@ class CreateUsersUsingBlockAndUsing < ActiveRecord::Migration
3
3
 
4
4
  def self.up
5
5
  Octopus.using(:canada) do
6
- User.create!(:name => "Canada")
6
+ User.create!(:name => 'Canada')
7
7
  end
8
8
 
9
- User.create!(:name => "Brazil")
9
+ User.create!(:name => 'Brazil')
10
10
  end
11
11
 
12
12
  def self.down
13
- User.delete_all()
13
+ User.delete_all
14
14
  end
15
- end
15
+ end
@@ -2,10 +2,10 @@ class CreateUsersOnShardsOfAGroupWithVersions < ActiveRecord::Migration
2
2
  using_group(:country_shards)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Group")
5
+ User.create!(:name => 'Group')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
11
  end
@@ -1,9 +1,9 @@
1
1
  class CreateUserOnShardsOfDefaultGroupWithVersions < ActiveRecord::Migration
2
2
  def self.up
3
- User.create!(:name => "Default Group")
3
+ User.create!(:name => 'Default Group')
4
4
  end
5
5
 
6
6
  def self.down
7
- User.delete_all()
7
+ User.delete_all
8
8
  end
9
9
  end
@@ -1,9 +1,9 @@
1
1
  class CreateUsersOnMaster < ActiveRecord::Migration
2
2
  def self.up
3
- User.create!(:name => "Master")
3
+ User.create!(:name => 'Master')
4
4
  end
5
5
 
6
6
  def self.down
7
- User.delete_all()
7
+ User.delete_all
8
8
  end
9
- end
9
+ end
@@ -2,10 +2,10 @@ class CreateUsersOnCanada < ActiveRecord::Migration
2
2
  using(:canada)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Sharding")
5
+ User.create!(:name => 'Sharding')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -2,10 +2,10 @@ class CreateUsersOnBothShards < ActiveRecord::Migration
2
2
  using(:brazil, :canada)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Both")
5
+ User.create!(:name => 'Both')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -2,10 +2,10 @@ class CreateUsersOnShardsOfAGroup < ActiveRecord::Migration
2
2
  using_group(:country_shards)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Group")
5
+ User.create!(:name => 'Group')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -2,10 +2,10 @@ class CreateUsersOnMultiplesGroups < ActiveRecord::Migration
2
2
  using_group('country_shards', 'history_shards')
3
3
 
4
4
  def self.up
5
- User.create!(:name => "MultipleGroup")
5
+ User.create!(:name => 'MultipleGroup')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
11
  end
@@ -2,10 +2,10 @@ class RaiseExceptionWithInvalidShardName < ActiveRecord::Migration
2
2
  using(:amazing_shard)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
5
+ User.create!(:name => 'Error')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -2,10 +2,10 @@ class RaiseExceptionWithInvalidMultipleShardNames < ActiveRecord::Migration
2
2
  using(:brazil, :invalid_shard)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
5
+ User.create!(:name => 'Error')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -2,10 +2,10 @@ class RaiseExceptionWithInvalidGroupName < ActiveRecord::Migration
2
2
  using_group(:invalid_group)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
5
+ User.create!(:name => 'Error')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -1,11 +1,11 @@
1
1
  class RaiseExceptionWithMultipleInvalidGroupNames < ActiveRecord::Migration
2
- using_group(:country_shards,:invalid_group)
2
+ using_group(:country_shards, :invalid_group)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
5
+ User.create!(:name => 'Error')
6
6
  end
7
7
 
8
8
  def self.down
9
- User.delete_all()
9
+ User.delete_all
10
10
  end
11
- end
11
+ end
@@ -1,430 +1,427 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canada] do
4
- describe "when you have a 1 x 1 relationship" do
4
+ describe 'when you have a 1 x 1 relationship' do
5
5
  before(:each) do
6
- @computer_brazil = Computer.using(:brazil).create!(:name => "Computer Brazil")
7
- @computer_master = Computer.create!(:name => "Computer Brazil")
8
- @keyboard_brazil = Keyboard.using(:brazil).create!(:name => "Keyboard Brazil", :computer => @computer_brazil)
9
- @keyboard_master = Keyboard.create!(:name => "Keyboard Master", :computer => @computer_master)
6
+ @computer_brazil = Computer.using(:brazil).create!(:name => 'Computer Brazil')
7
+ @computer_master = Computer.create!(:name => 'Computer Brazil')
8
+ @keyboard_brazil = Keyboard.using(:brazil).create!(:name => 'Keyboard Brazil', :computer => @computer_brazil)
9
+ @keyboard_master = Keyboard.create!(:name => 'Keyboard Master', :computer => @computer_master)
10
10
  end
11
11
 
12
- it "should find the models" do
13
- @keyboard_master.computer.should == @computer_master
14
- @keyboard_brazil.computer.should == @computer_brazil
12
+ it 'should find the models' do
13
+ expect(@keyboard_master.computer).to eq(@computer_master)
14
+ expect(@keyboard_brazil.computer).to eq(@computer_brazil)
15
15
  end
16
16
 
17
- it "should read correctly the relationed model" do
18
- new_computer_brazil = Computer.using(:brazil).create!(:name => "New Computer Brazil")
19
- new_computer_master = Computer.create!(:name => "New Computer Brazil")
17
+ it 'should read correctly the relationed model' do
18
+ new_computer_brazil = Computer.using(:brazil).create!(:name => 'New Computer Brazil')
19
+ _new_computer_hello = Computer.create!(:name => 'New Computer Brazil')
20
20
  @keyboard_brazil.computer = new_computer_brazil
21
- @keyboard_brazil.save()
21
+ @keyboard_brazil.save
22
22
  @keyboard_brazil.reload
23
- @keyboard_brazil.computer_id.should == new_computer_brazil.id
24
- @keyboard_brazil.computer.should == new_computer_brazil
25
- new_computer_brazil.save()
23
+ expect(@keyboard_brazil.computer_id).to eq(new_computer_brazil.id)
24
+ expect(@keyboard_brazil.computer).to eq(new_computer_brazil)
25
+ new_computer_brazil.save
26
26
  new_computer_brazil.reload
27
- new_computer_brazil.keyboard.should == @keyboard_brazil
27
+ expect(new_computer_brazil.keyboard).to eq(@keyboard_brazil)
28
28
  end
29
29
 
30
- it "should work when using #build_computer or #build_keyboard" do
31
- c = Computer.using(:brazil).create!(:name => "Computer Brazil")
32
- k = c.build_keyboard(:name => "Building keyboard")
33
- c.save()
34
- k.save()
35
- c.keyboard.should == k
36
- k.computer_id.should == c.id
37
- k.computer.should == c
30
+ it 'should work when using #build_computer or #build_keyboard' do
31
+ c = Computer.using(:brazil).create!(:name => 'Computer Brazil')
32
+ k = c.build_keyboard(:name => 'Building keyboard')
33
+ c.save
34
+ k.save
35
+ expect(c.keyboard).to eq(k)
36
+ expect(k.computer_id).to eq(c.id)
37
+ expect(k.computer).to eq(c)
38
38
  end
39
39
 
40
- it "should work when using #create_computer or #create_keyboard" do
41
- c = Computer.using(:brazil).create!(:name => "Computer Brazil")
42
- k = c.create_keyboard(:name => "Building keyboard")
43
- c.save()
44
- k.save()
45
- c.keyboard.should == k
46
- k.computer_id.should == c.id
47
- k.computer.should == c
40
+ it 'should work when using #create_computer or #create_keyboard' do
41
+ c = Computer.using(:brazil).create!(:name => 'Computer Brazil')
42
+ k = c.create_keyboard(:name => 'Building keyboard')
43
+ c.save
44
+ k.save
45
+ expect(c.keyboard).to eq(k)
46
+ expect(k.computer_id).to eq(c.id)
47
+ expect(k.computer).to eq(c)
48
48
  end
49
49
 
50
- it "should include models" do
51
- c = Computer.using(:brazil).create!(:name => "Computer Brazil")
52
- k = c.create_keyboard(:name => "Building keyboard")
53
- c.save()
54
- k.save()
50
+ it 'should include models' do
51
+ c = Computer.using(:brazil).create!(:name => 'Computer Brazil')
52
+ k = c.create_keyboard(:name => 'Building keyboard')
53
+ c.save
54
+ k.save
55
55
 
56
- Computer.using(:brazil).includes(:keyboard).find(c.id).should == c
56
+ expect(Computer.using(:brazil).includes(:keyboard).find(c.id)).to eq(c)
57
57
  end
58
58
  end
59
59
 
60
- describe "when you have a N x N relationship" do
60
+ describe 'when you have a N x N relationship' do
61
61
  before(:each) do
62
- @brazil_role = Role.using(:brazil).create!(:name => "Brazil Role")
63
- @master_role = Role.create!(:name => "Master Role")
64
- @permission_brazil = Permission.using(:brazil).create!(:name => "Brazil Permission")
65
- @permission_master = Permission.using(:master).create!(:name => "Master Permission")
62
+ @brazil_role = Role.using(:brazil).create!(:name => 'Brazil Role')
63
+ @master_role = Role.create!(:name => 'Master Role')
64
+ @permission_brazil = Permission.using(:brazil).create!(:name => 'Brazil Permission')
65
+ @permission_master = Permission.using(:master).create!(:name => 'Master Permission')
66
66
  @brazil_role.permissions << @permission_brazil
67
- @brazil_role.save()
68
- Client.using(:master).create!(:name => "teste")
67
+ @brazil_role.save
68
+ Client.using(:master).create!(:name => 'teste')
69
69
  end
70
70
 
71
- it "should find all models in the specified shard" do
72
- @brazil_role.permission_ids().should == [@permission_brazil.id]
73
- @brazil_role.permissions().should == [@permission_brazil]
71
+ it 'should find all models in the specified shard' do
72
+ expect(@brazil_role.permission_ids).to eq([@permission_brazil.id])
73
+ expect(@brazil_role.permissions).to eq([@permission_brazil])
74
74
 
75
- @brazil_role.permissions.first.should eq(@permission_brazil)
76
- @brazil_role.permissions.last.should eq(@permission_brazil)
75
+ expect(@brazil_role.permissions.first).to eq(@permission_brazil)
76
+ expect(@brazil_role.permissions.last).to eq(@permission_brazil)
77
77
  end
78
78
 
79
- it "should finds the client that the item belongs" do
80
- @permission_brazil.role_ids.should == [@brazil_role.id]
81
- @permission_brazil.roles.should == [@brazil_role]
79
+ it 'should finds the client that the item belongs' do
80
+ expect(@permission_brazil.role_ids).to eq([@brazil_role.id])
81
+ expect(@permission_brazil.roles).to eq([@brazil_role])
82
82
 
83
- @permission_brazil.roles.first.should eq(@brazil_role)
84
- @permission_brazil.roles.last.should eq(@brazil_role)
83
+ expect(@permission_brazil.roles.first).to eq(@brazil_role)
84
+ expect(@permission_brazil.roles.last).to eq(@brazil_role)
85
85
  end
86
86
 
87
- it "should update the attribute for the item" do
88
- new_brazil_role = Role.using(:brazil).create!(:name => "new Role")
87
+ it 'should update the attribute for the item' do
88
+ new_brazil_role = Role.using(:brazil).create!(:name => 'new Role')
89
89
  @permission_brazil.roles = [new_brazil_role]
90
- @permission_brazil.roles.should == [new_brazil_role]
91
- @permission_brazil.save()
90
+ expect(@permission_brazil.roles).to eq([new_brazil_role])
91
+ @permission_brazil.save
92
92
  @permission_brazil.reload
93
- @permission_brazil.role_ids.should == [new_brazil_role.id]
94
- @permission_brazil.roles().should == [new_brazil_role]
93
+ expect(@permission_brazil.role_ids).to eq([new_brazil_role.id])
94
+ expect(@permission_brazil.roles).to eq([new_brazil_role])
95
95
  end
96
96
 
97
- it "should works for build method" do
98
- new_brazil_role = Role.using(:brazil).create!(:name => "Brazil Role")
99
- c = new_brazil_role.permissions.create(:name => "new Permission")
100
- c.save()
101
- new_brazil_role.save()
102
- c.roles().should == [new_brazil_role]
103
- new_brazil_role.permissions.should == [c]
97
+ it 'should works for build method' do
98
+ new_brazil_role = Role.using(:brazil).create!(:name => 'Brazil Role')
99
+ c = new_brazil_role.permissions.create(:name => 'new Permission')
100
+ c.save
101
+ new_brazil_role.save
102
+ expect(c.roles).to eq([new_brazil_role])
103
+ expect(new_brazil_role.permissions).to eq([c])
104
104
  end
105
105
 
106
- describe "it should works when using" do
106
+ describe 'it should works when using' do
107
107
  before(:each) do
108
- @permission_brazil_2 = Permission.using(:brazil).create!(:name => "Brazil Item 2")
109
- @role = Role.using(:brazil).create!(:name => "testes")
108
+ @permission_brazil_2 = Permission.using(:brazil).create!(:name => 'Brazil Item 2')
109
+ @role = Role.using(:brazil).create!(:name => 'testes')
110
110
  end
111
111
 
112
- it "update_attributes" do
112
+ it 'update_attributes' do
113
113
  @permission_brazil_2.update_attributes(:role_ids => [@role.id])
114
- @permission_brazil_2.roles.to_set.should == [@role].to_set
114
+ expect(@permission_brazil_2.roles.to_set).to eq([@role].to_set)
115
115
  end
116
116
 
117
- it "update_attribute" do
117
+ it 'update_attribute' do
118
118
  @permission_brazil_2.update_attribute(:role_ids, [@role.id])
119
- @permission_brazil_2.roles.to_set.should == [@role].to_set
119
+ expect(@permission_brazil_2.roles.to_set).to eq([@role].to_set)
120
120
  end
121
121
 
122
- it "<<" do
122
+ it '<<' do
123
123
  @permission_brazil_2.roles << @role
124
- @role.save()
125
- @permission_brazil_2.save()
124
+ @role.save
125
+ @permission_brazil_2.save
126
126
  @permission_brazil_2.reload
127
- @permission_brazil_2.roles.to_set.should == [@role].to_set
127
+ expect(@permission_brazil_2.roles.to_set).to eq([@role].to_set)
128
128
  end
129
129
 
130
- it "build" do
131
- role = @permission_brazil_2.roles.build(:name => "Builded Role")
132
- @permission_brazil_2.save()
133
- @permission_brazil_2.roles.to_set.should == [role].to_set
130
+ it 'build' do
131
+ role = @permission_brazil_2.roles.build(:name => 'Builded Role')
132
+ @permission_brazil_2.save
133
+ expect(@permission_brazil_2.roles.to_set).to eq([role].to_set)
134
134
  end
135
135
 
136
- it "create" do
137
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
138
- @permission_brazil_2.roles.to_set.should == [role].to_set
136
+ it 'create' do
137
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
138
+ expect(@permission_brazil_2.roles.to_set).to eq([role].to_set)
139
139
  end
140
140
 
141
- it "create" do
142
- role = @permission_brazil_2.roles.create!(:name => "Builded Role")
143
- @permission_brazil_2.roles.to_set.should == [role].to_set
141
+ it 'create' do
142
+ role = @permission_brazil_2.roles.create!(:name => 'Builded Role')
143
+ expect(@permission_brazil_2.roles.to_set).to eq([role].to_set)
144
144
  end
145
145
 
146
- it "count" do
147
- @permission_brazil_2.roles.count.should == 0
148
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
149
- @permission_brazil_2.roles.count.should == 1
150
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
151
- @permission_brazil_2.roles.count.should == 2
146
+ it 'count' do
147
+ expect(@permission_brazil_2.roles.count).to eq(0)
148
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
149
+ expect(@permission_brazil_2.roles.count).to eq(1)
150
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
151
+ expect(@permission_brazil_2.roles.count).to eq(2)
152
152
  end
153
153
 
154
- it "size" do
155
- @permission_brazil_2.roles.size.should == 0
156
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
157
- @permission_brazil_2.roles.size.should == 1
158
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
159
- @permission_brazil_2.roles.size.should == 2
154
+ it 'size' do
155
+ expect(@permission_brazil_2.roles.size).to eq(0)
156
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
157
+ expect(@permission_brazil_2.roles.size).to eq(1)
158
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
159
+ expect(@permission_brazil_2.roles.size).to eq(2)
160
160
  end
161
161
 
162
- it "length" do
163
- @permission_brazil_2.roles.length.should == 0
164
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
165
- @permission_brazil_2.roles.length.should == 1
166
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
167
- @permission_brazil_2.roles.length.should == 2
162
+ it 'length' do
163
+ expect(@permission_brazil_2.roles.length).to eq(0)
164
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
165
+ expect(@permission_brazil_2.roles.length).to eq(1)
166
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
167
+ expect(@permission_brazil_2.roles.length).to eq(2)
168
168
  end
169
169
 
170
-
171
- it "empty?" do
172
- @permission_brazil_2.roles.empty?.should be_true
173
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
174
- @permission_brazil_2.roles.empty?.should be_false
170
+ it 'empty?' do
171
+ expect(@permission_brazil_2.roles.empty?).to be true
172
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
173
+ expect(@permission_brazil_2.roles.empty?).to be false
175
174
  end
176
175
 
177
- it "delete_all" do
178
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
179
- @permission_brazil_2.roles.empty?.should be_false
176
+ it 'delete_all' do
177
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
178
+ expect(@permission_brazil_2.roles.empty?).to be false
180
179
  @permission_brazil_2.roles.delete_all
181
- @permission_brazil_2.roles.empty?.should be_true
180
+ expect(@permission_brazil_2.roles.empty?).to be true
182
181
  end
183
182
 
184
- it "destroy_all" do
185
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
186
- @permission_brazil_2.roles.empty?.should be_false
183
+ it 'destroy_all' do
184
+ _role = @permission_brazil_2.roles.create(:name => 'Builded Role')
185
+ expect(@permission_brazil_2.roles.empty?).to be false
187
186
  @permission_brazil_2.roles.destroy_all
188
- @permission_brazil_2.roles.empty?.should be_true
187
+ expect(@permission_brazil_2.roles.empty?).to be true
189
188
  end
190
189
 
191
- it "find" do
192
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
193
- @permission_brazil_2.roles.first.should == role
190
+ it 'find' do
191
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
192
+ expect(@permission_brazil_2.roles.first).to eq(role)
194
193
  @permission_brazil_2.roles.destroy_all
195
- @permission_brazil_2.roles.first.should be_nil
194
+ expect(@permission_brazil_2.roles.first).to be_nil
196
195
  end
197
196
 
198
- it "exists?" do
199
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
200
- @permission_brazil_2.roles.exists?(role).should be_true
197
+ it 'exists?' do
198
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
199
+ expect(@permission_brazil_2.roles.exists?(role)).to be true
201
200
  @permission_brazil_2.roles.destroy_all
202
- @permission_brazil_2.roles.exists?(role).should be_false
201
+ expect(@permission_brazil_2.roles.exists?(role)).to be false
203
202
  end
204
203
 
205
- it "clear" do
206
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
207
- @permission_brazil_2.roles.empty?.should be_false
204
+ it 'clear' do
205
+ _rol = @permission_brazil_2.roles.create(:name => 'Builded Role')
206
+ expect(@permission_brazil_2.roles.empty?).to be false
208
207
  @permission_brazil_2.roles.clear
209
- @permission_brazil_2.roles.empty?.should be_true
208
+ expect(@permission_brazil_2.roles.empty?).to be true
210
209
  end
211
210
 
212
- it "delete" do
213
- role = @permission_brazil_2.roles.create(:name => "Builded Role")
214
- @permission_brazil_2.roles.empty?.should be_false
211
+ it 'delete' do
212
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
213
+ expect(@permission_brazil_2.roles.empty?).to be false
215
214
  @permission_brazil_2.roles.delete(role)
216
215
  @permission_brazil_2.reload
217
216
  @role.reload
218
- @role.permissions.should == []
219
- @permission_brazil_2.roles.should == []
217
+ expect(@role.permissions).to eq([])
218
+ expect(@permission_brazil_2.roles).to eq([])
220
219
  end
221
220
  end
222
221
  end
223
222
 
224
- describe "when you have has_many :through" do
223
+ describe 'when you have has_many :through' do
225
224
  before(:each) do
226
- @programmer = Programmer.using(:brazil).create!(:name => "Thiago")
227
- @project = Project.using(:brazil).create!(:name => "RubySoc")
228
- @project2 = Project.using(:brazil).create!(:name => "Cobol Application")
225
+ @programmer = Programmer.using(:brazil).create!(:name => 'Thiago')
226
+ @project = Project.using(:brazil).create!(:name => 'RubySoc')
227
+ @project2 = Project.using(:brazil).create!(:name => 'Cobol Application')
229
228
  @programmer.projects << @project
230
- @programmer.save()
231
- Project.using(:master).create!(:name => "Project Master")
229
+ @programmer.save
230
+ Project.using(:master).create!(:name => 'Project Master')
232
231
  end
233
232
 
234
- it "should find all models in the specified shard" do
235
- @programmer.project_ids().should eq([@project.id])
236
- @programmer.projects().should eq([@project])
233
+ it 'should find all models in the specified shard' do
234
+ expect(@programmer.project_ids).to eq([@project.id])
235
+ expect(@programmer.projects).to eq([@project])
237
236
 
238
- @programmer.projects.first.should eq(@project)
239
- @programmer.projects.last.should eq(@project)
237
+ expect(@programmer.projects.first).to eq(@project)
238
+ expect(@programmer.projects.last).to eq(@project)
240
239
  end
241
240
 
242
-
243
- it "should update the attribute for the item" do
244
- new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Joao")
241
+ it 'should update the attribute for the item' do
242
+ new_brazil_programmer = Programmer.using(:brazil).create!(:name => 'Joao')
245
243
  @project.programmers = [new_brazil_programmer]
246
- @project.programmers.should == [new_brazil_programmer]
247
- @project.save()
244
+ expect(@project.programmers).to eq([new_brazil_programmer])
245
+ @project.save
248
246
  @project.reload
249
- @project.programmer_ids.should == [new_brazil_programmer.id]
250
- @project.programmers().should == [new_brazil_programmer]
247
+ expect(@project.programmer_ids).to eq([new_brazil_programmer.id])
248
+ expect(@project.programmers).to eq([new_brazil_programmer])
251
249
  end
252
250
 
253
- it "should works for create method" do
254
- new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Joao")
255
- c = new_brazil_programmer.projects.create(:name => "new Project")
256
- c.save()
257
- new_brazil_programmer.save()
258
- c.programmers().should == [new_brazil_programmer]
259
- new_brazil_programmer.projects.should == [c]
251
+ it 'should works for create method' do
252
+ new_brazil_programmer = Programmer.using(:brazil).create!(:name => 'Joao')
253
+ c = new_brazil_programmer.projects.create(:name => 'new Project')
254
+ c.save
255
+ new_brazil_programmer.save
256
+ expect(c.programmers).to eq([new_brazil_programmer])
257
+ expect(new_brazil_programmer.projects).to eq([c])
260
258
  end
261
259
 
262
- describe "it should works when using" do
260
+ describe 'it should works when using' do
263
261
  before(:each) do
264
- @new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Jose")
265
- @project = Project.using(:brazil).create!(:name => "VB Application :-(")
262
+ @new_brazil_programmer = Programmer.using(:brazil).create!(:name => 'Jose')
263
+ @project = Project.using(:brazil).create!(:name => 'VB Application :-(')
266
264
  end
267
265
 
268
- it "update_attributes" do
266
+ it 'update_attributes' do
269
267
  @new_brazil_programmer.update_attributes(:project_ids => [@project.id])
270
- @new_brazil_programmer.projects.to_set.should == [@project].to_set
268
+ expect(@new_brazil_programmer.projects.to_set).to eq([@project].to_set)
271
269
  end
272
270
 
273
- it "update_attribute" do
271
+ it 'update_attribute' do
274
272
  @new_brazil_programmer.update_attribute(:project_ids, [@project.id])
275
- @new_brazil_programmer.projects.to_set.should == [@project].to_set
273
+ expect(@new_brazil_programmer.projects.to_set).to eq([@project].to_set)
276
274
  end
277
275
 
278
- it "<<" do
276
+ it '<<' do
279
277
  @new_brazil_programmer.projects << @project
280
- @project.save()
281
- @new_brazil_programmer.save()
278
+ @project.save
279
+ @new_brazil_programmer.save
282
280
  @new_brazil_programmer.reload
283
- @new_brazil_programmer.projects.to_set.should == [@project].to_set
281
+ expect(@new_brazil_programmer.projects.to_set).to eq([@project].to_set)
284
282
  end
285
283
 
286
- it "build" do
287
- role = @new_brazil_programmer.projects.build(:name => "New VB App :-/")
288
- @new_brazil_programmer.save()
289
- @new_brazil_programmer.projects.to_set.should == [role].to_set
284
+ it 'build' do
285
+ role = @new_brazil_programmer.projects.build(:name => 'New VB App :-/')
286
+ @new_brazil_programmer.save
287
+ expect(@new_brazil_programmer.projects.to_set).to eq([role].to_set)
290
288
  end
291
289
 
292
- it "create" do
293
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
294
- @new_brazil_programmer.projects.to_set.should == [role].to_set
290
+ it 'create' do
291
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
292
+ expect(@new_brazil_programmer.projects.to_set).to eq([role].to_set)
295
293
  end
296
294
 
297
- it "create" do
298
- role = @new_brazil_programmer.projects.create!(:name => "New VB App :-/")
299
- @new_brazil_programmer.projects.to_set.should == [role].to_set
295
+ it 'create' do
296
+ role = @new_brazil_programmer.projects.create!(:name => 'New VB App :-/')
297
+ expect(@new_brazil_programmer.projects.to_set).to eq([role].to_set)
300
298
  end
301
299
 
302
- it "count" do
303
- @new_brazil_programmer.projects.count.should == 0
304
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
305
- @new_brazil_programmer.projects.count.should == 1
306
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
307
- @new_brazil_programmer.projects.count.should == 2
300
+ it 'count' do
301
+ expect(@new_brazil_programmer.projects.count).to eq(0)
302
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
303
+ expect(@new_brazil_programmer.projects.count).to eq(1)
304
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
305
+ expect(@new_brazil_programmer.projects.count).to eq(2)
308
306
  end
309
307
 
310
- it "size" do
311
- @new_brazil_programmer.projects.size.should == 0
312
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
313
- @new_brazil_programmer.projects.size.should == 1
314
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
315
- @new_brazil_programmer.projects.size.should == 2
308
+ it 'size' do
309
+ expect(@new_brazil_programmer.projects.size).to eq(0)
310
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
311
+ expect(@new_brazil_programmer.projects.size).to eq(1)
312
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
313
+ expect(@new_brazil_programmer.projects.size).to eq(2)
316
314
  end
317
315
 
318
- it "length" do
319
- @new_brazil_programmer.projects.length.should == 0
320
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
321
- @new_brazil_programmer.projects.length.should == 1
322
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
323
- @new_brazil_programmer.projects.length.should == 2
316
+ it 'length' do
317
+ expect(@new_brazil_programmer.projects.length).to eq(0)
318
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
319
+ expect(@new_brazil_programmer.projects.length).to eq(1)
320
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
321
+ expect(@new_brazil_programmer.projects.length).to eq(2)
324
322
  end
325
323
 
326
-
327
- it "empty?" do
328
- @new_brazil_programmer.projects.empty?.should be_true
329
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
330
- @new_brazil_programmer.projects.empty?.should be_false
324
+ it 'empty?' do
325
+ expect(@new_brazil_programmer.projects.empty?).to be true
326
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
327
+ expect(@new_brazil_programmer.projects.empty?).to be false
331
328
  end
332
329
 
333
- it "delete_all" do
334
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
335
- @new_brazil_programmer.projects.empty?.should be_false
330
+ it 'delete_all' do
331
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
332
+ expect(@new_brazil_programmer.projects.empty?).to be false
336
333
  @new_brazil_programmer.projects.delete_all
337
- @new_brazil_programmer.projects.empty?.should be_true
334
+ expect(@new_brazil_programmer.projects.empty?).to be true
338
335
  end
339
336
 
340
- it "destroy_all" do
341
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
342
- @new_brazil_programmer.projects.empty?.should be_false
337
+ it 'destroy_all' do
338
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
339
+ expect(@new_brazil_programmer.projects.empty?).to be false
343
340
  @new_brazil_programmer.projects.destroy_all
344
- @new_brazil_programmer.projects.empty?.should be_true
341
+ expect(@new_brazil_programmer.projects.empty?).to be true
345
342
  end
346
343
 
347
- it "find" do
348
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
349
- @new_brazil_programmer.projects.first.should == role
344
+ it 'find' do
345
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
346
+ expect(@new_brazil_programmer.projects.first).to eq(role)
350
347
  @new_brazil_programmer.projects.destroy_all
351
- @new_brazil_programmer.projects.first.should be_nil
348
+ expect(@new_brazil_programmer.projects.first).to be_nil
352
349
  end
353
350
 
354
- it "exists?" do
355
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
356
- @new_brazil_programmer.projects.exists?(role).should be_true
351
+ it 'exists?' do
352
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
353
+ expect(@new_brazil_programmer.projects.exists?(role)).to be true
357
354
  @new_brazil_programmer.projects.destroy_all
358
- @new_brazil_programmer.projects.exists?(role).should be_false
355
+ expect(@new_brazil_programmer.projects.exists?(role)).to be false
359
356
  end
360
357
 
361
- it "clear" do
362
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
363
- @new_brazil_programmer.projects.empty?.should be_false
358
+ it 'clear' do
359
+ _role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
360
+ expect(@new_brazil_programmer.projects.empty?).to be false
364
361
  @new_brazil_programmer.projects.clear
365
- @new_brazil_programmer.projects.empty?.should be_true
362
+ expect(@new_brazil_programmer.projects.empty?).to be true
366
363
  end
367
364
 
368
- it "delete" do
369
- role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
370
- @new_brazil_programmer.projects.empty?.should be_false
365
+ it 'delete' do
366
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
367
+ expect(@new_brazil_programmer.projects.empty?).to be false
371
368
  @new_brazil_programmer.projects.delete(role)
372
369
  @new_brazil_programmer.reload
373
370
  @project.reload
374
- @project.programmers.should == []
375
- @new_brazil_programmer.projects.should == []
371
+ expect(@project.programmers).to eq([])
372
+ expect(@new_brazil_programmer.projects).to eq([])
376
373
  end
377
374
  end
378
375
  end
379
376
 
380
- describe "when you have a 1 x N relationship" do
377
+ describe 'when you have a 1 x N relationship' do
381
378
  before(:each) do
382
- @brazil_client = Client.using(:brazil).create!(:name => "Brazil Client")
383
- @master_client = Client.create!(:name => "Master Client")
384
- @item_brazil = Item.using(:brazil).create!(:name => "Brazil Item", :client => @brazil_client)
385
- @item_master = Item.create!(:name => "Master Item", :client => @master_client)
386
- @brazil_client = Client.using(:brazil).find_by_name("Brazil Client")
387
- Client.using(:master).create!(:name => "teste")
379
+ @brazil_client = Client.using(:brazil).create!(:name => 'Brazil Client')
380
+ @master_client = Client.create!(:name => 'Master Client')
381
+ @item_brazil = Item.using(:brazil).create!(:name => 'Brazil Item', :client => @brazil_client)
382
+ @item_master = Item.create!(:name => 'Master Item', :client => @master_client)
383
+ @brazil_client = Client.using(:brazil).find_by_name('Brazil Client')
384
+ Client.using(:master).create!(:name => 'teste')
388
385
  end
389
386
 
390
- it "should find all models in the specified shard" do
391
- @brazil_client.item_ids.should eq([@item_brazil.id])
392
- @brazil_client.items().should eq([@item_brazil])
387
+ it 'should find all models in the specified shard' do
388
+ expect(@brazil_client.item_ids).to eq([@item_brazil.id])
389
+ expect(@brazil_client.items).to eq([@item_brazil])
393
390
 
394
- @brazil_client.items.last.should eq(@item_brazil)
395
- @brazil_client.items.first.should eq(@item_brazil)
391
+ expect(@brazil_client.items.last).to eq(@item_brazil)
392
+ expect(@brazil_client.items.first).to eq(@item_brazil)
396
393
  end
397
394
 
398
- it "should finds the client that the item belongs" do
399
- @item_brazil.client.should == @brazil_client
395
+ it 'should finds the client that the item belongs' do
396
+ expect(@item_brazil.client).to eq(@brazil_client)
400
397
  end
401
398
 
402
- it "should raise error if you try to add a record from a different shard" do
403
- lambda do
404
- @brazil_client.items << Item.using(:canada).create!(:name => "New User")
405
- end.should raise_error("Association Error: Records are from different shards")
399
+ it 'should raise error if you try to add a record from a different shard' do
400
+ expect do
401
+ @brazil_client.items << Item.using(:canada).create!(:name => 'New User')
402
+ end.to raise_error('Association Error: Records are from different shards')
406
403
  end
407
404
 
408
- it "should update the attribute for the item" do
409
- new_brazil_client = Client.using(:brazil).create!(:name => "new Client")
405
+ it 'should update the attribute for the item' do
406
+ new_brazil_client = Client.using(:brazil).create!(:name => 'new Client')
410
407
  @item_brazil.client = new_brazil_client
411
- @item_brazil.client.should == new_brazil_client
412
- @item_brazil.save()
408
+ expect(@item_brazil.client).to eq(new_brazil_client)
409
+ @item_brazil.save
413
410
  @item_brazil.reload
414
- @item_brazil.client_id.should == new_brazil_client.id
415
- @item_brazil.client().should == new_brazil_client
411
+ expect(@item_brazil.client_id).to eq(new_brazil_client.id)
412
+ expect(@item_brazil.client).to eq(new_brazil_client)
416
413
  end
417
414
 
418
- it "should works for build method" do
419
- item2 = Item.using(:brazil).create!(:name => "Brazil Item")
420
- c = item2.create_client(:name => "new Client")
421
- c.save()
422
- item2.save()
423
- item2.client.should == c
424
- c.items().should == [item2]
415
+ it 'should works for build method' do
416
+ item2 = Item.using(:brazil).create!(:name => 'Brazil Item')
417
+ c = item2.create_client(:name => 'new Client')
418
+ c.save
419
+ item2.save
420
+ expect(item2.client).to eq(c)
421
+ expect(c.items).to eq([item2])
425
422
  end
426
423
 
427
- context "when calling methods on a collection generated by an association" do
424
+ context 'when calling methods on a collection generated by an association' do
428
425
  let(:collection) { @brazil_client.items }
429
426
  before :each do
430
427
  @brazil_client.items.create(:name => 'Brazil Item #2')
@@ -432,281 +429,280 @@ describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canad
432
429
 
433
430
  it "can call collection indexes directly without resetting the collection's current_shard" do
434
431
  last_item = collection[1]
435
- collection.length.should == 2
436
- collection.should eq([ collection[0], last_item ])
432
+ expect(collection.length).to eq(2)
433
+ expect(collection).to eq([collection[0], last_item])
437
434
  end
438
435
 
439
436
  it "can call methods on the collection without resetting the collection's current_shard" do
440
- last_item = collection[collection.size-1]
441
- collection.length.should == 2
442
- collection.should eq([ collection[0], last_item ])
437
+ last_item = collection[collection.size - 1]
438
+ expect(collection.length).to eq(2)
439
+ expect(collection).to eq([collection[0], last_item])
443
440
  end
444
441
  end
445
442
 
446
- describe "it should works when using" do
443
+ describe 'it should works when using' do
447
444
  before(:each) do
448
- @item_brazil_2 = Item.using(:brazil).create!(:name => "Brazil Item 2")
449
- @brazil_client.items.to_set.should == [@item_brazil].to_set
445
+ @item_brazil_2 = Item.using(:brazil).create!(:name => 'Brazil Item 2')
446
+ expect(@brazil_client.items.to_set).to eq([@item_brazil].to_set)
450
447
  end
451
448
 
452
-
453
- it "update_attributes" do
449
+ it 'update_attributes' do
454
450
  @brazil_client.update_attributes(:item_ids => [@item_brazil_2.id, @item_brazil.id])
455
- @brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
451
+ expect(@brazil_client.items.to_set).to eq([@item_brazil, @item_brazil_2].to_set)
456
452
  end
457
453
 
458
- it "update_attribute" do
454
+ it 'update_attribute' do
459
455
  @brazil_client.update_attribute(:item_ids, [@item_brazil_2.id, @item_brazil.id])
460
- @brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
456
+ expect(@brazil_client.items.to_set).to eq([@item_brazil, @item_brazil_2].to_set)
461
457
  end
462
458
 
463
- it "<<" do
459
+ it '<<' do
464
460
  @brazil_client.items << @item_brazil_2
465
- @brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
461
+ expect(@brazil_client.items.to_set).to eq([@item_brazil, @item_brazil_2].to_set)
466
462
  end
467
463
 
468
- it "all" do
469
- item = @brazil_client.items.build(:name => "Builded Item")
470
- item.save()
464
+ it 'all' do
465
+ item = @brazil_client.items.build(:name => 'Builded Item')
466
+ item.save
471
467
  i = @brazil_client.items
472
- i.to_set.should == [@item_brazil, item].to_set
473
- i.reload.all.to_set.should == [@item_brazil, item].to_set
468
+ expect(i.to_set).to eq([@item_brazil, item].to_set)
469
+ expect(i.reload.all.to_set).to eq([@item_brazil, item].to_set)
474
470
  end
475
471
 
476
- it "build" do
477
- item = @brazil_client.items.build(:name => "Builded Item")
478
- item.save()
479
- @brazil_client.items.to_set.should == [@item_brazil, item].to_set
472
+ it 'build' do
473
+ item = @brazil_client.items.build(:name => 'Builded Item')
474
+ item.save
475
+ expect(@brazil_client.items.to_set).to eq([@item_brazil, item].to_set)
480
476
  end
481
477
 
482
- it "create" do
483
- item = @brazil_client.items.create(:name => "Builded Item")
484
- @brazil_client.items.to_set.should == [@item_brazil, item].to_set
478
+ it 'create' do
479
+ item = @brazil_client.items.create(:name => 'Builded Item')
480
+ expect(@brazil_client.items.to_set).to eq([@item_brazil, item].to_set)
485
481
  end
486
482
 
487
- it "count" do
488
- @brazil_client.items.count.should == 1
489
- item = @brazil_client.items.create(:name => "Builded Item")
490
- @brazil_client.items.count.should == 2
483
+ it 'count' do
484
+ expect(@brazil_client.items.count).to eq(1)
485
+ _itm = @brazil_client.items.create(:name => 'Builded Item')
486
+ expect(@brazil_client.items.count).to eq(2)
491
487
  end
492
488
 
493
- it "size" do
494
- @brazil_client.items.size.should == 1
495
- item = @brazil_client.items.create(:name => "Builded Item")
496
- @brazil_client.items.size.should == 2
489
+ it 'size' do
490
+ expect(@brazil_client.items.size).to eq(1)
491
+ _itm = @brazil_client.items.create(:name => 'Builded Item')
492
+ expect(@brazil_client.items.size).to eq(2)
497
493
  end
498
494
 
499
- it "create!" do
500
- item = @brazil_client.items.create!(:name => "Builded Item")
501
- @brazil_client.items.to_set.should == [@item_brazil, item].to_set
495
+ it 'create!' do
496
+ item = @brazil_client.items.create!(:name => 'Builded Item')
497
+ expect(@brazil_client.items.to_set).to eq([@item_brazil, item].to_set)
502
498
  end
503
499
 
504
- it "length" do
505
- @brazil_client.items.length.should == 1
506
- item = @brazil_client.items.create(:name => "Builded Item")
507
- @brazil_client.items.length.should == 2
500
+ it 'length' do
501
+ expect(@brazil_client.items.length).to eq(1)
502
+ _itm = @brazil_client.items.create(:name => 'Builded Item')
503
+ expect(@brazil_client.items.length).to eq(2)
508
504
  end
509
505
 
510
- it "empty?" do
511
- @brazil_client.items.empty?.should be_false
512
- c = Client.create!(:name => "Client1")
513
- c.items.empty?.should be_true
506
+ it 'empty?' do
507
+ expect(@brazil_client.items.empty?).to be false
508
+ c = Client.create!(:name => 'Client1')
509
+ expect(c.items.empty?).to be true
514
510
  end
515
511
 
516
- it "delete" do
517
- @brazil_client.items.empty?.should be_false
512
+ it 'delete' do
513
+ expect(@brazil_client.items.empty?).to be false
518
514
  @brazil_client.items.delete(@item_brazil)
519
515
  @brazil_client.reload
520
516
  @item_brazil.reload
521
- @item_brazil.client.should be_nil
522
- @brazil_client.items.should == []
523
- @brazil_client.items.empty?.should be_true
517
+ expect(@item_brazil.client).to be_nil
518
+ expect(@brazil_client.items).to eq([])
519
+ expect(@brazil_client.items.empty?).to be true
524
520
  end
525
521
 
526
- it "delete_all" do
527
- @brazil_client.items.empty?.should be_false
522
+ it 'delete_all' do
523
+ expect(@brazil_client.items.empty?).to be false
528
524
  @brazil_client.items.delete_all
529
- @brazil_client.items.empty?.should be_true
525
+ expect(@brazil_client.items.empty?).to be true
530
526
  end
531
527
 
532
- it "destroy_all" do
533
- @brazil_client.items.empty?.should be_false
528
+ it 'destroy_all' do
529
+ expect(@brazil_client.items.empty?).to be false
534
530
  @brazil_client.items.destroy_all
535
- @brazil_client.items.empty?.should be_true
531
+ expect(@brazil_client.items.empty?).to be true
536
532
  end
537
533
 
538
- it "find" do
539
- @brazil_client.items.first.should == @item_brazil
534
+ it 'find' do
535
+ expect(@brazil_client.items.first).to eq(@item_brazil)
540
536
  @brazil_client.items.destroy_all
541
- @brazil_client.items.first.should be_nil
537
+ expect(@brazil_client.items.first).to be_nil
542
538
  end
543
539
 
544
- it "exists?" do
545
- @brazil_client.items.exists?(@item_brazil).should be_true
540
+ it 'exists?' do
541
+ expect(@brazil_client.items.exists?(@item_brazil)).to be true
546
542
  @brazil_client.items.destroy_all
547
- @brazil_client.items.exists?(@item_brazil).should be_false
543
+ expect(@brazil_client.items.exists?(@item_brazil)).to be false
548
544
  end
549
545
 
550
- it "uniq" do
551
- @brazil_client.items.uniq.should == [@item_brazil]
546
+ it 'uniq' do
547
+ expect(@brazil_client.items.uniq).to eq([@item_brazil])
552
548
  end
553
549
 
554
- it "clear" do
555
- @brazil_client.items.empty?.should be_false
550
+ it 'clear' do
551
+ expect(@brazil_client.items.empty?).to be false
556
552
  @brazil_client.items.clear
557
- @brazil_client.items.empty?.should be_true
553
+ expect(@brazil_client.items.empty?).to be true
558
554
  end
559
555
  end
560
556
  end
561
557
 
562
- describe "when you have a 1 x N polymorphic relationship" do
558
+ describe 'when you have a 1 x N polymorphic relationship' do
563
559
  before(:each) do
564
- @brazil_client = Client.using(:brazil).create!(:name => "Brazil Client")
565
- @master_client = Client.create!(:name => "Master Client")
566
- @comment_brazil = Comment.using(:brazil).create!(:name => "Brazil Comment", :commentable => @brazil_client)
567
- @comment_master = Comment.create!(:name => "Master Comment", :commentable => @master_client)
568
- @brazil_client = Client.using(:brazil).find_by_name("Brazil Client")
569
- Client.using(:master).create!(:name => "teste")
560
+ @brazil_client = Client.using(:brazil).create!(:name => 'Brazil Client')
561
+ @master_client = Client.create!(:name => 'Master Client')
562
+ @comment_brazil = Comment.using(:brazil).create!(:name => 'Brazil Comment', :commentable => @brazil_client)
563
+ @comment_master = Comment.create!(:name => 'Master Comment', :commentable => @master_client)
564
+ @brazil_client = Client.using(:brazil).find_by_name('Brazil Client')
565
+ Client.using(:master).create!(:name => 'teste')
570
566
  end
571
567
 
572
- it "should find all models in the specified shard" do
573
- @brazil_client.comment_ids.should == [@comment_brazil.id]
574
- @brazil_client.comments().should == [@comment_brazil]
568
+ it 'should find all models in the specified shard' do
569
+ expect(@brazil_client.comment_ids).to eq([@comment_brazil.id])
570
+ expect(@brazil_client.comments).to eq([@comment_brazil])
575
571
  end
576
572
 
577
- it "should finds the client that the comment belongs" do
578
- @comment_brazil.commentable.should == @brazil_client
573
+ it 'should finds the client that the comment belongs' do
574
+ expect(@comment_brazil.commentable).to eq(@brazil_client)
579
575
  end
580
576
 
581
- it "should update the attribute for the comment" do
582
- new_brazil_client = Client.using(:brazil).create!(:name => "new Client")
577
+ it 'should update the attribute for the comment' do
578
+ new_brazil_client = Client.using(:brazil).create!(:name => 'new Client')
583
579
  @comment_brazil.commentable = new_brazil_client
584
- @comment_brazil.commentable.should == new_brazil_client
585
- @comment_brazil.save()
580
+ expect(@comment_brazil.commentable).to eq(new_brazil_client)
581
+ @comment_brazil.save
586
582
  @comment_brazil.reload
587
- @comment_brazil.commentable_id.should == new_brazil_client.id
588
- @comment_brazil.commentable().should == new_brazil_client
583
+ expect(@comment_brazil.commentable_id).to eq(new_brazil_client.id)
584
+ expect(@comment_brazil.commentable).to eq(new_brazil_client)
589
585
  end
590
586
 
591
- describe "it should works when using" do
587
+ describe 'it should works when using' do
592
588
  before(:each) do
593
- @comment_brazil_2 = Comment.using(:brazil).create!(:name => "Brazil Comment 2")
594
- @brazil_client.comments.to_set.should == [@comment_brazil].to_set
589
+ @comment_brazil_2 = Comment.using(:brazil).create!(:name => 'Brazil Comment 2')
590
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil].to_set)
595
591
  end
596
592
 
597
- it "update_attributes" do
593
+ it 'update_attributes' do
598
594
  @brazil_client.update_attributes(:comment_ids => [@comment_brazil_2.id, @comment_brazil.id])
599
- @brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
595
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil, @comment_brazil_2].to_set)
600
596
  end
601
597
 
602
- it "update_attribute" do
598
+ it 'update_attribute' do
603
599
  @brazil_client.update_attribute(:comment_ids, [@comment_brazil_2.id, @comment_brazil.id])
604
- @brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
600
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil, @comment_brazil_2].to_set)
605
601
  end
606
602
 
607
- it "<<" do
603
+ it '<<' do
608
604
  @brazil_client.comments << @comment_brazil_2
609
- @brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
605
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil, @comment_brazil_2].to_set)
610
606
  end
611
607
 
612
- it "all" do
613
- comment = @brazil_client.comments.build(:name => "Builded Comment")
614
- comment.save()
608
+ it 'all' do
609
+ comment = @brazil_client.comments.build(:name => 'Builded Comment')
610
+ comment.save
615
611
  c = @brazil_client.comments
616
- c.to_set.should == [@comment_brazil, comment].to_set
617
- c.reload.all.to_set.should == [@comment_brazil, comment].to_set
612
+ expect(c.to_set).to eq([@comment_brazil, comment].to_set)
613
+ expect(c.reload.all.to_set).to eq([@comment_brazil, comment].to_set)
618
614
  end
619
615
 
620
- it "build" do
621
- comment = @brazil_client.comments.build(:name => "Builded Comment")
622
- comment.save()
623
- @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
616
+ it 'build' do
617
+ comment = @brazil_client.comments.build(:name => 'Builded Comment')
618
+ comment.save
619
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil, comment].to_set)
624
620
  end
625
621
 
626
- it "create" do
627
- comment = @brazil_client.comments.create(:name => "Builded Comment")
628
- @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
622
+ it 'create' do
623
+ comment = @brazil_client.comments.create(:name => 'Builded Comment')
624
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil, comment].to_set)
629
625
  end
630
626
 
631
- it "count" do
632
- @brazil_client.comments.count.should == 1
633
- comment = @brazil_client.comments.create(:name => "Builded Comment")
634
- @brazil_client.comments.count.should == 2
627
+ it 'count' do
628
+ expect(@brazil_client.comments.count).to eq(1)
629
+ _cmt = @brazil_client.comments.create(:name => 'Builded Comment')
630
+ expect(@brazil_client.comments.count).to eq(2)
635
631
  end
636
632
 
637
- it "size" do
638
- @brazil_client.comments.size.should == 1
639
- comment = @brazil_client.comments.create(:name => "Builded Comment")
640
- @brazil_client.comments.size.should == 2
633
+ it 'size' do
634
+ expect(@brazil_client.comments.size).to eq(1)
635
+ _cmt = @brazil_client.comments.create(:name => 'Builded Comment')
636
+ expect(@brazil_client.comments.size).to eq(2)
641
637
  end
642
638
 
643
- it "create!" do
644
- comment = @brazil_client.comments.create!(:name => "Builded Comment")
645
- @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
639
+ it 'create!' do
640
+ comment = @brazil_client.comments.create!(:name => 'Builded Comment')
641
+ expect(@brazil_client.comments.to_set).to eq([@comment_brazil, comment].to_set)
646
642
  end
647
643
 
648
- it "length" do
649
- @brazil_client.comments.length.should == 1
650
- comment = @brazil_client.comments.create(:name => "Builded Comment")
651
- @brazil_client.comments.length.should == 2
644
+ it 'length' do
645
+ expect(@brazil_client.comments.length).to eq(1)
646
+ _cmt = @brazil_client.comments.create(:name => 'Builded Comment')
647
+ expect(@brazil_client.comments.length).to eq(2)
652
648
  end
653
649
 
654
- it "empty?" do
655
- @brazil_client.comments.empty?.should be_false
656
- c = Client.create!(:name => "Client1")
657
- c.comments.empty?.should be_true
650
+ it 'empty?' do
651
+ expect(@brazil_client.comments.empty?).to be false
652
+ c = Client.create!(:name => 'Client1')
653
+ expect(c.comments.empty?).to be true
658
654
  end
659
655
 
660
- it "delete" do
661
- @brazil_client.comments.empty?.should be_false
656
+ it 'delete' do
657
+ expect(@brazil_client.comments.empty?).to be false
662
658
  @brazil_client.comments.delete(@comment_brazil)
663
659
  @brazil_client.reload
664
660
  @comment_brazil.reload
665
- @comment_brazil.commentable.should be_nil
666
- @brazil_client.comments.should == []
667
- @brazil_client.comments.empty?.should be_true
661
+ expect(@comment_brazil.commentable).to be_nil
662
+ expect(@brazil_client.comments).to eq([])
663
+ expect(@brazil_client.comments.empty?).to be true
668
664
  end
669
665
 
670
- it "delete_all" do
671
- @brazil_client.comments.empty?.should be_false
666
+ it 'delete_all' do
667
+ expect(@brazil_client.comments.empty?).to be false
672
668
  @brazil_client.comments.delete_all
673
- @brazil_client.comments.empty?.should be_true
669
+ expect(@brazil_client.comments.empty?).to be true
674
670
  end
675
671
 
676
- it "destroy_all" do
677
- @brazil_client.comments.empty?.should be_false
672
+ it 'destroy_all' do
673
+ expect(@brazil_client.comments.empty?).to be false
678
674
  @brazil_client.comments.destroy_all
679
- @brazil_client.comments.empty?.should be_true
675
+ expect(@brazil_client.comments.empty?).to be true
680
676
  end
681
677
 
682
- it "find" do
683
- @brazil_client.comments.first.should == @comment_brazil
678
+ it 'find' do
679
+ expect(@brazil_client.comments.first).to eq(@comment_brazil)
684
680
  @brazil_client.comments.destroy_all
685
- @brazil_client.comments.first.should be_nil
681
+ expect(@brazil_client.comments.first).to be_nil
686
682
  end
687
683
 
688
- it "exists?" do
689
- @brazil_client.comments.exists?(@comment_brazil).should be_true
684
+ it 'exists?' do
685
+ expect(@brazil_client.comments.exists?(@comment_brazil)).to be true
690
686
  @brazil_client.comments.destroy_all
691
- @brazil_client.comments.exists?(@comment_brazil).should be_false
687
+ expect(@brazil_client.comments.exists?(@comment_brazil)).to be false
692
688
  end
693
689
 
694
- it "uniq" do
695
- @brazil_client.comments.uniq.should == [@comment_brazil]
690
+ it 'uniq' do
691
+ expect(@brazil_client.comments.uniq).to eq([@comment_brazil])
696
692
  end
697
693
 
698
- it "clear" do
699
- @brazil_client.comments.empty?.should be_false
694
+ it 'clear' do
695
+ expect(@brazil_client.comments.empty?).to be false
700
696
  @brazil_client.comments.clear
701
- @brazil_client.comments.empty?.should be_true
697
+ expect(@brazil_client.comments.empty?).to be true
702
698
  end
703
699
  end
704
700
  end
705
701
 
706
- it "block" do
707
- @brazil_role = Role.using(:brazil).create!(:name => "Brazil Role")
708
- @brazil_role.permissions.build(:name => "ok").name.should == "ok"
709
- @brazil_role.permissions.create(:name => "ok").name.should == "ok"
710
- @brazil_role.permissions.create!(:name => "ok").name.should == "ok"
702
+ it 'block' do
703
+ @brazil_role = Role.using(:brazil).create!(:name => 'Brazil Role')
704
+ expect(@brazil_role.permissions.build(:name => 'ok').name).to eq('ok')
705
+ expect(@brazil_role.permissions.create(:name => 'ok').name).to eq('ok')
706
+ expect(@brazil_role.permissions.create!(:name => 'ok').name).to eq('ok')
711
707
  end
712
708
  end