hydra-collections 3.0.0.beta3 → 4.0.0.beta1

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.
@@ -1,18 +1,3 @@
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 -*-
16
1
  module Hydra
17
2
  module Collections
18
3
  module SolrDocumentBehavior
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module Collections
3
- VERSION = "3.0.0.beta3"
3
+ VERSION = "4.0.0.beta1"
4
4
  end
5
5
  end
@@ -1,40 +1,26 @@
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
1
  require 'spec_helper'
16
2
 
17
3
  include Rails.application.routes.url_helpers
18
4
 
19
5
  describe CatalogController, :type => :controller do
6
+
20
7
  before do
21
8
  allow(controller).to receive(:has_access?).and_return(true)
22
9
  @user = FactoryGirl.find_or_create(:user)
23
- @collection = Collection.new title:"Test"
10
+ @collection = Collection.new title: "Test"
24
11
  @collection.apply_depositor_metadata(@user.user_key)
25
12
  @collection.read_groups = ["public"]
26
- @collection.save
13
+ @collection.save!
27
14
  end
28
15
 
29
16
  after do
30
- @user.delete
31
- @collection.delete
17
+ @collection.destroy
32
18
  end
33
19
 
20
+ routes { Rails.application.routes }
34
21
 
35
22
  describe '#index' do
36
23
  it 'should assign @user_collections' do
37
- @routes = Rails.application.routes
38
24
  get :index
39
25
  expect(assigns(:user_collections)).to be_kind_of(Array)
40
26
  expect(assigns(:user_collections).index{|d| d.id == @collection.id}).not_to be_nil
@@ -1,33 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CollectionsController, :type => :controller do
4
+ let(:collections) { Hydra::Collections::Engine.routes.url_helpers }
5
+
4
6
  before(:all) do
5
7
  CollectionsController.configure_blacklight do |config|
6
8
  config.default_solr_params = {:qf => 'label_tesim'}
7
9
  end
8
10
 
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
14
26
 
15
- attr_accessor :title
16
27
  def to_solr(solr_doc={})
17
- super
18
- solr_doc = index_collection_pids(solr_doc)
19
- solr_doc["label_tesim"] = self.title
20
- solr_doc
28
+ super.tap do |solr_doc|
29
+ solr_doc = index_collection_ids(solr_doc)
30
+ solr_doc["label_tesim"] = self.title
31
+ end
21
32
  end
22
33
  end
23
34
  end
35
+
24
36
  after(:all) do
25
- @user.destroy
26
- GenericFile.destroy_all
27
- Collection.destroy_all
28
37
  Object.send(:remove_const, :GenericFile)
29
38
  end
30
-
39
+
31
40
  before do
32
41
  allow(controller).to receive(:has_access?).and_return(true)
33
42
 
@@ -42,22 +51,17 @@ describe CollectionsController, :type => :controller do
42
51
  get :new
43
52
  expect(assigns(:collection)).to be_kind_of(Collection)
44
53
  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
50
54
  end
51
-
55
+
52
56
  describe '#create' do
53
57
  it "should create a Collection" do
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)
58
+ expect {
59
+ post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
60
+ }.to change { Collection.count }.by(1)
57
61
  expect(assigns[:collection].title).to eq("My First Collection ")
58
62
  expect(assigns[:collection].description).to eq("The Description\r\n\r\nand more")
59
63
  expect(assigns[:collection].depositor).to eq(@user.user_key)
60
- expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(assigns[:collection].id)
64
+ expect(response).to redirect_to collections.collection_path(assigns[:collection])
61
65
  end
62
66
  it "should add docs to collection if batch ids provided" do
63
67
  @asset1 = ActiveFedora::Base.create!
@@ -73,12 +77,12 @@ describe CollectionsController, :type => :controller do
73
77
  it "should add one doc to collection if batch ids provided and add the collection id to the document in the colledction" do
74
78
  @asset1 = GenericFile.create!
75
79
  post :create, batch_document_ids: [@asset1], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
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)]}
80
+ expect(assigns[:collection].members).to eq [@asset1]
81
+ asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
78
82
  expect(asset_results["response"]["numFound"]).to eq(1)
79
83
  doc = asset_results["response"]["docs"].first
80
- expect(doc["id"]).to eq(@asset1.pid)
81
- afterupdate = GenericFile.find(@asset1.pid)
84
+ expect(doc["id"]).to eq(@asset1.id)
85
+ afterupdate = GenericFile.find(@asset1.id)
82
86
  expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
83
87
  end
84
88
  it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
@@ -86,11 +90,11 @@ describe CollectionsController, :type => :controller do
86
90
  @asset2 = GenericFile.create!
87
91
  post :create, batch_document_ids: [@asset1,@asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
88
92
  expect(assigns[:collection].members).to eq([@asset1,@asset2])
89
- asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
93
+ asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
90
94
  expect(asset_results["response"]["numFound"]).to eq(1)
91
95
  doc = asset_results["response"]["docs"].first
92
- expect(doc["id"]).to eq(@asset1.pid)
93
- afterupdate = GenericFile.find(@asset1.pid)
96
+ expect(doc["id"]).to eq(@asset1.id)
97
+ afterupdate = GenericFile.find(@asset1.id)
94
98
  expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
95
99
  end
96
100
  end
@@ -106,86 +110,91 @@ describe CollectionsController, :type => :controller do
106
110
  allow(controller).to receive(:authorize!).and_return(true)
107
111
  expect(controller).to receive(:authorize!).at_least(:once)
108
112
  end
113
+
109
114
  it "should update collection metadata" do
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)
115
+ put :update, id: @collection.id, collection: { title: "New Title", description: "New Description" }
116
+ expect(response).to redirect_to collections.collection_path(@collection)
112
117
  expect(assigns[:collection].title).to eq("New Title")
113
118
  expect(assigns[:collection].description).to eq("New Description")
114
119
  end
115
120
 
116
121
  it "should call after_update" do
117
122
  expect(controller).to receive(:after_update).and_call_original
118
- put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
119
- 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])
123
+ put :update, id: @collection.id, collection: { title: "New Title", description: "New Description" }
133
124
  end
134
- it "should support setting members array" do
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 })
125
+
126
+ context "when there are existing members in the collection" do
127
+ it "should support adding batches of members" do
128
+ @collection.members << @asset1
129
+ @collection.save
130
+ put :update, id: @collection.id, collection: { members:"add" }, batch_document_ids: [@asset2, @asset3]
131
+ expect(response).to redirect_to collections.collection_path(@collection)
132
+ expect(assigns[:collection].members).to match_array [@asset2, @asset3, @asset1]
133
+ end
134
+
135
+ it "should support removing batches of members" do
136
+ @collection.members = [@asset1, @asset2, @asset3]
137
+ @collection.save
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
138
142
  end
143
+
139
144
  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 })
145
+ put :update, id: @collection.id, collection: { members: "add" }, batch_document_ids: [@asset2, @asset3, @asset1]
146
+ expect(response).to redirect_to collections.collection_path(@collection)
147
+ expect(assigns[:collection].members).to match_array [@asset2, @asset3, @asset1]
143
148
  end
149
+
144
150
  it "should set/un-set collection on members" do
145
151
  # Add to collection (sets collection on members)
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 })
152
+ put :update, id: @collection.id, collection: { members: "add"}, batch_document_ids: [@asset2, @asset3]
153
+ expect(assigns[:collection].members).to match_array [@asset2, @asset3]
154
+
150
155
  ## Check that member lists collection in its solr doc
151
156
  @asset2.reload
152
- expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
157
+ expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq [@collection.id]
153
158
  ## Check that member was re-indexed with collection info
154
- asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
159
+ asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
155
160
  doc = asset_results["response"]["docs"].first
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])
161
+ expect(doc["id"]).to eq(@asset2.id)
162
+ expect(doc[Solrizer.solr_name(:collection)]).to eq [@collection.id]
160
163
 
161
164
  # Remove from collection (un-sets collection on members)
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)
165
+ put :update, id: @collection, collection: { members:"remove" }, batch_document_ids: [@asset2]
166
+ expect(assigns[:collection].members).to_not include(@asset2)
167
+
166
168
  ## Check that member no longer lists collection in its solr doc
167
169
  @asset2.reload
168
170
  expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq([])
171
+
169
172
  ## Check that member was re-indexed without collection info
170
- asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
173
+ asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
171
174
  doc = asset_results["response"]["docs"].first
172
- expect(doc["id"]).to eq(@asset2.pid)
175
+ expect(doc["id"]).to eq(@asset2.id)
173
176
  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
176
- 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])
187
177
  end
188
178
 
179
+ context "when moving members between collections" do
180
+ before do
181
+ @collection.members = [@asset1, @asset2, @asset3]
182
+ @collection.save
183
+ end
184
+ let(:collection2) do
185
+ Collection.new.tap do |col|
186
+ col.apply_depositor_metadata(@user.user_key)
187
+ col.save
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
197
+ end
189
198
  end
190
199
 
191
200
  describe "#destroy" do
@@ -211,15 +220,15 @@ describe CollectionsController, :type => :controller do
211
220
  @collection.save
212
221
  @asset1 = @asset1.reload
213
222
  @asset1.update_index
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)]}
223
+ expect(@asset1.collections).to eq [@collection]
224
+ asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
216
225
  expect(asset_results["response"]["numFound"]).to eq(1)
217
226
  doc = asset_results["response"]["docs"].first
218
- expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
227
+ expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.id])
219
228
 
220
- delete :destroy, id: @collection.id
229
+ delete :destroy, id: @collection
221
230
  expect(@asset1.reload.collections).to eq([])
222
- asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
231
+ asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
223
232
  expect(asset_results["response"]["numFound"]).to eq(1)
224
233
  doc = asset_results["response"]["docs"].first
225
234
  expect(doc[Solrizer.solr_name(:collection)]).to be_nil
@@ -236,71 +245,40 @@ describe CollectionsController, :type => :controller do
236
245
  @asset1 = GenericFile.create!(title: "First of the Assets")
237
246
  @asset2 = GenericFile.create!(title: "Second of the Assets")
238
247
  @asset3 = GenericFile.create!(title: "Third of the Assets")
239
- @collection = Collection.new(pid:"abc:123")
248
+ @collection = Collection.new(id:"abc123")
240
249
  @collection.title = "My collection"
241
250
  @collection.apply_depositor_metadata(@user.user_key)
242
- @collection.members = [@asset1,@asset2,@asset3]
243
- @collection.save
244
- allow(controller).to receive(:authorize!).and_return(true)
251
+ @collection.members = [@asset1, @asset2, @asset3]
252
+ @collection.save!
253
+ expect(controller).to receive(:authorize!).and_return(true)
245
254
  allow(controller).to receive(:apply_gated_search)
246
255
  end
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
256
+
267
257
  describe "additional collections" do
268
258
  before do
269
259
  @asset4 = GenericFile.create!(title: "#{@asset1.id}")
270
- @collection2 = Collection.new(pid:"abc:1234")
260
+ @collection2 = Collection.new(id: "abc1234")
271
261
  @collection2.title = "Other collection"
272
262
  @collection2.apply_depositor_metadata(@user.user_key)
273
263
  @collection2.members = [@asset4]
274
264
  @collection2.save
275
- @asset4 = @asset4.reload
276
- expect(@asset4.collections).to eq([@collection2])
277
265
  end
278
266
 
279
267
  it "should show only the collections assets" do
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
287
-
268
+ get :show, id: @collection
269
+ expect(assigns[:collection].title).to eq @collection.title
270
+ expect(assigns[:member_docs].map(&:id)).to match_array [@asset1.id, @asset2.id, @asset3.id]
288
271
  end
289
- it "should show only the other collections assets" do
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
272
 
273
+ it "should show only the other collections assets" do
274
+ get :show, id: @collection2
275
+ expect(assigns[:collection].title).to eq @collection2.title
276
+ expect(assigns[:member_docs].map(&:id)).to match_array [@asset4.id]
299
277
  end
300
278
  end
301
279
 
302
280
  it "when the collection is empty it should show no assets" do
303
- get :show, id: Collection.create(title: "Empty collection").id
281
+ get :show, id: Collection.create(title: "Empty collection")
304
282
  expect(assigns[:collection].title).to eq("Empty collection")
305
283
  expect(assigns[:member_docs]).to be_empty
306
284
  end
@@ -308,34 +286,27 @@ describe CollectionsController, :type => :controller do
308
286
  # NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
309
287
  it "should query the collections" do
310
288
  get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
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
289
+ expect(assigns[:collection].title).to eq @collection.title
290
+ expect(assigns[:member_docs].map(&:id)).to match_array [@asset1.id]
316
291
  end
317
292
 
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
293
+ context "When there are search matches that are not in the collection" do
294
+ before do
295
+ GenericFile.create!(title: "#{@asset1.id} #{@asset1.title}")
296
+ GenericFile.create!(title: @asset1.title)
297
+ end
298
+ # NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
299
+ it "should query the collections and show only the collection assets" do
300
+ get :show, id: @collection, cq: "\"#{@asset1.title}\""
301
+ expect(assigns[:collection].title).to eq @collection.title
302
+ expect(assigns[:member_docs].map(&:id)).to match_array [@asset1.id]
303
+ end
330
304
  end
331
305
 
332
306
  it "should query the collections with rows" do
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)
307
+ get :show, id: @collection, rows:"2"
308
+ expect(assigns[:collection].title).to eq @collection.title
309
+ expect(assigns[:member_docs].size).to eq 2
337
310
  end
338
-
339
311
  end
340
-
341
312
  end