ar-octopus 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/.rspec +1 -1
- data/.rubocop.yml +46 -0
- data/.rubocop_todo.yml +52 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -9
- data/Appraisals +4 -0
- data/Rakefile +17 -16
- data/ar-octopus.gemspec +22 -16
- data/gemfiles/rails41.gemfile +7 -0
- data/init.rb +1 -1
- data/lib/ar-octopus.rb +1 -1
- data/lib/octopus.rb +38 -37
- data/lib/octopus/abstract_adapter.rb +0 -2
- data/lib/octopus/association.rb +8 -6
- data/lib/octopus/association_shard_tracking.rb +80 -81
- data/lib/octopus/collection_association.rb +7 -5
- data/lib/octopus/collection_proxy.rb +11 -9
- data/lib/octopus/has_and_belongs_to_many_association.rb +5 -3
- data/lib/octopus/load_balancing.rb +3 -2
- data/lib/octopus/load_balancing/round_robin.rb +12 -8
- data/lib/octopus/migration.rb +117 -108
- data/lib/octopus/model.rb +130 -134
- data/lib/octopus/persistence.rb +1 -1
- data/lib/octopus/proxy.rb +345 -339
- data/lib/octopus/railtie.rb +2 -2
- data/lib/octopus/relation_proxy.rb +6 -1
- data/lib/octopus/scope_proxy.rb +38 -36
- data/lib/octopus/shard_tracking.rb +36 -35
- data/lib/octopus/shard_tracking/attribute.rb +12 -14
- data/lib/octopus/shard_tracking/dynamic.rb +7 -3
- data/lib/octopus/singular_association.rb +5 -3
- data/lib/octopus/slave_group.rb +10 -8
- data/lib/octopus/version.rb +1 -1
- data/rails/init.rb +1 -1
- data/sample_app/autotest/discover.rb +2 -2
- data/sample_app/config/application.rb +1 -1
- data/sample_app/config/boot.rb +1 -1
- data/sample_app/config/environments/test.rb +1 -1
- data/sample_app/config/initializers/session_store.rb +1 -1
- data/sample_app/config/initializers/wrap_parameters.rb +1 -1
- data/sample_app/config/routes.rb +1 -1
- data/sample_app/db/migrate/20100720210335_create_sample_users.rb +2 -2
- data/sample_app/db/schema.rb +10 -10
- data/sample_app/db/seeds.rb +3 -3
- data/sample_app/features/step_definitions/seeds_steps.rb +4 -4
- data/sample_app/features/step_definitions/web_steps.rb +3 -4
- data/sample_app/features/support/env.rb +3 -4
- data/sample_app/features/support/paths.rb +4 -4
- data/sample_app/spec/spec_helper.rb +3 -3
- data/spec/migrations/10_create_users_using_replication.rb +3 -3
- data/spec/migrations/11_add_field_in_all_slaves.rb +3 -3
- data/spec/migrations/12_create_users_using_block.rb +7 -7
- data/spec/migrations/13_create_users_using_block_and_using.rb +4 -4
- data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +2 -2
- data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +2 -2
- data/spec/migrations/1_create_users_on_master.rb +3 -3
- data/spec/migrations/2_create_users_on_canada.rb +3 -3
- data/spec/migrations/3_create_users_on_both_shards.rb +3 -3
- data/spec/migrations/4_create_users_on_shards_of_a_group.rb +3 -3
- data/spec/migrations/5_create_users_on_multiples_groups.rb +2 -2
- data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +3 -3
- data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +3 -3
- data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +3 -3
- data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +4 -4
- data/spec/octopus/association_shard_tracking_spec.rb +413 -417
- data/spec/octopus/collection_proxy_spec.rb +6 -5
- data/spec/octopus/log_subscriber_spec.rb +4 -4
- data/spec/octopus/migration_spec.rb +48 -48
- data/spec/octopus/model_spec.rb +267 -292
- data/spec/octopus/octopus_spec.rb +40 -41
- data/spec/octopus/proxy_spec.rb +124 -124
- data/spec/octopus/relation_proxy_spec.rb +32 -32
- data/spec/octopus/replicated_slave_grouped_spec.rb +23 -23
- data/spec/octopus/replication_spec.rb +61 -66
- data/spec/octopus/scope_proxy_spec.rb +56 -10
- data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +29 -29
- data/spec/octopus/sharded_spec.rb +10 -10
- data/spec/spec_helper.rb +6 -6
- data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +1 -3
- data/spec/support/database_connection.rb +2 -2
- data/spec/support/database_models.rb +16 -17
- data/spec/support/octopus_helper.rb +19 -21
- data/spec/support/query_count.rb +1 -3
- data/spec/support/shared_contexts.rb +3 -3
- data/spec/tasks/octopus.rake_spec.rb +10 -10
- 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
|
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 =
|
24
|
-
|
25
|
-
rescue
|
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[
|
4
|
-
require File.expand_path(
|
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
|
@@ -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 =>
|
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 =>
|
5
|
-
User.create!(:name =>
|
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 =>
|
10
|
-
User.create!(:name =>
|
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 =>
|
6
|
+
User.create!(:name => 'Canada')
|
7
7
|
end
|
8
8
|
|
9
|
-
User.create!(:name =>
|
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 =>
|
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
|
@@ -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 =>
|
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 =>
|
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 =>
|
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 =>
|
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 =>
|
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
|
2
|
+
using_group(:country_shards, :invalid_group)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
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
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canada] do
|
4
|
-
describe
|
4
|
+
describe 'when you have a 1 x 1 relationship' do
|
5
5
|
before(:each) do
|
6
|
-
@computer_brazil = Computer.using(:brazil).create!(:name =>
|
7
|
-
@computer_master = Computer.create!(:name =>
|
8
|
-
@keyboard_brazil = Keyboard.using(:brazil).create!(:name =>
|
9
|
-
@keyboard_master = Keyboard.create!(:name =>
|
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
|
13
|
-
@keyboard_master.computer.
|
14
|
-
@keyboard_brazil.computer.
|
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
|
18
|
-
new_computer_brazil = Computer.using(:brazil).create!(:name =>
|
19
|
-
|
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.
|
24
|
-
@keyboard_brazil.computer.
|
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.
|
27
|
+
expect(new_computer_brazil.keyboard).to eq(@keyboard_brazil)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
c = Computer.using(:brazil).create!(:name =>
|
32
|
-
k = c.build_keyboard(:name =>
|
33
|
-
c.save
|
34
|
-
k.save
|
35
|
-
c.keyboard.
|
36
|
-
k.computer_id.
|
37
|
-
k.computer.
|
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
|
41
|
-
c = Computer.using(:brazil).create!(:name =>
|
42
|
-
k = c.create_keyboard(:name =>
|
43
|
-
c.save
|
44
|
-
k.save
|
45
|
-
c.keyboard.
|
46
|
-
k.computer_id.
|
47
|
-
k.computer.
|
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
|
51
|
-
c = Computer.using(:brazil).create!(:name =>
|
52
|
-
k = c.create_keyboard(:name =>
|
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).
|
56
|
+
expect(Computer.using(:brazil).includes(:keyboard).find(c.id)).to eq(c)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe
|
60
|
+
describe 'when you have a N x N relationship' do
|
61
61
|
before(:each) do
|
62
|
-
@brazil_role = Role.using(:brazil).create!(:name =>
|
63
|
-
@master_role = Role.create!(:name =>
|
64
|
-
@permission_brazil = Permission.using(:brazil).create!(:name =>
|
65
|
-
@permission_master = Permission.using(:master).create!(:name =>
|
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 =>
|
67
|
+
@brazil_role.save
|
68
|
+
Client.using(:master).create!(:name => 'teste')
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
@brazil_role.permission_ids
|
73
|
-
@brazil_role.permissions
|
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.
|
76
|
-
@brazil_role.permissions.last.
|
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
|
80
|
-
@permission_brazil.role_ids.
|
81
|
-
@permission_brazil.roles.
|
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.
|
84
|
-
@permission_brazil.roles.last.
|
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
|
88
|
-
new_brazil_role = Role.using(:brazil).create!(:name =>
|
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.
|
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.
|
94
|
-
@permission_brazil.roles
|
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
|
98
|
-
new_brazil_role = Role.using(:brazil).create!(:name =>
|
99
|
-
c = new_brazil_role.permissions.create(:name =>
|
100
|
-
c.save
|
101
|
-
new_brazil_role.save
|
102
|
-
c.roles
|
103
|
-
new_brazil_role.permissions.
|
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
|
106
|
+
describe 'it should works when using' do
|
107
107
|
before(:each) do
|
108
|
-
@permission_brazil_2 = Permission.using(:brazil).create!(:name =>
|
109
|
-
@role = Role.using(:brazil).create!(:name =>
|
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
|
112
|
+
it 'update_attributes' do
|
113
113
|
@permission_brazil_2.update_attributes(:role_ids => [@role.id])
|
114
|
-
@permission_brazil_2.roles.to_set.
|
114
|
+
expect(@permission_brazil_2.roles.to_set).to eq([@role].to_set)
|
115
115
|
end
|
116
116
|
|
117
|
-
it
|
117
|
+
it 'update_attribute' do
|
118
118
|
@permission_brazil_2.update_attribute(:role_ids, [@role.id])
|
119
|
-
@permission_brazil_2.roles.to_set.
|
119
|
+
expect(@permission_brazil_2.roles.to_set).to eq([@role].to_set)
|
120
120
|
end
|
121
121
|
|
122
|
-
it
|
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.
|
127
|
+
expect(@permission_brazil_2.roles.to_set).to eq([@role].to_set)
|
128
128
|
end
|
129
129
|
|
130
|
-
it
|
131
|
-
role = @permission_brazil_2.roles.build(:name =>
|
132
|
-
@permission_brazil_2.save
|
133
|
-
@permission_brazil_2.roles.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
|
137
|
-
role = @permission_brazil_2.roles.create(:name =>
|
138
|
-
@permission_brazil_2.roles.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
|
142
|
-
role = @permission_brazil_2.roles.create!(:name =>
|
143
|
-
@permission_brazil_2.roles.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
|
147
|
-
@permission_brazil_2.roles.count.
|
148
|
-
|
149
|
-
@permission_brazil_2.roles.count.
|
150
|
-
|
151
|
-
@permission_brazil_2.roles.count.
|
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
|
155
|
-
@permission_brazil_2.roles.size.
|
156
|
-
|
157
|
-
@permission_brazil_2.roles.size.
|
158
|
-
|
159
|
-
@permission_brazil_2.roles.size.
|
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
|
163
|
-
@permission_brazil_2.roles.length.
|
164
|
-
|
165
|
-
@permission_brazil_2.roles.length.
|
166
|
-
|
167
|
-
@permission_brazil_2.roles.length.
|
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
|
-
|
172
|
-
@permission_brazil_2.roles.
|
173
|
-
|
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
|
178
|
-
|
179
|
-
@permission_brazil_2.roles.empty
|
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
|
180
|
+
expect(@permission_brazil_2.roles.empty?).to be true
|
182
181
|
end
|
183
182
|
|
184
|
-
it
|
185
|
-
|
186
|
-
@permission_brazil_2.roles.empty
|
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
|
187
|
+
expect(@permission_brazil_2.roles.empty?).to be true
|
189
188
|
end
|
190
189
|
|
191
|
-
it
|
192
|
-
role = @permission_brazil_2.roles.create(:name =>
|
193
|
-
@permission_brazil_2.roles.first.
|
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.
|
194
|
+
expect(@permission_brazil_2.roles.first).to be_nil
|
196
195
|
end
|
197
196
|
|
198
|
-
it
|
199
|
-
role = @permission_brazil_2.roles.create(:name =>
|
200
|
-
@permission_brazil_2.roles.exists?(role).
|
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).
|
201
|
+
expect(@permission_brazil_2.roles.exists?(role)).to be false
|
203
202
|
end
|
204
203
|
|
205
|
-
it
|
206
|
-
|
207
|
-
@permission_brazil_2.roles.empty
|
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
|
208
|
+
expect(@permission_brazil_2.roles.empty?).to be true
|
210
209
|
end
|
211
210
|
|
212
|
-
it
|
213
|
-
role = @permission_brazil_2.roles.create(:name =>
|
214
|
-
@permission_brazil_2.roles.empty
|
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.
|
219
|
-
@permission_brazil_2.roles.
|
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
|
223
|
+
describe 'when you have has_many :through' do
|
225
224
|
before(:each) do
|
226
|
-
@programmer = Programmer.using(:brazil).create!(:name =>
|
227
|
-
@project = Project.using(:brazil).create!(:name =>
|
228
|
-
@project2 = Project.using(:brazil).create!(:name =>
|
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 =>
|
229
|
+
@programmer.save
|
230
|
+
Project.using(:master).create!(:name => 'Project Master')
|
232
231
|
end
|
233
232
|
|
234
|
-
it
|
235
|
-
@programmer.project_ids
|
236
|
-
@programmer.projects
|
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.
|
239
|
-
@programmer.projects.last.
|
237
|
+
expect(@programmer.projects.first).to eq(@project)
|
238
|
+
expect(@programmer.projects.last).to eq(@project)
|
240
239
|
end
|
241
240
|
|
242
|
-
|
243
|
-
|
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.
|
247
|
-
@project.save
|
244
|
+
expect(@project.programmers).to eq([new_brazil_programmer])
|
245
|
+
@project.save
|
248
246
|
@project.reload
|
249
|
-
@project.programmer_ids.
|
250
|
-
@project.programmers
|
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
|
254
|
-
new_brazil_programmer = Programmer.using(:brazil).create!(:name =>
|
255
|
-
c = new_brazil_programmer.projects.create(:name =>
|
256
|
-
c.save
|
257
|
-
new_brazil_programmer.save
|
258
|
-
c.programmers
|
259
|
-
new_brazil_programmer.projects.
|
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
|
260
|
+
describe 'it should works when using' do
|
263
261
|
before(:each) do
|
264
|
-
@new_brazil_programmer = Programmer.using(:brazil).create!(:name =>
|
265
|
-
@project = Project.using(:brazil).create!(:name =>
|
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
|
266
|
+
it 'update_attributes' do
|
269
267
|
@new_brazil_programmer.update_attributes(:project_ids => [@project.id])
|
270
|
-
@new_brazil_programmer.projects.to_set.
|
268
|
+
expect(@new_brazil_programmer.projects.to_set).to eq([@project].to_set)
|
271
269
|
end
|
272
270
|
|
273
|
-
it
|
271
|
+
it 'update_attribute' do
|
274
272
|
@new_brazil_programmer.update_attribute(:project_ids, [@project.id])
|
275
|
-
@new_brazil_programmer.projects.to_set.
|
273
|
+
expect(@new_brazil_programmer.projects.to_set).to eq([@project].to_set)
|
276
274
|
end
|
277
275
|
|
278
|
-
it
|
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.
|
281
|
+
expect(@new_brazil_programmer.projects.to_set).to eq([@project].to_set)
|
284
282
|
end
|
285
283
|
|
286
|
-
it
|
287
|
-
role = @new_brazil_programmer.projects.build(:name =>
|
288
|
-
@new_brazil_programmer.save
|
289
|
-
@new_brazil_programmer.projects.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
|
293
|
-
role = @new_brazil_programmer.projects.create(:name =>
|
294
|
-
@new_brazil_programmer.projects.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
|
298
|
-
role = @new_brazil_programmer.projects.create!(:name =>
|
299
|
-
@new_brazil_programmer.projects.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
|
303
|
-
@new_brazil_programmer.projects.count.
|
304
|
-
|
305
|
-
@new_brazil_programmer.projects.count.
|
306
|
-
|
307
|
-
@new_brazil_programmer.projects.count.
|
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
|
311
|
-
@new_brazil_programmer.projects.size.
|
312
|
-
|
313
|
-
@new_brazil_programmer.projects.size.
|
314
|
-
|
315
|
-
@new_brazil_programmer.projects.size.
|
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
|
319
|
-
@new_brazil_programmer.projects.length.
|
320
|
-
|
321
|
-
@new_brazil_programmer.projects.length.
|
322
|
-
|
323
|
-
@new_brazil_programmer.projects.length.
|
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
|
-
|
328
|
-
@new_brazil_programmer.projects.
|
329
|
-
|
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
|
334
|
-
|
335
|
-
@new_brazil_programmer.projects.empty
|
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
|
334
|
+
expect(@new_brazil_programmer.projects.empty?).to be true
|
338
335
|
end
|
339
336
|
|
340
|
-
it
|
341
|
-
|
342
|
-
@new_brazil_programmer.projects.empty
|
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
|
341
|
+
expect(@new_brazil_programmer.projects.empty?).to be true
|
345
342
|
end
|
346
343
|
|
347
|
-
it
|
348
|
-
role = @new_brazil_programmer.projects.create(:name =>
|
349
|
-
@new_brazil_programmer.projects.first.
|
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.
|
348
|
+
expect(@new_brazil_programmer.projects.first).to be_nil
|
352
349
|
end
|
353
350
|
|
354
|
-
it
|
355
|
-
role = @new_brazil_programmer.projects.create(:name =>
|
356
|
-
@new_brazil_programmer.projects.exists?(role).
|
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).
|
355
|
+
expect(@new_brazil_programmer.projects.exists?(role)).to be false
|
359
356
|
end
|
360
357
|
|
361
|
-
it
|
362
|
-
|
363
|
-
@new_brazil_programmer.projects.empty
|
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
|
362
|
+
expect(@new_brazil_programmer.projects.empty?).to be true
|
366
363
|
end
|
367
364
|
|
368
|
-
it
|
369
|
-
role = @new_brazil_programmer.projects.create(:name =>
|
370
|
-
@new_brazil_programmer.projects.empty
|
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.
|
375
|
-
@new_brazil_programmer.projects.
|
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
|
377
|
+
describe 'when you have a 1 x N relationship' do
|
381
378
|
before(:each) do
|
382
|
-
@brazil_client = Client.using(:brazil).create!(:name =>
|
383
|
-
@master_client = Client.create!(:name =>
|
384
|
-
@item_brazil = Item.using(:brazil).create!(:name =>
|
385
|
-
@item_master = Item.create!(:name =>
|
386
|
-
@brazil_client = Client.using(:brazil).find_by_name(
|
387
|
-
Client.using(:master).create!(:name =>
|
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
|
391
|
-
@brazil_client.item_ids.
|
392
|
-
@brazil_client.items
|
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.
|
395
|
-
@brazil_client.items.first.
|
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
|
399
|
-
@item_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
|
403
|
-
|
404
|
-
@brazil_client.items << Item.using(:canada).create!(:name =>
|
405
|
-
end.
|
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
|
409
|
-
new_brazil_client = Client.using(:brazil).create!(:name =>
|
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.
|
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.
|
415
|
-
@item_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
|
419
|
-
item2 = Item.using(:brazil).create!(:name =>
|
420
|
-
c = item2.create_client(:name =>
|
421
|
-
c.save
|
422
|
-
item2.save
|
423
|
-
item2.client.
|
424
|
-
c.items
|
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
|
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.
|
436
|
-
collection.
|
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.
|
442
|
-
collection.
|
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
|
443
|
+
describe 'it should works when using' do
|
447
444
|
before(:each) do
|
448
|
-
@item_brazil_2 = Item.using(:brazil).create!(:name =>
|
449
|
-
@brazil_client.items.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.
|
451
|
+
expect(@brazil_client.items.to_set).to eq([@item_brazil, @item_brazil_2].to_set)
|
456
452
|
end
|
457
453
|
|
458
|
-
it
|
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.
|
456
|
+
expect(@brazil_client.items.to_set).to eq([@item_brazil, @item_brazil_2].to_set)
|
461
457
|
end
|
462
458
|
|
463
|
-
it
|
459
|
+
it '<<' do
|
464
460
|
@brazil_client.items << @item_brazil_2
|
465
|
-
@brazil_client.items.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
|
469
|
-
item = @brazil_client.items.build(:name =>
|
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.
|
473
|
-
i.reload.all.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
|
477
|
-
item = @brazil_client.items.build(:name =>
|
478
|
-
item.save
|
479
|
-
@brazil_client.items.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
|
483
|
-
item = @brazil_client.items.create(:name =>
|
484
|
-
@brazil_client.items.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
|
488
|
-
@brazil_client.items.count.
|
489
|
-
|
490
|
-
@brazil_client.items.count.
|
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
|
494
|
-
@brazil_client.items.size.
|
495
|
-
|
496
|
-
@brazil_client.items.size.
|
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
|
500
|
-
item = @brazil_client.items.create!(:name =>
|
501
|
-
@brazil_client.items.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
|
505
|
-
@brazil_client.items.length.
|
506
|
-
|
507
|
-
@brazil_client.items.length.
|
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
|
511
|
-
@brazil_client.items.empty
|
512
|
-
c = Client.create!(:name =>
|
513
|
-
c.items.empty
|
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
|
517
|
-
@brazil_client.items.empty
|
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.
|
522
|
-
@brazil_client.items.
|
523
|
-
@brazil_client.items.empty
|
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
|
527
|
-
@brazil_client.items.empty
|
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
|
525
|
+
expect(@brazil_client.items.empty?).to be true
|
530
526
|
end
|
531
527
|
|
532
|
-
it
|
533
|
-
@brazil_client.items.empty
|
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
|
531
|
+
expect(@brazil_client.items.empty?).to be true
|
536
532
|
end
|
537
533
|
|
538
|
-
it
|
539
|
-
@brazil_client.items.first.
|
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.
|
537
|
+
expect(@brazil_client.items.first).to be_nil
|
542
538
|
end
|
543
539
|
|
544
|
-
it
|
545
|
-
@brazil_client.items.exists?(@item_brazil).
|
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).
|
543
|
+
expect(@brazil_client.items.exists?(@item_brazil)).to be false
|
548
544
|
end
|
549
545
|
|
550
|
-
it
|
551
|
-
@brazil_client.items.uniq.
|
546
|
+
it 'uniq' do
|
547
|
+
expect(@brazil_client.items.uniq).to eq([@item_brazil])
|
552
548
|
end
|
553
549
|
|
554
|
-
it
|
555
|
-
@brazil_client.items.empty
|
550
|
+
it 'clear' do
|
551
|
+
expect(@brazil_client.items.empty?).to be false
|
556
552
|
@brazil_client.items.clear
|
557
|
-
@brazil_client.items.empty
|
553
|
+
expect(@brazil_client.items.empty?).to be true
|
558
554
|
end
|
559
555
|
end
|
560
556
|
end
|
561
557
|
|
562
|
-
describe
|
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 =>
|
565
|
-
@master_client = Client.create!(:name =>
|
566
|
-
@comment_brazil = Comment.using(:brazil).create!(:name =>
|
567
|
-
@comment_master = Comment.create!(:name =>
|
568
|
-
@brazil_client = Client.using(:brazil).find_by_name(
|
569
|
-
Client.using(:master).create!(:name =>
|
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
|
573
|
-
@brazil_client.comment_ids.
|
574
|
-
@brazil_client.comments
|
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
|
578
|
-
@comment_brazil.commentable.
|
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
|
582
|
-
new_brazil_client = Client.using(:brazil).create!(:name =>
|
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.
|
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.
|
588
|
-
@comment_brazil.commentable
|
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
|
587
|
+
describe 'it should works when using' do
|
592
588
|
before(:each) do
|
593
|
-
@comment_brazil_2 = Comment.using(:brazil).create!(:name =>
|
594
|
-
@brazil_client.comments.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
|
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.
|
595
|
+
expect(@brazil_client.comments.to_set).to eq([@comment_brazil, @comment_brazil_2].to_set)
|
600
596
|
end
|
601
597
|
|
602
|
-
it
|
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.
|
600
|
+
expect(@brazil_client.comments.to_set).to eq([@comment_brazil, @comment_brazil_2].to_set)
|
605
601
|
end
|
606
602
|
|
607
|
-
it
|
603
|
+
it '<<' do
|
608
604
|
@brazil_client.comments << @comment_brazil_2
|
609
|
-
@brazil_client.comments.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
|
613
|
-
comment = @brazil_client.comments.build(:name =>
|
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.
|
617
|
-
c.reload.all.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
|
621
|
-
comment = @brazil_client.comments.build(:name =>
|
622
|
-
comment.save
|
623
|
-
@brazil_client.comments.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
|
627
|
-
comment = @brazil_client.comments.create(:name =>
|
628
|
-
@brazil_client.comments.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
|
632
|
-
@brazil_client.comments.count.
|
633
|
-
|
634
|
-
@brazil_client.comments.count.
|
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
|
638
|
-
@brazil_client.comments.size.
|
639
|
-
|
640
|
-
@brazil_client.comments.size.
|
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
|
644
|
-
comment = @brazil_client.comments.create!(:name =>
|
645
|
-
@brazil_client.comments.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
|
649
|
-
@brazil_client.comments.length.
|
650
|
-
|
651
|
-
@brazil_client.comments.length.
|
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
|
655
|
-
@brazil_client.comments.empty
|
656
|
-
c = Client.create!(:name =>
|
657
|
-
c.comments.empty
|
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
|
661
|
-
@brazil_client.comments.empty
|
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.
|
666
|
-
@brazil_client.comments.
|
667
|
-
@brazil_client.comments.empty
|
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
|
671
|
-
@brazil_client.comments.empty
|
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
|
669
|
+
expect(@brazil_client.comments.empty?).to be true
|
674
670
|
end
|
675
671
|
|
676
|
-
it
|
677
|
-
@brazil_client.comments.empty
|
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
|
675
|
+
expect(@brazil_client.comments.empty?).to be true
|
680
676
|
end
|
681
677
|
|
682
|
-
it
|
683
|
-
@brazil_client.comments.first.
|
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.
|
681
|
+
expect(@brazil_client.comments.first).to be_nil
|
686
682
|
end
|
687
683
|
|
688
|
-
it
|
689
|
-
@brazil_client.comments.exists?(@comment_brazil).
|
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).
|
687
|
+
expect(@brazil_client.comments.exists?(@comment_brazil)).to be false
|
692
688
|
end
|
693
689
|
|
694
|
-
it
|
695
|
-
@brazil_client.comments.uniq.
|
690
|
+
it 'uniq' do
|
691
|
+
expect(@brazil_client.comments.uniq).to eq([@comment_brazil])
|
696
692
|
end
|
697
693
|
|
698
|
-
it
|
699
|
-
@brazil_client.comments.empty
|
694
|
+
it 'clear' do
|
695
|
+
expect(@brazil_client.comments.empty?).to be false
|
700
696
|
@brazil_client.comments.clear
|
701
|
-
@brazil_client.comments.empty
|
697
|
+
expect(@brazil_client.comments.empty?).to be true
|
702
698
|
end
|
703
699
|
end
|
704
700
|
end
|
705
701
|
|
706
|
-
it
|
707
|
-
@brazil_role = Role.using(:brazil).create!(:name =>
|
708
|
-
@brazil_role.permissions.build(:name =>
|
709
|
-
@brazil_role.permissions.create(:name =>
|
710
|
-
@brazil_role.permissions.create!(:name =>
|
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
|