ar-octopus 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +11 -0
  2. data/.travis.yml +22 -0
  3. data/Appraisals +18 -0
  4. data/Gemfile +3 -12
  5. data/README.mkdn +63 -24
  6. data/Rakefile +70 -92
  7. data/ar-octopus.gemspec +25 -198
  8. data/lib/ar-octopus.rb +1 -0
  9. data/lib/octopus.rb +73 -25
  10. data/lib/octopus/association.rb +6 -5
  11. data/lib/octopus/association_collection.rb +58 -4
  12. data/lib/octopus/has_and_belongs_to_many_association.rb +4 -4
  13. data/lib/octopus/logger.rb +9 -4
  14. data/lib/octopus/migration.rb +155 -50
  15. data/lib/octopus/model.rb +98 -34
  16. data/lib/octopus/proxy.rb +124 -53
  17. data/lib/octopus/rails2/association.rb +46 -93
  18. data/lib/octopus/rails2/persistence.rb +1 -1
  19. data/lib/octopus/rails2/scope.rb +17 -0
  20. data/lib/octopus/rails3.1/singular_association.rb +34 -0
  21. data/lib/octopus/rails3.2/persistence.rb +12 -0
  22. data/lib/octopus/rails3/abstract_adapter.rb +39 -0
  23. data/lib/octopus/rails3/arel.rb +5 -5
  24. data/lib/octopus/rails3/log_subscriber.rb +22 -0
  25. data/lib/octopus/rails3/persistence.rb +10 -5
  26. data/lib/octopus/railtie.rb +13 -0
  27. data/lib/octopus/scope_proxy.rb +22 -16
  28. data/lib/octopus/version.rb +3 -0
  29. data/lib/tasks/octopus.rake +20 -0
  30. data/sample_app/Gemfile +2 -2
  31. data/sample_app/config/initializers/inflections.rb +1 -1
  32. data/sample_app/config/initializers/secret_token.rb +1 -1
  33. data/sample_app/db/migrate/20100720172730_create_items.rb +1 -1
  34. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +1 -1
  35. data/sample_app/db/seeds.rb +1 -1
  36. data/sample_app/features/migrate.feature +12 -12
  37. data/sample_app/features/seed.feature +3 -3
  38. data/sample_app/features/step_definitions/web_steps.rb +5 -5
  39. data/sample_app/features/support/env.rb +8 -8
  40. data/sample_app/lib/tasks/cucumber.rake +2 -2
  41. data/sample_app/public/javascripts/effects.js +1 -1
  42. data/spec/config/shards.yml +38 -28
  43. data/spec/migrations/11_add_field_in_all_slaves.rb +1 -1
  44. data/spec/migrations/12_create_users_using_block.rb +2 -2
  45. data/spec/migrations/13_create_users_using_block_and_using.rb +2 -2
  46. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +11 -0
  47. data/spec/migrations/1_create_users_on_master.rb +1 -1
  48. data/spec/migrations/2_create_users_on_canada.rb +1 -1
  49. data/spec/migrations/3_create_users_on_both_shards.rb +1 -1
  50. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +1 -1
  51. data/spec/migrations/5_create_users_on_multiples_groups.rb +1 -1
  52. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +1 -1
  53. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +1 -1
  54. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +1 -1
  55. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +1 -1
  56. data/spec/octopus/association_spec.rb +88 -70
  57. data/spec/octopus/log_subscriber_spec.rb +22 -0
  58. data/spec/octopus/logger_spec.rb +28 -15
  59. data/spec/octopus/migration_spec.rb +47 -43
  60. data/spec/octopus/model_spec.rb +179 -13
  61. data/spec/octopus/octopus_spec.rb +26 -4
  62. data/spec/octopus/proxy_spec.rb +61 -23
  63. data/spec/octopus/{replication_specs.rb → replication_spec.rb} +33 -26
  64. data/spec/octopus/scope_proxy_spec.rb +3 -3
  65. data/spec/octopus/sharded_spec.rb +9 -9
  66. data/spec/spec_helper.rb +10 -12
  67. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +17 -0
  68. data/spec/support/database_connection.rb +2 -0
  69. data/spec/{database_models.rb → support/database_models.rb} +27 -2
  70. data/spec/support/octopus_helper.rb +50 -0
  71. data/spec/tasks/octopus.rake_spec.rb +36 -0
  72. metadata +188 -169
  73. data/Gemfile.lock +0 -68
  74. data/lib/octopus/rails3/association.rb +0 -112
  75. data/spec/database_connection.rb +0 -4
  76. data/spec/octopus/controller_spec.rb +0 -34
  77. data/spec/octopus_helper.rb +0 -37
@@ -1,6 +1,6 @@
1
1
  # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
- # It is recommended to regenerate this file in the future when you upgrade to a
3
- # newer version of cucumber-rails. Consider adding your own code to a new file
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
@@ -24,7 +24,7 @@ require 'aruba/cucumber'
24
24
  # steps to use the XPath syntax.
25
25
  Capybara.default_selector = :css
26
26
 
27
- # If you set this to false, any error raised from within your app will bubble
27
+ # If you set this to false, any error raised from within your app will bubble
28
28
  # up to your step definition and out to cucumber unless you catch it somewhere
29
29
  # on the way. You can make Rails rescue errors and render error pages on a
30
30
  # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
@@ -36,15 +36,15 @@ Capybara.default_selector = :css
36
36
  ActionController::Base.allow_rescue = false
37
37
 
38
38
  # If you set this to true, each scenario will run in a database transaction.
39
- # You can still turn off transactions on a per-scenario basis, simply tagging
39
+ # You can still turn off transactions on a per-scenario basis, simply tagging
40
40
  # a feature or scenario with the @no-txn tag. If you are using Capybara,
41
41
  # tagging with @culerity or @javascript will also turn transactions off.
42
42
  #
43
43
  # If you set this to false, transactions will be off for all scenarios,
44
44
  # regardless of whether you use @no-txn or not.
45
45
  #
46
- # Beware that turning transactions off will leave data in your database
47
- # after each scenario, which can lead to hard-to-debug failures in
46
+ # Beware that turning transactions off will leave data in your database
47
+ # after each scenario, which can lead to hard-to-debug failures in
48
48
  # subsequent scenarios. If you do this, we recommend you create a Before
49
49
  # block that will explicitly put your database in a known state.
50
50
  Cucumber::Rails::World.use_transactional_fixtures = true
@@ -58,14 +58,14 @@ if defined?(ActiveRecord::Base)
58
58
  end
59
59
  end
60
60
 
61
- After do
61
+ After do
62
62
  `rm #{Rails.root.to_s}/db/america.sqlite3`
63
63
  `rm #{Rails.root.to_s}/db/asia.sqlite3`
64
64
  `rm #{Rails.root.to_s}/db/development.sqlite3`
65
65
  `rm #{Rails.root.to_s}/db/europe.sqlite3`
66
66
  end
67
67
 
68
- Before do
68
+ Before do
69
69
  `rm #{Rails.root.to_s}/db/america.sqlite3`
70
70
  `rm #{Rails.root.to_s}/db/asia.sqlite3`
71
71
  `rm #{Rails.root.to_s}/db/development.sqlite3`
@@ -1,6 +1,6 @@
1
1
  # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
- # It is recommended to regenerate this file in the future when you upgrade to a
3
- # newer version of cucumber-rails. Consider adding your own code to a new file
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
@@ -150,7 +150,7 @@ var Effect = {
150
150
  toggle: function(element, effect, options) {
151
151
  element = $(element);
152
152
  effect = (effect || 'appear').toLowerCase();
153
-
153
+
154
154
  return Effect[ Effect.PAIRS[ effect ][ element.visible() ? 1 : 0 ] ](element, Object.extend({
155
155
  queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
156
156
  }, options || {}));
@@ -1,18 +1,19 @@
1
1
  mysql: &mysql
2
- adapter: <%= 'mysql2' %>
2
+ adapter: mysql
3
+ username: <%= ENV['MYSQL_USER'] || 'root' %>
3
4
  host: localhost
4
5
 
5
6
  octopus:
6
7
  shards:
7
8
  alone_shard:
8
- database: octopus_shard5
9
+ database: octopus_shard_5
9
10
  <<: *mysql
10
11
 
11
12
  postgresql_shard:
12
13
  adapter: postgresql
13
- username: <%= ENV['POSTGRES_USER'] || 'postgres'%>
14
+ username: <%= ENV['POSTGRES_USER'] || 'postgres' %>
14
15
  password:
15
- database: octopus_shard1
16
+ database: octopus_shard_1
16
17
  encoding: unicode
17
18
 
18
19
  sqlite_shard:
@@ -21,37 +22,38 @@ octopus:
21
22
 
22
23
  history_shards:
23
24
  aug2009:
24
- database: octopus_shard2
25
+ database: octopus_shard_2
25
26
  <<: *mysql
26
27
  aug2010:
27
- database: octopus_shard3
28
+ database: octopus_shard_3
28
29
  <<: *mysql
29
30
  aug2011:
30
- database: octopus_shard4
31
+ database: octopus_shard_4
31
32
  <<: *mysql
32
33
 
33
34
  country_shards:
34
35
  canada:
35
- database: octopus_shard2
36
+ database: octopus_shard_2
36
37
  <<: *mysql
37
38
  brazil:
38
- database: octopus_shard3
39
+ database: octopus_shard_3
39
40
  <<: *mysql
40
41
  russia:
41
- database: octopus_shard4
42
+ database: octopus_shard_4
42
43
  <<: *mysql
43
44
 
45
+ protocol_shard: postgres://<%= ENV['POSTGRES_USER'] || 'postgres' %>@localhost:5432/octopus_shard_2
44
46
 
45
47
  production_raise_error:
46
48
  shards:
47
49
  history_shards:
48
50
  duplicated_shard_name:
49
- database: octopus_shard5
51
+ database: octopus_shard_5
50
52
  <<: *mysql
51
53
 
52
54
  country_shards:
53
55
  duplicated_shard_name:
54
- database: octopus_shard4
56
+ database: octopus_shard_4
55
57
  <<: *mysql
56
58
 
57
59
  production_replicated:
@@ -60,16 +62,16 @@ production_replicated:
60
62
 
61
63
  shards:
62
64
  slave1:
63
- database: octopus_shard2
65
+ database: octopus_shard_2
64
66
  <<: *mysql
65
67
  slave2:
66
- database: octopus_shard3
68
+ database: octopus_shard_3
67
69
  <<: *mysql
68
70
  slave3:
69
- database: octopus_shard4
71
+ database: octopus_shard_4
70
72
  <<: *mysql
71
73
  slave4:
72
- database: octopus_shard5
74
+ database: octopus_shard_5
73
75
  <<: *mysql
74
76
 
75
77
 
@@ -77,16 +79,16 @@ production_fully_replicated:
77
79
  replicated: true
78
80
  shards:
79
81
  slave1:
80
- database: octopus_shard2
82
+ database: octopus_shard_2
81
83
  <<: *mysql
82
84
  slave2:
83
- database: octopus_shard3
85
+ database: octopus_shard_3
84
86
  <<: *mysql
85
87
  slave3:
86
- database: octopus_shard4
88
+ database: octopus_shard_4
87
89
  <<: *mysql
88
90
  slave4:
89
- database: octopus_shard5
91
+ database: octopus_shard_5
90
92
  <<: *mysql
91
93
 
92
94
  octopus_rails:
@@ -98,32 +100,40 @@ octopus_rails:
98
100
 
99
101
  staging:
100
102
  slave1:
101
- database: octopus_shard2
103
+ database: octopus_shard_2
102
104
  <<: *mysql
103
105
  slave2:
104
- database: octopus_shard3
106
+ database: octopus_shard_3
105
107
  <<: *mysql
106
108
 
107
109
  production:
108
110
  slave3:
109
- database: octopus_shard4
111
+ database: octopus_shard_4
110
112
  <<: *mysql
111
113
  slave4:
112
- database: octopus_shard5
114
+ database: octopus_shard_5
113
115
  <<: *mysql
114
116
 
115
117
  not_entire_sharded:
116
118
  entire_sharded: false
117
119
  shards:
118
120
  europe:
119
- database: octopus_shard2
121
+ database: octopus_shard_2
120
122
  <<: *mysql
121
123
  canada:
122
- database: octopus_shard3
124
+ database: octopus_shard_3
123
125
  <<: *mysql
124
126
  brazil:
125
- database: octopus_shard4
127
+ database: octopus_shard_4
126
128
  <<: *mysql
127
129
  russia:
128
- database: octopus_shard5
130
+ database: octopus_shard_5
129
131
  <<: *mysql
132
+
133
+ modify_config:
134
+ replicated: true
135
+ shards:
136
+ modify_config_read:
137
+ adapter: modify_config
138
+ database: octopus_shard_1
139
+ host: localhost
@@ -1,6 +1,6 @@
1
1
  class AddFieldInAllSlaves < ActiveRecord::Migration
2
2
  using(:slave1, :slave2, :slave3, :slave4)
3
-
3
+
4
4
  def self.up
5
5
  Cat.create!(:name => "Slaves")
6
6
  end
@@ -4,7 +4,7 @@ class CreateUsersUsingBlock < ActiveRecord::Migration
4
4
  User.create!(:name => "UsingBlock1")
5
5
  User.create!(:name => "UsingBlock2")
6
6
  end
7
-
7
+
8
8
  Octopus.using(:canada) do
9
9
  User.create!(:name => "UsingCanada")
10
10
  User.create!(:name => "UsingCanada2")
@@ -15,7 +15,7 @@ class CreateUsersUsingBlock < ActiveRecord::Migration
15
15
  Octopus.using(:brazil) do
16
16
  User.delete_all()
17
17
  end
18
-
18
+
19
19
  Octopus.using(:canada) do
20
20
  User.delete_all()
21
21
  end
@@ -1,11 +1,11 @@
1
1
  class CreateUsersUsingBlockAndUsing < ActiveRecord::Migration
2
2
  using(:brazil)
3
-
3
+
4
4
  def self.up
5
5
  Octopus.using(:canada) do
6
6
  User.create!(:name => "Canada")
7
7
  end
8
-
8
+
9
9
  User.create!(:name => "Brazil")
10
10
  end
11
11
 
@@ -0,0 +1,11 @@
1
+ class CreateUsersOnShardsOfAGroupWithVersions < ActiveRecord::Migration
2
+ using_group(:country_shards)
3
+
4
+ def self.up
5
+ User.create!(:name => "Group")
6
+ end
7
+
8
+ def self.down
9
+ User.delete_all()
10
+ end
11
+ end
@@ -1,4 +1,4 @@
1
- class CreateUsersOnMaster < ActiveRecord::Migration
1
+ class CreateUsersOnMaster < ActiveRecord::Migration
2
2
  def self.up
3
3
  User.create!(:name => "Master")
4
4
  end
@@ -1,6 +1,6 @@
1
1
  class CreateUsersOnCanada < ActiveRecord::Migration
2
2
  using(:canada)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Sharding")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class CreateUsersOnBothShards < ActiveRecord::Migration
2
2
  using(:brazil, :canada)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Both")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class CreateUsersOnShardsOfAGroup < ActiveRecord::Migration
2
2
  using_group(:country_shards)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Group")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class CreateUsersOnMultiplesGroups < ActiveRecord::Migration
2
2
  using_group('country_shards', 'history_shards')
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "MultipleGroup")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class RaiseExceptionWithInvalidShardName < ActiveRecord::Migration
2
2
  using(:amazing_shard)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Error")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class RaiseExceptionWithInvalidMultipleShardNames < ActiveRecord::Migration
2
2
  using(:brazil, :invalid_shard)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Error")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class RaiseExceptionWithInvalidGroupName < ActiveRecord::Migration
2
2
  using_group(:invalid_group)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Error")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class RaiseExceptionWithMultipleInvalidGroupNames < ActiveRecord::Migration
2
2
  using_group(:country_shards,:invalid_group)
3
-
3
+
4
4
  def self.up
5
5
  User.create!(:name => "Error")
6
6
  end
@@ -1,13 +1,13 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
- describe Octopus::Association do
3
+ describe Octopus::Association, :shards => [:brazil, :master, :canada] do
4
4
  describe "when you have a 1 x 1 relationship" do
5
5
  before(:each) do
6
6
  @computer_brazil = Computer.using(:brazil).create!(:name => "Computer Brazil")
7
7
  @computer_master = Computer.create!(:name => "Computer Brazil")
8
8
  @keyboard_brazil = Keyboard.using(:brazil).create!(:name => "Keyboard Brazil", :computer => @computer_brazil)
9
9
  @keyboard_master = Keyboard.create!(:name => "Keyboard Master", :computer => @computer_master)
10
- end
10
+ end
11
11
 
12
12
  it "should find the models" do
13
13
  @keyboard_master.computer.should == @computer_master
@@ -23,7 +23,7 @@ describe Octopus::Association do
23
23
  @keyboard_brazil.computer_id.should == new_computer_brazil.id
24
24
  @keyboard_brazil.computer.should == new_computer_brazil
25
25
  new_computer_brazil.save()
26
- new_computer_brazil.reload
26
+ new_computer_brazil.reload
27
27
  new_computer_brazil.keyboard.should == @keyboard_brazil
28
28
  end
29
29
 
@@ -46,6 +46,17 @@ describe Octopus::Association do
46
46
  k.computer_id.should == c.id
47
47
  k.computer.should == c
48
48
  end
49
+
50
+ if Octopus.rails3?
51
+ it "should include models" do
52
+ c = Computer.using(:brazil).create!(:name => "Computer Brazil")
53
+ k = c.create_keyboard(:name => "Building keyboard")
54
+ c.save()
55
+ k.save()
56
+
57
+ Computer.includes(:keyboard).find(c.id).should == c
58
+ end
59
+ end
49
60
  end
50
61
 
51
62
  describe "when you have a N x N reliationship" do
@@ -56,7 +67,7 @@ describe Octopus::Association do
56
67
  @permission_master = Permission.using(:master).create!(:name => "Master Permission")
57
68
  @brazil_role.permissions << @permission_brazil
58
69
  @brazil_role.save()
59
- Client.using(:master).create!(:name => "teste")
70
+ Client.using(:master).create!(:name => "teste")
60
71
  end
61
72
 
62
73
  it "should find all models in the specified shard" do
@@ -122,12 +133,12 @@ describe Octopus::Association do
122
133
 
123
134
  it "create" do
124
135
  role = @permission_brazil_2.roles.create(:name => "Builded Role")
125
- @permission_brazil_2.roles.to_set.should == [role].to_set
136
+ @permission_brazil_2.roles.to_set.should == [role].to_set
126
137
  end
127
138
 
128
139
  it "create" do
129
140
  role = @permission_brazil_2.roles.create!(:name => "Builded Role")
130
- @permission_brazil_2.roles.to_set.should == [role].to_set
141
+ @permission_brazil_2.roles.to_set.should == [role].to_set
131
142
  end
132
143
 
133
144
  it "count" do
@@ -163,37 +174,37 @@ describe Octopus::Association do
163
174
 
164
175
  it "delete_all" do
165
176
  role = @permission_brazil_2.roles.create(:name => "Builded Role")
166
- @permission_brazil_2.roles.empty?.should be_false
167
- @permission_brazil_2.roles.delete_all
177
+ @permission_brazil_2.roles.empty?.should be_false
178
+ @permission_brazil_2.roles.delete_all
168
179
  @permission_brazil_2.roles.empty?.should be_true
169
180
  end
170
181
 
171
182
  it "destroy_all" do
172
183
  role = @permission_brazil_2.roles.create(:name => "Builded Role")
173
- @permission_brazil_2.roles.empty?.should be_false
174
- @permission_brazil_2.roles.destroy_all
184
+ @permission_brazil_2.roles.empty?.should be_false
185
+ @permission_brazil_2.roles.destroy_all
175
186
  @permission_brazil_2.roles.empty?.should be_true
176
187
  end
177
188
 
178
189
  it "find" do
179
190
  role = @permission_brazil_2.roles.create(:name => "Builded Role")
180
191
  @permission_brazil_2.roles.find(:first).should == role
181
- @permission_brazil_2.roles.destroy_all
192
+ @permission_brazil_2.roles.destroy_all
182
193
  @permission_brazil_2.roles.find(:first).should be_nil
183
194
  end
184
195
 
185
196
  it "exists?" do
186
197
  role = @permission_brazil_2.roles.create(:name => "Builded Role")
187
198
  @permission_brazil_2.roles.exists?(role).should be_true
188
- @permission_brazil_2.roles.destroy_all
189
- @permission_brazil_2.roles.exists?(role).should be_false
199
+ @permission_brazil_2.roles.destroy_all
200
+ @permission_brazil_2.roles.exists?(role).should be_false
190
201
  end
191
202
 
192
203
  it "clear" do
193
204
  role = @permission_brazil_2.roles.create(:name => "Builded Role")
194
- @permission_brazil_2.roles.empty?.should be_false
195
- @permission_brazil_2.roles.clear
196
- @permission_brazil_2.roles.empty?.should be_true
205
+ @permission_brazil_2.roles.empty?.should be_false
206
+ @permission_brazil_2.roles.clear
207
+ @permission_brazil_2.roles.empty?.should be_true
197
208
  end
198
209
 
199
210
  it "delete" do
@@ -277,12 +288,12 @@ describe Octopus::Association do
277
288
 
278
289
  it "create" do
279
290
  role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
280
- @new_brazil_programmer.projects.to_set.should == [role].to_set
291
+ @new_brazil_programmer.projects.to_set.should == [role].to_set
281
292
  end
282
293
 
283
294
  it "create" do
284
295
  role = @new_brazil_programmer.projects.create!(:name => "New VB App :-/")
285
- @new_brazil_programmer.projects.to_set.should == [role].to_set
296
+ @new_brazil_programmer.projects.to_set.should == [role].to_set
286
297
  end
287
298
 
288
299
  it "count" do
@@ -318,37 +329,37 @@ describe Octopus::Association do
318
329
 
319
330
  it "delete_all" do
320
331
  role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
321
- @new_brazil_programmer.projects.empty?.should be_false
322
- @new_brazil_programmer.projects.delete_all
332
+ @new_brazil_programmer.projects.empty?.should be_false
333
+ @new_brazil_programmer.projects.delete_all
323
334
  @new_brazil_programmer.projects.empty?.should be_true
324
335
  end
325
336
 
326
337
  it "destroy_all" do
327
338
  role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
328
- @new_brazil_programmer.projects.empty?.should be_false
329
- @new_brazil_programmer.projects.destroy_all
339
+ @new_brazil_programmer.projects.empty?.should be_false
340
+ @new_brazil_programmer.projects.destroy_all
330
341
  @new_brazil_programmer.projects.empty?.should be_true
331
342
  end
332
343
 
333
344
  it "find" do
334
345
  role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
335
346
  @new_brazil_programmer.projects.find(:first).should == role
336
- @new_brazil_programmer.projects.destroy_all
347
+ @new_brazil_programmer.projects.destroy_all
337
348
  @new_brazil_programmer.projects.find(:first).should be_nil
338
349
  end
339
350
 
340
351
  it "exists?" do
341
352
  role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
342
353
  @new_brazil_programmer.projects.exists?(role).should be_true
343
- @new_brazil_programmer.projects.destroy_all
344
- @new_brazil_programmer.projects.exists?(role).should be_false
354
+ @new_brazil_programmer.projects.destroy_all
355
+ @new_brazil_programmer.projects.exists?(role).should be_false
345
356
  end
346
357
 
347
358
  it "clear" do
348
359
  role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
349
- @new_brazil_programmer.projects.empty?.should be_false
350
- @new_brazil_programmer.projects.clear
351
- @new_brazil_programmer.projects.empty?.should be_true
360
+ @new_brazil_programmer.projects.empty?.should be_false
361
+ @new_brazil_programmer.projects.clear
362
+ @new_brazil_programmer.projects.empty?.should be_true
352
363
  end
353
364
 
354
365
  it "delete" do
@@ -370,7 +381,7 @@ describe Octopus::Association do
370
381
  @item_brazil = Item.using(:brazil).create!(:name => "Brazil Item", :client => @brazil_client)
371
382
  @item_master = Item.create!(:name => "Master Item", :client => @master_client)
372
383
  @brazil_client = Client.using(:brazil).find_by_name("Brazil Client")
373
- Client.using(:master).create!(:name => "teste")
384
+ Client.using(:master).create!(:name => "teste")
374
385
  end
375
386
 
376
387
  it "should find all models in the specified shard" do
@@ -383,7 +394,7 @@ describe Octopus::Association do
383
394
  end
384
395
 
385
396
  it "should raise error if you try to add a record from a different shard" do
386
- lambda do
397
+ lambda do
387
398
  @brazil_client.items << Item.using(:canada).create!(:name => "New User")
388
399
  end.should raise_error("Association Error: Records are from different shards")
389
400
  end
@@ -410,7 +421,7 @@ describe Octopus::Association do
410
421
  describe "it should works when using" do
411
422
  before(:each) do
412
423
  @item_brazil_2 = Item.using(:brazil).create!(:name => "Brazil Item 2")
413
- @brazil_client.items.to_set.should == [@item_brazil].to_set
424
+ @brazil_client.items.to_set.should == [@item_brazil].to_set
414
425
  end
415
426
 
416
427
 
@@ -439,7 +450,7 @@ describe Octopus::Association do
439
450
 
440
451
  it "create" do
441
452
  item = @brazil_client.items.create(:name => "Builded Item")
442
- @brazil_client.items.to_set.should == [@item_brazil, item].to_set
453
+ @brazil_client.items.to_set.should == [@item_brazil, item].to_set
443
454
  end
444
455
 
445
456
  it "count" do
@@ -449,20 +460,20 @@ describe Octopus::Association do
449
460
  end
450
461
 
451
462
  it "size" do
452
- @brazil_client.items.size.should == 1
463
+ @brazil_client.items.size.should == 1
453
464
  item = @brazil_client.items.create(:name => "Builded Item")
454
- @brazil_client.items.size.should == 2
465
+ @brazil_client.items.size.should == 2
455
466
  end
456
467
 
457
468
  it "create!" do
458
469
  item = @brazil_client.items.create!(:name => "Builded Item")
459
- @brazil_client.items.to_set.should == [@item_brazil, item].to_set
470
+ @brazil_client.items.to_set.should == [@item_brazil, item].to_set
460
471
  end
461
472
 
462
473
  it "length" do
463
- @brazil_client.items.length.should == 1
474
+ @brazil_client.items.length.should == 1
464
475
  item = @brazil_client.items.create(:name => "Builded Item")
465
- @brazil_client.items.length.should == 2
476
+ @brazil_client.items.length.should == 2
466
477
  end
467
478
 
468
479
  it "empty?" do
@@ -482,37 +493,37 @@ describe Octopus::Association do
482
493
  end
483
494
 
484
495
  it "delete_all" do
485
- @brazil_client.items.empty?.should be_false
486
- @brazil_client.items.delete_all
496
+ @brazil_client.items.empty?.should be_false
497
+ @brazil_client.items.delete_all
487
498
  @brazil_client.items.empty?.should be_true
488
499
  end
489
500
 
490
501
  it "destroy_all" do
491
- @brazil_client.items.empty?.should be_false
492
- @brazil_client.items.destroy_all
502
+ @brazil_client.items.empty?.should be_false
503
+ @brazil_client.items.destroy_all
493
504
  @brazil_client.items.empty?.should be_true
494
505
  end
495
506
 
496
507
  it "find" do
497
508
  @brazil_client.items.find(:first).should == @item_brazil
498
- @brazil_client.items.destroy_all
509
+ @brazil_client.items.destroy_all
499
510
  @brazil_client.items.find(:first).should be_nil
500
511
  end
501
512
 
502
513
  it "exists?" do
503
514
  @brazil_client.items.exists?(@item_brazil).should be_true
504
- @brazil_client.items.destroy_all
505
- @brazil_client.items.exists?(@item_brazil).should be_false
515
+ @brazil_client.items.destroy_all
516
+ @brazil_client.items.exists?(@item_brazil).should be_false
506
517
  end
507
518
 
508
519
  it "uniq" do
509
- @brazil_client.items.uniq.should == [@item_brazil]
510
- end
520
+ @brazil_client.items.uniq.should == [@item_brazil]
521
+ end
511
522
 
512
523
  it "clear" do
513
- @brazil_client.items.empty?.should be_false
514
- @brazil_client.items.clear
515
- @brazil_client.items.empty?.should be_true
524
+ @brazil_client.items.empty?.should be_false
525
+ @brazil_client.items.clear
526
+ @brazil_client.items.empty?.should be_true
516
527
  end
517
528
  end
518
529
  end
@@ -524,7 +535,7 @@ describe Octopus::Association do
524
535
  @comment_brazil = Comment.using(:brazil).create!(:name => "Brazil Comment", :commentable => @brazil_client)
525
536
  @comment_master = Comment.create!(:name => "Master Comment", :commentable => @master_client)
526
537
  @brazil_client = Client.using(:brazil).find_by_name("Brazil Client")
527
- Client.using(:master).create!(:name => "teste")
538
+ Client.using(:master).create!(:name => "teste")
528
539
  end
529
540
 
530
541
  it "should find all models in the specified shard" do
@@ -549,7 +560,7 @@ describe Octopus::Association do
549
560
  describe "it should works when using" do
550
561
  before(:each) do
551
562
  @comment_brazil_2 = Comment.using(:brazil).create!(:name => "Brazil Comment 2")
552
- @brazil_client.comments.to_set.should == [@comment_brazil].to_set
563
+ @brazil_client.comments.to_set.should == [@comment_brazil].to_set
553
564
  end
554
565
 
555
566
  it "update_attributes" do
@@ -577,7 +588,7 @@ describe Octopus::Association do
577
588
 
578
589
  it "create" do
579
590
  comment = @brazil_client.comments.create(:name => "Builded Comment")
580
- @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
591
+ @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
581
592
  end
582
593
 
583
594
  it "count" do
@@ -587,20 +598,20 @@ describe Octopus::Association do
587
598
  end
588
599
 
589
600
  it "size" do
590
- @brazil_client.comments.size.should == 1
601
+ @brazil_client.comments.size.should == 1
591
602
  comment = @brazil_client.comments.create(:name => "Builded Comment")
592
- @brazil_client.comments.size.should == 2
603
+ @brazil_client.comments.size.should == 2
593
604
  end
594
605
 
595
606
  it "create!" do
596
607
  comment = @brazil_client.comments.create!(:name => "Builded Comment")
597
- @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
608
+ @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
598
609
  end
599
610
 
600
611
  it "length" do
601
- @brazil_client.comments.length.should == 1
612
+ @brazil_client.comments.length.should == 1
602
613
  comment = @brazil_client.comments.create(:name => "Builded Comment")
603
- @brazil_client.comments.length.should == 2
614
+ @brazil_client.comments.length.should == 2
604
615
  end
605
616
 
606
617
  it "empty?" do
@@ -620,38 +631,45 @@ describe Octopus::Association do
620
631
  end
621
632
 
622
633
  it "delete_all" do
623
- @brazil_client.comments.empty?.should be_false
624
- @brazil_client.comments.delete_all
634
+ @brazil_client.comments.empty?.should be_false
635
+ @brazil_client.comments.delete_all
625
636
  @brazil_client.comments.empty?.should be_true
626
637
  end
627
638
 
628
639
  it "destroy_all" do
629
- @brazil_client.comments.empty?.should be_false
630
- @brazil_client.comments.destroy_all
640
+ @brazil_client.comments.empty?.should be_false
641
+ @brazil_client.comments.destroy_all
631
642
  @brazil_client.comments.empty?.should be_true
632
643
  end
633
644
 
634
645
  it "find" do
635
646
  @brazil_client.comments.find(:first).should == @comment_brazil
636
- @brazil_client.comments.destroy_all
647
+ @brazil_client.comments.destroy_all
637
648
  @brazil_client.comments.find(:first).should be_nil
638
649
  end
639
650
 
640
651
  it "exists?" do
641
652
  @brazil_client.comments.exists?(@comment_brazil).should be_true
642
- @brazil_client.comments.destroy_all
643
- @brazil_client.comments.exists?(@comment_brazil).should be_false
653
+ @brazil_client.comments.destroy_all
654
+ @brazil_client.comments.exists?(@comment_brazil).should be_false
644
655
  end
645
656
 
646
657
  it "uniq" do
647
- @brazil_client.comments.uniq.should == [@comment_brazil]
648
- end
658
+ @brazil_client.comments.uniq.should == [@comment_brazil]
659
+ end
649
660
 
650
661
  it "clear" do
651
- @brazil_client.comments.empty?.should be_false
652
- @brazil_client.comments.clear
653
- @brazil_client.comments.empty?.should be_true
662
+ @brazil_client.comments.empty?.should be_false
663
+ @brazil_client.comments.clear
664
+ @brazil_client.comments.empty?.should be_true
654
665
  end
655
666
  end
656
667
  end
668
+
669
+ it "block" do
670
+ @brazil_role = Role.using(:brazil).create!(:name => "Brazil Role")
671
+ @brazil_role.permissions.build(:name => "ok").name.should == "ok"
672
+ @brazil_role.permissions.create(:name => "ok").name.should == "ok"
673
+ @brazil_role.permissions.create!(:name => "ok").name.should == "ok"
674
+ end
657
675
  end