sbf-dm-core 1.3.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +29 -0
- data/.document +5 -0
- data/.gitignore +44 -0
- data/.rspec +1 -0
- data/.rubocop.yml +468 -0
- data/.travis.yml +57 -0
- data/.yardopts +1 -0
- data/Gemfile +70 -0
- data/LICENSE +20 -0
- data/README.md +269 -0
- data/Rakefile +4 -0
- data/dm-core.gemspec +21 -0
- data/lib/dm-core/adapters/abstract_adapter.rb +233 -0
- data/lib/dm-core/adapters/in_memory_adapter.rb +110 -0
- data/lib/dm-core/adapters.rb +249 -0
- data/lib/dm-core/associations/many_to_many.rb +477 -0
- data/lib/dm-core/associations/many_to_one.rb +282 -0
- data/lib/dm-core/associations/one_to_many.rb +332 -0
- data/lib/dm-core/associations/one_to_one.rb +84 -0
- data/lib/dm-core/associations/relationship.rb +650 -0
- data/lib/dm-core/backwards.rb +11 -0
- data/lib/dm-core/collection.rb +1486 -0
- data/lib/dm-core/core_ext/kernel.rb +21 -0
- data/lib/dm-core/core_ext/pathname.rb +4 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +6 -0
- data/lib/dm-core/model/hook.rb +99 -0
- data/lib/dm-core/model/is.rb +30 -0
- data/lib/dm-core/model/property.rb +244 -0
- data/lib/dm-core/model/relationship.rb +366 -0
- data/lib/dm-core/model/scope.rb +87 -0
- data/lib/dm-core/model.rb +876 -0
- data/lib/dm-core/property/binary.rb +19 -0
- data/lib/dm-core/property/boolean.rb +35 -0
- data/lib/dm-core/property/class.rb +23 -0
- data/lib/dm-core/property/date.rb +45 -0
- data/lib/dm-core/property/date_time.rb +44 -0
- data/lib/dm-core/property/decimal.rb +47 -0
- data/lib/dm-core/property/discriminator.rb +40 -0
- data/lib/dm-core/property/float.rb +27 -0
- data/lib/dm-core/property/integer.rb +32 -0
- data/lib/dm-core/property/invalid_value_error.rb +17 -0
- data/lib/dm-core/property/lookup.rb +26 -0
- data/lib/dm-core/property/numeric.rb +35 -0
- data/lib/dm-core/property/object.rb +33 -0
- data/lib/dm-core/property/serial.rb +13 -0
- data/lib/dm-core/property/string.rb +47 -0
- data/lib/dm-core/property/text.rb +12 -0
- data/lib/dm-core/property/time.rb +46 -0
- data/lib/dm-core/property/typecast/numeric.rb +32 -0
- data/lib/dm-core/property/typecast/time.rb +33 -0
- data/lib/dm-core/property.rb +856 -0
- data/lib/dm-core/property_set.rb +177 -0
- data/lib/dm-core/query/conditions/comparison.rb +886 -0
- data/lib/dm-core/query/conditions/operation.rb +710 -0
- data/lib/dm-core/query/direction.rb +33 -0
- data/lib/dm-core/query/operator.rb +34 -0
- data/lib/dm-core/query/path.rb +113 -0
- data/lib/dm-core/query/sort.rb +38 -0
- data/lib/dm-core/query.rb +1352 -0
- data/lib/dm-core/relationship_set.rb +69 -0
- data/lib/dm-core/repository.rb +226 -0
- data/lib/dm-core/resource/persistence_state/clean.rb +36 -0
- data/lib/dm-core/resource/persistence_state/deleted.rb +26 -0
- data/lib/dm-core/resource/persistence_state/dirty.rb +91 -0
- data/lib/dm-core/resource/persistence_state/immutable.rb +32 -0
- data/lib/dm-core/resource/persistence_state/persisted.rb +25 -0
- data/lib/dm-core/resource/persistence_state/transient.rb +87 -0
- data/lib/dm-core/resource/persistence_state.rb +70 -0
- data/lib/dm-core/resource.rb +1220 -0
- data/lib/dm-core/spec/lib/adapter_helpers.rb +63 -0
- data/lib/dm-core/spec/lib/collection_helpers.rb +21 -0
- data/lib/dm-core/spec/lib/counter_adapter.rb +38 -0
- data/lib/dm-core/spec/lib/pending_helpers.rb +50 -0
- data/lib/dm-core/spec/lib/spec_helper.rb +74 -0
- data/lib/dm-core/spec/setup.rb +164 -0
- data/lib/dm-core/spec/shared/adapter_spec.rb +366 -0
- data/lib/dm-core/spec/shared/public/property_spec.rb +229 -0
- data/lib/dm-core/spec/shared/resource_spec.rb +1221 -0
- data/lib/dm-core/spec/shared/sel_spec.rb +111 -0
- data/lib/dm-core/spec/shared/semipublic/property_spec.rb +184 -0
- data/lib/dm-core/spec/shared/semipublic/query/conditions/abstract_comparison_spec.rb +261 -0
- data/lib/dm-core/support/assertions.rb +8 -0
- data/lib/dm-core/support/chainable.rb +18 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/descendant_set.rb +89 -0
- data/lib/dm-core/support/equalizer.rb +48 -0
- data/lib/dm-core/support/ext/array.rb +22 -0
- data/lib/dm-core/support/ext/blank.rb +25 -0
- data/lib/dm-core/support/ext/hash.rb +67 -0
- data/lib/dm-core/support/ext/module.rb +47 -0
- data/lib/dm-core/support/ext/object.rb +57 -0
- data/lib/dm-core/support/ext/string.rb +24 -0
- data/lib/dm-core/support/ext/try_dup.rb +12 -0
- data/lib/dm-core/support/hook.rb +388 -0
- data/lib/dm-core/support/inflections.rb +60 -0
- data/lib/dm-core/support/inflector/inflections.rb +211 -0
- data/lib/dm-core/support/inflector/methods.rb +151 -0
- data/lib/dm-core/support/lazy_array.rb +451 -0
- data/lib/dm-core/support/local_object_space.rb +13 -0
- data/lib/dm-core/support/logger.rb +201 -0
- data/lib/dm-core/support/mash.rb +176 -0
- data/lib/dm-core/support/naming_conventions.rb +109 -0
- data/lib/dm-core/support/ordered_set.rb +381 -0
- data/lib/dm-core/support/subject.rb +33 -0
- data/lib/dm-core/support/subject_set.rb +251 -0
- data/lib/dm-core/version.rb +3 -0
- data/lib/dm-core.rb +274 -0
- data/script/performance.rb +275 -0
- data/script/profile.rb +218 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +54 -0
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +69 -0
- data/spec/public/associations/many_to_many_spec.rb +197 -0
- data/spec/public/associations/many_to_one_spec.rb +83 -0
- data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +40 -0
- data/spec/public/associations/many_to_one_with_custom_fk_spec.rb +49 -0
- data/spec/public/associations/one_to_many_spec.rb +81 -0
- data/spec/public/associations/one_to_one_spec.rb +176 -0
- data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +46 -0
- data/spec/public/collection_spec.rb +69 -0
- data/spec/public/finalize_spec.rb +77 -0
- data/spec/public/model/hook_spec.rb +245 -0
- data/spec/public/model/property_spec.rb +91 -0
- data/spec/public/model/relationship_spec.rb +1040 -0
- data/spec/public/model_spec.rb +456 -0
- data/spec/public/property/binary_spec.rb +43 -0
- data/spec/public/property/boolean_spec.rb +21 -0
- data/spec/public/property/class_spec.rb +27 -0
- data/spec/public/property/date_spec.rb +21 -0
- data/spec/public/property/date_time_spec.rb +21 -0
- data/spec/public/property/decimal_spec.rb +23 -0
- data/spec/public/property/discriminator_spec.rb +134 -0
- data/spec/public/property/float_spec.rb +22 -0
- data/spec/public/property/integer_spec.rb +22 -0
- data/spec/public/property/object_spec.rb +117 -0
- data/spec/public/property/serial_spec.rb +22 -0
- data/spec/public/property/string_spec.rb +21 -0
- data/spec/public/property/text_spec.rb +62 -0
- data/spec/public/property/time_spec.rb +21 -0
- data/spec/public/property_spec.rb +333 -0
- data/spec/public/resource/state_spec.rb +72 -0
- data/spec/public/resource_spec.rb +289 -0
- data/spec/public/sel_spec.rb +53 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +309 -0
- data/spec/public/shared/collection_finder_shared_spec.rb +267 -0
- data/spec/public/shared/collection_shared_spec.rb +1637 -0
- data/spec/public/shared/finder_shared_spec.rb +1647 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +13 -0
- data/spec/semipublic/associations/many_to_many_spec.rb +94 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +63 -0
- data/spec/semipublic/associations/one_to_many_spec.rb +55 -0
- data/spec/semipublic/associations/one_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +200 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +110 -0
- data/spec/semipublic/model_spec.rb +96 -0
- data/spec/semipublic/property/binary_spec.rb +13 -0
- data/spec/semipublic/property/boolean_spec.rb +47 -0
- data/spec/semipublic/property/class_spec.rb +33 -0
- data/spec/semipublic/property/date_spec.rb +43 -0
- data/spec/semipublic/property/date_time_spec.rb +46 -0
- data/spec/semipublic/property/decimal_spec.rb +83 -0
- data/spec/semipublic/property/discriminator_spec.rb +19 -0
- data/spec/semipublic/property/float_spec.rb +82 -0
- data/spec/semipublic/property/integer_spec.rb +82 -0
- data/spec/semipublic/property/lookup_spec.rb +29 -0
- data/spec/semipublic/property/serial_spec.rb +13 -0
- data/spec/semipublic/property/string_spec.rb +13 -0
- data/spec/semipublic/property/text_spec.rb +31 -0
- data/spec/semipublic/property/time_spec.rb +50 -0
- data/spec/semipublic/property_spec.rb +114 -0
- data/spec/semipublic/query/conditions/comparison_spec.rb +1502 -0
- data/spec/semipublic/query/conditions/operation_spec.rb +1296 -0
- data/spec/semipublic/query/path_spec.rb +471 -0
- data/spec/semipublic/query_spec.rb +3665 -0
- data/spec/semipublic/resource/state/clean_spec.rb +89 -0
- data/spec/semipublic/resource/state/deleted_spec.rb +79 -0
- data/spec/semipublic/resource/state/dirty_spec.rb +163 -0
- data/spec/semipublic/resource/state/immutable_spec.rb +107 -0
- data/spec/semipublic/resource/state/transient_spec.rb +163 -0
- data/spec/semipublic/resource/state_spec.rb +230 -0
- data/spec/semipublic/resource_spec.rb +23 -0
- data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +198 -0
- data/spec/semipublic/shared/resource_state_shared_spec.rb +91 -0
- data/spec/semipublic/shared/subject_shared_spec.rb +79 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/core_ext/hash.rb +10 -0
- data/spec/support/core_ext/inheritable_attributes.rb +46 -0
- data/spec/support/properties/huge_integer.rb +17 -0
- data/spec/unit/array_spec.rb +23 -0
- data/spec/unit/blank_spec.rb +73 -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 +27 -0
- data/spec/unit/hook_spec.rb +1216 -0
- data/spec/unit/inflections_spec.rb +14 -0
- data/spec/unit/lazy_array_spec.rb +1949 -0
- data/spec/unit/mash_spec.rb +289 -0
- data/spec/unit/module_spec.rb +70 -0
- data/spec/unit/object_spec.rb +38 -0
- data/spec/unit/try_dup_spec.rb +46 -0
- data/tasks/ci.rake +1 -0
- data/tasks/spec.rake +18 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +323 -0
@@ -0,0 +1,289 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'dm-core/support/mash'
|
3
|
+
|
4
|
+
class AwesomeHash < Hash
|
5
|
+
end
|
6
|
+
|
7
|
+
describe DataMapper::Mash do
|
8
|
+
before(:each) do
|
9
|
+
@hash = { "mash" => "indifferent", :hash => "different" }
|
10
|
+
@sub = AwesomeHash.new("mash" => "indifferent", :hash => "different")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#initialize' do
|
14
|
+
it 'converts all keys into strings when param is a Hash' do
|
15
|
+
mash = DataMapper::Mash.new(@hash)
|
16
|
+
|
17
|
+
expect(mash.keys.any? { |key| key.is_a?(Symbol) }).to be(false)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'converts all pure Hash values into Mashes if param is a Hash' do
|
21
|
+
mash = DataMapper::Mash.new :hash => @hash
|
22
|
+
|
23
|
+
expect(mash['hash']).to be_an_instance_of(DataMapper::Mash)
|
24
|
+
# sanity check
|
25
|
+
expect(mash['hash']['hash']).to eq 'different'
|
26
|
+
end
|
27
|
+
|
28
|
+
mash = DataMapper::Mash.new :sub => @sub
|
29
|
+
it 'does not convert Hash subclass values into Mashes' do
|
30
|
+
expect(mash['sub']).to be_an_instance_of(AwesomeHash)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'converts all value items if value is an Array' do
|
34
|
+
mash = DataMapper::Mash.new :arry => { :hash => [@hash] }
|
35
|
+
|
36
|
+
expect(mash['arry']).to be_an_instance_of(DataMapper::Mash)
|
37
|
+
# sanity check
|
38
|
+
expect(mash['arry']['hash'].first['hash']).to eq 'different'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'delegates to superclass constructor if param is not a Hash' do
|
42
|
+
mash = DataMapper::Mash.new("dash berlin")
|
43
|
+
|
44
|
+
expect(mash['unexisting key']).to eq 'dash berlin'
|
45
|
+
end
|
46
|
+
end # describe "#initialize"
|
47
|
+
|
48
|
+
describe '#update' do
|
49
|
+
it 'converts all keys into strings when param is a Hash' do
|
50
|
+
mash = DataMapper::Mash.new(@hash)
|
51
|
+
mash.update("starry" => "night")
|
52
|
+
|
53
|
+
expect(mash.keys.any? { |key| key.is_a?(Symbol) }).to be(false)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'converts all Hash values into Mashes if param is a Hash' do
|
57
|
+
mash = DataMapper::Mash.new :hash => @hash
|
58
|
+
mash.update(:hash => { :hash => "is buggy in Ruby 1.8.6" })
|
59
|
+
|
60
|
+
expect(mash['hash']).to be_an_instance_of(DataMapper::Mash)
|
61
|
+
end
|
62
|
+
end # describe "#update"
|
63
|
+
|
64
|
+
describe '#[]=' do
|
65
|
+
it 'converts key into string' do
|
66
|
+
mash = DataMapper::Mash.new(@hash)
|
67
|
+
mash[:hash] = { "starry" => "night" }
|
68
|
+
|
69
|
+
expect(mash.keys.any? { |key| key.is_a?(Symbol) }).to be(false)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'converts all Hash value into Mash' do
|
73
|
+
mash = DataMapper::Mash.new :hash => @hash
|
74
|
+
mash[:hash] = { :hash => "is buggy in Ruby 1.8.6" }
|
75
|
+
|
76
|
+
expect(mash['hash']).to be_an_instance_of(DataMapper::Mash)
|
77
|
+
end
|
78
|
+
end # describe "#[]="
|
79
|
+
|
80
|
+
describe '#key?' do
|
81
|
+
before(:each) do
|
82
|
+
@mash = DataMapper::Mash.new(@hash)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'converts key before lookup' do
|
86
|
+
expect(@mash.key?('mash')).to be(true)
|
87
|
+
expect(@mash.key?(:mash)).to be(true)
|
88
|
+
|
89
|
+
expect(@mash.key?('hash')).to be(true)
|
90
|
+
expect(@mash.key?(:hash)).to be(true)
|
91
|
+
|
92
|
+
expect(@mash.key?(:rainclouds)).to be(false)
|
93
|
+
expect(@mash.key?('rainclouds')).to be(false)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'is aliased as include?' do
|
97
|
+
expect(@mash.include?('mash')).to be(true)
|
98
|
+
expect(@mash.include?(:mash)).to be(true)
|
99
|
+
|
100
|
+
expect(@mash.include?('hash')).to be(true)
|
101
|
+
expect(@mash.include?(:hash)).to be(true)
|
102
|
+
|
103
|
+
expect(@mash.include?(:rainclouds)).to be(false)
|
104
|
+
expect(@mash.include?('rainclouds')).to be(false)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'is aliased as member?' do
|
108
|
+
expect(@mash.member?('mash')).to be(true)
|
109
|
+
expect(@mash.member?(:mash)).to be(true)
|
110
|
+
|
111
|
+
expect(@mash.member?('hash')).to be(true)
|
112
|
+
expect(@mash.member?(:hash)).to be(true)
|
113
|
+
|
114
|
+
expect(@mash.member?(:rainclouds)).to be(false)
|
115
|
+
expect(@mash.member?('rainclouds')).to be(false)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#dup' do
|
120
|
+
it 'returns instance of Mash' do
|
121
|
+
expect(DataMapper::Mash.new(@hash).dup).to be_an_instance_of(DataMapper::Mash)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'preserves keys' do
|
125
|
+
mash = DataMapper::Mash.new(@hash)
|
126
|
+
dup = mash.dup
|
127
|
+
|
128
|
+
expect(mash.keys.sort).to eq dup.keys.sort
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'preserves value' do
|
132
|
+
mash = DataMapper::Mash.new(@hash)
|
133
|
+
dup = mash.dup
|
134
|
+
|
135
|
+
expect(mash.values.sort).to eq dup.values.sort
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#to_hash' do
|
140
|
+
it 'returns instance of Mash' do
|
141
|
+
expect(DataMapper::Mash.new(@hash).to_hash).to be_an_instance_of(Hash)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'preserves keys' do
|
145
|
+
mash = DataMapper::Mash.new(@hash)
|
146
|
+
converted = mash.to_hash
|
147
|
+
|
148
|
+
expect(mash.keys.sort).to eq converted.keys.sort
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'preserves value' do
|
152
|
+
mash = DataMapper::Mash.new(@hash)
|
153
|
+
converted = mash.to_hash
|
154
|
+
|
155
|
+
expect(mash.values.sort).to eq converted.values.sort
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe '#symbolize_keys' do
|
160
|
+
it 'returns instance of Mash' do
|
161
|
+
expect(DataMapper::Mash.new(@hash).symbolize_keys).to be_an_instance_of(Hash)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'converts keys to symbols' do
|
165
|
+
mash = DataMapper::Mash.new(@hash)
|
166
|
+
converted = mash.symbolize_keys
|
167
|
+
|
168
|
+
converted_keys = converted.keys.sort{|k1, k2| k1.to_s <=> k2.to_s}
|
169
|
+
orig_keys = mash.keys.map{|k| k.to_sym}.sort{|i1, i2| i1.to_s <=> i2.to_s}
|
170
|
+
|
171
|
+
expect(converted_keys).to eq orig_keys
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'preserves value' do
|
175
|
+
mash = DataMapper::Mash.new(@hash)
|
176
|
+
converted = mash.symbolize_keys
|
177
|
+
|
178
|
+
expect(mash.values.sort).to eq converted.values.sort
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '#delete' do
|
183
|
+
it 'converts Symbol key into String before deleting' do
|
184
|
+
mash = DataMapper::Mash.new(@hash)
|
185
|
+
|
186
|
+
mash.delete(:hash)
|
187
|
+
expect(mash.key?('hash')).to be(false)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'works with String keys as well' do
|
191
|
+
mash = DataMapper::Mash.new(@hash)
|
192
|
+
|
193
|
+
mash.delete("mash")
|
194
|
+
expect(mash.key?('mash')).to be(false)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe '#except' do
|
199
|
+
it 'converts Symbol key into String before calling super' do
|
200
|
+
mash = DataMapper::Mash.new(@hash)
|
201
|
+
|
202
|
+
hashless_mash = mash.except(:hash)
|
203
|
+
expect(hashless_mash.key?('hash')).to be(false)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'works with String keys as well' do
|
207
|
+
mash = DataMapper::Mash.new(@hash)
|
208
|
+
|
209
|
+
mashless_mash = mash.except("mash")
|
210
|
+
expect(mashless_mash.key?('mash')).to be(false)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'works with multiple keys' do
|
214
|
+
mash = DataMapper::Mash.new(@hash)
|
215
|
+
|
216
|
+
mashless = mash.except("hash", :mash)
|
217
|
+
expect(mashless.key?(:hash)).to be(false)
|
218
|
+
expect(mashless.key?('mash')).to be(false)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'returns a mash' do
|
222
|
+
mash = DataMapper::Mash.new(@hash)
|
223
|
+
|
224
|
+
hashless_mash = mash.except(:hash)
|
225
|
+
expect(hashless_mash.class).to be(DataMapper::Mash)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe '#merge' do
|
230
|
+
before(:each) do
|
231
|
+
@mash = DataMapper::Mash.new(@hash).merge(:no => "in between")
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'returns instance of Mash' do
|
235
|
+
expect(@mash).to be_an_instance_of(DataMapper::Mash)
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'merges in give Hash' do
|
239
|
+
expect(@mash['no']).to eq 'in between'
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe '#fetch' do
|
244
|
+
before(:each) do
|
245
|
+
@mash = DataMapper::Mash.new(@hash).merge(:no => "in between")
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'converts key before fetching' do
|
249
|
+
expect(@mash.fetch('no')).to eq 'in between'
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'returns alternative value if key lookup fails' do
|
253
|
+
expect(@mash.fetch('flying', 'screwdriver')).to eq 'screwdriver'
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#default' do
|
258
|
+
before(:each) do
|
259
|
+
@mash = DataMapper::Mash.new(:yet_another_technical_revolution)
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'returns default value unless key exists in mash' do
|
263
|
+
expect(@mash.default('peak oil is now behind, baby')).to eq :yet_another_technical_revolution
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'returns existing value if key is Symbol and exists in mash' do
|
267
|
+
@mash.update(:no => "in between")
|
268
|
+
expect(@mash.default(:no)).to eq 'in between'
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe '#values_at' do
|
273
|
+
before(:each) do
|
274
|
+
@mash = DataMapper::Mash.new(@hash).merge(:no => "in between")
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'is indifferent to whether keys are strings or symbols' do
|
278
|
+
expect(@mash.values_at('hash', :mash, :no)).to eq ['different', 'indifferent', 'in between']
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe '#stringify_keys!' do
|
283
|
+
it 'returns the mash itself' do
|
284
|
+
mash = DataMapper::Mash.new(@hash)
|
285
|
+
|
286
|
+
expect(mash.stringify_keys!.object_id).to eq mash.object_id
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'dm-core/support/ext/module'
|
3
|
+
|
4
|
+
describe DataMapper::Ext::Module do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
Object.send(:remove_const, :Foo) if defined?(Foo)
|
8
|
+
Object.send(:remove_const, :Baz) if defined?(Baz)
|
9
|
+
Object.send(:remove_const, :Bar) if defined?(Bar)
|
10
|
+
|
11
|
+
module ::Foo
|
12
|
+
module ModBar
|
13
|
+
module Noo
|
14
|
+
module Too
|
15
|
+
module Boo; end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Zed; end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ::Baz; end
|
24
|
+
|
25
|
+
class ::Bar; end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'raises NameError for a missing constant' do
|
29
|
+
expect { DataMapper::Ext::Module.find_const(Foo, 'Moo') }.to raise_error(NameError)
|
30
|
+
expect { DataMapper::Ext::Module.find_const(Object, 'MissingConstant') }.to raise_error(NameError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is able to get a recursive constant' do
|
34
|
+
expect(DataMapper::Ext::Module.find_const(Object, 'Foo::ModBar')).to eq Foo::ModBar
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'ignores get Constants from the Kernel namespace correctly' do
|
38
|
+
expect(DataMapper::Ext::Module.find_const(Object, '::Foo::ModBar')).to eq ::Foo::ModBar
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'finds relative constants' do
|
42
|
+
expect(DataMapper::Ext::Module.find_const(Foo, 'ModBar')).to eq Foo::ModBar
|
43
|
+
expect(DataMapper::Ext::Module.find_const(Foo, 'Baz')).to eq Baz
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'finds sibling constants' do
|
47
|
+
expect(DataMapper::Ext::Module.find_const(Foo::ModBar, 'Zed')).to eq Foo::Zed
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'finds nested constants on nested constants' do
|
51
|
+
expect(DataMapper::Ext::Module.find_const(Foo::ModBar, 'Noo::Too')).to eq Foo::ModBar::Noo::Too
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'finds constants outside of nested constants' do
|
55
|
+
expect(DataMapper::Ext::Module.find_const(Foo::ModBar::Noo::Too, 'Zed')).to eq Foo::Zed
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'is able to find past the second nested level' do
|
59
|
+
expect(DataMapper::Ext::Module.find_const(Foo::ModBar::Noo, 'Too')).to eq Foo::ModBar::Noo::Too
|
60
|
+
expect(DataMapper::Ext::Module.find_const(Foo::ModBar::Noo::Too, 'Boo')).to eq Foo::ModBar::Noo::Too::Boo
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'is able to deal with constants being added and removed' do
|
64
|
+
DataMapper::Ext::Module.find_const(Object, 'Bar') # First we load Bar with find_const
|
65
|
+
Object.module_eval { remove_const('Bar') } # Now we delete it
|
66
|
+
module ::Bar; end; # Now we redefine it
|
67
|
+
expect(DataMapper::Ext::Module.find_const(Object, 'Bar')).to eq Bar
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'dm-core/support/ext/object'
|
3
|
+
|
4
|
+
describe DataMapper::Ext::Object do
|
5
|
+
before :all do
|
6
|
+
Object.send(:remove_const, :HactiveSupport) if defined?(HactiveSupport)
|
7
|
+
module ::HactiveSupport
|
8
|
+
class MemoizeConsideredUseless; end
|
9
|
+
end
|
10
|
+
|
11
|
+
Object.send(:remove_const, :Foo) if defined?(Foo)
|
12
|
+
module ::Foo
|
13
|
+
class Bar; end
|
14
|
+
end
|
15
|
+
|
16
|
+
Object.send(:remove_const, :Oi) if defined?(Oi)
|
17
|
+
class ::Oi
|
18
|
+
attr_accessor :foo
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".full_const_get" do
|
23
|
+
it 'returns constant by FQ name in receiver namespace' do
|
24
|
+
expect(DataMapper::Ext::Object.full_const_get('Oi')).to eq Oi
|
25
|
+
expect(DataMapper::Ext::Object.full_const_get('Foo::Bar')).to eq Foo::Bar
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".full_const_set" do
|
30
|
+
it 'sets constant value by FQ name in receiver namespace' do
|
31
|
+
DataMapper::Ext::Object.full_const_set("HactiveSupport::MCU", HactiveSupport::MemoizeConsideredUseless)
|
32
|
+
|
33
|
+
expect(DataMapper::Ext::Object.full_const_get('HactiveSupport::MCU')).to eq HactiveSupport::MemoizeConsideredUseless
|
34
|
+
expect(DataMapper::Ext::Object.full_const_get(HactiveSupport, 'MCU')).to eq HactiveSupport::MemoizeConsideredUseless
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'dm-core/support/ext/try_dup'
|
3
|
+
|
4
|
+
describe 'try_dup' do
|
5
|
+
it 'returns a duplicate version on regular objects' do
|
6
|
+
obj = Object.new
|
7
|
+
oth = DataMapper::Ext.try_dup(obj)
|
8
|
+
expect(obj).not_to eq oth
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns self on Numerics' do
|
12
|
+
obj = 12
|
13
|
+
oth = DataMapper::Ext.try_dup(obj)
|
14
|
+
expect(obj).to eq oth
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns self on Symbols' do
|
18
|
+
obj = :test
|
19
|
+
oth = DataMapper::Ext.try_dup(obj)
|
20
|
+
expect(obj).to eq oth
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns self on true' do
|
24
|
+
obj = true
|
25
|
+
oth = DataMapper::Ext.try_dup(obj)
|
26
|
+
expect(obj).to eq oth
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns self on false' do
|
30
|
+
obj = false
|
31
|
+
oth = DataMapper::Ext.try_dup(obj)
|
32
|
+
expect(obj).to eq oth
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns self on nil' do
|
36
|
+
obj = nil
|
37
|
+
oth = DataMapper::Ext.try_dup(obj)
|
38
|
+
expect(obj).to eq oth
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns self on modules' do
|
42
|
+
obj = Module.new
|
43
|
+
oth = DataMapper::Ext.try_dup(obj)
|
44
|
+
expect(obj.object_id).to eq oth.object_id
|
45
|
+
end
|
46
|
+
end
|
data/tasks/ci.rake
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
task :ci => [ :verify_measurements, 'spec' ]
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
|
3
|
+
spec_defaults = lambda do |spec|
|
4
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
task(:default).clear
|
9
|
+
task(:spec).clear
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec, &spec_defaults)
|
12
|
+
rescue LoadError
|
13
|
+
task :spec do
|
14
|
+
abort 'rspec is not available. In order to run spec, you must: gem install rspec'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :spec
|
data/tasks/yard.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require 'pathname'
|
3
|
+
require 'yardstick/rake/measurement'
|
4
|
+
require 'yardstick/rake/verify'
|
5
|
+
|
6
|
+
# yardstick_measure task
|
7
|
+
Yardstick::Rake::Measurement.new
|
8
|
+
|
9
|
+
# verify_measurements task
|
10
|
+
Yardstick::Rake::Verify.new do |verify|
|
11
|
+
verify.threshold = 84.3
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
%w[ yardstick_measure verify_measurements ].each do |name|
|
15
|
+
task name.to_s do
|
16
|
+
abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|