hydra-collections 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/Changelog.md +25 -1
- data/Gemfile +3 -2
- data/app/controllers/concerns/hydra/collections_controller_behavior.rb +38 -41
- data/app/models/concerns/hydra/collection.rb +11 -36
- data/hydra-collections.gemspec +1 -1
- data/lib/hydra/collections/version.rb +1 -1
- data/spec/controllers/accepts_batches_spec.rb +18 -20
- data/spec/controllers/catalog_controller_spec.rb +3 -3
- data/spec/controllers/collections_controller_spec.rb +107 -87
- data/spec/controllers/other_collections_controller_spec.rb +9 -9
- data/spec/controllers/selects_collections_spec.rb +17 -17
- data/spec/helpers/collections_helper_spec.rb +23 -23
- data/spec/helpers/collections_search_helper_spec.rb +3 -3
- data/spec/lib/collectible_spec.rb +3 -3
- data/spec/lib/search_service_spec.rb +6 -6
- data/spec/models/collection_spec.rb +31 -20
- data/spec/spec_helper.rb +0 -1
- metadata +20 -23
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0848c18173f62f89254d85e85b584440db5c9360
|
4
|
+
data.tar.gz: f1f144ffa8fbc44c61ab2ad810c89ce8e7b18f38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 025f951414c29038af78092e552353de53181095da0f5fe6c16831a4a12e7d6e8c6de5fb30f68cab3f75e44bae2ee95d830c13a6455821339dd800332de82031
|
7
|
+
data.tar.gz: 7825b8ed470364197333795a2edd070df64a4935734864721a4914cf82970df572db73142fb33e031f8594045656ccc8b84754a9fe86647fff941b8ee9145a1e
|
data/.travis.yml
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.1
|
4
|
-
|
5
|
-
- gemfiles/rails3.gemfile
|
6
|
-
- gemfiles/rails4.gemfile
|
4
|
+
- 2.0
|
7
5
|
env:
|
8
6
|
global:
|
9
7
|
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
|
10
8
|
notifications:
|
11
9
|
email:
|
12
10
|
recipients:
|
13
|
-
- "
|
14
|
-
- "cam156@psu.edu"
|
15
|
-
- "dmc186@psu.edu"
|
11
|
+
- "ul-dlt-hydra@lists.psu.edu"
|
16
12
|
on_success: "change"
|
17
13
|
on_failure: "always"
|
18
14
|
irc:
|
@@ -20,4 +16,4 @@ notifications:
|
|
20
16
|
- "irc.freenode.org#scholarsphere"
|
21
17
|
- "irc.freenode.org#projecthydra"
|
22
18
|
template:
|
23
|
-
- "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
|
19
|
+
- "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
|
data/Changelog.md
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
+
# 2.0.4
|
2
|
+
|
3
|
+
* Updating dependencies
|
4
|
+
* Refactoring collection membership methods
|
5
|
+
* More thorough testing of relationships in Solr
|
6
|
+
* Update to Rspec 3
|
7
|
+
|
8
|
+
# 2.0.3
|
9
|
+
|
10
|
+
* Pin to Rspec 2.99
|
11
|
+
* Made compatible with hydra-head 7.1
|
12
|
+
|
13
|
+
# 2.0.2
|
14
|
+
|
15
|
+
* Javascript is turbolinks-capable
|
16
|
+
|
17
|
+
# 2.0.1
|
18
|
+
|
19
|
+
* Fixes to searching and RDF datastreams
|
20
|
+
|
21
|
+
# 2.0.0
|
22
|
+
|
23
|
+
* Made compatible with hydra-head 7
|
24
|
+
|
1
25
|
# 1.3.2
|
2
26
|
|
3
|
-
Fixes delete button behavior
|
27
|
+
* Fixes delete button behavior
|
4
28
|
|
5
29
|
# 1.2.0.rc1
|
6
30
|
|
data/Gemfile
CHANGED
@@ -60,10 +60,7 @@ module Hydra
|
|
60
60
|
|
61
61
|
def create
|
62
62
|
@collection.apply_depositor_metadata(current_user.user_key)
|
63
|
-
unless batch.empty?
|
64
|
-
params[:collection][:members]="add"
|
65
|
-
process_member_changes
|
66
|
-
end
|
63
|
+
add_members_to_collection unless batch.empty?
|
67
64
|
if @collection.save
|
68
65
|
after_create
|
69
66
|
else
|
@@ -98,7 +95,6 @@ module Hydra
|
|
98
95
|
end
|
99
96
|
end
|
100
97
|
|
101
|
-
|
102
98
|
def after_destroy (id)
|
103
99
|
respond_to do |format|
|
104
100
|
format.html { redirect_to catalog_index_path, notice: 'Collection was successfully deleted.' }
|
@@ -114,12 +110,12 @@ module Hydra
|
|
114
110
|
end
|
115
111
|
|
116
112
|
def destroy
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
113
|
+
if @collection.destroy
|
114
|
+
after_destroy(params[:id])
|
115
|
+
else
|
116
|
+
after_destroy_error(params[:id])
|
117
|
+
end
|
118
|
+
end
|
123
119
|
|
124
120
|
protected
|
125
121
|
|
@@ -136,37 +132,38 @@ module Hydra
|
|
136
132
|
end
|
137
133
|
|
138
134
|
def process_member_changes
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
case params[:collection][:members]
|
136
|
+
when "add" then add_members_to_collection
|
137
|
+
when "remove" then remove_members_from_collection
|
138
|
+
when "move" then move_members_between_collections
|
139
|
+
when Array then assign_batch_to_collection
|
140
|
+
end
|
141
|
+
end
|
144
142
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
143
|
+
def add_members_to_collection collection = nil
|
144
|
+
collection ||= @collection
|
145
|
+
collection.members(true)
|
146
|
+
collection.member_ids = batch.concat(collection.member_ids)
|
147
|
+
end
|
148
|
+
|
149
|
+
def remove_members_from_collection
|
150
|
+
@collection.members(true)
|
151
|
+
@collection.member_ids = (@collection.member_ids - batch)
|
152
|
+
end
|
153
|
+
|
154
|
+
def assign_batch_to_collection
|
155
|
+
@collection.members(true)
|
156
|
+
@collection.member_ids = batch
|
157
|
+
end
|
158
|
+
|
159
|
+
def move_members_between_collections
|
160
|
+
destination_collection = ::Collection.find(params[:destination_collection_id])
|
161
|
+
remove_members_from_collection
|
162
|
+
add_members_to_collection(destination_collection)
|
163
|
+
if destination_collection.save
|
164
|
+
flash[:notice] = "Successfully moved #{batch.count} files to #{destination_collection.title} Collection."
|
165
|
+
else
|
166
|
+
flash[:error] = "An error occured. Files were not moved to #{destination_collection.title} Collection."
|
170
167
|
end
|
171
168
|
end
|
172
169
|
|
@@ -11,7 +11,7 @@ module Hydra
|
|
11
11
|
has_metadata "descMetadata", type: Hydra::CollectionRdfDatastream
|
12
12
|
has_metadata "properties", type: Hydra::Datastream::Properties
|
13
13
|
|
14
|
-
has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base" , :after_remove => :
|
14
|
+
has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base" , :after_remove => :update_member
|
15
15
|
|
16
16
|
has_attributes :depositor, datastream: :properties, multiple: false
|
17
17
|
|
@@ -25,10 +25,9 @@ module Hydra
|
|
25
25
|
before_create :set_date_uploaded
|
26
26
|
before_save :set_date_modified
|
27
27
|
|
28
|
-
after_save :
|
29
|
-
after_create :create_member_index
|
28
|
+
after_save :update_all_members
|
30
29
|
|
31
|
-
before_destroy :
|
30
|
+
before_destroy :update_all_members
|
32
31
|
end
|
33
32
|
|
34
33
|
def terms_for_editing
|
@@ -39,9 +38,13 @@ module Hydra
|
|
39
38
|
self.descMetadata.class.config.keys.map{|v| v.to_sym}
|
40
39
|
end
|
41
40
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
41
|
+
def update_all_members
|
42
|
+
self.members.collect { |m| update_member(m) }
|
43
|
+
end
|
44
|
+
|
45
|
+
# TODO: Use solr atomic updates to accelerate this process
|
46
|
+
def update_member member
|
47
|
+
member.update_index
|
45
48
|
end
|
46
49
|
|
47
50
|
private
|
@@ -54,34 +57,6 @@ module Hydra
|
|
54
57
|
self.date_modified = Date.today
|
55
58
|
end
|
56
59
|
|
57
|
-
|
58
|
-
def local_update_members
|
59
|
-
if self.respond_to?(:members)
|
60
|
-
self.members.each do |member|
|
61
|
-
member.reload.update_index
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def create_member_index
|
67
|
-
self.members.each do |member|
|
68
|
-
member.to_solr # not sure why this to_solr is needed but it caused the removal and update to work
|
69
|
-
if member.respond_to?(:collections)
|
70
|
-
member.collections << self
|
71
|
-
member.update_index
|
72
|
-
member.collections << self if self.members.size == 1 #again who konw why but this allows on asset to be added
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def remove_all_members
|
78
|
-
self.members.each do |member|
|
79
|
-
member.to_solr # not sure why this to_solr is needed but it caused the removal and update to work
|
80
|
-
member.collections.delete(self) if member.respond_to?(:collections)
|
81
|
-
member.update_index
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
60
|
+
end
|
86
61
|
|
87
62
|
end
|
data/hydra-collections.gemspec
CHANGED
@@ -4,23 +4,24 @@ class AcceptsBatchesController < ApplicationController
|
|
4
4
|
include Hydra::Collections::AcceptsBatches
|
5
5
|
end
|
6
6
|
|
7
|
-
describe AcceptsBatchesController do
|
7
|
+
describe AcceptsBatchesController, :type => :controller do
|
8
8
|
|
9
9
|
describe "batch" do
|
10
10
|
it "should accept batch from parameters" do
|
11
11
|
controller.params["batch_document_ids"] = ["abc", "xyz"]
|
12
|
-
controller.batch.
|
12
|
+
expect(controller.batch).to eq(["abc", "xyz"])
|
13
13
|
end
|
14
14
|
describe ":all" do
|
15
|
+
let(:current_user) { double(user_key: 'vanessa') }
|
15
16
|
before do
|
16
17
|
doc1 = double(:id=>123)
|
17
18
|
doc2 = double(:id=>456)
|
18
|
-
Hydra::Collections::SearchService.
|
19
|
-
controller.
|
19
|
+
expect_any_instance_of(Hydra::Collections::SearchService).to receive(:last_search_documents).and_return([doc1, doc2])
|
20
|
+
allow(controller).to receive(:current_user).and_return(current_user)
|
20
21
|
end
|
21
22
|
it "should add every document in the current resultset to the batch" do
|
22
23
|
controller.params["batch_document_ids"] = "all"
|
23
|
-
controller.batch.
|
24
|
+
expect(controller.batch).to eq([123, 456])
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -32,39 +33,36 @@ describe AcceptsBatchesController do
|
|
32
33
|
subject.batch = @allowed + @disallowed
|
33
34
|
end
|
34
35
|
it "using filter_docs_with_access!" do
|
35
|
-
@allowed.each {|doc_id| subject.
|
36
|
-
@disallowed.each {|doc_id| subject.
|
36
|
+
@allowed.each {|doc_id| expect(subject).to receive(:can?).with(:foo, doc_id).and_return(true)}
|
37
|
+
@disallowed.each {|doc_id| expect(subject).to receive(:can?).with(:foo, doc_id).and_return(false)}
|
37
38
|
subject.send(:filter_docs_with_access!, :foo)
|
38
|
-
|
39
|
-
flash[:notice].should == "You do not have permission to edit the documents: #{@disallowed.join(', ')}"
|
39
|
+
expect(flash[:notice]).to eq("You do not have permission to edit the documents: #{@disallowed.join(', ')}")
|
40
40
|
end
|
41
41
|
it "using filter_docs_with_edit_access!" do
|
42
|
-
@allowed.each {|doc_id| subject.
|
43
|
-
@disallowed.each {|doc_id| subject.
|
42
|
+
@allowed.each {|doc_id| expect(subject).to receive(:can?).with(:edit, doc_id).and_return(true)}
|
43
|
+
@disallowed.each {|doc_id| expect(subject).to receive(:can?).with(:edit, doc_id).and_return(false)}
|
44
44
|
subject.send(:filter_docs_with_edit_access!)
|
45
|
-
|
46
|
-
flash[:notice].should == "You do not have permission to edit the documents: #{@disallowed.join(', ')}"
|
45
|
+
expect(flash[:notice]).to eq("You do not have permission to edit the documents: #{@disallowed.join(', ')}")
|
47
46
|
end
|
48
47
|
it "using filter_docs_with_read_access!" do
|
49
|
-
@allowed.each {|doc_id| subject.
|
50
|
-
@disallowed.each {|doc_id| subject.
|
48
|
+
@allowed.each {|doc_id| expect(subject).to receive(:can?).with(:read, doc_id).and_return(true)}
|
49
|
+
@disallowed.each {|doc_id| expect(subject).to receive(:can?).with(:read, doc_id).and_return(false)}
|
51
50
|
subject.send(:filter_docs_with_read_access!)
|
52
|
-
|
53
|
-
flash[:notice].should == "You do not have permission to edit the documents: #{@disallowed.join(', ')}"
|
51
|
+
expect(flash[:notice]).to eq("You do not have permission to edit the documents: #{@disallowed.join(', ')}")
|
54
52
|
end
|
55
53
|
it "and be sassy if you didn't select anything" do
|
56
54
|
subject.batch = []
|
57
55
|
subject.send(:filter_docs_with_read_access!)
|
58
|
-
flash[:notice].
|
56
|
+
expect(flash[:notice]).to eq("Select something first")
|
59
57
|
end
|
60
58
|
|
61
59
|
end
|
62
60
|
|
63
61
|
it "should check for empty" do
|
64
62
|
controller.batch = ["77826928", "94120425"]
|
65
|
-
controller.check_for_empty_batch
|
63
|
+
expect(controller.check_for_empty_batch?).to eq(false)
|
66
64
|
controller.batch = []
|
67
|
-
controller.check_for_empty_batch
|
65
|
+
expect(controller.check_for_empty_batch?).to eq(true)
|
68
66
|
end
|
69
67
|
|
70
68
|
|
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
|
17
17
|
include Rails.application.routes.url_helpers
|
18
18
|
|
19
|
-
describe CatalogController do
|
19
|
+
describe CatalogController, :type => :controller do
|
20
20
|
before do
|
21
|
-
controller.
|
21
|
+
allow(controller).to receive(:has_access?).and_return(true)
|
22
22
|
@user = FactoryGirl.find_or_create(:user)
|
23
23
|
@collection = Collection.new title:"Test"
|
24
24
|
@collection.apply_depositor_metadata(@user.user_key)
|
@@ -37,7 +37,7 @@ describe CatalogController do
|
|
37
37
|
@routes = Rails.application.routes
|
38
38
|
get :index
|
39
39
|
expect(assigns(:user_collections)).to be_kind_of(Array)
|
40
|
-
assigns(:user_collections).index{|d| d.id == @collection.id}.
|
40
|
+
expect(assigns(:user_collections).index{|d| d.id == @collection.id}).not_to be_nil
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe CollectionsController do
|
3
|
+
describe CollectionsController, :type => :controller do
|
4
4
|
before(:all) do
|
5
5
|
@user = FactoryGirl.find_or_create(:user)
|
6
6
|
# CollectionsController.config.default_solr_params = {:qf => 'title_tesim'}
|
@@ -25,12 +25,12 @@ describe CollectionsController do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
before do
|
28
|
-
controller.
|
28
|
+
allow(controller).to receive(:has_access?).and_return(true)
|
29
29
|
|
30
30
|
@user = FactoryGirl.find_or_create(:user)
|
31
31
|
sign_in @user
|
32
|
-
User.
|
33
|
-
controller.
|
32
|
+
allow_any_instance_of(User).to receive(:groups).and_return([])
|
33
|
+
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '#new' do
|
@@ -39,9 +39,9 @@ describe CollectionsController do
|
|
39
39
|
expect(assigns(:collection)).to be_kind_of(Collection)
|
40
40
|
end
|
41
41
|
it "should pass through batch ids if provided and stick them in the form" do
|
42
|
-
|
42
|
+
skip "Couldn't get have_selector working before I had to move on. - MZ"
|
43
43
|
get :new, batch_document_ids: ["test2", "test88"]
|
44
|
-
response.
|
44
|
+
expect(response).to have_selector("p[class='foo']")
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -49,45 +49,45 @@ describe CollectionsController do
|
|
49
49
|
it "should create a Collection" do
|
50
50
|
old_count = Collection.count
|
51
51
|
post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
|
52
|
-
Collection.count.
|
53
|
-
assigns[:collection].title.
|
54
|
-
assigns[:collection].description.
|
55
|
-
assigns[:collection].depositor.
|
56
|
-
response.
|
52
|
+
expect(Collection.count).to eq(old_count+1)
|
53
|
+
expect(assigns[:collection].title).to eq("My First Collection ")
|
54
|
+
expect(assigns[:collection].description).to eq("The Description\r\n\r\nand more")
|
55
|
+
expect(assigns[:collection].depositor).to eq(@user.user_key)
|
56
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(assigns[:collection].id)
|
57
57
|
end
|
58
58
|
it "should add docs to collection if batch ids provided" do
|
59
59
|
@asset1 = ActiveFedora::Base.create!
|
60
60
|
@asset2 = ActiveFedora::Base.create!
|
61
61
|
post :create, batch_document_ids: [@asset1, @asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
|
62
|
-
assigns[:collection].members.
|
62
|
+
expect(assigns[:collection].members).to eq([@asset1, @asset2])
|
63
63
|
end
|
64
64
|
it "should call after_create" do
|
65
|
-
controller.
|
65
|
+
expect(controller).to receive(:after_create).and_call_original
|
66
66
|
post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should add one doc to collection if batch ids provided and add the collection id to the document in the colledction" do
|
70
70
|
@asset1 = GenericFile.create!
|
71
71
|
post :create, batch_document_ids: [@asset1], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
|
72
|
-
assigns[:collection].members.
|
72
|
+
expect(assigns[:collection].members).to eq([@asset1])
|
73
73
|
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
74
|
-
asset_results["response"]["numFound"].
|
74
|
+
expect(asset_results["response"]["numFound"]).to eq(1)
|
75
75
|
doc = asset_results["response"]["docs"].first
|
76
|
-
doc["id"].
|
76
|
+
expect(doc["id"]).to eq(@asset1.pid)
|
77
77
|
afterupdate = GenericFile.find(@asset1.pid)
|
78
|
-
doc[Solrizer.solr_name(:collection)].
|
78
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
|
79
79
|
end
|
80
80
|
it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
|
81
81
|
@asset1 = GenericFile.create!
|
82
82
|
@asset2 = GenericFile.create!
|
83
83
|
post :create, batch_document_ids: [@asset1,@asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
|
84
|
-
assigns[:collection].members.
|
84
|
+
expect(assigns[:collection].members).to eq([@asset1,@asset2])
|
85
85
|
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
86
|
-
asset_results["response"]["numFound"].
|
86
|
+
expect(asset_results["response"]["numFound"]).to eq(1)
|
87
87
|
doc = asset_results["response"]["docs"].first
|
88
|
-
doc["id"].
|
88
|
+
expect(doc["id"]).to eq(@asset1.pid)
|
89
89
|
afterupdate = GenericFile.find(@asset1.pid)
|
90
|
-
doc[Solrizer.solr_name(:collection)].
|
90
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -99,68 +99,76 @@ describe CollectionsController do
|
|
99
99
|
@asset1 = GenericFile.create!
|
100
100
|
@asset2 = GenericFile.create!
|
101
101
|
@asset3 = GenericFile.create!
|
102
|
-
controller.
|
103
|
-
controller.
|
102
|
+
allow(controller).to receive(:authorize!).and_return(true)
|
103
|
+
expect(controller).to receive(:authorize!).at_least(:once)
|
104
104
|
end
|
105
105
|
it "should update collection metadata" do
|
106
106
|
put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
|
107
|
-
response.
|
108
|
-
assigns[:collection].title.
|
109
|
-
assigns[:collection].description.
|
107
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
108
|
+
expect(assigns[:collection].title).to eq("New Title")
|
109
|
+
expect(assigns[:collection].description).to eq("New Description")
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should call after_update" do
|
113
|
-
controller.
|
113
|
+
expect(controller).to receive(:after_update).and_call_original
|
114
114
|
put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
|
115
115
|
end
|
116
116
|
it "should support adding batches of members" do
|
117
117
|
@collection.members << @asset1
|
118
118
|
@collection.save
|
119
119
|
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
|
120
|
-
response.
|
121
|
-
assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.
|
120
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
121
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid })
|
122
122
|
end
|
123
123
|
it "should support removing batches of members" do
|
124
124
|
@collection.members = [@asset1, @asset2, @asset3]
|
125
125
|
@collection.save
|
126
126
|
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset1, @asset3]
|
127
|
-
response.
|
128
|
-
assigns[:collection].members.
|
127
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
128
|
+
expect(assigns[:collection].members).to eq([@asset2])
|
129
129
|
end
|
130
130
|
it "should support setting members array" do
|
131
131
|
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
|
132
|
-
response.
|
133
|
-
assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.
|
132
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
133
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid })
|
134
134
|
end
|
135
135
|
it "should support setting members array" do
|
136
136
|
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
|
137
|
-
response.
|
138
|
-
assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.
|
137
|
+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
|
138
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid })
|
139
139
|
end
|
140
140
|
it "should set/un-set collection on members" do
|
141
141
|
# Add to collection (sets collection on members)
|
142
|
+
solr_doc_before_add = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
143
|
+
expect(solr_doc_before_add[Solrizer.solr_name(:collection)]).to be_nil
|
142
144
|
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
|
143
|
-
assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.
|
145
|
+
expect(assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }).to eq([@asset2, @asset3].sort! { |a,b| a.pid <=> b.pid })
|
144
146
|
## Check that member lists collection in its solr doc
|
145
147
|
@asset2.reload
|
146
|
-
@asset2.to_solr[Solrizer.solr_name(:collection)].
|
148
|
+
expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
147
149
|
## Check that member was re-indexed with collection info
|
148
150
|
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
149
151
|
doc = asset_results["response"]["docs"].first
|
150
|
-
doc["id"].
|
151
|
-
doc[Solrizer.solr_name(:collection)].
|
152
|
-
|
152
|
+
expect(doc["id"]).to eq(@asset2.pid)
|
153
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
154
|
+
solr_doc_after_add = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
155
|
+
expect(solr_doc_after_add[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
156
|
+
|
153
157
|
# Remove from collection (un-sets collection on members)
|
158
|
+
solr_doc_before_remove = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
159
|
+
expect(solr_doc_before_remove[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
154
160
|
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset2]
|
155
|
-
assigns[:collection].members.
|
161
|
+
expect(assigns[:collection].members).not_to include(@asset2)
|
156
162
|
## Check that member no longer lists collection in its solr doc
|
157
163
|
@asset2.reload
|
158
|
-
@asset2.to_solr[Solrizer.solr_name(:collection)].
|
164
|
+
expect(@asset2.to_solr[Solrizer.solr_name(:collection)]).to eq([])
|
159
165
|
## Check that member was re-indexed without collection info
|
160
166
|
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
161
167
|
doc = asset_results["response"]["docs"].first
|
162
|
-
doc["id"].
|
163
|
-
doc[Solrizer.solr_name(:collection)].
|
168
|
+
expect(doc["id"]).to eq(@asset2.pid)
|
169
|
+
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
|
170
|
+
solr_doc_after_remove = ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, @asset2.pid).send(:solr_doc)
|
171
|
+
expect(solr_doc_after_remove[Solrizer.solr_name(:collection)]).to be_nil
|
164
172
|
end
|
165
173
|
|
166
174
|
it "should allow moving members between collections" do
|
@@ -170,8 +178,8 @@ describe CollectionsController do
|
|
170
178
|
@collection2.apply_depositor_metadata(@user.user_key)
|
171
179
|
@collection2.save
|
172
180
|
put :update, id: @collection.id, collection: {members:"move"}, destination_collection_id:@collection2.pid, batch_document_ids:[@asset2, @asset3]
|
173
|
-
::Collection.find(@collection.pid).members.
|
174
|
-
::Collection.find(@collection2.pid).members.
|
181
|
+
expect(::Collection.find(@collection.pid).members).to eq([@asset1])
|
182
|
+
expect(::Collection.find(@collection2.pid).members).to eq([@asset2, @asset3])
|
175
183
|
end
|
176
184
|
|
177
185
|
end
|
@@ -182,15 +190,15 @@ describe CollectionsController do
|
|
182
190
|
@collection = Collection.new
|
183
191
|
@collection.apply_depositor_metadata(@user.user_key)
|
184
192
|
@collection.save
|
185
|
-
controller.
|
193
|
+
expect(controller).to receive(:authorize!).and_return(true)
|
186
194
|
end
|
187
195
|
it "should delete collection" do
|
188
196
|
delete :destroy, id: @collection.id
|
189
|
-
response.
|
190
|
-
flash[:notice].
|
197
|
+
expect(response).to redirect_to Rails.application.routes.url_helpers.catalog_index_path
|
198
|
+
expect(flash[:notice]).to eq("Collection was successfully deleted.")
|
191
199
|
end
|
192
200
|
it "should after_destroy" do
|
193
|
-
controller.
|
201
|
+
expect(controller).to receive(:after_destroy).and_call_original
|
194
202
|
delete :destroy, id: @collection.id
|
195
203
|
end
|
196
204
|
it "should call update members" do
|
@@ -199,18 +207,18 @@ describe CollectionsController do
|
|
199
207
|
@collection.save
|
200
208
|
@asset1 = @asset1.reload
|
201
209
|
@asset1.update_index
|
202
|
-
@asset1.collections.
|
210
|
+
expect(@asset1.collections).to eq([@collection])
|
203
211
|
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
204
|
-
asset_results["response"]["numFound"].
|
212
|
+
expect(asset_results["response"]["numFound"]).to eq(1)
|
205
213
|
doc = asset_results["response"]["docs"].first
|
206
|
-
doc[Solrizer.solr_name(:collection)].
|
214
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq([@collection.pid])
|
207
215
|
|
208
216
|
delete :destroy, id: @collection.id
|
209
|
-
@asset1.reload.collections.
|
217
|
+
expect(@asset1.reload.collections).to eq([])
|
210
218
|
asset_results = blacklight_solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
211
|
-
asset_results["response"]["numFound"].
|
219
|
+
expect(asset_results["response"]["numFound"]).to eq(1)
|
212
220
|
doc = asset_results["response"]["docs"].first
|
213
|
-
doc[Solrizer.solr_name(:collection)].
|
221
|
+
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
|
214
222
|
@asset1.destroy
|
215
223
|
end
|
216
224
|
end
|
@@ -229,16 +237,28 @@ describe CollectionsController do
|
|
229
237
|
@collection.apply_depositor_metadata(@user.user_key)
|
230
238
|
@collection.members = [@asset1,@asset2,@asset3]
|
231
239
|
@collection.save
|
232
|
-
controller.
|
233
|
-
controller.
|
240
|
+
allow(controller).to receive(:authorize!).and_return(true)
|
241
|
+
allow(controller).to receive(:apply_gated_search)
|
234
242
|
end
|
235
243
|
it "should show the collections" do
|
236
244
|
get :show, id: @collection.id
|
237
|
-
assigns[:collection].title.
|
245
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
238
246
|
ids = assigns[:member_docs].map {|d| d.id}
|
239
|
-
ids.
|
240
|
-
ids.
|
241
|
-
ids.
|
247
|
+
expect(ids).to include @asset1.pid
|
248
|
+
expect(ids).to include @asset2.pid
|
249
|
+
expect(ids).to include @asset3.pid
|
250
|
+
end
|
251
|
+
context "when items have been added and removed" do
|
252
|
+
it "should return the items that are in the collection and not return items that have been removed" do
|
253
|
+
asset4 = GenericFile.create!(title: "Fourth of the Assets")
|
254
|
+
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset2.pid]
|
255
|
+
controller.batch = nil
|
256
|
+
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[asset4.pid]
|
257
|
+
get :show, id: @collection.id
|
258
|
+
ids = assigns[:member_docs].map(&:id)
|
259
|
+
expect(ids).to include @asset1.pid, @asset3.pid, asset4.pid
|
260
|
+
expect(ids).to_not include @asset2.pid
|
261
|
+
end
|
242
262
|
end
|
243
263
|
describe "additional collections" do
|
244
264
|
before do
|
@@ -249,46 +269,46 @@ describe CollectionsController do
|
|
249
269
|
@collection2.members = [@asset4]
|
250
270
|
@collection2.save
|
251
271
|
@asset4 = @asset4.reload
|
252
|
-
@asset4.collections.
|
272
|
+
expect(@asset4.collections).to eq([@collection2])
|
253
273
|
end
|
254
274
|
|
255
275
|
it "should show only the collections assets" do
|
256
276
|
get :show, id: @collection.pid
|
257
|
-
assigns[:collection].title.
|
277
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
258
278
|
ids = assigns[:member_docs].map {|d| d.id}
|
259
|
-
ids.
|
260
|
-
ids.
|
261
|
-
ids.
|
262
|
-
ids.
|
279
|
+
expect(ids).to include @asset1.pid
|
280
|
+
expect(ids).to include @asset2.pid
|
281
|
+
expect(ids).to include @asset3.pid
|
282
|
+
expect(ids).not_to include @asset4.pid
|
263
283
|
|
264
284
|
end
|
265
285
|
it "should show only the other collections assets" do
|
266
286
|
|
267
287
|
get :show, id: @collection2.pid
|
268
|
-
assigns[:collection].title.
|
288
|
+
expect(assigns[:collection].title).to eq(@collection2.title)
|
269
289
|
ids = assigns[:member_docs].map {|d| d.id}
|
270
|
-
ids.
|
271
|
-
ids.
|
272
|
-
ids.
|
273
|
-
ids.
|
290
|
+
expect(ids).not_to include @asset1.pid
|
291
|
+
expect(ids).not_to include @asset2.pid
|
292
|
+
expect(ids).not_to include @asset3.pid
|
293
|
+
expect(ids).to include @asset4.pid
|
274
294
|
|
275
295
|
end
|
276
296
|
end
|
277
297
|
|
278
298
|
it "when the collection is empty it should show no assets" do
|
279
299
|
get :show, id: Collection.create(title: "Empty collection").id
|
280
|
-
assigns[:collection].title.
|
281
|
-
assigns[:member_docs].
|
300
|
+
expect(assigns[:collection].title).to eq("Empty collection")
|
301
|
+
expect(assigns[:member_docs]).to be_empty
|
282
302
|
end
|
283
303
|
|
284
304
|
# NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
|
285
305
|
it "should query the collections" do
|
286
306
|
get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
|
287
|
-
assigns[:collection].title.
|
307
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
288
308
|
ids = assigns[:member_docs].map {|d| d.id}
|
289
|
-
ids.
|
290
|
-
ids.
|
291
|
-
ids.
|
309
|
+
expect(ids).to include @asset1.pid
|
310
|
+
expect(ids).not_to include @asset2.pid
|
311
|
+
expect(ids).not_to include @asset3.pid
|
292
312
|
end
|
293
313
|
|
294
314
|
# NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
|
@@ -296,20 +316,20 @@ describe CollectionsController do
|
|
296
316
|
@asset4 = GenericFile.create!(title: "#{@asset1.id} #{@asset1.title}")
|
297
317
|
@asset5 = GenericFile.create!(title: "#{@asset1.title}")
|
298
318
|
get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
|
299
|
-
assigns[:collection].title.
|
319
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
300
320
|
ids = assigns[:member_docs].map {|d| d.id}
|
301
|
-
ids.
|
302
|
-
ids.
|
303
|
-
ids.
|
304
|
-
ids.
|
305
|
-
ids.
|
321
|
+
expect(ids).to include @asset1.pid
|
322
|
+
expect(ids).not_to include @asset2.pid
|
323
|
+
expect(ids).not_to include @asset3.pid
|
324
|
+
expect(ids).not_to include @asset4.pid
|
325
|
+
expect(ids).not_to include @asset5.pid
|
306
326
|
end
|
307
327
|
|
308
328
|
it "should query the collections with rows" do
|
309
329
|
get :show, id: @collection.id, rows:"2"
|
310
|
-
assigns[:collection].title.
|
330
|
+
expect(assigns[:collection].title).to eq(@collection.title)
|
311
331
|
ids = assigns[:member_docs].map {|d| d.id}
|
312
|
-
ids.count.
|
332
|
+
expect(ids.count).to eq(2)
|
313
333
|
end
|
314
334
|
|
315
335
|
end
|