activerecord-turntable 3.0.0.alpha3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.rubocop.yml +18 -0
  4. data/.rubocop_todo.yml +153 -0
  5. data/.travis.yml +20 -4
  6. data/CHANGELOG.md +32 -0
  7. data/Guardfile +2 -2
  8. data/README.md +68 -14
  9. data/Rakefile +42 -0
  10. data/activerecord-turntable.gemspec +13 -3
  11. data/gemfiles/rails_edge.gemfile +8 -0
  12. data/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +3 -1
  13. data/lib/active_record/turntable/active_record_ext/activerecord_import_ext.rb +5 -7
  14. data/lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb +2 -2
  15. data/lib/active_record/turntable/active_record_ext/association.rb +3 -3
  16. data/lib/active_record/turntable/active_record_ext/clever_load.rb +2 -2
  17. data/lib/active_record/turntable/active_record_ext/database_tasks.rb +10 -8
  18. data/lib/active_record/turntable/active_record_ext/fixtures.rb +15 -13
  19. data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +6 -0
  20. data/lib/active_record/turntable/active_record_ext/persistence.rb +25 -23
  21. data/lib/active_record/turntable/active_record_ext/schema_dumper.rb +8 -75
  22. data/lib/active_record/turntable/algorithm/range_algorithm.rb +6 -7
  23. data/lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb +6 -7
  24. data/lib/active_record/turntable/base.rb +2 -17
  25. data/lib/active_record/turntable/cluster_helper_methods.rb +7 -4
  26. data/lib/active_record/turntable/connection_proxy.rb +4 -2
  27. data/lib/active_record/turntable/migration.rb +3 -5
  28. data/lib/active_record/turntable/mixer.rb +20 -19
  29. data/lib/active_record/turntable/pool_proxy.rb +20 -14
  30. data/lib/active_record/turntable/query_cache.rb +1 -1
  31. data/lib/active_record/turntable/railties/databases.rake +12 -12
  32. data/lib/active_record/turntable/seq_shard.rb +1 -1
  33. data/lib/active_record/turntable/sequencer/barrage.rb +3 -2
  34. data/lib/active_record/turntable/sequencer.rb +33 -29
  35. data/lib/active_record/turntable/shard.rb +8 -8
  36. data/lib/active_record/turntable/sharding_condition.rb +14 -14
  37. data/lib/active_record/turntable/sql_tree_patch.rb +7 -3
  38. data/lib/active_record/turntable/util.rb +4 -2
  39. data/lib/active_record/turntable/version.rb +1 -1
  40. data/lib/active_record/turntable.rb +6 -5
  41. data/lib/activerecord-turntable.rb +1 -0
  42. metadata +120 -101
  43. data/lib/active_record/turntable/helpers/test_helper.rb +0 -25
  44. data/lib/active_record/turntable/helpers.rb +0 -9
  45. data/spec/active_record/turntable/active_record_ext/association_preloader_spec.rb +0 -78
  46. data/spec/active_record/turntable/active_record_ext/association_spec.rb +0 -81
  47. data/spec/active_record/turntable/active_record_ext/clever_load_spec.rb +0 -72
  48. data/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb +0 -27
  49. data/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb +0 -28
  50. data/spec/active_record/turntable/active_record_ext/migration_spec.rb +0 -38
  51. data/spec/active_record/turntable/active_record_ext/persistence_spec.rb +0 -211
  52. data/spec/active_record/turntable/active_record_ext/sequencer_spec.rb +0 -22
  53. data/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb +0 -34
  54. data/spec/active_record/turntable/algorithm/modulo_algorithm_spec.rb +0 -34
  55. data/spec/active_record/turntable/algorithm/range_algorithm_spec.rb +0 -34
  56. data/spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb +0 -34
  57. data/spec/active_record/turntable/algorithm_spec.rb +0 -100
  58. data/spec/active_record/turntable/base_spec.rb +0 -13
  59. data/spec/active_record/turntable/cluster_spec.rb +0 -48
  60. data/spec/active_record/turntable/config_spec.rb +0 -17
  61. data/spec/active_record/turntable/connection_proxy_spec.rb +0 -252
  62. data/spec/active_record/turntable/finder_spec.rb +0 -40
  63. data/spec/active_record/turntable/mixer/fader_spec.rb +0 -4
  64. data/spec/active_record/turntable/mixer_spec.rb +0 -112
  65. data/spec/active_record/turntable/query_cache_spec.rb +0 -28
  66. data/spec/active_record/turntable/sequencer/api_spec.rb +0 -38
  67. data/spec/active_record/turntable/sequencer/barrage_spec.rb +0 -22
  68. data/spec/active_record/turntable/sequencer/mysql_spec.rb +0 -22
  69. data/spec/active_record/turntable/shard_spec.rb +0 -21
  70. data/spec/active_record/turntable/sql_tree_patch_spec.rb +0 -34
  71. data/spec/active_record/turntable/transaction_spec.rb +0 -35
  72. data/spec/active_record/turntable_spec.rb +0 -30
  73. data/spec/config/database.yml +0 -35
  74. data/spec/config/turntable.yml +0 -56
  75. data/spec/fabricators/.gitkeep +0 -0
  76. data/spec/fabricators/turntable_fabricator.rb +0 -12
  77. data/spec/fixtures/cards.yml +0 -11
  78. data/spec/migrations/.gitkeep +0 -0
  79. data/spec/migrations/001_create_users.rb +0 -17
  80. data/spec/migrations/002_create_user_statuses.rb +0 -16
  81. data/spec/migrations/003_create_cards.rb +0 -14
  82. data/spec/migrations/004_create_cards_users.rb +0 -15
  83. data/spec/models/card.rb +0 -3
  84. data/spec/models/cards_user.rb +0 -10
  85. data/spec/models/cards_users_histories.rb +0 -7
  86. data/spec/models/events_users_history.rb +0 -7
  87. data/spec/models/user.rb +0 -7
  88. data/spec/models/user_status.rb +0 -6
  89. data/spec/spec_helper.rb +0 -38
  90. data/spec/support/matchers/be_saved_to.rb +0 -6
  91. data/spec/support/turntable_helper.rb +0 -30
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-turntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gussan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-03 00:00:00.000000000 Z
12
+ date: 2017-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -261,6 +261,20 @@ dependencies:
261
261
  - - ">="
262
262
  - !ruby/object:Gem::Version
263
263
  version: '0'
264
+ - !ruby/object:Gem::Dependency
265
+ name: rails
266
+ requirement: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - ">="
269
+ - !ruby/object:Gem::Version
270
+ version: '0'
271
+ type: :development
272
+ prerelease: false
273
+ version_requirements: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - ">="
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
264
278
  - !ruby/object:Gem::Dependency
265
279
  name: rake
266
280
  requirement: !ruby/object:Gem::Requirement
@@ -317,6 +331,34 @@ dependencies:
317
331
  - - ">="
318
332
  - !ruby/object:Gem::Version
319
333
  version: '0'
334
+ - !ruby/object:Gem::Dependency
335
+ name: rspec-parameterized
336
+ requirement: !ruby/object:Gem::Requirement
337
+ requirements:
338
+ - - ">="
339
+ - !ruby/object:Gem::Version
340
+ version: '0'
341
+ type: :development
342
+ prerelease: false
343
+ version_requirements: !ruby/object:Gem::Requirement
344
+ requirements:
345
+ - - ">="
346
+ - !ruby/object:Gem::Version
347
+ version: '0'
348
+ - !ruby/object:Gem::Dependency
349
+ name: rspec-rails
350
+ requirement: !ruby/object:Gem::Requirement
351
+ requirements:
352
+ - - ">="
353
+ - !ruby/object:Gem::Version
354
+ version: '0'
355
+ type: :development
356
+ prerelease: false
357
+ version_requirements: !ruby/object:Gem::Requirement
358
+ requirements:
359
+ - - ">="
360
+ - !ruby/object:Gem::Version
361
+ version: '0'
320
362
  - !ruby/object:Gem::Dependency
321
363
  name: rubocop
322
364
  requirement: !ruby/object:Gem::Requirement
@@ -373,6 +415,76 @@ dependencies:
373
415
  - - ">="
374
416
  - !ruby/object:Gem::Version
375
417
  version: '0'
418
+ - !ruby/object:Gem::Dependency
419
+ name: actionview
420
+ requirement: !ruby/object:Gem::Requirement
421
+ requirements:
422
+ - - ">="
423
+ - !ruby/object:Gem::Version
424
+ version: '0'
425
+ type: :development
426
+ prerelease: false
427
+ version_requirements: !ruby/object:Gem::Requirement
428
+ requirements:
429
+ - - ">="
430
+ - !ruby/object:Gem::Version
431
+ version: '0'
432
+ - !ruby/object:Gem::Dependency
433
+ name: bcrypt
434
+ requirement: !ruby/object:Gem::Requirement
435
+ requirements:
436
+ - - "~>"
437
+ - !ruby/object:Gem::Version
438
+ version: 3.1.11
439
+ type: :development
440
+ prerelease: false
441
+ version_requirements: !ruby/object:Gem::Requirement
442
+ requirements:
443
+ - - "~>"
444
+ - !ruby/object:Gem::Version
445
+ version: 3.1.11
446
+ - !ruby/object:Gem::Dependency
447
+ name: minitest
448
+ requirement: !ruby/object:Gem::Requirement
449
+ requirements:
450
+ - - "<"
451
+ - !ruby/object:Gem::Version
452
+ version: 5.3.4
453
+ type: :development
454
+ prerelease: false
455
+ version_requirements: !ruby/object:Gem::Requirement
456
+ requirements:
457
+ - - "<"
458
+ - !ruby/object:Gem::Version
459
+ version: 5.3.4
460
+ - !ruby/object:Gem::Dependency
461
+ name: mocha
462
+ requirement: !ruby/object:Gem::Requirement
463
+ requirements:
464
+ - - "~>"
465
+ - !ruby/object:Gem::Version
466
+ version: '0.14'
467
+ type: :development
468
+ prerelease: false
469
+ version_requirements: !ruby/object:Gem::Requirement
470
+ requirements:
471
+ - - "~>"
472
+ - !ruby/object:Gem::Version
473
+ version: '0.14'
474
+ - !ruby/object:Gem::Dependency
475
+ name: sqlite3
476
+ requirement: !ruby/object:Gem::Requirement
477
+ requirements:
478
+ - - "~>"
479
+ - !ruby/object:Gem::Version
480
+ version: 1.3.6
481
+ type: :development
482
+ prerelease: false
483
+ version_requirements: !ruby/object:Gem::Requirement
484
+ requirements:
485
+ - - "~>"
486
+ - !ruby/object:Gem::Version
487
+ version: 1.3.6
376
488
  description: ActiveRecord sharding extension
377
489
  email:
378
490
  executables: []
@@ -385,8 +497,10 @@ files:
385
497
  - ".coveralls.yml"
386
498
  - ".document"
387
499
  - ".gitignore"
500
+ - ".gitmodules"
388
501
  - ".rspec"
389
502
  - ".rubocop.yml"
503
+ - ".rubocop_todo.yml"
390
504
  - ".travis.yml"
391
505
  - CHANGELOG.md
392
506
  - Gemfile
@@ -396,6 +510,7 @@ files:
396
510
  - Rakefile
397
511
  - activerecord-turntable.gemspec
398
512
  - gemfiles/rails5_0.gemfile
513
+ - gemfiles/rails_edge.gemfile
399
514
  - lib/active_record/turntable.rb
400
515
  - lib/active_record/turntable/active_record_ext.rb
401
516
  - lib/active_record/turntable/active_record_ext/.gitkeep
@@ -429,8 +544,6 @@ files:
429
544
  - lib/active_record/turntable/connection_proxy.rb
430
545
  - lib/active_record/turntable/connection_proxy/mixable.rb
431
546
  - lib/active_record/turntable/error.rb
432
- - lib/active_record/turntable/helpers.rb
433
- - lib/active_record/turntable/helpers/test_helper.rb
434
547
  - lib/active_record/turntable/master_shard.rb
435
548
  - lib/active_record/turntable/migration.rb
436
549
  - lib/active_record/turntable/mixer.rb
@@ -459,53 +572,6 @@ files:
459
572
  - lib/generators/active_record/turntable/install_generator.rb
460
573
  - lib/generators/templates/turntable.yml
461
574
  - script/performance/algorithm
462
- - spec/active_record/turntable/active_record_ext/association_preloader_spec.rb
463
- - spec/active_record/turntable/active_record_ext/association_spec.rb
464
- - spec/active_record/turntable/active_record_ext/clever_load_spec.rb
465
- - spec/active_record/turntable/active_record_ext/fixture_set_spec.rb
466
- - spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb
467
- - spec/active_record/turntable/active_record_ext/migration_spec.rb
468
- - spec/active_record/turntable/active_record_ext/persistence_spec.rb
469
- - spec/active_record/turntable/active_record_ext/sequencer_spec.rb
470
- - spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb
471
- - spec/active_record/turntable/algorithm/modulo_algorithm_spec.rb
472
- - spec/active_record/turntable/algorithm/range_algorithm_spec.rb
473
- - spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
474
- - spec/active_record/turntable/algorithm_spec.rb
475
- - spec/active_record/turntable/base_spec.rb
476
- - spec/active_record/turntable/cluster_spec.rb
477
- - spec/active_record/turntable/config_spec.rb
478
- - spec/active_record/turntable/connection_proxy_spec.rb
479
- - spec/active_record/turntable/finder_spec.rb
480
- - spec/active_record/turntable/mixer/fader_spec.rb
481
- - spec/active_record/turntable/mixer_spec.rb
482
- - spec/active_record/turntable/query_cache_spec.rb
483
- - spec/active_record/turntable/sequencer/api_spec.rb
484
- - spec/active_record/turntable/sequencer/barrage_spec.rb
485
- - spec/active_record/turntable/sequencer/mysql_spec.rb
486
- - spec/active_record/turntable/shard_spec.rb
487
- - spec/active_record/turntable/sql_tree_patch_spec.rb
488
- - spec/active_record/turntable/transaction_spec.rb
489
- - spec/active_record/turntable_spec.rb
490
- - spec/config/database.yml
491
- - spec/config/turntable.yml
492
- - spec/fabricators/.gitkeep
493
- - spec/fabricators/turntable_fabricator.rb
494
- - spec/fixtures/cards.yml
495
- - spec/migrations/.gitkeep
496
- - spec/migrations/001_create_users.rb
497
- - spec/migrations/002_create_user_statuses.rb
498
- - spec/migrations/003_create_cards.rb
499
- - spec/migrations/004_create_cards_users.rb
500
- - spec/models/card.rb
501
- - spec/models/cards_user.rb
502
- - spec/models/cards_users_histories.rb
503
- - spec/models/events_users_history.rb
504
- - spec/models/user.rb
505
- - spec/models/user_status.rb
506
- - spec/spec_helper.rb
507
- - spec/support/matchers/be_saved_to.rb
508
- - spec/support/turntable_helper.rb
509
575
  homepage: https://github.com/drecom/activerecord-turntable
510
576
  licenses:
511
577
  - MIT
@@ -521,60 +587,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
521
587
  version: 2.2.2
522
588
  required_rubygems_version: !ruby/object:Gem::Requirement
523
589
  requirements:
524
- - - ">"
590
+ - - ">="
525
591
  - !ruby/object:Gem::Version
526
- version: 1.3.1
592
+ version: '0'
527
593
  requirements: []
528
594
  rubyforge_project: activerecord-turntable
529
595
  rubygems_version: 2.5.2
530
596
  signing_key:
531
597
  specification_version: 4
532
598
  summary: ActiveRecord sharding extension
533
- test_files:
534
- - spec/active_record/turntable/active_record_ext/association_preloader_spec.rb
535
- - spec/active_record/turntable/active_record_ext/association_spec.rb
536
- - spec/active_record/turntable/active_record_ext/clever_load_spec.rb
537
- - spec/active_record/turntable/active_record_ext/fixture_set_spec.rb
538
- - spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb
539
- - spec/active_record/turntable/active_record_ext/migration_spec.rb
540
- - spec/active_record/turntable/active_record_ext/persistence_spec.rb
541
- - spec/active_record/turntable/active_record_ext/sequencer_spec.rb
542
- - spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb
543
- - spec/active_record/turntable/algorithm/modulo_algorithm_spec.rb
544
- - spec/active_record/turntable/algorithm/range_algorithm_spec.rb
545
- - spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb
546
- - spec/active_record/turntable/algorithm_spec.rb
547
- - spec/active_record/turntable/base_spec.rb
548
- - spec/active_record/turntable/cluster_spec.rb
549
- - spec/active_record/turntable/config_spec.rb
550
- - spec/active_record/turntable/connection_proxy_spec.rb
551
- - spec/active_record/turntable/finder_spec.rb
552
- - spec/active_record/turntable/mixer/fader_spec.rb
553
- - spec/active_record/turntable/mixer_spec.rb
554
- - spec/active_record/turntable/query_cache_spec.rb
555
- - spec/active_record/turntable/sequencer/api_spec.rb
556
- - spec/active_record/turntable/sequencer/barrage_spec.rb
557
- - spec/active_record/turntable/sequencer/mysql_spec.rb
558
- - spec/active_record/turntable/shard_spec.rb
559
- - spec/active_record/turntable/sql_tree_patch_spec.rb
560
- - spec/active_record/turntable/transaction_spec.rb
561
- - spec/active_record/turntable_spec.rb
562
- - spec/config/database.yml
563
- - spec/config/turntable.yml
564
- - spec/fabricators/.gitkeep
565
- - spec/fabricators/turntable_fabricator.rb
566
- - spec/fixtures/cards.yml
567
- - spec/migrations/.gitkeep
568
- - spec/migrations/001_create_users.rb
569
- - spec/migrations/002_create_user_statuses.rb
570
- - spec/migrations/003_create_cards.rb
571
- - spec/migrations/004_create_cards_users.rb
572
- - spec/models/card.rb
573
- - spec/models/cards_user.rb
574
- - spec/models/cards_users_histories.rb
575
- - spec/models/events_users_history.rb
576
- - spec/models/user.rb
577
- - spec/models/user_status.rb
578
- - spec/spec_helper.rb
579
- - spec/support/matchers/be_saved_to.rb
580
- - spec/support/turntable_helper.rb
599
+ test_files: []
@@ -1,25 +0,0 @@
1
- module ActiveRecord::Turntable
2
- module Helpers
3
- module TestHelper
4
- # all shards
5
- def FabricateAll(name, overrides = {}, &block)
6
- obj = Fabrication::Fabricator.generate(name, {
7
- save: true,
8
- }, overrides, &block)
9
-
10
- default_pool = obj.class.connection_pool
11
- connection_pools = obj.class.connection_handler.instance_variable_get(:@connection_pools)
12
-
13
- ActiveRecord::Base.turntable_connections.each do |_conn_name, conn|
14
- new_obj = obj.dup
15
- connection_pools[new_obj.class.name] = conn
16
- new_obj.id = obj.id
17
- new_obj.send(:create)
18
- end
19
- obj
20
- ensure
21
- connection_pools[obj.class.name] = default_pool
22
- end
23
- end
24
- end
25
- end
@@ -1,9 +0,0 @@
1
- module ActiveRecord::Turntable
2
- module Helpers
3
- extend ActiveSupport::Autoload
4
-
5
- eager_autoload do
6
- autoload :TestHelper
7
- end
8
- end
9
- end
@@ -1,78 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ActiveRecord::Turntable::ActiveRecordExt::Association do
4
- before(:all) do
5
- reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
6
- end
7
-
8
- before(:each) do
9
- establish_connection_to(:test)
10
- truncate_shard
11
- end
12
-
13
- let!(:user) do
14
- user = User.new({ nickname: "user1" })
15
- user.id = 1
16
- user.save
17
- user
18
- end
19
-
20
- let!(:cards_users) do
21
- 10.times.map do
22
- CardsUser.create(user: user, card_id: 1)
23
- end
24
- end
25
-
26
- let!(:cards_users_histories) do
27
- cards_users.map do |cards_user|
28
- CardsUsersHistory.create(cards_user: cards_user, user: user)
29
- end
30
- end
31
-
32
- let!(:events_users_histories) do
33
- cards_users.map do |cards_user|
34
- EventsUsersHistory.create(cards_user: cards_user, user: user, events_user_id: user.id)
35
- end
36
- end
37
-
38
- context "When preloads has_many association" do
39
- before do
40
- ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_query] = true
41
- end
42
-
43
- context "associated objects has same turntable_key" do
44
- subject { CardsUser.where(user: user).preload(:cards_users_histories).first }
45
- it { expect { subject }.to_not raise_error }
46
-
47
- it "its association should be loaded" do
48
- expect(subject.association(:cards_users_histories)).to be_loaded
49
- end
50
-
51
- it "its has_many targets should be assigned all related object" do
52
- expect(subject.cards_users_histories).to include(*cards_users_histories.select { |history| history.cards_user_id == subject.id })
53
- end
54
- end
55
-
56
- context "associated objects has different turntable_key" do
57
- context "when foreign_shard_key option passed" do
58
- subject { CardsUser.where(user: user).preload(:events_users_histories_with_foreign_shard_key).first }
59
-
60
- it { expect { subject }.to_not raise_error }
61
-
62
- it "its association should be loaded" do
63
- expect(subject.association(:events_users_histories_with_foreign_shard_key)).to be_loaded
64
- end
65
-
66
- it "its has_many targets should be assigned all related object" do
67
- expect(subject.events_users_histories_with_foreign_shard_key).to include(*events_users_histories.select { |history| history.cards_user_id == subject.id })
68
- end
69
- end
70
-
71
- context "when foreign_shard_key option is not passed" do
72
- subject { CardsUser.where(user: user).preload(:events_users_histories).first }
73
-
74
- it { expect { subject }.to raise_error }
75
- end
76
- end
77
- end
78
- end
@@ -1,81 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ActiveRecord::Turntable::ActiveRecordExt::Association do
4
- before(:all) do
5
- reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
6
- end
7
-
8
- before(:each) do
9
- establish_connection_to(:test)
10
- truncate_shard
11
- end
12
-
13
- let!(:user) do
14
- user = User.new({ nickname: "user1" })
15
- user.id = 1
16
- user.save
17
- user
18
- end
19
-
20
- let!(:cards_users) do
21
- 10.times.map do
22
- CardsUser.create(user: user, card_id: 1)
23
- end
24
- end
25
-
26
- let!(:cards_users_histories) do
27
- cards_users.map do |cards_user|
28
- CardsUsersHistory.create(cards_user: cards_user, user: user)
29
- end
30
- end
31
-
32
- let!(:events_users_histories) do
33
- cards_users.map do |cards_user|
34
- EventsUsersHistory.create(cards_user: cards_user, user: user, events_user_id: user.id)
35
- end
36
- end
37
-
38
- context "When a model with has_one relation" do
39
- context "When the has_one associated object doesn't exists" do
40
- subject { user.user_status }
41
- it { expect { subject }.to_not raise_error }
42
- end
43
- end
44
-
45
- context "With has_many association" do
46
- before do
47
- ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_query] = true
48
- end
49
- let(:cards_user) { CardsUser.where(user: user).first }
50
- let(:cards_users_history) { cards_users_histories.find { |history| history.user_id == user.id } }
51
-
52
- context "associated objects has same turntable_key" do
53
- context "AssociationRelation#to_a" do
54
- subject { cards_user.cards_users_histories.to_a }
55
- it { expect { subject }.to_not raise_error }
56
- it { is_expected.to include(*cards_users_histories.select { |history| history.cards_user_id == cards_user.id }) }
57
- end
58
-
59
- context "AssociationRelation#where" do
60
- subject { cards_user.cards_users_histories.where(id: cards_users_history.id).to_a }
61
- it { expect { subject }.to_not raise_error }
62
- it { is_expected.to include(cards_users_history) }
63
- end
64
- end
65
-
66
- context "associated objects has different turntable_key" do
67
- context "when foreign_shard_key option passed" do
68
- subject { cards_user.events_users_histories_with_foreign_shard_key.to_a }
69
-
70
- it { expect { subject }.to_not raise_error }
71
- it { is_expected.to include(*events_users_histories.select { |history| history.cards_user_id == cards_user.id }) }
72
- end
73
-
74
- context "when foreign_shard_key option is not passed" do
75
- subject { CardsUser.where(user: user).events_users_histories }
76
-
77
- it { expect { subject }.to raise_error }
78
- end
79
- end
80
- end
81
- end
@@ -1,72 +0,0 @@
1
- require "spec_helper"
2
- require "logger"
3
-
4
- describe ActiveRecord::Turntable::ActiveRecordExt::CleverLoad do
5
- before(:all) do
6
- reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
7
- end
8
-
9
- before(:each) do
10
- establish_connection_to(:test)
11
- truncate_shard
12
-
13
- @user1 = User.new({ nickname: "user1" })
14
- @user1.id = 1
15
- @user1.save
16
- @user1_status = @user1.create_user_status(hp: 10, mp: 10)
17
- @user2 = User.new({ nickname: "user2" })
18
- @user2.id = 2
19
- @user2.save
20
- @user2_status = @user2.create_user_status(hp: 20, mp: 10)
21
- end
22
-
23
- context "When a model has has_one relation" do
24
- context "When call clever_load!" do
25
- let(:users) { User.all.clever_load!(:user_status) }
26
-
27
- context "With their associations" do
28
- subject { users.map { |u| u.association(:user_status) } }
29
-
30
- it "should be association target loaded" do
31
- is_expected.to all(be_loaded)
32
- end
33
- end
34
-
35
- context "With their targets" do
36
- subject { users.map { |u| u.association(:user_status).target } }
37
-
38
- it "should be loaded target object" do
39
- is_expected.to all(be_instance_of(UserStatus))
40
- end
41
- end
42
- end
43
- end
44
-
45
- context "When a model has belongs_to relation" do
46
- context "When call clever_load!" do
47
- let(:user_statuses) { UserStatus.all.clever_load!(:user) }
48
-
49
- context "With their associations" do
50
- subject { user_statuses.map { |us| us.association(:user) } }
51
-
52
- it "should target loaded" do
53
- is_expected.to all(be_loaded)
54
- end
55
- end
56
-
57
- context "With their targets" do
58
- subject { user_statuses.map { |us| us.association(:user).target } }
59
-
60
- it "should be loaded target object" do
61
- is_expected.to all(be_instance_of(User))
62
- end
63
- end
64
- end
65
- end
66
-
67
- context "When a model has has_many relation" do
68
- it "should send query only 2 times." do
69
- skip "not implemented yet"
70
- end
71
- end
72
- end
@@ -1,27 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "active_record"
4
- require "active_record/turntable/active_record_ext/fixtures"
5
-
6
- describe ActiveRecord::FixtureSet do
7
- before(:all) do
8
- reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
9
- end
10
-
11
- before do
12
- establish_connection_to(:test)
13
- truncate_shard
14
- end
15
-
16
- let(:fixtures_root) { File.join(File.dirname(__FILE__), "../../../fixtures") }
17
- let(:fixture_file) { File.join(fixtures_root, "cards.yml") }
18
- let(:cards) { YAML.load(ERB.new(IO.read(fixture_file)).result) }
19
-
20
- describe ".create_fixtures" do
21
- subject { ActiveRecord::FixtureSet.create_fixtures(fixtures_root, "cards") }
22
- it { is_expected.to be_instance_of(Array) }
23
- it "creates card records" do
24
- expect { subject }.to change { Card.count }.from(0).to(cards.size)
25
- end
26
- end
27
- end
@@ -1,28 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ActiveRecord::Turntable::ActiveRecordExt::LockingOptimistic do
4
- before(:all) do
5
- reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
6
- end
7
-
8
- before(:each) do
9
- establish_connection_to(:test)
10
- truncate_shard
11
- end
12
-
13
- before do
14
- ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_update] = true
15
- end
16
-
17
- let!(:user_status) do
18
- user_status = UserStatus.new(user_id: 1)
19
- user_status.id = 10
20
- user_status.save
21
- user_status
22
- end
23
-
24
- describe "optimistic locking" do
25
- subject { user_status.update_attributes(hp: 20) }
26
- it { expect { subject }.to change(user_status, :lock_version).by(1) }
27
- end
28
- end
@@ -1,38 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ActiveRecord::Turntable::Migration do
4
- before(:all) do
5
- reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml"))
6
- end
7
-
8
- before(:each) do
9
- establish_connection_to(:test)
10
- truncate_shard
11
- end
12
-
13
- describe ".target_shards" do
14
- subject { migration_class.new.target_shards }
15
-
16
- context "With clusters definitions" do
17
- let(:migration_class) {
18
- klass = Class.new(ActiveRecord::Migration) {
19
- clusters :user_cluster
20
- }
21
- }
22
- let(:cluster_config) { ActiveRecord::Base.turntable_config[:clusters][:user_cluster] }
23
- let(:user_cluster_shards) { cluster_config[:shards].map { |s| s[:connection] } }
24
-
25
- it { is_expected.to eq(user_cluster_shards) }
26
- end
27
-
28
- context "With shards definitions" do
29
- let(:migration_class) {
30
- klass = Class.new(ActiveRecord::Migration) {
31
- shards :user_shard_01
32
- }
33
- }
34
-
35
- it { is_expected.to eq([:user_shard_01]) }
36
- end
37
- end
38
- end