ar-octopus 0.8.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/.rubocop.yml +46 -0
- data/.rubocop_todo.yml +56 -0
- data/.travis.yml +7 -12
- data/Appraisals +11 -4
- data/Gemfile +1 -1
- data/README.mkdn +138 -63
- data/Rakefile +23 -16
- data/ar-octopus.gemspec +23 -20
- data/gemfiles/rails42.gemfile +7 -0
- data/gemfiles/{rails32.gemfile → rails5.gemfile} +2 -2
- data/gemfiles/{rails4.gemfile → rails51.gemfile} +2 -2
- data/gemfiles/rails52.gemfile +7 -0
- data/lib/ar-octopus.rb +1 -1
- data/lib/octopus/{rails3/abstract_adapter.rb → abstract_adapter.rb} +4 -15
- data/lib/octopus/association.rb +8 -99
- data/lib/octopus/association_shard_tracking.rb +74 -0
- data/lib/octopus/collection_association.rb +17 -0
- data/lib/octopus/collection_proxy.rb +16 -0
- data/lib/octopus/exception.rb +4 -0
- data/lib/octopus/finder_methods.rb +8 -0
- data/lib/octopus/load_balancing/round_robin.rb +20 -0
- data/lib/octopus/load_balancing.rb +4 -0
- data/lib/octopus/{rails3/log_subscriber.rb → log_subscriber.rb} +6 -2
- data/lib/octopus/migration.rb +187 -110
- data/lib/octopus/model.rb +151 -131
- data/lib/octopus/persistence.rb +45 -0
- data/lib/octopus/proxy.rb +297 -232
- data/lib/octopus/proxy_config.rb +251 -0
- data/lib/octopus/query_cache_for_shards.rb +24 -0
- data/lib/octopus/railtie.rb +1 -3
- data/lib/octopus/relation_proxy.rb +70 -0
- data/lib/octopus/result_patch.rb +19 -0
- data/lib/octopus/scope_proxy.rb +54 -36
- data/lib/octopus/shard_tracking/attribute.rb +22 -0
- data/lib/octopus/shard_tracking/dynamic.rb +11 -0
- data/lib/octopus/shard_tracking.rb +46 -0
- data/lib/octopus/singular_association.rb +9 -0
- data/lib/octopus/slave_group.rb +13 -0
- data/lib/octopus/version.rb +1 -1
- data/lib/octopus.rb +125 -33
- data/lib/tasks/octopus.rake +2 -2
- data/sample_app/Gemfile +3 -3
- 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/lib/tasks/cucumber.rake +43 -44
- data/sample_app/spec/spec_helper.rb +3 -3
- data/spec/config/shards.yml +78 -0
- data/spec/migrations/10_create_users_using_replication.rb +4 -4
- data/spec/migrations/11_add_field_in_all_slaves.rb +4 -4
- data/spec/migrations/12_create_users_using_block.rb +8 -8
- data/spec/migrations/13_create_users_using_block_and_using.rb +5 -5
- data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +3 -3
- data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +3 -3
- data/spec/migrations/1_create_users_on_master.rb +4 -4
- data/spec/migrations/2_create_users_on_canada.rb +4 -4
- data/spec/migrations/3_create_users_on_both_shards.rb +4 -4
- data/spec/migrations/4_create_users_on_shards_of_a_group.rb +4 -4
- data/spec/migrations/5_create_users_on_multiples_groups.rb +3 -3
- data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +4 -4
- data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +4 -4
- data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +4 -4
- data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +5 -5
- data/spec/octopus/association_shard_tracking_spec.rb +1036 -0
- data/spec/octopus/collection_proxy_spec.rb +16 -0
- data/spec/octopus/load_balancing/round_robin_spec.rb +15 -0
- data/spec/octopus/log_subscriber_spec.rb +5 -5
- data/spec/octopus/migration_spec.rb +83 -49
- data/spec/octopus/model_spec.rb +544 -292
- data/spec/octopus/octopus_spec.rb +64 -31
- data/spec/octopus/proxy_spec.rb +145 -141
- data/spec/octopus/query_cache_for_shards_spec.rb +40 -0
- data/spec/octopus/relation_proxy_spec.rb +132 -0
- data/spec/octopus/replicated_slave_grouped_spec.rb +91 -0
- data/spec/octopus/replication_spec.rb +140 -65
- data/spec/octopus/scope_proxy_spec.rb +90 -10
- data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +55 -0
- data/spec/octopus/sharded_spec.rb +10 -10
- data/spec/spec_helper.rb +8 -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 +18 -17
- data/spec/support/octopus_helper.rb +32 -25
- 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 +112 -70
- data/.ruby-version +0 -1
- data/init.rb +0 -1
- data/lib/octopus/association_collection.rb +0 -49
- data/lib/octopus/has_and_belongs_to_many_association.rb +0 -17
- data/lib/octopus/rails3/persistence.rb +0 -39
- data/lib/octopus/rails3/singular_association.rb +0 -34
- data/rails/init.rb +0 -1
- data/spec/octopus/association_spec.rb +0 -712
@@ -1,712 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Octopus::Association, :shards => [:brazil, :master, :canada] do
|
4
|
-
describe "when you have a 1 x 1 relationship" do
|
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)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should find the models" do
|
13
|
-
@keyboard_master.computer.should == @computer_master
|
14
|
-
@keyboard_brazil.computer.should == @computer_brazil
|
15
|
-
end
|
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")
|
20
|
-
@keyboard_brazil.computer = new_computer_brazil
|
21
|
-
@keyboard_brazil.save()
|
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()
|
26
|
-
new_computer_brazil.reload
|
27
|
-
new_computer_brazil.keyboard.should == @keyboard_brazil
|
28
|
-
end
|
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
|
38
|
-
end
|
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
|
48
|
-
end
|
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()
|
55
|
-
|
56
|
-
Computer.using(:brazil).includes(:keyboard).find(c.id).should == c
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "when you have a N x N relationship" do
|
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")
|
66
|
-
@brazil_role.permissions << @permission_brazil
|
67
|
-
@brazil_role.save()
|
68
|
-
Client.using(:master).create!(:name => "teste")
|
69
|
-
end
|
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]
|
74
|
-
|
75
|
-
@brazil_role.permissions.first.should eq(@permission_brazil)
|
76
|
-
@brazil_role.permissions.last.should eq(@permission_brazil)
|
77
|
-
end
|
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]
|
82
|
-
|
83
|
-
@permission_brazil.roles.first.should eq(@brazil_role)
|
84
|
-
@permission_brazil.roles.last.should eq(@brazil_role)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should update the attribute for the item" do
|
88
|
-
new_brazil_role = Role.using(:brazil).create!(:name => "new Role")
|
89
|
-
@permission_brazil.roles = [new_brazil_role]
|
90
|
-
@permission_brazil.roles.should == [new_brazil_role]
|
91
|
-
@permission_brazil.save()
|
92
|
-
@permission_brazil.reload
|
93
|
-
@permission_brazil.role_ids.should == [new_brazil_role.id]
|
94
|
-
@permission_brazil.roles().should == [new_brazil_role]
|
95
|
-
end
|
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]
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "it should works when using" do
|
107
|
-
before(:each) do
|
108
|
-
@permission_brazil_2 = Permission.using(:brazil).create!(:name => "Brazil Item 2")
|
109
|
-
@role = Role.using(:brazil).create!(:name => "testes")
|
110
|
-
end
|
111
|
-
|
112
|
-
it "update_attributes" do
|
113
|
-
@permission_brazil_2.update_attributes(:role_ids => [@role.id])
|
114
|
-
@permission_brazil_2.roles.to_set.should == [@role].to_set
|
115
|
-
end
|
116
|
-
|
117
|
-
it "update_attribute" do
|
118
|
-
@permission_brazil_2.update_attribute(:role_ids, [@role.id])
|
119
|
-
@permission_brazil_2.roles.to_set.should == [@role].to_set
|
120
|
-
end
|
121
|
-
|
122
|
-
it "<<" do
|
123
|
-
@permission_brazil_2.roles << @role
|
124
|
-
@role.save()
|
125
|
-
@permission_brazil_2.save()
|
126
|
-
@permission_brazil_2.reload
|
127
|
-
@permission_brazil_2.roles.to_set.should == [@role].to_set
|
128
|
-
end
|
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
|
134
|
-
end
|
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
|
139
|
-
end
|
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
|
144
|
-
end
|
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
|
152
|
-
end
|
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
|
160
|
-
end
|
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
|
168
|
-
end
|
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
|
175
|
-
end
|
176
|
-
|
177
|
-
it "delete_all" do
|
178
|
-
role = @permission_brazil_2.roles.create(:name => "Builded Role")
|
179
|
-
@permission_brazil_2.roles.empty?.should be_false
|
180
|
-
@permission_brazil_2.roles.delete_all
|
181
|
-
@permission_brazil_2.roles.empty?.should be_true
|
182
|
-
end
|
183
|
-
|
184
|
-
it "destroy_all" do
|
185
|
-
role = @permission_brazil_2.roles.create(:name => "Builded Role")
|
186
|
-
@permission_brazil_2.roles.empty?.should be_false
|
187
|
-
@permission_brazil_2.roles.destroy_all
|
188
|
-
@permission_brazil_2.roles.empty?.should be_true
|
189
|
-
end
|
190
|
-
|
191
|
-
it "find" do
|
192
|
-
role = @permission_brazil_2.roles.create(:name => "Builded Role")
|
193
|
-
@permission_brazil_2.roles.first.should == role
|
194
|
-
@permission_brazil_2.roles.destroy_all
|
195
|
-
@permission_brazil_2.roles.first.should be_nil
|
196
|
-
end
|
197
|
-
|
198
|
-
it "exists?" do
|
199
|
-
role = @permission_brazil_2.roles.create(:name => "Builded Role")
|
200
|
-
@permission_brazil_2.roles.exists?(role).should be_true
|
201
|
-
@permission_brazil_2.roles.destroy_all
|
202
|
-
@permission_brazil_2.roles.exists?(role).should be_false
|
203
|
-
end
|
204
|
-
|
205
|
-
it "clear" do
|
206
|
-
role = @permission_brazil_2.roles.create(:name => "Builded Role")
|
207
|
-
@permission_brazil_2.roles.empty?.should be_false
|
208
|
-
@permission_brazil_2.roles.clear
|
209
|
-
@permission_brazil_2.roles.empty?.should be_true
|
210
|
-
end
|
211
|
-
|
212
|
-
it "delete" do
|
213
|
-
role = @permission_brazil_2.roles.create(:name => "Builded Role")
|
214
|
-
@permission_brazil_2.roles.empty?.should be_false
|
215
|
-
@permission_brazil_2.roles.delete(role)
|
216
|
-
@permission_brazil_2.reload
|
217
|
-
@role.reload
|
218
|
-
@role.permissions.should == []
|
219
|
-
@permission_brazil_2.roles.should == []
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe "when you have has_many :through" do
|
225
|
-
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")
|
229
|
-
@programmer.projects << @project
|
230
|
-
@programmer.save()
|
231
|
-
Project.using(:master).create!(:name => "Project Master")
|
232
|
-
end
|
233
|
-
|
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])
|
237
|
-
|
238
|
-
@programmer.projects.first.should eq(@project)
|
239
|
-
@programmer.projects.last.should eq(@project)
|
240
|
-
end
|
241
|
-
|
242
|
-
|
243
|
-
it "should update the attribute for the item" do
|
244
|
-
new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Joao")
|
245
|
-
@project.programmers = [new_brazil_programmer]
|
246
|
-
@project.programmers.should == [new_brazil_programmer]
|
247
|
-
@project.save()
|
248
|
-
@project.reload
|
249
|
-
@project.programmer_ids.should == [new_brazil_programmer.id]
|
250
|
-
@project.programmers().should == [new_brazil_programmer]
|
251
|
-
end
|
252
|
-
|
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]
|
260
|
-
end
|
261
|
-
|
262
|
-
describe "it should works when using" do
|
263
|
-
before(:each) do
|
264
|
-
@new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Jose")
|
265
|
-
@project = Project.using(:brazil).create!(:name => "VB Application :-(")
|
266
|
-
end
|
267
|
-
|
268
|
-
it "update_attributes" do
|
269
|
-
@new_brazil_programmer.update_attributes(:project_ids => [@project.id])
|
270
|
-
@new_brazil_programmer.projects.to_set.should == [@project].to_set
|
271
|
-
end
|
272
|
-
|
273
|
-
it "update_attribute" do
|
274
|
-
@new_brazil_programmer.update_attribute(:project_ids, [@project.id])
|
275
|
-
@new_brazil_programmer.projects.to_set.should == [@project].to_set
|
276
|
-
end
|
277
|
-
|
278
|
-
it "<<" do
|
279
|
-
@new_brazil_programmer.projects << @project
|
280
|
-
@project.save()
|
281
|
-
@new_brazil_programmer.save()
|
282
|
-
@new_brazil_programmer.reload
|
283
|
-
@new_brazil_programmer.projects.to_set.should == [@project].to_set
|
284
|
-
end
|
285
|
-
|
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
|
290
|
-
end
|
291
|
-
|
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
|
295
|
-
end
|
296
|
-
|
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
|
300
|
-
end
|
301
|
-
|
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
|
308
|
-
end
|
309
|
-
|
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
|
316
|
-
end
|
317
|
-
|
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
|
324
|
-
end
|
325
|
-
|
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
|
331
|
-
end
|
332
|
-
|
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
|
336
|
-
@new_brazil_programmer.projects.delete_all
|
337
|
-
@new_brazil_programmer.projects.empty?.should be_true
|
338
|
-
end
|
339
|
-
|
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
|
343
|
-
@new_brazil_programmer.projects.destroy_all
|
344
|
-
@new_brazil_programmer.projects.empty?.should be_true
|
345
|
-
end
|
346
|
-
|
347
|
-
it "find" do
|
348
|
-
role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
|
349
|
-
@new_brazil_programmer.projects.first.should == role
|
350
|
-
@new_brazil_programmer.projects.destroy_all
|
351
|
-
@new_brazil_programmer.projects.first.should be_nil
|
352
|
-
end
|
353
|
-
|
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
|
357
|
-
@new_brazil_programmer.projects.destroy_all
|
358
|
-
@new_brazil_programmer.projects.exists?(role).should be_false
|
359
|
-
end
|
360
|
-
|
361
|
-
it "clear" do
|
362
|
-
role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
|
363
|
-
@new_brazil_programmer.projects.empty?.should be_false
|
364
|
-
@new_brazil_programmer.projects.clear
|
365
|
-
@new_brazil_programmer.projects.empty?.should be_true
|
366
|
-
end
|
367
|
-
|
368
|
-
it "delete" do
|
369
|
-
role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
|
370
|
-
@new_brazil_programmer.projects.empty?.should be_false
|
371
|
-
@new_brazil_programmer.projects.delete(role)
|
372
|
-
@new_brazil_programmer.reload
|
373
|
-
@project.reload
|
374
|
-
@project.programmers.should == []
|
375
|
-
@new_brazil_programmer.projects.should == []
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
describe "when you have a 1 x N relationship" do
|
381
|
-
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")
|
388
|
-
end
|
389
|
-
|
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])
|
393
|
-
|
394
|
-
@brazil_client.items.last.should eq(@item_brazil)
|
395
|
-
@brazil_client.items.first.should eq(@item_brazil)
|
396
|
-
end
|
397
|
-
|
398
|
-
it "should finds the client that the item belongs" do
|
399
|
-
@item_brazil.client.should == @brazil_client
|
400
|
-
end
|
401
|
-
|
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")
|
406
|
-
end
|
407
|
-
|
408
|
-
it "should update the attribute for the item" do
|
409
|
-
new_brazil_client = Client.using(:brazil).create!(:name => "new Client")
|
410
|
-
@item_brazil.client = new_brazil_client
|
411
|
-
@item_brazil.client.should == new_brazil_client
|
412
|
-
@item_brazil.save()
|
413
|
-
@item_brazil.reload
|
414
|
-
@item_brazil.client_id.should == new_brazil_client.id
|
415
|
-
@item_brazil.client().should == new_brazil_client
|
416
|
-
end
|
417
|
-
|
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]
|
425
|
-
end
|
426
|
-
|
427
|
-
context "when calling methods on a collection generated by an association" do
|
428
|
-
let(:collection) { @brazil_client.items }
|
429
|
-
before :each do
|
430
|
-
@brazil_client.items.create(:name => 'Brazil Item #2')
|
431
|
-
end
|
432
|
-
|
433
|
-
it "can call collection indexes directly without resetting the collection's current_shard" do
|
434
|
-
last_item = collection[1]
|
435
|
-
collection.length.should == 2
|
436
|
-
collection.should eq([ collection[0], last_item ])
|
437
|
-
end
|
438
|
-
|
439
|
-
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 ])
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
describe "it should works when using" do
|
447
|
-
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
|
450
|
-
end
|
451
|
-
|
452
|
-
|
453
|
-
it "update_attributes" do
|
454
|
-
@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
|
456
|
-
end
|
457
|
-
|
458
|
-
it "update_attribute" do
|
459
|
-
@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
|
461
|
-
end
|
462
|
-
|
463
|
-
it "<<" do
|
464
|
-
@brazil_client.items << @item_brazil_2
|
465
|
-
@brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
|
466
|
-
end
|
467
|
-
|
468
|
-
it "all" do
|
469
|
-
item = @brazil_client.items.build(:name => "Builded Item")
|
470
|
-
item.save()
|
471
|
-
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
|
474
|
-
end
|
475
|
-
|
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
|
480
|
-
end
|
481
|
-
|
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
|
485
|
-
end
|
486
|
-
|
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
|
491
|
-
end
|
492
|
-
|
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
|
497
|
-
end
|
498
|
-
|
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
|
502
|
-
end
|
503
|
-
|
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
|
508
|
-
end
|
509
|
-
|
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
|
514
|
-
end
|
515
|
-
|
516
|
-
it "delete" do
|
517
|
-
@brazil_client.items.empty?.should be_false
|
518
|
-
@brazil_client.items.delete(@item_brazil)
|
519
|
-
@brazil_client.reload
|
520
|
-
@item_brazil.reload
|
521
|
-
@item_brazil.client.should be_nil
|
522
|
-
@brazil_client.items.should == []
|
523
|
-
@brazil_client.items.empty?.should be_true
|
524
|
-
end
|
525
|
-
|
526
|
-
it "delete_all" do
|
527
|
-
@brazil_client.items.empty?.should be_false
|
528
|
-
@brazil_client.items.delete_all
|
529
|
-
@brazil_client.items.empty?.should be_true
|
530
|
-
end
|
531
|
-
|
532
|
-
it "destroy_all" do
|
533
|
-
@brazil_client.items.empty?.should be_false
|
534
|
-
@brazil_client.items.destroy_all
|
535
|
-
@brazil_client.items.empty?.should be_true
|
536
|
-
end
|
537
|
-
|
538
|
-
it "find" do
|
539
|
-
@brazil_client.items.first.should == @item_brazil
|
540
|
-
@brazil_client.items.destroy_all
|
541
|
-
@brazil_client.items.first.should be_nil
|
542
|
-
end
|
543
|
-
|
544
|
-
it "exists?" do
|
545
|
-
@brazil_client.items.exists?(@item_brazil).should be_true
|
546
|
-
@brazil_client.items.destroy_all
|
547
|
-
@brazil_client.items.exists?(@item_brazil).should be_false
|
548
|
-
end
|
549
|
-
|
550
|
-
it "uniq" do
|
551
|
-
@brazil_client.items.uniq.should == [@item_brazil]
|
552
|
-
end
|
553
|
-
|
554
|
-
it "clear" do
|
555
|
-
@brazil_client.items.empty?.should be_false
|
556
|
-
@brazil_client.items.clear
|
557
|
-
@brazil_client.items.empty?.should be_true
|
558
|
-
end
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
describe "when you have a 1 x N polymorphic relationship" do
|
563
|
-
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")
|
570
|
-
end
|
571
|
-
|
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]
|
575
|
-
end
|
576
|
-
|
577
|
-
it "should finds the client that the comment belongs" do
|
578
|
-
@comment_brazil.commentable.should == @brazil_client
|
579
|
-
end
|
580
|
-
|
581
|
-
it "should update the attribute for the comment" do
|
582
|
-
new_brazil_client = Client.using(:brazil).create!(:name => "new Client")
|
583
|
-
@comment_brazil.commentable = new_brazil_client
|
584
|
-
@comment_brazil.commentable.should == new_brazil_client
|
585
|
-
@comment_brazil.save()
|
586
|
-
@comment_brazil.reload
|
587
|
-
@comment_brazil.commentable_id.should == new_brazil_client.id
|
588
|
-
@comment_brazil.commentable().should == new_brazil_client
|
589
|
-
end
|
590
|
-
|
591
|
-
describe "it should works when using" do
|
592
|
-
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
|
595
|
-
end
|
596
|
-
|
597
|
-
it "update_attributes" do
|
598
|
-
@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
|
600
|
-
end
|
601
|
-
|
602
|
-
it "update_attribute" do
|
603
|
-
@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
|
605
|
-
end
|
606
|
-
|
607
|
-
it "<<" do
|
608
|
-
@brazil_client.comments << @comment_brazil_2
|
609
|
-
@brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
|
610
|
-
end
|
611
|
-
|
612
|
-
it "all" do
|
613
|
-
comment = @brazil_client.comments.build(:name => "Builded Comment")
|
614
|
-
comment.save()
|
615
|
-
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
|
618
|
-
end
|
619
|
-
|
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
|
624
|
-
end
|
625
|
-
|
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
|
629
|
-
end
|
630
|
-
|
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
|
635
|
-
end
|
636
|
-
|
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
|
641
|
-
end
|
642
|
-
|
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
|
646
|
-
end
|
647
|
-
|
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
|
652
|
-
end
|
653
|
-
|
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
|
658
|
-
end
|
659
|
-
|
660
|
-
it "delete" do
|
661
|
-
@brazil_client.comments.empty?.should be_false
|
662
|
-
@brazil_client.comments.delete(@comment_brazil)
|
663
|
-
@brazil_client.reload
|
664
|
-
@comment_brazil.reload
|
665
|
-
@comment_brazil.commentable.should be_nil
|
666
|
-
@brazil_client.comments.should == []
|
667
|
-
@brazil_client.comments.empty?.should be_true
|
668
|
-
end
|
669
|
-
|
670
|
-
it "delete_all" do
|
671
|
-
@brazil_client.comments.empty?.should be_false
|
672
|
-
@brazil_client.comments.delete_all
|
673
|
-
@brazil_client.comments.empty?.should be_true
|
674
|
-
end
|
675
|
-
|
676
|
-
it "destroy_all" do
|
677
|
-
@brazil_client.comments.empty?.should be_false
|
678
|
-
@brazil_client.comments.destroy_all
|
679
|
-
@brazil_client.comments.empty?.should be_true
|
680
|
-
end
|
681
|
-
|
682
|
-
it "find" do
|
683
|
-
@brazil_client.comments.first.should == @comment_brazil
|
684
|
-
@brazil_client.comments.destroy_all
|
685
|
-
@brazil_client.comments.first.should be_nil
|
686
|
-
end
|
687
|
-
|
688
|
-
it "exists?" do
|
689
|
-
@brazil_client.comments.exists?(@comment_brazil).should be_true
|
690
|
-
@brazil_client.comments.destroy_all
|
691
|
-
@brazil_client.comments.exists?(@comment_brazil).should be_false
|
692
|
-
end
|
693
|
-
|
694
|
-
it "uniq" do
|
695
|
-
@brazil_client.comments.uniq.should == [@comment_brazil]
|
696
|
-
end
|
697
|
-
|
698
|
-
it "clear" do
|
699
|
-
@brazil_client.comments.empty?.should be_false
|
700
|
-
@brazil_client.comments.clear
|
701
|
-
@brazil_client.comments.empty?.should be_true
|
702
|
-
end
|
703
|
-
end
|
704
|
-
end
|
705
|
-
|
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"
|
711
|
-
end
|
712
|
-
end
|