hydra-collections 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -1
  3. data/CONTRIBUTING.md +113 -0
  4. data/Changelog.md +105 -0
  5. data/LICENSE.txt +12 -19
  6. data/README.md +67 -22
  7. data/{lib → app/controllers/concerns}/hydra/collections_controller_behavior.rb +29 -38
  8. data/app/helpers/collections_helper.rb +10 -0
  9. data/app/helpers/collections_search_helper.rb +6 -30
  10. data/{lib → app/models/concerns}/hydra/collection.rb +0 -8
  11. data/app/views/collections/_button_for_delete_collection.html.erb +1 -1
  12. data/app/views/collections/_button_remove_from_collection.html.erb +1 -1
  13. data/app/views/collections/_form.html.erb +2 -6
  14. data/app/views/collections/_form_for_select_destination_collection.html.erb +21 -0
  15. data/app/views/collections/_single_item_action_fields.html.erb +1 -1
  16. data/gemfiles/rails3.gemfile +6 -0
  17. data/gemfiles/rails4.gemfile +6 -0
  18. data/hydra-collections.gemspec +1 -0
  19. data/lib/hydra/collections/collectible.rb +1 -1
  20. data/lib/hydra/collections/selects_collections.rb +17 -5
  21. data/lib/hydra/collections/version.rb +1 -1
  22. data/lib/hydra/datastreams/collection_rdf_datastream.rb +0 -7
  23. data/lib/hydra-collections.rb +20 -7
  24. data/spec/controllers/accepts_batches_spec.rb +4 -4
  25. data/spec/controllers/collections_controller_spec.rb +46 -27
  26. data/spec/controllers/other_collections_controller_spec.rb +74 -0
  27. data/spec/controllers/selects_collections_spec.rb +11 -0
  28. data/spec/helpers/collections_helper_spec.rb +98 -40
  29. data/spec/helpers/collections_search_helper_spec.rb +5 -34
  30. data/spec/models/collection_spec.rb +30 -2
  31. data/spec/spec_helper.rb +7 -0
  32. data/tasks/hydra-collections-dev.rake +12 -6
  33. metadata +31 -7
  34. data/lib/hydra/collections.rb +0 -14
  35. data/spec/support/Gemfile +0 -19
@@ -1,6 +1,6 @@
1
1
  <%#= button_to label, , :class=>"btn btn-primary collection-remove", 'data-behavior'=>'hydra-collections-remove', members:"delete", batch_document_ids:[document.id] %>
2
2
 
3
- <%= form_for @collection, url:collections.collection_path(@collection.id), :method=>:put do |f| %>
3
+ <%= form_for @collection, url:collections.collection_path(@collection.id), :method=>:put, as:'collection' do |f| %>
4
4
  <%= single_item_action_remove_form_fields(f,document) %>
5
5
  <%= f.submit label, :class => "btn btn-primary collection-remove" %>
6
6
  <% end %>
@@ -23,14 +23,10 @@
23
23
  <%= f.text_area :description %>
24
24
  </div>
25
25
 
26
- <%- unless params[:batch_document_ids].nil? || params[:batch_document_ids].empty? %>
27
- <%- params[:batch_document_ids].each do |batch_item| %>
28
- <input type="hidden" name="batch_document_ids[]" value="<%= batch_item %>"/>
29
- <%- end %>
30
- <%- end %>
26
+ <%= hidden_collection_members %>
31
27
 
32
28
  <div class="actions">
33
29
  <%= f.submit %>
34
30
  </div>
35
31
  <% end %>
36
- </div>
32
+ </div>
@@ -0,0 +1,21 @@
1
+ <% if user_collections.nil?%>
2
+ <b> Make sure you have included Hydra::Collections::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(collections.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.collections_path, :method=>:put, :class=>"btn btn-primary collection-update submits-batches", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-move' %>
20
+ <% end %>
21
+ <% end %>
@@ -3,4 +3,4 @@
3
3
  <%# action - collection action: add or remove %>
4
4
  <%# document - current document %>
5
5
  <%= form.hidden_field :members, :value => action %>
6
- <%= hidden_field :batch_document_ids, '',{value:document.id, multiple:true} %>
6
+ <%= hidden_field :batch_document_ids, '', {value:document.id} %>
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Please see hydra-batch-edit.gemspec for dependency information.
4
+ gemspec :path=>"../"
5
+
6
+ gem 'rails', "~> 3.2"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Please see hydra-batch-edit.gemspec for dependency information.
4
+ gemspec :path=>"../"
5
+
6
+ gem 'rails', '~> 4.0.0'
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec-rails"
27
+ spec.add_development_dependency "sass-rails", "< 5", ">= 3.2"
27
28
  end
@@ -6,7 +6,7 @@ module Hydra::Collections::Collectible
6
6
 
7
7
  included do
8
8
  #after_solrize << :index_collection_pids
9
- has_many :collections, property: :has_collection_member
9
+ has_many :collections, property: :has_collection_member, :class_name => "ActiveFedora::Base"
10
10
  end
11
11
 
12
12
  # Add this method to your solrization logic (ie. in to_solr) in order to populate the 'collection' facet
@@ -17,7 +17,8 @@ module Hydra::Collections::SelectsCollections
17
17
  def find_collections_with_edit_access
18
18
  find_collections(:edit)
19
19
  end
20
-
20
+
21
+ #
21
22
  def find_collections (access_level='')
22
23
  # need to know the user if there is an access level applied otherwise we are just doing public collections
23
24
  authenticate_user! unless access_level.blank?
@@ -26,13 +27,17 @@ module Hydra::Collections::SelectsCollections
26
27
  original_permissions = discovery_permissions
27
28
  self.class.send(:define_method, "discovery_permissions") { access_levels[access_level] } unless access_level.blank?
28
29
 
29
- # add the collection filter to the solr logic for this query
30
- orig_solr_search_params_logic = self.class.solr_search_params_logic
31
- self.class.solr_search_params_logic += [:add_collection_filter]
30
+ # Blacklight doesn't let you explicitly pass your own solr_search_params_logic when running searches --
31
+ # You have to set the controller's solr_search_params_logic class attribute. So this method temporarily sets solr_search_params_logic to collection_search_params_logic then switches it back.
32
32
 
33
+ # temporarily set solr_search_params_logic to collection_search_params_logic
34
+ orig_solr_search_params_logic = self.class.solr_search_params_logic
35
+ # self.class.solr_search_params_logic += [:add_collection_filter]
36
+ self.class.solr_search_params_logic = collection_search_params_logic
37
+ logger.debug "Collection Search logic: "+ self.class.solr_search_params_logic.inspect
33
38
  # run the solr query to find the collections
34
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?
38
43
  self.class.solr_search_params_logic = orig_solr_search_params_logic
@@ -46,4 +51,11 @@ module Hydra::Collections::SelectsCollections
46
51
  solr_parameters[:fq] << "#{Solrizer.solr_name("has_model", :symbol)}:\"info:fedora/afmodel:Collection\""
47
52
  end
48
53
 
54
+ # Defines which solr_search_params_logic should be used when searching for Collections
55
+ def collection_search_params_logic
56
+ base_logic = [:default_solr_parameters, :add_query_to_solr, :add_access_controls_to_solr_params]
57
+ base_logic += [:add_collection_filter]
58
+ base_logic
59
+ end
60
+
49
61
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module Collections
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -67,12 +67,5 @@ module Hydra
67
67
  end
68
68
  map.related_url(:to => "seeAlso", :in => RDF::RDFS)
69
69
  end
70
- begin
71
- LocalAuthority.register_vocabulary(self, "subject", "lc_subjects")
72
- LocalAuthority.register_vocabulary(self, "language", "lexvo_languages")
73
- LocalAuthority.register_vocabulary(self, "tag", "lc_genres")
74
- rescue
75
- puts "tables for vocabularies missing"
76
- end
77
70
  end
78
71
  end
@@ -1,8 +1,21 @@
1
- require "hydra/collections"
2
- require "hydra/collections_controller_behavior"
3
- require "hydra/collection"
4
- require "bundler/setup"
5
- require "blacklight"
6
1
  require "hydra/head"
7
- require "active_fedora"
8
- require "hydra/collections/selects_collections"
2
+
3
+ module Hydra
4
+ module Collections
5
+ extend ActiveSupport::Autoload
6
+ autoload :Version
7
+ autoload :Collectible
8
+ autoload :SearchService
9
+ autoload :AcceptsBatches
10
+ autoload :SelectsCollections
11
+ autoload :SolrDocumentBehavior
12
+ class Engine < ::Rails::Engine
13
+ engine_name "collections"
14
+ config.autoload_paths += %W(
15
+ #{config.root}/app/controllers/concerns
16
+ #{config.root}/app/models/concerns
17
+ )
18
+ end
19
+ end
20
+ end
21
+
@@ -13,10 +13,10 @@ describe AcceptsBatchesController do
13
13
  end
14
14
  describe ":all" do
15
15
  before do
16
- doc1 = stub(:id=>123)
17
- doc2 = stub(:id=>456)
16
+ doc1 = double(:id=>123)
17
+ doc2 = double(:id=>456)
18
18
  Hydra::Collections::SearchService.any_instance.should_receive(:last_search_documents).and_return([doc1, doc2])
19
- controller.stub(:current_user=>stub(:user_key=>'vanessa'))
19
+ controller.stub(current_user: double(user_key: 'vanessa'))
20
20
  end
21
21
  it "should add every document in the current resultset to the batch" do
22
22
  controller.params["batch_document_ids"] = "all"
@@ -69,4 +69,4 @@ describe AcceptsBatchesController do
69
69
 
70
70
 
71
71
 
72
- end
72
+ end
@@ -1,22 +1,9 @@
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
  describe CollectionsController do
18
4
  before(:all) do
19
5
  @user = FactoryGirl.find_or_create(:user)
6
+ # CollectionsController.config.default_solr_params = {:qf => 'title_tesim'}
20
7
  class GenericFile < ActiveFedora::Base
21
8
  include Hydra::Collections::Collectible
22
9
 
@@ -88,7 +75,6 @@ describe CollectionsController do
88
75
  doc = asset_results["response"]["docs"].first
89
76
  doc["id"].should == @asset1.pid
90
77
  afterupdate = GenericFile.find(@asset1.pid)
91
- puts doc
92
78
  doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
93
79
  end
94
80
  it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
@@ -101,7 +87,6 @@ describe CollectionsController do
101
87
  doc = asset_results["response"]["docs"].first
102
88
  doc["id"].should == @asset1.pid
103
89
  afterupdate = GenericFile.find(@asset1.pid)
104
- puts doc
105
90
  doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
106
91
  end
107
92
  end
@@ -152,26 +137,42 @@ describe CollectionsController do
152
137
  response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
153
138
  assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid }
154
139
  end
155
- it "should set collection on members" do
156
- @collection.members << @asset1
157
- @collection.save
140
+ it "should set/un-set collection on members" do
141
+ # Add to collection (sets collection on members)
158
142
  put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
159
- response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
160
- assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid }
143
+ assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3].sort! { |a,b| a.pid <=> b.pid }
144
+ ## Check that member lists collection in its solr doc
145
+ @asset2.reload
146
+ @asset2.to_solr[Solrizer.solr_name(:collection)].should == [@collection.pid]
147
+ ## Check that member was re-indexed with collection info
161
148
  asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
162
- asset_results["response"]["numFound"].should == 1
163
149
  doc = asset_results["response"]["docs"].first
164
150
  doc["id"].should == @asset2.pid
165
- afterupdate = GenericFile.find(@asset2.pid)
166
- doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
151
+ doc[Solrizer.solr_name(:collection)].should == [@collection.pid]
152
+
153
+ # Remove from collection (un-sets collection on members)
167
154
  put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset2]
155
+ assigns[:collection].members.should_not include(@asset2)
156
+ ## Check that member no longer lists collection in its solr doc
157
+ @asset2.reload
158
+ @asset2.to_solr[Solrizer.solr_name(:collection)].should == []
159
+ ## Check that member was re-indexed without collection info
168
160
  asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
169
- asset_results["response"]["numFound"].should == 1
170
161
  doc = asset_results["response"]["docs"].first
171
162
  doc["id"].should == @asset2.pid
172
- afterupdate = GenericFile.find(@asset2.pid)
173
163
  doc[Solrizer.solr_name(:collection)].should be_nil
174
164
  end
165
+
166
+ it "should allow moving members between collections" do
167
+ @collection.members = [@asset1, @asset2, @asset3]
168
+ @collection.save
169
+ @collection2 = Collection.new
170
+ @collection2.apply_depositor_metadata(@user.user_key)
171
+ @collection2.save
172
+ put :update, id: @collection.id, collection: {members:"move"}, destination_collection_id:@collection2.pid, batch_document_ids:[@asset2, @asset3]
173
+ ::Collection.find(@collection.pid).members.should == [@asset1]
174
+ ::Collection.find(@collection2.pid).members.should == [@asset2, @asset3]
175
+ end
175
176
 
176
177
  end
177
178
 
@@ -218,7 +219,7 @@ describe CollectionsController do
218
219
  end
219
220
  end
220
221
 
221
- describe "#show" do
222
+ describe "with a number of assets #show" do
222
223
  before do
223
224
  @asset1 = GenericFile.create!(title: "First of the Assets")
224
225
  @asset2 = GenericFile.create!(title: "Second of the Assets")
@@ -249,6 +250,14 @@ describe CollectionsController do
249
250
  ids.should include @asset3.pid
250
251
  ids.should_not include @asset4.pid
251
252
  end
253
+
254
+ it "when the collection is empty it should show no assets" do
255
+ get :show, id: Collection.create(title: "Empty collection").id
256
+ assigns[:collection].title.should == "Empty collection"
257
+ assigns[:member_docs].should be_empty
258
+ end
259
+
260
+ # NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
252
261
  it "should query the collections" do
253
262
  get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
254
263
  assigns[:collection].title.should == @collection.title
@@ -257,6 +266,8 @@ describe CollectionsController do
257
266
  ids.should_not include @asset2.pid
258
267
  ids.should_not include @asset3.pid
259
268
  end
269
+
270
+ # NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
260
271
  it "should query the collections and show only the collection assets" do
261
272
  @asset4 = GenericFile.create!(title: "#{@asset1.id} #{@asset1.title}")
262
273
  @asset5 = GenericFile.create!(title: "#{@asset1.title}")
@@ -269,6 +280,14 @@ describe CollectionsController do
269
280
  ids.should_not include @asset4.pid
270
281
  ids.should_not include @asset5.pid
271
282
  end
283
+
284
+ it "should query the collections with rows" do
285
+ get :show, id: @collection.id, rows:"2"
286
+ assigns[:collection].title.should == @collection.title
287
+ ids = assigns[:member_docs].map {|d| d.id}
288
+ ids.count.should == 2
289
+ end
290
+
272
291
  end
273
292
 
274
293
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ class OtherCollectionsController < ApplicationController
4
+ include Hydra::CollectionsControllerBehavior
5
+
6
+ def show
7
+ super
8
+ redirect_to root_path
9
+ end
10
+
11
+ end
12
+
13
+ class OtherCollection < ActiveFedora::Base
14
+ include Hydra::Collection
15
+ include Hydra::Collections::Collectible
16
+ end
17
+ class Member < ActiveFedora::Base
18
+ include Hydra::Collections::Collectible
19
+ attr_accessor :title
20
+
21
+ end
22
+
23
+ # make sure a collection by another name still assigns the @collection variable
24
+ describe OtherCollectionsController do
25
+ before(:all) do
26
+ @user = FactoryGirl.find_or_create(:user)
27
+ end
28
+ after(:all) do
29
+ @user.destroy
30
+ Member.destroy_all
31
+ OtherCollection.destroy_all
32
+ Object.send(:remove_const, :Member)
33
+ Object.send(:remove_const, :OtherCollection)
34
+ Object.send(:remove_const, :OtherCollectionsController)
35
+
36
+ end
37
+
38
+ before do
39
+ controller.stub(:has_access?).and_return(true)
40
+
41
+ @user = FactoryGirl.find_or_create(:user)
42
+ sign_in @user
43
+ User.any_instance.stub(:groups).and_return([])
44
+ controller.stub(:clear_session_user) ## Don't clear out the authenticated session
45
+ end
46
+
47
+ describe "#show" do
48
+ let(:asset1) {Member.create!(title: "First of the Assets")}
49
+ let(:asset2) {Member.create!(title: "Second of the Assets")}
50
+ let(:asset3) {Member.create!(title: "Third of the Assets")}
51
+ let(:collection) {OtherCollection.new}
52
+
53
+ before do
54
+ collection.title = "My collection"
55
+ collection.apply_depositor_metadata(@user.user_key)
56
+ collection.members = [asset1,asset2,asset3]
57
+ collection.save
58
+ controller.stub(:apply_gated_search)
59
+ end
60
+ after do
61
+ Rails.application.reload_routes!
62
+ end
63
+ it "should show the collections" do
64
+ routes.draw { resources :other_collections, except: :index }
65
+ get :show, id: collection.id
66
+ assigns[:collection].title.should == collection.title
67
+ ids = assigns[:member_docs].map {|d| d.id}
68
+ ids.should include asset1.pid
69
+ ids.should include asset2.pid
70
+ ids.should include asset3.pid
71
+ end
72
+ end
73
+
74
+ end
@@ -14,6 +14,17 @@ end
14
14
 
15
15
  describe SelectsCollectionsController do
16
16
 
17
+ describe "#find_collections" do
18
+ it "should override solr_search_params_logic to use collection_search_params_logic, then switch it back" do
19
+ # Looks like we can only test this indirectly b/c blacklight doesn't let you explicitly pass solr_search_params_logic when running searches -- you have to set the controller's solr_search_params_logic class attribute
20
+ original_solr_logic = subject.solr_search_params_logic
21
+ subject.collection_search_params_logic.should == [:default_solr_parameters, :add_query_to_solr, :add_access_controls_to_solr_params, :add_collection_filter]
22
+ subject.class.should_receive(:solr_search_params_logic=).with(subject.collection_search_params_logic)
23
+ subject.class.should_receive(:solr_search_params_logic=).with(original_solr_logic)
24
+ subject.find_collections
25
+ end
26
+ end
27
+
17
28
  describe "Select Collections" do
18
29
  before (:all) do
19
30
  @user = FactoryGirl.find_or_create(:user)
@@ -1,17 +1,3 @@
1
- # Copyright © 2013 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 Hydra::Collections::Engine.routes.url_helpers
@@ -19,32 +5,85 @@ include Hydra::Collections::Engine.routes.url_helpers
19
5
  describe CollectionsHelper do
20
6
  describe "button_for_create_collection" do
21
7
  it " should create a button to the collections new path" do
22
- html = button_for_create_collection
23
- html.should have_selector("form[action='#{collections.new_collection_path}']")
24
- html.should have_selector("input[type='submit']")
8
+ str = String.new(helper.button_for_create_collection)
9
+ doc = Nokogiri::HTML(str)
10
+ form = doc.xpath('//form').first
11
+ form.attr('action').should == "#{collections.new_collection_path}"
12
+ i = form.children.first.children.first
13
+ i.attr('type').should == 'submit'
25
14
  end
26
15
  it "should create a button with my text" do
27
- html = button_for_create_collection "Create My Button"
28
- html.should have_selector("input[value='Create My Button']")
16
+ str = String.new(helper.button_for_create_collection "Create My Button")
17
+ doc = Nokogiri::HTML(str)
18
+ form = doc.xpath('//form').first
19
+ form.attr('action').should == "#{collections.new_collection_path}"
20
+ i = form.children.first.children.first
21
+ i.attr('value').should == 'Create My Button'
29
22
  end
30
23
  end
31
- describe "button_for_delete_collection" do
32
- before (:all) do
33
- @collection = Collection.create title:"Test Public"
34
- end
35
- after (:all) do
36
- @collection.delete
37
- end
38
- it " should create a button to the collections delete path" do
39
- html = button_for_delete_collection @collection
40
- html.should have_selector("form[action='#{collections.collection_path(@collection.pid)}']")
41
- html.should have_selector("input[type='submit']")
42
- end
43
- it "should create a button with my text" do
44
- html = button_for_delete_collection @collection, "Delete My Button"
45
- html.should have_selector("input[value='Delete My Button']")
24
+ describe "button_for_delete_collection" do
25
+ before (:all) do
26
+ @collection = Collection.create(title: "Test Public")
27
+ end
28
+ after (:all) do
29
+ @collection.delete
30
+ end
31
+ it " should create a button to the collections delete path" do
32
+ str = button_for_delete_collection @collection
33
+ doc = Nokogiri::HTML(str)
34
+ form = doc.xpath('//form').first
35
+ form.attr('action').should == "#{collections.collection_path(@collection.pid)}"
36
+ i = form.children.first.children[1]
37
+ i.attr('type').should == 'submit'
38
+ end
39
+ it "should create a button with my text" do
40
+ str = button_for_delete_collection @collection, "Delete My Button"
41
+ doc = Nokogiri::HTML(str)
42
+ form = doc.xpath('//form').first
43
+ form.attr('action').should == "#{collections.collection_path(@collection.pid)}"
44
+ i = form.children.first.children[1]
45
+ i.attr('value').should == "Delete My Button"
46
+ end
46
47
  end
47
- end
48
+ describe "button_for_remove_from_collection" do
49
+ let(:item) { double(id: 'changeme:123') }
50
+ before do
51
+ @collection = Collection.create
52
+ end
53
+
54
+ it "should generate a form that can remove the item" do
55
+ str = button_for_remove_from_collection item
56
+ doc = Nokogiri::HTML(str)
57
+ form = doc.xpath('//form').first
58
+ form.attr('action').should == "#{collections.collection_path(@collection.pid)}"
59
+ form.css('input#collection_members[type="hidden"][value="remove"]').should_not be_empty
60
+ form.css('input[type="hidden"][name="batch_document_ids[]"][value="changeme:123"]').should_not be_empty
61
+ end
62
+
63
+ describe "for a collection of another name" do
64
+ before(:all) do
65
+ class OtherCollection < ActiveFedora::Base
66
+ include Hydra::Collection
67
+ include Hydra::Collections::Collectible
68
+ end
69
+
70
+ @collection = OtherCollection.create
71
+ end
72
+ after(:all) do
73
+ Object.send(:remove_const, :OtherCollection)
74
+ end
75
+
76
+ it "should generate a form that can remove the item" do
77
+ str = button_for_remove_from_collection item
78
+ doc = Nokogiri::HTML(str)
79
+ form = doc.xpath('//form').first
80
+ form.attr('action').should == "#{collections.collection_path(@collection.pid)}"
81
+ form.css('input#collection_members[type="hidden"][value="remove"]').should_not be_empty
82
+ form.css('input[type="hidden"][name="batch_document_ids[]"][value="changeme:123"]').should_not be_empty
83
+ end
84
+
85
+ end
86
+ end
48
87
  describe "button_for_remove_selected_from_collection" do
49
88
  before (:all) do
50
89
  @collection = Collection.create title:"Test Public"
@@ -53,13 +92,32 @@ end
53
92
  @collection.delete
54
93
  end
55
94
  it " should create a button to the collections delete path" do
56
- html = button_for_remove_selected_from_collection @collection
57
- html.should have_selector("form[action='#{collections.collection_path(@collection.pid)}']")
58
- html.should have_selector("input[type='submit']")
95
+ str = button_for_remove_selected_from_collection @collection
96
+ doc = Nokogiri::HTML(str)
97
+ form = doc.xpath('//form').first
98
+ form.attr('action').should == "#{collections.collection_path(@collection.pid)}"
99
+ i = form.children[2]
100
+ i.attr('value').should == "remove"
101
+ i.attr('name').should == "collection[members]"
59
102
  end
60
103
  it "should create a button with my text" do
61
- html = button_for_remove_selected_from_collection @collection, "Remove My Button"
62
- html.should have_selector("input[value='Remove My Button']")
104
+ str = button_for_remove_selected_from_collection @collection, "Remove My Button"
105
+ doc = Nokogiri::HTML(str)
106
+ form = doc.xpath('//form').first
107
+ form.attr('action').should == "#{collections.collection_path(@collection.pid)}"
108
+ i = form.children[3]
109
+ i.attr('value').should == "Remove My Button"
110
+ end
111
+ end
112
+
113
+ describe "hidden_collection_members" do
114
+ before { helper.params[:batch_document_ids] = ['foo:12', 'foo:23'] }
115
+ it "should make hidden fields" do
116
+ doc = Nokogiri::HTML(hidden_collection_members)
117
+ inputs = doc.xpath('//input[@type="hidden"][@name="batch_document_ids[]"]')
118
+ inputs.length.should == 2
119
+ inputs[0].attr('value').should == 'foo:12'
120
+ inputs[1].attr('value').should == 'foo:23'
63
121
  end
64
122
  end
65
123
 
@@ -1,43 +1,14 @@
1
- # Copyright © 2013 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
  describe CollectionsSearchHelper do
18
- before do
19
- @collection = Collection.create(title: "Title of Collection 1")
20
- class CollectionWithMetadata < ActiveFedora::Base
21
- include Hydra::Collection
22
- def to_solr(solr_doc={})
23
- super
24
- solr_doc[Solrizer.solr_name(:title, :displayable)] = self.descMetadata.title
25
- solr_doc
26
- end
27
- end
28
- @collection_with_metadata = CollectionWithMetadata.create(title: "Title of Collection 2")
29
- end
30
4
  describe "collection_name" do
5
+ let (:collection_without_title) { Collection.create() }
6
+ let (:collection_with_title) { Collection.create(title: "Title of Collection 2") }
31
7
  it "should return the pid if no title available" do
32
- collection_name(@collection.pid).should == @collection.pid
8
+ collection_name(collection_without_title.pid).should == collection_without_title.pid
33
9
  end
34
10
  it "should return the title value associated with the given pid" do
35
- collection_name(@collection_with_metadata.pid).should == "Title of Collection 2"
36
- end
37
- end
38
- describe "display_value_for_facet" do
39
- it "should look up collection_name when displaying collection facet" do
40
- display_value_for_facet(Solrizer.solr_name(:collection, :facetable), @collection_with_metadata.pid).should == "Title of Collection 2"
11
+ collection_name(collection_with_title.pid).should == "Title of Collection 2"
41
12
  end
42
13
  end
43
- end
14
+ end