hydra-collections 4.0.0.beta1 → 4.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/collections_search_helper.rb +2 -1
- data/app/models/concerns/hydra/collection.rb +7 -28
- data/lib/hydra/collections/version.rb +1 -1
- data/spec/controllers/collections_controller_spec.rb +2 -13
- data/spec/helpers/collections_search_helper_spec.rb +1 -1
- data/spec/models/collection_spec.rb +124 -66
- data/spec/spec_helper.rb +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 878b10998101cbd6d3b1420408215b6605180517
|
4
|
+
data.tar.gz: 015496e71bfabd20eb28668f4dd1d42ed3a83b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 374d069be8e10287435c0544a8c571da379cfd8e86d05176f327a4340cba7c95df59005ef599106a516d4f33b1ba0763d1ecded7a9b61546886f229e75c8c64d
|
7
|
+
data.tar.gz: ed325dd51ed6abbfd585702f9a6f796f9d66b088767b4230100669e4116cdcd0678d91a687f0cda705fe3a68f03dce186a3941ba97cf4370f082a1c355e56a6f
|
@@ -5,7 +5,8 @@ module CollectionsSearchHelper
|
|
5
5
|
# @return [String] the title of the collection if available, otherwise its pid
|
6
6
|
def collection_name(collection_pid)
|
7
7
|
#TODO this can be loaded from solr
|
8
|
-
|
8
|
+
# the .result is due to ActiveTriples/ActiveTripes#74
|
9
|
+
Collection.find(collection_pid).title.result || collection_pid
|
9
10
|
end
|
10
11
|
|
11
12
|
end
|
@@ -9,7 +9,7 @@ module Hydra
|
|
9
9
|
included do
|
10
10
|
has_and_belongs_to_many :members, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base" , after_remove: :update_member
|
11
11
|
|
12
|
-
property :depositor, predicate: RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt")
|
12
|
+
property :depositor, predicate: RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt"), multiple: false
|
13
13
|
|
14
14
|
property :part_of, predicate: RDF::DC.isPartOf
|
15
15
|
property :contributor, predicate: RDF::DC.contributor do |index|
|
@@ -18,10 +18,10 @@ module Hydra
|
|
18
18
|
property :creator, predicate: RDF::DC.creator do |index|
|
19
19
|
index.as :stored_searchable, :facetable
|
20
20
|
end
|
21
|
-
property :title, predicate: RDF::DC.title do |index|
|
21
|
+
property :title, predicate: RDF::DC.title, multiple: false do |index|
|
22
22
|
index.as :stored_searchable
|
23
23
|
end
|
24
|
-
property :description, predicate: RDF::DC.description do |index|
|
24
|
+
property :description, predicate: RDF::DC.description, multiple: false do |index|
|
25
25
|
index.type :text
|
26
26
|
index.as :stored_searchable
|
27
27
|
end
|
@@ -31,11 +31,11 @@ module Hydra
|
|
31
31
|
property :date_created, predicate: RDF::DC.created do |index|
|
32
32
|
index.as :stored_searchable
|
33
33
|
end
|
34
|
-
property :date_uploaded, predicate: RDF::DC.dateSubmitted do |index|
|
34
|
+
property :date_uploaded, predicate: RDF::DC.dateSubmitted, multiple: false do |index|
|
35
35
|
index.type :date
|
36
36
|
index.as :stored_sortable
|
37
37
|
end
|
38
|
-
property :date_modified, predicate: RDF::DC.modified do |index|
|
38
|
+
property :date_modified, predicate: RDF::DC.modified, multiple: false do |index|
|
39
39
|
index.type :date
|
40
40
|
index.as :stored_sortable
|
41
41
|
end
|
@@ -62,27 +62,6 @@ module Hydra
|
|
62
62
|
end
|
63
63
|
property :related_url, predicate: RDF::RDFS.seeAlso
|
64
64
|
|
65
|
-
# Single-valued properties
|
66
|
-
def depositor
|
67
|
-
super.first
|
68
|
-
end
|
69
|
-
|
70
|
-
def title
|
71
|
-
super.first
|
72
|
-
end
|
73
|
-
|
74
|
-
def date_uploaded
|
75
|
-
super.first
|
76
|
-
end
|
77
|
-
|
78
|
-
def date_modified
|
79
|
-
super.first
|
80
|
-
end
|
81
|
-
|
82
|
-
def description
|
83
|
-
super.first
|
84
|
-
end
|
85
|
-
|
86
65
|
before_create :set_date_uploaded
|
87
66
|
before_save :set_date_modified
|
88
67
|
before_destroy :update_all_members
|
@@ -96,8 +75,8 @@ module Hydra
|
|
96
75
|
|
97
76
|
def terms_for_display
|
98
77
|
[
|
99
|
-
:part_of, :contributor, :creator, :title, :description, :publisher,
|
100
|
-
:date_created, :date_uploaded, :date_modified, :subject, :language, :rights,
|
78
|
+
:part_of, :contributor, :creator, :title, :description, :publisher,
|
79
|
+
:date_created, :date_uploaded, :date_modified, :subject, :language, :rights,
|
101
80
|
:resource_type, :identifier, :based_near, :tag, :related_url
|
102
81
|
]
|
103
82
|
end
|
@@ -11,18 +11,7 @@ describe CollectionsController, :type => :controller do
|
|
11
11
|
class GenericFile < ActiveFedora::Base
|
12
12
|
include Hydra::Collections::Collectible
|
13
13
|
|
14
|
-
property :title, predicate: ::RDF::DC.title
|
15
|
-
|
16
|
-
# Hack until https://github.com/no-reply/ActiveTriples/pull/37 is merged
|
17
|
-
def title_with_first
|
18
|
-
title_without_first.first
|
19
|
-
end
|
20
|
-
alias_method_chain :title, :first
|
21
|
-
|
22
|
-
# use this until https://github.com/projecthydra/active_fedora/issues/457 is resolved
|
23
|
-
def to_param
|
24
|
-
id
|
25
|
-
end
|
14
|
+
property :title, predicate: ::RDF::DC.title, multiple: false
|
26
15
|
|
27
16
|
def to_solr(solr_doc={})
|
28
17
|
super.tap do |solr_doc|
|
@@ -293,7 +282,7 @@ describe CollectionsController, :type => :controller do
|
|
293
282
|
context "When there are search matches that are not in the collection" do
|
294
283
|
before do
|
295
284
|
GenericFile.create!(title: "#{@asset1.id} #{@asset1.title}")
|
296
|
-
GenericFile.create!(title: @asset1.title)
|
285
|
+
GenericFile.create!(title: @asset1.title.to_s)
|
297
286
|
end
|
298
287
|
# NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
|
299
288
|
it "should query the collections and show only the collection assets" do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe CollectionsSearchHelper, :type => :helper do
|
4
4
|
describe "collection_name" do
|
5
|
-
let (:collection_without_title) { Collection.create() }
|
5
|
+
let (:collection_without_title) { Collection.create!() }
|
6
6
|
let (:collection_with_title) { Collection.create(title: "Title of Collection 2") }
|
7
7
|
|
8
8
|
it "should return the pid if no title available" do
|
@@ -19,94 +19,153 @@ describe Collection, :type => :model do
|
|
19
19
|
Object.send(:remove_const, :GenericFile)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
@collection.apply_depositor_metadata(@user.user_key)
|
25
|
-
@collection.save!
|
26
|
-
@gf1 = GenericFile.create
|
27
|
-
@gf2 = GenericFile.create
|
28
|
-
end
|
22
|
+
let(:gf1) { GenericFile.create }
|
23
|
+
let(:gf2) { GenericFile.create }
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
let(:user) { @user }
|
26
|
+
|
27
|
+
describe "#to_solr" do
|
28
|
+
let(:collection) { Collection.new(title: "A good title") }
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
subject { collection.to_solr }
|
31
|
+
|
32
|
+
it "should have title" do
|
33
|
+
expect(subject['title_tesim']).to eq ['A good title']
|
34
|
+
end
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
37
|
+
describe "#depositor" do
|
38
|
+
before do
|
39
|
+
subject.apply_depositor_metadata(user)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have a depositor" do
|
43
|
+
expect(subject.depositor).to eq(user.user_key)
|
44
|
+
end
|
42
45
|
end
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
describe "the ability" do
|
48
|
+
let(:collection) do
|
49
|
+
Collection.new.tap do |collection|
|
50
|
+
collection.apply_depositor_metadata(user)
|
51
|
+
collection.save
|
52
|
+
end
|
53
|
+
end
|
54
|
+
subject { Ability.new(user) }
|
55
|
+
|
56
|
+
it "should allow the depositor to edit and read" do
|
57
|
+
expect(subject.can?(:read, collection)).to be true
|
58
|
+
expect(subject.can?(:edit, collection)).to be true
|
59
|
+
end
|
48
60
|
end
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
62
|
+
describe "#members" do
|
63
|
+
it "should be empty by default" do
|
64
|
+
expect(subject.members).to be_empty
|
65
|
+
end
|
66
|
+
|
67
|
+
context "adding members" do
|
68
|
+
context "using assignment" do
|
69
|
+
subject { Collection.create(members: [gf1, gf2]) }
|
70
|
+
|
71
|
+
it "should have many files" do
|
72
|
+
expect(subject.reload.members).to eq [gf1, gf2]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "using append" do
|
77
|
+
before do
|
78
|
+
subject.members = [gf1]
|
79
|
+
subject.save
|
80
|
+
end
|
81
|
+
it "should allow new files to be added" do
|
82
|
+
subject.reload
|
83
|
+
subject.members << gf2
|
84
|
+
subject.save
|
85
|
+
expect(subject.reload.members).to eq [gf1, gf2]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
context "removing members" do
|
92
|
+
before do
|
93
|
+
subject.members = [gf1, gf2]
|
94
|
+
subject.save
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should allow files to be removed" do
|
98
|
+
expect(gf1.collections).to eq [subject] # This line forces the "collections" to be cached.
|
99
|
+
# We need to ensure that deleting causes the collection to be flushed.
|
100
|
+
solr_doc_before_remove = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, gf1.id).send(:solr_doc)
|
101
|
+
expect(solr_doc_before_remove["collection_tesim"]).to eq [subject.id]
|
102
|
+
subject.reload.members.delete(gf1)
|
103
|
+
subject.save
|
104
|
+
expect(subject.reload.members).to eq [gf2]
|
105
|
+
solr_doc_after_remove = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, gf1.id).send(:solr_doc)
|
106
|
+
expect(solr_doc_after_remove["collection_tesim"]).to be_nil
|
107
|
+
end
|
108
|
+
end
|
57
109
|
end
|
58
110
|
|
59
111
|
it "should set the date uploaded on create" do
|
60
|
-
|
61
|
-
expect(
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
112
|
+
subject.save
|
113
|
+
expect(subject.date_uploaded).to be_kind_of(Date)
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "when updating" do
|
117
|
+
let(:gf1) { GenericFile.create }
|
118
|
+
|
119
|
+
it "should update the date modified on update" do
|
120
|
+
uploaded_date = Date.today
|
121
|
+
modified_date = Date.tomorrow
|
122
|
+
subject.save
|
123
|
+
allow(Date).to receive(:today).and_return(uploaded_date, modified_date)
|
124
|
+
subject.save
|
125
|
+
expect(subject.date_modified).to eq uploaded_date
|
126
|
+
subject.members = [gf1]
|
127
|
+
subject.save
|
128
|
+
expect(subject.date_modified).to eq modified_date
|
129
|
+
expect(gf1.reload.collections).to include(subject)
|
130
|
+
expect(gf1.to_solr[Solrizer.solr_name(:collection)]).to eq [subject.id]
|
131
|
+
end
|
75
132
|
end
|
133
|
+
|
76
134
|
it "should have a title" do
|
77
|
-
|
78
|
-
|
79
|
-
expect(
|
135
|
+
subject.title = "title"
|
136
|
+
subject.save
|
137
|
+
expect(subject.title).to eq "title"
|
80
138
|
end
|
139
|
+
|
81
140
|
it "should have a description" do
|
82
|
-
|
83
|
-
|
84
|
-
expect(
|
141
|
+
subject.description = "description"
|
142
|
+
subject.save
|
143
|
+
expect(subject.reload.description).to eq "description"
|
85
144
|
end
|
86
145
|
|
87
146
|
it "should have the expected display terms" do
|
88
|
-
expect(
|
89
|
-
:part_of, :contributor, :creator, :title, :description, :publisher,
|
90
|
-
:date_created, :date_uploaded, :date_modified, :subject, :language, :rights,
|
91
|
-
:resource_type, :identifier, :based_near, :tag, :related_url
|
92
|
-
)
|
147
|
+
expect(subject.terms_for_display).to eq([:part_of, :contributor, :creator, :title, :description, :publisher, :date_created, :date_uploaded, :date_modified, :subject, :language, :rights, :resource_type, :identifier, :based_near, :tag, :related_url])
|
93
148
|
end
|
149
|
+
|
94
150
|
it "should have the expected edit terms" do
|
95
|
-
expect(
|
96
|
-
:part_of, :contributor, :creator, :title, :description, :publisher, :date_created,
|
97
|
-
:subject, :language, :rights, :resource_type, :identifier, :based_near, :tag, :related_url
|
98
|
-
)
|
151
|
+
expect(subject.terms_for_editing).to eq([:part_of, :contributor, :creator, :title, :description, :publisher, :date_created, :subject, :language, :rights, :resource_type, :identifier, :based_near, :tag, :related_url])
|
99
152
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
153
|
+
|
154
|
+
describe "#destroy" do
|
155
|
+
before do
|
156
|
+
subject.members = [gf1, gf2]
|
157
|
+
subject.save
|
158
|
+
subject.destroy
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should not delete member files when deleted" do
|
162
|
+
expect(GenericFile.exists?(gf1.id)).to be true
|
163
|
+
expect(GenericFile.exists?(gf2.id)).to be true
|
164
|
+
end
|
106
165
|
end
|
107
166
|
|
108
167
|
describe "Collection by another name" do
|
109
|
-
before
|
168
|
+
before do
|
110
169
|
class OtherCollection < ActiveFedora::Base
|
111
170
|
include Hydra::Collection
|
112
171
|
end
|
@@ -115,7 +174,7 @@ describe Collection, :type => :model do
|
|
115
174
|
include Hydra::Collections::Collectible
|
116
175
|
end
|
117
176
|
end
|
118
|
-
after
|
177
|
+
after do
|
119
178
|
Object.send(:remove_const, :OtherCollection)
|
120
179
|
Object.send(:remove_const, :Member)
|
121
180
|
end
|
@@ -133,5 +192,4 @@ describe Collection, :type => :model do
|
|
133
192
|
expect(member.collections).to eq [collection]
|
134
193
|
end
|
135
194
|
end
|
136
|
-
|
137
195
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,11 +9,10 @@ require 'hydra-collections'
|
|
9
9
|
FactoryGirl.definition_file_paths = [File.expand_path("../factories", __FILE__)]
|
10
10
|
FactoryGirl.find_definitions
|
11
11
|
|
12
|
+
# require 'http_logger'
|
12
13
|
# HttpLogger.logger = Logger.new(STDOUT)
|
13
14
|
# HttpLogger.ignore = [/localhost:8983\/solr/]
|
14
15
|
# HttpLogger.colorize = false
|
15
|
-
# # Patch for https://github.com/railsware/http_logger/issues/13
|
16
|
-
# HttpLogger::HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET PATCH))
|
17
16
|
|
18
17
|
module EngineRoutes
|
19
18
|
def self.included(base)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-collections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carolyn Cole
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blacklight
|