common_repository_model 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/common_repository_model.gemspec +0 -1
- data/lib/common_repository_model/collection.rb +23 -17
- data/lib/common_repository_model/test_support.rb +9 -3
- data/lib/common_repository_model/version.rb +1 -1
- data/lib/generators/common_repository_model/collection/templates/collection.rb.erb +4 -1
- data/lib/generators/common_repository_model/collection/templates/collection_factory.rb.erb +1 -1
- data/spec/common_respository_model/area_spec.rb +3 -3
- data/spec/common_respository_model/collection_serializer_spec.rb +4 -2
- data/spec/common_respository_model/collection_spec.rb +13 -32
- data/spec/common_respository_model/data_spec.rb +2 -2
- data/spec/common_respository_model/integration_spec.rb +217 -252
- data/spec/config/predicate_mappings.yml +1 -0
- data/spec/factories/common_repository_model/collection_factory.rb +5 -1
- data/spec/support/spec_models.rb +68 -0
- metadata +4 -18
@@ -24,7 +24,6 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_dependency "activesupport", "~>3.2"
|
25
25
|
gem.add_dependency "activemodel", "~>3.2"
|
26
26
|
gem.add_dependency "builder", "~>3.0"
|
27
|
-
gem.add_dependency "morphine"
|
28
27
|
gem.add_dependency "active_model_serializers"
|
29
28
|
gem.add_runtime_dependency "minitest"
|
30
29
|
gem.add_runtime_dependency "minitest-matchers"
|
@@ -60,9 +60,26 @@ module CommonRepositoryModel
|
|
60
60
|
has_and_belongs_to_many(method_name, options)
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
before_validation :assign_area!, on: :create
|
64
|
+
def assign_area!
|
65
|
+
self.__area =
|
66
|
+
if area
|
67
|
+
CommonRepositoryModel::Area.find(area.pid)
|
68
|
+
else
|
69
|
+
CommonRepositoryModel::Area.find_by_name!(name_of_area_to_assign)
|
70
|
+
end
|
71
|
+
rescue CommonRepositoryModel::ObjectNotFoundError
|
72
|
+
true
|
73
|
+
end
|
74
|
+
protected :assign_area!
|
75
|
+
|
76
|
+
def name_of_area_to_assign
|
77
|
+
'NDLIB'
|
78
|
+
end
|
79
|
+
|
80
|
+
before_validation :register_parent_and_collections, on: :create
|
81
|
+
before_validation :register_parent_and_collections, on: :update
|
64
82
|
def register_parent_and_collections
|
65
|
-
self.__area = CommonRepositoryModel::Area.find(area.pid) if area
|
66
83
|
|
67
84
|
collected_has_members = membership_registry.has_members.
|
68
85
|
collect do |association_name|
|
@@ -74,7 +91,6 @@ module CommonRepositoryModel
|
|
74
91
|
collect do |association_name|
|
75
92
|
public_send(association_name)
|
76
93
|
end.flatten
|
77
|
-
|
78
94
|
self.parent_collections = collected_is_member_of
|
79
95
|
|
80
96
|
true
|
@@ -89,31 +105,21 @@ module CommonRepositoryModel
|
|
89
105
|
parent_collections.collect(&:__area).uniq
|
90
106
|
end
|
91
107
|
|
92
|
-
def area=(an_area)
|
93
|
-
if is_root?
|
94
|
-
self.__area = an_area
|
95
|
-
else
|
96
|
-
self.__area = parent_areas.first
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
108
|
def area
|
101
109
|
if is_root?
|
102
110
|
__area
|
103
111
|
else
|
104
112
|
parent_areas.first
|
105
|
-
end
|
113
|
+
end ||
|
114
|
+
CommonRepositoryModel::Area.find_by_name!(name_of_area_to_assign)
|
115
|
+
rescue CommonRepositoryModel::ObjectNotFoundError
|
116
|
+
nil
|
106
117
|
end
|
107
118
|
|
108
119
|
def area_name
|
109
120
|
area.name
|
110
121
|
end
|
111
122
|
|
112
|
-
include Morphine
|
113
|
-
register :named_area_finder do
|
114
|
-
CommonRepositoryModel::Area.method(:find_by_name!)
|
115
|
-
end
|
116
|
-
|
117
123
|
belongs_to(
|
118
124
|
:__area,
|
119
125
|
class_name:'CommonRepositoryModel::Area',
|
@@ -21,11 +21,17 @@ module CommonRepositoryModel
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def with_persisted_area(name = nil)
|
24
|
+
def with_persisted_area(name = nil, &block)
|
25
25
|
options = {}
|
26
26
|
options[:name] = name if name
|
27
|
-
area =
|
28
|
-
|
27
|
+
area = nil
|
28
|
+
area = CommonRepositoryModel::Area.find_by_name(name) if name
|
29
|
+
area ||= FactoryGirl.create(:common_repository_model_area, options)
|
30
|
+
if block.arity == 1
|
31
|
+
block.call(area)
|
32
|
+
else
|
33
|
+
block.call
|
34
|
+
end
|
29
35
|
ensure
|
30
36
|
area.delete if area
|
31
37
|
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
# `rails generate common_repository_model::collection <%= class_name %>`
|
3
3
|
require 'common_repository_model/collection'
|
4
4
|
class <%= class_name %> < CommonRepositoryModel::Collection
|
5
|
+
# Write the logic for assigning the area
|
6
|
+
def name_of_area_to_assign
|
7
|
+
end
|
5
8
|
|
6
9
|
# ***************************************************************************
|
7
10
|
# ***************************************************************************
|
@@ -29,7 +32,7 @@ class <%= class_name %> < CommonRepositoryModel::Collection
|
|
29
32
|
# is_member_of :containers, type: "Container", property: "is_contained_in"
|
30
33
|
#
|
31
34
|
# For Examples Specs:
|
32
|
-
# https://github.com/ndlib/
|
35
|
+
# https://github.com/ndlib/common_repository_model/blob/master/spec/common_repository_model/integration_spec.rb
|
33
36
|
#
|
34
37
|
|
35
38
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
require 'common_repository_model/test_support'
|
7
7
|
FactoryGirl.define do
|
8
|
-
factory :<%= singular_table_name %>, class: <%= class_name
|
8
|
+
factory :<%= singular_table_name %>, class: <%= class_name %>, parent: :common_repository_model_collection do
|
9
9
|
<% for attribute in attributes -%>
|
10
10
|
<%= attribute.name %> <%= attribute.default.inspect %>
|
11
11
|
<% end -%>
|
@@ -30,9 +30,9 @@ describe CommonRepositoryModel::Area do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe 'integration (with persistence)' do
|
33
|
-
let(:collection) { FactoryGirl.build(:common_repository_model_collection
|
33
|
+
let(:collection) { FactoryGirl.build(:common_repository_model_collection) }
|
34
34
|
it 'should .find_by_name and .find_by_name!' do
|
35
|
-
with_persisted_area do |area|
|
35
|
+
with_persisted_area(collection.name_of_area_to_assign) do |area|
|
36
36
|
CommonRepositoryModel::Area.find_by_name(area.name).must_equal area
|
37
37
|
CommonRepositoryModel::Area.
|
38
38
|
find_by_name("#{area.name}-tmp").must_equal nil
|
@@ -44,7 +44,7 @@ describe CommonRepositoryModel::Area do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
it 'should save' do
|
47
|
-
with_persisted_area do |area|
|
47
|
+
with_persisted_area(collection.name_of_area_to_assign) do |area|
|
48
48
|
# Before we can add a collection, the containing object
|
49
49
|
# must be saved
|
50
50
|
area.collections << collection
|
@@ -9,7 +9,9 @@ describe CommonRepositoryModel::CollectionSerializer do
|
|
9
9
|
let(:json) { JSON.parse(subject.to_json) }
|
10
10
|
let(:root) { json.fetch('collection') }
|
11
11
|
it 'should be JSON' do
|
12
|
-
|
13
|
-
|
12
|
+
with_persisted_area(collection.name_of_area_to_assign) do
|
13
|
+
root.fetch('pid')
|
14
|
+
root.fetch('area').must_equal collection.area.pid
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
@@ -8,22 +8,18 @@ describe CommonRepositoryModel::Collection do
|
|
8
8
|
subject.respond_to?(:area_name)
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'should have #
|
12
|
-
|
13
|
-
subject.named_area_finder.call('NEVER-GONNA_EXIST')
|
14
|
-
}.must_raise CommonRepositoryModel::ObjectNotFoundError
|
11
|
+
it 'should have an #name_of_area_to_assign' do
|
12
|
+
subject.respond_to?(:name_of_area_to_assign)
|
15
13
|
end
|
16
14
|
|
17
15
|
it 'should require an area' do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
subject.area
|
22
|
-
subject.area.must_be_kind_of(CommonRepositoryModel::Area)
|
16
|
+
subject.valid?.must_equal false
|
17
|
+
subject.errors[:area].size.wont_equal 0
|
18
|
+
with_persisted_area(subject.name_of_area_to_assign) do |area|
|
19
|
+
subject.area.must_equal area
|
23
20
|
subject.valid?.must_equal true
|
24
|
-
subject.area = nil
|
25
|
-
subject.valid?.must_equal false
|
26
21
|
end
|
22
|
+
|
27
23
|
end
|
28
24
|
|
29
25
|
describe '#find_or_build_data_for_given_slot_names' do
|
@@ -61,34 +57,19 @@ describe CommonRepositoryModel::Collection do
|
|
61
57
|
|
62
58
|
describe 'integration' do
|
63
59
|
let(:child_collection) {
|
64
|
-
FactoryGirl.build(:common_repository_model_collection
|
60
|
+
FactoryGirl.build(:common_repository_model_collection)
|
65
61
|
}
|
66
62
|
it 'should keep a child collection in the parent collection' do
|
67
|
-
with_persisted_area do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
subject.area = area_1
|
72
|
-
subject.save!
|
73
|
-
|
74
|
-
child_collection.area = area_2
|
75
|
-
|
76
|
-
child_collection.parent_collections += [subject]
|
77
|
-
|
78
|
-
child_collection.area.must_equal subject.area
|
79
|
-
|
80
|
-
child_collection.save!
|
81
|
-
|
82
|
-
child_collection.area.must_equal subject.area
|
83
|
-
end
|
63
|
+
with_persisted_area(subject.name_of_area_to_assign) do
|
64
|
+
subject.save!
|
65
|
+
child_collection.parent_collections += [subject]
|
66
|
+
child_collection.area.must_equal subject.area
|
84
67
|
end
|
85
68
|
end
|
86
69
|
it 'should handle parent/child collection' do
|
87
70
|
# Before we can add a collection, the containing object
|
88
71
|
# must be saved
|
89
|
-
with_persisted_area do
|
90
|
-
subject.area = area
|
91
|
-
child_collection.area = area
|
72
|
+
with_persisted_area(subject.name_of_area_to_assign) do
|
92
73
|
subject.save!
|
93
74
|
subject.child_collections << child_collection
|
94
75
|
subject.save!
|
@@ -32,8 +32,8 @@ describe CommonRepositoryModel::Data do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should save' do
|
35
|
-
with_persisted_area do |area|
|
36
|
-
|
35
|
+
with_persisted_area(collection.name_of_area_to_assign) do |area|
|
36
|
+
|
37
37
|
# Before we can add a collection, the containing object
|
38
38
|
# must be saved
|
39
39
|
collection.save!
|
@@ -1,258 +1,223 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class Clothing < CommonRepositoryModel::Data
|
6
|
-
end
|
7
|
-
|
8
|
-
class Job < CommonRepositoryModel::Collection
|
9
|
-
has_and_belongs_to_many(
|
10
|
-
:people,
|
11
|
-
class_name: 'Person',
|
12
|
-
property: :has_workers,
|
13
|
-
inverse_of: :is_working_as
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
class Family < CommonRepositoryModel::Collection
|
18
|
-
has_members(
|
19
|
-
:family_members,
|
20
|
-
class_name: 'Person',
|
21
|
-
property: :is_family_member_of
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
class Person < CommonRepositoryModel::Collection
|
26
|
-
|
27
|
-
is_member_of(
|
28
|
-
:parents,
|
29
|
-
class_name: 'Person',
|
30
|
-
property: :is_child_of
|
31
|
-
)
|
32
|
-
|
33
|
-
has_members(
|
34
|
-
:children,
|
35
|
-
class_name: 'Person',
|
36
|
-
property: :is_child_of
|
37
|
-
)
|
38
|
-
|
39
|
-
# People can be part of multiple families
|
40
|
-
is_member_of(
|
41
|
-
:families,
|
42
|
-
class_name: 'Family',
|
43
|
-
property: :is_family_member_of
|
44
|
-
)
|
45
|
-
|
46
|
-
has_and_belongs_to_many(
|
47
|
-
:jobs,
|
48
|
-
class_name: 'Job',
|
49
|
-
property: :is_working_as,
|
50
|
-
inverse_of: :has_workers
|
51
|
-
)
|
52
|
-
|
53
|
-
end
|
2
|
+
require_relative '../support/spec_models'
|
54
3
|
|
55
4
|
describe CommonRepositoryModel::Collection do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
vanessa.save
|
80
|
-
rudy.save
|
81
|
-
|
82
|
-
dress.save
|
83
|
-
|
84
|
-
claire.children = [theo,vanessa,rudy]
|
85
|
-
claire.jobs << lawyer
|
86
|
-
claire.families << family
|
87
|
-
claire.data << dress
|
88
|
-
claire.save
|
89
|
-
|
90
|
-
heathcliff.children = [theo,vanessa,rudy]
|
91
|
-
heathcliff.jobs << doctor
|
92
|
-
heathcliff.families << family
|
93
|
-
heathcliff.save
|
94
|
-
|
95
|
-
theo.families << family
|
96
|
-
theo.save
|
97
|
-
vanessa.families << family
|
98
|
-
vanessa.save
|
99
|
-
rudy.families << family
|
100
|
-
rudy.save
|
101
|
-
|
102
|
-
family.family_members = [claire,heathcliff,theo,vanessa,rudy]
|
103
|
-
family.save.must_equal true
|
104
|
-
|
105
|
-
@dress = dress.class.find(dress.pid)
|
106
|
-
@theo = theo.class.find(theo.pid)
|
107
|
-
@family = family.class.find(family.pid)
|
108
|
-
@claire = claire.class.find(claire.pid)
|
109
|
-
@rudy = rudy.class.find(rudy.pid)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'verifies complicated relationships' do
|
113
|
-
verify_initial_relations_for_family
|
114
|
-
verify_initial_relations_for_theo
|
115
|
-
verify_initial_relations_for_claire
|
116
|
-
verify_initial_relations_for_dress
|
117
|
-
|
118
|
-
verify_claire_adding_a_child
|
119
|
-
|
120
|
-
verify_claire_losing_a_child
|
121
|
-
|
122
|
-
verify_rudy_losing_a_parent
|
123
|
-
end
|
124
|
-
|
125
|
-
protected
|
126
|
-
def verify_initial_relations_for_family
|
127
|
-
# We are not storing the RELS-EXT entry on the "container" collection
|
128
|
-
assert_rels_ext(
|
129
|
-
@family,
|
130
|
-
:has_family_members,
|
131
|
-
[]
|
132
|
-
)
|
133
|
-
assert_rels_ext(
|
134
|
-
@family,
|
135
|
-
:has_members,
|
136
|
-
[]
|
137
|
-
)
|
138
|
-
|
139
|
-
# However, we do have access to Family#family_members
|
140
|
-
assert_active_fedora_has_many(
|
141
|
-
@family,
|
142
|
-
:family_members,
|
143
|
-
[@theo,@claire, heathcliff,rudy, vanessa]
|
144
|
-
)
|
145
|
-
|
146
|
-
assert_active_fedora_has_many(
|
147
|
-
@family,
|
148
|
-
:child_collections,
|
149
|
-
[@theo,@claire, heathcliff,rudy, vanessa]
|
150
|
-
)
|
151
|
-
end
|
152
|
-
|
153
|
-
def verify_initial_relations_for_theo
|
154
|
-
assert_rels_ext @theo, :is_child_of, [@claire, heathcliff]
|
155
|
-
assert_rels_ext @theo, :is_member_of, [@claire, family, heathcliff]
|
156
|
-
|
157
|
-
assert_active_fedora_has_many(@theo, :jobs, [])
|
158
|
-
assert_active_fedora_has_many(@theo, :families, [family])
|
159
|
-
assert_active_fedora_has_many(@theo, :parents, [heathcliff,claire])
|
160
|
-
assert_active_fedora_has_many(@theo, :child_collections, [])
|
161
|
-
assert_active_fedora_has_many(
|
162
|
-
@theo, :parent_collections, [heathcliff,claire,family]
|
163
|
-
)
|
5
|
+
describe 'with journal / volume' do
|
6
|
+
it 'should have volumes' do
|
7
|
+
journal = Journal.new
|
8
|
+
with_persisted_area(journal.name_of_area_to_assign) do |area|
|
9
|
+
journal.save!
|
10
|
+
volume = JournalVolume.new
|
11
|
+
volume.save!
|
12
|
+
volume.journals << journal
|
13
|
+
volume.save!
|
14
|
+
|
15
|
+
@journal = journal.class.find(journal.pid)
|
16
|
+
@volume = volume.class.find(volume.pid)
|
17
|
+
|
18
|
+
assert_rels_ext(@volume, :is_volume_of, [@journal])
|
19
|
+
assert_rels_ext(@volume, :is_member_of, [@journal])
|
20
|
+
assert_active_fedora_has_many(@volume, :journals, [@journal])
|
21
|
+
|
22
|
+
assert_rels_ext(@journal, :is_volume_of, [])
|
23
|
+
assert_rels_ext(@journal, :is_member_of, [])
|
24
|
+
assert_active_fedora_has_many(@journal, :volumes, [@volume])
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
164
28
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
29
|
+
describe 'with family' do
|
30
|
+
let(:family) { Family.new }
|
31
|
+
let(:lawyer) { Job.new }
|
32
|
+
let(:doctor) { Job.new }
|
33
|
+
let(:heathcliff) { Person.new }
|
34
|
+
let(:claire) { Person.new }
|
35
|
+
let(:theo) { Person.new }
|
36
|
+
let(:vanessa) { Person.new }
|
37
|
+
let(:rudy) { Person.new }
|
38
|
+
let(:dress) { Clothing.new(slot_name: 'outerwear') }
|
39
|
+
|
40
|
+
it 'verifies complicated relationships' do
|
41
|
+
with_persisted_area(Family.new.name_of_area_to_assign) do |area|
|
42
|
+
setup_variables
|
43
|
+
verify_initial_relations_for_family
|
44
|
+
verify_initial_relations_for_theo
|
45
|
+
verify_initial_relations_for_claire
|
46
|
+
verify_initial_relations_for_dress
|
47
|
+
verify_claire_adding_a_child
|
48
|
+
verify_claire_losing_a_child
|
49
|
+
verify_rudy_losing_a_parent
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
def setup_variables
|
55
|
+
family.save!
|
56
|
+
|
57
|
+
lawyer.save!
|
58
|
+
doctor.save!
|
59
|
+
|
60
|
+
heathcliff.save!
|
61
|
+
claire.save!
|
62
|
+
theo.save!
|
63
|
+
vanessa.save!
|
64
|
+
rudy.save!
|
65
|
+
|
66
|
+
dress.save!
|
67
|
+
|
68
|
+
claire.children = [theo,vanessa,rudy]
|
69
|
+
claire.jobs << lawyer
|
70
|
+
claire.families << family
|
71
|
+
claire.data << dress
|
72
|
+
claire.save!
|
73
|
+
|
74
|
+
heathcliff.children = [theo,vanessa,rudy]
|
75
|
+
heathcliff.jobs << doctor
|
76
|
+
heathcliff.families << family
|
77
|
+
heathcliff.save!
|
78
|
+
|
79
|
+
theo.families << family
|
80
|
+
theo.save!
|
81
|
+
vanessa.families << family
|
82
|
+
vanessa.save!
|
83
|
+
rudy.families << family
|
84
|
+
rudy.save!
|
85
|
+
|
86
|
+
family.family_members = [claire,heathcliff,theo,vanessa,rudy]
|
87
|
+
family.save!
|
88
|
+
|
89
|
+
@dress = dress.class.find(dress.pid)
|
90
|
+
@theo = theo.class.find(theo.pid)
|
91
|
+
@family = family.class.find(family.pid)
|
92
|
+
@claire = claire.class.find(claire.pid)
|
93
|
+
@rudy = rudy.class.find(rudy.pid)
|
94
|
+
@vanessa = vanessa.class.find(vanessa.pid)
|
95
|
+
end
|
96
|
+
def verify_initial_relations_for_family
|
97
|
+
# We are not storing the RELS-EXT entry on the "container" collection
|
98
|
+
assert_rels_ext(@family,:has_family_members,[])
|
99
|
+
assert_rels_ext(@family,:has_members,[])
|
100
|
+
|
101
|
+
# However, we do have access to Family#family_members
|
102
|
+
assert_active_fedora_has_many(
|
103
|
+
@family,
|
104
|
+
:family_members,
|
105
|
+
[@theo,@claire, heathcliff,rudy, @vanessa]
|
106
|
+
)
|
107
|
+
|
108
|
+
assert_active_fedora_has_many(
|
109
|
+
@family,
|
110
|
+
:child_collections,
|
111
|
+
[@theo,@claire, heathcliff,rudy, @vanessa]
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
def verify_initial_relations_for_theo
|
116
|
+
assert_rels_ext @theo, :is_child_of, [@claire, heathcliff]
|
117
|
+
assert_rels_ext @theo, :is_member_of, [@claire, family, heathcliff]
|
118
|
+
|
119
|
+
assert_active_fedora_has_many(@theo, :jobs, [])
|
120
|
+
assert_active_fedora_has_many(@theo, :families, [family])
|
121
|
+
assert_active_fedora_has_many(@theo, :parents, [heathcliff,claire])
|
122
|
+
assert_active_fedora_has_many(@theo, :child_collections, [])
|
123
|
+
assert_active_fedora_has_many(
|
124
|
+
@theo, :parent_collections, [heathcliff,claire,family]
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
def verify_initial_relations_for_dress
|
129
|
+
assert_rels_ext(@dress, :is_part_of, [@claire])
|
130
|
+
assert_active_fedora_belongs_to(@dress, :collection, @claire)
|
131
|
+
end
|
132
|
+
|
133
|
+
def verify_initial_relations_for_claire
|
134
|
+
assert_rels_ext @claire, :is_parent_of, []
|
135
|
+
assert_rels_ext @claire, :is_child_of, []
|
136
|
+
assert_rels_ext @claire, :is_family_member_of, [family]
|
137
|
+
assert_rels_ext @claire, :is_member_of, [family]
|
138
|
+
|
139
|
+
assert_active_fedora_has_many(@claire,:data,[@dress])
|
140
|
+
assert_active_fedora_has_many(@claire,:jobs,[lawyer])
|
141
|
+
assert_active_fedora_has_many(@claire,:families,[family])
|
142
|
+
assert_active_fedora_has_many(@claire,:children,[theo, rudy, @vanessa])
|
143
|
+
assert_active_fedora_has_many(
|
144
|
+
@claire,:child_collections,[theo, rudy, @vanessa]
|
145
|
+
)
|
146
|
+
assert_active_fedora_has_many(@claire,:parent_collections,[family])
|
147
|
+
end
|
148
|
+
|
149
|
+
def verify_claire_adding_a_child
|
150
|
+
@sandra = Person.new
|
151
|
+
@sandra.save!
|
152
|
+
@claire.children << @sandra
|
153
|
+
@claire.save!
|
154
|
+
@claire = @claire.class.find(@claire.pid)
|
155
|
+
@sandra = @sandra.class.find(@sandra.pid)
|
156
|
+
|
157
|
+
assert_rels_ext @claire, :is_parent_of, []
|
158
|
+
assert_rels_ext @claire, :is_child_of, []
|
159
|
+
|
160
|
+
assert_active_fedora_has_many(@claire,:parents,[])
|
161
|
+
assert_active_fedora_has_many(@claire,:children,[theo, rudy, @vanessa,@sandra])
|
162
|
+
assert_active_fedora_has_many(
|
163
|
+
@claire,:child_collections,[theo, rudy, @vanessa, @sandra]
|
164
|
+
)
|
165
|
+
assert_active_fedora_has_many(
|
166
|
+
@claire,:parent_collections,[family]
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
def verify_claire_losing_a_child
|
171
|
+
@vanessa.break_relation_with_parents(@claire)
|
172
|
+
@vanessa.save!
|
173
|
+
@sandra.break_relation_with_parents(@claire)
|
174
|
+
@sandra.save!
|
175
|
+
|
176
|
+
@claire.save!
|
177
|
+
@claire = @claire.class.find(@claire.pid)
|
178
|
+
|
179
|
+
assert_active_fedora_has_many(@claire,:children,[theo, rudy])
|
180
|
+
assert_active_fedora_has_many(
|
181
|
+
@claire,:child_collections,[theo, rudy]
|
182
|
+
)
|
183
|
+
|
184
|
+
@vanessa = @vanessa.class.find(@vanessa.pid)
|
185
|
+
|
186
|
+
# Note, just because we said Claire was not Vanessa's parent, Vanessa did
|
187
|
+
# not update
|
188
|
+
assert_rels_ext(@vanessa, :is_child_of, [heathcliff])
|
189
|
+
assert_rels_ext(@vanessa, :is_member_of, [heathcliff, family])
|
190
|
+
|
191
|
+
assert_active_fedora_has_many(@vanessa, :parents, [heathcliff])
|
192
|
+
assert_active_fedora_has_many(
|
193
|
+
@vanessa, :parent_collections, [heathcliff, family]
|
194
|
+
)
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
def verify_rudy_losing_a_parent
|
199
|
+
assert_rels_ext @rudy, :is_child_of, [heathcliff,@claire]
|
200
|
+
assert_rels_ext @rudy, :is_member_of, [heathcliff,@claire,family]
|
201
|
+
assert_active_fedora_has_many @rudy, :parents, [heathcliff,@claire]
|
202
|
+
assert_active_fedora_has_many(
|
203
|
+
@rudy, :parent_collections, [heathcliff,@claire,family]
|
204
|
+
)
|
205
|
+
|
206
|
+
@rudy.break_relation_with_parents(heathcliff)
|
207
|
+
@rudy.save!
|
208
|
+
|
209
|
+
assert_active_fedora_has_many(@rudy, :parents, [@claire])
|
210
|
+
assert_active_fedora_has_many(@rudy, :parent_collections, [@claire, family])
|
211
|
+
assert_rels_ext @rudy, :is_child_of, [@claire]
|
212
|
+
assert_rels_ext @rudy, :is_member_of, [@claire, family]
|
213
|
+
|
214
|
+
@rudy = @rudy.class.find(@rudy.pid)
|
215
|
+
|
216
|
+
assert_rels_ext @rudy, :is_child_of, [@claire]
|
217
|
+
assert_rels_ext @rudy, :is_member_of, [@claire, family]
|
218
|
+
|
219
|
+
assert_active_fedora_has_many(@rudy, :parents, [@claire])
|
220
|
+
assert_active_fedora_has_many(@rudy, :parent_collections, [@claire, family])
|
221
|
+
end
|
257
222
|
end
|
258
223
|
end
|
@@ -2,6 +2,10 @@ require_relative '../../../lib/common_repository_model/data'
|
|
2
2
|
|
3
3
|
FactoryGirl.define do
|
4
4
|
factory :common_repository_model_collection, class: CommonRepositoryModel::Collection do
|
5
|
-
|
5
|
+
before(:create) { |collection|
|
6
|
+
area_name = collection.name_of_area_to_assign
|
7
|
+
CommonRepositoryModel::Area.find_by_name(area_name) ||
|
8
|
+
FactoryGirl.create(:common_repository_model_area, name: area_name)
|
9
|
+
}
|
6
10
|
end
|
7
11
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'common_repository_model/collection'
|
2
|
+
|
3
|
+
class JournalVolume < CommonRepositoryModel::Collection
|
4
|
+
def name_of_area_to_assign
|
5
|
+
Journal::AREA_NAME.freeze
|
6
|
+
end
|
7
|
+
|
8
|
+
is_member_of :journals, class_name: "Journal", property: :is_volume_of
|
9
|
+
end
|
10
|
+
|
11
|
+
class Journal < CommonRepositoryModel::Collection
|
12
|
+
AREA_NAME ='NDLIB-LAW'.freeze
|
13
|
+
def name_of_area_to_assign
|
14
|
+
AREA_NAME
|
15
|
+
end
|
16
|
+
|
17
|
+
has_members :volumes, class_name: "JournalVolume", property: :is_volume_of
|
18
|
+
end
|
19
|
+
|
20
|
+
class Clothing < CommonRepositoryModel::Data
|
21
|
+
end
|
22
|
+
|
23
|
+
class Job < CommonRepositoryModel::Collection
|
24
|
+
has_and_belongs_to_many(
|
25
|
+
:people,
|
26
|
+
class_name: 'Person',
|
27
|
+
property: :has_workers,
|
28
|
+
inverse_of: :is_working_as
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Family < CommonRepositoryModel::Collection
|
33
|
+
has_members(
|
34
|
+
:family_members,
|
35
|
+
class_name: 'Person',
|
36
|
+
property: :is_family_member_of
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
class Person < CommonRepositoryModel::Collection
|
41
|
+
|
42
|
+
is_member_of(
|
43
|
+
:parents,
|
44
|
+
class_name: 'Person',
|
45
|
+
property: :is_child_of
|
46
|
+
)
|
47
|
+
|
48
|
+
has_members(
|
49
|
+
:children,
|
50
|
+
class_name: 'Person',
|
51
|
+
property: :is_child_of
|
52
|
+
)
|
53
|
+
|
54
|
+
# People can be part of multiple families
|
55
|
+
is_member_of(
|
56
|
+
:families,
|
57
|
+
class_name: 'Family',
|
58
|
+
property: :is_family_member_of
|
59
|
+
)
|
60
|
+
|
61
|
+
has_and_belongs_to_many(
|
62
|
+
:jobs,
|
63
|
+
class_name: 'Job',
|
64
|
+
property: :is_working_as,
|
65
|
+
inverse_of: :has_workers
|
66
|
+
)
|
67
|
+
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: common_repository_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: morphine
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: active_model_serializers
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -210,6 +194,7 @@ files:
|
|
210
194
|
- spec/factories/common_repository_model/collection_factory.rb
|
211
195
|
- spec/factories/common_repository_model/data_factory.rb
|
212
196
|
- spec/spec_helper.rb
|
197
|
+
- spec/support/spec_models.rb
|
213
198
|
homepage: https://github.com/ndlib/common_repository_model
|
214
199
|
licenses: []
|
215
200
|
post_install_message:
|
@@ -253,3 +238,4 @@ test_files:
|
|
253
238
|
- spec/factories/common_repository_model/collection_factory.rb
|
254
239
|
- spec/factories/common_repository_model/data_factory.rb
|
255
240
|
- spec/spec_helper.rb
|
241
|
+
- spec/support/spec_models.rb
|