vorpal 0.0.6.rc4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,17 @@
1
1
  module Vorpal
2
-
3
- # @private
4
- module ArrayHash
5
- def add_to_hash(array_hash, key, values)
6
- if array_hash[key].nil? || array_hash[key].empty?
7
- array_hash[key] = []
2
+ # @private
3
+ module ArrayHash
4
+ def add_to_hash(array_hash, key, values)
5
+ if array_hash[key].nil? || array_hash[key].empty?
6
+ array_hash[key] = []
7
+ end
8
+ array_hash[key].concat(Array(values))
8
9
  end
9
- array_hash[key].concat(Array(values))
10
- end
11
10
 
12
- def pop(array_hash)
13
- key = array_hash.first.first
14
- values = array_hash.delete(key)
15
- [key, values]
11
+ def pop(array_hash)
12
+ key = array_hash.first.first
13
+ values = array_hash.delete(key)
14
+ [key, values]
15
+ end
16
16
  end
17
17
  end
18
-
19
- end
@@ -1,3 +1,3 @@
1
1
  module Vorpal
2
- VERSION = "0.0.6.rc4"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -211,7 +211,7 @@ describe 'Aggregate Repository' do
211
211
  expect(tree.fissures.first.length).to eq 21
212
212
  end
213
213
 
214
- describe "cycles" do
214
+ describe 'cycles' do
215
215
  it 'persists' do
216
216
  test_repository = configure_with_cycle
217
217
 
@@ -225,7 +225,7 @@ describe 'Aggregate Repository' do
225
225
  end
226
226
 
227
227
  it 'hydrates' do
228
- test_repository = configure_with_cycle
228
+ test_repository = configure_with_cycle
229
229
 
230
230
  tree_db = TreeDB.create!
231
231
  BranchDB.create!(length: 50, tree_id: tree_db.id)
@@ -514,6 +514,20 @@ describe 'Aggregate Repository' do
514
514
  end
515
515
  end
516
516
 
517
+ describe 'load_all' do
518
+ it 'returns objects in the same order as the ids' do
519
+ test_repository = configure
520
+
521
+ tree_db1 = TreeDB.create!
522
+ tree_db2 = TreeDB.create!
523
+ tree_db3 = TreeDB.create!
524
+
525
+ trees = test_repository.load_all([tree_db2.id, tree_db1.id, tree_db3.id], Tree)
526
+
527
+ expect(trees.map(&:id)).to eq [tree_db2.id, tree_db1.id, tree_db3.id]
528
+ end
529
+ end
530
+
517
531
  describe 'destroy' do
518
532
  it 'removes the entity from the database' do
519
533
  test_repository = configure
@@ -581,6 +595,123 @@ describe 'Aggregate Repository' do
581
595
  end
582
596
  end
583
597
 
598
+ describe 'destroy_by_id' do
599
+ it 'removes the entity from the database' do
600
+ test_repository = configure
601
+
602
+ tree_db = TreeDB.create!
603
+
604
+ test_repository.destroy_all_by_id([tree_db.id], Tree)
605
+
606
+ expect(TreeDB.count).to eq 0
607
+ end
608
+ end
609
+
610
+ describe 'non-existent values' do
611
+ it 'load_all ignores ids that do not exist' do
612
+ test_repository = configure
613
+
614
+ results = test_repository.load_all([99], Tree)
615
+ expect(results).to eq []
616
+ end
617
+
618
+ it 'load_all throws an exception when given a nil id' do
619
+ test_repository = configure
620
+
621
+ expect {
622
+ test_repository.load_all([nil], Tree)
623
+ }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
624
+ end
625
+
626
+ it 'load throws an exception when given a nil id' do
627
+ test_repository = configure
628
+
629
+ expect {
630
+ test_repository.load(nil, Tree)
631
+ }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
632
+ end
633
+
634
+ it 'load_all ignores empty arrays' do
635
+ test_repository = configure
636
+
637
+ results = test_repository.load_all([], Tree)
638
+ expect(results).to eq []
639
+ end
640
+
641
+ it 'persist_all ignores empty arrays' do
642
+ test_repository = configure
643
+
644
+ results = test_repository.persist_all([])
645
+ expect(results).to eq []
646
+ end
647
+
648
+ it 'persist_all throws an exception when given a nil root' do
649
+ test_repository = configure
650
+ expect {
651
+ test_repository.persist_all([nil])
652
+ }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
653
+ end
654
+
655
+ it 'persist throws an exception when given a nil root' do
656
+ test_repository = configure
657
+ expect {
658
+ test_repository.persist(nil)
659
+ }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
660
+ end
661
+
662
+ it 'destroy_all ignores empty arrays' do
663
+ test_repository = configure
664
+
665
+ results = test_repository.destroy_all([])
666
+ expect(results).to eq []
667
+ end
668
+
669
+ it 'destroy throws an exception when given a nil root' do
670
+ test_repository = configure
671
+
672
+ expect {
673
+ test_repository.destroy(nil)
674
+ }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
675
+ end
676
+
677
+ it 'destroy_all throws an exception when given a nil root' do
678
+ test_repository = configure
679
+
680
+ expect {
681
+ test_repository.destroy_all([nil])
682
+ }.to raise_error(Vorpal::InvalidAggregateRoot, "Nil aggregate roots are not allowed.")
683
+ end
684
+
685
+ it 'destroy_all_by_id ignores empty arrays' do
686
+ test_repository = configure
687
+
688
+ results = test_repository.destroy_all_by_id([], Tree)
689
+ expect(results).to eq []
690
+ end
691
+
692
+ it 'destroy_all_by_id ignores ids that do not exist' do
693
+ test_repository = configure
694
+
695
+ test_repository.destroy_all_by_id([99], Tree)
696
+ end
697
+
698
+ it 'destroy_all_by_id throws an exception when given a nil id' do
699
+ test_repository = configure
700
+
701
+ expect {
702
+ test_repository.destroy_all_by_id([nil], Tree)
703
+ }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
704
+ end
705
+
706
+ it 'destroy_by_id throws an exception when given a nil id' do
707
+ test_repository = configure
708
+
709
+ expect {
710
+ test_repository.destroy_by_id(nil, Tree)
711
+ }.to raise_error(Vorpal::InvalidPrimaryKeyValue, "Nil primary key values are not allowed.")
712
+ end
713
+ end
714
+
584
715
  private
585
716
 
586
717
  def configure_polymorphic_has_many
@@ -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_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) }
99
99
  end
100
100
  end
101
101
 
@@ -0,0 +1,22 @@
1
+ require 'unit_spec_helper'
2
+
3
+ require 'virtus'
4
+ require 'vorpal/loaded_objects'
5
+ require 'vorpal/configs'
6
+
7
+ describe Vorpal::LoadedObjects do
8
+ class TestObject
9
+ include Virtus.model
10
+ attribute :id, Integer
11
+ end
12
+
13
+ it 'does not accept duplicate objects' do
14
+ object = TestObject.new(id: 22)
15
+ config = Vorpal::ClassConfig.new({domain_class: Object})
16
+
17
+ subject.add(config, [object, object])
18
+ subject.add(config, [object])
19
+
20
+ expect(subject.objects.values.flatten).to contain_exactly(object)
21
+ end
22
+ end
data/vorpal.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "simple_serializer", "~> 1.0"
22
22
  spec.add_runtime_dependency "equalizer"
23
+ spec.add_runtime_dependency "activesupport"
23
24
 
24
25
  spec.add_development_dependency "rake", "~> 10.0"
25
26
  spec.add_development_dependency "rspec", "~> 3.0.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.6.rc4
4
+ version: 0.0.6
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-04-23 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_serializer
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -153,11 +167,12 @@ files:
153
167
  - spec/helpers/db_helpers.rb
154
168
  - spec/integration_spec_helper.rb
155
169
  - spec/unit_spec_helper.rb
156
- - spec/vorpal/aggregate_repository_spec.rb
157
- - spec/vorpal/class_config_builder_spec.rb
158
- - spec/vorpal/configs_spec.rb
159
- - spec/vorpal/identity_map_spec.rb
160
- - spec/vorpal/performance_spec.rb
170
+ - spec/vorpal/acceptance/aggregate_repository_spec.rb
171
+ - spec/vorpal/acceptance/performance_spec.rb
172
+ - spec/vorpal/unit/class_config_builder_spec.rb
173
+ - spec/vorpal/unit/configs_spec.rb
174
+ - spec/vorpal/unit/identity_map_spec.rb
175
+ - spec/vorpal/unit/loaded_objects_spec.rb
161
176
  - vorpal.gemspec
162
177
  homepage: https://github.com/nulogy/vorpal
163
178
  licenses:
@@ -174,9 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
189
  version: '0'
175
190
  required_rubygems_version: !ruby/object:Gem::Requirement
176
191
  requirements:
177
- - - ! '>'
192
+ - - ! '>='
178
193
  - !ruby/object:Gem::Version
179
- version: 1.3.1
194
+ version: '0'
180
195
  requirements: []
181
196
  rubyforge_project:
182
197
  rubygems_version: 2.4.5
@@ -187,8 +202,9 @@ test_files:
187
202
  - spec/helpers/db_helpers.rb
188
203
  - spec/integration_spec_helper.rb
189
204
  - spec/unit_spec_helper.rb
190
- - spec/vorpal/aggregate_repository_spec.rb
191
- - spec/vorpal/class_config_builder_spec.rb
192
- - spec/vorpal/configs_spec.rb
193
- - spec/vorpal/identity_map_spec.rb
194
- - spec/vorpal/performance_spec.rb
205
+ - spec/vorpal/acceptance/aggregate_repository_spec.rb
206
+ - spec/vorpal/acceptance/performance_spec.rb
207
+ - spec/vorpal/unit/class_config_builder_spec.rb
208
+ - spec/vorpal/unit/configs_spec.rb
209
+ - spec/vorpal/unit/identity_map_spec.rb
210
+ - spec/vorpal/unit/loaded_objects_spec.rb