vorpal 0.0.7.rc1 → 0.0.7.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -131,7 +131,7 @@ describe 'Aggregate Repository' do
131
131
  it 'does not change the id on update' do
132
132
  test_repository = configure
133
133
 
134
- tree = Tree.new()
134
+ tree = Tree.new
135
135
  test_repository.persist(tree)
136
136
 
137
137
  original_id = tree.id
@@ -145,7 +145,7 @@ describe 'Aggregate Repository' do
145
145
  it 'does not create additional records' do
146
146
  test_repository = configure
147
147
 
148
- tree = Tree.new()
148
+ tree = Tree.new
149
149
  test_repository.persist(tree)
150
150
 
151
151
  tree.name = 'change it'
@@ -185,7 +185,7 @@ describe 'Aggregate Repository' do
185
185
  test_repository = configure
186
186
 
187
187
  tree_db = TreeDB.create! name: 'tree name'
188
- tree = test_repository.load(tree_db.id, Tree)
188
+ tree = test_repository.load_one(tree_db)
189
189
 
190
190
  expect(tree.id).to eq tree_db.id
191
191
  expect(tree.name).to eq 'tree name'
@@ -197,7 +197,7 @@ describe 'Aggregate Repository' do
197
197
  tree_db = TreeDB.create!
198
198
  Fissure.create! length: 21, tree_id: tree_db.id
199
199
 
200
- tree = test_repository.load(tree_db.id, Tree)
200
+ tree = test_repository.load_one(tree_db)
201
201
 
202
202
  expect(tree.fissures.first.length).to eq 21
203
203
  end
@@ -221,7 +221,7 @@ describe 'Aggregate Repository' do
221
221
  tree_db = TreeDB.create!
222
222
  BranchDB.create!(length: 50, tree_id: tree_db.id)
223
223
 
224
- tree = test_repository.load(tree_db.id, Tree)
224
+ tree = test_repository.load_one(tree_db)
225
225
 
226
226
  expect(tree).to be tree.branches.first.tree
227
227
  end
@@ -249,7 +249,7 @@ describe 'Aggregate Repository' do
249
249
  long_branch = BranchDB.create!(length: 100, tree_id: tree_db.id)
250
250
  BranchDB.create!(length: 50, branch_id: long_branch.id)
251
251
 
252
- tree = test_repository.load(tree_db.id, Tree)
252
+ tree = test_repository.load_one(tree_db)
253
253
 
254
254
  expect(tree.branches.first.branches.first.length).to eq 50
255
255
  end
@@ -269,7 +269,7 @@ describe 'Aggregate Repository' do
269
269
 
270
270
  it 'saves foreign keys' do
271
271
  test_repository = configure
272
- trunk = Trunk.new()
272
+ trunk = Trunk.new
273
273
  tree = Tree.new(trunk: trunk)
274
274
 
275
275
  test_repository.persist(tree)
@@ -306,7 +306,7 @@ describe 'Aggregate Repository' do
306
306
  trunk_db = TrunkDB.create!(length: 21)
307
307
  tree_db = TreeDB.create!(trunk_id: trunk_db.id)
308
308
 
309
- new_tree = test_repository.load(tree_db.id, Tree)
309
+ new_tree = test_repository.load_one(tree_db)
310
310
  expect(new_tree.trunk.length).to eq 21
311
311
  end
312
312
  end
@@ -371,7 +371,7 @@ describe 'Aggregate Repository' do
371
371
  tree_db = TreeDB.create!
372
372
  BranchDB.create!(length: 50, tree_id: tree_db.id)
373
373
 
374
- tree = test_repository.load(tree_db.id, Tree)
374
+ tree = test_repository.load_one(tree_db)
375
375
 
376
376
  expect(tree.branches.first.length).to eq 50
377
377
  end
@@ -414,7 +414,7 @@ describe 'Aggregate Repository' do
414
414
  trunk_db = TrunkDB.create!
415
415
  TreeDB.create!(name: 'big tree', trunk_id: trunk_db.id)
416
416
 
417
- trunk = test_repository.load(trunk_db.id, Trunk)
417
+ trunk = test_repository.load_one(trunk_db)
418
418
 
419
419
  expect(trunk.tree.name).to eq 'big tree'
420
420
  end
@@ -442,12 +442,13 @@ describe 'Aggregate Repository' do
442
442
  test_repository = configure_polymorphic_has_many
443
443
 
444
444
  trunk_db = TrunkDB.create!
445
+ tree_db = TreeDB.create!(trunk_id: trunk_db.id)
445
446
  BugDB.create!(name: 'trunk bug', lives_on_id: trunk_db.id, lives_on_type: Trunk.name)
446
447
  BugDB.create!(name: 'not a trunk bug!', lives_on_id: trunk_db.id, lives_on_type: 'some other table')
447
448
 
448
- trunk = test_repository.load(trunk_db.id, Trunk)
449
+ tree = test_repository.load_one(tree_db)
449
450
 
450
- expect(trunk.bugs.map(&:name)).to eq ['trunk bug']
451
+ expect(tree.trunk.bugs.map(&:name)).to eq ['trunk bug']
451
452
  end
452
453
 
453
454
  it 'saves with belongs_tos' do
@@ -456,7 +457,7 @@ describe 'Aggregate Repository' do
456
457
  trunk_bug = Bug.new(lives_on: Trunk.new)
457
458
  branch_bug = Bug.new(lives_on: Branch.new)
458
459
 
459
- test_repository.persist_all([trunk_bug, branch_bug])
460
+ test_repository.persist([trunk_bug, branch_bug])
460
461
 
461
462
  expect(BugDB.find(trunk_bug.id).lives_on_type).to eq Trunk.name
462
463
  expect(BugDB.find(branch_bug.id).lives_on_type).to eq Branch.name
@@ -487,7 +488,7 @@ describe 'Aggregate Repository' do
487
488
  branch_db.save!
488
489
  branch_bug_db = BugDB.create!(lives_on_id: branch_db.id, lives_on_type: Branch.name)
489
490
 
490
- trunk_bug, branch_bug = test_repository.load_all([trunk_bug_db.id, branch_bug_db.id], Bug)
491
+ trunk_bug, branch_bug = test_repository.load_many([trunk_bug_db, branch_bug_db])
491
492
 
492
493
  expect(trunk_bug.lives_on.length).to eq 99
493
494
  expect(branch_bug.lives_on.length).to eq 5
@@ -499,23 +500,58 @@ describe 'Aggregate Repository' do
499
500
  swamp = Swamp.create!
500
501
  tree_db = TreeDB.create!(environment_id: swamp.id, environment_type: Swamp.name)
501
502
 
502
- tree = test_repository.load(tree_db.id, Tree)
503
+ tree = test_repository.load_one(tree_db)
503
504
 
504
505
  expect(tree.environment).to eq swamp
505
506
  end
506
507
  end
507
508
 
508
- describe 'load_all' do
509
- it 'returns objects in the same order as the ids' do
509
+ describe 'arel' do
510
+ it 'loads many' do
511
+ test_repository = configure
512
+
513
+ TreeDB.create!
514
+ tree_db = TreeDB.create!
515
+
516
+ trees = test_repository.query.where(id: tree_db.id).load_many
517
+
518
+ expect(trees.map(&:id)).to eq [tree_db.id]
519
+ end
520
+
521
+ it 'loads one' do
510
522
  test_repository = configure
511
523
 
512
- tree_db1 = TreeDB.create!
513
- tree_db2 = TreeDB.create!
514
- tree_db3 = TreeDB.create!
524
+ TreeDB.create!
525
+ tree_db = TreeDB.create!
515
526
 
516
- trees = test_repository.load_all([tree_db2.id, tree_db1.id, tree_db3.id], Tree)
527
+ trees = test_repository.query.where(id: tree_db.id).load_one
517
528
 
518
- expect(trees.map(&:id)).to eq [tree_db2.id, tree_db1.id, tree_db3.id]
529
+ expect(trees.id).to eq tree_db.id
530
+ end
531
+ end
532
+
533
+ describe 'load_many' do
534
+ it 'maps given db objects' do
535
+ test_repository = configure
536
+
537
+ TreeDB.create!
538
+ tree_db = TreeDB.create!
539
+
540
+ trees = test_repository.load_many([tree_db])
541
+
542
+ expect(trees.map(&:id)).to eq [tree_db.id]
543
+ end
544
+
545
+ it 'only returns roots' do
546
+ test_repository = configure
547
+
548
+ TreeDB.create!
549
+ tree_db = TreeDB.create!
550
+ BranchDB.create!(tree_id: tree_db.id)
551
+
552
+ trees = test_repository.load_many([tree_db])
553
+
554
+ expect(trees.map(&:id)).to eq [tree_db.id]
519
555
  end
520
556
  end
521
557
 
@@ -525,7 +561,7 @@ describe 'Aggregate Repository' do
525
561
 
526
562
  tree_db = TreeDB.create!
527
563
 
528
- test_repository.destroy_all([Tree.new(id: tree_db.id)])
564
+ test_repository.destroy([Tree.new(id: tree_db.id)])
529
565
 
530
566
  expect(TreeDB.count).to eq 0
531
567
  end
@@ -592,54 +628,46 @@ describe 'Aggregate Repository' do
592
628
 
593
629
  tree_db = TreeDB.create!
594
630
 
595
- test_repository.destroy_all_by_id([tree_db.id], Tree)
631
+ test_repository.destroy_by_id([tree_db.id])
596
632
 
597
633
  expect(TreeDB.count).to eq 0
598
634
  end
599
635
  end
600
636
 
601
637
  describe 'non-existent values' do
602
- it 'load_all ignores ids that do not exist' do
638
+ it 'load_many returns an empty array when given an empty array' do
603
639
  test_repository = configure
604
640
 
605
- results = test_repository.load_all([99], Tree)
641
+ results = test_repository.load_many([])
606
642
  expect(results).to eq []
607
643
  end
608
644
 
609
- it 'load_all throws an exception when given a nil id' do
645
+ it 'load_many throws an exception when given a nil db_object' do
610
646
  test_repository = configure
611
647
 
612
648
  expect {
613
- test_repository.load_all([nil], Tree)
614
- }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
615
- end
616
-
617
- it 'load throws an exception when given a nil id' do
618
- test_repository = configure
619
-
620
- expect {
621
- test_repository.load(nil, Tree)
622
- }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
649
+ test_repository.load_many([nil])
650
+ }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
623
651
  end
624
652
 
625
- it 'load_all ignores empty arrays' do
653
+ it 'load_one returns nil when given nil' do
626
654
  test_repository = configure
627
655
 
628
- results = test_repository.load_all([], Tree)
629
- expect(results).to eq []
656
+ result = test_repository.load_one(nil)
657
+ expect(result).to eq nil
630
658
  end
631
659
 
632
- it 'persist_all ignores empty arrays' do
660
+ it 'persist ignores empty arrays' do
633
661
  test_repository = configure
634
662
 
635
- results = test_repository.persist_all([])
663
+ results = test_repository.persist([])
636
664
  expect(results).to eq []
637
665
  end
638
666
 
639
- it 'persist_all throws an exception when given a nil root' do
667
+ it 'persist throws an exception when given a collection with a nil root' do
640
668
  test_repository = configure
641
669
  expect {
642
- test_repository.persist_all([nil])
670
+ test_repository.persist([nil])
643
671
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
644
672
  end
645
673
 
@@ -650,10 +678,10 @@ describe 'Aggregate Repository' do
650
678
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
651
679
  end
652
680
 
653
- it 'destroy_all ignores empty arrays' do
681
+ it 'destroy ignores empty arrays' do
654
682
  test_repository = configure
655
683
 
656
- results = test_repository.destroy_all([])
684
+ results = test_repository.destroy([])
657
685
  expect(results).to eq []
658
686
  end
659
687
 
@@ -665,32 +693,32 @@ describe 'Aggregate Repository' do
665
693
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
666
694
  end
667
695
 
668
- it 'destroy_all throws an exception when given a nil root' do
696
+ it 'destroy throws an exception when given a collection with a nil root' do
669
697
  test_repository = configure
670
698
 
671
699
  expect {
672
- test_repository.destroy_all([nil])
700
+ test_repository.destroy([nil])
673
701
  }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
674
702
  end
675
703
 
676
- it 'destroy_all_by_id ignores empty arrays' do
704
+ it 'destroy_by_id ignores empty arrays' do
677
705
  test_repository = configure
678
706
 
679
- results = test_repository.destroy_all_by_id([], Tree)
707
+ results = test_repository.destroy_by_id([])
680
708
  expect(results).to eq []
681
709
  end
682
710
 
683
- it 'destroy_all_by_id ignores ids that do not exist' do
711
+ it 'destroy_by_id ignores ids that do not exist' do
684
712
  test_repository = configure
685
713
 
686
- test_repository.destroy_all_by_id([99], Tree)
714
+ test_repository.destroy_by_id([99])
687
715
  end
688
716
 
689
- it 'destroy_all_by_id throws an exception when given a nil id' do
717
+ it 'destroy_by_id throws an exception when given a collection with a nil id' do
690
718
  test_repository = configure
691
719
 
692
720
  expect {
693
- test_repository.destroy_all_by_id([nil], Tree)
721
+ test_repository.destroy_by_id([nil])
694
722
  }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
695
723
  end
696
724
 
@@ -698,7 +726,7 @@ describe 'Aggregate Repository' do
698
726
  test_repository = configure
699
727
 
700
728
  expect {
701
- test_repository.destroy_by_id(nil, Tree)
729
+ test_repository.destroy_by_id(nil)
702
730
  }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
703
731
  end
704
732
  end
@@ -706,7 +734,7 @@ describe 'Aggregate Repository' do
706
734
  private
707
735
 
708
736
  def configure_polymorphic_has_many
709
- Vorpal.define do
737
+ engine = Vorpal.define do
710
738
  map Tree do
711
739
  attributes :name
712
740
  has_many :branches
@@ -727,10 +755,11 @@ private
727
755
  attributes :name
728
756
  end
729
757
  end
758
+ engine.repository_for(Tree)
730
759
  end
731
760
 
732
761
  def configure_polymorphic_belongs_to
733
- Vorpal.define do
762
+ engine = Vorpal.define do
734
763
  map Bug do
735
764
  attributes :name
736
765
  belongs_to :lives_on, fk: :lives_on_id, fk_type: :lives_on_type, child_classes: [Trunk, Branch]
@@ -744,10 +773,11 @@ private
744
773
  attributes :length
745
774
  end
746
775
  end
776
+ engine.repository_for(Bug)
747
777
  end
748
778
 
749
779
  def configure_ar_polymorphic_belongs_to
750
- Vorpal.define do
780
+ engine = Vorpal.define do
751
781
  map Tree do
752
782
  attributes :name
753
783
  belongs_to :environment, owned: false, fk: :environment_id, fk_type: :environment_type, child_class: Swamp
@@ -755,10 +785,11 @@ private
755
785
 
756
786
  map Swamp, to: Swamp
757
787
  end
788
+ engine.repository_for(Tree)
758
789
  end
759
790
 
760
791
  def configure_unowned_polymorphic_belongs_to
761
- Vorpal.define do
792
+ engine = Vorpal.define do
762
793
  map Bug do
763
794
  attributes :name
764
795
  belongs_to :lives_on, owned: false, fk: :lives_on_id, fk_type: :lives_on_type, child_classes: [Trunk, Branch]
@@ -772,10 +803,11 @@ private
772
803
  attributes :length
773
804
  end
774
805
  end
806
+ engine.repository_for(Bug)
775
807
  end
776
808
 
777
809
  def configure_unowned
778
- Vorpal.define do
810
+ engine = Vorpal.define do
779
811
  map Tree do
780
812
  attributes :name
781
813
  has_many :branches, owned: false
@@ -790,10 +822,11 @@ private
790
822
  attributes :length
791
823
  end
792
824
  end
825
+ engine.repository_for(Tree)
793
826
  end
794
827
 
795
828
  def configure_recursive
796
- Vorpal.define do
829
+ engine = Vorpal.define do
797
830
  map Branch do
798
831
  attributes :length
799
832
  has_many :branches
@@ -804,10 +837,11 @@ private
804
837
  has_many :branches
805
838
  end
806
839
  end
840
+ engine.repository_for(Tree)
807
841
  end
808
842
 
809
843
  def configure_with_cycle
810
- Vorpal.define do
844
+ engine = Vorpal.define do
811
845
  map Branch do
812
846
  attributes :length
813
847
  belongs_to :tree
@@ -818,10 +852,11 @@ private
818
852
  has_many :branches
819
853
  end
820
854
  end
855
+ engine.repository_for(Tree)
821
856
  end
822
857
 
823
858
  def configure(options={})
824
- Vorpal.define(options) do
859
+ engine = Vorpal.define(options) do
825
860
  map Tree do
826
861
  attributes :name
827
862
  belongs_to :trunk
@@ -839,10 +874,11 @@ private
839
874
 
840
875
  map Fissure, to: Fissure
841
876
  end
877
+ engine.repository_for(Tree)
842
878
  end
843
879
 
844
880
  def configure_has_one
845
- Vorpal.define do
881
+ engine = Vorpal.define do
846
882
  map Trunk do
847
883
  attributes :length
848
884
  has_one :tree
@@ -852,10 +888,11 @@ private
852
888
  attributes :name
853
889
  end
854
890
  end
891
+ engine.repository_for(Trunk)
855
892
  end
856
893
 
857
894
  def configure_unowned_has_one
858
- Vorpal.define do
895
+ engine = Vorpal.define do
859
896
  map Trunk do
860
897
  attributes :length
861
898
  has_one :tree, owned: false
@@ -865,5 +902,6 @@ private
865
902
  attributes :name
866
903
  end
867
904
  end
905
+ engine.repository_for(Trunk)
868
906
  end
869
907
  end
@@ -92,10 +92,10 @@ describe 'performance' do
92
92
  it 'benchmarks all operations' do
93
93
  trees = build_trees(1000)
94
94
  Benchmark.bm(7) do |x|
95
- x.report('create') { test_repository.persist_all(trees) }
96
- x.report('update') { test_repository.persist_all(trees) }
97
- x.report('load') { ids = trees.map(&:id); test_repository.load_all(ids, Tree) }
98
- x.report('destroy') { test_repository.destroy_all(trees) }
95
+ x.report('create') { test_repository.persist(trees) }
96
+ x.report('update') { test_repository.persist(trees) }
97
+ x.report('load') { test_repository.load_many(TreeDB.where(id: trees.map(&:id)).all) }
98
+ x.report('destroy') { test_repository.destroy(trees) }
99
99
  end
100
100
  end
101
101
 
@@ -104,39 +104,39 @@ describe 'performance' do
104
104
 
105
105
  puts 'starting persistence benchmark'
106
106
  puts Benchmark.measure {
107
- test_repository.persist_all(trees)
107
+ test_repository.persist(trees)
108
108
  }
109
109
  end
110
110
 
111
111
  it 'updates aggregates quickly' do
112
112
  trees = build_trees(1000)
113
113
 
114
- test_repository.persist_all(trees)
114
+ test_repository.persist(trees)
115
115
 
116
116
  puts 'starting update benchmark'
117
117
  puts Benchmark.measure {
118
- test_repository.persist_all(trees)
118
+ test_repository.persist(trees)
119
119
  }
120
120
  end
121
121
 
122
122
  it 'loads aggregates quickly' do
123
123
  trees = build_trees(1000)
124
- test_repository.persist_all(trees)
124
+ test_repository.persist(trees)
125
125
  ids = trees.map(&:id)
126
126
 
127
127
  puts 'starting loading benchmark'
128
128
  puts Benchmark.measure {
129
- test_repository.load_all(ids, Tree)
129
+ test_repository.load_many(TreeDB.where(id: ids).all)
130
130
  }
131
131
  end
132
132
 
133
133
  it 'destroys aggregates quickly' do
134
134
  trees = build_trees(1000)
135
- test_repository.persist_all(trees)
135
+ test_repository.persist(trees)
136
136
 
137
137
  puts 'starting destruction benchmark'
138
138
  puts Benchmark.measure {
139
- test_repository.destroy_all(trees)
139
+ test_repository.destroy(trees)
140
140
  }
141
141
  end
142
142
 
@@ -163,7 +163,7 @@ describe 'performance' do
163
163
  end
164
164
 
165
165
  def build_repository
166
- Vorpal.define do
166
+ engine = Vorpal.define do
167
167
  map Tree do
168
168
  attributes :name
169
169
  belongs_to :trunk
@@ -188,5 +188,6 @@ describe 'performance' do
188
188
  belongs_to :lives_on, fk: :lives_on_id, fk_type: :lives_on_type, child_classes: [Trunk, Branch]
189
189
  end
190
190
  end
191
+ engine.repository_for(Tree)
191
192
  end
192
193
  end
@@ -1,6 +1,7 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  require 'vorpal/config_builder'
4
+ require 'vorpal/db_driver'
4
5
 
5
6
  describe Vorpal::ConfigBuilder do
6
7
  class Tester; end
data/vorpal.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency "activesupport"
24
24
 
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "activerecord", "~> 3.2.0"
28
28
  spec.add_development_dependency "pg", "~> 0.17.0"
29
29
  spec.add_development_dependency "virtus", "~> 1.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vorpal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.rc1
4
+ version: 0.0.7.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_serializer
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.0.0
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.0.0
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +146,7 @@ extra_rdoc_files: []
146
146
  files:
147
147
  - ".gitignore"
148
148
  - ".yardopts"
149
+ - CHANGELOG.md
149
150
  - Gemfile
150
151
  - LICENSE.txt
151
152
  - README.md
@@ -159,6 +160,7 @@ files:
159
160
  - lib/vorpal/configuration.rb
160
161
  - lib/vorpal/db_driver.rb
161
162
  - lib/vorpal/db_loader.rb
163
+ - lib/vorpal/engine.rb
162
164
  - lib/vorpal/identity_map.rb
163
165
  - lib/vorpal/loaded_objects.rb
164
166
  - lib/vorpal/util/array_hash.rb