datamapper-dm-core 0.9.11 → 0.10.0
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 +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -39
- data/Manifest.txt +67 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +16 -15
- data/SPECS +2 -29
- data/TODO +1 -1
- data/dm-core.gemspec +11 -15
- data/lib/dm-core/adapters/abstract_adapter.rb +182 -185
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +560 -158
- data/lib/dm-core/collection.rb +1104 -381
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +248 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/property.rb +753 -280
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query/conditions/comparison.rb +814 -0
- data/lib/dm-core/query/conditions/operation.rb +247 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +42 -0
- data/lib/dm-core/query/path.rb +102 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/query.rb +974 -492
- data/lib/dm-core/repository.rb +147 -107
- data/lib/dm-core/resource.rb +644 -429
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +20 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/equalizer.rb +23 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/lib/dm-core.rb +106 -110
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1723 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +72 -93
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- data/spec/unit/type_spec.rb +0 -119
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '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 :referrer, self, :nullable => true
|
|
16
|
+
has n, :comments
|
|
17
|
+
|
|
18
|
+
# FIXME: figure out a different approach than stubbing things out
|
|
19
|
+
def comment=(*)
|
|
20
|
+
# do nothing with comment
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Author < User; end
|
|
25
|
+
|
|
26
|
+
class Comment
|
|
27
|
+
include DataMapper::Resource
|
|
28
|
+
|
|
29
|
+
property :id, Serial
|
|
30
|
+
property :body, Text
|
|
31
|
+
|
|
32
|
+
belongs_to :user
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Article
|
|
36
|
+
include DataMapper::Resource
|
|
37
|
+
|
|
38
|
+
property :id, Serial
|
|
39
|
+
property :body, Text
|
|
40
|
+
|
|
41
|
+
has n, :paragraphs
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Paragraph
|
|
45
|
+
include DataMapper::Resource
|
|
46
|
+
|
|
47
|
+
property :id, Serial
|
|
48
|
+
property :text, String
|
|
49
|
+
|
|
50
|
+
belongs_to :article
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
@user_model = Blog::User
|
|
55
|
+
@author_model = Blog::Author
|
|
56
|
+
@comment_model = Blog::Comment
|
|
57
|
+
@article_model = Blog::Article
|
|
58
|
+
@paragraph_model = Blog::Paragraph
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
supported_by :all do
|
|
62
|
+
before :all do
|
|
63
|
+
user = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test')
|
|
64
|
+
comment = @comment_model.create(:body => 'Cool spec', :user => user)
|
|
65
|
+
|
|
66
|
+
@comment = @comment_model.get(*comment.key)
|
|
67
|
+
@user = @comment.user
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it_should_behave_like 'A public Resource'
|
|
71
|
+
it_should_behave_like 'A Resource supporting Strategic Eager Loading'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
|
2
|
+
|
|
3
|
+
# run the specs once with a loaded association and once not
|
|
4
|
+
[ false, true ].each do |loaded|
|
|
5
|
+
describe 'One to Many Associations' do
|
|
6
|
+
extend DataMapper::Spec::CollectionHelpers::GroupMethods
|
|
7
|
+
|
|
8
|
+
self.loaded = loaded
|
|
9
|
+
|
|
10
|
+
# define the model prior to supported_by
|
|
11
|
+
before :all do
|
|
12
|
+
module ::Blog
|
|
13
|
+
class Author
|
|
14
|
+
include DataMapper::Resource
|
|
15
|
+
|
|
16
|
+
property :id, Serial
|
|
17
|
+
property :name, String
|
|
18
|
+
|
|
19
|
+
has n, :articles
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Article
|
|
23
|
+
include DataMapper::Resource
|
|
24
|
+
|
|
25
|
+
property :id, Serial
|
|
26
|
+
property :title, String, :nullable => false
|
|
27
|
+
property :content, Text
|
|
28
|
+
property :subtitle, String
|
|
29
|
+
|
|
30
|
+
belongs_to :author, :nullable => true
|
|
31
|
+
belongs_to :original, self, :nullable => true
|
|
32
|
+
has n, :revisions, self, :child_key => [ :original_id ]
|
|
33
|
+
has 1, :previous, self, :child_key => [ :original_id ], :order => [ :id.desc ]
|
|
34
|
+
has n, :publications, :through => Resource
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Publication
|
|
38
|
+
include DataMapper::Resource
|
|
39
|
+
|
|
40
|
+
property :id, Serial
|
|
41
|
+
property :name, String
|
|
42
|
+
|
|
43
|
+
has n, :articles, :through => Resource
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@author_model = Blog::Author
|
|
48
|
+
@article_model = Blog::Article
|
|
49
|
+
@publication_model = Blog::Publication
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
supported_by :all do
|
|
53
|
+
before :all do
|
|
54
|
+
@author = @author_model.create(:name => 'Dan Kubb')
|
|
55
|
+
|
|
56
|
+
@original = @author.articles.create(:title => 'Original Article')
|
|
57
|
+
@article = @author.articles.create(:title => 'Sample Article', :content => 'Sample', :original => @original)
|
|
58
|
+
@other = @author.articles.create(:title => 'Other Article', :content => 'Other')
|
|
59
|
+
|
|
60
|
+
# load the targets without references to a single source
|
|
61
|
+
load_collection = lambda do |query|
|
|
62
|
+
@author_model.get(*@author.key).articles(query)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
@articles = load_collection.call(:title => 'Sample Article')
|
|
66
|
+
@other_articles = load_collection.call(:title => 'Other Article')
|
|
67
|
+
|
|
68
|
+
@articles.entries if loaded
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it_should_behave_like 'A public Collection'
|
|
72
|
+
it_should_behave_like 'A public Association Collection'
|
|
73
|
+
it_should_behave_like 'A Collection supporting Strategic Eager Loading'
|
|
74
|
+
it_should_behave_like 'Finder Interface'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
|
2
|
+
|
|
3
|
+
describe 'One 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 :referrer, self, :nullable => true
|
|
16
|
+
belongs_to :comment
|
|
17
|
+
|
|
18
|
+
# TODO: remove this after Relationship#inverse can dynamically
|
|
19
|
+
# create an inverse relationship when no perfect match can be found
|
|
20
|
+
has n, :referree, self, :child_key => [ :referrer_name ]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Author < User; end
|
|
24
|
+
|
|
25
|
+
class Comment
|
|
26
|
+
include DataMapper::Resource
|
|
27
|
+
|
|
28
|
+
property :id, Serial
|
|
29
|
+
property :body, Text
|
|
30
|
+
|
|
31
|
+
has 1, :user
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Article
|
|
35
|
+
include DataMapper::Resource
|
|
36
|
+
|
|
37
|
+
property :id, Serial
|
|
38
|
+
property :body, Text
|
|
39
|
+
|
|
40
|
+
has 1, :paragraph
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class Paragraph
|
|
44
|
+
include DataMapper::Resource
|
|
45
|
+
|
|
46
|
+
property :id, Serial
|
|
47
|
+
property :text, String
|
|
48
|
+
|
|
49
|
+
belongs_to :article
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
@user_model = Blog::User
|
|
54
|
+
@author_model = Blog::Author
|
|
55
|
+
@comment_model = Blog::Comment
|
|
56
|
+
@article_model = Blog::Article
|
|
57
|
+
@paragraph_model = Blog::Paragraph
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
supported_by :all do
|
|
61
|
+
before :all do
|
|
62
|
+
comment = @comment_model.create(:body => 'Cool spec')
|
|
63
|
+
user = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test', :comment => comment)
|
|
64
|
+
|
|
65
|
+
@comment = @comment_model.get(*comment.key)
|
|
66
|
+
@user = @comment.user
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it_should_behave_like 'A public Resource'
|
|
70
|
+
it_should_behave_like 'A Resource supporting Strategic Eager Loading'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe 'One to One Through Associations' do
|
|
75
|
+
before :all do
|
|
76
|
+
module ::Blog
|
|
77
|
+
class Referral
|
|
78
|
+
include DataMapper::Resource
|
|
79
|
+
|
|
80
|
+
property :referrer_name, String, :key => true
|
|
81
|
+
property :referree_name, String, :key => true
|
|
82
|
+
|
|
83
|
+
belongs_to :referrer, 'User', :child_key => [ :referrer_name ]
|
|
84
|
+
belongs_to :referree, 'User', :child_key => [ :referree_name ]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class User
|
|
88
|
+
include DataMapper::Resource
|
|
89
|
+
|
|
90
|
+
property :name, String, :key => true
|
|
91
|
+
property :age, Integer
|
|
92
|
+
property :summary, Text
|
|
93
|
+
property :description, Text
|
|
94
|
+
property :admin, Boolean, :accessor => :private
|
|
95
|
+
|
|
96
|
+
has 1, :referral_from, Referral, :child_key => [ :referree_name ]
|
|
97
|
+
has 1, :referral_to, Referral, :child_key => [ :referrer_name ]
|
|
98
|
+
|
|
99
|
+
has 1, :referrer, self, :through => :referral_from
|
|
100
|
+
has 1, :referree, self, :through => :referral_to
|
|
101
|
+
has 1, :comment, :through => Resource
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
class Author < User; end
|
|
105
|
+
|
|
106
|
+
class Comment
|
|
107
|
+
include DataMapper::Resource
|
|
108
|
+
|
|
109
|
+
property :id, Serial
|
|
110
|
+
property :body, Text
|
|
111
|
+
|
|
112
|
+
has 1, :user, :through => Resource
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
class Article
|
|
116
|
+
include DataMapper::Resource
|
|
117
|
+
|
|
118
|
+
property :id, Serial
|
|
119
|
+
property :body, Text
|
|
120
|
+
|
|
121
|
+
has 1, :paragraph, :through => Resource
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
class Paragraph
|
|
125
|
+
include DataMapper::Resource
|
|
126
|
+
|
|
127
|
+
property :id, Serial
|
|
128
|
+
property :text, String
|
|
129
|
+
|
|
130
|
+
has 1, :article, :through => Resource
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
@referral_model = Blog::Referral
|
|
135
|
+
@user_model = Blog::User
|
|
136
|
+
@author_model = Blog::Author
|
|
137
|
+
@comment_model = Blog::Comment
|
|
138
|
+
@article_model = Blog::Article
|
|
139
|
+
@paragraph_model = Blog::Paragraph
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
supported_by :all do
|
|
143
|
+
before :all do
|
|
144
|
+
comment = @comment_model.create(:body => 'Cool spec')
|
|
145
|
+
user = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test', :comment => comment)
|
|
146
|
+
|
|
147
|
+
@comment = @comment_model.get(*comment.key)
|
|
148
|
+
@user = @comment.user
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it_should_behave_like 'A public Resource'
|
|
152
|
+
|
|
153
|
+
# TODO: make this pass
|
|
154
|
+
#it_should_behave_like 'A Resource supporting Strategic Eager Loading'
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
2
|
+
|
|
3
|
+
# run the specs once with a loaded collection and once not
|
|
4
|
+
[ false, true ].each do |loaded|
|
|
5
|
+
describe DataMapper::Collection do
|
|
6
|
+
extend DataMapper::Spec::CollectionHelpers::GroupMethods
|
|
7
|
+
|
|
8
|
+
self.loaded = loaded
|
|
9
|
+
|
|
10
|
+
before :all do
|
|
11
|
+
module ::Blog
|
|
12
|
+
class Article
|
|
13
|
+
include DataMapper::Resource
|
|
14
|
+
|
|
15
|
+
property :id, Serial
|
|
16
|
+
property :title, String, :nullable => false
|
|
17
|
+
property :content, Text
|
|
18
|
+
property :subtitle, String
|
|
19
|
+
property :author, String, :nullable => false
|
|
20
|
+
|
|
21
|
+
belongs_to :original, self, :nullable => true
|
|
22
|
+
has n, :revisions, self, :child_key => [ :original_id ]
|
|
23
|
+
has 1, :previous, self, :child_key => [ :original_id ], :order => [ :id.desc ]
|
|
24
|
+
has n, :publications, :through => Resource
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Publication
|
|
28
|
+
include DataMapper::Resource
|
|
29
|
+
|
|
30
|
+
property :id, Serial
|
|
31
|
+
property :name, String
|
|
32
|
+
|
|
33
|
+
has n, :articles, :through => Resource
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
@article_model = Blog::Article
|
|
38
|
+
@publication_model = Blog::Publication
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
supported_by :all do
|
|
42
|
+
before :all do
|
|
43
|
+
@author = 'Dan Kubb'
|
|
44
|
+
|
|
45
|
+
@original = @article_model.create(:title => 'Original Article', :author => @author)
|
|
46
|
+
@article = @article_model.create(:title => 'Sample Article', :content => 'Sample', :original => @original, :author => @author)
|
|
47
|
+
@other = @article_model.create(:title => 'Other Article', :content => 'Other', :author => @author)
|
|
48
|
+
|
|
49
|
+
# load the targets without references to a single source
|
|
50
|
+
load_collection = lambda do |query|
|
|
51
|
+
@article_model.all(query)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
@articles = load_collection.call(:title => 'Sample Article', :author => @author)
|
|
55
|
+
@other_articles = load_collection.call(:title => 'Other Article', :author => @author)
|
|
56
|
+
|
|
57
|
+
@articles.entries if loaded
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it_should_behave_like 'A public Collection'
|
|
61
|
+
it_should_behave_like 'A Collection supporting Strategic Eager Loading'
|
|
62
|
+
it_should_behave_like 'Finder Interface'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|