curation_concerns 0.12.0.pre9 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/curation_concerns/collections_controller_behavior.rb +1 -1
- data/app/helpers/curation_concerns/collections_helper_behavior.rb +0 -15
- data/app/views/collections/_form_for_select_collection.html.erb +3 -3
- data/lib/curation_concerns/version.rb +1 -1
- data/spec/controllers/curation_concerns/collections_controller_spec.rb +44 -0
- data/spec/helpers/collections_helper_spec.rb +0 -41
- metadata +4 -7
- data/app/views/collections/_form_for_select_destination_collection.html.erb +0 -21
- data/spec/controllers/collections_controller_spec.rb +0 -272
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 385f4e3748f29f5498d701ecaca78b830e466317
|
4
|
+
data.tar.gz: 9df2179967ddec4f5eac6e8a3e2adec52f50b61a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 560677b0f20e0024f49e8a30fbb19114be599f2bbba7a360808c008b0d888593a2051c7bfea46c3a606423299a7e0464f0fa3a7044b398735bb86c106c9aa86c
|
7
|
+
data.tar.gz: 50a8a6920a23729f5a83fa73bb92fc41ec25e27c520cbe6414405f7e14d54c59711c7ac8fab580eb9e3b60712a5aab2523133cdd3a1439e867dbac115832dd08
|
@@ -160,7 +160,7 @@ module CurationConcerns
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def collection_search_builder
|
163
|
-
collection_search_builder_class.new(self).with(params.except(:q)).tap do |builder|
|
163
|
+
collection_search_builder_class.new(self).with(params.except(:q, :page)).tap do |builder|
|
164
164
|
builder.current_ability = current_ability
|
165
165
|
end
|
166
166
|
end
|
@@ -5,21 +5,6 @@ module CurationConcerns
|
|
5
5
|
!params[:cq].blank?
|
6
6
|
end
|
7
7
|
|
8
|
-
# Displays the Collections create collection button. Put this in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
|
9
|
-
def button_for_create_collection(label = 'Create Collection')
|
10
|
-
render '/collections/button_create_collection', label: label
|
11
|
-
end
|
12
|
-
|
13
|
-
# Displays the Collections update collection button. Put this in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
|
14
|
-
def button_for_update_collection(label = 'Update Collection', collection_id = 'collection_replace_id')
|
15
|
-
render '/collections/button_for_update_collection', label: label, collection_id: collection_id
|
16
|
-
end
|
17
|
-
|
18
|
-
# Displays the Collections delete collection button. Put this in your search result page for each collection found.
|
19
|
-
def button_for_delete_collection(collection, label = 'Delete Collection', confirm = 'Are you sure?')
|
20
|
-
render '/collections/button_for_delete_collection', collection: collection, label: label, confirm: confirm
|
21
|
-
end
|
22
|
-
|
23
8
|
def button_for_remove_from_collection(collection, document, label = 'Remove From Collection')
|
24
9
|
render '/collections/button_remove_from_collection', collection: collection, label: label, document: document
|
25
10
|
end
|
@@ -23,10 +23,10 @@
|
|
23
23
|
<div class="modal-footer">
|
24
24
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
25
25
|
<% if user_collections.blank? %>
|
26
|
-
<%=
|
26
|
+
<%= render '/collections/button_create_collection', label: 'Create Collection' %>
|
27
27
|
<% else %>
|
28
|
-
<%= button_for_update_collection %>
|
29
|
-
<%=
|
28
|
+
<%= render '/collections/button_for_update_collection', label: 'Update Collection', collection_id: 'collection_replace_id' %>
|
29
|
+
<%= render '/collections/button_create_collection', label: 'Add to new Collection' %>
|
30
30
|
<% end %>
|
31
31
|
</div>
|
32
32
|
</div><!-- /.modal-content -->
|
@@ -78,6 +78,20 @@ describe CollectionsController do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
describe '#index' do
|
82
|
+
before { sign_in user }
|
83
|
+
let!(:collection1) { create(:collection, title: ['Beta'], user: user) }
|
84
|
+
let!(:collection2) { create(:collection, title: ['Alpha'], user: user) }
|
85
|
+
let!(:generic_work) { create(:generic_work, user: user) }
|
86
|
+
|
87
|
+
it 'shows a list of collections sorted alphabetically' do
|
88
|
+
get :index
|
89
|
+
expect(response).to be_successful
|
90
|
+
expect(assigns[:document_list].map(&:id)).not_to include generic_work.id
|
91
|
+
expect(assigns[:document_list].map(&:id)).to match_array [collection2.id, collection1.id]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
81
95
|
describe '#update' do
|
82
96
|
before { sign_in user }
|
83
97
|
|
@@ -137,6 +151,28 @@ describe CollectionsController do
|
|
137
151
|
end
|
138
152
|
end
|
139
153
|
|
154
|
+
context 'when moving members between collections' do
|
155
|
+
let(:asset1) { create(:generic_work, user: user) }
|
156
|
+
let(:asset2) { create(:generic_work, user: user) }
|
157
|
+
let(:asset3) { create(:generic_work, user: user) }
|
158
|
+
before do
|
159
|
+
collection.members = [asset1, asset2, asset3]
|
160
|
+
collection.save!
|
161
|
+
end
|
162
|
+
let(:collection2) do
|
163
|
+
Collection.create(title: ['Some Collection']) do |col|
|
164
|
+
col.apply_depositor_metadata(user.user_key)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'moves the members' do
|
169
|
+
put :update, id: collection, collection: { members: 'move' },
|
170
|
+
destination_collection_id: collection2, batch_document_ids: [asset2, asset3]
|
171
|
+
expect(collection.reload.members).to eq [asset1]
|
172
|
+
expect(collection2.reload.members).to match_array [asset2, asset3]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
140
176
|
context 'updating a collections metadata' do
|
141
177
|
it 'saves the metadata' do
|
142
178
|
put :update, id: collection, collection: { creator: ['Emily'], visibility: 'open' }
|
@@ -181,6 +217,14 @@ describe CollectionsController do
|
|
181
217
|
expect(assigns[:presenter].title).to eq 'Collection Title'
|
182
218
|
end
|
183
219
|
end
|
220
|
+
context 'when the page parameter is passed' do
|
221
|
+
it 'loads the collection (paying no attention to the page param)' do
|
222
|
+
get :show, id: collection, page: '2'
|
223
|
+
expect(response).to be_successful
|
224
|
+
expect(assigns[:presenter]).to be_kind_of CurationConcerns::CollectionPresenter
|
225
|
+
expect(assigns[:presenter].title).to eq 'Collection Title'
|
226
|
+
end
|
227
|
+
end
|
184
228
|
end
|
185
229
|
|
186
230
|
context 'not signed in' do
|
@@ -15,47 +15,6 @@ describe CollectionsHelper, type: :helper do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe "button_for_create_collection" do
|
19
|
-
it "creates a button to the collections new path" do
|
20
|
-
str = String.new(helper.button_for_create_collection)
|
21
|
-
doc = Nokogiri::HTML(str)
|
22
|
-
form = doc.xpath('//form').first
|
23
|
-
expect(form.attr('action')).to eq(new_collection_path.to_s)
|
24
|
-
i = form.xpath('.//input').first
|
25
|
-
expect(i.attr('type')).to eq('submit')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "creates a button with my text" do
|
29
|
-
str = String.new(helper.button_for_create_collection("Create My Button"))
|
30
|
-
doc = Nokogiri::HTML(str)
|
31
|
-
form = doc.xpath('//form').first
|
32
|
-
expect(form.attr('action')).to eq(new_collection_path.to_s)
|
33
|
-
i = form.xpath('.//input').first
|
34
|
-
expect(i.attr('value')).to eq('Create My Button')
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "button_for_delete_collection" do
|
39
|
-
let(:collection) { FactoryGirl.create(:collection) }
|
40
|
-
|
41
|
-
it "creates a button to the collections delete path" do
|
42
|
-
str = button_for_delete_collection collection
|
43
|
-
doc = Nokogiri::HTML(str)
|
44
|
-
form = doc.xpath('//form').first
|
45
|
-
expect(form.attr('action')).to eq collection_path(collection)
|
46
|
-
i = form.xpath('.//input')[1]
|
47
|
-
expect(i.attr('type')).to eq('submit')
|
48
|
-
end
|
49
|
-
it "creates a button with my text" do
|
50
|
-
str = button_for_delete_collection collection, "Delete My Button"
|
51
|
-
doc = Nokogiri::HTML(str)
|
52
|
-
form = doc.xpath('//form').first
|
53
|
-
expect(form.attr('action')).to eq collection_path(collection)
|
54
|
-
i = form.xpath('.//input')[1]
|
55
|
-
expect(i.attr('value')).to eq("Delete My Button")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
18
|
describe "button_for_remove_from_collection" do
|
60
19
|
let(:item) { double(id: 'changeme:123') }
|
61
20
|
let(:collection) { FactoryGirl.create(:collection) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curation_concerns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.0
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-04-
|
13
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hydra-head
|
@@ -842,7 +842,6 @@ files:
|
|
842
842
|
- app/views/collections/_form.html.erb
|
843
843
|
- app/views/collections/_form_additional_information.html.erb
|
844
844
|
- app/views/collections/_form_for_select_collection.html.erb
|
845
|
-
- app/views/collections/_form_for_select_destination_collection.html.erb
|
846
845
|
- app/views/collections/_form_permission.html.erb
|
847
846
|
- app/views/collections/_form_to_add_member.html.erb
|
848
847
|
- app/views/collections/_index_default.html.erb
|
@@ -1046,7 +1045,6 @@ files:
|
|
1046
1045
|
- spec/actors/curation_concerns/work_actor_spec.rb
|
1047
1046
|
- spec/controllers/accepts_batches_controller_spec.rb
|
1048
1047
|
- spec/controllers/catalog_controller_spec.rb
|
1049
|
-
- spec/controllers/collections_controller_spec.rb
|
1050
1048
|
- spec/controllers/curation_concerns/classify_concerns_controller_spec.rb
|
1051
1049
|
- spec/controllers/curation_concerns/collections_controller_spec.rb
|
1052
1050
|
- spec/controllers/curation_concerns/file_sets_controller_json_spec.rb
|
@@ -1221,9 +1219,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
1221
1219
|
version: '0'
|
1222
1220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
1223
1221
|
requirements:
|
1224
|
-
- - "
|
1222
|
+
- - ">="
|
1225
1223
|
- !ruby/object:Gem::Version
|
1226
|
-
version:
|
1224
|
+
version: '0'
|
1227
1225
|
requirements: []
|
1228
1226
|
rubyforge_project:
|
1229
1227
|
rubygems_version: 2.5.1
|
@@ -1245,7 +1243,6 @@ test_files:
|
|
1245
1243
|
- spec/actors/curation_concerns/work_actor_spec.rb
|
1246
1244
|
- spec/controllers/accepts_batches_controller_spec.rb
|
1247
1245
|
- spec/controllers/catalog_controller_spec.rb
|
1248
|
-
- spec/controllers/collections_controller_spec.rb
|
1249
1246
|
- spec/controllers/curation_concerns/classify_concerns_controller_spec.rb
|
1250
1247
|
- spec/controllers/curation_concerns/collections_controller_spec.rb
|
1251
1248
|
- spec/controllers/curation_concerns/file_sets_controller_json_spec.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
<% if user_collections.nil?%>
|
2
|
-
<b> Make sure you have included CurationConcerns::SelectsCollections in your controller for this page and
|
3
|
-
added a before filter with one of the find_collections variations depending on your access level: find_collections, find_collections_with_read_access, find_collections_with_edit_access
|
4
|
-
</b>
|
5
|
-
<% elsif user_collections.blank? %>
|
6
|
-
<b> You do not have access to any existing collections please create a collection. </b>
|
7
|
-
<% else %>
|
8
|
-
Please Select your collection to add you files to:
|
9
|
-
<%= form_tag(collection_path(@collection), :method => "put") do %>
|
10
|
-
<input type="hidden" name="test" value="val" />
|
11
|
-
<%= hash_as_hidden_fields({:collection =>{members:"move"}}) %>
|
12
|
-
<div class="collection-list">
|
13
|
-
<ul>
|
14
|
-
<% user_collections.each do |collection| %>
|
15
|
-
<li> <%= radio_button_tag(:destination_collection_id, collection.id, false, :class => "collection-selector") %><%= label_tag(:collection, collection.title) %> </li>
|
16
|
-
<% end %>
|
17
|
-
</ul>
|
18
|
-
</div>
|
19
|
-
<%= button_to "Move to Selected Collection", collections_path, :method=>:put, :class=>"btn btn-primary collection-update submits-batches", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-move' %>
|
20
|
-
<% end %>
|
21
|
-
<% end %>
|
@@ -1,272 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CollectionsController, type: :controller do
|
4
|
-
let(:user) { FactoryGirl.create(:user) }
|
5
|
-
|
6
|
-
before do
|
7
|
-
allow(controller).to receive(:has_access?).and_return(true)
|
8
|
-
|
9
|
-
sign_in user
|
10
|
-
allow_any_instance_of(User).to receive(:groups).and_return([])
|
11
|
-
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#index' do
|
15
|
-
let!(:collection1) { FactoryGirl.create(:collection, title: ['Beta'], user: user) }
|
16
|
-
let!(:collection2) { FactoryGirl.create(:collection, title: ['Alpha'], user: user) }
|
17
|
-
let!(:generic_file) { create(:generic_work, user: user) }
|
18
|
-
|
19
|
-
it 'shows a list of collections sorted alphabetically' do
|
20
|
-
get :index
|
21
|
-
expect(response).to be_successful
|
22
|
-
expect(assigns[:document_list].map(&:id)).not_to include generic_file.id
|
23
|
-
expect(assigns[:document_list].map(&:id)).to match_array [collection2.id, collection1.id]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#new' do
|
28
|
-
it 'assigns @collection' do
|
29
|
-
get :new
|
30
|
-
expect(assigns(:collection)).to be_kind_of(Collection)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#create' do
|
35
|
-
it 'creates a Collection' do
|
36
|
-
expect do
|
37
|
-
post :create, collection: { title: ['My First Collection'],
|
38
|
-
description: ["The Description\r\n\r\nand more"] }
|
39
|
-
end.to change { Collection.count }.by(1)
|
40
|
-
expect(assigns[:collection].title).to eq ['My First Collection']
|
41
|
-
expect(assigns[:collection].description).to eq ["The Description\r\n\r\nand more"]
|
42
|
-
expect(assigns[:collection].depositor).to eq(user.user_key)
|
43
|
-
expect(response).to redirect_to collection_path(assigns[:collection])
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'adds docs to collection if batch ids provided' do
|
47
|
-
@asset1 = create(:generic_work, user: user)
|
48
|
-
@asset2 = create(:generic_work, user: user)
|
49
|
-
post :create, batch_document_ids: [@asset1, @asset2],
|
50
|
-
collection: { title: ['My Secong Collection'],
|
51
|
-
description: ["The Description\r\n\r\nand more"] }
|
52
|
-
expect(assigns[:collection].members).to eq [@asset1, @asset2]
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'calls after_create' do
|
56
|
-
expect(controller).to receive(:after_create).and_call_original
|
57
|
-
post :create, collection: { title: ['My First Collection'],
|
58
|
-
description: ["The Description\r\n\r\nand more"] }
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'adds one doc to collection if batch ids provided and add the collection id to the document in the colledction' do
|
62
|
-
@asset1 = create(:generic_work, user: user)
|
63
|
-
post :create, batch_document_ids: [@asset1],
|
64
|
-
collection: { title: ['My Second Collection'],
|
65
|
-
description: ["The Description\r\n\r\nand more"] }
|
66
|
-
expect(assigns[:collection].members).to eq [@asset1]
|
67
|
-
asset_results = ActiveFedora::SolrService.instance.conn.get 'select', params: { fq: ["id:\"#{@asset1.id}\""], fl: ['id', Solrizer.solr_name(:collection)] }
|
68
|
-
expect(asset_results['response']['numFound']).to eq(1)
|
69
|
-
doc = asset_results['response']['docs'].first
|
70
|
-
expect(doc['id']).to eq @asset1.id
|
71
|
-
afterupdate = GenericWork.find(@asset1.id)
|
72
|
-
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'adds docs to collection if batch ids provided and add the collection id to the documents int he colledction' do
|
76
|
-
@asset1 = create(:generic_work, user: user)
|
77
|
-
@asset2 = create(:generic_work, user: user)
|
78
|
-
post :create, batch_document_ids: [@asset1, @asset2],
|
79
|
-
collection: { title: ['My Secong Collection'],
|
80
|
-
description: ["The Description\r\n\r\nand more"] }
|
81
|
-
expect(assigns[:collection].members).to eq [@asset1, @asset2]
|
82
|
-
asset_results = ActiveFedora::SolrService.instance.conn.get 'select', params: { fq: ["id:\"#{@asset1.id}\""], fl: ['id', Solrizer.solr_name(:collection)] }
|
83
|
-
expect(asset_results['response']['numFound']).to eq(1)
|
84
|
-
doc = asset_results['response']['docs'].first
|
85
|
-
expect(doc['id']).to eq(@asset1.id)
|
86
|
-
afterupdate = GenericWork.find(@asset1.id)
|
87
|
-
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#update' do
|
92
|
-
let(:collection) { FactoryGirl.create(:collection, user: user) }
|
93
|
-
before do
|
94
|
-
@asset1 = create(:generic_work, user: user)
|
95
|
-
@asset2 = create(:generic_work, user: user)
|
96
|
-
@asset3 = create(:generic_work, user: user)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'updates collection metadata' do
|
100
|
-
put :update, id: collection.id, collection: { title: ['New Title'], description: ['New Description'] }
|
101
|
-
expect(response).to redirect_to collection_path(collection)
|
102
|
-
expect(assigns[:collection].title).to eq(['New Title'])
|
103
|
-
expect(assigns[:collection].description).to eq(['New Description'])
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'calls after_update' do
|
107
|
-
expect(controller).to receive(:after_update).and_call_original
|
108
|
-
put :update, id: collection.id, collection: { title: ['New Title'], description: ['New Description'] }
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when updating fails' do
|
112
|
-
before do
|
113
|
-
allow_any_instance_of(Collection).to receive(:save).and_return(false)
|
114
|
-
end
|
115
|
-
it 'renders edit succesfully' do
|
116
|
-
put :update, id: collection.id, collection: { title: ['New Title'] }
|
117
|
-
expect(response).to render_template 'edit'
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'when there are existing members in the collection' do
|
122
|
-
it 'supports adding batches of members' do
|
123
|
-
collection.members << @asset1
|
124
|
-
collection.save!
|
125
|
-
put :update, id: collection, collection: { members: 'add' }, batch_document_ids: [@asset2, @asset3]
|
126
|
-
expect(response).to redirect_to collection_path(collection)
|
127
|
-
expect(assigns[:collection].members).to match_array [@asset2, @asset3, @asset1]
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'supports removing batches of members' do
|
131
|
-
collection.members = [@asset1, @asset2, @asset3]
|
132
|
-
collection.save!
|
133
|
-
put :update, id: collection, collection: { members: 'remove' }, batch_document_ids: [@asset1, @asset3]
|
134
|
-
expect(response).to redirect_to collection_path(collection)
|
135
|
-
expect(assigns[:collection].members).to eq([@asset2])
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'supports setting members array' do
|
140
|
-
put :update, id: collection, collection: { members: 'add' }, batch_document_ids: [@asset2, @asset3, @asset1]
|
141
|
-
expect(response).to redirect_to collection_path(collection)
|
142
|
-
expect(assigns[:collection].members).to match_array [@asset2, @asset3, @asset1]
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'set/un-sets collection on members' do
|
146
|
-
# Add to collection (sets collection on members)
|
147
|
-
put :update, id: collection, collection: { members: 'add' }, batch_document_ids: [@asset2, @asset3]
|
148
|
-
expect(assigns[:collection].members).to match_array [@asset2, @asset3]
|
149
|
-
|
150
|
-
# Remove from collection (un-sets collection on members)
|
151
|
-
put :update, id: collection, collection: { members: 'remove' }, batch_document_ids: [@asset2]
|
152
|
-
expect(assigns[:collection].members).not_to include(@asset2)
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'when moving members between collections' do
|
156
|
-
before do
|
157
|
-
collection.members = [@asset1, @asset2, @asset3]
|
158
|
-
collection.save!
|
159
|
-
end
|
160
|
-
let(:collection2) do
|
161
|
-
Collection.create(title: ['Some Collection']) do |col|
|
162
|
-
col.apply_depositor_metadata(user.user_key)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'moves the members' do
|
167
|
-
put :update, id: collection, collection: { members: 'move' },
|
168
|
-
destination_collection_id: collection2, batch_document_ids: [@asset2, @asset3]
|
169
|
-
expect(collection.reload.members).to eq [@asset1]
|
170
|
-
expect(collection2.reload.members).to match_array [@asset2, @asset3]
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe '#destroy' do
|
176
|
-
describe 'valid collection' do
|
177
|
-
let!(:collection) { FactoryGirl.create(:collection, user: user) }
|
178
|
-
before do
|
179
|
-
expect(controller).to receive(:authorize!).and_return(true)
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'deletes the collection' do
|
183
|
-
delete :destroy, id: collection
|
184
|
-
expect(response).to redirect_to Rails.application.routes.url_helpers.search_catalog_path
|
185
|
-
expect(flash[:notice]).to eq('Collection was successfully deleted.')
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'calls after_destroy' do
|
189
|
-
expect(controller).to receive(:after_destroy).and_call_original
|
190
|
-
delete :destroy, id: collection
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'updates members' do
|
194
|
-
asset1 = create(:generic_work, user: user)
|
195
|
-
collection.members << asset1
|
196
|
-
collection.save!
|
197
|
-
expect(asset1.in_collections).to eq [collection]
|
198
|
-
|
199
|
-
delete :destroy, id: collection
|
200
|
-
expect(asset1.in_collections).to eq []
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'does not delete an invalid collection' do
|
205
|
-
expect { delete :destroy, id: 'zz:-1' }.to raise_error
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe '#show' do
|
210
|
-
context 'when there are no assets in the collection' do
|
211
|
-
let(:collection) { FactoryGirl.create(:collection, user: user) }
|
212
|
-
it 'shows no assets' do
|
213
|
-
get :show, id: collection
|
214
|
-
expect(response).to be_successful
|
215
|
-
expect(assigns[:presenter].id).to eq collection.id
|
216
|
-
expect(assigns[:member_docs]).to be_empty
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
context 'with a number of assets' do
|
221
|
-
let(:asset1) { create(:generic_work, title: ['First of the Assets'], read_users: [user.user_key]) }
|
222
|
-
let(:asset2) { create(:generic_work, title: ['Second of the Assets'], read_users: [user.user_key]) }
|
223
|
-
let(:asset3) { create(:generic_work, title: ['Third of the Assets'], read_users: [user.user_key]) }
|
224
|
-
let!(:collection) do
|
225
|
-
FactoryGirl.create(:collection, members: [asset1, asset2, asset3], user: user)
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'queries the collections' do
|
229
|
-
get :show, id: collection, cq: 'First'
|
230
|
-
expect(assigns[:presenter].id).to eq collection.id
|
231
|
-
expect(assigns[:member_docs].map(&:id)).to match_array [asset1.id]
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'returns the specified number of rows' do
|
235
|
-
get :show, id: collection, rows: '2'
|
236
|
-
expect(assigns[:presenter].id).to eq collection.id
|
237
|
-
expect(assigns[:member_docs].size).to eq 2
|
238
|
-
end
|
239
|
-
|
240
|
-
describe 'additional collections' do
|
241
|
-
let(:asset4) { create(:generic_work, user: user, title: [asset1.id.to_s], read_users: [user.user_key]) }
|
242
|
-
let!(:collection2) do
|
243
|
-
FactoryGirl.create(:collection, members: [asset4], user: user)
|
244
|
-
end
|
245
|
-
it 'shows only the collections assets' do
|
246
|
-
get :show, id: collection
|
247
|
-
expect(assigns[:presenter].id).to eq collection.id
|
248
|
-
expect(assigns[:member_docs].map(&:id)).to match_array [asset1.id, asset2.id, asset3.id]
|
249
|
-
end
|
250
|
-
|
251
|
-
it 'shows only the other collections assets' do
|
252
|
-
get :show, id: collection2
|
253
|
-
expect(assigns[:presenter].id).to eq collection2.id
|
254
|
-
expect(assigns[:member_docs].map(&:id)).to match_array [asset4.id]
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
context 'When there are search matches that are not in the collection' do
|
259
|
-
let!(:bad_asset1) { create(:generic_work, user: user, title: ["#{asset1.id} #{asset1.title.first}"]) }
|
260
|
-
let!(:bad_asset2) { create(:generic_work, user: user, title: ["#{asset1.id} #{asset1.title.first}"]) }
|
261
|
-
|
262
|
-
# NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
|
263
|
-
it 'only shows the collection assets' do
|
264
|
-
get :show, id: collection, cq: "\"#{asset1.title.first}\""
|
265
|
-
expect(assigns[:presenter].id).to eq collection.id
|
266
|
-
expect(assigns[:member_docs].map(&:id)).not_to include bad_asset1.id, bad_asset2.id
|
267
|
-
expect(assigns[:member_docs].map(&:id)).to match_array [asset1.id]
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|