active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
describe "with inverse" do
|
5
5
|
before do
|
6
|
-
class Book < ActiveFedora::Base
|
7
|
-
has_and_belongs_to_many :topics, :
|
8
|
-
has_and_belongs_to_many :collections, :
|
6
|
+
class Book < ActiveFedora::Base
|
7
|
+
has_and_belongs_to_many :topics, predicate: ::RDF::FOAF.primaryTopic, inverse_of: :books
|
8
|
+
has_and_belongs_to_many :collections, predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection
|
9
9
|
end
|
10
10
|
|
11
11
|
class SpecialInheritedBook < Book
|
@@ -15,8 +15,8 @@ describe ActiveFedora::Base do
|
|
15
15
|
class Collection < ActiveFedora::Base
|
16
16
|
end
|
17
17
|
|
18
|
-
class Topic < ActiveFedora::Base
|
19
|
-
has_and_belongs_to_many :books, :
|
18
|
+
class Topic < ActiveFedora::Base
|
19
|
+
has_and_belongs_to_many :books, predicate: ::RDF::FOAF.isPrimaryTopicOf
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,91 +28,96 @@ describe ActiveFedora::Base do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "an unsaved instance" do
|
31
|
+
let(:topic1) { Topic.create }
|
31
32
|
before do
|
32
|
-
@topic1 = Topic.create
|
33
|
-
@topic2 = Topic.create
|
34
33
|
@book = Book.create
|
35
|
-
@special_book = SpecialInheritedBook.create #TODO this isnt' needed in every test.
|
36
34
|
end
|
35
|
+
|
37
36
|
it "habtm should set and remove relationships bidirectionally" do
|
38
|
-
@book.topics <<
|
39
|
-
expect(@book.topics).to eq
|
40
|
-
expect(
|
41
|
-
expect(
|
37
|
+
@book.topics << topic1
|
38
|
+
expect(@book.topics).to eq [topic1]
|
39
|
+
expect(topic1.books).to eq [@book]
|
40
|
+
expect(topic1.reload.books).to eq [@book]
|
42
41
|
|
43
|
-
@book.topics.delete(
|
44
|
-
|
45
|
-
expect(
|
46
|
-
expect(@topic1.books).to eq([])
|
42
|
+
@book.topics.delete(topic1)
|
43
|
+
expect(@book.topics).to be_empty
|
44
|
+
expect(topic1.books).to be_empty
|
47
45
|
end
|
48
|
-
it "Should allow for more than 10 items" do
|
49
46
|
|
50
|
-
|
47
|
+
it "Should allow for more than 10 items" do
|
48
|
+
(1..12).each do
|
51
49
|
@book.topics << Topic.create
|
52
50
|
end
|
53
51
|
@book.save
|
54
|
-
expect(@book.topics.count).to eq
|
55
|
-
book2 = Book.find(@book.
|
56
|
-
expect(book2.topics.count).to eq
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
expect(@book.topics.count).to eq 12
|
53
|
+
book2 = Book.find(@book.id)
|
54
|
+
expect(book2.topics.count).to eq 12
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with subclassed objects" do
|
58
|
+
let!(:special_book) { SpecialInheritedBook.create }
|
59
|
+
it "Should find inherited objects along with base objects" do
|
60
|
+
@book.topics << topic1
|
61
|
+
special_book.topics << topic1
|
62
|
+
expect(topic1.books).to eq [@book, special_book]
|
63
|
+
expect(topic1.reload.books).to eq [@book, special_book]
|
64
|
+
end
|
64
65
|
end
|
65
66
|
|
66
67
|
it "Should cast found books to the correct cmodel" do
|
67
|
-
|
68
|
-
|
68
|
+
topic1.books[0].class == Book
|
69
|
+
topic1.books[1].class == SpecialInheritedBook
|
69
70
|
end
|
70
71
|
|
71
|
-
after do
|
72
|
-
@topic1.delete
|
73
|
-
@topic2.delete
|
74
|
-
@book.delete
|
75
|
-
@special_book.delete
|
76
|
-
end
|
77
72
|
end
|
73
|
+
|
78
74
|
describe "a saved instance" do
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
75
|
+
let!(:book) { Book.create }
|
76
|
+
let!(:topic1) { Topic.create }
|
77
|
+
let!(:topic2) { Topic.create }
|
78
|
+
|
84
79
|
it "should set relationships bidirectionally" do
|
85
|
-
|
86
|
-
expect(
|
87
|
-
expect(
|
88
|
-
expect(
|
89
|
-
expect(
|
90
|
-
expect(Topic.find(@topic1.pid).books).to eq([@book]) #Can't have saved it because @book isn't saved yet.
|
80
|
+
book.topics << topic1
|
81
|
+
expect(book.topics).to eq [topic1]
|
82
|
+
expect(book['topic_ids']).to eq [topic1.id]
|
83
|
+
expect(topic1['book_ids']).to eq [book.id]
|
84
|
+
expect(Topic.find(topic1.id).books).to eq [book] #Can't have saved it because book isn't saved yet.
|
91
85
|
end
|
86
|
+
|
92
87
|
it "should save new child objects" do
|
93
|
-
|
94
|
-
expect(
|
88
|
+
book.topics << Topic.new
|
89
|
+
expect(book.topics.first.id).to_not be_nil
|
95
90
|
end
|
91
|
+
|
96
92
|
it "should clear out the old associtions" do
|
97
|
-
|
98
|
-
|
99
|
-
expect(
|
93
|
+
book.topics = [topic1]
|
94
|
+
book.topics = [topic2]
|
95
|
+
expect(book.topic_ids).to eq [topic2.id]
|
100
96
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
97
|
+
|
98
|
+
context "with members" do
|
99
|
+
before do
|
100
|
+
book.topics = [topic1, topic2]
|
101
|
+
book.save
|
102
|
+
end
|
103
|
+
|
104
|
+
context "destroy" do
|
105
|
+
it "should remove the associations" do
|
106
|
+
book.destroy
|
107
|
+
end
|
108
|
+
end
|
105
109
|
end
|
106
110
|
end
|
107
111
|
end
|
108
112
|
|
109
113
|
describe "when inverse is not specified" do
|
110
114
|
before do
|
111
|
-
class Book < ActiveFedora::Base
|
112
|
-
has_and_belongs_to_many :collections, :
|
115
|
+
class Book < ActiveFedora::Base
|
116
|
+
has_and_belongs_to_many :collections, predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection
|
113
117
|
end
|
114
118
|
|
115
119
|
class Collection < ActiveFedora::Base
|
120
|
+
has_and_belongs_to_many :books, predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection
|
116
121
|
end
|
117
122
|
end
|
118
123
|
|
@@ -129,33 +134,29 @@ describe ActiveFedora::Base do
|
|
129
134
|
book.collections << collection
|
130
135
|
book.save!
|
131
136
|
end
|
132
|
-
after do
|
133
|
-
collection.delete
|
134
|
-
book.delete
|
135
|
-
end
|
136
137
|
|
137
138
|
it "should have a collection" do
|
138
|
-
expect(book
|
139
|
-
expect(book.collections).to eq
|
139
|
+
expect(book['collection_ids']).to eq [collection.id]
|
140
|
+
expect(book.collections).to eq [collection]
|
140
141
|
end
|
141
142
|
it "habtm should not set foreign relationships if :inverse_of is not specified" do
|
142
|
-
|
143
|
+
expect(collection['book_ids']).to be_empty
|
143
144
|
end
|
144
145
|
it "should load the collections" do
|
145
|
-
reloaded = Book.find(book.
|
146
|
-
expect(reloaded.collections).to eq
|
146
|
+
reloaded = Book.find(book.id)
|
147
|
+
expect(reloaded.collections).to eq [collection]
|
147
148
|
end
|
148
149
|
|
149
150
|
describe "#empty?" do
|
150
151
|
subject { book.collections }
|
151
|
-
|
152
|
+
it { should_not be_empty }
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
155
|
-
context "when a book isn't in a collection" do
|
156
|
+
context "when a book isn't in a collection" do
|
156
157
|
describe "#empty?" do
|
157
158
|
subject { book.collections }
|
158
|
-
|
159
|
+
it { should be_empty }
|
159
160
|
end
|
160
161
|
end
|
161
162
|
end
|
@@ -164,8 +165,8 @@ describe ActiveFedora::Base do
|
|
164
165
|
describe "when destroying the association" do
|
165
166
|
describe "without callbacks" do
|
166
167
|
before do
|
167
|
-
class Book < ActiveFedora::Base
|
168
|
-
has_and_belongs_to_many :collections,
|
168
|
+
class Book < ActiveFedora::Base
|
169
|
+
has_and_belongs_to_many :collections, predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection
|
169
170
|
end
|
170
171
|
|
171
172
|
class Collection < ActiveFedora::Base
|
@@ -184,38 +185,33 @@ describe ActiveFedora::Base do
|
|
184
185
|
book.collections << collection1 << collection2
|
185
186
|
book.save!
|
186
187
|
end
|
187
|
-
after do
|
188
|
-
collection1.delete
|
189
|
-
collection2.delete
|
190
|
-
book.delete
|
191
|
-
end
|
192
188
|
|
193
189
|
it "delete should cause the entries to be removed from RELS-EXT, but not destroy the original record" do
|
194
|
-
expect(book.collections).to eq
|
190
|
+
expect(book.collections).to eq [collection1, collection2]
|
195
191
|
book.collections.delete(collection1)
|
196
|
-
expect(book.collections).to eq
|
192
|
+
expect(book.collections).to eq [collection2]
|
197
193
|
book.save!
|
198
194
|
book.reload
|
199
|
-
expect(book.collections).to eq
|
200
|
-
expect(Collection.find(collection1.
|
195
|
+
expect(book.collections).to eq [collection2]
|
196
|
+
expect(Collection.find(collection1.id)).to_not be_nil
|
201
197
|
end
|
202
198
|
|
203
199
|
it "destroy should cause the entries to be removed from RELS-EXT, but not destroy the original record" do
|
204
|
-
expect(book.collections).to eq
|
200
|
+
expect(book.collections).to eq [collection1, collection2]
|
205
201
|
book.collections.destroy(collection1)
|
206
|
-
expect(book.collections).to eq
|
202
|
+
expect(book.collections).to eq [collection2]
|
207
203
|
book.save!
|
208
204
|
book.reload
|
209
|
-
expect(book.collections).to eq
|
210
|
-
expect(Collection.find(collection1.
|
205
|
+
expect(book.collections).to eq [collection2]
|
206
|
+
expect(Collection.find(collection1.id)).to_not be_nil
|
211
207
|
end
|
212
208
|
end
|
213
209
|
|
214
210
|
describe "with remove callbacks" do
|
215
211
|
before do
|
216
|
-
class Book < ActiveFedora::Base
|
217
|
-
has_and_belongs_to_many :collections,
|
218
|
-
|
212
|
+
class Book < ActiveFedora::Base
|
213
|
+
has_and_belongs_to_many :collections,
|
214
|
+
predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection,
|
219
215
|
before_remove: :foo, after_remove: :bar
|
220
216
|
end
|
221
217
|
|
@@ -234,10 +230,6 @@ describe ActiveFedora::Base do
|
|
234
230
|
book.collections << collection
|
235
231
|
book.save!
|
236
232
|
end
|
237
|
-
after do
|
238
|
-
collection.delete
|
239
|
-
book.delete
|
240
|
-
end
|
241
233
|
|
242
234
|
it "destroy should cause the before_remove and after_remove callback to be triggered" do
|
243
235
|
expect(book).to receive(:foo).with(collection)
|
@@ -253,20 +245,20 @@ describe ActiveFedora::Base do
|
|
253
245
|
|
254
246
|
it "should not remove if an exception is thrown in before_remove" do
|
255
247
|
expect(book).to receive(:foo).with(collection).and_raise
|
256
|
-
expect(book).
|
248
|
+
expect(book).to_not receive(:bar)
|
257
249
|
begin
|
258
250
|
book.collections.delete(collection)
|
259
251
|
rescue RuntimeError
|
260
252
|
end
|
261
|
-
expect(book.collections).to eq
|
253
|
+
expect(book.collections).to eq [collection]
|
262
254
|
end
|
263
255
|
end
|
264
256
|
|
265
257
|
describe "with add callbacks" do
|
266
258
|
before do
|
267
|
-
class Book < ActiveFedora::Base
|
268
|
-
has_and_belongs_to_many :collections,
|
269
|
-
|
259
|
+
class Book < ActiveFedora::Base
|
260
|
+
has_and_belongs_to_many :collections,
|
261
|
+
predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection,
|
270
262
|
before_add: :foo, after_add: :bar
|
271
263
|
end
|
272
264
|
|
@@ -279,12 +271,8 @@ describe ActiveFedora::Base do
|
|
279
271
|
Object.send(:remove_const, :Collection)
|
280
272
|
end
|
281
273
|
|
282
|
-
let
|
283
|
-
let
|
284
|
-
after do
|
285
|
-
collection.delete
|
286
|
-
book.delete
|
287
|
-
end
|
274
|
+
let(:book) { Book.create }
|
275
|
+
let(:collection) { Collection.create }
|
288
276
|
|
289
277
|
it "shift should cause the before_add and after_add callback to be triggered" do
|
290
278
|
expect(book).to receive(:foo).with(collection)
|
@@ -300,19 +288,45 @@ describe ActiveFedora::Base do
|
|
300
288
|
|
301
289
|
it "should not add if an exception is thrown in before_add" do
|
302
290
|
expect(book).to receive(:foo).with(collection).and_raise
|
303
|
-
expect(book).
|
291
|
+
expect(book).to_not receive(:bar)
|
304
292
|
begin
|
305
293
|
book.collections << collection
|
306
294
|
rescue RuntimeError
|
307
295
|
end
|
308
|
-
expect(book.collections).to eq
|
296
|
+
expect(book.collections).to eq []
|
309
297
|
end
|
310
298
|
end
|
299
|
+
end
|
300
|
+
end
|
311
301
|
|
302
|
+
describe "create" do
|
303
|
+
before do
|
304
|
+
class Book < ActiveFedora::Base
|
305
|
+
has_and_belongs_to_many :collections, predicate: ActiveFedora::RDF::RelsExt.isMemberOfCollection
|
306
|
+
end
|
307
|
+
|
308
|
+
class Collection < ActiveFedora::Base
|
309
|
+
property :title, predicate: ::RDF::DC.title
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
after do
|
314
|
+
Object.send(:remove_const, :Book)
|
315
|
+
Object.send(:remove_const, :Collection)
|
312
316
|
end
|
313
317
|
|
318
|
+
let(:book) { Book.create }
|
319
|
+
|
320
|
+
it "should create" do
|
321
|
+
collection = book.collections.create(title: ["Permanent"])
|
322
|
+
expect(collection).to be_kind_of Collection
|
323
|
+
expect(book.collections).to include collection
|
324
|
+
book.save
|
325
|
+
expect(book.reload.collections.first.title).to eq ['Permanent']
|
326
|
+
end
|
314
327
|
end
|
315
328
|
|
329
|
+
|
316
330
|
describe "Autosave" do
|
317
331
|
before do
|
318
332
|
class Item < ActiveFedora::Base
|
@@ -322,8 +336,9 @@ describe "Autosave" do
|
|
322
336
|
end
|
323
337
|
has_attributes :title, datastream: 'foo'
|
324
338
|
end
|
339
|
+
|
325
340
|
class Component < ActiveFedora::Base
|
326
|
-
has_and_belongs_to_many :items, :
|
341
|
+
has_and_belongs_to_many :items, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
327
342
|
has_metadata "foo", type: ActiveFedora::SimpleDatastream do |m|
|
328
343
|
m.field "description", :string
|
329
344
|
end
|
@@ -332,25 +347,37 @@ describe "Autosave" do
|
|
332
347
|
end
|
333
348
|
|
334
349
|
after do
|
335
|
-
|
336
|
-
|
350
|
+
Object.send(:remove_const, :Item)
|
351
|
+
Object.send(:remove_const, :Component)
|
337
352
|
end
|
338
353
|
|
339
354
|
describe "From the has_and_belongs_to_many side" do
|
340
|
-
|
355
|
+
describe "dependent records" do
|
356
|
+
let(:component) { Component.create(items: [Item.new(title: 'my title')]) }
|
341
357
|
|
342
|
-
|
343
|
-
|
344
|
-
|
358
|
+
it "should be saved" do
|
359
|
+
component.reload
|
360
|
+
expect(component.items.first.title).to eq 'my title'
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe "shifting" do
|
365
|
+
let(:component) { Component.new }
|
366
|
+
let(:item) { Item.create }
|
367
|
+
|
368
|
+
it "should set item_ids" do
|
369
|
+
component.items << item
|
370
|
+
expect(component.item_ids).to eq [item.id]
|
371
|
+
end
|
345
372
|
end
|
346
373
|
end
|
374
|
+
|
347
375
|
describe "From the has_many side" do
|
348
376
|
let(:item) { Item.create(components: [Component.new(description: 'my description')]) }
|
349
377
|
|
350
378
|
it "should save dependent records" do
|
351
379
|
item.reload
|
352
|
-
expect(item.components.first.description).to eq
|
380
|
+
expect(item.components.first.description).to eq 'my description'
|
353
381
|
end
|
354
382
|
end
|
355
|
-
|
356
383
|
end
|
@@ -2,18 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Collection members" do
|
4
4
|
before :all do
|
5
|
-
class Library < ActiveFedora::Base
|
5
|
+
class Library < ActiveFedora::Base
|
6
6
|
has_many :books
|
7
7
|
end
|
8
8
|
|
9
|
-
class Book < ActiveFedora::Base
|
10
|
-
belongs_to :library,
|
9
|
+
class Book < ActiveFedora::Base
|
10
|
+
belongs_to :library, predicate: ActiveFedora::RDF::RelsExt.hasConstituent
|
11
11
|
end
|
12
12
|
end
|
13
13
|
after :all do
|
14
14
|
Object.send(:remove_const, :Book)
|
15
15
|
Object.send(:remove_const, :Library)
|
16
16
|
end
|
17
|
+
|
17
18
|
describe "size of has_many" do
|
18
19
|
let(:library) { Library.create }
|
19
20
|
context "when no members" do
|
@@ -21,10 +22,11 @@ describe "Collection members" do
|
|
21
22
|
expect(library.books).not_to be_loaded
|
22
23
|
expect(library.books.size).to eq(0)
|
23
24
|
expect(library.books).to be_loaded
|
24
|
-
expect(library.books.any?).to
|
25
|
+
expect(library.books.any?).to be false
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
28
30
|
describe "looking up has_many" do
|
29
31
|
let(:book) { Book.create }
|
30
32
|
let(:library) { Library.create() }
|
@@ -33,40 +35,41 @@ describe "Collection members" do
|
|
33
35
|
library.save!
|
34
36
|
library.reload
|
35
37
|
end
|
38
|
+
|
36
39
|
it "should read book_ids from solr" do
|
37
|
-
expect(library.book_ids).to eq [book.
|
40
|
+
expect(library.book_ids).to eq [book.id]
|
38
41
|
end
|
39
42
|
it "should read books from solr" do
|
40
43
|
expect(library.books).to eq [book]
|
41
44
|
end
|
42
45
|
|
43
46
|
it "should cache the results" do
|
44
|
-
expect(library.books
|
47
|
+
expect(library.books).to_not be_loaded
|
45
48
|
expect(library.books).to eq [book]
|
46
|
-
expect(library.books
|
49
|
+
expect(library.books).to be_loaded
|
47
50
|
end
|
48
51
|
it "should load from solr" do
|
49
|
-
expect(library.books.load_from_solr.map {|r| r["id"]}).to eq([book.
|
52
|
+
expect(library.books.load_from_solr.map {|r| r["id"]}).to eq([book.id])
|
50
53
|
end
|
51
54
|
it "should load from solr with options" do
|
52
55
|
expect(library.books.load_from_solr(rows: 0).size).to eq(0)
|
53
56
|
end
|
54
57
|
it "should respond to #any?" do
|
55
|
-
expect(library.books.any?).to
|
56
|
-
expect(library.books.any? {|book| book.library == nil}).to
|
57
|
-
expect(library.books.any? {|book| book.library == library}).to
|
58
|
+
expect(library.books.any?).to be true
|
59
|
+
expect(library.books.any? {|book| book.library == nil}).to be false
|
60
|
+
expect(library.books.any? {|book| book.library == library}).to be true
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
62
65
|
describe "After save callbacks" do
|
63
66
|
before :all do
|
64
|
-
class Library < ActiveFedora::Base
|
67
|
+
class Library < ActiveFedora::Base
|
65
68
|
has_many :books
|
66
69
|
end
|
67
70
|
|
68
|
-
class Book < ActiveFedora::Base
|
69
|
-
belongs_to :library, :
|
71
|
+
class Book < ActiveFedora::Base
|
72
|
+
belongs_to :library, predicate: ActiveFedora::RDF::RelsExt.hasConstituent
|
70
73
|
after_save :find_self
|
71
74
|
attr_accessor :library_books
|
72
75
|
|
@@ -80,27 +83,29 @@ describe "After save callbacks" do
|
|
80
83
|
Object.send(:remove_const, :Book)
|
81
84
|
Object.send(:remove_const, :Library)
|
82
85
|
end
|
83
|
-
|
86
|
+
|
87
|
+
let(:library) { Library.create }
|
84
88
|
let(:book) { Book.new(library: library) }
|
89
|
+
|
85
90
|
it "should have the relationship available in after_save" do
|
86
91
|
book.save!
|
87
92
|
expect(book.library_books).to include book
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
|
-
describe "When two or more relationships share the same property" do
|
96
|
+
describe "When two or more relationships share the same property" do
|
92
97
|
before do
|
93
|
-
class Book < ActiveFedora::Base
|
98
|
+
class Book < ActiveFedora::Base
|
94
99
|
has_many :collections, :class_name=>'Collection'
|
95
100
|
has_many :people
|
96
101
|
end
|
97
102
|
|
98
103
|
class Person < ActiveFedora::Base
|
99
|
-
belongs_to :book, :
|
104
|
+
belongs_to :book, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
100
105
|
end
|
101
106
|
|
102
107
|
class Collection < ActiveFedora::Base
|
103
|
-
belongs_to :book, :
|
108
|
+
belongs_to :book, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
104
109
|
end
|
105
110
|
|
106
111
|
@book = Book.create!
|
@@ -115,30 +120,57 @@ describe "When two or more relationships share the same property" do
|
|
115
120
|
|
116
121
|
it "Should only return relationships of the correct class" do
|
117
122
|
@book.reload
|
118
|
-
expect(@book.people).to eq
|
119
|
-
expect(@book.collections).to eq
|
123
|
+
expect(@book.people).to eq [@person1, @person2]
|
124
|
+
expect(@book.collections).to eq []
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "with an polymorphic association" do
|
129
|
+
before do
|
130
|
+
class Permissionable1 < ActiveFedora::Base
|
131
|
+
has_many :permissions, predicate: ActiveFedora::RDF::RelsExt.isPartOf, inverse_of: :access_to
|
132
|
+
end
|
133
|
+
class Permissionable2 < ActiveFedora::Base
|
134
|
+
has_many :permissions, predicate: ActiveFedora::RDF::RelsExt.isPartOf, inverse_of: :access_to
|
135
|
+
end
|
136
|
+
|
137
|
+
class Permission < ActiveFedora::Base
|
138
|
+
belongs_to :access_to, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
after do
|
143
|
+
Permissionable1.destroy_all
|
144
|
+
Object.send(:remove_const, :Permissionable1)
|
145
|
+
Object.send(:remove_const, :Permissionable2)
|
146
|
+
Object.send(:remove_const, :Permission)
|
147
|
+
end
|
148
|
+
let(:p1) { Permissionable1.create }
|
149
|
+
|
150
|
+
it "should make an association" do
|
151
|
+
expect(p1.permissions.create).to be_kind_of Permission
|
120
152
|
end
|
121
153
|
end
|
122
154
|
|
123
155
|
describe "When relationship is restricted to AF::Base" do
|
124
156
|
before do
|
125
|
-
class Email < ActiveFedora::Base
|
126
|
-
has_many :attachments, :
|
157
|
+
class Email < ActiveFedora::Base
|
158
|
+
has_many :attachments, predicate: ActiveFedora::RDF::RelsExt.isPartOf, :class_name=>'ActiveFedora::Base'
|
127
159
|
end
|
128
160
|
|
129
161
|
class Image < ActiveFedora::Base
|
130
|
-
belongs_to :email, :
|
162
|
+
belongs_to :email, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
131
163
|
end
|
132
164
|
|
133
165
|
class PDF < ActiveFedora::Base
|
134
|
-
belongs_to :email, :
|
166
|
+
belongs_to :email, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
135
167
|
end
|
136
168
|
end
|
137
169
|
|
138
170
|
after do
|
139
|
-
|
140
|
-
|
141
|
-
|
171
|
+
Object.send(:remove_const, :Image)
|
172
|
+
Object.send(:remove_const, :PDF)
|
173
|
+
Object.send(:remove_const, :Email)
|
142
174
|
end
|
143
175
|
|
144
176
|
|
@@ -150,7 +182,7 @@ describe "When relationship is restricted to AF::Base" do
|
|
150
182
|
end
|
151
183
|
it "Should not restrict relationships " do
|
152
184
|
@book.reload
|
153
|
-
expect(@book.attachments).to eq
|
185
|
+
expect(@book.attachments).to eq [@image, @pdf]
|
154
186
|
end
|
155
187
|
end
|
156
188
|
|
@@ -160,15 +192,15 @@ describe "When relationship is restricted to AF::Base" do
|
|
160
192
|
let!(:pdf) { PDF.create }
|
161
193
|
|
162
194
|
after do
|
163
|
-
email.destroy
|
164
195
|
pdf.destroy
|
165
196
|
image.destroy
|
197
|
+
email.destroy
|
166
198
|
end
|
167
199
|
|
168
200
|
it "Should not restrict relationships " do
|
169
201
|
email.attachment_ids = [image.id, pdf.id]
|
170
202
|
email.reload
|
171
|
-
expect(email.attachments).to eq
|
203
|
+
expect(email.attachments).to eq [image, pdf]
|
172
204
|
end
|
173
205
|
end
|
174
206
|
end
|
@@ -176,10 +208,10 @@ end
|
|
176
208
|
describe "Deleting a dependent relationship" do
|
177
209
|
before do
|
178
210
|
class Item < ActiveFedora::Base
|
179
|
-
has_many :components
|
211
|
+
has_many :components
|
180
212
|
end
|
181
213
|
class Component < ActiveFedora::Base
|
182
|
-
belongs_to :item, :
|
214
|
+
belongs_to :item, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
183
215
|
end
|
184
216
|
end
|
185
217
|
|
@@ -191,15 +223,25 @@ describe "Deleting a dependent relationship" do
|
|
191
223
|
let(:item) { Item.create }
|
192
224
|
let(:component) { Component.create }
|
193
225
|
|
226
|
+
context "when the relationship is set by an id" do
|
227
|
+
let(:item_id) { item.id }
|
228
|
+
let!(:component1) { Component.create(item_id: item_id) }
|
229
|
+
let!(:component2) { Component.create(item_id: item_id) }
|
230
|
+
|
231
|
+
it "should set the inverse relationship" do
|
232
|
+
expect(component1.item.components).to match_array [component1, component2]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
194
236
|
it "should remove relationships" do
|
195
237
|
component.item = item
|
196
238
|
component.save!
|
197
|
-
expect(item.components).to eq
|
239
|
+
expect(item.components).to eq [component]
|
198
240
|
item.components.delete(component)
|
199
241
|
item.reload
|
200
242
|
component.reload
|
201
|
-
expect(component
|
202
|
-
expect(item.components).to eq
|
243
|
+
expect(component['item_id']).to be_nil
|
244
|
+
expect(item.components).to eq []
|
203
245
|
end
|
204
246
|
|
205
247
|
it "should remove the relationships that point at that object" do
|
@@ -207,7 +249,7 @@ describe "Deleting a dependent relationship" do
|
|
207
249
|
component.save!
|
208
250
|
item.delete
|
209
251
|
component.reload
|
210
|
-
expect(component
|
252
|
+
expect(component['item_id']).to be_nil
|
211
253
|
end
|
212
254
|
|
213
255
|
it "should only try to delete objects that exist in the datastore (not cached objects)" do
|
@@ -227,45 +269,81 @@ describe "Deleting a dependent relationship" do
|
|
227
269
|
end
|
228
270
|
|
229
271
|
describe "Autosave" do
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
272
|
+
context "a has_many - belongs_to relationship" do
|
273
|
+
before do
|
274
|
+
class Item < ActiveFedora::Base
|
275
|
+
has_many :components
|
276
|
+
has_metadata "foo", type: ActiveFedora::SimpleDatastream do |m|
|
277
|
+
m.field "title", :string
|
278
|
+
end
|
279
|
+
has_attributes :title, datastream: 'foo'
|
235
280
|
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
281
|
+
class Component < ActiveFedora::Base
|
282
|
+
belongs_to :item, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
283
|
+
has_metadata "foo", type: ActiveFedora::SimpleDatastream do |m|
|
284
|
+
m.field "description", :string
|
285
|
+
end
|
286
|
+
has_attributes :description, datastream: 'foo'
|
242
287
|
end
|
243
|
-
has_attributes :description, datastream: 'foo'
|
244
288
|
end
|
245
|
-
end
|
246
289
|
|
247
|
-
|
290
|
+
after do
|
248
291
|
Object.send(:remove_const, :Item)
|
249
292
|
Object.send(:remove_const, :Component)
|
250
|
-
|
293
|
+
end
|
251
294
|
|
252
|
-
|
253
|
-
|
295
|
+
context "From the belongs_to side" do
|
296
|
+
let(:component) { Component.create(item: Item.new(title: 'my title')) }
|
254
297
|
|
255
|
-
|
256
|
-
|
257
|
-
|
298
|
+
it "should save dependent records" do
|
299
|
+
component.reload
|
300
|
+
expect(component.item.title).to eq 'my title'
|
301
|
+
end
|
258
302
|
end
|
259
|
-
end
|
260
|
-
describe "From the has_many side" do
|
261
|
-
let(:item) { Item.create(components: [Component.new(description: 'my description')]) }
|
262
303
|
|
263
|
-
|
264
|
-
item.
|
265
|
-
|
304
|
+
context "From the has_many side" do
|
305
|
+
let(:item) { Item.create(components: [Component.new(description: 'my description')]) }
|
306
|
+
|
307
|
+
it "should save dependent records" do
|
308
|
+
item.reload
|
309
|
+
expect(item.components.first.description).to eq 'my description'
|
310
|
+
end
|
266
311
|
end
|
267
312
|
end
|
268
313
|
|
269
|
-
|
314
|
+
context "a has_many - has_and_belongs_to_many relationship" do
|
315
|
+
context "with ActiveFedora::Base as classes" do
|
316
|
+
before do
|
317
|
+
class Novel < ActiveFedora::Base
|
318
|
+
has_many :books, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
319
|
+
has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
320
|
+
end
|
321
|
+
class Text < ActiveFedora::Base
|
322
|
+
has_many :books, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
323
|
+
end
|
324
|
+
end
|
325
|
+
let(:text) { Text.create}
|
326
|
+
let(:novel) { Novel.create}
|
327
|
+
|
328
|
+
after do
|
329
|
+
Object.send(:remove_const, :Novel)
|
330
|
+
Object.send(:remove_const, :Text)
|
331
|
+
end
|
270
332
|
|
333
|
+
it "should work when added via the has_many" do
|
334
|
+
text.books << novel
|
335
|
+
novel.save
|
336
|
+
expect(novel.reload.contents).to eq [text]
|
337
|
+
expect(text.reload.books).to eq [novel]
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should work when added via the has_and_belongs_to_many" do
|
341
|
+
novel.contents << text
|
342
|
+
novel.save!
|
343
|
+
text.reload
|
344
|
+
expect(text.books).to eq [novel]
|
345
|
+
end
|
271
346
|
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|