dm-core 1.0.2 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +28 -94
- data/LICENSE +1 -1
- data/README.rdoc +44 -11
- data/Rakefile +1 -7
- data/VERSION +1 -1
- data/dm-core.gemspec +398 -299
- data/lib/dm-core.rb +23 -13
- data/lib/dm-core/adapters/abstract_adapter.rb +1 -1
- data/lib/dm-core/associations/many_to_many.rb +1 -3
- data/lib/dm-core/associations/many_to_one.rb +54 -36
- data/lib/dm-core/associations/one_to_many.rb +1 -2
- data/lib/dm-core/associations/relationship.rb +11 -2
- data/lib/dm-core/collection.rb +3 -7
- data/lib/dm-core/core_ext/symbol.rb +1 -1
- data/lib/dm-core/identity_map.rb +0 -5
- data/lib/dm-core/model.rb +11 -21
- data/lib/dm-core/model/property.rb +43 -58
- data/lib/dm-core/model/relationship.rb +49 -44
- data/lib/dm-core/property.rb +106 -130
- data/lib/dm-core/property/date_time.rb +1 -3
- data/lib/dm-core/property/decimal.rb +11 -7
- data/lib/dm-core/property/integer.rb +2 -2
- data/lib/dm-core/property/lookup.rb +3 -16
- data/lib/dm-core/property/numeric.rb +3 -3
- data/lib/dm-core/property/object.rb +2 -11
- data/lib/dm-core/property/string.rb +1 -1
- data/lib/dm-core/property_set.rb +34 -54
- data/lib/dm-core/query.rb +85 -56
- data/lib/dm-core/query/conditions/comparison.rb +3 -6
- data/lib/dm-core/query/direction.rb +0 -4
- data/lib/dm-core/query/path.rb +22 -6
- data/lib/dm-core/relationship_set.rb +74 -0
- data/lib/dm-core/resource.rb +21 -32
- data/lib/dm-core/resource/state.rb +3 -4
- data/lib/dm-core/spec/lib/spec_helper.rb +1 -4
- data/lib/dm-core/spec/setup.rb +12 -5
- data/lib/dm-core/spec/shared/public/property_spec.rb +35 -21
- data/lib/dm-core/spec/shared/resource_spec.rb +1 -1
- data/lib/dm-core/spec/shared/semipublic/property_spec.rb +9 -9
- data/lib/dm-core/spec/shared/semipublic/query/conditions/abstract_comparison_spec.rb +261 -0
- data/lib/dm-core/support/deprecate.rb +1 -1
- data/lib/dm-core/support/descendant_set.rb +12 -5
- data/lib/dm-core/support/ordered_set.rb +382 -0
- data/lib/dm-core/support/subject_set.rb +252 -0
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +1 -2
- data/spec/public/associations/many_to_many_spec.rb +11 -9
- data/spec/public/associations/many_to_one_spec.rb +1 -1
- data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +1 -1
- data/spec/public/associations/many_to_one_with_custom_fk_spec.rb +2 -2
- data/spec/public/associations/one_to_many_spec.rb +6 -5
- data/spec/public/associations/one_to_one_spec.rb +1 -1
- data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +1 -1
- data/spec/public/collection_spec.rb +7 -6
- data/spec/public/finalize_spec.rb +1 -1
- data/spec/public/model/hook_spec.rb +4 -3
- data/spec/public/model/property_spec.rb +9 -3
- data/spec/public/model/relationship_spec.rb +2 -4
- data/spec/public/model_spec.rb +1 -1
- data/spec/public/property/binary_spec.rb +1 -1
- data/spec/public/property/boolean_spec.rb +1 -1
- data/spec/public/property/class_spec.rb +1 -1
- data/spec/public/property/date_spec.rb +1 -1
- data/spec/public/property/date_time_spec.rb +1 -1
- data/spec/public/property/decimal_spec.rb +7 -6
- data/spec/public/property/discriminator_spec.rb +1 -1
- data/spec/public/property/float_spec.rb +1 -1
- data/spec/public/property/integer_spec.rb +1 -1
- data/spec/public/property/object_spec.rb +2 -2
- data/spec/public/property/serial_spec.rb +1 -1
- data/spec/public/property/string_spec.rb +1 -1
- data/spec/public/property/text_spec.rb +6 -3
- data/spec/public/property/time_spec.rb +1 -1
- data/spec/public/property_spec.rb +13 -11
- data/spec/public/resource_spec.rb +43 -1
- data/spec/public/sel_spec.rb +1 -1
- data/spec/public/setup_spec.rb +1 -1
- data/spec/public/shared/collection_shared_spec.rb +6 -1
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +1 -1
- data/spec/semipublic/associations/many_to_many_spec.rb +1 -1
- data/spec/semipublic/associations/many_to_one_spec.rb +1 -1
- data/spec/semipublic/associations/one_to_many_spec.rb +1 -1
- data/spec/semipublic/associations/one_to_one_spec.rb +1 -1
- data/spec/semipublic/associations/relationship_spec.rb +1 -1
- data/spec/semipublic/associations_spec.rb +1 -1
- data/spec/semipublic/collection_spec.rb +1 -1
- data/spec/semipublic/model_spec.rb +1 -1
- data/spec/semipublic/property/binary_spec.rb +1 -1
- data/spec/semipublic/property/boolean_spec.rb +1 -1
- data/spec/semipublic/property/class_spec.rb +1 -1
- data/spec/semipublic/property/date_spec.rb +1 -1
- data/spec/semipublic/property/date_time_spec.rb +1 -1
- data/spec/semipublic/property/decimal_spec.rb +6 -5
- data/spec/semipublic/property/discriminator_spec.rb +1 -1
- data/spec/semipublic/property/float_spec.rb +1 -1
- data/spec/semipublic/property/integer_spec.rb +1 -1
- data/spec/semipublic/property/lookup_spec.rb +8 -5
- data/spec/semipublic/property/serial_spec.rb +1 -1
- data/spec/semipublic/property/string_spec.rb +1 -1
- data/spec/semipublic/property/text_spec.rb +1 -1
- data/spec/semipublic/property/time_spec.rb +1 -1
- data/spec/semipublic/property_spec.rb +32 -7
- data/spec/semipublic/query/conditions/comparison_spec.rb +1 -264
- data/spec/semipublic/query/conditions/operation_spec.rb +1 -2
- data/spec/semipublic/query/path_spec.rb +27 -1
- data/spec/semipublic/query_spec.rb +87 -36
- data/spec/semipublic/resource/state/clean_spec.rb +1 -2
- data/spec/semipublic/resource/state/deleted_spec.rb +1 -2
- data/spec/semipublic/resource/state/dirty_spec.rb +1 -2
- data/spec/semipublic/resource/state/immutable_spec.rb +1 -2
- data/spec/semipublic/resource/state/transient_spec.rb +7 -2
- data/spec/semipublic/resource/state_spec.rb +1 -1
- data/spec/semipublic/resource_spec.rb +1 -1
- data/spec/unit/array_spec.rb +1 -0
- data/spec/unit/data_mapper/ordered_set/append_spec.rb +26 -0
- data/spec/unit/data_mapper/ordered_set/clear_spec.rb +24 -0
- data/spec/unit/data_mapper/ordered_set/delete_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/each_spec.rb +19 -0
- data/spec/unit/data_mapper/ordered_set/empty_spec.rb +20 -0
- data/spec/unit/data_mapper/ordered_set/entries_spec.rb +22 -0
- data/spec/unit/data_mapper/ordered_set/eql_spec.rb +51 -0
- data/spec/unit/data_mapper/ordered_set/equal_value_spec.rb +84 -0
- data/spec/unit/data_mapper/ordered_set/hash_spec.rb +12 -0
- data/spec/unit/data_mapper/ordered_set/include_spec.rb +23 -0
- data/spec/unit/data_mapper/ordered_set/index_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/initialize_spec.rb +32 -0
- data/spec/unit/data_mapper/ordered_set/merge_spec.rb +36 -0
- data/spec/unit/data_mapper/ordered_set/shared/append_spec.rb +24 -0
- data/spec/unit/data_mapper/ordered_set/shared/clear_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/delete_spec.rb +25 -0
- data/spec/unit/data_mapper/ordered_set/shared/each_spec.rb +17 -0
- data/spec/unit/data_mapper/ordered_set/shared/empty_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/entries_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/include_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/index_spec.rb +13 -0
- data/spec/unit/data_mapper/ordered_set/shared/initialize_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/shared/merge_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/shared/size_spec.rb +13 -0
- data/spec/unit/data_mapper/ordered_set/shared/to_ary_spec.rb +11 -0
- data/spec/unit/data_mapper/ordered_set/size_spec.rb +27 -0
- data/spec/unit/data_mapper/ordered_set/to_ary_spec.rb +23 -0
- data/spec/unit/data_mapper/subject_set/append_spec.rb +47 -0
- data/spec/unit/data_mapper/subject_set/clear_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/delete_spec.rb +40 -0
- data/spec/unit/data_mapper/subject_set/each_spec.rb +30 -0
- data/spec/unit/data_mapper/subject_set/empty_spec.rb +31 -0
- data/spec/unit/data_mapper/subject_set/entries_spec.rb +31 -0
- data/spec/unit/data_mapper/subject_set/get_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/include_spec.rb +32 -0
- data/spec/unit/data_mapper/subject_set/named_spec.rb +33 -0
- data/spec/unit/data_mapper/subject_set/shared/append_spec.rb +18 -0
- data/spec/unit/data_mapper/subject_set/shared/clear_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/delete_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/each_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/empty_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/entries_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/get_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/include_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/named_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/size_spec.rb +13 -0
- data/spec/unit/data_mapper/subject_set/shared/to_ary_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/values_at_spec.rb +44 -0
- data/spec/unit/data_mapper/subject_set/size_spec.rb +42 -0
- data/spec/unit/data_mapper/subject_set/to_ary_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/values_at_spec.rb +57 -0
- data/spec/unit/hash_spec.rb +2 -1
- data/spec/unit/hook_spec.rb +1 -0
- data/spec/unit/lazy_array_spec.rb +2 -1
- data/spec/unit/module_spec.rb +2 -1
- data/spec/unit/object_spec.rb +1 -0
- data/spec/unit/try_dup_spec.rb +1 -0
- data/tasks/spec.rake +0 -3
- metadata +149 -52
- data/.gitignore +0 -37
- data/lib/dm-core/type.rb +0 -216
- data/lib/dm-core/types/boolean.rb +0 -9
- data/lib/dm-core/types/decimal.rb +0 -9
- data/lib/dm-core/types/discriminator.rb +0 -50
- data/lib/dm-core/types/object.rb +0 -25
- data/lib/dm-core/types/serial.rb +0 -11
- data/lib/dm-core/types/text.rb +0 -11
- data/tasks/local_gemfile.rake +0 -16
- data/tasks/metrics.rake +0 -37
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/empty_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#empty?' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.empty? }
|
18
|
+
|
19
|
+
context 'with no entries in it' do
|
20
|
+
let(:set) { DataMapper::SubjectSet.new }
|
21
|
+
|
22
|
+
it_should_behave_like 'DataMapper::SubjectSet#empty? with no entries in it'
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with entries in it' do
|
26
|
+
let(:set) { DataMapper::SubjectSet.new([ entry ]) }
|
27
|
+
let(:entry) { Person.new('Alice') }
|
28
|
+
|
29
|
+
it_should_behave_like 'DataMapper::SubjectSet#empty? with entries in it'
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/entries_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#entries' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.entries }
|
18
|
+
|
19
|
+
context 'with no entries' do
|
20
|
+
let(:set) { DataMapper::SubjectSet.new }
|
21
|
+
|
22
|
+
it_should_behave_like 'DataMapper::SubjectSet#entries with no entries'
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with entries' do
|
26
|
+
let(:set) { DataMapper::SubjectSet.new([ entry ]) }
|
27
|
+
let(:entry) { Person.new('Alice') }
|
28
|
+
|
29
|
+
it_should_behave_like 'DataMapper::SubjectSet#entries with entries'
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/get_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#[]' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set[name] }
|
18
|
+
|
19
|
+
let(:set ) { DataMapper::SubjectSet.new(entries) }
|
20
|
+
let(:entry) { Person.new(name) }
|
21
|
+
let(:name ) { 'Alice' }
|
22
|
+
|
23
|
+
context 'when the entry with the given name is not present' do
|
24
|
+
let(:entries) { [] }
|
25
|
+
|
26
|
+
it_should_behave_like 'DataMapper::SubjectSet#[] when the entry with the given name is not present'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when the entry with the given name is present' do
|
30
|
+
let(:entries) { [ entry ] }
|
31
|
+
|
32
|
+
it_should_behave_like 'DataMapper::SubjectSet#[] when the entry with the given name is present'
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/include_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#include?' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.include?(entry) }
|
18
|
+
|
19
|
+
let(:entry) { Person.new('Alice') }
|
20
|
+
|
21
|
+
context 'when the entry is present' do
|
22
|
+
let(:set) { DataMapper::SubjectSet.new([ entry ]) }
|
23
|
+
|
24
|
+
it_should_behave_like 'DataMapper::SubjectSet#include? when the entry is present'
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when the entry is not present' do
|
28
|
+
let(:set) { DataMapper::SubjectSet.new }
|
29
|
+
|
30
|
+
it_should_behave_like 'DataMapper::SubjectSet#include? when the entry is not present'
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/named_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#named?' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.named?(name) }
|
18
|
+
|
19
|
+
let(:entry) { Person.new(name) }
|
20
|
+
let(:name ) { 'Alice' }
|
21
|
+
|
22
|
+
context 'when no entry with the given name is present' do
|
23
|
+
let(:set) { DataMapper::SubjectSet.new([]) }
|
24
|
+
|
25
|
+
it_should_behave_like 'DataMapper::SubjectSet#named? when no entry with the given name is present'
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when an entry with the given name is present' do
|
29
|
+
let(:set) { DataMapper::SubjectSet.new([ entry ]) }
|
30
|
+
|
31
|
+
it_should_behave_like 'DataMapper::SubjectSet#named? when an entry with the given name is present'
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/append_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#<< when appending a not yet included entry' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#<< when appending a not yet included entry'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#<< when updating an entry with the same cache key and the new entry is already included' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#<< when updating an already included entry'
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for 'DataMapper::SubjectSet#<< when updating an entry with the same cache key and the new entry is not yet included' do
|
12
|
+
its(:entries) { should_not include(entry1) }
|
13
|
+
its(:entries) { should include(entry2) }
|
14
|
+
|
15
|
+
it 'should insert the new entry at the old position' do
|
16
|
+
subject.entries.index(entry2).should == @old_index
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/clear_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#clear when no entries are present' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#clear when no entries are present'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#clear when entries are present' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#clear when entries are present'
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/delete_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#delete when deleting an already included entry' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#delete when deleting an already included entry'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#delete when deleting a not yet included entry' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#delete when deleting a not yet included entry'
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/each_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#each' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#each'
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/empty_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#empty? with no entries in it' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#empty? with no entries in it'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#empty? with entries in it' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#empty? with entries in it'
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/entries_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#entries with no entries' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#entries with no entries'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#entries with entries' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#entries with entries'
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#[] when the entry with the given name is not present' do
|
4
|
+
it { should be_nil }
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#[] when the entry with the given name is present' do
|
8
|
+
it { should == entry }
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/include_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#include? when the entry is present' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#include? when the entry is present'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#include? when the entry is not present' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#include? when the entry is not present'
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#named? when no entry with the given name is present' do
|
4
|
+
it { should be(false) }
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#named? when an entry with the given name is present' do
|
8
|
+
it { should be(true) }
|
9
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/size_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#size when no entry is present' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#size when no entry is present'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#size when 1 entry is present' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#size when 1 entry is present'
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for 'DataMapper::SubjectSet#size when more than 1 entry is present' do
|
12
|
+
it_should_behave_like 'DataMapper::OrderedSet#size when more than 1 entry is present'
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit/data_mapper/ordered_set/shared/to_ary_spec'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#to_ary when no entries are present' do
|
4
|
+
it_should_behave_like 'DataMapper::OrderedSet#to_ary when no entries are present'
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'DataMapper::SubjectSet#to_ary when entries are present' do
|
8
|
+
it_should_behave_like 'DataMapper::OrderedSet#to_ary when entries are present'
|
9
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'DataMapper::SubjectSet#values_at when one name is given and no entry with the given name is present' do
|
4
|
+
its(:size) { should == given_names.size }
|
5
|
+
|
6
|
+
it 'should contain nil values for the names not found' do
|
7
|
+
subject.compact.should be_empty
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for 'DataMapper::SubjectSet#values_at when one name is given and an entry with the given name is present' do
|
12
|
+
its(:size) { should == given_names.size }
|
13
|
+
|
14
|
+
it { should include(entry1) }
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples_for 'DataMapper::SubjectSet#values_at when more than one name is given and no entry with any of the given names is present' do
|
18
|
+
its(:size) { should == given_names.size }
|
19
|
+
|
20
|
+
it 'should contain nil values for the names not found' do
|
21
|
+
subject.compact.should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
shared_examples_for 'DataMapper::SubjectSet#values_at when more than one name is given and one entry with one of the given names is present' do
|
26
|
+
it { should include(entry1) }
|
27
|
+
|
28
|
+
its(:size) { should == given_names.size }
|
29
|
+
|
30
|
+
it 'should contain nil values for the names not found' do
|
31
|
+
subject.compact.size.should == 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
shared_examples_for 'DataMapper::SubjectSet#values_at when more than one name is given and an entry for every given name is present' do
|
36
|
+
it { should include(entry1) }
|
37
|
+
it { should include(entry2) }
|
38
|
+
|
39
|
+
its(:size) { should == given_names.size }
|
40
|
+
|
41
|
+
it 'should not contain any nil values' do
|
42
|
+
subject.compact.size.should == given_names.size
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/size_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#size' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.size }
|
18
|
+
|
19
|
+
let(:entry1) { Person.new('Alice') }
|
20
|
+
let(:entry2) { Person.new('Bob' ) }
|
21
|
+
|
22
|
+
context 'when no entry is present' do
|
23
|
+
let(:set) { DataMapper::SubjectSet.new }
|
24
|
+
|
25
|
+
it_should_behave_like 'DataMapper::SubjectSet#size when no entry is present'
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when 1 entry is present' do
|
29
|
+
let(:set) { DataMapper::SubjectSet.new(entries) }
|
30
|
+
let(:entries) { [ entry1 ] }
|
31
|
+
|
32
|
+
it_should_behave_like 'DataMapper::SubjectSet#size when 1 entry is present'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when more than 1 entry is present' do
|
36
|
+
let(:set) { DataMapper::SubjectSet.new(entries) }
|
37
|
+
let(:entries) { [ entry1, entry2 ] }
|
38
|
+
let(:expected_size) { entries.size }
|
39
|
+
|
40
|
+
it_should_behave_like 'DataMapper::SubjectSet#size when more than 1 entry is present'
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/to_ary_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#to_ary' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.to_ary }
|
18
|
+
|
19
|
+
let(:set) { DataMapper::SubjectSet.new(entries) }
|
20
|
+
let(:entry1) { Person.new('Alice') }
|
21
|
+
let(:entry2) { Person.new('Bob' ) }
|
22
|
+
|
23
|
+
context 'when no entries are present' do
|
24
|
+
let(:entries) { [] }
|
25
|
+
|
26
|
+
it_should_behave_like 'DataMapper::SubjectSet#to_ary when no entries are present'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when entries are present' do
|
30
|
+
let(:entries) { [ entry1, entry2 ] }
|
31
|
+
|
32
|
+
it_should_behave_like 'DataMapper::SubjectSet#to_ary when entries are present'
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-core/support/subject_set'
|
3
|
+
require 'unit/data_mapper/subject_set/shared/values_at_spec'
|
4
|
+
|
5
|
+
describe 'DataMapper::SubjectSet#values_at' do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
class ::Person
|
9
|
+
attr_reader :name
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { set.values_at(*given_names) }
|
18
|
+
|
19
|
+
let(:set) { DataMapper::SubjectSet.new(entries) }
|
20
|
+
let(:entry1) { Person.new('Alice') }
|
21
|
+
let(:entry2) { Person.new('Bob' ) }
|
22
|
+
|
23
|
+
context 'when one name is given and no entry with the given name is present' do
|
24
|
+
let(:given_names) { [ 'Alice' ] }
|
25
|
+
let(:entries) { [] }
|
26
|
+
|
27
|
+
it_should_behave_like 'DataMapper::SubjectSet#values_at when one name is given and no entry with the given name is present'
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when one name is given and an entry with the given name is present' do
|
31
|
+
let(:given_names) { [ 'Alice' ] }
|
32
|
+
let(:entries) { [ entry1 ] }
|
33
|
+
|
34
|
+
it_should_behave_like 'DataMapper::SubjectSet#values_at when one name is given and an entry with the given name is present'
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when more than one name is given and no entry with any of the given names is present' do
|
38
|
+
let(:given_names) { [ 'Alice', 'Bob' ] }
|
39
|
+
let(:entries) { [] }
|
40
|
+
|
41
|
+
it_should_behave_like 'DataMapper::SubjectSet#values_at when more than one name is given and no entry with any of the given names is present'
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when more than one name is given and one entry with one of the given names is present' do
|
45
|
+
let(:given_names) { [ 'Alice', 'Bob' ] }
|
46
|
+
let(:entries) { [ entry1 ] }
|
47
|
+
|
48
|
+
it_should_behave_like 'DataMapper::SubjectSet#values_at when more than one name is given and one entry with one of the given names is present'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when more than one name is given and an entry for every given name is present' do
|
52
|
+
let(:given_names) { [ 'Alice', 'Bob' ] }
|
53
|
+
let(:entries) { [ entry1, entry2 ] }
|
54
|
+
|
55
|
+
it_should_behave_like 'DataMapper::SubjectSet#values_at when more than one name is given and an entry for every given name is present'
|
56
|
+
end
|
57
|
+
end
|