ghost_dm-core 1.3.0.beta
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.
- data/.autotest +29 -0
- data/.document +5 -0
- data/.gitignore +35 -0
- data/.yardopts +1 -0
- data/Gemfile +65 -0
- data/LICENSE +20 -0
- data/README.md +269 -0
- data/Rakefile +4 -0
- data/dm-core.gemspec +24 -0
- data/lib/dm-core.rb +292 -0
- data/lib/dm-core/adapters.rb +222 -0
- data/lib/dm-core/adapters/abstract_adapter.rb +237 -0
- data/lib/dm-core/adapters/in_memory_adapter.rb +113 -0
- data/lib/dm-core/associations/many_to_many.rb +499 -0
- data/lib/dm-core/associations/many_to_one.rb +290 -0
- data/lib/dm-core/associations/one_to_many.rb +348 -0
- data/lib/dm-core/associations/one_to_one.rb +86 -0
- data/lib/dm-core/associations/relationship.rb +663 -0
- data/lib/dm-core/backwards.rb +13 -0
- data/lib/dm-core/collection.rb +1515 -0
- data/lib/dm-core/core_ext/kernel.rb +23 -0
- data/lib/dm-core/core_ext/pathname.rb +6 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +7 -0
- data/lib/dm-core/model.rb +874 -0
- data/lib/dm-core/model/hook.rb +103 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +249 -0
- data/lib/dm-core/model/relationship.rb +378 -0
- data/lib/dm-core/model/scope.rb +89 -0
- data/lib/dm-core/property.rb +866 -0
- data/lib/dm-core/property/binary.rb +21 -0
- data/lib/dm-core/property/boolean.rb +20 -0
- data/lib/dm-core/property/class.rb +17 -0
- data/lib/dm-core/property/date.rb +10 -0
- data/lib/dm-core/property/date_time.rb +10 -0
- data/lib/dm-core/property/decimal.rb +36 -0
- data/lib/dm-core/property/discriminator.rb +44 -0
- data/lib/dm-core/property/float.rb +16 -0
- data/lib/dm-core/property/integer.rb +22 -0
- data/lib/dm-core/property/invalid_value_error.rb +22 -0
- data/lib/dm-core/property/lookup.rb +27 -0
- data/lib/dm-core/property/numeric.rb +38 -0
- data/lib/dm-core/property/object.rb +34 -0
- data/lib/dm-core/property/serial.rb +14 -0
- data/lib/dm-core/property/string.rb +38 -0
- data/lib/dm-core/property/text.rb +9 -0
- data/lib/dm-core/property/time.rb +10 -0
- data/lib/dm-core/property_set.rb +177 -0
- data/lib/dm-core/query.rb +1366 -0
- data/lib/dm-core/query/conditions/comparison.rb +911 -0
- data/lib/dm-core/query/conditions/operation.rb +721 -0
- data/lib/dm-core/query/direction.rb +36 -0
- data/lib/dm-core/query/operator.rb +35 -0
- data/lib/dm-core/query/path.rb +114 -0
- data/lib/dm-core/query/sort.rb +39 -0
- data/lib/dm-core/relationship_set.rb +72 -0
- data/lib/dm-core/repository.rb +226 -0
- data/lib/dm-core/resource.rb +1214 -0
- data/lib/dm-core/resource/persistence_state.rb +75 -0
- data/lib/dm-core/resource/persistence_state/clean.rb +40 -0
- data/lib/dm-core/resource/persistence_state/deleted.rb +30 -0
- data/lib/dm-core/resource/persistence_state/dirty.rb +96 -0
- data/lib/dm-core/resource/persistence_state/immutable.rb +34 -0
- data/lib/dm-core/resource/persistence_state/persisted.rb +29 -0
- data/lib/dm-core/resource/persistence_state/transient.rb +80 -0
- data/lib/dm-core/spec/lib/adapter_helpers.rb +64 -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 +174 -0
- data/lib/dm-core/spec/shared/adapter_spec.rb +341 -0
- data/lib/dm-core/spec/shared/public/property_spec.rb +229 -0
- data/lib/dm-core/spec/shared/resource_spec.rb +1232 -0
- data/lib/dm-core/spec/shared/sel_spec.rb +111 -0
- data/lib/dm-core/spec/shared/semipublic/property_spec.rb +176 -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 +405 -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 +90 -0
- data/lib/dm-core/support/ordered_set.rb +380 -0
- data/lib/dm-core/support/subject.rb +33 -0
- data/lib/dm-core/support/subject_set.rb +250 -0
- data/lib/dm-core/version.rb +3 -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 +68 -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 +76 -0
- data/spec/public/model/hook_spec.rb +246 -0
- data/spec/public/model/property_spec.rb +88 -0
- data/spec/public/model/relationship_spec.rb +1040 -0
- data/spec/public/model_spec.rb +462 -0
- data/spec/public/property/binary_spec.rb +41 -0
- data/spec/public/property/boolean_spec.rb +22 -0
- data/spec/public/property/class_spec.rb +28 -0
- data/spec/public/property/date_spec.rb +22 -0
- data/spec/public/property/date_time_spec.rb +22 -0
- data/spec/public/property/decimal_spec.rb +23 -0
- data/spec/public/property/discriminator_spec.rb +135 -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 +107 -0
- data/spec/public/property/serial_spec.rb +22 -0
- data/spec/public/property/string_spec.rb +22 -0
- data/spec/public/property/text_spec.rb +63 -0
- data/spec/public/property/time_spec.rb +22 -0
- data/spec/public/property_spec.rb +341 -0
- data/spec/public/resource_spec.rb +288 -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 +1667 -0
- data/spec/public/shared/finder_shared_spec.rb +1629 -0
- data/spec/rcov.opts +6 -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 +1501 -0
- data/spec/semipublic/query/conditions/operation_spec.rb +1294 -0
- data/spec/semipublic/query/path_spec.rb +471 -0
- data/spec/semipublic/query_spec.rb +3682 -0
- data/spec/semipublic/resource/state/clean_spec.rb +88 -0
- data/spec/semipublic/resource/state/deleted_spec.rb +78 -0
- data/spec/semipublic/resource/state/dirty_spec.rb +162 -0
- data/spec/semipublic/resource/state/immutable_spec.rb +105 -0
- data/spec/semipublic/resource/state/transient_spec.rb +162 -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 +199 -0
- data/spec/semipublic/shared/resource_state_shared_spec.rb +79 -0
- data/spec/semipublic/shared/subject_shared_spec.rb +79 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +38 -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 +28 -0
- data/spec/unit/hook_spec.rb +1235 -0
- data/spec/unit/inflections_spec.rb +16 -0
- data/spec/unit/lazy_array_spec.rb +1949 -0
- data/spec/unit/mash_spec.rb +312 -0
- data/spec/unit/module_spec.rb +71 -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 +38 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +365 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DataMapper::Property::Text do
|
|
4
|
+
before :all do
|
|
5
|
+
@name = :title
|
|
6
|
+
@type = described_class
|
|
7
|
+
@value = 'value'
|
|
8
|
+
@other_value = 'return value'
|
|
9
|
+
@invalid_value = 1
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'A semipublic Property'
|
|
13
|
+
|
|
14
|
+
describe '#load' do
|
|
15
|
+
before :all do
|
|
16
|
+
@value = mock('value')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
subject { @property.load(@value) }
|
|
20
|
+
|
|
21
|
+
before do
|
|
22
|
+
@property = @type.new(@model, @name)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should delegate to #type.load' do
|
|
26
|
+
return_value = mock('return value')
|
|
27
|
+
@property.should_receive(:load).with(@value).and_return(return_value)
|
|
28
|
+
should == return_value
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DataMapper::Property::Time do
|
|
4
|
+
before :all do
|
|
5
|
+
@name = :deleted_at
|
|
6
|
+
@type = described_class
|
|
7
|
+
@value = Time.now
|
|
8
|
+
@other_value = Time.now + 15
|
|
9
|
+
@invalid_value = 1
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'A semipublic Property'
|
|
13
|
+
|
|
14
|
+
describe '#typecast' do
|
|
15
|
+
describe 'and value given as a hash with keys like :year, :month, etc' do
|
|
16
|
+
it 'builds a Time instance from hash values' do
|
|
17
|
+
result = @property.typecast(
|
|
18
|
+
:year => '2006',
|
|
19
|
+
:month => '11',
|
|
20
|
+
:day => '23',
|
|
21
|
+
:hour => '12',
|
|
22
|
+
:min => '0',
|
|
23
|
+
:sec => '0'
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
result.should be_kind_of(Time)
|
|
27
|
+
result.year.should eql(2006)
|
|
28
|
+
result.month.should eql(11)
|
|
29
|
+
result.day.should eql(23)
|
|
30
|
+
result.hour.should eql(12)
|
|
31
|
+
result.min.should eql(0)
|
|
32
|
+
result.sec.should eql(0)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe 'and value is a string' do
|
|
37
|
+
it 'parses the string' do
|
|
38
|
+
result = @property.typecast('22:24')
|
|
39
|
+
result.hour.should eql(22)
|
|
40
|
+
result.min.should eql(24)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'does not typecast non-time values' do
|
|
45
|
+
pending_if 'Time#parse is too permissive', RUBY_VERSION <= '1.9.1' do
|
|
46
|
+
@property.typecast('not-time').should eql('not-time')
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# instance methods
|
|
4
|
+
describe DataMapper::Property do
|
|
5
|
+
describe ".find_class" do
|
|
6
|
+
[ :Serial, :Text ].each do |type|
|
|
7
|
+
describe "with #{type}" do
|
|
8
|
+
subject { DataMapper::Property.find_class(type) }
|
|
9
|
+
|
|
10
|
+
it { subject.should be(DataMapper::Property.const_get(type)) }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe ".determine_class" do
|
|
16
|
+
[ Integer, String, Float, Class, String, Time, DateTime, Date ].each do |type|
|
|
17
|
+
describe "with #{type}" do
|
|
18
|
+
subject { DataMapper::Property.determine_class(type) }
|
|
19
|
+
|
|
20
|
+
it { subject.should be(DataMapper::Property.const_get(type.name)) }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "with property subclasses" do
|
|
25
|
+
before :all do
|
|
26
|
+
Object.send(:remove_const, :CustomProps) if Object.const_defined?(:CustomProps)
|
|
27
|
+
|
|
28
|
+
module ::CustomProps
|
|
29
|
+
module Property
|
|
30
|
+
class Hash < DataMapper::Property::Object; end
|
|
31
|
+
class Other < DataMapper::Property::Object; end
|
|
32
|
+
class Serial < DataMapper::Property::Object; end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "with ::Foo::Property::Hash" do
|
|
38
|
+
subject { DataMapper::Property.determine_class(Hash) }
|
|
39
|
+
|
|
40
|
+
it { subject.should be(::CustomProps::Property::Hash) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "with ::Foo::Property::Other" do
|
|
44
|
+
subject { DataMapper::Property.determine_class(::CustomProps::Property::Other) }
|
|
45
|
+
|
|
46
|
+
it { subject.should be(::CustomProps::Property::Other) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "should always use the DM property when a built-in is referenced indirectly" do
|
|
50
|
+
subject do
|
|
51
|
+
Class.new do
|
|
52
|
+
extend ::DataMapper::Model
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it { subject::Serial.should be(::DataMapper::Property::Serial) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "should always use the custom property when an overridden built-in is directly attached to the model" do
|
|
60
|
+
subject do
|
|
61
|
+
Class.new do
|
|
62
|
+
extend ::DataMapper::Model
|
|
63
|
+
include ::CustomProps::Property
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it { subject::Serial.should be(::CustomProps::Property::Serial) }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
before :all do
|
|
74
|
+
module ::Blog
|
|
75
|
+
class Author
|
|
76
|
+
include DataMapper::Resource
|
|
77
|
+
|
|
78
|
+
property :id, Integer, :key => true
|
|
79
|
+
property :name, String
|
|
80
|
+
property :rating, Float
|
|
81
|
+
property :rate, Decimal, :precision => 5, :scale => 2
|
|
82
|
+
property :type, Class
|
|
83
|
+
property :alias, String
|
|
84
|
+
property :active, Boolean
|
|
85
|
+
property :deleted_at, Time
|
|
86
|
+
property :created_at, DateTime
|
|
87
|
+
property :created_on, Date
|
|
88
|
+
property :info, Text
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
@model = Blog::Author
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe 'override property definition in other repository' do
|
|
96
|
+
before :all do
|
|
97
|
+
module ::Blog
|
|
98
|
+
class Author
|
|
99
|
+
repository(:other) do
|
|
100
|
+
property :name, String, :key => true, :field => 'other_name'
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'should return property options in other repository' do
|
|
107
|
+
@model.properties(:other)[:name].options[:field].should == 'other_name'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'should return property options in default repository' do
|
|
111
|
+
@model.properties[:name].options[:field].should be_nil
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,1501 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
describe DataMapper::Query::Conditions::Comparison do
|
|
3
|
+
before :all do
|
|
4
|
+
module ::Blog
|
|
5
|
+
class Article
|
|
6
|
+
include DataMapper::Resource
|
|
7
|
+
|
|
8
|
+
property :id, Serial
|
|
9
|
+
property :title, String, :required => true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
DataMapper.finalize
|
|
13
|
+
|
|
14
|
+
@model = Blog::Article
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
before :all do
|
|
18
|
+
@property = @model.properties[:id]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it { DataMapper::Query::Conditions::Comparison.should respond_to(:new) }
|
|
22
|
+
|
|
23
|
+
describe '.new' do
|
|
24
|
+
{
|
|
25
|
+
:eql => DataMapper::Query::Conditions::EqualToComparison,
|
|
26
|
+
:in => DataMapper::Query::Conditions::InclusionComparison,
|
|
27
|
+
:regexp => DataMapper::Query::Conditions::RegexpComparison,
|
|
28
|
+
:like => DataMapper::Query::Conditions::LikeComparison,
|
|
29
|
+
:gt => DataMapper::Query::Conditions::GreaterThanComparison,
|
|
30
|
+
:lt => DataMapper::Query::Conditions::LessThanComparison,
|
|
31
|
+
:gte => DataMapper::Query::Conditions::GreaterThanOrEqualToComparison,
|
|
32
|
+
:lte => DataMapper::Query::Conditions::LessThanOrEqualToComparison,
|
|
33
|
+
}.each do |slug, klass|
|
|
34
|
+
describe "with a slug #{slug.inspect}" do
|
|
35
|
+
subject { DataMapper::Query::Conditions::Comparison.new(slug, @property, @value) }
|
|
36
|
+
|
|
37
|
+
it { should be_kind_of(klass) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'with an invalid slug' do
|
|
42
|
+
subject { DataMapper::Query::Conditions::Comparison.new(:invalid, @property, @value) }
|
|
43
|
+
|
|
44
|
+
it { method(:subject).should raise_error(ArgumentError, 'No Comparison class for :invalid has been defined') }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe DataMapper::Query::Conditions::EqualToComparison do
|
|
50
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
51
|
+
|
|
52
|
+
before do
|
|
53
|
+
@property = @model.properties[:id]
|
|
54
|
+
@other_property = @model.properties[:title]
|
|
55
|
+
@value = 1
|
|
56
|
+
@other_value = 2
|
|
57
|
+
@slug = :eql
|
|
58
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
59
|
+
@other = OtherComparison.new(@property, @value)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
subject { @comparison }
|
|
63
|
+
|
|
64
|
+
it { should respond_to(:foreign_key_mapping) }
|
|
65
|
+
|
|
66
|
+
describe '#foreign_key_mapping' do
|
|
67
|
+
supported_by :all do
|
|
68
|
+
before do
|
|
69
|
+
@parent = @model.create(:title => 'Parent')
|
|
70
|
+
@child = @parent.children.create(:title => 'Child')
|
|
71
|
+
|
|
72
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'should return criteria that matches the record' do
|
|
76
|
+
@model.all(:conditions => @comparison.foreign_key_mapping).should == [ @child ]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it { should respond_to(:inspect) }
|
|
82
|
+
|
|
83
|
+
describe '#inspect' do
|
|
84
|
+
subject { @comparison.inspect }
|
|
85
|
+
|
|
86
|
+
it { should == '#<DataMapper::Query::Conditions::EqualToComparison @subject=#<DataMapper::Property::Serial @model=Blog::Article @name=:id> @dumped_value=1 @loaded_value=1>' }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it { should respond_to(:matches?) }
|
|
90
|
+
|
|
91
|
+
describe '#matches?' do
|
|
92
|
+
supported_by :all do
|
|
93
|
+
describe 'with a Property subject' do
|
|
94
|
+
describe 'with an Integer value' do
|
|
95
|
+
describe 'with a matching Hash' do
|
|
96
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
97
|
+
|
|
98
|
+
it { should be(true) }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe 'with a not matching Hash' do
|
|
102
|
+
subject { @comparison.matches?(@property.field => 2) }
|
|
103
|
+
|
|
104
|
+
it { should be(false) }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe 'with a matching Resource' do
|
|
108
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
109
|
+
|
|
110
|
+
it { should be(true) }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe 'with a not matching Resource' do
|
|
114
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
115
|
+
|
|
116
|
+
it { should be(false) }
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe 'with a nil value' do
|
|
121
|
+
before do
|
|
122
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe 'with a matching Hash' do
|
|
126
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
127
|
+
|
|
128
|
+
it { should be(true) }
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
describe 'with a not matching Hash' do
|
|
132
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
133
|
+
|
|
134
|
+
it { should be(false) }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe 'with a matching Resource' do
|
|
138
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
139
|
+
|
|
140
|
+
it { should be(true) }
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
describe 'with a not matching Resource' do
|
|
144
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
145
|
+
|
|
146
|
+
it { should be(false) }
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
describe 'with a Relationship subject' do
|
|
152
|
+
describe 'with a nil value' do
|
|
153
|
+
before do
|
|
154
|
+
@parent = @model.create(:title => 'Parent')
|
|
155
|
+
@child = @parent.children.create(:title => 'Child')
|
|
156
|
+
|
|
157
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, nil)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
describe 'with a matching Hash' do
|
|
161
|
+
subject { @comparison.matches?({ @relationship.field => nil }) }
|
|
162
|
+
|
|
163
|
+
it { should be(true) }
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
describe 'with a not matching Hash' do
|
|
167
|
+
subject { @comparison.matches?({ @relationship.field => {} }) }
|
|
168
|
+
|
|
169
|
+
it { pending { should be(false) } }
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe 'with a matching Resource' do
|
|
173
|
+
subject { @comparison.matches?(@parent) }
|
|
174
|
+
|
|
175
|
+
it { should be(true) }
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
describe 'with a not matching Resource' do
|
|
179
|
+
subject { @comparison.matches?(@child) }
|
|
180
|
+
|
|
181
|
+
it { should be(false) }
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe 'with a Hash value' do
|
|
186
|
+
before do
|
|
187
|
+
@parent = @model.create(:title => 'Parent')
|
|
188
|
+
@child = @parent.children.create(:title => 'Child')
|
|
189
|
+
|
|
190
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent.attributes.except(:id))
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe 'with a matching Hash' do
|
|
194
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
195
|
+
|
|
196
|
+
it { should be(true) }
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
describe 'with a not matching Hash' do
|
|
200
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
201
|
+
|
|
202
|
+
it { pending { should be(false) } }
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
describe 'with a matching Resource' do
|
|
206
|
+
subject { @comparison.matches?(@child) }
|
|
207
|
+
|
|
208
|
+
it { pending { should be(true) } }
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
describe 'with a not matching Resource' do
|
|
212
|
+
subject { @comparison.matches?(@parent) }
|
|
213
|
+
|
|
214
|
+
it { pending { should be(false) } }
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe 'with new Resource value' do
|
|
219
|
+
before do
|
|
220
|
+
@parent = @model.create(:title => 'Parent')
|
|
221
|
+
@child = @parent.children.create(:title => 'Child')
|
|
222
|
+
|
|
223
|
+
new_resource = @model.new(@parent.attributes.except(:id))
|
|
224
|
+
|
|
225
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, new_resource)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
describe 'with a matching Hash' do
|
|
229
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
230
|
+
|
|
231
|
+
it { should be(true) }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
describe 'with a not matching Hash' do
|
|
235
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
236
|
+
|
|
237
|
+
it { pending { should be(false) } }
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
describe 'with a matching Resource' do
|
|
241
|
+
subject { @comparison.matches?(@child) }
|
|
242
|
+
|
|
243
|
+
it { pending { should be(true) } }
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
describe 'with a not matching Resource' do
|
|
247
|
+
subject { @comparison.matches?(@parent) }
|
|
248
|
+
|
|
249
|
+
it { pending { should be(false) } }
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
describe 'with a saved Resource value' do
|
|
254
|
+
before do
|
|
255
|
+
@parent = @model.create(:title => 'Parent')
|
|
256
|
+
@child = @parent.children.create(:title => 'Child')
|
|
257
|
+
|
|
258
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
describe 'with a matching Hash' do
|
|
262
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
263
|
+
|
|
264
|
+
it { pending { should be(true) } }
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
describe 'with a not matching Hash' do
|
|
268
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
269
|
+
|
|
270
|
+
it { should be(false) }
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
describe 'with a matching Resource' do
|
|
274
|
+
subject { @comparison.matches?(@child) }
|
|
275
|
+
|
|
276
|
+
it { should be(true) }
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
describe 'with a not matching Resource' do
|
|
280
|
+
subject { @comparison.matches?(@parent) }
|
|
281
|
+
|
|
282
|
+
it { should be(false) }
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it { should respond_to(:relationship?) }
|
|
290
|
+
|
|
291
|
+
describe '#relationship?' do
|
|
292
|
+
subject { @comparison.relationship? }
|
|
293
|
+
|
|
294
|
+
it { should be(false) }
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it { should respond_to(:to_s) }
|
|
298
|
+
|
|
299
|
+
describe '#to_s' do
|
|
300
|
+
subject { @comparison.to_s }
|
|
301
|
+
|
|
302
|
+
it { should == 'id = 1' }
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it { should respond_to(:value) }
|
|
306
|
+
|
|
307
|
+
describe '#value' do
|
|
308
|
+
supported_by :all do
|
|
309
|
+
subject { @comparison.value }
|
|
310
|
+
|
|
311
|
+
describe 'with a Property subject' do
|
|
312
|
+
describe 'with an Integer value' do
|
|
313
|
+
it { should == @value }
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
describe 'with a nil value' do
|
|
317
|
+
before do
|
|
318
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it { should be_nil }
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
describe 'with a Relationship subject' do
|
|
326
|
+
before :all do
|
|
327
|
+
@parent = @model.create(:title => 'Parent')
|
|
328
|
+
@child = @parent.children.create(:title => 'Child')
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
describe 'with an Hash value' do
|
|
332
|
+
before do
|
|
333
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, :id => 1)
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
it { should == @model.new(:id => 1) }
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
describe 'with a Resource value' do
|
|
340
|
+
before do
|
|
341
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent)
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
it { should == @parent }
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
describe DataMapper::Query::Conditions::InclusionComparison do
|
|
352
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
353
|
+
|
|
354
|
+
before do
|
|
355
|
+
@property = @model.properties[:id]
|
|
356
|
+
@other_property = @model.properties[:title]
|
|
357
|
+
@value = [ 1 ]
|
|
358
|
+
@other_value = [ 2 ]
|
|
359
|
+
@slug = :in
|
|
360
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
361
|
+
@other = OtherComparison.new(@property, @value)
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
subject { @comparison }
|
|
365
|
+
|
|
366
|
+
it { should respond_to(:foreign_key_mapping) }
|
|
367
|
+
|
|
368
|
+
describe '#foreign_key_mapping' do
|
|
369
|
+
supported_by :all do
|
|
370
|
+
before do
|
|
371
|
+
@parent = @model.create(:title => 'Parent')
|
|
372
|
+
@child = @parent.children.create(:title => 'Child')
|
|
373
|
+
|
|
374
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @model.all)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
it 'should return criteria that matches the record' do
|
|
378
|
+
@model.all(:conditions => @comparison.foreign_key_mapping).should == [ @child ]
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
it { should respond_to(:inspect) }
|
|
384
|
+
|
|
385
|
+
describe '#inspect' do
|
|
386
|
+
subject { @comparison.inspect }
|
|
387
|
+
|
|
388
|
+
it { should == '#<DataMapper::Query::Conditions::InclusionComparison @subject=#<DataMapper::Property::Serial @model=Blog::Article @name=:id> @dumped_value=[1] @loaded_value=[1]>' }
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
it { should respond_to(:matches?) }
|
|
392
|
+
|
|
393
|
+
describe '#matches?' do
|
|
394
|
+
supported_by :all do
|
|
395
|
+
describe 'with a Property subject' do
|
|
396
|
+
describe 'with an Array value' do
|
|
397
|
+
describe 'with a matching Hash' do
|
|
398
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
399
|
+
|
|
400
|
+
it { should be(true) }
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
describe 'with a not matching Hash' do
|
|
404
|
+
subject { @comparison.matches?(@property.field => 2) }
|
|
405
|
+
|
|
406
|
+
it { should be(false) }
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
describe 'with a matching Resource' do
|
|
410
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
411
|
+
|
|
412
|
+
it { should be(true) }
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
describe 'with a not matching Resource' do
|
|
416
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
417
|
+
|
|
418
|
+
it { should be(false) }
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
describe 'with an Array value that needs typecasting' do
|
|
423
|
+
before do
|
|
424
|
+
@value = [ '1' ]
|
|
425
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
describe 'with a matching Hash' do
|
|
429
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
430
|
+
|
|
431
|
+
it { should be(true) }
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
describe 'with a not matching Hash' do
|
|
435
|
+
subject { @comparison.matches?(@property.field => 2) }
|
|
436
|
+
|
|
437
|
+
it { should be(false) }
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
describe 'with a matching Resource' do
|
|
441
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
442
|
+
|
|
443
|
+
it { should be(true) }
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
describe 'with a not matching Resource' do
|
|
447
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
448
|
+
|
|
449
|
+
it { should be(false) }
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
describe 'with a Range value' do
|
|
454
|
+
before do
|
|
455
|
+
@value = 1..2
|
|
456
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
describe 'with a matching Hash' do
|
|
460
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
461
|
+
|
|
462
|
+
it { should be(true) }
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
describe 'with a not matching Hash' do
|
|
466
|
+
subject { @comparison.matches?(@property.field => 0) }
|
|
467
|
+
|
|
468
|
+
it { should be(false) }
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
describe 'with a matching Resource' do
|
|
472
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
473
|
+
|
|
474
|
+
it { should be(true) }
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
describe 'with a not matching Resource' do
|
|
478
|
+
subject { @comparison.matches?(@model.new(@property => 0)) }
|
|
479
|
+
|
|
480
|
+
it { should be(false) }
|
|
481
|
+
end
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
describe 'with a Range value that needs typecasting' do
|
|
485
|
+
before do
|
|
486
|
+
@value = '1'...'2'
|
|
487
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
describe 'with a matching Hash' do
|
|
491
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
492
|
+
|
|
493
|
+
it { should be(true) }
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
describe 'with a not matching Hash' do
|
|
497
|
+
subject { @comparison.matches?(@property.field => 2) }
|
|
498
|
+
|
|
499
|
+
it { should be(false) }
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
describe 'with a matching Resource' do
|
|
503
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
504
|
+
|
|
505
|
+
it { should be(true) }
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
describe 'with a not matching Resource' do
|
|
509
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
510
|
+
|
|
511
|
+
it { should be(false) }
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
describe 'with a Relationship subject' do
|
|
517
|
+
describe 'with a Hash value' do
|
|
518
|
+
before do
|
|
519
|
+
@parent = @model.create(:title => 'Parent')
|
|
520
|
+
@child = @parent.children.create(:title => 'Child')
|
|
521
|
+
|
|
522
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent.attributes.except(:id))
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
describe 'with a matching Hash' do
|
|
526
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
527
|
+
|
|
528
|
+
it { pending { should be(true) } }
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
describe 'with a not matching Hash' do
|
|
532
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
533
|
+
|
|
534
|
+
it { should be(false) }
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
describe 'with a matching Resource' do
|
|
538
|
+
subject { @comparison.matches?(@child) }
|
|
539
|
+
|
|
540
|
+
it { should be(true) }
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
describe 'with a not matching Resource' do
|
|
544
|
+
subject { @comparison.matches?(@parent) }
|
|
545
|
+
|
|
546
|
+
it { should be(false) }
|
|
547
|
+
end
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
describe 'with a new Resource value' do
|
|
551
|
+
before do
|
|
552
|
+
@parent = @model.create(:title => 'Parent')
|
|
553
|
+
@child = @parent.children.create(:title => 'Child')
|
|
554
|
+
|
|
555
|
+
new_resource = @model.new(@parent.attributes.except(:id))
|
|
556
|
+
|
|
557
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, new_resource)
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
describe 'with a matching Hash' do
|
|
561
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
562
|
+
|
|
563
|
+
it { should be(true) }
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
describe 'with a not matching Hash' do
|
|
567
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
568
|
+
|
|
569
|
+
it { pending { should be(false) } }
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
describe 'with a matching Resource' do
|
|
573
|
+
subject { @comparison.matches?(@child) }
|
|
574
|
+
|
|
575
|
+
it { pending { should be(true) } }
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
describe 'with a not matching Resource' do
|
|
579
|
+
subject { @comparison.matches?(@parent) }
|
|
580
|
+
|
|
581
|
+
it { pending { should be(false) } }
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
describe 'with a saved Resource value' do
|
|
586
|
+
before do
|
|
587
|
+
@parent = @model.create(:title => 'Parent')
|
|
588
|
+
@child = @parent.children.create(:title => 'Child')
|
|
589
|
+
|
|
590
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent)
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
describe 'with a matching Hash' do
|
|
594
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
595
|
+
|
|
596
|
+
it { pending { should be(true) } }
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
describe 'with a not matching Hash' do
|
|
600
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
601
|
+
|
|
602
|
+
it { should be(false) }
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
describe 'with a matching Resource' do
|
|
606
|
+
subject { @comparison.matches?(@child) }
|
|
607
|
+
|
|
608
|
+
it { should be(true) }
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
describe 'with a not matching Resource' do
|
|
612
|
+
subject { @comparison.matches?(@parent) }
|
|
613
|
+
|
|
614
|
+
it { should be(false) }
|
|
615
|
+
end
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
describe 'with a Collection value' do
|
|
619
|
+
before do
|
|
620
|
+
@parent = @model.create(:title => 'Parent')
|
|
621
|
+
@child = @parent.children.create(:title => 'Child')
|
|
622
|
+
|
|
623
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @model.all(:title => 'Parent'))
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
describe 'with a matching Hash' do
|
|
627
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
628
|
+
|
|
629
|
+
it { pending { should be(true) } }
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
describe 'with a not matching Hash' do
|
|
633
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
634
|
+
|
|
635
|
+
it { should be(false) }
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
describe 'with a matching Resource' do
|
|
639
|
+
subject { @comparison.matches?(@child) }
|
|
640
|
+
|
|
641
|
+
it { should be(true) }
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
describe 'with a not matching Resource' do
|
|
645
|
+
subject { @comparison.matches?(@parent) }
|
|
646
|
+
|
|
647
|
+
it { should be(false) }
|
|
648
|
+
end
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
describe 'with an Enumerable value containing a Hash' do
|
|
652
|
+
before do
|
|
653
|
+
@parent = @model.create(:title => 'Parent')
|
|
654
|
+
@child = @parent.children.create(:title => 'Child')
|
|
655
|
+
|
|
656
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, [ @parent.attributes.except(:id), { :title => 'Other' } ])
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
describe 'with a matching Hash' do
|
|
660
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
661
|
+
|
|
662
|
+
it { pending { should be(true) } }
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
describe 'with a not matching Hash' do
|
|
666
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
667
|
+
|
|
668
|
+
it { should be(false) }
|
|
669
|
+
end
|
|
670
|
+
|
|
671
|
+
describe 'with a matching Resource' do
|
|
672
|
+
subject { @comparison.matches?(@child) }
|
|
673
|
+
|
|
674
|
+
it { should be(true) }
|
|
675
|
+
end
|
|
676
|
+
|
|
677
|
+
describe 'with a not matching Resource' do
|
|
678
|
+
subject { @comparison.matches?(@parent) }
|
|
679
|
+
|
|
680
|
+
it { should be(false) }
|
|
681
|
+
end
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
describe 'with an Enumerable value containing a new Resource' do
|
|
685
|
+
before do
|
|
686
|
+
@parent = @model.create(:title => 'Parent')
|
|
687
|
+
@child = @parent.children.create(:title => 'Child')
|
|
688
|
+
|
|
689
|
+
new_resource = @model.new(@parent.attributes.except(:id))
|
|
690
|
+
|
|
691
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, [ new_resource ])
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
describe 'with a matching Hash' do
|
|
695
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
696
|
+
|
|
697
|
+
it { should be(true) }
|
|
698
|
+
end
|
|
699
|
+
|
|
700
|
+
describe 'with a not matching Hash' do
|
|
701
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
702
|
+
|
|
703
|
+
it { pending { should be(false) } }
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
describe 'with a matching Resource' do
|
|
707
|
+
subject { @comparison.matches?(@child) }
|
|
708
|
+
|
|
709
|
+
it { pending { should be(true) } }
|
|
710
|
+
end
|
|
711
|
+
|
|
712
|
+
describe 'with a not matching Resource' do
|
|
713
|
+
subject { @comparison.matches?(@parent) }
|
|
714
|
+
|
|
715
|
+
it { pending { should be(false) } }
|
|
716
|
+
end
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
describe 'with an Enumerable value containing a saved Resource' do
|
|
720
|
+
before do
|
|
721
|
+
@parent = @model.create(:title => 'Parent')
|
|
722
|
+
@child = @parent.children.create(:title => 'Child')
|
|
723
|
+
|
|
724
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, [ @parent ])
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
describe 'with a matching Hash' do
|
|
728
|
+
subject { @comparison.matches?({ @relationship.field => @parent.attributes(:field) }) }
|
|
729
|
+
|
|
730
|
+
it { pending { should be(true) } }
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
describe 'with a not matching Hash' do
|
|
734
|
+
subject { @comparison.matches?({ @relationship.field => @child.attributes(:field) }) }
|
|
735
|
+
|
|
736
|
+
it { should be(false) }
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
describe 'with a matching Resource' do
|
|
740
|
+
subject { @comparison.matches?(@child) }
|
|
741
|
+
|
|
742
|
+
it { should be(true) }
|
|
743
|
+
end
|
|
744
|
+
|
|
745
|
+
describe 'with a not matching Resource' do
|
|
746
|
+
subject { @comparison.matches?(@parent) }
|
|
747
|
+
|
|
748
|
+
it { should be(false) }
|
|
749
|
+
end
|
|
750
|
+
end
|
|
751
|
+
end
|
|
752
|
+
end
|
|
753
|
+
end
|
|
754
|
+
|
|
755
|
+
it { should respond_to(:relationship?) }
|
|
756
|
+
|
|
757
|
+
describe '#relationship?' do
|
|
758
|
+
subject { @comparison.relationship? }
|
|
759
|
+
|
|
760
|
+
it { should be(false) }
|
|
761
|
+
end
|
|
762
|
+
|
|
763
|
+
it { should respond_to(:to_s) }
|
|
764
|
+
|
|
765
|
+
describe '#to_s' do
|
|
766
|
+
subject { @comparison.to_s }
|
|
767
|
+
|
|
768
|
+
it { should == 'id IN [1]' }
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
it { should respond_to(:valid?) }
|
|
772
|
+
|
|
773
|
+
describe '#valid?' do
|
|
774
|
+
subject { @comparison.valid? }
|
|
775
|
+
|
|
776
|
+
describe 'with a Property subject' do
|
|
777
|
+
describe 'with a valid Array value' do
|
|
778
|
+
it { should be(true) }
|
|
779
|
+
end
|
|
780
|
+
|
|
781
|
+
describe 'with a valid Array value that needs typecasting' do
|
|
782
|
+
before do
|
|
783
|
+
@value = [ '1' ]
|
|
784
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
785
|
+
end
|
|
786
|
+
|
|
787
|
+
it { should be(true) }
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
describe 'with an invalid Array value' do
|
|
791
|
+
before do
|
|
792
|
+
@value = [ 'invalid' ]
|
|
793
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
794
|
+
end
|
|
795
|
+
|
|
796
|
+
it { should be(false) }
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
describe 'with an empty Array value' do
|
|
800
|
+
before do
|
|
801
|
+
@value = []
|
|
802
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
803
|
+
end
|
|
804
|
+
|
|
805
|
+
it { should be(false) }
|
|
806
|
+
end
|
|
807
|
+
|
|
808
|
+
describe 'with a valid Range value' do
|
|
809
|
+
before do
|
|
810
|
+
@value = 1..1
|
|
811
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
812
|
+
end
|
|
813
|
+
|
|
814
|
+
it { should be(true) }
|
|
815
|
+
end
|
|
816
|
+
|
|
817
|
+
describe 'with a valid Range value that needs typecasting' do
|
|
818
|
+
before do
|
|
819
|
+
@value = '1'...'2'
|
|
820
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
821
|
+
end
|
|
822
|
+
|
|
823
|
+
it { should be(true) }
|
|
824
|
+
end
|
|
825
|
+
|
|
826
|
+
describe 'with an invalid Range value' do
|
|
827
|
+
before do
|
|
828
|
+
@value = 'a'..'z'
|
|
829
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
it { should be(false) }
|
|
833
|
+
end
|
|
834
|
+
|
|
835
|
+
describe 'with an empty Range value' do
|
|
836
|
+
before do
|
|
837
|
+
@value = 1..0
|
|
838
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
839
|
+
end
|
|
840
|
+
|
|
841
|
+
it { should be(false) }
|
|
842
|
+
end
|
|
843
|
+
end
|
|
844
|
+
|
|
845
|
+
describe 'with a Relationship subject' do
|
|
846
|
+
supported_by :all do
|
|
847
|
+
describe 'with a valid Array value' do
|
|
848
|
+
before do
|
|
849
|
+
@value = [ @model.new(:id => 1) ]
|
|
850
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @value)
|
|
851
|
+
end
|
|
852
|
+
|
|
853
|
+
it { should be(true) }
|
|
854
|
+
end
|
|
855
|
+
|
|
856
|
+
describe 'with an invalid Array value' do
|
|
857
|
+
before do
|
|
858
|
+
@value = [ @model.new ]
|
|
859
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @value)
|
|
860
|
+
end
|
|
861
|
+
|
|
862
|
+
it { should be(false) }
|
|
863
|
+
end
|
|
864
|
+
|
|
865
|
+
describe 'with an empty Array value' do
|
|
866
|
+
before do
|
|
867
|
+
@value = []
|
|
868
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @value)
|
|
869
|
+
end
|
|
870
|
+
|
|
871
|
+
it { should be(false) }
|
|
872
|
+
end
|
|
873
|
+
|
|
874
|
+
describe 'with a valid Collection' do
|
|
875
|
+
before do
|
|
876
|
+
@value = @model.all
|
|
877
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @value)
|
|
878
|
+
end
|
|
879
|
+
|
|
880
|
+
it { should be(true) }
|
|
881
|
+
end
|
|
882
|
+
end
|
|
883
|
+
end
|
|
884
|
+
end
|
|
885
|
+
|
|
886
|
+
it { should respond_to(:value) }
|
|
887
|
+
|
|
888
|
+
describe '#value' do
|
|
889
|
+
supported_by :all do
|
|
890
|
+
subject { @comparison.value }
|
|
891
|
+
|
|
892
|
+
describe 'with a Property subject' do
|
|
893
|
+
describe 'with an Array value' do
|
|
894
|
+
before do
|
|
895
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, [ 1, 1 ])
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
it { should be_kind_of(Array) }
|
|
899
|
+
|
|
900
|
+
it { should == @value }
|
|
901
|
+
end
|
|
902
|
+
|
|
903
|
+
describe 'with a Range value' do
|
|
904
|
+
before do
|
|
905
|
+
@value = 1..1
|
|
906
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
907
|
+
end
|
|
908
|
+
|
|
909
|
+
it { should be_kind_of(Range) }
|
|
910
|
+
|
|
911
|
+
it { should == @value }
|
|
912
|
+
end
|
|
913
|
+
end
|
|
914
|
+
|
|
915
|
+
describe 'with a Relationship subject' do
|
|
916
|
+
before :all do
|
|
917
|
+
@parent = @model.create(:title => 'Parent')
|
|
918
|
+
@child = @parent.children.create(:title => 'Child')
|
|
919
|
+
end
|
|
920
|
+
|
|
921
|
+
describe 'with an Hash value' do
|
|
922
|
+
before do
|
|
923
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, :id => @parent.id)
|
|
924
|
+
end
|
|
925
|
+
|
|
926
|
+
it { should be_kind_of(DataMapper::Collection) }
|
|
927
|
+
|
|
928
|
+
it { should == [ @parent ] }
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
describe 'with an Array value' do
|
|
932
|
+
before do
|
|
933
|
+
@value = [ @parent ]
|
|
934
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @value)
|
|
935
|
+
end
|
|
936
|
+
|
|
937
|
+
it { should be_kind_of(DataMapper::Collection) }
|
|
938
|
+
|
|
939
|
+
it { should == @value }
|
|
940
|
+
end
|
|
941
|
+
|
|
942
|
+
describe 'with a Resource value' do
|
|
943
|
+
before do
|
|
944
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @parent)
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
it { should be_kind_of(DataMapper::Collection) }
|
|
948
|
+
|
|
949
|
+
it { should == [ @parent ] }
|
|
950
|
+
end
|
|
951
|
+
|
|
952
|
+
describe 'with a Collection value' do
|
|
953
|
+
before do
|
|
954
|
+
@value = @model.all
|
|
955
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @relationship, @value)
|
|
956
|
+
end
|
|
957
|
+
|
|
958
|
+
it 'should not be a kicker' do
|
|
959
|
+
@value.should_not be_loaded
|
|
960
|
+
end
|
|
961
|
+
|
|
962
|
+
it { should be_kind_of(DataMapper::Collection) }
|
|
963
|
+
|
|
964
|
+
it { should == @value }
|
|
965
|
+
end
|
|
966
|
+
end
|
|
967
|
+
end
|
|
968
|
+
end
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
describe DataMapper::Query::Conditions::RegexpComparison do
|
|
972
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
973
|
+
|
|
974
|
+
before do
|
|
975
|
+
@property = @model.properties[:title]
|
|
976
|
+
@other_property = @model.properties[:id]
|
|
977
|
+
@value = /Title/
|
|
978
|
+
@other_value = /Other Title/
|
|
979
|
+
@slug = :regexp
|
|
980
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
981
|
+
@other = OtherComparison.new(@property, @value)
|
|
982
|
+
end
|
|
983
|
+
|
|
984
|
+
subject { @comparison }
|
|
985
|
+
|
|
986
|
+
it { should respond_to(:inspect) }
|
|
987
|
+
|
|
988
|
+
describe '#inspect' do
|
|
989
|
+
subject { @comparison.inspect }
|
|
990
|
+
|
|
991
|
+
it { should == '#<DataMapper::Query::Conditions::RegexpComparison @subject=#<DataMapper::Property::String @model=Blog::Article @name=:title> @dumped_value=/Title/ @loaded_value=/Title/>' }
|
|
992
|
+
end
|
|
993
|
+
|
|
994
|
+
it { should respond_to(:matches?) }
|
|
995
|
+
|
|
996
|
+
describe '#matches?' do
|
|
997
|
+
supported_by :all do
|
|
998
|
+
describe 'with a matching Hash' do
|
|
999
|
+
subject { @comparison.matches?(@property.field => 'Title') }
|
|
1000
|
+
|
|
1001
|
+
it { should be(true) }
|
|
1002
|
+
end
|
|
1003
|
+
|
|
1004
|
+
describe 'with a not matching Hash' do
|
|
1005
|
+
subject { @comparison.matches?(@property.field => 'Other') }
|
|
1006
|
+
|
|
1007
|
+
it { should be(false) }
|
|
1008
|
+
end
|
|
1009
|
+
|
|
1010
|
+
describe 'with a matching Resource' do
|
|
1011
|
+
subject { @comparison.matches?(@model.new(@property => 'Title')) }
|
|
1012
|
+
|
|
1013
|
+
it { should be(true) }
|
|
1014
|
+
end
|
|
1015
|
+
|
|
1016
|
+
describe 'with a not matching Resource' do
|
|
1017
|
+
subject { @comparison.matches?(@model.new(@property => 'Other')) }
|
|
1018
|
+
|
|
1019
|
+
it { should be(false) }
|
|
1020
|
+
end
|
|
1021
|
+
|
|
1022
|
+
describe 'with a not matching nil field' do
|
|
1023
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
1024
|
+
|
|
1025
|
+
it { should be(false) }
|
|
1026
|
+
end
|
|
1027
|
+
|
|
1028
|
+
describe 'with a not matching nil attribute' do
|
|
1029
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
1030
|
+
|
|
1031
|
+
it { should be(false) }
|
|
1032
|
+
end
|
|
1033
|
+
end
|
|
1034
|
+
end
|
|
1035
|
+
|
|
1036
|
+
it { should respond_to(:relationship?) }
|
|
1037
|
+
|
|
1038
|
+
describe '#relationship?' do
|
|
1039
|
+
subject { @comparison.relationship? }
|
|
1040
|
+
|
|
1041
|
+
it { should be(false) }
|
|
1042
|
+
end
|
|
1043
|
+
|
|
1044
|
+
it { should respond_to(:to_s) }
|
|
1045
|
+
|
|
1046
|
+
describe '#to_s' do
|
|
1047
|
+
subject { @comparison.to_s }
|
|
1048
|
+
|
|
1049
|
+
it { should == 'title =~ /Title/' }
|
|
1050
|
+
end
|
|
1051
|
+
end
|
|
1052
|
+
|
|
1053
|
+
describe DataMapper::Query::Conditions::LikeComparison do
|
|
1054
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
1055
|
+
|
|
1056
|
+
before do
|
|
1057
|
+
@property = @model.properties[:title]
|
|
1058
|
+
@other_property = @model.properties[:id]
|
|
1059
|
+
@value = '_it%'
|
|
1060
|
+
@other_value = 'Other Title'
|
|
1061
|
+
@slug = :like
|
|
1062
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
1063
|
+
@other = OtherComparison.new(@property, @value)
|
|
1064
|
+
end
|
|
1065
|
+
|
|
1066
|
+
subject { @comparison }
|
|
1067
|
+
|
|
1068
|
+
it { should respond_to(:inspect) }
|
|
1069
|
+
|
|
1070
|
+
describe '#inspect' do
|
|
1071
|
+
subject { @comparison.inspect }
|
|
1072
|
+
|
|
1073
|
+
it { should == '#<DataMapper::Query::Conditions::LikeComparison @subject=#<DataMapper::Property::String @model=Blog::Article @name=:title> @dumped_value="_it%" @loaded_value="_it%">' }
|
|
1074
|
+
end
|
|
1075
|
+
|
|
1076
|
+
it { should respond_to(:matches?) }
|
|
1077
|
+
|
|
1078
|
+
describe '#matches?' do
|
|
1079
|
+
supported_by :all do
|
|
1080
|
+
describe 'with a matching Hash' do
|
|
1081
|
+
subject { @comparison.matches?(@property.field => 'Title') }
|
|
1082
|
+
|
|
1083
|
+
it { should be(true) }
|
|
1084
|
+
end
|
|
1085
|
+
|
|
1086
|
+
describe 'with a not matching Hash' do
|
|
1087
|
+
subject { @comparison.matches?(@property.field => 'Other Title') }
|
|
1088
|
+
|
|
1089
|
+
it { should be(false) }
|
|
1090
|
+
end
|
|
1091
|
+
|
|
1092
|
+
describe 'with a matching Resource' do
|
|
1093
|
+
subject { @comparison.matches?(@model.new(@property => 'Title')) }
|
|
1094
|
+
|
|
1095
|
+
it { should be(true) }
|
|
1096
|
+
end
|
|
1097
|
+
|
|
1098
|
+
describe 'with a not matching Resource' do
|
|
1099
|
+
subject { @comparison.matches?(@model.new(@property => 'Other Title')) }
|
|
1100
|
+
|
|
1101
|
+
it { should be(false) }
|
|
1102
|
+
end
|
|
1103
|
+
|
|
1104
|
+
describe 'with a not matching nil field' do
|
|
1105
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
1106
|
+
|
|
1107
|
+
it { should be(false) }
|
|
1108
|
+
end
|
|
1109
|
+
|
|
1110
|
+
describe 'with a not matching nil attribute' do
|
|
1111
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
1112
|
+
|
|
1113
|
+
it { should be(false) }
|
|
1114
|
+
end
|
|
1115
|
+
end
|
|
1116
|
+
end
|
|
1117
|
+
|
|
1118
|
+
it { should respond_to(:relationship?) }
|
|
1119
|
+
|
|
1120
|
+
describe '#relationship?' do
|
|
1121
|
+
subject { @comparison.relationship? }
|
|
1122
|
+
|
|
1123
|
+
it { should be(false) }
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
|
+
it { should respond_to(:to_s) }
|
|
1127
|
+
|
|
1128
|
+
describe '#to_s' do
|
|
1129
|
+
subject { @comparison.to_s }
|
|
1130
|
+
|
|
1131
|
+
it { should == 'title LIKE "_it%"' }
|
|
1132
|
+
end
|
|
1133
|
+
end
|
|
1134
|
+
|
|
1135
|
+
describe DataMapper::Query::Conditions::GreaterThanComparison do
|
|
1136
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
1137
|
+
|
|
1138
|
+
before do
|
|
1139
|
+
@property = @model.properties[:id]
|
|
1140
|
+
@other_property = @model.properties[:title]
|
|
1141
|
+
@value = 1
|
|
1142
|
+
@other_value = 2
|
|
1143
|
+
@slug = :gt
|
|
1144
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
1145
|
+
@other = OtherComparison.new(@property, @value)
|
|
1146
|
+
end
|
|
1147
|
+
|
|
1148
|
+
subject { @comparison }
|
|
1149
|
+
|
|
1150
|
+
it { should respond_to(:inspect) }
|
|
1151
|
+
|
|
1152
|
+
describe '#inspect' do
|
|
1153
|
+
subject { @comparison.inspect }
|
|
1154
|
+
|
|
1155
|
+
it { should == '#<DataMapper::Query::Conditions::GreaterThanComparison @subject=#<DataMapper::Property::Serial @model=Blog::Article @name=:id> @dumped_value=1 @loaded_value=1>' }
|
|
1156
|
+
end
|
|
1157
|
+
|
|
1158
|
+
it { should respond_to(:matches?) }
|
|
1159
|
+
|
|
1160
|
+
describe '#matches?' do
|
|
1161
|
+
supported_by :all do
|
|
1162
|
+
describe 'with a matching Hash' do
|
|
1163
|
+
subject { @comparison.matches?(@property.field => 2) }
|
|
1164
|
+
|
|
1165
|
+
it { should be(true) }
|
|
1166
|
+
end
|
|
1167
|
+
|
|
1168
|
+
describe 'with a not matching Hash' do
|
|
1169
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
1170
|
+
|
|
1171
|
+
it { should be(false) }
|
|
1172
|
+
end
|
|
1173
|
+
|
|
1174
|
+
describe 'with a matching Resource' do
|
|
1175
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
1176
|
+
|
|
1177
|
+
it { should be(true) }
|
|
1178
|
+
end
|
|
1179
|
+
|
|
1180
|
+
describe 'with a not matching Resource' do
|
|
1181
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
1182
|
+
|
|
1183
|
+
it { should be(false) }
|
|
1184
|
+
end
|
|
1185
|
+
|
|
1186
|
+
describe 'with a not matching nil field' do
|
|
1187
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
1188
|
+
|
|
1189
|
+
it { should be(false) }
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1192
|
+
describe 'with a not matching nil attribute' do
|
|
1193
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
1194
|
+
|
|
1195
|
+
it { should be(false) }
|
|
1196
|
+
end
|
|
1197
|
+
|
|
1198
|
+
describe 'with an expected value of nil' do
|
|
1199
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
1200
|
+
|
|
1201
|
+
before do
|
|
1202
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
|
|
1203
|
+
end
|
|
1204
|
+
|
|
1205
|
+
it { should be(false) }
|
|
1206
|
+
end
|
|
1207
|
+
end
|
|
1208
|
+
end
|
|
1209
|
+
|
|
1210
|
+
it { should respond_to(:relationship?) }
|
|
1211
|
+
|
|
1212
|
+
describe '#relationship?' do
|
|
1213
|
+
subject { @comparison.relationship? }
|
|
1214
|
+
|
|
1215
|
+
it { should be(false) }
|
|
1216
|
+
end
|
|
1217
|
+
|
|
1218
|
+
it { should respond_to(:to_s) }
|
|
1219
|
+
|
|
1220
|
+
describe '#to_s' do
|
|
1221
|
+
subject { @comparison.to_s }
|
|
1222
|
+
|
|
1223
|
+
it { should == 'id > 1' }
|
|
1224
|
+
end
|
|
1225
|
+
end
|
|
1226
|
+
|
|
1227
|
+
describe DataMapper::Query::Conditions::LessThanComparison do
|
|
1228
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
1229
|
+
|
|
1230
|
+
before do
|
|
1231
|
+
@property = @model.properties[:id]
|
|
1232
|
+
@other_property = @model.properties[:title]
|
|
1233
|
+
@value = 1
|
|
1234
|
+
@other_value = 2
|
|
1235
|
+
@slug = :lt
|
|
1236
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
1237
|
+
@other = OtherComparison.new(@property, @value)
|
|
1238
|
+
end
|
|
1239
|
+
|
|
1240
|
+
subject { @comparison }
|
|
1241
|
+
|
|
1242
|
+
it { should respond_to(:inspect) }
|
|
1243
|
+
|
|
1244
|
+
describe '#inspect' do
|
|
1245
|
+
subject { @comparison.inspect }
|
|
1246
|
+
|
|
1247
|
+
it { should == '#<DataMapper::Query::Conditions::LessThanComparison @subject=#<DataMapper::Property::Serial @model=Blog::Article @name=:id> @dumped_value=1 @loaded_value=1>' }
|
|
1248
|
+
end
|
|
1249
|
+
|
|
1250
|
+
it { should respond_to(:matches?) }
|
|
1251
|
+
|
|
1252
|
+
describe '#matches?' do
|
|
1253
|
+
supported_by :all do
|
|
1254
|
+
describe 'with a matching Hash' do
|
|
1255
|
+
subject { @comparison.matches?(@property.field => 0) }
|
|
1256
|
+
|
|
1257
|
+
it { should be(true) }
|
|
1258
|
+
end
|
|
1259
|
+
|
|
1260
|
+
describe 'with a not matching Hash' do
|
|
1261
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
1262
|
+
|
|
1263
|
+
it { should be(false) }
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1266
|
+
describe 'with a matching Resource' do
|
|
1267
|
+
subject { @comparison.matches?(@model.new(@property => 0)) }
|
|
1268
|
+
|
|
1269
|
+
it { should be(true) }
|
|
1270
|
+
end
|
|
1271
|
+
|
|
1272
|
+
describe 'with a not matching Resource' do
|
|
1273
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
1274
|
+
|
|
1275
|
+
it { should be(false) }
|
|
1276
|
+
end
|
|
1277
|
+
|
|
1278
|
+
describe 'with a not matching nil field' do
|
|
1279
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
1280
|
+
|
|
1281
|
+
it { should be(false) }
|
|
1282
|
+
end
|
|
1283
|
+
|
|
1284
|
+
describe 'with a not matching nil attribute' do
|
|
1285
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
1286
|
+
|
|
1287
|
+
it { should be(false) }
|
|
1288
|
+
end
|
|
1289
|
+
|
|
1290
|
+
describe 'with an expected value of nil' do
|
|
1291
|
+
subject { @comparison.matches?(@model.new(@property => 0)) }
|
|
1292
|
+
|
|
1293
|
+
before do
|
|
1294
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
|
|
1295
|
+
end
|
|
1296
|
+
|
|
1297
|
+
it { should be(false) }
|
|
1298
|
+
end
|
|
1299
|
+
end
|
|
1300
|
+
end
|
|
1301
|
+
|
|
1302
|
+
it { should respond_to(:relationship?) }
|
|
1303
|
+
|
|
1304
|
+
describe '#relationship?' do
|
|
1305
|
+
subject { @comparison.relationship? }
|
|
1306
|
+
|
|
1307
|
+
it { should be(false) }
|
|
1308
|
+
end
|
|
1309
|
+
|
|
1310
|
+
it { should respond_to(:to_s) }
|
|
1311
|
+
|
|
1312
|
+
describe '#to_s' do
|
|
1313
|
+
subject { @comparison.to_s }
|
|
1314
|
+
|
|
1315
|
+
it { should == 'id < 1' }
|
|
1316
|
+
end
|
|
1317
|
+
end
|
|
1318
|
+
|
|
1319
|
+
describe DataMapper::Query::Conditions::GreaterThanOrEqualToComparison do
|
|
1320
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
1321
|
+
|
|
1322
|
+
before do
|
|
1323
|
+
@property = @model.properties[:id]
|
|
1324
|
+
@other_property = @model.properties[:title]
|
|
1325
|
+
@value = 1
|
|
1326
|
+
@other_value = 2
|
|
1327
|
+
@slug = :gte
|
|
1328
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
1329
|
+
@other = OtherComparison.new(@property, @value)
|
|
1330
|
+
end
|
|
1331
|
+
|
|
1332
|
+
subject { @comparison }
|
|
1333
|
+
|
|
1334
|
+
it { should respond_to(:inspect) }
|
|
1335
|
+
|
|
1336
|
+
describe '#inspect' do
|
|
1337
|
+
subject { @comparison.inspect }
|
|
1338
|
+
|
|
1339
|
+
it { should == '#<DataMapper::Query::Conditions::GreaterThanOrEqualToComparison @subject=#<DataMapper::Property::Serial @model=Blog::Article @name=:id> @dumped_value=1 @loaded_value=1>' }
|
|
1340
|
+
end
|
|
1341
|
+
|
|
1342
|
+
it { should respond_to(:matches?) }
|
|
1343
|
+
|
|
1344
|
+
describe '#matches?' do
|
|
1345
|
+
supported_by :all do
|
|
1346
|
+
describe 'with a matching Hash' do
|
|
1347
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
1348
|
+
|
|
1349
|
+
it { should be(true) }
|
|
1350
|
+
end
|
|
1351
|
+
|
|
1352
|
+
describe 'with a not matching Hash' do
|
|
1353
|
+
subject { @comparison.matches?(@property.field => 0) }
|
|
1354
|
+
|
|
1355
|
+
it { should be(false) }
|
|
1356
|
+
end
|
|
1357
|
+
|
|
1358
|
+
describe 'with a matching Resource' do
|
|
1359
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
1360
|
+
|
|
1361
|
+
it { should be(true) }
|
|
1362
|
+
end
|
|
1363
|
+
|
|
1364
|
+
describe 'with a not matching Resource' do
|
|
1365
|
+
subject { @comparison.matches?(@model.new(@property => 0)) }
|
|
1366
|
+
|
|
1367
|
+
it { should be(false) }
|
|
1368
|
+
end
|
|
1369
|
+
|
|
1370
|
+
describe 'with a not matching nil field' do
|
|
1371
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
1372
|
+
|
|
1373
|
+
it { should be(false) }
|
|
1374
|
+
end
|
|
1375
|
+
|
|
1376
|
+
describe 'with a not matching nil attribute' do
|
|
1377
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
1378
|
+
|
|
1379
|
+
it { should be(false) }
|
|
1380
|
+
end
|
|
1381
|
+
|
|
1382
|
+
describe 'with an expected value of nil' do
|
|
1383
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
1384
|
+
|
|
1385
|
+
before do
|
|
1386
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
|
|
1387
|
+
end
|
|
1388
|
+
|
|
1389
|
+
it { should be(false) }
|
|
1390
|
+
end
|
|
1391
|
+
end
|
|
1392
|
+
end
|
|
1393
|
+
|
|
1394
|
+
it { should respond_to(:relationship?) }
|
|
1395
|
+
|
|
1396
|
+
describe '#relationship?' do
|
|
1397
|
+
subject { @comparison.relationship? }
|
|
1398
|
+
|
|
1399
|
+
it { should be(false) }
|
|
1400
|
+
end
|
|
1401
|
+
|
|
1402
|
+
it { should respond_to(:to_s) }
|
|
1403
|
+
|
|
1404
|
+
describe '#to_s' do
|
|
1405
|
+
subject { @comparison.to_s }
|
|
1406
|
+
|
|
1407
|
+
it { should == 'id >= 1' }
|
|
1408
|
+
end
|
|
1409
|
+
end
|
|
1410
|
+
|
|
1411
|
+
describe DataMapper::Query::Conditions::LessThanOrEqualToComparison do
|
|
1412
|
+
it_should_behave_like 'DataMapper::Query::Conditions::AbstractComparison'
|
|
1413
|
+
|
|
1414
|
+
before do
|
|
1415
|
+
@property = @model.properties[:id]
|
|
1416
|
+
@other_property = @model.properties[:title]
|
|
1417
|
+
@value = 1
|
|
1418
|
+
@other_value = 2
|
|
1419
|
+
@slug = :lte
|
|
1420
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, @value)
|
|
1421
|
+
@other = OtherComparison.new(@property, @value)
|
|
1422
|
+
end
|
|
1423
|
+
|
|
1424
|
+
subject { @comparison }
|
|
1425
|
+
|
|
1426
|
+
it { should respond_to(:inspect) }
|
|
1427
|
+
|
|
1428
|
+
describe '#inspect' do
|
|
1429
|
+
subject { @comparison.inspect }
|
|
1430
|
+
|
|
1431
|
+
it { should == '#<DataMapper::Query::Conditions::LessThanOrEqualToComparison @subject=#<DataMapper::Property::Serial @model=Blog::Article @name=:id> @dumped_value=1 @loaded_value=1>' }
|
|
1432
|
+
end
|
|
1433
|
+
|
|
1434
|
+
it { should respond_to(:matches?) }
|
|
1435
|
+
|
|
1436
|
+
describe '#matches?' do
|
|
1437
|
+
supported_by :all do
|
|
1438
|
+
describe 'with a matching Hash' do
|
|
1439
|
+
subject { @comparison.matches?(@property.field => 1) }
|
|
1440
|
+
|
|
1441
|
+
it { should be(true) }
|
|
1442
|
+
end
|
|
1443
|
+
|
|
1444
|
+
describe 'with a not matching Hash' do
|
|
1445
|
+
subject { @comparison.matches?(@property.field => 2) }
|
|
1446
|
+
|
|
1447
|
+
it { should be(false) }
|
|
1448
|
+
end
|
|
1449
|
+
|
|
1450
|
+
describe 'with a matching Resource' do
|
|
1451
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
1452
|
+
|
|
1453
|
+
it { should be(true) }
|
|
1454
|
+
end
|
|
1455
|
+
|
|
1456
|
+
describe 'with a not matching Resource' do
|
|
1457
|
+
subject { @comparison.matches?(@model.new(@property => 2)) }
|
|
1458
|
+
|
|
1459
|
+
it { should be(false) }
|
|
1460
|
+
end
|
|
1461
|
+
|
|
1462
|
+
describe 'with a not matching nil field' do
|
|
1463
|
+
subject { @comparison.matches?(@property.field => nil) }
|
|
1464
|
+
|
|
1465
|
+
it { should be(false) }
|
|
1466
|
+
end
|
|
1467
|
+
|
|
1468
|
+
describe 'with a not matching nil attribute' do
|
|
1469
|
+
subject { @comparison.matches?(@model.new(@property => nil)) }
|
|
1470
|
+
|
|
1471
|
+
it { should be(false) }
|
|
1472
|
+
end
|
|
1473
|
+
|
|
1474
|
+
describe 'with an expected value of nil' do
|
|
1475
|
+
subject { @comparison.matches?(@model.new(@property => 1)) }
|
|
1476
|
+
|
|
1477
|
+
before do
|
|
1478
|
+
@comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
|
|
1479
|
+
end
|
|
1480
|
+
|
|
1481
|
+
it { should be(false) }
|
|
1482
|
+
end
|
|
1483
|
+
end
|
|
1484
|
+
end
|
|
1485
|
+
|
|
1486
|
+
it { should respond_to(:relationship?) }
|
|
1487
|
+
|
|
1488
|
+
describe '#relationship?' do
|
|
1489
|
+
subject { @comparison.relationship? }
|
|
1490
|
+
|
|
1491
|
+
it { should be(false) }
|
|
1492
|
+
end
|
|
1493
|
+
|
|
1494
|
+
it { should respond_to(:to_s) }
|
|
1495
|
+
|
|
1496
|
+
describe '#to_s' do
|
|
1497
|
+
subject { @comparison.to_s }
|
|
1498
|
+
|
|
1499
|
+
it { should == 'id <= 1' }
|
|
1500
|
+
end
|
|
1501
|
+
end
|