common_repository_model 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p286@common_repository_model"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create use "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ if command -v bundle && [[ -s Gemfile ]]
51
+ then
52
+ bundle
53
+ fi
54
+
55
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in common_repository_model.gemspec
4
+ gemspec
5
+
6
+ gem 'debugger'
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ ##########################################################################
2
+ # Copyright 2012 University of Notre Dame
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # CommonRepositoryModel
2
+
3
+ Notre Dame's Common Fedora Repository Model
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'common_repository_model'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install common_repository_model
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ t.verbose = true
9
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'common_repository_model/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "common_repository_model"
8
+ gem.version = CommonRepositoryModel::VERSION
9
+ gem.authors = [
10
+ "Jeremy Friesen"
11
+ ]
12
+ gem.email = [
13
+ "jeremy.n.friesen@gmail.com"
14
+ ]
15
+ gem.description = %q{Notre Dame's Common Fedora Repository Model}
16
+ gem.summary = %q{Notre Dame's Common Fedora Repository Model}
17
+ gem.homepage = "https://github.com/ndlib/common_repository_model"
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.add_dependency "activesupport", "~>3.2"
25
+ gem.add_dependency "activemodel", "~>3.2"
26
+ gem.add_dependency "builder", "~>3.0"
27
+ gem.add_runtime_dependency "minitest"
28
+ gem.add_runtime_dependency "minitest-matchers"
29
+ gem.add_runtime_dependency "active-fedora"
30
+ end
@@ -0,0 +1,18 @@
1
+ require_relative './persistence_base'
2
+ require_relative './collection'
3
+ module CommonRepositoryModel
4
+ class Area < PersistenceBase
5
+
6
+ has_many(
7
+ :collections,
8
+ class_name: 'CommonRepositoryModel::Collection',
9
+ property: :is_member_of_area
10
+ )
11
+
12
+ has_metadata(name: "properties",type: ActiveFedora::SimpleDatastream) do |m|
13
+ m.field 'area_name', :string
14
+ end
15
+
16
+ delegate_to 'properties', [:area_name], unique: true
17
+ end
18
+ end
@@ -0,0 +1,95 @@
1
+ require_relative './persistence_base'
2
+ require_relative './area'
3
+ require_relative './data'
4
+ require 'set'
5
+
6
+ module CommonRepositoryModel
7
+ class MembershipRegistry
8
+ def initialize
9
+ @has_members = Set.new
10
+ @is_member_of = Set.new
11
+ end
12
+ attr_reader :has_members, :is_member_of
13
+ end
14
+ class Collection < PersistenceBase
15
+
16
+ def self.membership_registry
17
+ @membership_registry ||= MembershipRegistry.new
18
+ end
19
+
20
+ def membership_registry
21
+ self.class.membership_registry
22
+ end
23
+
24
+ def self.has_members(method_name, options = {})
25
+ membership_registry.has_members << method_name
26
+ has_many(method_name, options)
27
+ end
28
+
29
+ # Creates the :break_relation_with_<macro_name> method which is useful for
30
+ # managing both the ActiveFedora association and relationship.
31
+ #
32
+ # NOTE: I believe this is actually masking an ActiveFedora bug, at some
33
+ # point, I would imagine that the :break_relation_with method would be
34
+ # deprecated and ultimately be an alias for
35
+ # object.<association_name>.delete(obj1,obj2)
36
+ def self.is_member_of(method_name, options = {})
37
+ membership_registry.is_member_of << method_name
38
+ define_method "break_relation_with_#{method_name}" do |*args|
39
+ send(method_name).delete(*args)
40
+ args.each do |obj|
41
+ remove_relationship(options[:property], obj)
42
+ remove_relationship(:is_member_of, obj)
43
+ end
44
+ end
45
+ has_and_belongs_to_many(method_name, options)
46
+ end
47
+
48
+ def save
49
+ collected_has_members = membership_registry.has_members.
50
+ collect do |association_name|
51
+ public_send(association_name)
52
+ end.flatten
53
+ self.child_collections = collected_has_members
54
+
55
+ collected_is_member_of = membership_registry.is_member_of.
56
+ collect do |association_name|
57
+ public_send(association_name)
58
+ end.flatten
59
+
60
+ self.parent_collections = collected_is_member_of
61
+
62
+ super
63
+ end
64
+
65
+ belongs_to(
66
+ :area,
67
+ class_name:'CommonRepositoryModel::Area',
68
+ property: :is_member_of_area
69
+ )
70
+
71
+ has_many(
72
+ :child_collections,
73
+ class_name: 'CommonRepositoryModel::Collection',
74
+ property: :is_member_of
75
+ )
76
+
77
+ has_and_belongs_to_many(
78
+ :parent_collections,
79
+ class_name: 'CommonRepositoryModel::Collection',
80
+ property: :is_member_of
81
+ )
82
+
83
+ has_many(
84
+ :data,
85
+ class_name: 'CommonRepositoryModel::Data',
86
+ property: :is_part_of
87
+ )
88
+
89
+ def find_or_build_data_for_given_slot_names(slot_names)
90
+ slot_names.collect { |name|
91
+ data.detect { |d| d.slot_name == name } || data.build(slot_name: name)
92
+ }
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,28 @@
1
+ require_relative './persistence_base'
2
+ require_relative './collection'
3
+ require_relative './file_datastream'
4
+
5
+ class CommonRepositoryModel::Data < CommonRepositoryModel::PersistenceBase
6
+ belongs_to(
7
+ :collection,
8
+ class_name: 'CommonRepositoryModel::Collection',
9
+ property: :is_part_of
10
+ )
11
+
12
+ has_file_datastream(
13
+ name: "content",
14
+ type: CommonRepositoryModel::FileDatastream
15
+ )
16
+
17
+ has_metadata name: "properties", type: ActiveFedora::SimpleDatastream do |m|
18
+ m.field :slot_name, :string
19
+ m.field :md5_checksum, :string
20
+ end
21
+ delegate :slot_name, unique: true, to: :properties
22
+ delegate :md5_checksum, unique: true, to: :properties
23
+ validates :slot_name, presence: true
24
+
25
+ def content=(file)
26
+ add_file_datastream(file, dsid: "content")
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ require 'active_fedora'
2
+ require_relative './data'
3
+ module CommonRepositoryModel
4
+ class FileDatastream < ActiveFedora::Datastream
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_fedora'
2
+ module CommonRepositoryModel
3
+ class PersistenceBase < ActiveFedora::Base
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module CommonRepositoryModel
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "common_repository_model/version"
2
+
3
+ module CommonRepositoryModel
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ This generator provides a means of creating a service
3
+
4
+ Example:
5
+ rails generate service ChickenPieService
6
+
7
+ This will create:
8
+ app/services/chicken_pie_service.rb
9
+ spec/services/chicken_pie_service_spec.rb
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+ class CommonRepositoryModel::Collection < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_collection
6
+ template(
7
+ 'collection.rb.erb',
8
+ File.join('app/repository_models/', "#{file_name}.rb")
9
+ )
10
+ end
11
+ def create_service_spec
12
+ template(
13
+ 'collection_spec.rb.erb',
14
+ File.join('spec/repository_models/', "#{file_name}_spec.rb")
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # Generated via
2
+ # `rails generate common_repository_model::collection <%= class_name %>`
3
+ require 'common_repository_model/collection'
4
+ class <%= class_name %> < CommonRepositoryModel::Collection
5
+
6
+ # ***************************************************************************
7
+ # ***************************************************************************
8
+ # NOTE: When managing associations, there is a bug in the underlying
9
+ # has_and_belongs_to_many. To remove an item from the association, you
10
+ # will presently need to operate on the child object – that is the object
11
+ # with the RELS-EXT entry.
12
+ # use `object.remove_from_containers(a_container)`
13
+ # ***************************************************************************
14
+ # ***************************************************************************
15
+ #
16
+ # EXAMPLE OF .has_members && .is_member_of
17
+ # Creates a relationship in which the RELS-EXT entries are stored in the
18
+ # "child" object. By using the has_members and is_member_of, the RELS-EXT
19
+ # also has an "isMemberOf" entry. In this way, we can generically walk the
20
+ # document tree as we know a related object exists.
21
+ #
22
+ # has_members :children, type: "<%= class_name %>" , property: 'is_named_member_of'
23
+ # is_member_of :parents, type: "<%= class_name %>" , property: 'is_named_member_of'
24
+ #
25
+ # In this case, a Page object would have the RELS-EXT entry
26
+ # has_members :pages, type: "Page", property: "is_page_of"
27
+ #
28
+ # In this case, the <%= class_name %> object would have the RELS-EXT entry
29
+ # is_member_of :containers, type: "Container", property: "is_contained_in"
30
+ #
31
+ # For Examples Specs:
32
+ # https://github.com/ndlib/common_respository_model/blob/master/spec/common_respository_model/integration_spec.rb
33
+ #
34
+
35
+ end
@@ -0,0 +1,4 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../spec_helper'
2
+ require 'common_repository_model/area'
3
+ require 'common_repository_model/collection'
4
+
5
+ describe CommonRepositoryModel::Area do
6
+
7
+ subject { CommonRepositoryModel::Area.new(area_name: area_name) }
8
+ let(:area_name) { 'My Area Name'}
9
+
10
+ it 'should have #area_name' do
11
+ subject.area_name.must_equal area_name
12
+ end
13
+
14
+ describe 'has_many #collections' do
15
+ it 'should build #collections' do
16
+ subject.collections.build.
17
+ must_be_kind_of(CommonRepositoryModel::Collection)
18
+ end
19
+ end
20
+
21
+ describe 'integration' do
22
+ let(:collection) { CommonRepositoryModel::Collection.new }
23
+ it 'should save' do
24
+ # Before we can add a collection, the containing object
25
+ # must be saved
26
+ subject.save.must_equal true
27
+ subject.collections << collection
28
+ subject.save.must_equal true
29
+ new_subject = subject.class.find(subject.pid)
30
+
31
+ new_subject.collections.size.must_equal 1
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,72 @@
1
+ require_relative '../spec_helper'
2
+ require 'common_repository_model/collection'
3
+
4
+ describe CommonRepositoryModel::Collection do
5
+
6
+ subject { CommonRepositoryModel::Collection.new }
7
+
8
+ it 'should belong_to #area' do
9
+ subject.must_respond_to(:area)
10
+ subject.must_respond_to(:area=)
11
+ subject.must_respond_to(:area_id)
12
+ subject.must_respond_to(:area_id=)
13
+ end
14
+
15
+ describe '#find_or_build_data_for_given_slot_names' do
16
+ it 'yields an existing data node if the slot name exists' do
17
+ slot_name = 'AnotherThing'
18
+ initial_object = subject.data.build(slot_name: slot_name)
19
+ object = subject.find_or_build_data_for_given_slot_names([slot_name]).first
20
+ object.must_equal initial_object
21
+ end
22
+ it 'yields a newly built data node if the slot name does not exist' do
23
+ slot_name = 'Chicken'
24
+ object = subject.find_or_build_data_for_given_slot_names([slot_name]).first
25
+ object.slot_name.must_equal slot_name
26
+ object.persisted?.must_equal false
27
+ end
28
+ end
29
+
30
+ it 'has many data' do
31
+ subject.data.build.must_be_kind_of(CommonRepositoryModel::Data)
32
+ end
33
+
34
+ describe 'has_many #child_collections' do
35
+ it 'should build #child_collections' do
36
+ subject.child_collections.build.
37
+ must_be_kind_of(CommonRepositoryModel::Collection)
38
+ end
39
+ end
40
+
41
+ describe 'has_and_belongs_to_many #parent_collections' do
42
+ it 'should be an Array' do
43
+ subject.parent_collections.must_be_kind_of Array
44
+ end
45
+ end
46
+
47
+
48
+ describe 'integration' do
49
+ let(:child_collection) { CommonRepositoryModel::Collection.new }
50
+ it 'should handle parent/child collection' do
51
+ # Before we can add a collection, the containing object
52
+ # must be saved
53
+ subject.save.must_equal true
54
+ subject.child_collections << child_collection
55
+ subject.save.must_equal true
56
+ @collection = subject.class.find(subject.pid)
57
+ @child_collection = child_collection.class.find(child_collection.pid)
58
+
59
+ # We shouldn't store any child relations
60
+ assert_rels_ext(@collection, :has_members, [])
61
+ assert_active_fedora_has_many(
62
+ @collection, :child_collections, [@child_collection]
63
+ )
64
+
65
+ assert_rels_ext(@child_collection, :is_member_of, [@collection])
66
+ assert_active_fedora_has_many(
67
+ @child_collection, :parent_collections, [@collection]
68
+ )
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,53 @@
1
+ require_relative '../spec_helper'
2
+ require 'common_repository_model/data'
3
+
4
+ describe CommonRepositoryModel::Data do
5
+
6
+ subject {
7
+ CommonRepositoryModel::Data.new(
8
+ slot_name: '1234',
9
+ md5_checksum: 'abcdefg'
10
+ )
11
+ }
12
+
13
+ describe 'integration' do
14
+ let(:collection) { CommonRepositoryModel::Collection.new }
15
+ let(:file_1) { File.new(__FILE__) }
16
+ let(:file_2) {
17
+ File.new(File.join(File.dirname(__FILE__), '../spec_helper.rb'))
18
+ }
19
+
20
+ it 'should have #slot_name' do
21
+ subject.must_respond_to :slot_name
22
+ subject.must_respond_to :slot_name=
23
+ end
24
+
25
+ it 'should have #md5_checksum' do
26
+ subject.must_respond_to :md5_checksum
27
+ subject.must_respond_to :md5_checksum=
28
+ end
29
+
30
+ it 'should have content versions' do
31
+ subject.content = file_1
32
+ subject.save
33
+ subject.content.content.must_equal file_1.read
34
+ subject.content = file_2
35
+ subject.save
36
+ subject.content.content.must_equal file_2.read
37
+ subject.content.versions.count.must_equal 2
38
+ end
39
+
40
+ it 'should save' do
41
+ # Before we can add a collection, the containing object
42
+ # must be saved
43
+ collection.save
44
+ subject.collection = collection
45
+ subject.save
46
+
47
+ @subject = subject.class.find(subject.pid)
48
+
49
+ assert_rels_ext(@subject, :is_part_of, [collection])
50
+ assert_active_fedora_belongs_to(@subject, :collection, collection)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ require_relative '../spec_helper'
2
+ require 'common_repository_model/file_datastream'
3
+
4
+ describe CommonRepositoryModel::FileDatastream do
5
+ subject { CommonRepositoryModel::FileDatastream.new(nil, 'content') }
6
+ end
@@ -0,0 +1,255 @@
1
+ require_relative '../spec_helper'
2
+ require 'common_repository_model/collection'
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
54
+
55
+ describe CommonRepositoryModel::Collection do
56
+
57
+ let(:family) { Family.new }
58
+ let(:lawyer) { Job.new }
59
+ let(:doctor) { Job.new }
60
+ let(:heathcliff) { Person.new }
61
+ let(:claire) { Person.new }
62
+ let(:theo) { Person.new }
63
+ let(:vanessa) { Person.new }
64
+ let(:rudy) { Person.new }
65
+ let(:dress) { Clothing.new(slot_name: 'outerwear') }
66
+
67
+ before(:all) do
68
+ family.save
69
+
70
+ lawyer.save
71
+ doctor.save
72
+
73
+ heathcliff.save
74
+ claire.save
75
+ theo.save
76
+ vanessa.save
77
+ rudy.save
78
+
79
+ dress.save
80
+
81
+ claire.children = [theo,vanessa,rudy]
82
+ claire.jobs << lawyer
83
+ claire.families << family
84
+ claire.data << dress
85
+ claire.save
86
+
87
+ heathcliff.children = [theo,vanessa,rudy]
88
+ heathcliff.jobs << doctor
89
+ heathcliff.families << family
90
+ heathcliff.save
91
+
92
+ theo.families << family
93
+ theo.save
94
+ vanessa.families << family
95
+ vanessa.save
96
+ rudy.families << family
97
+ rudy.save
98
+
99
+ family.family_members = [claire,heathcliff,theo,vanessa,rudy]
100
+ family.save.must_equal true
101
+
102
+ @dress = dress.class.find(dress.pid)
103
+ @theo = theo.class.find(theo.pid)
104
+ @family = family.class.find(family.pid)
105
+ @claire = claire.class.find(claire.pid)
106
+ @rudy = rudy.class.find(rudy.pid)
107
+ end
108
+
109
+ it 'verifies complicated relationships' do
110
+ # verify_initial_relations_for_family
111
+ # verify_initial_relations_for_theo
112
+ # verify_initial_relations_for_claire
113
+ # verify_initial_relations_for_dress
114
+
115
+ # verify_claire_adding_a_child
116
+
117
+ # verify_claire_losing_a_child
118
+
119
+ verify_rudy_losing_a_parent
120
+ end
121
+
122
+ protected
123
+ def verify_initial_relations_for_family
124
+ # We are not storing the RELS-EXT entry on the "container" collection
125
+ assert_rels_ext(
126
+ @family,
127
+ :has_family_members,
128
+ []
129
+ )
130
+ assert_rels_ext(
131
+ @family,
132
+ :has_members,
133
+ []
134
+ )
135
+
136
+ # However, we do have access to Family#family_members
137
+ assert_active_fedora_has_many(
138
+ @family,
139
+ :family_members,
140
+ [@theo,@claire, heathcliff,rudy, vanessa]
141
+ )
142
+
143
+ assert_active_fedora_has_many(
144
+ @family,
145
+ :child_collections,
146
+ [@theo,@claire, heathcliff,rudy, vanessa]
147
+ )
148
+ end
149
+
150
+ def verify_initial_relations_for_theo
151
+ assert_rels_ext @theo, :is_child_of, [@claire, heathcliff]
152
+ assert_rels_ext @theo, :is_member_of, [@claire, family, heathcliff]
153
+
154
+ assert_active_fedora_has_many(@theo, :jobs, [])
155
+ assert_active_fedora_has_many(@theo, :families, [family])
156
+ assert_active_fedora_has_many(@theo, :parents, [heathcliff,claire])
157
+ assert_active_fedora_has_many(@theo, :child_collections, [])
158
+ assert_active_fedora_has_many(
159
+ @theo, :parent_collections, [heathcliff,claire,family]
160
+ )
161
+ end
162
+
163
+ def verify_initial_relations_for_dress
164
+ assert_rels_ext(@dress, :is_part_of, [@claire])
165
+ assert_active_fedora_belongs_to(@dress, :collection, @claire)
166
+ end
167
+
168
+ def verify_initial_relations_for_claire
169
+ assert_rels_ext @claire, :is_parent_of, []
170
+ assert_rels_ext @claire, :is_child_of, []
171
+ assert_rels_ext @claire, :is_family_member_of, [family]
172
+ assert_rels_ext @claire, :is_member_of, [family]
173
+
174
+ assert_active_fedora_has_many(@claire,:data,[@dress])
175
+ assert_active_fedora_has_many(@claire,:jobs,[lawyer])
176
+ assert_active_fedora_has_many(@claire,:families,[family])
177
+ assert_active_fedora_has_many(@claire,:children,[theo, rudy, vanessa])
178
+ assert_active_fedora_has_many(
179
+ @claire,:child_collections,[theo, rudy, vanessa]
180
+ )
181
+ assert_active_fedora_has_many(@claire,:parent_collections,[family])
182
+ end
183
+
184
+ def verify_claire_adding_a_child
185
+ sandra = Person.new
186
+ sandra.save
187
+ @claire.children << sandra
188
+ @claire.save
189
+ @claire = @claire.class.find(@claire.pid)
190
+
191
+ assert_rels_ext @claire, :is_parent_of, []
192
+ assert_rels_ext @claire, :is_child_of, []
193
+
194
+ assert_active_fedora_has_many(@claire,:parents,[])
195
+ assert_active_fedora_has_many(@claire,:children,[theo, rudy, vanessa,sandra])
196
+ assert_active_fedora_has_many(
197
+ @claire,:child_collections,[theo, rudy, vanessa, sandra]
198
+ )
199
+ assert_active_fedora_has_many(
200
+ @claire,:parent_collections,[family]
201
+ )
202
+ end
203
+
204
+ def verify_claire_losing_a_child
205
+ @claire.children = [theo,rudy]
206
+ @claire.save
207
+
208
+ assert_active_fedora_has_many(@claire,:children,[theo, rudy])
209
+ assert_active_fedora_has_many(
210
+ @claire,:child_collections,[theo, rudy]
211
+ )
212
+
213
+ reloaded_vanessa = vanessa.class.find(vanessa.pid)
214
+
215
+ # Note, just because we said Claire was not Vanessa's parent, Vanessa did
216
+ # not update
217
+ assert_rels_ext reloaded_vanessa, :is_child_of, [claire, heathcliff]
218
+ assert_rels_ext(
219
+ reloaded_vanessa, :is_member_of, [claire, heathcliff, family]
220
+ )
221
+
222
+ assert_active_fedora_has_many(
223
+ reloaded_vanessa, :parents, [claire, heathcliff]
224
+ )
225
+ assert_active_fedora_has_many(
226
+ reloaded_vanessa, :parent_collections, [claire,heathcliff, family]
227
+ )
228
+
229
+ end
230
+
231
+ def verify_rudy_losing_a_parent
232
+ assert_rels_ext @rudy, :is_child_of, [heathcliff,claire]
233
+ assert_rels_ext @rudy, :is_member_of, [heathcliff,claire,family]
234
+ assert_active_fedora_has_many @rudy, :parents, [heathcliff,claire]
235
+ assert_active_fedora_has_many(
236
+ @rudy, :parent_collections, [heathcliff,claire,family]
237
+ )
238
+
239
+ @rudy.break_relation_with_parents(heathcliff)
240
+ @rudy.save.must_equal true
241
+
242
+ assert_active_fedora_has_many(@rudy, :parents, [claire])
243
+ assert_active_fedora_has_many(@rudy, :parent_collections, [claire, family])
244
+ assert_rels_ext @rudy, :is_child_of, [claire]
245
+ assert_rels_ext @rudy, :is_member_of, [claire, family]
246
+
247
+ @rudy = @rudy.class.find(@rudy.pid)
248
+
249
+ assert_rels_ext @rudy, :is_child_of, [claire]
250
+ assert_rels_ext @rudy, :is_member_of, [claire, family]
251
+
252
+ assert_active_fedora_has_many(@rudy, :parents, [claire])
253
+ assert_active_fedora_has_many(@rudy, :parent_collections, [claire, family])
254
+ end
255
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../spec_helper'
2
+ require 'common_repository_model/persistence_base'
3
+
4
+ describe CommonRepositoryModel::PersistenceBase do
5
+
6
+ subject { CommonRepositoryModel::PersistenceBase.new }
7
+
8
+ end
@@ -0,0 +1,4 @@
1
+ test: &TEST
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:8983/fedora-test
@@ -0,0 +1,62 @@
1
+ # The default namespace maps to the default namespace for generating rels_ext from solr
2
+ :default_namespace: info:fedora/fedora-system:def/relations-external#
3
+
4
+ # namespace mappings---
5
+ # you can add specific mappings for your institution by providing the following:
6
+ # namespace_uri:
7
+ # :relationship_symbol: relationship_identifier
8
+ #
9
+ # For example, if you have the following element in your rels_ext:
10
+ #
11
+ # <oai:itemID>oai:example.edu:changeme:500</oai:itemID>
12
+ #
13
+ # With the last two lines of this file uncommented, the relationships hash of your object will include:
14
+ # :oai_item_id => ["info:fedora/oai:example.edu:changeme:500"]
15
+ #
16
+ :predicate_mapping:
17
+ info:common_repository_model#:
18
+ :is_member_of_area: isMemberOfArea
19
+ :has_members: hasMembers
20
+ :is_parent_of: isParentOf
21
+ :is_child_of: isChildOf
22
+ :is_family_member_of: isFamilyMemberOf
23
+ :has_family_members: hasFamilyMembers
24
+ :is_working_as: isWorkingAs
25
+ :has_workers: hasWorkers
26
+ info:fedora/fedora-system:def/relations-external#:
27
+ :conforms_to: conformsTo
28
+ :has_annotation: hasAnnotation
29
+ :has_collection_member: hasCollectionMember
30
+ :has_constituent: hasConstituent
31
+ :has_dependent: hasDependent
32
+ :has_derivation: hasDerivation
33
+ :has_description: hasDescription
34
+ :has_equivalent: hasEquivalent
35
+ :has_metadata: hasMetadata
36
+ :has_member: hasMember
37
+ :has_model: hasModel
38
+ :has_part: hasPart
39
+ :has_subset: hasSubset
40
+ :is_annotation_of: isAnnotationOf
41
+ :is_constituent_of: isConstituentOf
42
+ :is_dependent_of: isDependentOf
43
+ :is_derivation_of: isDerivationOf
44
+ :is_description_of: isDescriptionOf
45
+ :is_member_of: isMemberOf
46
+ :is_member_of_collection: isMemberOfCollection
47
+ :is_metadata_for: isMetadataFor
48
+ :is_part_of: isPartOf
49
+ :is_subset_of: isSubsetOf
50
+ :is_topic_of: isTopicOf
51
+ info:fedora/fedora-system:def/model#:
52
+ :is_contractor_of: isContractorOf
53
+ :is_deployment_of: isDeploymentOf
54
+ :has_service: hasService
55
+ :has_model: hasModel
56
+ http://www.openarchives.org/OAI/2.0/:
57
+ :oai_item_id: itemID
58
+ http://projecthydra.org/ns/relations#:
59
+ :is_governed_by: isGovernedBy
60
+ :is_image_of: isImageOf
61
+ :has_image: hasImage
62
+
@@ -0,0 +1,10 @@
1
+ # This is a sample config file that does not have multiple solr instances. You will also need to be sure to
2
+ # edit the fedora.yml file to match the solr URL for active-fedora.
3
+ development:
4
+ url: http://localhost:8983/solr/development
5
+ test: &TEST
6
+ url: http://127.0.0.1:8983/solr/test
7
+ cucumber:
8
+ <<: *TEST
9
+ production:
10
+ url: http://localhost:80/solr/
@@ -0,0 +1,32 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'minitest/autorun'
3
+ require 'active_fedora'
4
+ ActiveFedora.init(
5
+ fedora_config_path: File.join(File.dirname(__FILE__),"config/fedora.yml"),
6
+ solr_config_path: File.join(File.dirname(__FILE__),"config/solr.yml"),
7
+ environment: :test
8
+ )
9
+
10
+
11
+ class MiniTest::Unit::TestCase
12
+ def assert_rels_ext(subject, predicate, objects = [])
13
+ assert_equal objects.count, subject.relationships(predicate).count
14
+ objects.each do |object|
15
+ internal_uri = object.respond_to?(:internal_uri) ?
16
+ object.internal_uri : object
17
+ assert subject.relationships(predicate).include?(internal_uri)
18
+ end
19
+ end
20
+
21
+ def assert_active_fedora_belongs_to(subject, method_name, object)
22
+ subject.send(method_name).must_equal object
23
+ end
24
+
25
+ def assert_active_fedora_has_many(subject, method_name, objects)
26
+ association = subject.send(method_name)
27
+ assert_equal objects.count, association.count
28
+ objects.each do |object|
29
+ assert association.include?(object)
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: common_repository_model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Friesen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: builder
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
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
+ - !ruby/object:Gem::Dependency
79
+ name: minitest-matchers
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: active-fedora
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Notre Dame's Common Fedora Repository Model
111
+ email:
112
+ - jeremy.n.friesen@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rvmrc
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - common_repository_model.gemspec
124
+ - lib/common_repository_model.rb
125
+ - lib/common_repository_model/area.rb
126
+ - lib/common_repository_model/collection.rb
127
+ - lib/common_repository_model/data.rb
128
+ - lib/common_repository_model/file_datastream.rb
129
+ - lib/common_repository_model/persistence_base.rb
130
+ - lib/common_repository_model/version.rb
131
+ - lib/generators/common_repository_model/collection/USAGE
132
+ - lib/generators/common_repository_model/collection/collection_generator.rb
133
+ - lib/generators/common_repository_model/collection/templates/collection.rb.erb
134
+ - lib/generators/common_repository_model/collection/templates/collection_spec.rb.erb
135
+ - spec/common_respository_model/area_spec.rb
136
+ - spec/common_respository_model/collection_spec.rb
137
+ - spec/common_respository_model/data_spec.rb
138
+ - spec/common_respository_model/file_datastream_spec.rb
139
+ - spec/common_respository_model/integration_spec.rb
140
+ - spec/common_respository_model/persistence_base_spec.rb
141
+ - spec/config/fedora.yml
142
+ - spec/config/predicate_mappings.yml
143
+ - spec/config/solr.yml
144
+ - spec/spec_helper.rb
145
+ homepage: https://github.com/ndlib/common_repository_model
146
+ licenses: []
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 1.8.24
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Notre Dame's Common Fedora Repository Model
169
+ test_files:
170
+ - spec/common_respository_model/area_spec.rb
171
+ - spec/common_respository_model/collection_spec.rb
172
+ - spec/common_respository_model/data_spec.rb
173
+ - spec/common_respository_model/file_datastream_spec.rb
174
+ - spec/common_respository_model/integration_spec.rb
175
+ - spec/common_respository_model/persistence_base_spec.rb
176
+ - spec/config/fedora.yml
177
+ - spec/config/predicate_mappings.yml
178
+ - spec/config/solr.yml
179
+ - spec/spec_helper.rb