hydra-collections 3.0.0.beta2 → 3.0.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/controllers/concerns/hydra/collections_controller_behavior.rb +20 -19
- data/app/helpers/collections_search_helper.rb +1 -2
- data/app/models/concerns/hydra/collection.rb +18 -82
- data/app/models/datastreams/hydra/collection_rdf_datastream.rb +54 -0
- data/app/views/collections/_search_form.html.erb +16 -0
- data/hydra-collections.gemspec +2 -3
- data/lib/hydra/collections/accepts_batches.rb +5 -5
- data/lib/hydra/collections/collectible.rb +8 -15
- data/{app/controllers/concerns → lib}/hydra/collections/selects_collections.rb +8 -3
- data/lib/hydra/collections/solr_document_behavior.rb +15 -0
- data/lib/hydra/collections/version.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +19 -5
- data/spec/controllers/collections_controller_spec.rb +154 -125
- data/spec/controllers/other_collections_controller_spec.rb +15 -13
- data/spec/controllers/selects_collections_spec.rb +48 -39
- data/spec/factories.rb +14 -0
- data/spec/factories/.gitkeep +0 -0
- data/spec/factories/users.rb +14 -0
- data/spec/helpers/collections_helper_spec.rb +16 -14
- data/spec/helpers/collections_search_helper_spec.rb +2 -4
- data/spec/lib/collectible_spec.rb +7 -7
- data/spec/models/collection_spec.rb +133 -78
- data/spec/spec_helper.rb +1 -12
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -1
- data/tasks/hydra-collections-dev.rake +1 -19
- metadata +9 -21
- data/.rspec +0 -1
@@ -1,8 +1,12 @@
|
|
1
|
+
require 'blacklight/catalog'
|
2
|
+
|
1
3
|
module Hydra::Collections::SelectsCollections
|
4
|
+
|
5
|
+
extend ActiveSupport::Autoload
|
2
6
|
extend ActiveSupport::Concern
|
3
7
|
|
4
8
|
def access_levels
|
5
|
-
{
|
9
|
+
{read:[:read,:edit],edit:[:edit]}
|
6
10
|
end
|
7
11
|
|
8
12
|
# add one of the following methods as a before filter on any page that shows the form_for_select_collection
|
@@ -28,10 +32,11 @@ module Hydra::Collections::SelectsCollections
|
|
28
32
|
|
29
33
|
# temporarily set solr_search_params_logic to collection_search_params_logic
|
30
34
|
orig_solr_search_params_logic = self.class.solr_search_params_logic
|
35
|
+
# self.class.solr_search_params_logic += [:add_collection_filter]
|
31
36
|
self.class.solr_search_params_logic = collection_search_params_logic
|
32
37
|
logger.debug "Collection Search logic: "+ self.class.solr_search_params_logic.inspect
|
33
38
|
# run the solr query to find the collections
|
34
|
-
(resp, doc_list) = get_search_results({q
|
39
|
+
(resp, doc_list) = get_search_results({:q => ''}, {:rows=>100})
|
35
40
|
|
36
41
|
#reset to original solr logic
|
37
42
|
self.class.send(:define_method, "discovery_permissions") { original_permissions } unless access_level.blank?
|
@@ -43,7 +48,7 @@ module Hydra::Collections::SelectsCollections
|
|
43
48
|
|
44
49
|
def add_collection_filter(solr_parameters, user_parameters)
|
45
50
|
solr_parameters[:fq] ||= []
|
46
|
-
solr_parameters[:fq] << "#{Solrizer.solr_name("has_model", :symbol)}:Collection"
|
51
|
+
solr_parameters[:fq] << "#{Solrizer.solr_name("has_model", :symbol)}:\"info:fedora/afmodel:Collection\""
|
47
52
|
end
|
48
53
|
|
49
54
|
# Defines which solr_search_params_logic should be used when searching for Collections
|
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright © 2012 The Pennsylvania State University
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# -*- encoding : utf-8 -*-
|
1
16
|
module Hydra
|
2
17
|
module Collections
|
3
18
|
module SolrDocumentBehavior
|
@@ -1,26 +1,40 @@
|
|
1
|
+
# Copyright © 2012 The Pennsylvania State University
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
1
15
|
require 'spec_helper'
|
2
16
|
|
3
17
|
include Rails.application.routes.url_helpers
|
4
18
|
|
5
19
|
describe CatalogController, :type => :controller do
|
6
|
-
|
7
20
|
before do
|
8
21
|
allow(controller).to receive(:has_access?).and_return(true)
|
9
22
|
@user = FactoryGirl.find_or_create(:user)
|
10
|
-
@collection = Collection.new title:
|
23
|
+
@collection = Collection.new title:"Test"
|
11
24
|
@collection.apply_depositor_metadata(@user.user_key)
|
12
25
|
@collection.read_groups = ["public"]
|
13
|
-
@collection.save
|
26
|
+
@collection.save
|
14
27
|
end
|
15
28
|
|
16
29
|
after do
|
17
|
-
@
|
30
|
+
@user.delete
|
31
|
+
@collection.delete
|
18
32
|
end
|
19
33
|
|
20
|
-
routes { Rails.application.routes }
|
21
34
|
|
22
35
|
describe '#index' do
|
23
36
|
it 'should assign @user_collections' do
|
37
|
+
@routes = Rails.application.routes
|
24
38
|
get :index
|
25
39
|
expect(assigns(:user_collections)).to be_kind_of(Array)
|
26
40
|
expect(assigns(:user_collections).index{|d| d.id == @collection.id}).not_to be_nil
|
@@ -1,42 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CollectionsController, :type => :controller do
|
4
|
-
let(:collections) { Hydra::Collections::Engine.routes.url_helpers }
|
5
|
-
|
6
4
|
before(:all) do
|
7
5
|
CollectionsController.configure_blacklight do |config|
|
8
6
|
config.default_solr_params = {:qf => 'label_tesim'}
|
9
7
|
end
|
10
8
|
|
9
|
+
@user = FactoryGirl.find_or_create(:user)
|
10
|
+
|
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
|
26
14
|
|
15
|
+
attr_accessor :title
|
27
16
|
def to_solr(solr_doc={})
|
28
|
-
super
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
super
|
18
|
+
solr_doc = index_collection_pids(solr_doc)
|
19
|
+
solr_doc["label_tesim"] = self.title
|
20
|
+
solr_doc
|
32
21
|
end
|
33
22
|
end
|
34
23
|
end
|
35
|
-
|
36
24
|
after(:all) do
|
25
|
+
@user.destroy
|
26
|
+
GenericFile.destroy_all
|
27
|
+
Collection.destroy_all
|
37
28
|
Object.send(:remove_const, :GenericFile)
|
38
29
|
end
|
39
|
-
|
30
|
+
|
40
31
|
before do
|
41
32
|
allow(controller).to receive(:has_access?).and_return(true)
|
42
33
|
|
@@ -51,17 +42,22 @@ describe CollectionsController, :type => :controller do
|
|
51
42
|
get :new
|
52
43
|
expect(assigns(:collection)).to be_kind_of(Collection)
|
53
44
|
end
|
45
|
+
it "should pass through batch ids if provided and stick them in the form" do
|
46
|
+
skip "Couldn't get have_selector working before I had to move on. - MZ"
|
47
|
+
get :new, batch_document_ids: ["test2", "test88"]
|
48
|
+
expect(response).to have_selector("p[class='foo']")
|
49
|
+
end
|
54
50
|
end
|
55
|
-
|
51
|
+
|
56
52
|
describe '#create' do
|
57
53
|
it "should create a Collection" do
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
old_count = Collection.count
|
55
|
+
post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
|
56
|
+
expect(Collection.count).to eq(old_count+1)
|
61
57
|
expect(assigns[:collection].title).to eq("My First Collection ")
|
62
58
|
expect(assigns[:collection].description).to eq("The Description\r\n\r\nand more")
|
63
59
|
expect(assigns[:collection].depositor).to eq(@user.user_key)
|
64
|
-
expect(response).to redirect_to
|
60
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(assigns[:collection].id)
|
65
61
|
end
|
66
62
|
it "should add docs to collection if batch ids provided" do
|
67
63
|
@asset1 = ActiveFedora::Base.create!
|
@@ -77,12 +73,12 @@ describe CollectionsController, :type => :controller do
|
|
77
73
|
it "should add one doc to collection if batch ids provided and add the collection id to the document in the colledction" do
|
78
74
|
@asset1 = GenericFile.create!
|
79
75
|
post :create, batch_document_ids: [@asset1], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
|
80
|
-
expect(assigns[:collection].members).to eq
|
81
|
-
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.
|
76
|
+
expect(assigns[:collection].members).to eq([@asset1])
|
77
|
+
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
82
78
|
expect(asset_results["response"]["numFound"]).to eq(1)
|
83
79
|
doc = asset_results["response"]["docs"].first
|
84
|
-
expect(doc["id"]).to eq(@asset1.
|
85
|
-
afterupdate = GenericFile.find(@asset1.
|
80
|
+
expect(doc["id"]).to eq(@asset1.pid)
|
81
|
+
afterupdate = GenericFile.find(@asset1.pid)
|
86
82
|
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
|
87
83
|
end
|
88
84
|
it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
|
@@ -90,11 +86,11 @@ describe CollectionsController, :type => :controller do
|
|
90
86
|
@asset2 = GenericFile.create!
|
91
87
|
post :create, batch_document_ids: [@asset1,@asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
|
92
88
|
expect(assigns[:collection].members).to eq([@asset1,@asset2])
|
93
|
-
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.
|
89
|
+
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
94
90
|
expect(asset_results["response"]["numFound"]).to eq(1)
|
95
91
|
doc = asset_results["response"]["docs"].first
|
96
|
-
expect(doc["id"]).to eq(@asset1.
|
97
|
-
afterupdate = GenericFile.find(@asset1.
|
92
|
+
expect(doc["id"]).to eq(@asset1.pid)
|
93
|
+
afterupdate = GenericFile.find(@asset1.pid)
|
98
94
|
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
|
99
95
|
end
|
100
96
|
end
|
@@ -110,91 +106,86 @@ describe CollectionsController, :type => :controller do
|
|
110
106
|
allow(controller).to receive(:authorize!).and_return(true)
|
111
107
|
expect(controller).to receive(:authorize!).at_least(:once)
|
112
108
|
end
|
113
|
-
|
114
109
|
it "should update collection metadata" do
|
115
|
-
put :update, id: @collection.id, collection: {
|
116
|
-
expect(response).to redirect_to
|
110
|
+
put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
|
111
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
117
112
|
expect(assigns[:collection].title).to eq("New Title")
|
118
113
|
expect(assigns[:collection].description).to eq("New Description")
|
119
114
|
end
|
120
115
|
|
121
116
|
it "should call after_update" do
|
122
117
|
expect(controller).to receive(:after_update).and_call_original
|
123
|
-
put :update, id: @collection.id, collection: {
|
118
|
+
put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
|
124
119
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
put :update, id: @collection.id, collection: { members: "remove" }, batch_document_ids: [@asset1, @asset3]
|
139
|
-
expect(response).to redirect_to collections.collection_path(@collection)
|
140
|
-
expect(assigns[:collection].members).to eq([@asset2])
|
141
|
-
end
|
120
|
+
it "should support adding batches of members" do
|
121
|
+
@collection.members << @asset1
|
122
|
+
@collection.save
|
123
|
+
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
|
124
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
125
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid })
|
126
|
+
end
|
127
|
+
it "should support removing batches of members" do
|
128
|
+
@collection.members = [@asset1, @asset2, @asset3]
|
129
|
+
@collection.save
|
130
|
+
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset1, @asset3]
|
131
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
132
|
+
expect(assigns[:collection].members).to eq([@asset2])
|
142
133
|
end
|
143
|
-
|
144
134
|
it "should support setting members array" do
|
145
|
-
put :update, id: @collection.id, collection: {
|
146
|
-
expect(response).to redirect_to
|
147
|
-
expect(assigns[:collection].members).to
|
135
|
+
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
|
136
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
137
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid })
|
138
|
+
end
|
139
|
+
it "should support setting members array" do
|
140
|
+
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
|
141
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
142
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid })
|
148
143
|
end
|
149
|
-
|
150
144
|
it "should set/un-set collection on members" do
|
151
145
|
# Add to collection (sets collection on members)
|
152
|
-
|
153
|
-
expect(
|
154
|
-
|
146
|
+
solr_doc_before_add = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
147
|
+
expect(solr_doc_before_add[Solrizer.solr_name(:collection)]).to be_nil
|
148
|
+
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
|
149
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3].sort! { |a,b| a.pid <=> b.pid })
|
155
150
|
## Check that member lists collection in its solr doc
|
156
151
|
@asset2.reload
|
157
|
-
expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq
|
152
|
+
expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
158
153
|
## Check that member was re-indexed with collection info
|
159
|
-
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.
|
154
|
+
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
160
155
|
doc = asset_results["response"]["docs"].first
|
161
|
-
expect(doc["id"]).to eq(@asset2.
|
162
|
-
expect(doc[Solrizer.solr_name(:collection)]).to eq
|
156
|
+
expect(doc["id"]).to eq(@asset2.pid)
|
157
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
158
|
+
solr_doc_after_add = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
159
|
+
expect(solr_doc_after_add[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
163
160
|
|
164
161
|
# Remove from collection (un-sets collection on members)
|
165
|
-
|
166
|
-
expect(
|
167
|
-
|
162
|
+
solr_doc_before_remove = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
163
|
+
expect(solr_doc_before_remove[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
164
|
+
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset2]
|
165
|
+
expect(assigns[:collection].members).not_to include(@asset2)
|
168
166
|
## Check that member no longer lists collection in its solr doc
|
169
167
|
@asset2.reload
|
170
168
|
expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq([])
|
171
|
-
|
172
169
|
## Check that member was re-indexed without collection info
|
173
|
-
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.
|
170
|
+
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
174
171
|
doc = asset_results["response"]["docs"].first
|
175
|
-
expect(doc["id"]).to eq(@asset2.
|
172
|
+
expect(doc["id"]).to eq(@asset2.pid)
|
176
173
|
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
|
174
|
+
solr_doc_after_remove = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
175
|
+
expect(solr_doc_after_remove[Solrizer.solr_name(:collection)]).to be_nil
|
177
176
|
end
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
it "moves the members" do
|
192
|
-
put :update, id: @collection, collection: {members: "move"},
|
193
|
-
destination_collection_id: collection2, batch_document_ids: [@asset2, @asset3]
|
194
|
-
expect(@collection.reload.members).to eq [@asset1]
|
195
|
-
expect(collection2.reload.members).to match_array [@asset2, @asset3]
|
196
|
-
end
|
177
|
+
|
178
|
+
it "should allow moving members between collections" do
|
179
|
+
@collection.members = [@asset1, @asset2, @asset3]
|
180
|
+
@collection.save
|
181
|
+
@collection2 = Collection.new
|
182
|
+
@collection2.apply_depositor_metadata(@user.user_key)
|
183
|
+
@collection2.save
|
184
|
+
put :update, id: @collection.id, collection: {members:"move"}, destination_collection_id:@collection2.pid, batch_document_ids:[@asset2, @asset3]
|
185
|
+
expect(::Collection.find(@collection.pid).members).to eq([@asset1])
|
186
|
+
expect(::Collection.find(@collection2.pid).members).to eq([@asset2, @asset3])
|
197
187
|
end
|
188
|
+
|
198
189
|
end
|
199
190
|
|
200
191
|
describe "#destroy" do
|
@@ -220,15 +211,15 @@ describe CollectionsController, :type => :controller do
|
|
220
211
|
@collection.save
|
221
212
|
@asset1 = @asset1.reload
|
222
213
|
@asset1.update_index
|
223
|
-
expect(@asset1.collections).to eq
|
224
|
-
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.
|
214
|
+
expect(@asset1.collections).to eq([@collection])
|
215
|
+
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
225
216
|
expect(asset_results["response"]["numFound"]).to eq(1)
|
226
217
|
doc = asset_results["response"]["docs"].first
|
227
|
-
expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.
|
218
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
228
219
|
|
229
|
-
delete :destroy, id: @collection
|
220
|
+
delete :destroy, id: @collection.id
|
230
221
|
expect(@asset1.reload.collections).to eq([])
|
231
|
-
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.
|
222
|
+
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
232
223
|
expect(asset_results["response"]["numFound"]).to eq(1)
|
233
224
|
doc = asset_results["response"]["docs"].first
|
234
225
|
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
|
@@ -245,40 +236,71 @@ describe CollectionsController, :type => :controller do
|
|
245
236
|
@asset1 = GenericFile.create!(title: "First of the Assets")
|
246
237
|
@asset2 = GenericFile.create!(title: "Second of the Assets")
|
247
238
|
@asset3 = GenericFile.create!(title: "Third of the Assets")
|
248
|
-
@collection = Collection.new(
|
239
|
+
@collection = Collection.new(pid:"abc:123")
|
249
240
|
@collection.title = "My collection"
|
250
241
|
@collection.apply_depositor_metadata(@user.user_key)
|
251
|
-
@collection.members = [@asset1
|
252
|
-
@collection.save
|
253
|
-
|
242
|
+
@collection.members = [@asset1,@asset2,@asset3]
|
243
|
+
@collection.save
|
244
|
+
allow(controller).to receive(:authorize!).and_return(true)
|
254
245
|
allow(controller).to receive(:apply_gated_search)
|
255
246
|
end
|
256
|
-
|
247
|
+
it "should show the collections" do
|
248
|
+
get :show, id: @collection.id
|
249
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
250
|
+
ids = assigns[:member_docs].map {|d| d.id}
|
251
|
+
expect(ids).to include @asset1.pid
|
252
|
+
expect(ids).to include @asset2.pid
|
253
|
+
expect(ids).to include @asset3.pid
|
254
|
+
end
|
255
|
+
context "when items have been added and removed" do
|
256
|
+
it "should return the items that are in the collection and not return items that have been removed" do
|
257
|
+
asset4 = GenericFile.create!(title: "Fourth of the Assets")
|
258
|
+
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset2.pid]
|
259
|
+
controller.batch = nil
|
260
|
+
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[asset4.pid]
|
261
|
+
get :show, id: @collection.id
|
262
|
+
ids = assigns[:member_docs].map(&:id)
|
263
|
+
expect(ids).to include @asset1.pid, @asset3.pid, asset4.pid
|
264
|
+
expect(ids).to_not include @asset2.pid
|
265
|
+
end
|
266
|
+
end
|
257
267
|
describe "additional collections" do
|
258
268
|
before do
|
259
269
|
@asset4 = GenericFile.create!(title: "#{@asset1.id}")
|
260
|
-
@collection2 = Collection.new(
|
270
|
+
@collection2 = Collection.new(pid:"abc:1234")
|
261
271
|
@collection2.title = "Other collection"
|
262
272
|
@collection2.apply_depositor_metadata(@user.user_key)
|
263
273
|
@collection2.members = [@asset4]
|
264
274
|
@collection2.save
|
275
|
+
@asset4 = @asset4.reload
|
276
|
+
expect(@asset4.collections).to eq([@collection2])
|
265
277
|
end
|
266
278
|
|
267
279
|
it "should show only the collections assets" do
|
268
|
-
get :show, id: @collection
|
269
|
-
expect(assigns[:collection].title).to eq
|
270
|
-
|
271
|
-
|
280
|
+
get :show, id: @collection.pid
|
281
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
282
|
+
ids = assigns[:member_docs].map {|d| d.id}
|
283
|
+
expect(ids).to include @asset1.pid
|
284
|
+
expect(ids).to include @asset2.pid
|
285
|
+
expect(ids).to include @asset3.pid
|
286
|
+
expect(ids).not_to include @asset4.pid
|
272
287
|
|
288
|
+
end
|
273
289
|
it "should show only the other collections assets" do
|
274
|
-
|
275
|
-
|
276
|
-
expect(assigns[:
|
290
|
+
|
291
|
+
get :show, id: @collection2.pid
|
292
|
+
expect(assigns[:collection].title).to eq(@collection2.title)
|
293
|
+
ids = assigns[:member_docs].map {|d| d.id}
|
294
|
+
expect(ids).not_to include @asset1.pid
|
295
|
+
expect(ids).not_to include @asset2.pid
|
296
|
+
expect(ids).not_to include @asset3.pid
|
297
|
+
expect(ids).to include @asset4.pid
|
298
|
+
|
277
299
|
end
|
278
300
|
end
|
279
301
|
|
280
302
|
it "when the collection is empty it should show no assets" do
|
281
|
-
get :show, id: Collection.create(title: "Empty collection")
|
303
|
+
get :show, id: Collection.create(title: "Empty collection").id
|
282
304
|
expect(assigns[:collection].title).to eq("Empty collection")
|
283
305
|
expect(assigns[:member_docs]).to be_empty
|
284
306
|
end
|
@@ -286,27 +308,34 @@ describe CollectionsController, :type => :controller do
|
|
286
308
|
# NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
|
287
309
|
it "should query the collections" do
|
288
310
|
get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
|
289
|
-
expect(assigns[:collection].title).to eq
|
290
|
-
|
311
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
312
|
+
ids = assigns[:member_docs].map {|d| d.id}
|
313
|
+
expect(ids).to include @asset1.pid
|
314
|
+
expect(ids).not_to include @asset2.pid
|
315
|
+
expect(ids).not_to include @asset3.pid
|
291
316
|
end
|
292
317
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
318
|
+
# NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
|
319
|
+
it "should query the collections and show only the collection assets" do
|
320
|
+
@asset4 = GenericFile.create!(title: "#{@asset1.id} #{@asset1.title}")
|
321
|
+
@asset5 = GenericFile.create!(title: "#{@asset1.title}")
|
322
|
+
get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
|
323
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
324
|
+
ids = assigns[:member_docs].map {|d| d.id}
|
325
|
+
expect(ids).to include @asset1.pid
|
326
|
+
expect(ids).not_to include @asset2.pid
|
327
|
+
expect(ids).not_to include @asset3.pid
|
328
|
+
expect(ids).not_to include @asset4.pid
|
329
|
+
expect(ids).not_to include @asset5.pid
|
304
330
|
end
|
305
331
|
|
306
332
|
it "should query the collections with rows" do
|
307
|
-
get :show, id: @collection, rows:"2"
|
308
|
-
expect(assigns[:collection].title).to eq
|
309
|
-
|
333
|
+
get :show, id: @collection.id, rows:"2"
|
334
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
335
|
+
ids = assigns[:member_docs].map {|d| d.id}
|
336
|
+
expect(ids.count).to eq(2)
|
310
337
|
end
|
338
|
+
|
311
339
|
end
|
340
|
+
|
312
341
|
end
|