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,54 @@
|
|
|
1
|
+
require 'spec/runner/formatter/base_text_formatter'
|
|
2
|
+
|
|
3
|
+
# Code is based on standard SpecdocFormatter, but will print full error details as soon as they are found.
|
|
4
|
+
# Successful or pending examples are written only as a dot in the output. Header is only printed if errors occur.
|
|
5
|
+
#
|
|
6
|
+
# To use it, add the following to your spec/spec.opts:
|
|
7
|
+
# --require
|
|
8
|
+
# lib/rspec_immediate_feedback_formatter.rb
|
|
9
|
+
# --format
|
|
10
|
+
# Spec::Runner::Formatter::ImmediateFeedbackFormatter
|
|
11
|
+
|
|
12
|
+
module Spec
|
|
13
|
+
module Runner
|
|
14
|
+
module Formatter
|
|
15
|
+
class ImmediateFeedbackFormatter < BaseTextFormatter
|
|
16
|
+
|
|
17
|
+
def add_example_group(example_group)
|
|
18
|
+
super
|
|
19
|
+
@current_group = example_group.description
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def example_failed(example, counter, failure)
|
|
23
|
+
if @current_group
|
|
24
|
+
output.puts
|
|
25
|
+
output.puts @current_group
|
|
26
|
+
@current_group = nil # only print the group name once
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
message = if failure.expectation_not_met?
|
|
30
|
+
"- #{example.description} (FAILED - #{counter})"
|
|
31
|
+
else
|
|
32
|
+
"- #{example.description} (ERROR - #{counter})"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
output.puts(red(message))
|
|
36
|
+
# output.puts(failure.expectation_not_met? ? red(message) : message)
|
|
37
|
+
dump_failure(counter, failure) # dump stacktrace immediately
|
|
38
|
+
output.flush
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def example_passed(*)
|
|
42
|
+
output.print green('.')
|
|
43
|
+
output.flush
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def example_pending(*)
|
|
47
|
+
super
|
|
48
|
+
output.print yellow('*')
|
|
49
|
+
output.flush
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
describe 'Many to Many Associations read across multiple join associations' do
|
|
3
|
+
before :all do
|
|
4
|
+
class ::User
|
|
5
|
+
include DataMapper::Resource
|
|
6
|
+
|
|
7
|
+
property :id, Serial
|
|
8
|
+
|
|
9
|
+
has n, :sales
|
|
10
|
+
has n, :sale_items, :through => :sales
|
|
11
|
+
has n, :items, :through => :sale_items
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class ::Sale
|
|
15
|
+
include DataMapper::Resource
|
|
16
|
+
|
|
17
|
+
property :id, Serial
|
|
18
|
+
|
|
19
|
+
belongs_to :user
|
|
20
|
+
has n, :sale_items
|
|
21
|
+
has n, :items, :through => :sale_items
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class ::SaleItem
|
|
25
|
+
include DataMapper::Resource
|
|
26
|
+
|
|
27
|
+
property :id, Serial
|
|
28
|
+
|
|
29
|
+
belongs_to :sale
|
|
30
|
+
belongs_to :item
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class ::Item
|
|
34
|
+
include DataMapper::Resource
|
|
35
|
+
|
|
36
|
+
property :id, Serial
|
|
37
|
+
|
|
38
|
+
has n, :sale_items
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
DataMapper.finalize
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
supported_by :all do
|
|
45
|
+
before :all do
|
|
46
|
+
@user = User.create
|
|
47
|
+
@sale = @user.sales.create
|
|
48
|
+
|
|
49
|
+
5.times { @sale.items.create }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
before :all do
|
|
53
|
+
@no_join = defined?(DataMapper::Adapters::InMemoryAdapter) && @adapter.kind_of?(DataMapper::Adapters::InMemoryAdapter) ||
|
|
54
|
+
defined?(DataMapper::Adapters::YamlAdapter) && @adapter.kind_of?(DataMapper::Adapters::YamlAdapter)
|
|
55
|
+
|
|
56
|
+
@skip = @no_join
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
pending if @skip
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'should return all the created entries' do
|
|
64
|
+
@user.items.to_a.should == Item.all.to_a
|
|
65
|
+
@sale.items.to_a.should == Item.all.to_a
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
share_examples_for 'A Limited Many to Many Collection' do
|
|
4
|
+
describe '#destroy!' do
|
|
5
|
+
describe 'on a limited collection' do
|
|
6
|
+
before :all do
|
|
7
|
+
@other = @articles.create
|
|
8
|
+
@limited = @articles.all(:limit => 1)
|
|
9
|
+
|
|
10
|
+
@return = @limited.destroy!
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'should only remove the join resource for the destroyed resource' do
|
|
14
|
+
@join_model.all.should_not be_empty
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# run the specs once with a loaded association and once not
|
|
21
|
+
[ false, true ].each do |loaded|
|
|
22
|
+
describe 'Many to Many Associations with :through => Resource' do
|
|
23
|
+
extend DataMapper::Spec::CollectionHelpers::GroupMethods
|
|
24
|
+
|
|
25
|
+
self.loaded = loaded
|
|
26
|
+
|
|
27
|
+
# define the model prior to supported_by
|
|
28
|
+
before :all do
|
|
29
|
+
module ::Blog
|
|
30
|
+
class Author
|
|
31
|
+
include DataMapper::Resource
|
|
32
|
+
|
|
33
|
+
property :id, Serial
|
|
34
|
+
property :name, String
|
|
35
|
+
|
|
36
|
+
has n, :articles, :through => Resource
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class Article
|
|
40
|
+
include DataMapper::Resource
|
|
41
|
+
|
|
42
|
+
property :id, Serial
|
|
43
|
+
property :title, String, :required => true
|
|
44
|
+
property :content, Text
|
|
45
|
+
property :subtitle, String
|
|
46
|
+
property :attachment, Object
|
|
47
|
+
|
|
48
|
+
has n, :authors, :through => Resource
|
|
49
|
+
belongs_to :original, self, :required => false
|
|
50
|
+
has n, :revisions, self, :child_key => [ :original_id ]
|
|
51
|
+
has 1, :previous, self, :child_key => [ :original_id ], :order => [ :id.desc ]
|
|
52
|
+
has n, :publications, :through => Resource
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class Publication
|
|
56
|
+
include DataMapper::Resource
|
|
57
|
+
|
|
58
|
+
property :id, Serial
|
|
59
|
+
property :name, String
|
|
60
|
+
|
|
61
|
+
has n, :articles, :through => Resource
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
@author_model = Blog::Author
|
|
66
|
+
@article_model = Blog::Article
|
|
67
|
+
@publication_model = Blog::Publication
|
|
68
|
+
|
|
69
|
+
# initialize the join model
|
|
70
|
+
DataMapper.finalize
|
|
71
|
+
|
|
72
|
+
@join_model = Blog::ArticleAuthor
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
supported_by :all do
|
|
76
|
+
before :all do
|
|
77
|
+
@author = @author_model.create(:name => 'Dan Kubb')
|
|
78
|
+
|
|
79
|
+
@original = @author.articles.create(:title => 'Original Article')
|
|
80
|
+
@article = @author.articles.create(:title => 'Sample Article', :content => 'Sample', :original => @original)
|
|
81
|
+
@other = @author.articles.create(:title => 'Other Article', :content => 'Other')
|
|
82
|
+
|
|
83
|
+
# load the targets without references to a single source
|
|
84
|
+
load_collection = lambda do |query|
|
|
85
|
+
@author_model.get(*@author.key).articles(query)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
@articles = load_collection.call(:title => 'Sample Article')
|
|
89
|
+
@other_articles = load_collection.call(:title => 'Other Article')
|
|
90
|
+
|
|
91
|
+
@articles.entries if loaded
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it_should_behave_like 'A public Collection'
|
|
95
|
+
it_should_behave_like 'A public Association Collection'
|
|
96
|
+
it_should_behave_like 'A Collection supporting Strategic Eager Loading' unless loaded
|
|
97
|
+
it_should_behave_like 'Finder Interface'
|
|
98
|
+
it_should_behave_like 'Collection Finder Interface'
|
|
99
|
+
it_should_behave_like 'A Limited Many to Many Collection'
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe 'Many to Many Associations :through => one_to_many' do
|
|
104
|
+
extend DataMapper::Spec::CollectionHelpers::GroupMethods
|
|
105
|
+
|
|
106
|
+
self.loaded = loaded
|
|
107
|
+
|
|
108
|
+
# define the model prior to supported_by
|
|
109
|
+
before :all do
|
|
110
|
+
module ::Blog
|
|
111
|
+
class Author
|
|
112
|
+
include DataMapper::Resource
|
|
113
|
+
|
|
114
|
+
property :id, Serial
|
|
115
|
+
property :name, String
|
|
116
|
+
|
|
117
|
+
has n, :sites
|
|
118
|
+
has n, :articles, :through => :sites
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
class Site
|
|
122
|
+
include DataMapper::Resource
|
|
123
|
+
|
|
124
|
+
property :name, String, :key => true, :default => 'default'
|
|
125
|
+
|
|
126
|
+
belongs_to :author
|
|
127
|
+
has n, :articles
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
class Article
|
|
131
|
+
include DataMapper::Resource
|
|
132
|
+
|
|
133
|
+
property :id, Serial
|
|
134
|
+
property :title, String, :required => true
|
|
135
|
+
property :content, Text
|
|
136
|
+
property :subtitle, String
|
|
137
|
+
property :attachment, Object
|
|
138
|
+
|
|
139
|
+
property :site_name, String, :default => 'default'
|
|
140
|
+
|
|
141
|
+
belongs_to :site
|
|
142
|
+
has n, :authors, :through => :site
|
|
143
|
+
belongs_to :original, self, :required => false
|
|
144
|
+
has n, :revisions, self, :child_key => [ :original_id ]
|
|
145
|
+
has 1, :previous, self, :child_key => [ :original_id ], :order => [ :id.desc ]
|
|
146
|
+
has n, :publications, :through => Resource
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
class Publication
|
|
150
|
+
include DataMapper::Resource
|
|
151
|
+
|
|
152
|
+
property :id, Serial
|
|
153
|
+
property :name, String
|
|
154
|
+
|
|
155
|
+
has n, :articles, :through => Resource
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
@author_model = Blog::Author
|
|
160
|
+
@article_model = Blog::Article
|
|
161
|
+
@publication_model = Blog::Publication
|
|
162
|
+
|
|
163
|
+
@join_model = Blog::Site
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
supported_by :all do
|
|
167
|
+
before :all do
|
|
168
|
+
@author = @author_model.create(:name => 'Dan Kubb')
|
|
169
|
+
|
|
170
|
+
@original_site = @author.sites.create(:name => 'original')
|
|
171
|
+
@article_site = @author.sites.create(:name => 'article')
|
|
172
|
+
@other_site = @author.sites.create(:name => 'other')
|
|
173
|
+
|
|
174
|
+
@original = @original_site.articles.create(:title => 'Original Article')
|
|
175
|
+
@article = @article_site.articles.create(:title => 'Sample Article', :content => 'Sample', :original => @original)
|
|
176
|
+
@other = @other_site.articles.create(:title => 'Other Article', :content => 'Other')
|
|
177
|
+
|
|
178
|
+
# load the targets without references to a single source
|
|
179
|
+
load_collection = lambda do |query|
|
|
180
|
+
@author_model.get(*@author.key).articles(query)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
@articles = load_collection.call(:title => 'Sample Article')
|
|
184
|
+
@other_articles = load_collection.call(:title => 'Other Article')
|
|
185
|
+
|
|
186
|
+
@articles.entries if loaded
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it_should_behave_like 'A public Collection'
|
|
190
|
+
it_should_behave_like 'A public Association Collection'
|
|
191
|
+
it_should_behave_like 'A Collection supporting Strategic Eager Loading' unless loaded
|
|
192
|
+
it_should_behave_like 'Finder Interface'
|
|
193
|
+
it_should_behave_like 'Collection Finder Interface'
|
|
194
|
+
it_should_behave_like 'A Limited Many to Many Collection'
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Many to One Associations' do
|
|
4
|
+
before :all do
|
|
5
|
+
module ::Blog
|
|
6
|
+
class User
|
|
7
|
+
include DataMapper::Resource
|
|
8
|
+
|
|
9
|
+
property :name, String, :key => true
|
|
10
|
+
property :age, Integer
|
|
11
|
+
property :summary, Text
|
|
12
|
+
property :description, Text
|
|
13
|
+
property :admin, Boolean, :accessor => :private
|
|
14
|
+
|
|
15
|
+
belongs_to :parent, self, :required => false
|
|
16
|
+
has n, :children, self, :inverse => :parent
|
|
17
|
+
|
|
18
|
+
belongs_to :referrer, self, :required => false
|
|
19
|
+
has n, :comments
|
|
20
|
+
|
|
21
|
+
# FIXME: figure out a different approach than stubbing things out
|
|
22
|
+
def comment=(*)
|
|
23
|
+
# do nothing with comment
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Author < User; end
|
|
28
|
+
|
|
29
|
+
class Comment
|
|
30
|
+
include DataMapper::Resource
|
|
31
|
+
|
|
32
|
+
property :id, Serial
|
|
33
|
+
property :body, Text
|
|
34
|
+
|
|
35
|
+
belongs_to :user
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Article
|
|
39
|
+
include DataMapper::Resource
|
|
40
|
+
|
|
41
|
+
property :id, Serial
|
|
42
|
+
property :body, Text
|
|
43
|
+
|
|
44
|
+
has n, :paragraphs
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Paragraph
|
|
48
|
+
include DataMapper::Resource
|
|
49
|
+
|
|
50
|
+
property :id, Serial
|
|
51
|
+
property :text, String
|
|
52
|
+
|
|
53
|
+
belongs_to :article
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class ::Default
|
|
58
|
+
include DataMapper::Resource
|
|
59
|
+
|
|
60
|
+
property :name, String, :key => true, :default => 'a default value'
|
|
61
|
+
end
|
|
62
|
+
DataMapper.finalize
|
|
63
|
+
|
|
64
|
+
@user_model = Blog::User
|
|
65
|
+
@author_model = Blog::Author
|
|
66
|
+
@comment_model = Blog::Comment
|
|
67
|
+
@article_model = Blog::Article
|
|
68
|
+
@paragraph_model = Blog::Paragraph
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
supported_by :all do
|
|
72
|
+
before :all do
|
|
73
|
+
user = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test')
|
|
74
|
+
comment = @comment_model.create(:body => 'Cool spec', :user => user)
|
|
75
|
+
|
|
76
|
+
@comment = @comment_model.get(*comment.key)
|
|
77
|
+
@user = @comment.user
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it_should_behave_like 'A public Resource'
|
|
81
|
+
it_should_behave_like 'A Resource supporting Strategic Eager Loading'
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# TODO: combine this into many_to_one_spec.rb
|
|
4
|
+
|
|
5
|
+
describe 'Many to One Associations when foreign key is part of a composite key, with an integer and a boolean making up the composite key' do
|
|
6
|
+
before :all do
|
|
7
|
+
class ::ManyModel
|
|
8
|
+
include DataMapper::Resource
|
|
9
|
+
|
|
10
|
+
property :integer_key, Integer, :key => true
|
|
11
|
+
property :boolean_key, Boolean, :key => true
|
|
12
|
+
|
|
13
|
+
belongs_to :one_model, :child_key => [ :integer_key ]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class ::OneModel
|
|
17
|
+
include DataMapper::Resource
|
|
18
|
+
|
|
19
|
+
property :integer_key, Integer, :key => true
|
|
20
|
+
|
|
21
|
+
has n, :many_models, :child_key => [ :integer_key ]
|
|
22
|
+
end
|
|
23
|
+
DataMapper.finalize
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
supported_by :all do
|
|
27
|
+
before :all do
|
|
28
|
+
@one = OneModel.create(:integer_key => 1)
|
|
29
|
+
@many = ManyModel.create(:integer_key => 1, :boolean_key => false)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should be able to access parent' do
|
|
33
|
+
@many.one_model.should == @one
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'should be able to access the child' do
|
|
37
|
+
@one.many_models.should == [ @many ]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# TODO: combine this into many_to_one_spec.rb
|
|
4
|
+
|
|
5
|
+
describe 'Many to One Associations when foreign key is a property subclass' do
|
|
6
|
+
before :all do
|
|
7
|
+
class ::CustomPK < DataMapper::Property::String
|
|
8
|
+
key true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ::Animal
|
|
12
|
+
include DataMapper::Resource
|
|
13
|
+
|
|
14
|
+
property :id, Serial
|
|
15
|
+
property :name, String
|
|
16
|
+
|
|
17
|
+
belongs_to :zoo
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class ::Zoo
|
|
21
|
+
include DataMapper::Resource
|
|
22
|
+
|
|
23
|
+
property :id, ::CustomPK
|
|
24
|
+
|
|
25
|
+
has n, :animals
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
DataMapper.finalize
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
supported_by :all do
|
|
32
|
+
before :all do
|
|
33
|
+
@zoo = Zoo.create(:id => 'foo')
|
|
34
|
+
@animal = @zoo.animals.create(:name => 'marty')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'should have FK of the same property type as zoo PK' do
|
|
38
|
+
Animal.properties[:zoo_id].class.should be(Zoo.properties[:id].class)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'should be able to access parent' do
|
|
42
|
+
@animal.zoo.should == @zoo
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'should be able to access the children' do
|
|
46
|
+
@zoo.animals.should == [ @animal ]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|